Change syntax of DEFINE-FOP, and remove from target image.
[sbcl.git] / src / code / fop.lisp
blob719301d0a3c733c20d6a1f907811b08945cbbf5f
1 ;;;; FOP definitions
3 (in-package "SB!FASL")
5 ;;; Sometimes we want to skip over any FOPs with side-effects (like
6 ;;; function calls) while executing other FOPs. *SKIP-UNTIL* will
7 ;;; either contain the position where the skipping will stop, or
8 ;;; NIL if we're executing normally.
9 (defvar *skip-until* nil)
11 ;;; Bind STACK-VAR and PTR-VAR to the start of a subsequence of
12 ;;; the fop stack of length COUNT, then execute BODY.
13 ;;; Within the body, FOP-STACK-REF is used in lieu of SVREF
14 ;;; to elide bounds checking.
15 (defmacro with-fop-stack ((stack-var ptr-var count) &body body)
16 `(multiple-value-bind (,stack-var ,ptr-var)
17 (truly-the (values simple-vector index) (fop-stack-pop-n ,count))
18 (macrolet ((fop-stack-ref (i)
19 `(locally
20 #-sb-xc-host
21 (declare (optimize (sb!c::insert-array-bounds-checks 0)))
22 (svref ,',stack-var (truly-the index ,i)))))
23 ,@body)))
25 ;;; Define NAME as a fasl operation, with op-code FOP-CODE. PUSHP
26 ;;; describes what the body does to the fop stack:
27 ;;; T
28 ;;; The body might pop the fop stack. The result of the body is
29 ;;; pushed on the fop stack.
30 ;;; NIL
31 ;;; The body might pop the fop stack. The result of the body is
32 ;;; discarded.
33 ;;;
34 (defmacro !define-fop (fop-code (name &optional arglist (pushp t)) &body forms)
35 (aver (member pushp '(nil t)))
36 (binding* (((operands stack-args)
37 (if (consp (car arglist))
38 (ecase (caar arglist)
39 (:operands (values (cdar arglist) (cdr arglist))))
40 (values nil arglist)))
41 (guts (if pushp `((push-fop-stack (progn ,@forms))) forms)))
42 (assert (<= (length operands) 2))
43 `(progn
44 (defun ,name ,operands
45 ,@(if (null stack-args)
46 guts
47 (with-unique-names (stack ptr)
48 `((with-fop-stack (,stack ,ptr ,(length stack-args))
49 (multiple-value-bind ,stack-args
50 (values ,@(loop for i below (length stack-args)
51 collect `(fop-stack-ref (+ ,ptr ,i))))
52 ,@guts))))))
53 (!%define-fop ',name ,fop-code ,(length operands)))))
55 (defun !%define-fop (name code n-operands)
56 (declare (type (mod 3) n-operands)) ; 0, 1, or 2 are allowed
57 (let ((n-slots (expt 4 n-operands)))
58 (unless (zerop (mod code n-slots))
59 (error "Opcode for fop ~S must be a multiple of ~D" name n-slots))
60 (loop for opcode from code below (+ code n-slots)
61 when (functionp (svref *fop-funs* opcode))
62 do (let ((oname (svref *fop-names* opcode)))
63 (when (and oname (not (eq oname name)))
64 (error "fop ~S with opcode ~D conflicts with fop ~S."
65 name opcode oname))))
66 (let ((existing-opcode (get name 'opcode)))
67 (when (and existing-opcode (/= existing-opcode code))
68 (error "multiple codes for fop name ~S: ~D and ~D"
69 name code existing-opcode)))
70 (setf (get name 'opcode) code)
71 ;; The low 2 bits of the opcode comprise the length modifier if there is
72 ;; exactly one operand. Such opcodes are aligned in blocks of 4.
73 ;; 2-operand fops occupy 16 slots in a reserved range of the function table.
74 (loop for opcode from code below (+ code n-slots)
75 do (setf (svref *fop-names* opcode) name
76 (svref *fop-funs* opcode) (symbol-function name)
77 (sbit *fop-argp* (ash opcode -2)) (signum n-operands))))
78 name)
80 ;;; a helper function for reading string values from FASL files: sort
81 ;;; of like READ-SEQUENCE specialized for files of (UNSIGNED-BYTE 8),
82 ;;; with an automatic conversion from (UNSIGNED-BYTE 8) into CHARACTER
83 ;;; for each element read
84 (defun read-string-as-bytes (stream string &optional (length (length string)))
85 (declare (type (simple-array character (*)) string)
86 (type index length)
87 (optimize speed))
88 (with-fast-read-byte ((unsigned-byte 8) stream)
89 (dotimes (i length)
90 (setf (aref string i)
91 (sb!xc:code-char (fast-read-byte)))))
92 string)
93 (defun read-base-string-as-bytes (stream string &optional (length (length string)))
94 (declare (type (simple-array base-char (*)) string)
95 (type index length)
96 (optimize speed))
97 (with-fast-read-byte ((unsigned-byte 8) stream)
98 (dotimes (i length)
99 (setf (aref string i)
100 (sb!xc:code-char (fast-read-byte)))))
101 string)
102 #!+sb-unicode
103 (defun read-string-as-unsigned-byte-32
104 (stream string &optional (length (length string)))
105 (declare (type (simple-array character (*)) string)
106 (type index length)
107 (optimize speed))
108 #+sb-xc-host (bug "READ-STRING-AS-UNSIGNED-BYTE-32 called")
109 (with-fast-read-byte ((unsigned-byte 8) stream)
110 (dotimes (i length)
111 (setf (aref string i)
112 (sb!xc:code-char (fast-read-u-integer 4)))))
113 string)
115 ;;;; miscellaneous fops
117 ;;; Setting this variable causes execution of a FOP-NOP4 to produce
118 ;;; output to *DEBUG-IO*. This can be handy when trying to follow the
119 ;;; progress of FASL loading.
120 #!+sb-show
121 (defvar *show-fop-nop4-p* nil)
123 ;;; CMU CL had a single no-op fop, FOP-NOP, with fop code 0. Since 0
124 ;;; occurs disproportionately often in fasl files for other reasons,
125 ;;; FOP-NOP is less than ideal for writing human-readable patterns
126 ;;; into fasl files for debugging purposes. There's no shortage of
127 ;;; unused fop codes, so we add this second NOP, which reads 4
128 ;;; arbitrary bytes and discards them.
129 (!define-fop 137 (fop-nop4 () nil)
130 (let ((arg (read-arg 4)))
131 (declare (ignorable arg))
132 #!+sb-show
133 (when *show-fop-nop4-p*
134 (format *debug-io* "~&/FOP-NOP4 ARG=~W=#X~X~%" arg arg))))
136 (!define-fop 0 (fop-nop () nil))
137 (!define-fop 1 (fop-pop (x) nil) (push-fop-table x))
138 (!define-fop 2 (fop-empty-list) nil)
139 (!define-fop 3 (fop-truth) t)
140 (!define-fop 4 (fop-push ((:operands index))) (ref-fop-table index))
142 ;;; CMU CL had FOP-POP-FOR-EFFECT as fop 65, but it was never used and seemed
143 ;;; to have no possible use.
144 (!define-fop 66 (fop-misc-trap)
145 #+sb-xc-host ; since xc host doesn't know how to compile %PRIMITIVE
146 (error "FOP-MISC-TRAP can't be defined without %PRIMITIVE.")
147 #-sb-xc-host
148 (%primitive sb!c:make-unbound-marker))
150 (!define-fop 76 (fop-character ((:operands char-code)))
151 (code-char char-code))
153 (!define-fop 48 (fop-struct ((:operands size) layout))
154 (let* ((res (%make-instance size)) ; number of words excluding header
155 ;; Compute count of elements to pop from stack, sans layout.
156 ;; If instance-data-start is 0, then size is the count,
157 ;; otherwise subtract 1 because the layout consumes a slot.
158 (n-data-words (- size sb!vm:instance-data-start)))
159 (declare (type index size))
160 (with-fop-stack (stack ptr n-data-words)
161 (let ((ptr (+ ptr n-data-words)))
162 (declare (type index ptr))
163 (setf (%instance-layout res) layout)
164 #!-interleaved-raw-slots
165 (let* ((nuntagged (layout-n-untagged-slots layout))
166 (ntagged (- size nuntagged)))
167 (dotimes (n (1- ntagged))
168 (declare (type index n))
169 (setf (%instance-ref res (1+ n)) (fop-stack-ref (decf ptr))))
170 (dotimes (n nuntagged)
171 (declare (type index n))
172 (setf (%raw-instance-ref/word res (- nuntagged n 1))
173 (fop-stack-ref (decf ptr)))))
174 #!+interleaved-raw-slots
175 (let ((metadata (layout-untagged-bitmap layout)))
176 (do ((i sb!vm:instance-data-start (1+ i)))
177 ((>= i size))
178 (declare (type index i))
179 (let ((val (fop-stack-ref (decf ptr))))
180 (if (logbitp i metadata)
181 (setf (%raw-instance-ref/word res i) val)
182 (setf (%instance-ref res i) val)))))))
183 res))
185 (!define-fop 45 (fop-layout (name inherits depthoid length metadata))
186 (find-and-init-or-check-layout name length inherits depthoid metadata))
188 ;; Allocate a CLOS object. This is used when the compiler detects that
189 ;; MAKE-LOAD-FORM returned a simple use of MAKE-LOAD-FORM-SAVING-SLOTS,
190 ;; or possibly a hand-written equivalent (however unlikely).
191 (!define-fop 68 (fop-allocate-instance (name) nil)
192 (let ((instance (allocate-instance (find-class (the symbol name)))))
193 (push-fop-table instance)))
195 ;; Fill in object slots as dictated by the second return value from
196 ;; MAKE-LOAD-FORM-SAVING-SLOTS.
197 ;; This wants a 'count' as the first item in the SLOT-NAMES argument
198 ;; rather than using read-arg because many calls of this might share
199 ;; the list, which must be constructed into the fop-table no matter what.
200 (!define-fop 69 (fop-initialize-instance (slot-names obj) nil)
201 (let ((n-slots (pop slot-names)))
202 (multiple-value-bind (stack ptr) (fop-stack-pop-n n-slots)
203 (dotimes (i n-slots)
204 (let ((val (svref stack (+ ptr i)))
205 (slot-name (pop slot-names)))
206 (if (eq val 'sb!pcl::..slot-unbound..)
207 ;; SLOT-MAKUNBOUND-USING-CLASS might do something nonstandard.
208 (slot-makunbound obj slot-name)
209 ;; FIXME: the DEFSETF for this isn't defined until warm load
210 (sb!pcl::set-slot-value obj slot-name val)))))))
212 (!define-fop 64 (fop-end-group () nil)
213 (/show0 "THROWing FASL-GROUP-END")
214 (throw 'fasl-group-end t))
216 ;;; We used to have FOP-NORMAL-LOAD as 81 and FOP-MAYBE-COLD-LOAD as
217 ;;; 82 until GENESIS learned how to work with host symbols and
218 ;;; packages directly instead of piggybacking on the host code.
220 (!define-fop 62 (fop-verify-table-size () nil)
221 (let ((expected-index (read-word-arg)))
222 (unless (= (get-fop-table-index) expected-index)
223 (bug "fasl table of improper size"))))
224 (!define-fop 63 (fop-verify-empty-stack () nil)
225 (unless (fop-stack-empty-p)
226 (bug "fasl stack not empty when it should be")))
228 ;;;; fops for loading symbols
230 (defstruct (undefined-package
231 (:copier nil))
232 error)
234 (declaim (freeze-type undefined-package))
236 (defun aux-fop-intern (size package)
237 (declare (optimize speed))
238 (let ((buffer (make-string size)))
239 #+sb-xc-host
240 (read-string-as-bytes *fasl-input-stream* buffer size)
241 #-sb-xc-host
242 (progn
243 #!+sb-unicode
244 (read-string-as-unsigned-byte-32 *fasl-input-stream* buffer size)
245 #!-sb-unicode
246 (read-string-as-bytes *fasl-input-stream* buffer size))
247 (if (undefined-package-p package)
248 (error 'simple-package-error
249 :format-control "Error finding package for symbol ~s:~% ~a"
250 :format-arguments
251 (list (subseq buffer 0 size)
252 (undefined-package-error package)))
253 (push-fop-table (without-package-locks
254 (intern* buffer
255 size
256 package
257 :no-copy t))))))
259 (!define-fop 80 (fop-lisp-symbol-save ((:operands namelen)))
260 (aux-fop-intern namelen *cl-package*))
261 (!define-fop 84 (fop-keyword-symbol-save ((:operands namelen)))
262 (aux-fop-intern namelen *keyword-package*))
264 ;; But srsly? Most of the space is wasted by UCS4 encoding of ASCII.
265 ;; An extra word per symbol for the package is nothing by comparison.
266 ;; FIXME: Because we don't have FOP-SYMBOL-SAVE any more, an
267 ;; enormous number of symbols will fall through to this case,
268 ;; probably resulting in bloated fasl files. A new
269 ;; FOP-SYMBOL-IN-LAST-PACKAGE-SAVE/FOP-SMALL-SYMBOL-IN-LAST-PACKAGE-SAVE
270 ;; cloned fop pair could undo some of this bloat.
271 (!define-fop #xF0 (fop-symbol-in-package-save ((:operands pkg-index namelen)))
272 (aux-fop-intern namelen (ref-fop-table pkg-index)))
274 (!define-fop 96 (fop-uninterned-symbol-save ((:operands namelen)))
275 (let ((res (make-string namelen)))
276 #!-sb-unicode
277 (read-string-as-bytes *fasl-input-stream* res)
278 #!+sb-unicode
279 (read-string-as-unsigned-byte-32 *fasl-input-stream* res)
280 (push-fop-table (make-symbol res))))
282 (!define-fop 44 (fop-package (pkg-designator))
283 (find-undeleted-package-or-lose pkg-designator))
285 (!define-fop 156 (fop-named-package-save ((:operands length)) nil)
286 (let ((package-name (make-string length)))
287 #+sb-xc-host
288 (read-string-as-bytes *fasl-input-stream* package-name)
289 #-sb-xc-host
290 (progn
291 #!-sb-unicode
292 (read-string-as-bytes *fasl-input-stream* package-name)
293 #!+sb-unicode
294 (read-string-as-unsigned-byte-32 *fasl-input-stream* package-name))
295 (push-fop-table
296 (handler-case (find-undeleted-package-or-lose package-name)
297 (simple-package-error (c)
298 (make-undefined-package :error (princ-to-string c)))))))
300 ;;;; fops for loading numbers
302 ;;; Load a signed integer LENGTH bytes long from *FASL-INPUT-STREAM*.
303 (defun load-s-integer (length)
304 (declare (fixnum length)
305 (optimize speed))
306 (with-fast-read-byte ((unsigned-byte 8) *fasl-input-stream*)
307 (do* ((index length (1- index))
308 (byte 0 (fast-read-byte))
309 (result 0 (+ result (ash byte bits)))
310 (bits 0 (+ bits 8)))
311 ((= index 0)
312 (if (logbitp 7 byte) ; look at sign bit
313 (- result (ash 1 bits))
314 result))
315 (declare (fixnum index byte bits)))))
317 (!define-fop 36 (fop-integer ((:operands n-bytes)))
318 (load-s-integer n-bytes))
320 (!define-fop 34 (fop-word-integer)
321 (with-fast-read-byte ((unsigned-byte 8) *fasl-input-stream*)
322 (fast-read-s-integer #.sb!vm:n-word-bytes)))
324 (!define-fop 35 (fop-byte-integer)
325 (with-fast-read-byte ((unsigned-byte 8) *fasl-input-stream*)
326 (fast-read-s-integer 1)))
328 (!define-fop 70 (fop-ratio (num den)) (%make-ratio num den))
330 (!define-fop 71 (fop-complex (realpart imagpart))
331 (%make-complex realpart imagpart))
333 (macrolet ((fast-read-single-float ()
334 '(make-single-float (fast-read-s-integer 4)))
335 (fast-read-double-float ()
336 '(let ((lo (fast-read-u-integer 4)))
337 (make-double-float (fast-read-s-integer 4) lo))))
338 (macrolet ((define-complex-fop (opcode name type)
339 (let ((reader (symbolicate "FAST-READ-" type)))
340 `(!define-fop ,opcode (,name)
341 (with-fast-read-byte ((unsigned-byte 8) *fasl-input-stream*)
342 (complex (,reader) (,reader))))))
343 (define-float-fop (opcode name type)
344 (let ((reader (symbolicate "FAST-READ-" type)))
345 `(!define-fop ,opcode (,name)
346 (with-fast-read-byte ((unsigned-byte 8) *fasl-input-stream*)
347 (,reader))))))
348 (define-complex-fop 72 fop-complex-single-float single-float)
349 (define-complex-fop 73 fop-complex-double-float double-float)
350 #!+long-float
351 (define-complex-fop 67 fop-complex-long-float long-float)
352 (define-float-fop 46 fop-single-float single-float)
353 (define-float-fop 47 fop-double-float double-float)
354 #!+long-float
355 (define-float-fop 52 fop-long-float long-float)))
357 #!+sb-simd-pack
358 (!define-fop 88 (fop-simd-pack)
359 (with-fast-read-byte ((unsigned-byte 8) *fasl-input-stream*)
360 (%make-simd-pack (fast-read-s-integer 8)
361 (fast-read-u-integer 8)
362 (fast-read-u-integer 8))))
364 ;;;; loading lists
366 (defun fop-list-from-stack (n)
367 ;; N is 0-255 when called from FOP-LIST,
368 ;; but it is as large as ARRAY-RANK-LIMIT in FOP-ARRAY.
369 (declare (type (unsigned-byte 16) n)
370 (optimize (speed 3)))
371 (with-fop-stack (stack ptr n)
372 (do* ((i (+ ptr n) (1- i))
373 (res () (cons (fop-stack-ref i) res)))
374 ((= i ptr) res)
375 (declare (type index i)))))
377 (!define-fop 33 (fop-list) (fop-list-from-stack (read-byte-arg)))
378 (!define-fop 16 (fop-list*)
379 (let ((n (read-byte-arg))) ; N is the number of cons cells (0 is ok)
380 (with-fop-stack (stack ptr (1+ n))
381 (do* ((i (+ ptr n) (1- i))
382 (res (fop-stack-ref (+ ptr n))
383 (cons (fop-stack-ref i) res)))
384 ((= i ptr) res)
385 (declare (type index i))))))
387 (macrolet ((frob (name op fun n)
388 (let ((args (make-gensym-list n)))
389 `(!define-fop ,op (,name ,args) (,fun ,@args)))))
391 (frob fop-list-1 17 list 1)
392 (frob fop-list-2 18 list 2)
393 (frob fop-list-3 19 list 3)
394 (frob fop-list-4 20 list 4)
395 (frob fop-list-5 21 list 5)
396 (frob fop-list-6 22 list 6)
397 (frob fop-list-7 23 list 7)
398 (frob fop-list-8 24 list 8)
400 (frob fop-list*-1 25 list* 2)
401 (frob fop-list*-2 26 list* 3)
402 (frob fop-list*-3 27 list* 4)
403 (frob fop-list*-4 28 list* 5)
404 (frob fop-list*-5 29 list* 6)
405 (frob fop-list*-6 30 list* 7)
406 (frob fop-list*-7 31 list* 8)
407 (frob fop-list*-8 32 list* 9))
409 ;;;; fops for loading arrays
411 (!define-fop 100 (fop-base-string ((:operands length)))
412 (let ((res (make-string length :element-type 'base-char)))
413 (read-base-string-as-bytes *fasl-input-stream* res)
414 res))
416 #!+sb-unicode
417 ;; FIXME: can save space by UTF-8 encoding, or use 1 bit to indicate pure ASCII
418 ;; in the fasl even though the result will be a non-base string.
419 (progn
420 #+sb-xc-host
421 (!define-fop 160 (fop-character-string ((:operands length)))
422 (bug "CHARACTER-STRING FOP encountered"))
424 #-sb-xc-host
425 (!define-fop 160 (fop-character-string ((:operands length)))
426 (let ((res (make-string length)))
427 (read-string-as-unsigned-byte-32 *fasl-input-stream* res)
428 res)))
430 (!define-fop 92 (fop-vector ((:operands size)))
431 (let ((res (make-array size)))
432 (declare (fixnum size))
433 (unless (zerop size)
434 (multiple-value-bind (stack ptr) (fop-stack-pop-n size)
435 (replace res stack :start2 ptr)))
436 res))
438 (!define-fop 89 (fop-array (vec))
439 (let* ((rank (read-word-arg))
440 (length (length vec))
441 (res (make-array-header sb!vm:simple-array-widetag rank)))
442 (declare (simple-array vec)
443 (type (unsigned-byte #.(- sb!vm:n-word-bits sb!vm:n-widetag-bits)) rank))
444 (set-array-header res vec length nil 0 (fop-list-from-stack rank) nil t)
445 res))
447 (defglobal **saetp-bits-per-length**
448 (let ((array (make-array (1+ sb!vm:widetag-mask)
449 :element-type '(unsigned-byte 8)
450 :initial-element 255)))
451 (loop for saetp across sb!vm:*specialized-array-element-type-properties*
453 (setf (aref array (sb!vm:saetp-typecode saetp))
454 (sb!vm:saetp-n-bits saetp)))
455 array)
456 #!+sb-doc
457 "255 means bad entry.")
458 (declaim (type (simple-array (unsigned-byte 8) (#.(1+ sb!vm:widetag-mask)))
459 **saetp-bits-per-length**))
461 (!define-fop 43 (fop-spec-vector)
462 (let* ((length (read-word-arg))
463 (widetag (read-byte-arg))
464 (bits-per-length (aref **saetp-bits-per-length** widetag))
465 (bits (progn (aver (< bits-per-length 255))
466 (* length bits-per-length)))
467 (bytes (ceiling bits sb!vm:n-byte-bits))
468 (words (ceiling bytes sb!vm:n-word-bytes))
469 (vector (allocate-vector widetag length words)))
470 (declare (type index length bytes words)
471 (type word bits))
472 (read-n-bytes *fasl-input-stream* vector 0 bytes)
473 vector))
475 (!define-fop 53 (fop-eval (expr)) ; This seems to be unused
476 (if *skip-until*
477 expr
478 (eval expr)))
480 (!define-fop 54 (fop-eval-for-effect (expr) nil) ; This seems to be unused
481 (unless *skip-until*
482 (eval expr))
483 nil)
485 (defun fop-funcall* ()
486 (let ((argc (read-byte-arg)))
487 (with-fop-stack (stack ptr (1+ argc))
488 (unless *skip-until*
489 (do ((i (+ ptr argc))
490 (args))
491 ((= i ptr) (apply (fop-stack-ref i) args))
492 (declare (type index i))
493 (push (fop-stack-ref i) args)
494 (decf i))))))
496 (!define-fop 55 (fop-funcall) (fop-funcall*))
497 (!define-fop 56 (fop-funcall-for-effect () nil) (fop-funcall*))
499 ;;;; fops for fixing up circularities
501 (!define-fop 200 (fop-rplaca (val) nil)
502 (let ((obj (ref-fop-table (read-word-arg)))
503 (idx (read-word-arg)))
504 (setf (car (nthcdr idx obj)) val)))
506 (!define-fop 201 (fop-rplacd (val) nil)
507 (let ((obj (ref-fop-table (read-word-arg)))
508 (idx (read-word-arg)))
509 (setf (cdr (nthcdr idx obj)) val)))
511 (!define-fop 202 (fop-svset (val) nil)
512 (let* ((obi (read-word-arg))
513 (obj (ref-fop-table obi))
514 (idx (read-word-arg)))
515 (if (%instancep obj)
516 (setf (%instance-ref obj idx) val)
517 (setf (svref obj idx) val))))
519 (!define-fop 204 (fop-structset (val) nil)
520 (setf (%instance-ref (ref-fop-table (read-word-arg))
521 (read-word-arg))
522 val))
524 ;;; In the original CMUCL code, this actually explicitly declared PUSHP
525 ;;; to be T, even though that's what it defaults to in DEFINE-FOP.
526 (!define-fop 203 (fop-nthcdr (obj))
527 (nthcdr (read-word-arg) obj))
529 ;;;; fops for loading functions
531 ;;; (In CMU CL there was a FOP-CODE-FORMAT (47) which was
532 ;;; conventionally placed at the beginning of each fasl file to test
533 ;;; for compatibility between the fasl file and the CMU CL which
534 ;;; loaded it. In SBCL, this functionality has been replaced by
535 ;;; putting the implementation and version in required fields in the
536 ;;; fasl file header.)
538 (!define-fop #xE0 (fop-code ((:operands n-boxed-words n-unboxed-bytes)))
539 (load-code n-boxed-words n-unboxed-bytes))
541 ;; this gets you an #<fdefn> object, not the result of (FDEFINITION x)
542 (!define-fop 60 (fop-fdefn (name))
543 (find-or-create-fdefn name))
545 (!define-fop 65 (fop-known-fun (name))
546 (%coerce-name-to-fun name))
548 #!-(or x86 x86-64)
549 (!define-fop 61 (fop-sanctify-for-execution (component))
550 (sb!vm:sanctify-for-execution component)
551 component)
553 (!define-fop 74 (fop-fset (name fn) nil)
554 ;; Ordinary, not-for-cold-load code shouldn't need to mess with this
555 ;; at all, since it's only used as part of the conspiracy between
556 ;; the cross-compiler and GENESIS to statically link FDEFINITIONs
557 ;; for cold init.
558 (warn "~@<FOP-FSET seen in ordinary load (not cold load) -- quite strange! ~
559 If you didn't do something strange to cause this, please report it as a ~
560 bug.~:@>")
561 ;; Unlike CMU CL, we don't treat this as a no-op in ordinary code.
562 ;; If the user (or, more likely, developer) is trying to reload
563 ;; compiled-for-cold-load code into a warm SBCL, we'll do a warm
564 ;; assignment. (This is partly for abstract tidiness, since the warm
565 ;; assignment is the closest analogy to what happens at cold load,
566 ;; and partly because otherwise our compiled-for-cold-load code will
567 ;; fail, since in SBCL things like compiled-for-cold-load %DEFUN
568 ;; depend more strongly than in CMU CL on FOP-FSET actually doing
569 ;; something.)
570 (setf (fdefinition name) fn))
572 (!define-fop 174 (fop-note-debug-source (debug-source) nil)
573 (warn "~@<FOP-NOTE-DEBUG-SOURCE seen in ordinary load (not cold load) -- ~
574 very strange! If you didn't do something to cause this, please report it as ~
575 a bug.~@:>")
576 ;; as with COLD-FSET above, we are going to be lenient with coming
577 ;; across this fop in a warm SBCL.
578 (setf (sb!c::debug-source-compiled debug-source) (get-universal-time)
579 (sb!c::debug-source-created debug-source)
580 (file-write-date (sb!c::debug-source-namestring debug-source))))
582 ;;; Modify a slot in a CONSTANTS object.
583 (!define-fop 140 (fop-alter-code ((:operands index) code value) nil)
584 (setf (code-header-ref code index) value)
585 (values))
587 (!define-fop 139 (fop-fun-entry (code-object name arglist type info))
588 #+sb-xc-host ; since xc host doesn't know how to compile %PRIMITIVE
589 (error "FOP-FUN-ENTRY can't be defined without %PRIMITIVE.")
590 #-sb-xc-host
591 (let ((offset (read-word-arg)))
592 (declare (type index offset))
593 (unless (zerop (logand offset sb!vm:lowtag-mask))
594 (bug "unaligned function object, offset = #X~X" offset))
595 (let ((fun (%primitive sb!c:compute-fun code-object offset)))
596 (setf (%simple-fun-self fun) fun)
597 (setf (%simple-fun-next fun) (%code-entry-points code-object))
598 (setf (%code-entry-points code-object) fun)
599 (setf (%simple-fun-name fun) name)
600 (setf (%simple-fun-arglist fun) arglist)
601 (setf (%simple-fun-type fun) type)
602 (setf (%simple-fun-info fun) info)
603 fun)))
605 ;;;; Some Dylan FOPs used to live here. By 1 November 1998 the code
606 ;;;; was sufficiently stale that the functions it called were no
607 ;;;; longer defined, so I (William Harold Newman) deleted it.
608 ;;;;
609 ;;;; In case someone in the future is trying to make sense of FOP layout,
610 ;;;; it might be worth recording that the Dylan FOPs were
611 ;;;; 100 FOP-DYLAN-SYMBOL-SAVE
612 ;;;; 101 FOP-SMALL-DYLAN-SYMBOL-SAVE
613 ;;;; 102 FOP-DYLAN-KEYWORD-SAVE
614 ;;;; 103 FOP-SMALL-DYLAN-KEYWORD-SAVE
615 ;;;; 104 FOP-DYLAN-VARINFO-VALUE
617 ;;;; assemblerish fops
619 (!define-fop 144 (fop-assembler-code)
620 (error "cannot load assembler code except at cold load"))
622 (!define-fop 145 (fop-assembler-routine)
623 (error "cannot load assembler code except at cold load"))
625 (!define-fop 146 (fop-symbol-tls-fixup (code-object kind symbol))
626 (sb!vm:fixup-code-object code-object
627 (read-word-arg)
628 (ensure-symbol-tls-index symbol)
629 kind)
630 code-object)
632 (!define-fop 147 (fop-foreign-fixup (code-object kind))
633 (let* ((len (read-byte-arg))
634 (sym (make-string len :element-type 'base-char)))
635 (read-n-bytes *fasl-input-stream* sym 0 len)
636 (sb!vm:fixup-code-object code-object
637 (read-word-arg)
638 (foreign-symbol-address sym)
639 kind)
640 code-object))
642 (!define-fop 148 (fop-assembler-fixup (code-object kind routine))
643 (multiple-value-bind (value found) (gethash routine *assembler-routines*)
644 (unless found
645 (error "undefined assembler routine: ~S" routine))
646 (sb!vm:fixup-code-object code-object (read-word-arg) value kind))
647 code-object)
649 (!define-fop 149 (fop-code-object-fixup (code-object kind))
650 ;; Note: We don't have to worry about GC moving the code-object after
651 ;; the GET-LISP-OBJ-ADDRESS and before that value is deposited, because
652 ;; we can only use code-object fixups when code-objects don't move.
653 (sb!vm:fixup-code-object code-object (read-word-arg)
654 (get-lisp-obj-address code-object) kind)
655 code-object)
657 #!+linkage-table
658 (!define-fop 150 (fop-foreign-dataref-fixup (code-object kind))
659 (let* ((len (read-byte-arg))
660 (sym (make-string len :element-type 'base-char)))
661 (read-n-bytes *fasl-input-stream* sym 0 len)
662 (sb!vm:fixup-code-object code-object
663 (read-word-arg)
664 (foreign-symbol-address sym t)
665 kind)
666 code-object))
668 ;;; FOPs needed for implementing an IF operator in a FASL
670 ;;; Skip until a FOP-MAYBE-STOP-SKIPPING with the same POSITION is
671 ;;; executed. While skipping, we execute most FOPs normally, except
672 ;;; for ones that a) funcall/eval b) start skipping. This needs to
673 ;;; be done to ensure that the fop table gets populated correctly
674 ;;; regardless of the execution path.
675 (!define-fop 151 (fop-skip (position) nil)
676 (unless *skip-until*
677 (setf *skip-until* position))
678 (values))
680 ;;; As before, but only start skipping if the top of the FOP stack is NIL.
681 (!define-fop 152 (fop-skip-if-false (position condition) nil)
682 (unless (or condition *skip-until*)
683 (setf *skip-until* position))
684 (values))
686 ;;; If skipping, pop the top of the stack and discard it. Needed for
687 ;;; ensuring that the stack stays balanced when skipping.
688 (!define-fop 153 (fop-drop-if-skipping () nil)
689 (when *skip-until*
690 (fop-stack-pop-n 1))
691 (values))
693 ;;; If skipping, push a dummy value on the stack. Needed for
694 ;;; ensuring that the stack stays balanced when skipping.
695 (!define-fop 154 (fop-push-nil-if-skipping () nil)
696 (when *skip-until*
697 (push-fop-stack nil))
698 (values))
700 ;;; Stop skipping if the top of the stack matches *SKIP-UNTIL*
701 (!define-fop 155 (fop-maybe-stop-skipping (label) nil)
702 (when (eql *skip-until* label)
703 (setf *skip-until* nil))
704 (values))