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