1 ;;;; cross-compile-time-only replacements for miscellaneous unportable
4 ;;;; This software is part of the SBCL system. See the README file for
7 ;;;; This software is derived from the CMU CL system, which was
8 ;;;; written at Carnegie Mellon University and released into the
9 ;;;; public domain. The software is in the public domain and is
10 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
11 ;;;; files for more information.
13 (in-package "SB!IMPL")
15 ;;; In correct code, TRULY-THE has only a performance impact and can
16 ;;; be safely degraded to ordinary THE.
17 (defmacro truly-the (type expr)
20 ;;; MAYBE-INLINE and FREEZE-TYPE declarations can be safely ignored
21 ;;; (possibly at some cost in efficiency).
22 (declaim (declaration freeze-type maybe-inline))
24 ;;; INHIBIT-WARNINGS declarations can be safely ignored (although we
25 ;;; may then have to wade through some irrelevant warnings).
26 (declaim (declaration inhibit-warnings))
28 ;;; Interrupt control isn't an issue in the cross-compiler: we don't
29 ;;; use address-dependent (and thus GC-dependent) hashes, and we only
30 ;;; have a single thread of control.
31 (defmacro without-interrupts (&rest forms)
34 ;;; The GENESIS function works with fasl code which would, in the
35 ;;; target SBCL, work on ANSI-STREAMs (streams which aren't extended
36 ;;; Gray streams). In ANSI Common Lisp, an ANSI-STREAM is just a
38 (deftype ansi-stream () 'stream)
40 (deftype sb!kernel:instance ()
41 '(or condition structure-object standard-object))
42 (deftype sb!kernel:funcallable-instance ()
43 (error "not clear how to represent FUNCALLABLE-INSTANCE type"))
45 ;;; In the target SBCL, the INSTANCE type refers to a base
46 ;;; implementation for compound types with lowtag
47 ;;; INSTANCE-POINTER-LOWTAG. There's no way to express exactly that
48 ;;; concept portably, but we can get essentially the same effect by
49 ;;; testing for any of the standard types which would, in the target
50 ;;; SBCL, be derived from INSTANCE:
52 (typep x '(or condition structure-object standard-object)))
54 ;;; There aren't any FUNCALLABLE-INSTANCEs in the cross-compilation
56 (defun funcallable-instance-p (x)
57 (if (typep x 'generic-function)
58 ;; In the target SBCL, FUNCALLABLE-INSTANCEs are used to implement
59 ;; generic functions, so any case which tests for this might in
60 ;; fact be trying to test for generic functions. My (WHN 19990313)
61 ;; expectation is that this case won't arise in the
62 ;; cross-compiler, but if it does, it deserves a little thought,
63 ;; rather than reflexively returning NIL.
64 (error "not clear how to handle GENERIC-FUNCTION")
67 ;;; This seems to be the portable Common Lisp type test which
68 ;;; corresponds to the effect of the target SBCL implementation test...
69 (defun sb!kernel:array-header-p (x)
71 (or (not (typep x 'simple-array))
72 (/= (array-rank x) 1))))
74 ;;; GENESIS needs these at cross-compile time. The target
75 ;;; implementation of these is reasonably efficient by virtue of its
76 ;;; ability to peek into the internals of the package implementation;
77 ;;; this reimplementation is portable but slow.
78 (defun package-internal-symbol-count (package)
80 (declare (type fixnum result))
81 (do-symbols (i package)
82 ;; KLUDGE: The ANSI Common Lisp specification warns that
83 ;; DO-SYMBOLS may execute its body more than once for symbols
84 ;; that are inherited from multiple packages, and we currently
85 ;; make no attempt to correct for that here. (The current uses
86 ;; of this function at cross-compile time don't really care if
87 ;; the count is a little too high.) -- WHN 19990826
88 (multiple-value-bind (symbol status)
89 (find-symbol (symbol-name i) package)
90 (declare (ignore symbol))
91 (when (member status '(:internal :inherited))
94 (defun package-external-symbol-count (package)
96 (declare (type fixnum result))
97 (do-external-symbols (i package)
98 (declare (ignorable i))
102 ;;; In the target Lisp, INTERN* is the primitive and INTERN is
103 ;;; implemented in terms of it. This increases efficiency by letting
104 ;;; us reuse a fixed-size buffer; the alternative would be
105 ;;; particularly painful because we don't implement DYNAMIC-EXTENT. In
106 ;;; the host Lisp, this is only used at cold load time, and we don't
107 ;;; care as much about efficiency, so it's fine to treat the host
108 ;;; Lisp's INTERN as primitive and implement INTERN* in terms of it.
109 (defun intern* (nameoid length package)
110 (intern (replace (make-string length) nameoid :end2 length) package))
112 ;;; In the target Lisp this is implemented by reading a fixed slot in
113 ;;; the symbol. In portable ANSI Common Lisp the same criteria can be
114 ;;; met (more slowly, and with the extra property of repeatability
115 ;;; between runs) by just calling SXHASH.
116 (defun symbol-hash (symbol)
117 (declare (type symbol symbol))
120 ;;; These functions are needed for constant-folding.
121 (defun sb!kernel:simple-array-nil-p (object)
122 (when (typep object 'array)
123 (assert (not (eq (array-element-type object) nil))))
126 (defun sb!kernel:%negate (number)
129 (defun sb!kernel:%single-float (number)
130 (coerce number 'single-float))
132 (defun sb!kernel:%double-float (number)
133 (coerce number 'double-float))
135 (defun sb!kernel:%ldb (size posn integer)
136 (ldb (byte size posn) integer))
138 (defun sb!kernel:%dpb (newbyte size posn integer)
139 (dpb newbyte (byte size posn) integer))
141 (defun sb!kernel:%with-array-data (array start end)
142 (assert (typep array '(simple-array * (*))))
143 (values array start end 0))
145 (defun sb!kernel:signed-byte-32-p (number)
146 (typep number '(signed-byte 32)))
148 ;;; package locking nops for the cross-compiler
150 (defmacro without-package-locks (&body body)
153 (defmacro with-single-package-locked-error ((&optional kind thing &rest format)
155 (declare (ignore kind thing format))
158 (defun program-assert-symbol-home-package-unlocked (context symbol control)
159 (declare (ignore context control))
162 (defun assert-package-unlocked (package &optional control &rest args)
163 (declare (ignore control args))
166 (defun assert-symbol-home-package-unlocked (name format &key continuablep)
167 (declare (ignore format continuablep))
170 (declaim (declaration enable-package-locks disable-package-locks))