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 ;;; Define NAME as a fasl operation, with op-code FOP-CODE. PUSHP
12 ;;; describes what the body does to the fop stack:
14 ;;; The body might pop the fop stack. The result of the body is
15 ;;; pushed on the fop stack.
17 ;;; The body might pop the fop stack. The result of the body is
19 ;;; STACKP describes whether or not the body interacts with the fop stack.
20 (defmacro define-fop ((name fop-code &key (pushp t) (stackp t)) &rest forms)
24 `(with-fop-stack ,pushp ,@forms)
26 (%define-fop ',name ,fop-code)))
28 (defun %define-fop (name code)
29 (let ((oname (svref *fop-names* code)))
30 (when (and oname (not (eq oname name)))
31 (error "multiple names for fop code ~D: ~S and ~S" code name oname)))
32 ;; KLUDGE: It's mnemonically suboptimal to use 'FOP-CODE as the name of the
33 ;; tag which associates names with codes when it's also used as one of
34 ;; the names. Perhaps the fops named FOP-CODE and FOP-SMALL-CODE could
35 ;; be renamed to something more mnemonic? -- WHN 19990902
36 (let ((ocode (get name 'fop-code)))
37 (when (and ocode (/= ocode code))
38 (error "multiple codes for fop name ~S: ~D and ~D" name code ocode)))
39 (setf (svref *fop-names* code) name
40 (get name 'fop-code) code
41 (svref *fop-funs* code) (symbol-function name))
44 ;;; Define a pair of fops which are identical except that one reads
45 ;;; a four-byte argument while the other reads a one-byte argument. The
46 ;;; argument can be accessed by using the CLONE-ARG macro.
48 ;;; KLUDGE: It would be nice if the definition here encapsulated which
49 ;;; value ranges went with which fop variant, and chose the correct
50 ;;; fop code to use. Currently, since such logic isn't encapsulated,
51 ;;; we see callers doing stuff like
52 ;;; (cond ((and (< num-consts #x100) (< total-length #x10000))
53 ;;; (dump-fop 'sb!impl::fop-small-code file)
54 ;;; (dump-byte num-consts file)
55 ;;; (dump-integer-as-n-bytes total-length 2 file))
57 ;;; (dump-fop 'sb!impl::fop-code file)
58 ;;; (dump-word num-consts file)
59 ;;; (dump-word total-length file))))
60 ;;; in several places. It would be cleaner if this could be replaced with
62 ;;; (dump-fop file fop-code num-consts total-length)
63 ;;; Some of this logic is already in DUMP-FOP*, but that still requires the
64 ;;; caller to know that it's a 1-byte-arg/4-byte-arg cloned fop pair, and to
65 ;;; know both the 1-byte-arg and the 4-byte-arg fop names. -- WHN 19990902
66 (defmacro define-cloned-fops ((name code &key (pushp t) (stackp t))
67 (small-name small-code) &rest forms)
68 (aver (member pushp '(nil t)))
69 (aver (member stackp '(nil t)))
71 (macrolet ((clone-arg () '(read-word-arg)))
72 (define-fop (,name ,code :pushp ,pushp :stackp ,stackp) ,@forms))
73 (macrolet ((clone-arg () '(read-byte-arg)))
74 (define-fop (,small-name ,small-code :pushp ,pushp :stackp ,stackp) ,@forms))))
76 ;;; a helper function for reading string values from FASL files: sort
77 ;;; of like READ-SEQUENCE specialized for files of (UNSIGNED-BYTE 8),
78 ;;; with an automatic conversion from (UNSIGNED-BYTE 8) into CHARACTER
79 ;;; for each element read
80 (declaim (ftype (function (stream simple-string &optional index) (values))
82 #!+sb-unicode read-string-as-unsigned-byte-32))
83 (defun read-string-as-bytes (stream string &optional (length (length string)))
86 (sb!xc:code-char (read-byte stream))))
87 ;; FIXME: The classic CMU CL code to do this was
88 ;; (READ-N-BYTES FILE STRING START END).
89 ;; It was changed for SBCL because we needed a portable version for
90 ;; bootstrapping. Benchmark the non-portable version and see whether it's
91 ;; significantly better than the portable version here. If it is, then use
92 ;; it as an alternate definition, protected with #-SB-XC-HOST.
95 (defun read-string-as-unsigned-byte-32
96 (stream string &optional (length (length string)))
97 #+sb-xc-host (bug "READ-STRING-AS-UNSIGNED-BYTE-32 called")
101 (dotimes (k 4 (sb!xc:code-char code))
102 (setf code (logior code (ash (read-byte stream)
103 (* k sb!vm:n-byte-bits))))))))
106 ;;;; miscellaneous fops
108 ;;; FIXME: POP-STACK should be called something more mnemonic. (POP-FOP-STACK?
109 ;;; But that would conflict with PUSH-FOP-TABLE. Something, anyway..)
111 ;;; Setting this variable causes execution of a FOP-NOP4 to produce
112 ;;; output to *DEBUG-IO*. This can be handy when trying to follow the
113 ;;; progress of FASL loading.
115 (defvar *show-fop-nop4-p* nil)
117 ;;; CMU CL had a single no-op fop, FOP-NOP, with fop code 0. Since 0
118 ;;; occurs disproportionately often in fasl files for other reasons,
119 ;;; FOP-NOP is less than ideal for writing human-readable patterns
120 ;;; into fasl files for debugging purposes. There's no shortage of
121 ;;; unused fop codes, so we add this second NOP, which reads 4
122 ;;; arbitrary bytes and discards them.
123 (define-fop (fop-nop4 137 :stackp nil)
124 (let ((arg (read-arg 4)))
125 (declare (ignorable arg))
127 (when *show-fop-nop4-p*
128 (format *debug-io* "~&/FOP-NOP4 ARG=~W=#X~X~%" arg arg))))
130 (define-fop (fop-nop 0 :stackp nil))
131 (define-fop (fop-pop 1 :pushp nil) (push-fop-table (pop-stack)))
132 (define-fop (fop-push 2) (svref *current-fop-table* (read-word-arg)))
133 (define-fop (fop-byte-push 3) (svref *current-fop-table* (read-byte-arg)))
135 (define-fop (fop-empty-list 4) ())
136 (define-fop (fop-truth 5) t)
137 ;;; CMU CL had FOP-POP-FOR-EFFECT as fop 65, but it was never used and seemed
138 ;;; to have no possible use.
139 (define-fop (fop-misc-trap 66)
140 #+sb-xc-host ; since xc host doesn't know how to compile %PRIMITIVE
141 (error "FOP-MISC-TRAP can't be defined without %PRIMITIVE.")
143 (%primitive sb!c:make-other-immediate-type 0 sb!vm:unbound-marker-widetag))
145 (define-cloned-fops (fop-character 68) (fop-short-character 69)
146 (code-char (clone-arg)))
148 (define-cloned-fops (fop-struct 48) (fop-small-struct 49)
149 (let* ((size (clone-arg))
150 (res (%make-instance size)))
151 (declare (type index size))
152 (let* ((layout (pop-stack))
153 (nuntagged (layout-n-untagged-slots layout))
154 (ntagged (- size nuntagged)))
155 (setf (%instance-ref res 0) layout)
156 (dotimes (n (1- ntagged))
157 (declare (type index n))
158 (setf (%instance-ref res (1+ n)) (pop-stack)))
159 (dotimes (n nuntagged)
160 (declare (type index n))
161 (setf (%raw-instance-ref/word res (- nuntagged n 1)) (pop-stack))))
164 (define-fop (fop-layout 45)
165 (let ((nuntagged (pop-stack))
167 (depthoid (pop-stack))
168 (inherits (pop-stack))
170 (find-and-init-or-check-layout name length inherits depthoid nuntagged)))
172 (define-fop (fop-end-group 64 :stackp nil)
173 (/show0 "THROWing FASL-GROUP-END")
174 (throw 'fasl-group-end t))
176 ;;; In the normal loader, we just ignore these. GENESIS overwrites
177 ;;; FOP-MAYBE-COLD-LOAD with something that knows whether to revert to
178 ;;; cold-loading or not.
179 (define-fop (fop-normal-load 81 :stackp nil))
180 (define-fop (fop-maybe-cold-load 82 :stackp nil))
182 (define-fop (fop-verify-table-size 62 :stackp nil)
183 (let ((expected-index (read-word-arg)))
184 (unless (= *current-fop-table-index* expected-index)
185 (bug "fasl table of improper size"))))
186 (define-fop (fop-verify-empty-stack 63 :stackp nil)
187 (unless (zerop (length *fop-stack*))
188 (bug "fasl stack not empty when it should be")))
190 ;;;; fops for loading symbols
192 (macrolet (;; FIXME: Should all this code really be duplicated inside
193 ;; each fop? Perhaps it would be better for this shared
194 ;; code to live in FLET FROB1 and FLET FROB4 (for the
195 ;; two different sizes of counts).
196 (frob (name code name-size package)
197 (let ((n-package (gensym))
200 `(define-fop (,name ,code)
201 (prepare-for-fast-read-byte *fasl-input-stream*
202 (let ((,n-package ,package)
203 (,n-size (fast-read-u-integer ,name-size)))
204 (when (> ,n-size (length *fasl-symbol-buffer*))
205 (setq *fasl-symbol-buffer*
206 (make-string (* ,n-size 2))))
207 (done-with-fast-read-byte)
208 (let ((,n-buffer *fasl-symbol-buffer*))
210 (read-string-as-bytes *fasl-input-stream*
214 (#!+sb-unicode read-string-as-unsigned-byte-32
215 #!-sb-unicode read-string-as-bytes
219 (push-fop-table (without-package-locks
224 ;; Note: CMU CL had FOP-SYMBOL-SAVE and FOP-SMALL-SYMBOL-SAVE, but
225 ;; since they made the behavior of the fasloader depend on the
226 ;; *PACKAGE* variable, not only were they a pain to support (because
227 ;; they required various hacks to handle *PACKAGE*-manipulation
228 ;; forms) they were basically broken by design, because ANSI gives
229 ;; the user so much flexibility in manipulating *PACKAGE* at
230 ;; load-time that no reasonable hacks could possibly make things
231 ;; work right. The ones used in CMU CL certainly didn't, as shown by
233 ;; (IN-PACKAGE :CL-USER)
234 ;; (DEFVAR CL::*FOO* 'FOO-VALUE)
235 ;; (EVAL-WHEN (:COMPILE-TOPLEVEL :LOAD-TOPLEVEL :EXECUTE)
236 ;; (SETF *PACKAGE* (FIND-PACKAGE :CL)))
237 ;; which in CMU CL 2.4.9 defines a variable CL-USER::*FOO* instead of
238 ;; defining CL::*FOO*. Therefore, we don't use those fops in SBCL.
239 ;;(frob fop-symbol-save 6 4 *package*)
240 ;;(frob fop-small-symbol-save 7 1 *package*)
242 (frob fop-lisp-symbol-save 75 #.sb!vm:n-word-bytes *cl-package*)
243 (frob fop-lisp-small-symbol-save 76 1 *cl-package*)
244 (frob fop-keyword-symbol-save 77 #.sb!vm:n-word-bytes *keyword-package*)
245 (frob fop-keyword-small-symbol-save 78 1 *keyword-package*)
247 ;; FIXME: Because we don't have FOP-SYMBOL-SAVE any more, an enormous number
248 ;; of symbols will fall through to this case, probably resulting in bloated
250 ;; FOP-SYMBOL-IN-LAST-PACKAGE-SAVE/FOP-SMALL-SYMBOL-IN-LAST-PACKAGE-SAVE
251 ;; cloned fop pair could undo some of this bloat.
252 (frob fop-symbol-in-package-save 8 #.sb!vm:n-word-bytes
253 (svref *current-fop-table* (fast-read-u-integer #.sb!vm:n-word-bytes)))
254 (frob fop-small-symbol-in-package-save 9 1
255 (svref *current-fop-table* (fast-read-u-integer #.sb!vm:n-word-bytes)))
256 (frob fop-symbol-in-byte-package-save 10 #.sb!vm:n-word-bytes
257 (svref *current-fop-table* (fast-read-u-integer 1)))
258 (frob fop-small-symbol-in-byte-package-save 11 1
259 (svref *current-fop-table* (fast-read-u-integer 1))))
261 (define-cloned-fops (fop-uninterned-symbol-save 12)
262 (fop-uninterned-small-symbol-save 13)
263 (let* ((arg (clone-arg))
264 (res (make-string arg)))
266 (read-string-as-bytes *fasl-input-stream* res)
268 (read-string-as-unsigned-byte-32 *fasl-input-stream* res)
269 (push-fop-table (make-symbol res))))
271 (define-fop (fop-package 14)
272 (find-undeleted-package-or-lose (pop-stack)))
274 ;;;; fops for loading numbers
276 ;;; Load a signed integer LENGTH bytes long from *FASL-INPUT-STREAM*.
277 (defun load-s-integer (length)
278 (declare (fixnum length))
279 ;; #+cmu (declare (optimize (inhibit-warnings 2)))
280 (do* ((index length (1- index))
281 (byte 0 (read-byte *fasl-input-stream*))
282 (result 0 (+ result (ash byte bits)))
285 (if (logbitp 7 byte) ; look at sign bit
286 (- result (ash 1 bits))
288 (declare (fixnum index byte bits))))
290 (define-cloned-fops (fop-integer 33) (fop-small-integer 34)
291 (load-s-integer (clone-arg)))
293 (define-fop (fop-word-integer 35)
294 (prepare-for-fast-read-byte *fasl-input-stream*
296 (fast-read-s-integer #.sb!vm:n-word-bytes)
297 (done-with-fast-read-byte))))
299 (define-fop (fop-byte-integer 36)
300 (prepare-for-fast-read-byte *fasl-input-stream*
302 (fast-read-s-integer 1)
303 (done-with-fast-read-byte))))
305 (define-fop (fop-ratio 70)
306 (let ((den (pop-stack)))
307 (%make-ratio (pop-stack) den)))
309 (define-fop (fop-complex 71)
310 (let ((im (pop-stack)))
311 (%make-complex (pop-stack) im)))
313 (macrolet ((fast-read-single-float ()
314 '(make-single-float (fast-read-s-integer 4)))
315 (fast-read-double-float ()
316 '(let ((lo (fast-read-u-integer 4)))
317 (make-double-float (fast-read-s-integer 4) lo))))
318 (macrolet ((define-complex-fop (name fop-code type)
319 (let ((reader (symbolicate "FAST-READ-" type)))
320 `(define-fop (,name ,fop-code)
321 (prepare-for-fast-read-byte *fasl-input-stream*
323 (complex (,reader) (,reader))
324 (done-with-fast-read-byte))))))
325 (define-float-fop (name fop-code type)
326 (let ((reader (symbolicate "FAST-READ-" type)))
327 `(define-fop (,name ,fop-code)
328 (prepare-for-fast-read-byte *fasl-input-stream*
331 (done-with-fast-read-byte)))))))
332 (define-complex-fop fop-complex-single-float 72 single-float)
333 (define-complex-fop fop-complex-double-float 73 double-float)
335 (define-complex-fop fop-complex-long-float 67 long-float)
336 (define-float-fop fop-single-float 46 single-float)
337 (define-float-fop fop-double-float 47 double-float)
339 (define-float-fop fop-long-float 52 long-float)))
344 (define-fop (fop-list 15)
345 (do ((res () (cons (pop-stack) res))
346 (n (read-byte-arg) (1- n)))
348 (declare (type index n))))
350 (define-fop (fop-list* 16)
351 (do ((res (pop-stack) (cons (pop-stack) res))
352 (n (read-byte-arg) (1- n)))
354 (declare (type index n))))
356 (macrolet ((frob (name op fun n)
357 `(define-fop (,name ,op)
358 (call-with-popped-args ,fun ,n))))
360 (frob fop-list-1 17 list 1)
361 (frob fop-list-2 18 list 2)
362 (frob fop-list-3 19 list 3)
363 (frob fop-list-4 20 list 4)
364 (frob fop-list-5 21 list 5)
365 (frob fop-list-6 22 list 6)
366 (frob fop-list-7 23 list 7)
367 (frob fop-list-8 24 list 8)
369 (frob fop-list*-1 25 list* 2)
370 (frob fop-list*-2 26 list* 3)
371 (frob fop-list*-3 27 list* 4)
372 (frob fop-list*-4 28 list* 5)
373 (frob fop-list*-5 29 list* 6)
374 (frob fop-list*-6 30 list* 7)
375 (frob fop-list*-7 31 list* 8)
376 (frob fop-list*-8 32 list* 9))
378 ;;;; fops for loading arrays
380 (define-cloned-fops (fop-base-string 37) (fop-small-base-string 38)
381 (let* ((arg (clone-arg))
382 (res (make-string arg :element-type 'base-char)))
383 (read-string-as-bytes *fasl-input-stream* res)
389 (define-cloned-fops (fop-character-string 161) (fop-small-character-string 162)
390 (bug "CHARACTER-STRING FOP encountered"))
393 (define-cloned-fops (fop-character-string 161) (fop-small-character-string 162)
394 (let* ((arg (clone-arg))
395 (res (make-string arg)))
396 (read-string-as-unsigned-byte-32 *fasl-input-stream* res)
399 (define-cloned-fops (fop-vector 39) (fop-small-vector 40)
400 (let* ((size (clone-arg))
401 (res (make-array size)))
402 (declare (fixnum size))
403 (do ((n (1- size) (1- n)))
405 (setf (svref res n) (pop-stack)))
408 (define-fop (fop-array 83)
409 (let* ((rank (read-word-arg))
411 (length (length vec))
412 (res (make-array-header sb!vm:simple-array-widetag rank)))
413 (declare (simple-array vec)
414 (type (unsigned-byte #.(- sb!vm:n-word-bits sb!vm:n-widetag-bits)) rank))
415 (set-array-header res vec length nil 0
417 (dimensions () (cons (pop-stack) dimensions)))
418 ((zerop i) dimensions)
419 (declare (type index i)))
423 (define-fop (fop-single-float-vector 84)
424 (let* ((length (read-word-arg))
425 (result (make-array length :element-type 'single-float)))
426 (read-n-bytes *fasl-input-stream* result 0 (* length 4))
429 (define-fop (fop-double-float-vector 85)
430 (let* ((length (read-word-arg))
431 (result (make-array length :element-type 'double-float)))
432 (read-n-bytes *fasl-input-stream* result 0 (* length 8))
435 (define-fop (fop-complex-single-float-vector 86)
436 (let* ((length (read-word-arg))
437 (result (make-array length :element-type '(complex single-float))))
438 (read-n-bytes *fasl-input-stream* result 0 (* length 8))
441 (define-fop (fop-complex-double-float-vector 87)
442 (let* ((length (read-word-arg))
443 (result (make-array length :element-type '(complex double-float))))
444 (read-n-bytes *fasl-input-stream* result 0 (* length 16))
448 ;;; *** NOT *** the FOP-INT-VECTOR as currently documented in rtguts.
449 ;;; Size must be a directly supported I-vector element size, with no
450 ;;; extra bits. This must be packed according to the local
451 ;;; byte-ordering, allowing us to directly read the bits.
452 (define-fop (fop-int-vector 43)
453 (prepare-for-fast-read-byte *fasl-input-stream*
454 (let* ((len (fast-read-u-integer #.sb!vm:n-word-bytes))
455 (size (fast-read-byte))
457 (0 (make-array len :element-type 'nil))
458 (1 (make-array len :element-type 'bit))
459 (2 (make-array len :element-type '(unsigned-byte 2)))
460 (4 (make-array len :element-type '(unsigned-byte 4)))
461 (7 (prog1 (make-array len :element-type '(unsigned-byte 7))
463 (8 (make-array len :element-type '(unsigned-byte 8)))
464 (15 (prog1 (make-array len :element-type '(unsigned-byte 15))
466 (16 (make-array len :element-type '(unsigned-byte 16)))
467 (31 (prog1 (make-array len :element-type '(unsigned-byte 31))
469 (32 (make-array len :element-type '(unsigned-byte 32)))
470 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
471 (63 (prog1 (make-array len :element-type '(unsigned-byte 63))
473 (64 (make-array len :element-type '(unsigned-byte 64)))
474 (t (bug "losing i-vector element size: ~S" size)))))
475 (declare (type index len))
476 (done-with-fast-read-byte)
477 (read-n-bytes *fasl-input-stream*
480 (ceiling (the index (* size len)) sb!vm:n-byte-bits))
483 ;;; This is the same as FOP-INT-VECTOR, except this is for signed
485 (define-fop (fop-signed-int-vector 50)
486 (prepare-for-fast-read-byte *fasl-input-stream*
487 (let* ((len (fast-read-u-integer #.sb!vm:n-word-bytes))
488 (size (fast-read-byte))
490 (8 (make-array len :element-type '(signed-byte 8)))
491 (16 (make-array len :element-type '(signed-byte 16)))
492 #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
493 (29 (prog1 (make-array len :element-type '(unsigned-byte 29))
495 #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
496 (30 (prog1 (make-array len :element-type '(signed-byte 30))
498 (32 (make-array len :element-type '(signed-byte 32)))
499 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
500 (60 (prog1 (make-array len :element-type '(unsigned-byte 60))
502 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
503 (61 (prog1 (make-array len :element-type '(signed-byte 61))
505 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
506 (64 (make-array len :element-type '(signed-byte 64)))
507 (t (bug "losing si-vector element size: ~S" size)))))
508 (declare (type index len))
509 (done-with-fast-read-byte)
510 (read-n-bytes *fasl-input-stream*
513 (ceiling (the index (* size len)) sb!vm:n-byte-bits))
516 (define-fop (fop-eval 53)
519 (let ((result (eval (pop-stack))))
520 ;; FIXME: CMU CL had this code here:
521 ;; (when *load-print*
525 ;; Unfortunately, this dependence on the *LOAD-PRINT* global
526 ;; variable is non-ANSI, so for now we've just punted printing in
530 (define-fop (fop-eval-for-effect 54 :pushp nil)
533 (let ((result (eval (pop-stack))))
534 ;; FIXME: See the comment about *LOAD-PRINT* in FOP-EVAL.
535 (declare (ignore result))
536 #+nil (when *load-print*
541 (define-fop (fop-funcall 55)
542 (let ((arg (read-byte-arg)))
544 (dotimes (i (1+ arg))
547 (funcall (pop-stack))
548 (do ((args () (cons (pop-stack) args))
550 ((zerop n) (apply (pop-stack) args))
551 (declare (type index n)))))))
553 (define-fop (fop-funcall-for-effect 56 :pushp nil)
554 (let ((arg (read-byte-arg)))
556 (dotimes (i (1+ arg))
559 (funcall (pop-stack))
560 (do ((args () (cons (pop-stack) args))
562 ((zerop n) (apply (pop-stack) args))
563 (declare (type index n)))))))
565 ;;;; fops for fixing up circularities
567 (define-fop (fop-rplaca 200 :pushp nil)
568 (let ((obj (svref *current-fop-table* (read-word-arg)))
569 (idx (read-word-arg))
571 (setf (car (nthcdr idx obj)) val)))
573 (define-fop (fop-rplacd 201 :pushp nil)
574 (let ((obj (svref *current-fop-table* (read-word-arg)))
575 (idx (read-word-arg))
577 (setf (cdr (nthcdr idx obj)) val)))
579 (define-fop (fop-svset 202 :pushp nil)
580 (let* ((obi (read-word-arg))
581 (obj (svref *current-fop-table* obi))
582 (idx (read-word-arg))
585 (setf (%instance-ref obj idx) val)
586 (setf (svref obj idx) val))))
588 (define-fop (fop-structset 204 :pushp nil)
589 (setf (%instance-ref (svref *current-fop-table* (read-word-arg))
593 ;;; In the original CMUCL code, this actually explicitly declared PUSHP
594 ;;; to be T, even though that's what it defaults to in DEFINE-FOP.
595 (define-fop (fop-nthcdr 203)
596 (nthcdr (read-word-arg) (pop-stack)))
598 ;;;; fops for loading functions
600 ;;; (In CMU CL there was a FOP-CODE-FORMAT (47) which was
601 ;;; conventionally placed at the beginning of each fasl file to test
602 ;;; for compatibility between the fasl file and the CMU CL which
603 ;;; loaded it. In SBCL, this functionality has been replaced by
604 ;;; putting the implementation and version in required fields in the
605 ;;; fasl file header.)
607 (define-fop (fop-code 58 :stackp nil)
608 (load-code (read-word-arg) (read-word-arg)))
610 (define-fop (fop-small-code 59 :stackp nil)
611 (load-code (read-byte-arg) (read-halfword-arg)))
613 (define-fop (fop-fdefinition 60)
614 (fdefinition-object (pop-stack) t))
616 (define-fop (fop-sanctify-for-execution 61)
617 (let ((component (pop-stack)))
618 (sb!vm:sanctify-for-execution component)
621 (define-fop (fop-fset 74 :pushp nil)
622 ;; Ordinary, not-for-cold-load code shouldn't need to mess with this
623 ;; at all, since it's only used as part of the conspiracy between
624 ;; the cross-compiler and GENESIS to statically link FDEFINITIONs
626 (warn "~@<FOP-FSET seen in ordinary load (not cold load) -- quite strange! ~
627 If you didn't do something strange to cause this, please report it as a ~
629 ;; Unlike CMU CL, we don't treat this as a no-op in ordinary code.
630 ;; If the user (or, more likely, developer) is trying to reload
631 ;; compiled-for-cold-load code into a warm SBCL, we'll do a warm
632 ;; assignment. (This is partly for abstract tidiness, since the warm
633 ;; assignment is the closest analogy to what happens at cold load,
634 ;; and partly because otherwise our compiled-for-cold-load code will
635 ;; fail, since in SBCL things like compiled-for-cold-load %DEFUN
636 ;; depend more strongly than in CMU CL on FOP-FSET actually doing
638 (let ((fn (pop-stack))
640 (setf (fdefinition name) fn)))
642 ;;; Modify a slot in a CONSTANTS object.
643 (define-cloned-fops (fop-alter-code 140 :pushp nil) (fop-byte-alter-code 141)
644 (let ((value (pop-stack))
646 (setf (code-header-ref code (clone-arg)) value)
649 (define-fop (fop-fun-entry 142)
650 #+sb-xc-host ; since xc host doesn't know how to compile %PRIMITIVE
651 (error "FOP-FUN-ENTRY can't be defined without %PRIMITIVE.")
653 (let ((xrefs (pop-stack))
655 (arglist (pop-stack))
657 (code-object (pop-stack))
658 (offset (read-word-arg)))
659 (declare (type index offset))
660 (unless (zerop (logand offset sb!vm:lowtag-mask))
661 (bug "unaligned function object, offset = #X~X" offset))
662 (let ((fun (%primitive sb!c:compute-fun code-object offset)))
663 (setf (%simple-fun-self fun) fun)
664 (setf (%simple-fun-next fun) (%code-entry-points code-object))
665 (setf (%code-entry-points code-object) fun)
666 (setf (%simple-fun-name fun) name)
667 (setf (%simple-fun-arglist fun) arglist)
668 (setf (%simple-fun-type fun) type)
669 (setf (%simple-fun-xrefs fun) xrefs)
670 ;; FIXME: See the comment about *LOAD-PRINT* in FOP-EVAL.
671 #+nil (when *load-print*
673 (format t "~S defined~%" fun))
676 ;;;; Some Dylan FOPs used to live here. By 1 November 1998 the code
677 ;;;; was sufficiently stale that the functions it called were no
678 ;;;; longer defined, so I (William Harold Newman) deleted it.
680 ;;;; In case someone in the future is trying to make sense of FOP layout,
681 ;;;; it might be worth recording that the Dylan FOPs were
682 ;;;; 100 FOP-DYLAN-SYMBOL-SAVE
683 ;;;; 101 FOP-SMALL-DYLAN-SYMBOL-SAVE
684 ;;;; 102 FOP-DYLAN-KEYWORD-SAVE
685 ;;;; 103 FOP-SMALL-DYLAN-KEYWORD-SAVE
686 ;;;; 104 FOP-DYLAN-VARINFO-VALUE
688 ;;;; assemblerish fops
690 (define-fop (fop-assembler-code 144)
691 (error "cannot load assembler code except at cold load"))
693 (define-fop (fop-assembler-routine 145)
694 (error "cannot load assembler code except at cold load"))
696 (define-fop (fop-foreign-fixup 147)
697 (let* ((kind (pop-stack))
698 (code-object (pop-stack))
699 (len (read-byte-arg))
700 (sym (make-string len :element-type 'base-char)))
701 (read-n-bytes *fasl-input-stream* sym 0 len)
702 (sb!vm:fixup-code-object code-object
704 (foreign-symbol-address sym)
708 (define-fop (fop-assembler-fixup 148)
709 (let ((routine (pop-stack))
711 (code-object (pop-stack)))
712 (multiple-value-bind (value found) (gethash routine *assembler-routines*)
714 (error "undefined assembler routine: ~S" routine))
715 (sb!vm:fixup-code-object code-object (read-word-arg) value kind))
718 (define-fop (fop-code-object-fixup 149)
719 (let ((kind (pop-stack))
720 (code-object (pop-stack)))
721 ;; Note: We don't have to worry about GC moving the code-object after
722 ;; the GET-LISP-OBJ-ADDRESS and before that value is deposited, because
723 ;; we can only use code-object fixups when code-objects don't move.
724 (sb!vm:fixup-code-object code-object (read-word-arg)
725 (get-lisp-obj-address code-object) kind)
729 (define-fop (fop-foreign-dataref-fixup 150)
730 (let* ((kind (pop-stack))
731 (code-object (pop-stack))
732 (len (read-byte-arg))
733 (sym (make-string len :element-type 'base-char)))
734 (read-n-bytes *fasl-input-stream* sym 0 len)
735 (sb!vm:fixup-code-object code-object
737 (foreign-symbol-address sym t)
741 ;;; FOPs needed for implementing an IF operator in a FASL
743 ;;; Skip until a FOP-MAYBE-STOP-SKIPPING with the same POSITION is
744 ;;; executed. While skipping, we execute most FOPs normally, except
745 ;;; for ones that a) funcall/eval b) start skipping. This needs to
746 ;;; be done to ensure that the fop table gets populated correctly
747 ;;; regardless of the execution path.
748 (define-fop (fop-skip 151 :pushp nil)
749 (let ((position (pop-stack)))
751 (setf *skip-until* position)))
754 ;;; As before, but only start skipping if the top of the FOP stack is NIL.
755 (define-fop (fop-skip-if-false 152 :pushp nil)
756 (let ((condition (pop-stack))
757 (position (pop-stack)))
758 (unless (or condition
760 (setf *skip-until* position)))
763 ;;; If skipping, pop the top of the stack and discard it. Needed for
764 ;;; ensuring that the stack stays balanced when skipping.
765 (define-fop (fop-drop-if-skipping 153 :pushp nil)
770 ;;; If skipping, push a dummy value on the stack. Needed for
771 ;;; ensuring that the stack stays balanced when skipping.
772 (define-fop (fop-push-nil-if-skipping 154 :pushp nil)
777 ;;; Stop skipping if the top of the stack matches *SKIP-UNTIL*
778 (define-fop (fop-maybe-stop-skipping 155 :pushp nil)
779 (let ((label (pop-stack)))
780 (when (eql *skip-until* label)
781 (setf *skip-until* nil)))