5 ;;; Define NAME as a fasl operation, with op-code FOP-CODE. PUSHP
6 ;;; describes what the body does to the fop stack:
8 ;;; The body might pop the fop stack. The result of the body is
9 ;;; pushed on the fop stack.
11 ;;; The body might pop the fop stack. The result of the body is
13 ;;; STACKP describes whether or not the body interacts with the fop stack.
14 (defmacro define-fop ((name fop-code &key (pushp t) (stackp t)) &rest forms)
18 `(with-fop-stack ,pushp ,@forms)
20 (%define-fop ',name ,fop-code)))
22 (defun %define-fop (name code)
23 (let ((oname (svref *fop-names* code)))
24 (when (and oname (not (eq oname name)))
25 (error "multiple names for fop code ~D: ~S and ~S" code name oname)))
26 ;; KLUDGE: It's mnemonically suboptimal to use 'FOP-CODE as the name of the
27 ;; tag which associates names with codes when it's also used as one of
28 ;; the names. Perhaps the fops named FOP-CODE and FOP-SMALL-CODE could
29 ;; be renamed to something more mnemonic? -- WHN 19990902
30 (let ((ocode (get name 'fop-code)))
31 (when (and ocode (/= ocode code))
32 (error "multiple codes for fop name ~S: ~D and ~D" name code ocode)))
33 (setf (svref *fop-names* code) name
34 (get name 'fop-code) code
35 (svref *fop-funs* code) (symbol-function name))
38 ;;; Define a pair of fops which are identical except that one reads
39 ;;; a four-byte argument while the other reads a one-byte argument. The
40 ;;; argument can be accessed by using the CLONE-ARG macro.
42 ;;; KLUDGE: It would be nice if the definition here encapsulated which
43 ;;; value ranges went with which fop variant, and chose the correct
44 ;;; fop code to use. Currently, since such logic isn't encapsulated,
45 ;;; we see callers doing stuff like
46 ;;; (cond ((and (< num-consts #x100) (< total-length #x10000))
47 ;;; (dump-fop 'sb!impl::fop-small-code file)
48 ;;; (dump-byte num-consts file)
49 ;;; (dump-integer-as-n-bytes total-length 2 file))
51 ;;; (dump-fop 'sb!impl::fop-code file)
52 ;;; (dump-word num-consts file)
53 ;;; (dump-word total-length file))))
54 ;;; in several places. It would be cleaner if this could be replaced with
56 ;;; (dump-fop file fop-code num-consts total-length)
57 ;;; Some of this logic is already in DUMP-FOP*, but that still requires the
58 ;;; caller to know that it's a 1-byte-arg/4-byte-arg cloned fop pair, and to
59 ;;; know both the 1-byte-arg and the 4-byte-arg fop names. -- WHN 19990902
60 (defmacro define-cloned-fops ((name code &key (pushp t) (stackp t))
61 (small-name small-code) &rest forms)
62 (aver (member pushp '(nil t)))
63 (aver (member stackp '(nil t)))
65 (macrolet ((clone-arg () '(read-word-arg)))
66 (define-fop (,name ,code :pushp ,pushp :stackp ,stackp) ,@forms))
67 (macrolet ((clone-arg () '(read-byte-arg)))
68 (define-fop (,small-name ,small-code :pushp ,pushp :stackp stackp) ,@forms))))
70 ;;; a helper function for reading string values from FASL files: sort
71 ;;; of like READ-SEQUENCE specialized for files of (UNSIGNED-BYTE 8),
72 ;;; with an automatic conversion from (UNSIGNED-BYTE 8) into CHARACTER
73 ;;; for each element read
74 (declaim (ftype (function (stream simple-string &optional index) (values)) read-string-as-bytes))
75 (defun read-string-as-bytes (stream string &optional (length (length string)))
78 (code-char (read-byte stream))))
79 ;; FIXME: The classic CMU CL code to do this was
80 ;; (READ-N-BYTES FILE STRING START END).
81 ;; It was changed for SBCL because we needed a portable version for
82 ;; bootstrapping. Benchmark the non-portable version and see whether it's
83 ;; significantly better than the portable version here. If it is, then use
84 ;; it as an alternate definition, protected with #-SB-XC-HOST.
87 ;;;; miscellaneous fops
89 ;;; FIXME: POP-STACK should be called something more mnemonic. (POP-FOP-STACK?
90 ;;; But that would conflict with PUSH-FOP-TABLE. Something, anyway..)
92 ;;; Setting this variable causes execution of a FOP-NOP4 to produce
93 ;;; output to *DEBUG-IO*. This can be handy when trying to follow the
94 ;;; progress of FASL loading.
96 (defvar *show-fop-nop4-p* nil)
98 ;;; CMU CL had a single no-op fop, FOP-NOP, with fop code 0. Since 0
99 ;;; occurs disproportionately often in fasl files for other reasons,
100 ;;; FOP-NOP is less than ideal for writing human-readable patterns
101 ;;; into fasl files for debugging purposes. There's no shortage of
102 ;;; unused fop codes, so we add this second NOP, which reads 4
103 ;;; arbitrary bytes and discards them.
104 (define-fop (fop-nop4 137 :stackp nil)
105 (let ((arg (read-arg 4)))
106 (declare (ignorable arg))
108 (when *show-fop-nop4-p*
109 (format *debug-io* "~&/FOP-NOP4 ARG=~W=#X~X~%" arg arg))))
111 (define-fop (fop-nop 0 :stackp nil))
112 (define-fop (fop-pop 1 :pushp nil) (push-fop-table (pop-stack)))
113 (define-fop (fop-push 2) (svref *current-fop-table* (read-word-arg)))
114 (define-fop (fop-byte-push 3) (svref *current-fop-table* (read-byte-arg)))
116 (define-fop (fop-empty-list 4) ())
117 (define-fop (fop-truth 5) t)
118 ;;; CMU CL had FOP-POP-FOR-EFFECT as fop 65, but it was never used and seemed
119 ;;; to have no possible use.
120 (define-fop (fop-misc-trap 66)
121 #+sb-xc-host ; since xc host doesn't know how to compile %PRIMITIVE
122 (error "FOP-MISC-TRAP can't be defined without %PRIMITIVE.")
124 (%primitive sb!c:make-other-immediate-type 0 sb!vm:unbound-marker-widetag))
126 ;;; CMU CL had FOP-CHARACTER as fop 68, but it's not needed in current
127 ;;; SBCL as we have no extended characters, only 1-byte characters.
128 ;;; (Ditto for CMU CL, actually: FOP-CHARACTER was speculative generality.)
129 (define-fop (fop-short-character 69)
130 (code-char (read-byte-arg)))
132 (define-cloned-fops (fop-struct 48) (fop-small-struct 49)
133 (let* ((size (clone-arg))
134 (res (%make-instance size)))
135 (declare (type index size))
136 (do ((n (1- size) (1- n)))
138 (declare (type index-or-minus-1 n))
139 (setf (%instance-ref res n) (pop-stack)))
142 (define-fop (fop-layout 45)
143 (let ((length (pop-stack))
144 (depthoid (pop-stack))
145 (inherits (pop-stack))
147 (find-and-init-or-check-layout name length inherits depthoid)))
149 (define-fop (fop-end-group 64 :stackp nil)
150 (/show0 "THROWing FASL-GROUP-END")
151 (throw 'fasl-group-end t))
153 ;;; In the normal loader, we just ignore these. GENESIS overwrites
154 ;;; FOP-MAYBE-COLD-LOAD with something that knows whether to revert to
155 ;;; cold-loading or not.
156 (define-fop (fop-normal-load 81 :stackp nil))
157 (define-fop (fop-maybe-cold-load 82 :stackp nil))
159 (define-fop (fop-verify-table-size 62 :stackp nil)
160 (let ((expected-index (read-word-arg)))
161 (unless (= *current-fop-table-index* expected-index)
162 (bug "fasl table of improper size"))))
163 (define-fop (fop-verify-empty-stack 63 :stackp nil)
164 (unless (zerop (length *fop-stack*))
165 (bug "fasl stack not empty when it should be")))
167 ;;;; fops for loading symbols
169 (macrolet (;; FIXME: Should all this code really be duplicated inside
170 ;; each fop? Perhaps it would be better for this shared
171 ;; code to live in FLET FROB1 and FLET FROB4 (for the
172 ;; two different sizes of counts).
173 (frob (name code name-size package)
174 (let ((n-package (gensym))
177 `(define-fop (,name ,code)
178 (prepare-for-fast-read-byte *fasl-input-stream*
179 (let ((,n-package ,package)
180 (,n-size (fast-read-u-integer ,name-size)))
181 (when (> ,n-size (length *fasl-symbol-buffer*))
182 (setq *fasl-symbol-buffer*
183 (make-string (* ,n-size 2))))
184 (done-with-fast-read-byte)
185 (let ((,n-buffer *fasl-symbol-buffer*))
186 (read-string-as-bytes *fasl-input-stream*
189 (push-fop-table (without-package-locks
194 ;; Note: CMU CL had FOP-SYMBOL-SAVE and FOP-SMALL-SYMBOL-SAVE, but
195 ;; since they made the behavior of the fasloader depend on the
196 ;; *PACKAGE* variable, not only were they a pain to support (because
197 ;; they required various hacks to handle *PACKAGE*-manipulation
198 ;; forms) they were basically broken by design, because ANSI gives
199 ;; the user so much flexibility in manipulating *PACKAGE* at
200 ;; load-time that no reasonable hacks could possibly make things
201 ;; work right. The ones used in CMU CL certainly didn't, as shown by
203 ;; (IN-PACKAGE :CL-USER)
204 ;; (DEFVAR CL::*FOO* 'FOO-VALUE)
205 ;; (EVAL-WHEN (:COMPILE-TOPLEVEL :LOAD-TOPLEVEL :EXECUTE)
206 ;; (SETF *PACKAGE* (FIND-PACKAGE :CL)))
207 ;; which in CMU CL 2.4.9 defines a variable CL-USER::*FOO* instead of
208 ;; defining CL::*FOO*. Therefore, we don't use those fops in SBCL.
209 ;;(frob fop-symbol-save 6 4 *package*)
210 ;;(frob fop-small-symbol-save 7 1 *package*)
212 (frob fop-lisp-symbol-save 75 #.sb!vm:n-word-bytes *cl-package*)
213 (frob fop-lisp-small-symbol-save 76 1 *cl-package*)
214 (frob fop-keyword-symbol-save 77 #.sb!vm:n-word-bytes *keyword-package*)
215 (frob fop-keyword-small-symbol-save 78 1 *keyword-package*)
217 ;; FIXME: Because we don't have FOP-SYMBOL-SAVE any more, an enormous number
218 ;; of symbols will fall through to this case, probably resulting in bloated
220 ;; FOP-SYMBOL-IN-LAST-PACKAGE-SAVE/FOP-SMALL-SYMBOL-IN-LAST-PACKAGE-SAVE
221 ;; cloned fop pair could undo some of this bloat.
222 (frob fop-symbol-in-package-save 8 #.sb!vm:n-word-bytes
223 (svref *current-fop-table* (fast-read-u-integer #.sb!vm:n-word-bytes)))
224 (frob fop-small-symbol-in-package-save 9 1
225 (svref *current-fop-table* (fast-read-u-integer #.sb!vm:n-word-bytes)))
226 (frob fop-symbol-in-byte-package-save 10 #.sb!vm:n-word-bytes
227 (svref *current-fop-table* (fast-read-u-integer 1)))
228 (frob fop-small-symbol-in-byte-package-save 11 1
229 (svref *current-fop-table* (fast-read-u-integer 1))))
231 (define-cloned-fops (fop-uninterned-symbol-save 12)
232 (fop-uninterned-small-symbol-save 13)
233 (let* ((arg (clone-arg))
234 (res (make-string arg)))
235 (read-string-as-bytes *fasl-input-stream* res)
236 (push-fop-table (make-symbol res))))
238 (define-fop (fop-package 14)
239 (find-undeleted-package-or-lose (pop-stack)))
241 ;;;; fops for loading numbers
243 ;;; Load a signed integer LENGTH bytes long from *FASL-INPUT-STREAM*.
244 (defun load-s-integer (length)
245 (declare (fixnum length))
246 ;; #+cmu (declare (optimize (inhibit-warnings 2)))
247 (do* ((index length (1- index))
248 (byte 0 (read-byte *fasl-input-stream*))
249 (result 0 (+ result (ash byte bits)))
252 (if (logbitp 7 byte) ; look at sign bit
253 (- result (ash 1 bits))
255 (declare (fixnum index byte bits))))
257 (define-cloned-fops (fop-integer 33) (fop-small-integer 34)
258 (load-s-integer (clone-arg)))
260 (define-fop (fop-word-integer 35)
261 (prepare-for-fast-read-byte *fasl-input-stream*
263 (fast-read-s-integer #.sb!vm:n-word-bytes)
264 (done-with-fast-read-byte))))
266 (define-fop (fop-byte-integer 36)
267 (prepare-for-fast-read-byte *fasl-input-stream*
269 (fast-read-s-integer 1)
270 (done-with-fast-read-byte))))
272 (define-fop (fop-ratio 70)
273 (let ((den (pop-stack)))
274 (%make-ratio (pop-stack) den)))
276 (define-fop (fop-complex 71)
277 (let ((im (pop-stack)))
278 (%make-complex (pop-stack) im)))
280 (macrolet ((fast-read-single-float ()
281 '(make-single-float (fast-read-s-integer 4)))
282 (fast-read-double-float ()
283 '(let ((lo (fast-read-u-integer 4)))
284 (make-double-float (fast-read-s-integer 4) lo))))
285 (macrolet ((define-complex-fop (name fop-code type)
286 (let ((reader (symbolicate "FAST-READ-" type)))
287 `(define-fop (,name ,fop-code)
288 (prepare-for-fast-read-byte *fasl-input-stream*
290 (complex (,reader) (,reader))
291 (done-with-fast-read-byte))))))
292 (define-float-fop (name fop-code type)
293 (let ((reader (symbolicate "FAST-READ-" type)))
294 `(define-fop (,name ,fop-code)
295 (prepare-for-fast-read-byte *fasl-input-stream*
298 (done-with-fast-read-byte)))))))
299 (define-complex-fop fop-complex-single-float 72 single-float)
300 (define-complex-fop fop-complex-double-float 73 double-float)
302 (define-complex-fop fop-complex-long-float 67 long-float)
303 (define-float-fop fop-single-float 46 single-float)
304 (define-float-fop fop-double-float 47 double-float)
306 (define-float-fop fop-long-float 52 long-float)))
311 (define-fop (fop-list 15)
312 (do ((res () (cons (pop-stack) res))
313 (n (read-byte-arg) (1- n)))
315 (declare (type index n))))
317 (define-fop (fop-list* 16)
318 (do ((res (pop-stack) (cons (pop-stack) res))
319 (n (read-byte-arg) (1- n)))
321 (declare (type index n))))
323 (macrolet ((frob (name op fun n)
324 `(define-fop (,name ,op)
325 (call-with-popped-args ,fun ,n))))
327 (frob fop-list-1 17 list 1)
328 (frob fop-list-2 18 list 2)
329 (frob fop-list-3 19 list 3)
330 (frob fop-list-4 20 list 4)
331 (frob fop-list-5 21 list 5)
332 (frob fop-list-6 22 list 6)
333 (frob fop-list-7 23 list 7)
334 (frob fop-list-8 24 list 8)
336 (frob fop-list*-1 25 list* 2)
337 (frob fop-list*-2 26 list* 3)
338 (frob fop-list*-3 27 list* 4)
339 (frob fop-list*-4 28 list* 5)
340 (frob fop-list*-5 29 list* 6)
341 (frob fop-list*-6 30 list* 7)
342 (frob fop-list*-7 31 list* 8)
343 (frob fop-list*-8 32 list* 9))
345 ;;;; fops for loading arrays
347 (define-cloned-fops (fop-string 37) (fop-small-string 38)
348 (let* ((arg (clone-arg))
349 (res (make-string arg)))
350 (read-string-as-bytes *fasl-input-stream* res)
353 (define-cloned-fops (fop-vector 39) (fop-small-vector 40)
354 (let* ((size (clone-arg))
355 (res (make-array size)))
356 (declare (fixnum size))
357 (do ((n (1- size) (1- n)))
359 (setf (svref res n) (pop-stack)))
362 (define-fop (fop-array 83)
363 (let* ((rank (read-word-arg))
365 (length (length vec))
366 (res (make-array-header sb!vm:simple-array-widetag rank)))
367 (declare (simple-array vec)
368 (type (unsigned-byte #.(- sb!vm:n-word-bits sb!vm:n-widetag-bits)) rank))
369 (set-array-header res vec length nil 0
371 (dimensions () (cons (pop-stack) dimensions)))
372 ((zerop i) dimensions)
373 (declare (type index i)))
377 (define-fop (fop-single-float-vector 84)
378 (let* ((length (read-word-arg))
379 (result (make-array length :element-type 'single-float)))
380 (read-n-bytes *fasl-input-stream* result 0 (* length 4))
383 (define-fop (fop-double-float-vector 85)
384 (let* ((length (read-word-arg))
385 (result (make-array length :element-type 'double-float)))
386 (read-n-bytes *fasl-input-stream* result 0 (* length 8))
389 (define-fop (fop-complex-single-float-vector 86)
390 (let* ((length (read-word-arg))
391 (result (make-array length :element-type '(complex single-float))))
392 (read-n-bytes *fasl-input-stream* result 0 (* length 8))
395 (define-fop (fop-complex-double-float-vector 87)
396 (let* ((length (read-word-arg))
397 (result (make-array length :element-type '(complex double-float))))
398 (read-n-bytes *fasl-input-stream* result 0 (* length 16))
402 ;;; *** NOT *** the FOP-INT-VECTOR as currently documented in rtguts.
403 ;;; Size must be a directly supported I-vector element size, with no
404 ;;; extra bits. This must be packed according to the local
405 ;;; byte-ordering, allowing us to directly read the bits.
406 (define-fop (fop-int-vector 43)
407 (prepare-for-fast-read-byte *fasl-input-stream*
408 (let* ((len (fast-read-u-integer #.sb!vm:n-word-bytes))
409 (size (fast-read-byte))
411 (0 (make-array len :element-type 'nil))
412 (1 (make-array len :element-type 'bit))
413 (2 (make-array len :element-type '(unsigned-byte 2)))
414 (4 (make-array len :element-type '(unsigned-byte 4)))
415 (7 (prog1 (make-array len :element-type '(unsigned-byte 7))
417 (8 (make-array len :element-type '(unsigned-byte 8)))
418 (15 (prog1 (make-array len :element-type '(unsigned-byte 15))
420 (16 (make-array len :element-type '(unsigned-byte 16)))
421 (31 (prog1 (make-array len :element-type '(unsigned-byte 31))
423 (32 (make-array len :element-type '(unsigned-byte 32)))
424 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
425 (63 (prog1 (make-array len :element-type '(unsigned-byte 63))
427 (64 (make-array len :element-type '(unsigned-byte 64)))
428 (t (bug "losing i-vector element size: ~S" size)))))
429 (declare (type index len))
430 (done-with-fast-read-byte)
431 (read-n-bytes *fasl-input-stream*
434 (ceiling (the index (* size len)) sb!vm:n-byte-bits))
437 ;;; This is the same as FOP-INT-VECTOR, except this is for signed
439 (define-fop (fop-signed-int-vector 50)
440 (prepare-for-fast-read-byte *fasl-input-stream*
441 (let* ((len (fast-read-u-integer #.sb!vm:n-word-bytes))
442 (size (fast-read-byte))
444 (8 (make-array len :element-type '(signed-byte 8)))
445 (16 (make-array len :element-type '(signed-byte 16)))
446 #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
447 (29 (prog1 (make-array len :element-type '(unsigned-byte 29))
449 #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
450 (30 (prog1 (make-array len :element-type '(signed-byte 30))
452 (32 (make-array len :element-type '(signed-byte 32)))
453 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
454 (60 (prog1 (make-array len :element-type '(unsigned-byte 60))
456 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
457 (61 (prog1 (make-array len :element-type '(signed-byte 61))
459 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
460 (64 (make-array len :element-type '(signed-byte 64)))
461 (t (bug "losing si-vector element size: ~S" size)))))
462 (declare (type index len))
463 (done-with-fast-read-byte)
464 (read-n-bytes *fasl-input-stream*
467 (ceiling (the index (* size len)) sb!vm:n-byte-bits))
470 (define-fop (fop-eval 53)
471 (let ((result (eval (pop-stack))))
472 ;; FIXME: CMU CL had this code here:
473 ;; (when *load-print*
477 ;; Unfortunately, this dependence on the *LOAD-PRINT* global
478 ;; variable is non-ANSI, so for now we've just punted printing in
482 (define-fop (fop-eval-for-effect 54 :pushp nil)
483 (let ((result (eval (pop-stack))))
484 ;; FIXME: See the comment about *LOAD-PRINT* in FOP-EVAL.
485 (declare (ignore result))
486 #+nil (when *load-print*
491 (define-fop (fop-funcall 55)
492 (let ((arg (read-byte-arg)))
494 (funcall (pop-stack))
495 (do ((args () (cons (pop-stack) args))
497 ((zerop n) (apply (pop-stack) args))
498 (declare (type index n))))))
500 (define-fop (fop-funcall-for-effect 56 :pushp nil)
501 (let ((arg (read-byte-arg)))
503 (funcall (pop-stack))
504 (do ((args () (cons (pop-stack) args))
506 ((zerop n) (apply (pop-stack) args))
507 (declare (type index n))))))
509 ;;;; fops for fixing up circularities
511 (define-fop (fop-rplaca 200 :pushp nil)
512 (let ((obj (svref *current-fop-table* (read-word-arg)))
513 (idx (read-word-arg))
515 (setf (car (nthcdr idx obj)) val)))
517 (define-fop (fop-rplacd 201 :pushp nil)
518 (let ((obj (svref *current-fop-table* (read-word-arg)))
519 (idx (read-word-arg))
521 (setf (cdr (nthcdr idx obj)) val)))
523 (define-fop (fop-svset 202 :pushp nil)
524 (let* ((obi (read-word-arg))
525 (obj (svref *current-fop-table* obi))
526 (idx (read-word-arg))
528 (if (typep obj 'instance)
529 (setf (%instance-ref obj idx) val)
530 (setf (svref obj idx) val))))
532 (define-fop (fop-structset 204 :pushp nil)
533 (setf (%instance-ref (svref *current-fop-table* (read-word-arg))
537 ;;; In the original CMUCL code, this actually explicitly declared PUSHP
538 ;;; to be T, even though that's what it defaults to in DEFINE-FOP.
539 (define-fop (fop-nthcdr 203)
540 (nthcdr (read-word-arg) (pop-stack)))
542 ;;;; fops for loading functions
544 ;;; (In CMU CL there was a FOP-CODE-FORMAT (47) which was
545 ;;; conventionally placed at the beginning of each fasl file to test
546 ;;; for compatibility between the fasl file and the CMU CL which
547 ;;; loaded it. In SBCL, this functionality has been replaced by
548 ;;; putting the implementation and version in required fields in the
549 ;;; fasl file header.)
551 (define-fop (fop-code 58 :stackp nil)
552 (load-code (read-word-arg) (read-word-arg)))
554 (define-fop (fop-small-code 59 :stackp nil)
555 (load-code (read-byte-arg) (read-halfword-arg)))
557 (define-fop (fop-fdefinition 60)
558 (fdefinition-object (pop-stack) t))
560 (define-fop (fop-sanctify-for-execution 61)
561 (let ((component (pop-stack)))
562 (sb!vm:sanctify-for-execution component)
565 (define-fop (fop-fset 74 :pushp nil)
566 ;; Ordinary, not-for-cold-load code shouldn't need to mess with this
567 ;; at all, since it's only used as part of the conspiracy between
568 ;; the cross-compiler and GENESIS to statically link FDEFINITIONs
570 (warn "~@<FOP-FSET seen in ordinary load (not cold load) -- quite strange! ~
571 If you didn't do something strange to cause this, please report it as a ~
573 ;; Unlike CMU CL, we don't treat this as a no-op in ordinary code.
574 ;; If the user (or, more likely, developer) is trying to reload
575 ;; compiled-for-cold-load code into a warm SBCL, we'll do a warm
576 ;; assignment. (This is partly for abstract tidiness, since the warm
577 ;; assignment is the closest analogy to what happens at cold load,
578 ;; and partly because otherwise our compiled-for-cold-load code will
579 ;; fail, since in SBCL things like compiled-for-cold-load %DEFUN
580 ;; depend more strongly than in CMU CL on FOP-FSET actually doing
582 (let ((fn (pop-stack))
584 (setf (fdefinition name) fn)))
586 ;;; Modify a slot in a CONSTANTS object.
587 (define-cloned-fops (fop-alter-code 140 :pushp nil) (fop-byte-alter-code 141)
588 (let ((value (pop-stack))
590 (setf (code-header-ref code (clone-arg)) value)
593 (define-fop (fop-fun-entry 142)
594 #+sb-xc-host ; since xc host doesn't know how to compile %PRIMITIVE
595 (error "FOP-FUN-ENTRY can't be defined without %PRIMITIVE.")
597 (let ((type (pop-stack))
598 (arglist (pop-stack))
600 (code-object (pop-stack))
601 (offset (read-word-arg)))
602 (declare (type index offset))
603 (unless (zerop (logand offset sb!vm:lowtag-mask))
604 (bug "unaligned function object, offset = #X~X" offset))
605 (let ((fun (%primitive sb!c:compute-fun code-object offset)))
606 (setf (%simple-fun-self fun) fun)
607 (setf (%simple-fun-next fun) (%code-entry-points code-object))
608 (setf (%code-entry-points code-object) fun)
609 (setf (%simple-fun-name fun) name)
610 (setf (%simple-fun-arglist fun) arglist)
611 (setf (%simple-fun-type fun) type)
612 ;; FIXME: See the comment about *LOAD-PRINT* in FOP-EVAL.
613 #+nil (when *load-print*
615 (format t "~S defined~%" fun))
618 ;;;; Some Dylan FOPs used to live here. By 1 November 1998 the code
619 ;;;; was sufficiently stale that the functions it called were no
620 ;;;; longer defined, so I (William Harold Newman) deleted it.
622 ;;;; In case someone in the future is trying to make sense of FOP layout,
623 ;;;; it might be worth recording that the Dylan FOPs were
624 ;;;; 100 FOP-DYLAN-SYMBOL-SAVE
625 ;;;; 101 FOP-SMALL-DYLAN-SYMBOL-SAVE
626 ;;;; 102 FOP-DYLAN-KEYWORD-SAVE
627 ;;;; 103 FOP-SMALL-DYLAN-KEYWORD-SAVE
628 ;;;; 104 FOP-DYLAN-VARINFO-VALUE
630 ;;;; assemblerish fops
632 (define-fop (fop-assembler-code 144)
633 (error "cannot load assembler code except at cold load"))
635 (define-fop (fop-assembler-routine 145)
636 (error "cannot load assembler code except at cold load"))
638 (define-fop (fop-foreign-fixup 147)
639 (let* ((kind (pop-stack))
640 (code-object (pop-stack))
641 (len (read-byte-arg))
642 (sym (make-string len)))
643 (read-n-bytes *fasl-input-stream* sym 0 len)
644 (sb!vm:fixup-code-object code-object
646 (foreign-symbol-address-as-integer sym)
650 (define-fop (fop-assembler-fixup 148)
651 (let ((routine (pop-stack))
653 (code-object (pop-stack)))
654 (multiple-value-bind (value found) (gethash routine *assembler-routines*)
656 (error "undefined assembler routine: ~S" routine))
657 (sb!vm:fixup-code-object code-object (read-word-arg) value kind))
660 (define-fop (fop-code-object-fixup 149)
661 (let ((kind (pop-stack))
662 (code-object (pop-stack)))
663 ;; Note: We don't have to worry about GC moving the code-object after
664 ;; the GET-LISP-OBJ-ADDRESS and before that value is deposited, because
665 ;; we can only use code-object fixups when code-objects don't move.
666 (sb!vm:fixup-code-object code-object (read-word-arg)
667 (get-lisp-obj-address code-object) kind)
671 (define-fop (fop-foreign-dataref-fixup 150)
672 (let* ((kind (pop-stack))
673 (code-object (pop-stack))
674 (len (read-byte-arg))
675 (sym (make-string len)))
676 (read-n-bytes *fasl-input-stream* sym 0 len)
677 (sb!vm:fixup-code-object code-object
679 (foreign-symbol-address-as-integer sym t)