0.pre7.14:
[sbcl.git] / src / code / target-misc.lisp
1 ;;;; Environment query functions, DOCUMENTATION and DRIBBLE.
2 ;;;;
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.
5
6 ;;;; This software is part of the SBCL system. See the README file for
7 ;;;; more information.
8 ;;;;
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.
14
15 (in-package "SB!IMPL")
16
17 ;;; cobbled from stuff in describe.lisp.
18 (defun function-doc (x)
19   (let ((name
20          (case (get-type x)
21            (#.sb!vm:closure-header-type
22             (%function-name (%closure-function x)))
23            ((#.sb!vm:function-header-type #.sb!vm:closure-function-header-type)
24             (%function-name x))
25            (#.sb!vm:funcallable-instance-header-type
26             (typecase x
27               (byte-function
28                (sb!c::byte-function-name x))
29               (byte-closure
30                (sb!c::byte-function-name (byte-closure-function x)))
31               #!+sb-interpreter
32               (sb!eval:interpreted-function
33                (multiple-value-bind (exp closure-p dname)
34                    (sb!eval:interpreted-function-lambda-expression x)
35                  (declare (ignore exp closure-p))
36                  dname))
37               (t ;; funcallable-instance
38                (%function-name
39                 (funcallable-instance-function x))))))))
40     (when (and name (typep name '(or symbol cons)))
41       (values (info :function :documentation name)))))
42
43 (defvar *features* '#.sb-cold:*shebang-features*
44   #!+sb-doc
45   "a list of symbols that describe features provided by the
46    implementation")
47 \f
48 ;;; various environment inquiries
49
50 (defun machine-instance ()
51   #!+sb-doc
52   "Return a string giving the name of the local machine."
53   (sb!unix:unix-gethostname))
54
55 ;;; FIXME: Don't forget to set these in a sample site-init file.
56 ;;; FIXME: Perhaps the functions could be SETFable instead of having the
57 ;;; interface be through special variables? As far as I can tell
58 ;;; from ANSI 11.1.2.1.1 "Constraints on the COMMON-LISP Package
59 ;;; for Conforming Implementations" it is kosher to add a SETF function for
60 ;;; a symbol in COMMON-LISP..
61 (defvar *short-site-name* nil
62   #!+sb-doc
63   "The value of SHORT-SITE-NAME.")
64 (defvar *long-site-name* nil
65   #!+sb-doc "the value of LONG-SITE-NAME")
66 (defun short-site-name ()
67   #!+sb-doc
68   "Returns a string with the abbreviated site name, or NIL if not known."
69   *short-site-name*)
70 (defun long-site-name ()
71   #!+sb-doc
72   "Returns a string with the long form of the site name, or NIL if not known."
73   *long-site-name*)
74 \f
75 ;;;; dribble stuff
76
77 ;;; Each time we start dribbling to a new stream, we put it in
78 ;;; *DRIBBLE-STREAM*, and push a list of *DRIBBLE-STREAM*, *STANDARD-INPUT*,
79 ;;; *STANDARD-OUTPUT* and *ERROR-OUTPUT* in *PREVIOUS-DRIBBLE-STREAMS*.
80 ;;; *STANDARD-OUTPUT* and *ERROR-OUTPUT* is changed to a broadcast stream that
81 ;;; broadcasts to *DRIBBLE-STREAM* and to the old values of the variables.
82 ;;; *STANDARD-INPUT* is changed to an echo stream that echos input from the old
83 ;;; value of standard input to *DRIBBLE-STREAM*.
84 ;;;
85 ;;; When dribble is called with no arguments, *DRIBBLE-STREAM* is closed,
86 ;;; and the values of *DRIBBLE-STREAM*, *STANDARD-INPUT*, and
87 ;;; *STANDARD-OUTPUT* are popped from *PREVIOUS-DRIBBLE-STREAMS*.
88
89 (defvar *previous-dribble-streams* nil)
90 (defvar *dribble-stream* nil)
91
92 (defun dribble (&optional pathname &key (if-exists :append))
93   #!+sb-doc
94   "With a file name as an argument, dribble opens the file and sends a
95   record of further I/O to that file. Without an argument, it closes
96   the dribble file, and quits logging."
97   (cond (pathname
98          (let* ((new-dribble-stream
99                  (open pathname
100                        :direction :output
101                        :if-exists if-exists
102                        :if-does-not-exist :create))
103                 (new-standard-output
104                  (make-broadcast-stream *standard-output* new-dribble-stream))
105                 (new-error-output
106                  (make-broadcast-stream *error-output* new-dribble-stream))
107                 (new-standard-input
108                  (make-echo-stream *standard-input* new-dribble-stream)))
109            (push (list *dribble-stream* *standard-input* *standard-output*
110                        *error-output*)
111                  *previous-dribble-streams*)
112            (setf *dribble-stream* new-dribble-stream)
113            (setf *standard-input* new-standard-input)
114            (setf *standard-output* new-standard-output)
115            (setf *error-output* new-error-output)))
116         ((null *dribble-stream*)
117          (error "not currently dribbling"))
118         (t
119          (let ((old-streams (pop *previous-dribble-streams*)))
120            (close *dribble-stream*)
121            (setf *dribble-stream* (first old-streams))
122            (setf *standard-input* (second old-streams))
123            (setf *standard-output* (third old-streams))
124            (setf *error-output* (fourth old-streams)))))
125   (values))
126
127 (defun %byte-blt (src src-start dst dst-start dst-end)
128   (%byte-blt src src-start dst dst-start dst-end))