1 ;;;; Replicate much of the ACL toplevel functionality in SBCL. Mostly
2 ;;;; this is portable code, but fundamentally it all hangs from a few
3 ;;;; SBCL-specific hooks like SB-INT:*REPL-READ-FUN* and
4 ;;;; SB-INT:*REPL-PROMPT-FUN*.
6 ;;;; The documentation, which may or may not apply in its entirety at
7 ;;;; any given time, for this functionality is on the ACL website:
8 ;;;; <http://www.franz.com/support/documentation/6.2/doc/top-level.htm>.
10 (cl:in-package :sb-aclrepl)
13 (input nil) ; input, maybe a string or form
14 (func nil) ; cmd func entered, overloaded
15 ; (:eof :null-cmd :cmd-error :history-error)
16 (args nil) ; args for cmd func
17 (hnum nil)) ; history number
21 (defstruct cmd-table-entry
22 (name nil) ; name of command
23 (func nil) ; function handler
24 (desc nil) ; short description
25 (parsing nil) ; (:string :case-sensitive nil)
26 (group nil) ; command group (:cmd or :alias)
27 (abbr-len 0)) ; abbreviation length
29 (eval-when (:compile-toplevel :load-toplevel :execute)
30 (defparameter *default-prompt*
31 "~:[~3*~;[~:*~D~:[~;~:*:~D~]~:[~;i~]~:[~;c~]] ~]~A(~D): "
32 "The default prompt."))
33 (defparameter *prompt* #.*default-prompt*
34 "The current prompt string or formatter function.")
35 (defparameter *use-short-package-name* t
36 "when T, use the shortnest package nickname in a prompt")
37 (defparameter *dir-stack* nil
38 "The top-level directory stack")
39 (defparameter *command-char* #\:
40 "Prefix character for a top-level command")
41 (defvar *max-history* 100
42 "Maximum number of history commands to remember")
43 (defvar *exit-on-eof* t
44 "If T, then exit when the EOF character is entered.")
45 (defparameter *history* nil
47 (defparameter *cmd-number* 1
48 "Number of the next command")
53 (declaim (type list *history*))
55 (defvar *eof-marker* :eof)
56 (defvar *eof-cmd* (make-user-cmd :func :eof))
57 (defvar *null-cmd* (make-user-cmd :func :null-cmd))
59 (defparameter *cmd-table-hash*
60 (make-hash-table :size 30 :test #'equal))
62 (defun prompt-package-name ()
63 (if *use-short-package-name*
65 (package-nicknames cl:*package*)
66 (list (package-name cl:*package*)))
67 (lambda (a b) (< (length a) (length b)))))
68 (package-name cl:*package*)))
70 (defun read-cmd (input-stream)
71 ;; Reads a command from the user and returns a user-cmd object
72 (let* ((next-char (peek-char-non-whitespace input-stream))
74 ((eql *command-char* next-char)
75 (dispatch-command-line input-stream))
76 ((eql #\newline next-char)
77 (read-char input-stream)
82 (let* ((eof (cons nil *eof-marker*))
83 (form (read input-stream nil eof)))
86 (make-user-cmd :input form :func nil :hnum *cmd-number*)))))))
87 (if (and (eq cmd *eof-cmd*) (typep input-stream 'string-stream))
88 (throw 'repl-catcher cmd)
91 (defun dispatch-command-line (input-stream)
92 "Processes an input line that starts with *command-char*"
93 (let* ((line (string-trim-whitespace (read-line input-stream)))
94 (first-space-pos (position #\space line))
95 (cmd-string (subseq line 1 first-space-pos))
98 (string-trim-whitespace (subseq line first-space-pos))
100 (declare (simple-string line))
102 ((or (zerop (length cmd-string))
103 (whitespace-char-p (char cmd-string 0)))
105 ((or (numberp (read-from-string cmd-string))
106 (char= (char cmd-string 0) #\+)
107 (char= (char cmd-string 0) #\-))
108 (process-cmd-numeric cmd-string cmd-args-string))
109 ((char= (char cmd-string 0) *command-char*)
110 (process-history-search (subseq cmd-string 1) cmd-args-string))
112 (process-cmd-text cmd-string line cmd-args-string)))))
114 (defun process-cmd-numeric (cmd-string cmd-args-string)
115 "Process a numeric cmd, such as ':123'"
116 (let* ((first-char (char cmd-string 0))
117 (number-string (if (digit-char-p first-char)
119 (subseq cmd-string 1)))
120 (is-minus (char= first-char #\-))
121 (raw-number (read-from-string number-string))
123 (- *cmd-number* raw-number)
125 (cmd (get-history number)))
126 (when (eq cmd *null-cmd*)
127 (return-from process-cmd-numeric
128 (make-user-cmd :func :history-error :input (read-from-string
130 (maybe-return-history-cmd cmd cmd-args-string)))
132 (defun maybe-return-history-cmd (cmd cmd-args-string)
133 (format *output* "~A~%" (user-cmd-input cmd))
135 (when (and (stringp cmd-args-string)
136 (plusp (length cmd-args-string))
137 (char= #\? (char cmd-args-string 0)))
138 (do ((line nil (read-line *input*)))
139 ((and line (or (zerop (length line))
140 (string-equal line "Y")
141 (string-equal line "N")))
142 (when (string-equal line "N")
145 (format *output* "Type \"y\" for yes or \"n\" for no.~%"))
146 (format *output* "redo? [y] ")
147 (force-output *output*)))))
150 (make-user-cmd :func (user-cmd-func cmd)
151 :input (user-cmd-input cmd)
152 :args (user-cmd-args cmd)
153 :hnum *cmd-number*))))
156 (defun find-history-matching-pattern (cmd-string)
157 "Return history item matching cmd-string or NIL if not found"
158 (dolist (his *history* nil)
159 (let* ((input (user-cmd-input his))
160 (string-input (if (stringp input)
162 (write-to-string input))))
163 (when (search cmd-string string-input :test #'string-equal)
164 (return-from find-history-matching-pattern his)))))
166 (defun process-history-search (pattern cmd-args-string)
167 (let ((cmd (find-history-matching-pattern pattern)))
169 (format *output* "No match on history list with pattern ~S~%" pattern)
170 (return-from process-history-search *null-cmd*))
171 (maybe-return-history-cmd cmd cmd-args-string)))
174 (defun process-cmd-text (cmd-string line cmd-args-string)
175 "Process a text cmd, such as ':ld a b c'"
176 (flet ((parse-args (parsing args-string)
179 (if (zerop (length args-string))
183 (let ((string-stream (make-string-input-stream args-string))
184 (eof (cons nil *eof-marker*))) ;new cons for eq uniqueness
185 (loop as arg = (read string-stream nil eof)
188 (let ((cmd-entry (find-cmd cmd-string)))
190 (return-from process-cmd-text
191 (make-user-cmd :func :cmd-error :input cmd-string)))
192 (make-user-cmd :func (cmd-table-entry-func cmd-entry)
194 :args (parse-args (cmd-table-entry-parsing cmd-entry)
196 :hnum *cmd-number*))))
198 (defun make-cte (name-param func desc parsing group abbr-len)
199 (let ((name (etypecase name-param
203 (string-downcase (write-to-string name-param))))))
204 (make-cmd-table-entry :name name :func func :desc desc
205 :parsing parsing :group group
206 :abbr-len (if abbr-len
210 (defun %add-entry (cmd &optional abbr-len)
211 (let* ((name (cmd-table-entry-name cmd))
215 (dotimes (i (length name))
216 (when (>= i (1- alen))
217 (setf (gethash (subseq name 0 (1+ i)) *cmd-table-hash*)
220 (defun add-cmd-table-entry (cmd-string abbr-len func-name desc parsing)
222 (make-cte cmd-string (symbol-function func-name) desc parsing :cmd abbr-len)
225 (defun find-cmd (cmdstr)
226 (gethash (string-downcase cmdstr) *cmd-table-hash*))
228 (defun user-cmd= (c1 c2)
229 "Returns T if two user commands are equal"
230 (and (eq (user-cmd-func c1) (user-cmd-func c2))
231 (equal (user-cmd-args c1) (user-cmd-args c2))
232 (equal (user-cmd-input c1) (user-cmd-input c2))))
234 (defun add-to-history (cmd)
235 (unless (and *history* (user-cmd= cmd (car *history*)))
236 (when (>= (length *history*) *max-history*)
237 (setq *history* (nbutlast *history*
238 (1+ (- (length *history*) *max-history*)))))
240 (incf *cmd-number*)))
242 (defun get-history (n)
243 (let ((cmd (find n *history* :key #'user-cmd-hnum :test #'eql)))
248 (defun get-cmd-doc-list (&optional (group :cmd))
249 "Return list of all commands"
251 (maphash (lambda (k v)
253 (= (length k) (length (cmd-table-entry-name v)))
254 (eq (cmd-table-entry-group v) group))
256 (if (= (cmd-table-entry-abbr-len v)
259 (subseq k 0 (cmd-table-entry-abbr-len v)))
260 (cmd-table-entry-desc v)) cmds)))
262 (sort cmds #'string-lessp :key #'car)))
264 (defun cd-cmd (&optional string-dir)
266 ((or (zerop (length string-dir))
267 (string= string-dir "~"))
268 (setf cl:*default-pathname-defaults* (user-homedir-pathname)))
270 (let ((new (truename string-dir)))
271 (when (pathnamep new)
272 (setf cl:*default-pathname-defaults* new)))))
273 (format *output* "~A~%" (namestring cl:*default-pathname-defaults*))
277 (format *output* "Lisp's current working directory is ~s.~%"
278 (namestring cl:*default-pathname-defaults*))
281 (defun trace-cmd (&rest args)
283 (format *output* "~A~%" (eval (sb-debug::expand-trace args)))
284 (format *output* "~A~%" (sb-debug::%list-traced-funs)))
287 (defun untrace-cmd (&rest args)
289 (format *output* "~A~%"
291 (sb-int:collect ((res))
292 (let ((current args))
294 (unless current (return))
295 (let ((name (pop current)))
296 (res (if (eq name :function)
297 `(sb-debug::untrace-1 ,(pop current))
298 `(sb-debug::untrace-1 ',name))))))
299 `(progn ,@(res) t))))
300 (format *output* "~A~%" (eval (sb-debug::untrace-all))))
304 (defun all-threads ()
305 "Return a list of all threads"
306 (sb-thread:list-all-threads))
309 (defun other-threads ()
310 "Returns a list of all threads except the current one"
311 (delete sb-thread:*current-thread* (all-threads)))
313 (defun exit-cmd (&optional (status 0))
315 (let ((other-threads (other-threads)))
317 (format *output* "There exists the following processes~%")
318 (format *output* "~{~A~%~}" other-threads)
319 (format *output* "Do you want to exit lisp anyway [n]? ")
320 (force-output *output*)
321 (let ((input (string-trim-whitespace (read-line *input*))))
322 (if (and (plusp (length input))
323 (or (char= #\y (char input 0))
324 (char= #\Y (char input 0))))
325 ;; loop in case more threads get created while trying to exit
326 (do ((threads other-threads (other-threads)))
328 (map nil #'sb-thread:destroy-thread threads)
330 (return-from exit-cmd)))))
331 (sb-ext:quit :unix-status status)
334 (defun package-cmd (&optional pkg)
337 (format *output* "The ~A package is current.~%"
338 (package-name cl:*package*)))
339 ((null (find-package (write-to-string pkg)))
340 (format *output* "Unknown package: ~A.~%" pkg))
342 (setf cl:*package* (find-package (write-to-string pkg)))))
345 (defun string-to-list-skip-spaces (str)
346 "Return a list of strings, delimited by spaces, skipping spaces."
347 (declare (type (or null string) str))
349 (loop for i = 0 then (1+ j)
350 as j = (position #\space str :start i)
351 when (not (char= (char str i) #\space))
352 collect (subseq str i j) while j)))
354 (let ((last-files-loaded nil))
355 (defun ld-cmd (&optional string-files)
357 (setq last-files-loaded string-files)
358 (setq string-files last-files-loaded))
359 (dolist (arg (string-to-list-skip-spaces string-files))
361 (if (string= arg "~/" :end1 1 :end2 1)
362 (merge-pathnames (parse-namestring
363 (string-left-trim "~/" arg))
364 (user-homedir-pathname))
366 (format *output* "loading ~S~%" file)
370 (defun cf-cmd (string-files)
372 (dolist (arg (string-to-list-skip-spaces string-files))
377 "Return if x and y are numbers, and x > y"
378 (and (numberp x) (numberp y) (> x y)))
380 (defun newer-file-p (file1 file2)
381 "Is file1 newer (written later than) file2?"
382 (>-num (if (probe-file file1) (file-write-date file1))
383 (if (probe-file file2) (file-write-date file2))))
385 (defun compile-file-as-needed (src-path)
386 "Compiles a file if needed, returns path."
387 (let ((dest-path (compile-file-pathname src-path)))
388 (when (or (not (probe-file dest-path))
389 (newer-file-p src-path dest-path))
390 (ensure-directories-exist dest-path)
391 (compile-file src-path :output-file dest-path))
394 ;;;; implementation of commands
396 (defun apropos-cmd (string)
397 (apropos (string-upcase string))
398 (fresh-line *output*)
401 (let ((last-files-loaded nil))
402 (defun cload-cmd (&optional string-files)
404 (setq last-files-loaded string-files)
405 (setq string-files last-files-loaded))
406 (dolist (arg (string-to-list-skip-spaces string-files))
407 (format *output* "loading ~a~%" arg)
408 (load (compile-file-as-needed arg)))
411 (defun inspect-cmd (arg)
412 (inspector-fun (eval arg) nil *output*)
415 (defun istep-cmd (&optional arg-string)
416 (istep (string-to-list-skip-spaces arg-string) *output*)
419 (defun describe-cmd (&rest args)
421 (eval `(describe ,arg)))
424 (defun macroexpand-cmd (arg)
425 (pprint (macroexpand arg) *output*)
428 (defun history-cmd ()
429 (let ((n (length *history*)))
433 (let ((hist (nth (- n i 1) *history*)))
434 (format *output* "~3A " (user-cmd-hnum hist))
435 (if (stringp (user-cmd-input hist))
436 (format *output* "~A~%" (user-cmd-input hist))
437 (format *output* "~W~%" (user-cmd-input hist))))))
440 (defun help-cmd (&optional cmd)
443 (let ((cmd-entry (find-cmd cmd)))
445 (format *output* "Documentation for ~A: ~A~%"
446 (cmd-table-entry-name cmd-entry)
447 (cmd-table-entry-desc cmd-entry)))))
449 (format *output* "~11A ~4A ~A~%" "COMMAND" "ABBR" "DESCRIPTION")
450 (format *output* "~11A ~4A ~A~%" "<n>" ""
451 "re-execute <n>th history command")
452 (dolist (doc-entry (get-cmd-doc-list :cmd))
453 (format *output* "~11A ~4A ~A~%" (first doc-entry)
454 (second doc-entry) (third doc-entry)))))
458 (let ((doc-entries (get-cmd-doc-list :alias)))
459 (typecase doc-entries
461 (format *output* "~11A ~A ~4A~%" "ALIAS" "ABBR" "DESCRIPTION")
462 (dolist (doc-entry doc-entries)
463 (format *output* "~11A ~4A ~A~%" (first doc-entry) (second doc-entry) (third doc-entry))))
465 (format *output* "No aliases are defined~%"))))
468 (defun shell-cmd (string-arg)
469 (sb-ext:run-program "/bin/sh" (list "-c" string-arg)
470 :input nil :output *output*)
473 (defun pushd-cmd (string-arg)
474 (push string-arg *dir-stack*)
480 (let ((dir (pop *dir-stack*)))
482 (format *output* "No directory on stack to pop.~%"))
485 (defun pop-cmd (&optional (n 1))
488 (throw 'repl-catcher (values :inspect n)))
489 ((plusp *break-level*)
490 (throw 'repl-catcher (values :pop n))))
493 (defun bt-cmd (&optional (n most-positive-fixnum))
494 (sb-debug::backtrace n))
496 (defun current-cmd ()
497 (sb-debug::describe-debug-command))
500 (sb-debug::frame-debug-command 0))
503 (sb-debug::bottom-debug-command))
505 (defun up-cmd (&optional (n 1))
507 (if (and sb-debug::*current-frame*
508 (sb-di:frame-up sb-debug::*current-frame*))
509 (sb-debug::up-debug-command)
511 (format *output* "Top of the stack")
512 (return-from up-cmd)))))
514 (defun dn-cmd (&optional (n 1))
516 (if (and sb-debug::*current-frame*
517 (sb-di:frame-down sb-debug::*current-frame*))
518 (sb-debug::down-debug-command)
520 (format *output* "Bottom of the stack")
521 (return-from dn-cmd)))))
523 (defun continue-cmd (&optional (num 0))
524 ;; don't look at first restart
525 (let ((restarts (compute-restarts)))
530 (if (< -1 num (length restarts))
533 (format *output* "There is no such restart")
534 (return-from continue-cmd))))
536 (find num (the list restarts)
538 :test (lambda (sym1 sym2)
539 (string= (symbol-name sym1)
540 (symbol-name sym2)))))
542 (format *output* "~S is invalid as a restart name" num)
543 (return-from continue-cmd nil)))))
545 (invoke-restart-interactively restart)))
546 (format *output* "~&There are no restarts"))))
549 (when (plusp *break-level*)
551 (sb-debug::show-restarts (compute-restarts) *output*)
552 (let ((sb-debug::*debug-restarts* (compute-restarts)))
553 (sb-debug::error-debug-command)))))
556 (sb-debug::print-frame-call sb-debug::*current-frame*))
561 (defun local-cmd (&optional var)
562 (declare (ignore var))
563 (sb-debug::list-locals-debug-command))
565 (defun processes-cmd ()
567 (dolist (thread (all-threads))
568 (format *output* "~&~A" thread)
569 (when (eq thread sb-thread:*current-thread*)
570 (format *output* " [current listener]")))
572 (format *output* "~&Threads are not supported in this version of sbcl")
575 (defun sb-aclrepl::kill-cmd (&rest selected-threads)
577 (dolist (thread selected-threads)
578 (let ((found (find thread (all-threads) :key 'sb-thread:thread-name
582 (format *output* "~&Destroying thread ~A" thread)
583 (sb-thread:destroy-thread found))
584 (format *output* "~&Thread ~A not found" thread))))
586 (declare (ignore selected-threads))
588 (format *output* "~&Threads are not supported in this version of sbcl")
591 (defun focus-cmd (&optional process)
593 (declare (ignore process))
596 (format *output* "~&Focusing on next thread waiting waiting for the debugger~%"))
599 (sb-thread:release-foreground)
602 (format *output* "~&Threads are not supported in this version of sbcl")
606 (throw 'sb-impl::toplevel-catcher nil))
609 (dolist (dir *dir-stack*)
610 (format *output* "~a~%" dir))
614 ;;;; dispatch table for commands
617 '(("aliases" 3 alias-cmd "show aliases")
618 ("apropos" 2 apropos-cmd "show apropos" :parsing :string)
619 ("bottom" 3 bottom-cmd "move to bottom stack frame")
620 ("top" 3 top-cmd "move to top stack frame")
621 ("bt" 2 bt-cmd "backtrace `n' stack frames, default all")
622 ("up" 2 up-cmd "move up `n' stack frames, default 1")
623 ("dn" 2 dn-cmd "move down `n' stack frames, default 1")
624 ("cd" 2 cd-cmd "change default diretory" :parsing :string)
625 ("ld" 2 ld-cmd "load a file" :parsing :string)
626 ("cf" 2 cf-cmd "compile file" :parsing :string)
627 ("cload" 2 cload-cmd "compile if needed and load file"
629 ("current" 3 current-cmd "print the expression for the current stack frame")
630 ("continue" 4 continue-cmd "continue from a continuable error")
631 ("describe" 2 describe-cmd "describe an object")
632 ("macroexpand" 2 macroexpand-cmd "macroexpand an expression")
633 ("package" 2 package-cmd "change current package")
634 ("error" 3 error-cmd "print the last error message")
635 ("exit" 2 exit-cmd "exit sbcl")
636 ("frame" 2 frame-cmd "print info about the current frame")
637 ("help" 2 help-cmd "print this help")
638 ("history" 3 history-cmd "print the recent history")
639 ("inspect" 2 inspect-cmd "inspect an object")
640 ("istep" 1 istep-cmd "navigate within inspection of a lisp object" :parsing :string)
641 #+sb-thread ("kill" 2 kill-cmd "kill (destroy) processes")
642 #+sb-thread ("focus" 2 focus-cmd "focus the top level on a process")
643 ("local" 3 local-cmd "print the value of a local variable")
644 ("pwd" 3 pwd-cmd "print current directory")
645 ("pushd" 2 pushd-cmd "push directory on stack" :parsing :string)
646 ("pop" 3 pop-cmd "pop up `n' (default 1) break levels")
647 ("popd" 4 popd-cmd "pop directory from stack")
648 #+sb-thread ("processes" 3 processes-cmd "list all processes")
649 ("reset" 3 reset-cmd "reset to top break level")
650 ("trace" 2 trace-cmd "trace a function")
651 ("untrace" 4 untrace-cmd "untrace a function")
652 ("dirs" 2 dirs-cmd "show directory stack")
653 ("shell" 2 shell-cmd "execute a shell cmd" :parsing :string)
654 ("zoom" 2 zoom-cmd "print the runtime stack")
656 (dolist (cmd cmd-table)
657 (destructuring-bind (cmd-string abbr-len func-name desc &key parsing) cmd
658 (add-cmd-table-entry cmd-string abbr-len func-name desc parsing))))
660 ;;;; machinery for aliases
662 (defsetf alias (name &key abbr-len description) (user-func)
665 (make-cte (quote ,name) ,user-func ,description nil :alias ,abbr-len))
668 (defmacro alias (name-param args &rest body)
672 (name (if (atom name-param)
675 (when (consp name-param)
676 (dolist (param (cdr name-param))
679 (eq param :case-sensitive)
681 (setq parsing param))
685 (setq abbr-index param)))))
688 (make-cte (quote ,name) (lambda ,args ,@body) ,desc ,parsing :alias (when ,abbr-index
694 (defun remove-alias (&rest aliases)
695 (declare (list aliases))
697 (remove-all (not (null (find :all aliases)))))
698 (unless remove-all ;; ensure all alias are strings
700 (loop for alias in aliases
706 (symbol-name alias))))))
709 (when (eq (cmd-table-entry-group cmd) :alias)
714 (let ((klen (length key)))
715 (and (>= (length alias) klen)
716 (string-equal (subseq alias 0 klen)
717 (subseq key 0 klen)))))
722 (remhash key *cmd-table-hash*))
725 ;;;; low-level reading/parsing functions
727 ;;; Skip white space (but not #\NEWLINE), and peek at the next
729 (defun peek-char-non-whitespace (&optional stream)
730 (do ((char (peek-char nil stream nil *eof-marker*)
731 (peek-char nil stream nil *eof-marker*)))
732 ((not (whitespace-char-not-newline-p char)) char)
735 (defun string-trim-whitespace (str)
736 (string-trim '(#\space #\tab #\return)
739 (defun whitespace-char-p (x)
741 (or (char= x #\space)
745 (char= x #\return))))
747 (defun whitespace-char-not-newline-p (x)
748 (and (whitespace-char-p x)
749 (not (char= x #\newline))))
751 ;;;; linking into SBCL hooks
753 (defun repl-prompt-fun (stream)
754 (let ((break-level (when (plusp *break-level*)
756 (frame-number (when (and (plusp *break-level*)
757 sb-debug::*current-frame*)
758 (sb-di::frame-number sb-debug::*current-frame*))))
759 (sb-thread::get-foreground)
761 (if (functionp *prompt*)
762 (write-string (funcall *prompt*
767 (prompt-package-name) *cmd-number*)
775 (prompt-package-name) *cmd-number*)
777 (format stream "~&Prompt error> "))
779 (format stream "~A" prompt))))))
781 (defun process-cmd (user-cmd)
782 ;; Processes a user command. Returns t if the user-cmd was a top-level
784 (cond ((eq user-cmd *eof-cmd*)
787 (format *output* "EOF~%")
789 ((eq user-cmd *null-cmd*)
791 ((eq (user-cmd-func user-cmd) :cmd-error)
792 (format *output* "Unknown top-level command: ~s.~%"
793 (user-cmd-input user-cmd))
794 (format *output* "Type `~Ahelp' for the list of commands.~%" *command-char*)
796 ((eq (user-cmd-func user-cmd) :history-error)
797 (format *output* "Input numbered ~d is not on the history list~%"
798 (user-cmd-input user-cmd))
800 ((functionp (user-cmd-func user-cmd))
801 (add-to-history user-cmd)
802 (apply (user-cmd-func user-cmd) (user-cmd-args user-cmd))
806 (add-to-history user-cmd)
807 nil))) ; nope, not in my job description
809 (defun repl-read-form-fun (input output)
810 ;; Pick off all the leading ACL magic commands, then return a normal
812 (let ((*input* input)
814 (loop for user-cmd = (read-cmd *input*) do
815 (if (process-cmd user-cmd)
817 (funcall sb-int:*repl-prompt-fun* *output*)
818 (force-output *output*))
819 (return (user-cmd-input user-cmd))))))
822 (setf sb-int:*repl-prompt-fun* #'repl-prompt-fun
823 sb-int:*repl-read-form-fun* #'repl-read-form-fun)
825 (defmacro with-new-repl-state ((&rest vars) &body forms)
826 (let ((gvars (mapcar (lambda (var) (gensym (symbol-name var))) vars)))
827 `(let (,@(mapcar (lambda (var gvar) `(,gvar ,var)) vars gvars))
829 (let ((*noprint* noprint))
830 (let (,@(mapcar (lambda (var gvar) `(,var ,gvar)) vars gvars))
833 ,@(mapcar (lambda (var gvar) `(setf ,gvar ,var))
836 (defun make-repl-fun ()
837 (with-new-repl-state (*break-level* *inspect-break* *continuable-break*
838 *dir-stack* *command-char* *prompt*
839 *use-short-package-name* *max-history* *exit-on-eof*
840 *history* *cmd-number*)
841 (repl :noprint noprint :break-level 0)))
843 (when (boundp 'sb-impl::*repl-fun-generator*)
844 (setq sb-impl::*repl-fun-generator* #'make-repl-fun))