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