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