Fix FORMAT compilation on non-simple strings.
[sbcl.git] / src / code / cross-misc.lisp
blobdbe71d9c521c1b4fb305eb0f0eed0a1918a8ba25
1 ;;;; cross-compile-time-only replacements for miscellaneous unportable
2 ;;;; stuff
4 ;;;; This software is part of the SBCL system. See the README file for
5 ;;;; more information.
6 ;;;;
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 ;;; Forward declarations
17 ;;; In correct code, TRULY-THE has only a performance impact and can
18 ;;; be safely degraded to ordinary THE.
19 (defmacro truly-the (type expr)
20 `(the ,type ,expr))
22 (defmacro named-lambda (name args &body body)
23 (declare (ignore name))
24 `#'(lambda ,args ,@body))
26 (defmacro with-locked-system-table ((table) &body body)
27 (declare (ignore table))
28 `(progn ,@body))
30 (defmacro defglobal (name value &rest doc)
31 `(eval-when (:compile-toplevel :load-toplevel :execute)
32 (defparameter ,name
33 (if (boundp ',name)
34 (symbol-value ',name)
35 ,value)
36 ,@doc)))
38 (defmacro define-load-time-global (&rest args) `(defvar ,@args))
40 ;;; The GENESIS function works with fasl code which would, in the
41 ;;; target SBCL, work on ANSI-STREAMs (streams which aren't extended
42 ;;; Gray streams). In ANSI Common Lisp, an ANSI-STREAM is just a
43 ;;; CL:STREAM.
44 (deftype ansi-stream () 'stream)
46 (deftype instance ()
47 '(or condition structure-object standard-object))
48 (deftype funcallable-instance ()
49 (error "not clear how to represent FUNCALLABLE-INSTANCE type"))
51 ;; The definition of TYPE-SPECIFIER for the target appears in the file
52 ;; 'deftypes-for-target' - it allows CLASSes and CLASOIDs as specifiers.
53 ;; Instances are never used as specifiers when building SBCL,
54 ;; handily avoiding a problem in figuring out an order in which to
55 ;; define the types CLASS, CLASSOID, and TYPE-SPECIFIER.
56 (deftype type-specifier () '(or list symbol))
58 ;;; In the target SBCL, the INSTANCE type refers to a base
59 ;;; implementation for compound types with lowtag
60 ;;; INSTANCE-POINTER-LOWTAG. There's no way to express exactly that
61 ;;; concept portably, but we can get essentially the same effect by
62 ;;; testing for any of the standard types which would, in the target
63 ;;; SBCL, be derived from INSTANCE:
64 (defun %instancep (x)
65 (typep x '(or condition structure-object standard-object)))
67 ;;; There aren't any FUNCALLABLE-INSTANCEs in the cross-compilation
68 ;;; host Common Lisp.
69 (defun funcallable-instance-p (x)
70 (if (typep x 'generic-function)
71 ;; In the target SBCL, FUNCALLABLE-INSTANCEs are used to implement
72 ;; generic functions, so any case which tests for this might in
73 ;; fact be trying to test for generic functions. My (WHN 19990313)
74 ;; expectation is that this case won't arise in the
75 ;; cross-compiler, but if it does, it deserves a little thought,
76 ;; rather than reflexively returning NIL.
77 (error "not clear how to handle GENERIC-FUNCTION")
78 nil))
80 ;;; This seems to be the portable Common Lisp type test which
81 ;;; corresponds to the effect of the target SBCL implementation test...
82 (defun array-header-p (x)
83 (and (typep x 'array)
84 (or (not (typep x 'simple-array))
85 (/= (array-rank x) 1))))
87 (defvar sb!xc:*gensym-counter* 0)
89 (defun sb!xc:gensym (&optional (thing "G"))
90 (declare (type string thing))
91 (let ((n sb!xc:*gensym-counter*))
92 (prog1
93 (make-symbol (concatenate 'string thing (write-to-string n :base 10 :radix nil :pretty nil)))
94 (incf sb!xc:*gensym-counter*))))
96 ;;; These functions are needed for constant-folding.
97 (defun simple-array-nil-p (object)
98 (when (typep object 'array)
99 (assert (not (eq (array-element-type object) nil))))
100 nil)
102 (defun %negate (number)
103 (- number))
105 (defun %single-float (number)
106 (coerce number 'single-float))
108 (defun %double-float (number)
109 (coerce number 'double-float))
111 (defun %ldb (size posn integer)
112 (ldb (byte size posn) integer))
114 (defun %dpb (newbyte size posn integer)
115 (dpb newbyte (byte size posn) integer))
117 (defun %with-array-data (array start end)
118 (assert (typep array '(simple-array * (*))))
119 (values array start end 0))
121 (defun %with-array-data/fp (array start end)
122 (assert (typep array '(simple-array * (*))))
123 (values array start end 0))
125 (defun signed-byte-32-p (number)
126 (typep number '(signed-byte 32)))
128 ;; This has an obvious portable implementation
129 ;; as (typep number 'ratio), but apparently we
130 ;; expect never to need it.
131 (defun ratiop (number)
132 (declare (ignore number))
133 (error "Should not call RATIOP"))
135 (defun make-value-cell (value)
136 (declare (ignore value))
137 (error "cross-compiler can not make value cells"))
139 ;;; package locking nops for the cross-compiler
141 (defmacro without-package-locks (&body body)
142 `(progn ,@body))
144 (defmacro with-single-package-locked-error ((&optional kind thing &rest format)
145 &body body)
146 ;; FIXME: perhaps this should touch THING to make it used?
147 (declare (ignore kind thing format))
148 `(progn ,@body))
150 (defun program-assert-symbol-home-package-unlocked (context symbol control)
151 (declare (ignore context control))
152 symbol)
154 (defun assert-package-unlocked (package &optional format-control
155 &rest format-arguments)
156 (declare (ignore format-control format-arguments))
157 package)
159 (defun assert-symbol-home-package-unlocked (name &optional format-control
160 &rest format-arguments)
161 (declare (ignore format-control format-arguments))
162 name)
164 (declaim (declaration enable-package-locks disable-package-locks))
166 ;; Nonstandard accessor for when you know you have a valid package in hand.
167 ;; This avoids double lookup in *PACKAGE-NAMES* in a few places.
168 ;; But portably we have to just fallback to PACKAGE-NAME.
169 (defun package-%name (x) (package-name x))
171 ;;; printing structures
173 (defun default-structure-print (structure stream depth)
174 (declare (ignore depth))
175 (write structure :stream stream :circle t))
177 (in-package "SB!KERNEL")
178 (defun %find-position (item seq from-end start end key test)
179 (let ((position (position item seq :from-end from-end
180 :start start :end end :key key :test test)))
181 (values (if position (elt seq position) nil) position)))
183 (defun sb!impl::split-seconds-for-sleep (&rest args)
184 (declare (ignore args))
185 (error "Can't call SPLIT-SECONDS-FOR-SLEEP"))
187 ;;; Avoid an unknown type reference from globaldb.
188 (deftype fdefn () '(satisfies fdefn-p))
190 ;;; Avoid an unknown function reference from globaldb on some build
191 ;;; hosts. It doesn't really matter what this function does: we don't
192 ;;; have FDEFN objects on the host anyway.
193 (defun fdefn-p (x) (declare (ignore x)) nil)
195 ;;; Needed for constant-folding
196 (defun system-area-pointer-p (x) x nil) ; nothing is a SAP
197 ;;; Needed for DEFINE-MOVE-FUN LOAD-SYSTEM-AREA-POINTER
198 (defun sap-int (x) (error "can't take SAP-INT ~S" x))
199 ;;; Needed for FIXUP-CODE-OBJECT
200 (defmacro without-gcing (&body body) `(progn ,@body))
202 (defun logically-readonlyize (x) x)
204 ;;; Mainly for the fasl loader
205 (defun %fun-name (f) (nth-value 2 (function-lambda-expression f)))
207 ;;;; Variables which have meaning only to the cross-compiler, defined here
208 ;;;; in lieu of #+sb-xc-host elsewere which messes up toplevel form numbers.
209 (in-package "SB!C")
211 ;;; Set of function names whose definition will never be seen in make-host-2,
212 ;;; as they are deferred until warm load.
213 ;;; The table is populated by compile-cold-sbcl, and not present in the target.
214 (defparameter *undefined-fun-whitelist* (make-hash-table :test 'equal))
216 ;;; The opposite of the whitelist - if certain full calls are seen, it is probably
217 ;;; the result of a missed transform and/or misconfiguration.
218 (defparameter *full-calls-to-warn-about*
219 '(;mask-signed-field ;; Too many to fix
222 ;;; Used by OPEN-FASL-OUTPUT
223 (defun string-to-octets (string &key external-format)
224 (assert (eq external-format :utf-8))
225 (let* ((n (length string))
226 (a (make-array n :element-type '(unsigned-byte 8))))
227 (dotimes (i n a)
228 (let ((code (sb!xc:char-code (char string i))))
229 (unless (<= 0 code 127)
230 (setf code (sb!xc:char-code #\?)))
231 (setf (aref a i) code)))))