1 ;;;; Environment query functions, DOCUMENTATION and DRIBBLE.
3 ;;;; FIXME: If there are exactly three things in here, it could be
4 ;;;; exactly three files named e.g. equery.lisp, doc.lisp, and dribble.lisp.
6 ;;;; This software is part of the SBCL system. See the README file for
9 ;;;; This software is derived from the CMU CL system, which was
10 ;;;; written at Carnegie Mellon University and released into the
11 ;;;; public domain. The software is in the public domain and is
12 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
13 ;;;; files for more information.
15 (in-package "SB!IMPL")
16 ;;;; Generalizing over SIMPLE-FUN, CLOSURE, and FUNCALLABLE-INSTANCEs
18 ;;; Underlying SIMPLE-FUN
19 (defun %fun-fun (function)
20 (declare (function function))
25 (%closure-fun function))
27 (%fun-fun (funcallable-instance-fun function)))))
29 (defun %fun-lambda-list (function)
32 (sb!eval:interpreted-function
33 (sb!eval:interpreted-function-debug-lambda-list function))
35 (%simple-fun-arglist (%fun-fun function)))))
37 (defun (setf %fun-lambda-list) (new-value function)
40 (sb!eval:interpreted-function
41 (setf (sb!eval:interpreted-function-debug-lambda-list function) new-value))
42 ;; FIXME: Eliding general funcallable-instances for now.
43 ((or simple-fun closure)
44 (setf (%simple-fun-arglist (%fun-fun function)) new-value)))
47 (defun %fun-type (function)
48 (%simple-fun-type (%fun-fun function)))
50 ;;; a SETFable function to return the associated debug name for FUN
51 ;;; (i.e., the third value returned from CL:FUNCTION-LAMBDA-EXPRESSION),
52 ;;; or NIL if there's none
53 (defun %fun-name (function)
56 (sb!eval:interpreted-function
57 (sb!eval:interpreted-function-debug-name function))
59 (%simple-fun-name (%fun-fun function)))))
61 (defun (setf %fun-name) (new-value function)
64 (sb!eval:interpreted-function
65 (setf (sb!eval:interpreted-function-debug-name function) new-value))
66 ;; FIXME: Eliding general funcallable-instances for now.
67 ((or simple-fun closure)
68 (setf (%simple-fun-name (%fun-fun function)) new-value)))
71 (defun %fun-doc (function)
74 (sb!eval:interpreted-function
75 (sb!eval:interpreted-function-documentation function))
77 (%simple-fun-doc (%fun-fun function)))))
79 (defun (setf %fun-doc) (new-value function)
80 (declare (type (or null string) new-value))
83 (sb!eval:interpreted-function
84 (setf (sb!eval:interpreted-function-documentation function) new-value))
85 ((or simple-fun closure)
86 (setf (%simple-fun-doc (%fun-fun function)) new-value)))
89 ;;; various environment inquiries
92 '#.(sort (copy-list sb-cold:*shebang-features*) #'string<)
94 "a list of symbols that describe features provided by the
97 (defun machine-instance ()
99 "Return a string giving the name of the local machine."
100 #!+win32 (sb!win32::get-computer-name)
101 #!-win32 (sb!unix:unix-gethostname))
103 (defvar *machine-version*)
105 (defun machine-version ()
107 "Return a string describing the version of the computer hardware we
108 are running on, or NIL if we can't find any useful information."
109 (unless (boundp '*machine-version*)
110 (setf *machine-version* (get-machine-version)))
113 ;;; FIXME: Don't forget to set these in a sample site-init file.
114 ;;; FIXME: Perhaps the functions could be SETFable instead of having the
115 ;;; interface be through special variables? As far as I can tell
116 ;;; from ANSI 11.1.2.1.1 "Constraints on the COMMON-LISP Package
117 ;;; for Conforming Implementations" it is kosher to add a SETF function for
118 ;;; a symbol in COMMON-LISP..
119 (defvar *short-site-name* nil
121 "The value of SHORT-SITE-NAME.")
122 (defvar *long-site-name* nil
123 #!+sb-doc "the value of LONG-SITE-NAME")
124 (defun short-site-name ()
126 "Return a string with the abbreviated site name, or NIL if not known."
128 (defun long-site-name ()
130 "Return a string with the long form of the site name, or NIL if not known."
134 (defvar *ed-functions* nil
135 "See function documentation for ED.")
137 (defun ed (&optional x)
138 "Starts the editor (on a file or a function if named). Functions
139 from the list *ED-FUNCTIONS* are called in order with X as an argument
140 until one of them returns non-NIL; these functions are responsible for
141 signalling a FILE-ERROR to indicate failure to perform an operation on
143 (dolist (fun *ed-functions*
144 (error 'extension-failure
145 :format-control "Don't know how to ~S ~A"
146 :format-arguments (list 'ed x)
147 :references (list '(:sbcl :variable *ed-functions*))))
148 (when (funcall fun x)
153 ;;; Each time we start dribbling to a new stream, we put it in
154 ;;; *DRIBBLE-STREAM*, and push a list of *DRIBBLE-STREAM*, *STANDARD-INPUT*,
155 ;;; *STANDARD-OUTPUT* and *ERROR-OUTPUT* in *PREVIOUS-DRIBBLE-STREAMS*.
156 ;;; *STANDARD-OUTPUT* and *ERROR-OUTPUT* is changed to a broadcast stream that
157 ;;; broadcasts to *DRIBBLE-STREAM* and to the old values of the variables.
158 ;;; *STANDARD-INPUT* is changed to an echo stream that echos input from the old
159 ;;; value of standard input to *DRIBBLE-STREAM*.
161 ;;; When dribble is called with no arguments, *DRIBBLE-STREAM* is closed,
162 ;;; and the values of *DRIBBLE-STREAM*, *STANDARD-INPUT*, and
163 ;;; *STANDARD-OUTPUT* are popped from *PREVIOUS-DRIBBLE-STREAMS*.
165 (defvar *previous-dribble-streams* nil)
166 (defvar *dribble-stream* nil)
168 (defun dribble (&optional pathname &key (if-exists :append))
170 "With a file name as an argument, dribble opens the file and sends a
171 record of further I/O to that file. Without an argument, it closes
172 the dribble file, and quits logging."
174 (let* ((new-dribble-stream
178 :if-does-not-exist :create))
180 (make-broadcast-stream *standard-output* new-dribble-stream))
182 (make-broadcast-stream *error-output* new-dribble-stream))
184 (make-echo-stream *standard-input* new-dribble-stream)))
185 (push (list *dribble-stream* *standard-input* *standard-output*
187 *previous-dribble-streams*)
188 (setf *dribble-stream* new-dribble-stream)
189 (setf *standard-input* new-standard-input)
190 (setf *standard-output* new-standard-output)
191 (setf *error-output* new-error-output)))
192 ((null *dribble-stream*)
193 (error "not currently dribbling"))
195 (let ((old-streams (pop *previous-dribble-streams*)))
196 (close *dribble-stream*)
197 (setf *dribble-stream* (first old-streams))
198 (setf *standard-input* (second old-streams))
199 (setf *standard-output* (third old-streams))
200 (setf *error-output* (fourth old-streams)))))
203 (defun %byte-blt (src src-start dst dst-start dst-end)
204 (%byte-blt src src-start dst dst-start dst-end))
206 ;;;; some *LOAD-FOO* variables
208 (defvar *load-print* nil
210 "the default for the :PRINT argument to LOAD")
212 (defvar *load-verbose* nil
213 ;; Note that CMU CL's default for this was T, and ANSI says it's
214 ;; implementation-dependent. We choose NIL on the theory that it's
215 ;; a nicer default behavior for Unix programs.
217 "the default for the :VERBOSE argument to LOAD")