0.6.11.45:
[sbcl.git] / src / code / target-extensions.lisp
1 ;;;; This file contains things for the extensions packages (SB-EXT and
2 ;;;; also "internal extensions" SB-INT) which can't be built at
3 ;;;; cross-compile time, and perhaps also some things which might as
4 ;;;; well not be built at cross-compile time because they're not
5 ;;;; needed then. Things which can't be built at cross-compile time
6 ;;;; (e.g. because they need machinery which only exists inside SBCL's
7 ;;;; implementation of the LISP package) do not belong in this file.
8
9 ;;;; This software is part of the SBCL system. See the README file for
10 ;;;; more information.
11 ;;;;
12 ;;;; This software is derived from the CMU CL system, which was
13 ;;;; written at Carnegie Mellon University and released into the
14 ;;;; public domain. The software is in the public domain and is
15 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
16 ;;;; files for more information.
17
18 (in-package "SB!IMPL")
19 \f
20 ;;;; miscellaneous I/O
21
22 ;;; INDENTING-FURTHER is a user-level macro which may be used to locally
23 ;;; increment the indentation of a stream.
24 (defmacro indenting-further (stream more &rest body)
25   #!+sb-doc
26   "Causes the output of the indenting Stream to indent More spaces. More is
27   evaluated twice."
28   `(unwind-protect
29      (progn
30       (incf (sb!impl::indenting-stream-indentation ,stream) ,more)
31       ,@body)
32      (decf (sb!impl::indenting-stream-indentation ,stream) ,more)))
33
34 (defun skip-whitespace (&optional (stream *standard-input*))
35   (loop (let ((char (read-char stream)))
36           (unless (sb!impl::whitespacep char)
37             (return (unread-char char stream))))))
38
39 ;;; like LISTEN, but any whitespace in the input stream will be flushed
40 (defun listen-skip-whitespace (&optional (stream *standard-input*))
41   (do ((char (read-char-no-hang stream nil nil nil)
42              (read-char-no-hang stream nil nil nil)))
43       ((null char) nil)
44     (cond ((not (whitespace-char-p char))
45            (unread-char char stream)
46            (return t)))))
47 \f
48 ;;;; helpers for C library calls
49
50 ;;; Signal a SIMPLE-CONDITION/ERROR condition associated with an ANSI C
51 ;;; errno problem, arranging for the condition's print representation
52 ;;; to be similar to the ANSI C perror(3) style.
53 (defun simple-perror (prefix-string
54                       &key
55                       (errno (get-errno))
56                       (simple-error 'simple-error)
57                       other-condition-args)
58   (declare (type symbol simple-error))
59   (aver (subtypep simple-error 'simple-condition))
60   (aver (subtypep simple-error 'error))
61   (apply #'error
62          simple-error
63          :format-control "~@<~A: ~2I~_~A~:>"
64          :format-arguments (list prefix-string (strerror errno))
65          other-condition-args))
66 \f
67 ;;;; optimization idioms
68
69 (eval-when (:compile-toplevel :load-toplevel :execute)
70
71   ;; Byte compile this thing if possible.
72   (defvar *optimize-byte-compilation*
73     '(optimize (speed 0) (safety 1)))
74
75   ;; This thing is externally visible, so compiling meta-information
76   ;; is more important than byte-compiling it; but it's otherwise
77   ;; suitable for byte-compilation.
78   ;;
79   ;; (As long as the byte compiler isn't capable of compiling
80   ;; meta-information such as the argument list required by functions
81   ;; (as in sbcl-0.6.12, anyway), it's not suitable for compiling
82   ;; externally visible things like CL:INSPECT even if their speed
83   ;; requirements are small enough that it'd otherwise be OK. If some
84   ;; later version of the byte compiler learns to compile such
85   ;; meta-information, we'll probably change the implementation of
86   ;; this idiom so that it causes byte compilation of the thing after
87   ;; all.)
88   (defvar *optimize-external-despite-byte-compilation*
89     '(optimize (speed 1)
90                ;; still might as well be as small as possible..
91                (space 3))))