CHANGE-CLASS now works correctly on unbound slots
[sbcl.git] / src / code / fop.lisp
blob2e91e321b5d7aa8455eb1084e31a409a13c154d4
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 ;;; Define NAME as a fasl operation, with op-code FOP-CODE. PUSHP
12 ;;; describes what the body does to the fop stack:
13 ;;; T
14 ;;; The body might pop the fop stack. The result of the body is
15 ;;; pushed on the fop stack.
16 ;;; NIL
17 ;;; The body might pop the fop stack. The result of the body is
18 ;;; discarded.
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)) &body forms)
21 `(progn
22 (defun ,name ()
23 ,(if stackp
24 `(with-fop-stack ,pushp ,@forms)
25 `(progn ,@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))
42 (values))
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.
47 ;;;
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))
56 ;;; (t
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
61 ;;; something like
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)))
70 `(progn
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 (defun read-string-as-bytes (stream string &optional (length (length string)))
81 (declare (type (simple-array character (*)) string)
82 (type index length)
83 (optimize speed))
84 (with-fast-read-byte ((unsigned-byte 8) stream)
85 (dotimes (i length)
86 (setf (aref string i)
87 (sb!xc:code-char (fast-read-byte)))))
88 string)
89 (defun read-base-string-as-bytes (stream string &optional (length (length string)))
90 (declare (type (simple-array base-char (*)) string)
91 (type index length)
92 (optimize speed))
93 (with-fast-read-byte ((unsigned-byte 8) stream)
94 (dotimes (i length)
95 (setf (aref string i)
96 (sb!xc:code-char (fast-read-byte)))))
97 string)
98 #!+sb-unicode
99 (defun read-string-as-unsigned-byte-32
100 (stream string &optional (length (length string)))
101 (declare (type (simple-array character (*)) string)
102 (type index length)
103 (optimize speed))
104 #+sb-xc-host (bug "READ-STRING-AS-UNSIGNED-BYTE-32 called")
105 (with-fast-read-byte ((unsigned-byte 8) stream)
106 (dotimes (i length)
107 (setf (aref string i)
108 (sb!xc:code-char (fast-read-u-integer 4)))))
109 string)
111 ;;;; miscellaneous fops
113 ;;; FIXME: POP-STACK should be called something more mnemonic. (POP-FOP-STACK?
114 ;;; But that would conflict with PUSH-FOP-TABLE. Something, anyway..)
116 ;;; Setting this variable causes execution of a FOP-NOP4 to produce
117 ;;; output to *DEBUG-IO*. This can be handy when trying to follow the
118 ;;; progress of FASL loading.
119 #!+sb-show
120 (defvar *show-fop-nop4-p* nil)
122 ;;; CMU CL had a single no-op fop, FOP-NOP, with fop code 0. Since 0
123 ;;; occurs disproportionately often in fasl files for other reasons,
124 ;;; FOP-NOP is less than ideal for writing human-readable patterns
125 ;;; into fasl files for debugging purposes. There's no shortage of
126 ;;; unused fop codes, so we add this second NOP, which reads 4
127 ;;; arbitrary bytes and discards them.
128 (define-fop (fop-nop4 137 :stackp nil)
129 (let ((arg (read-arg 4)))
130 (declare (ignorable arg))
131 #!+sb-show
132 (when *show-fop-nop4-p*
133 (format *debug-io* "~&/FOP-NOP4 ARG=~W=#X~X~%" arg arg))))
135 (define-fop (fop-nop 0 :stackp nil))
136 (define-fop (fop-pop 1 :pushp nil) (push-fop-table (pop-stack)))
137 (define-fop (fop-push 2) (ref-fop-table (read-word-arg)))
138 (define-fop (fop-byte-push 3) (ref-fop-table (read-byte-arg)))
140 (define-fop (fop-empty-list 4) ())
141 (define-fop (fop-truth 5) t)
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 (fop-misc-trap 66)
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-cloned-fops (fop-character 68) (fop-short-character 69)
151 (code-char (clone-arg)))
153 (define-cloned-fops (fop-struct 48) (fop-small-struct 49)
154 (let* ((size (clone-arg))
155 (res (%make-instance size)))
156 (declare (type index size))
157 (let* ((layout (pop-stack))
158 (nuntagged (layout-n-untagged-slots layout))
159 (ntagged (- size nuntagged)))
160 (setf (%instance-ref res 0) layout)
161 (dotimes (n (1- ntagged))
162 (declare (type index n))
163 (setf (%instance-ref res (1+ n)) (pop-stack)))
164 (dotimes (n nuntagged)
165 (declare (type index n))
166 (setf (%raw-instance-ref/word res (- nuntagged n 1)) (pop-stack))))
167 res))
169 (define-fop (fop-layout 45)
170 (let ((nuntagged (pop-stack))
171 (length (pop-stack))
172 (depthoid (pop-stack))
173 (inherits (pop-stack))
174 (name (pop-stack)))
175 (find-and-init-or-check-layout name length inherits depthoid nuntagged)))
177 (define-fop (fop-end-group 64 :stackp nil)
178 (/show0 "THROWing FASL-GROUP-END")
179 (throw 'fasl-group-end t))
181 ;;; We used to have FOP-NORMAL-LOAD as 81 and FOP-MAYBE-COLD-LOAD as
182 ;;; 82 until GENESIS learned how to work with host symbols and
183 ;;; packages directly instead of piggybacking on the host code.
185 (define-fop (fop-verify-table-size 62 :stackp nil)
186 (let ((expected-index (read-word-arg)))
187 (unless (= (get-fop-table-index) expected-index)
188 (bug "fasl table of improper size"))))
189 (define-fop (fop-verify-empty-stack 63 :stackp nil)
190 (unless (fop-stack-empty-p)
191 (bug "fasl stack not empty when it should be")))
193 ;;;; fops for loading symbols
195 (defstruct (undefined-package
196 (:copier nil))
197 error)
199 (declaim (freeze-type undefined-package))
201 (defun aux-fop-intern (smallp package)
202 (declare (optimize speed))
203 (let* ((size (if smallp
204 (read-byte-arg)
205 (read-word-arg)))
206 (buffer (make-string size)))
207 #+sb-xc-host
208 (read-string-as-bytes *fasl-input-stream* buffer size)
209 #-sb-xc-host
210 (progn
211 #!+sb-unicode
212 (read-string-as-unsigned-byte-32 *fasl-input-stream* buffer size)
213 #!-sb-unicode
214 (read-string-as-bytes *fasl-input-stream* buffer size))
215 (if (undefined-package-p package)
216 (error 'simple-package-error
217 :format-control "Error finding package for symbol ~s:~% ~a"
218 :format-arguments
219 (list (subseq buffer 0 size)
220 (undefined-package-error package)))
221 (push-fop-table (without-package-locks
222 (intern* buffer
223 size
224 package
225 :no-copy t))))))
227 (macrolet ((def (name code smallp package-form)
228 `(define-fop (,name ,code)
229 (aux-fop-intern ,smallp ,package-form))))
231 (def fop-lisp-symbol-save 75 nil *cl-package*)
232 (def fop-lisp-small-symbol-save 76 t *cl-package*)
233 (def fop-keyword-symbol-save 77 nil *keyword-package*)
234 (def fop-keyword-small-symbol-save 78 t *keyword-package*)
236 ;; FIXME: Because we don't have FOP-SYMBOL-SAVE any more, an
237 ;; enormous number of symbols will fall through to this case,
238 ;; probably resulting in bloated fasl files. A new
239 ;; FOP-SYMBOL-IN-LAST-PACKAGE-SAVE/FOP-SMALL-SYMBOL-IN-LAST-PACKAGE-SAVE
240 ;; cloned fop pair could undo some of this bloat.
241 (def fop-symbol-in-package-save 8 nil
242 (ref-fop-table (read-word-arg)))
243 (def fop-small-symbol-in-package-save 9 t
244 (ref-fop-table (read-word-arg)))
245 (def fop-symbol-in-byte-package-save 10 nil
246 (ref-fop-table (read-byte-arg)))
247 (def fop-small-symbol-in-byte-package-save 11 t
248 (ref-fop-table (read-byte-arg))))
250 (define-cloned-fops (fop-uninterned-symbol-save 12)
251 (fop-uninterned-small-symbol-save 13)
252 (let* ((arg (clone-arg))
253 (res (make-string arg)))
254 #!-sb-unicode
255 (read-string-as-bytes *fasl-input-stream* res)
256 #!+sb-unicode
257 (read-string-as-unsigned-byte-32 *fasl-input-stream* res)
258 (push-fop-table (make-symbol res))))
260 (define-fop (fop-package 14)
261 (find-undeleted-package-or-lose (pop-stack)))
263 (define-cloned-fops (fop-named-package-save 156 :stackp nil)
264 (fop-small-named-package-save 157)
265 (let* ((arg (clone-arg))
266 (package-name (make-string arg)))
267 #+sb-xc-host
268 (read-string-as-bytes *fasl-input-stream* package-name)
269 #-sb-xc-host
270 (progn
271 #!-sb-unicode
272 (read-string-as-bytes *fasl-input-stream* package-name)
273 #!+sb-unicode
274 (read-string-as-unsigned-byte-32 *fasl-input-stream* package-name))
275 (push-fop-table
276 (handler-case (find-undeleted-package-or-lose package-name)
277 (simple-package-error (c)
278 (make-undefined-package :error (princ-to-string c)))))))
280 ;;;; fops for loading numbers
282 ;;; Load a signed integer LENGTH bytes long from *FASL-INPUT-STREAM*.
283 (defun load-s-integer (length)
284 (declare (fixnum length)
285 (optimize speed))
286 (with-fast-read-byte ((unsigned-byte 8) *fasl-input-stream*)
287 (do* ((index length (1- index))
288 (byte 0 (fast-read-byte))
289 (result 0 (+ result (ash byte bits)))
290 (bits 0 (+ bits 8)))
291 ((= index 0)
292 (if (logbitp 7 byte) ; look at sign bit
293 (- result (ash 1 bits))
294 result))
295 (declare (fixnum index byte bits)))))
297 (define-cloned-fops (fop-integer 33) (fop-small-integer 34)
298 (load-s-integer (clone-arg)))
300 (define-fop (fop-word-integer 35)
301 (with-fast-read-byte ((unsigned-byte 8) *fasl-input-stream*)
302 (fast-read-s-integer #.sb!vm:n-word-bytes)))
304 (define-fop (fop-byte-integer 36)
305 (with-fast-read-byte ((unsigned-byte 8) *fasl-input-stream*)
306 (fast-read-s-integer 1)))
308 (define-fop (fop-ratio 70)
309 (let ((den (pop-stack)))
310 (%make-ratio (pop-stack) den)))
312 (define-fop (fop-complex 71)
313 (let ((im (pop-stack)))
314 (%make-complex (pop-stack) im)))
316 (macrolet ((fast-read-single-float ()
317 '(make-single-float (fast-read-s-integer 4)))
318 (fast-read-double-float ()
319 '(let ((lo (fast-read-u-integer 4)))
320 (make-double-float (fast-read-s-integer 4) lo))))
321 (macrolet ((define-complex-fop (name fop-code type)
322 (let ((reader (symbolicate "FAST-READ-" type)))
323 `(define-fop (,name ,fop-code)
324 (with-fast-read-byte ((unsigned-byte 8) *fasl-input-stream*)
325 (complex (,reader) (,reader))))))
326 (define-float-fop (name fop-code type)
327 (let ((reader (symbolicate "FAST-READ-" type)))
328 `(define-fop (,name ,fop-code)
329 (with-fast-read-byte ((unsigned-byte 8) *fasl-input-stream*)
330 (,reader))))))
331 (define-complex-fop fop-complex-single-float 72 single-float)
332 (define-complex-fop fop-complex-double-float 73 double-float)
333 #!+long-float
334 (define-complex-fop fop-complex-long-float 67 long-float)
335 (define-float-fop fop-single-float 46 single-float)
336 (define-float-fop fop-double-float 47 double-float)
337 #!+long-float
338 (define-float-fop fop-long-float 52 long-float)))
340 #!+sb-simd-pack
341 (define-fop (fop-simd-pack 88)
342 (with-fast-read-byte ((unsigned-byte 8) *fasl-input-stream*)
343 (%make-simd-pack (fast-read-s-integer 8)
344 (fast-read-u-integer 8)
345 (fast-read-u-integer 8))))
347 ;;;; loading lists
349 (define-fop (fop-list 15)
350 (do ((res () (cons (pop-stack) res))
351 (n (read-byte-arg) (1- n)))
352 ((zerop n) res)
353 (declare (type index n))))
355 (define-fop (fop-list* 16)
356 (do ((res (pop-stack) (cons (pop-stack) res))
357 (n (read-byte-arg) (1- n)))
358 ((zerop n) res)
359 (declare (type index n))))
361 (macrolet ((frob (name op fun n)
362 `(define-fop (,name ,op)
363 (call-with-popped-args ,fun ,n))))
365 (frob fop-list-1 17 list 1)
366 (frob fop-list-2 18 list 2)
367 (frob fop-list-3 19 list 3)
368 (frob fop-list-4 20 list 4)
369 (frob fop-list-5 21 list 5)
370 (frob fop-list-6 22 list 6)
371 (frob fop-list-7 23 list 7)
372 (frob fop-list-8 24 list 8)
374 (frob fop-list*-1 25 list* 2)
375 (frob fop-list*-2 26 list* 3)
376 (frob fop-list*-3 27 list* 4)
377 (frob fop-list*-4 28 list* 5)
378 (frob fop-list*-5 29 list* 6)
379 (frob fop-list*-6 30 list* 7)
380 (frob fop-list*-7 31 list* 8)
381 (frob fop-list*-8 32 list* 9))
383 ;;;; fops for loading arrays
385 (define-cloned-fops (fop-base-string 37) (fop-small-base-string 38)
386 (let* ((arg (clone-arg))
387 (res (make-string arg :element-type 'base-char)))
388 (read-base-string-as-bytes *fasl-input-stream* res)
389 res))
391 #!+sb-unicode
392 (progn
393 #+sb-xc-host
394 (define-cloned-fops (fop-character-string 161) (fop-small-character-string 162)
395 (bug "CHARACTER-STRING FOP encountered"))
397 #-sb-xc-host
398 (define-cloned-fops (fop-character-string 161) (fop-small-character-string 162)
399 (let* ((arg (clone-arg))
400 (res (make-string arg)))
401 (read-string-as-unsigned-byte-32 *fasl-input-stream* res)
402 res)))
404 (define-cloned-fops (fop-vector 39) (fop-small-vector 40)
405 (let* ((size (clone-arg))
406 (res (make-array size)))
407 (declare (fixnum size))
408 (do ((n (1- size) (1- n)))
409 ((minusp n))
410 (setf (svref res n) (pop-stack)))
411 res))
413 (define-fop (fop-array 83)
414 (let* ((rank (read-word-arg))
415 (vec (pop-stack))
416 (length (length vec))
417 (res (make-array-header sb!vm:simple-array-widetag rank)))
418 (declare (simple-array vec)
419 (type (unsigned-byte #.(- sb!vm:n-word-bits sb!vm:n-widetag-bits)) rank))
420 (set-array-header res vec length nil 0
421 (do ((i rank (1- i))
422 (dimensions () (cons (pop-stack) dimensions)))
423 ((zerop i) dimensions)
424 (declare (type index i)))
427 res))
429 (defglobal **saetp-bits-per-length**
430 (let ((array (make-array (1+ sb!vm:widetag-mask)
431 :element-type '(unsigned-byte 8)
432 :initial-element 255)))
433 (loop for saetp across sb!vm:*specialized-array-element-type-properties*
435 (setf (aref array (sb!vm:saetp-typecode saetp))
436 (sb!vm:saetp-n-bits saetp)))
437 array)
438 #!+sb-doc
439 "255 means bad entry.")
440 (declaim (type (simple-array (unsigned-byte 8) (#.(1+ sb!vm:widetag-mask)))
441 **saetp-bits-per-length**))
443 (define-fop (fop-spec-vector 43)
444 (let* ((length (read-word-arg))
445 (widetag (read-byte-arg))
446 (bits-per-length (aref **saetp-bits-per-length** widetag))
447 (bits (progn (aver (< bits-per-length 255))
448 (* length bits-per-length)))
449 (bytes (ceiling bits sb!vm:n-byte-bits))
450 (words (ceiling bytes sb!vm:n-word-bytes))
451 (vector (allocate-vector widetag length words)))
452 (declare (type index length bytes words)
453 (type word bits))
454 (read-n-bytes *fasl-input-stream* vector 0 bytes)
455 vector))
457 (define-fop (fop-eval 53)
458 (if *skip-until*
459 (pop-stack)
460 (let ((result (eval (pop-stack))))
461 ;; FIXME: CMU CL had this code here:
462 ;; (when *load-print*
463 ;; (load-fresh-line)
464 ;; (prin1 result)
465 ;; (terpri))
466 ;; Unfortunately, this dependence on the *LOAD-PRINT* global
467 ;; variable is non-ANSI, so for now we've just punted printing in
468 ;; fasl loading.
469 result)))
471 (define-fop (fop-eval-for-effect 54 :pushp nil)
472 (if *skip-until*
473 (pop-stack)
474 (let ((result (eval (pop-stack))))
475 ;; FIXME: See the comment about *LOAD-PRINT* in FOP-EVAL.
476 (declare (ignore result))
477 #+nil (when *load-print*
478 (load-fresh-line)
479 (prin1 result)
480 (terpri)))))
482 (define-fop (fop-funcall 55)
483 (let ((arg (read-byte-arg)))
484 (if *skip-until*
485 (dotimes (i (1+ arg))
486 (pop-stack))
487 (if (zerop arg)
488 (funcall (pop-stack))
489 (do ((args () (cons (pop-stack) args))
490 (n arg (1- n)))
491 ((zerop n) (apply (pop-stack) args))
492 (declare (type index n)))))))
494 (define-fop (fop-funcall-for-effect 56 :pushp nil)
495 (let ((arg (read-byte-arg)))
496 (if *skip-until*
497 (dotimes (i (1+ arg))
498 (pop-stack))
499 (if (zerop arg)
500 (funcall (pop-stack))
501 (do ((args () (cons (pop-stack) args))
502 (n arg (1- n)))
503 ((zerop n) (apply (pop-stack) args))
504 (declare (type index n)))))))
506 ;;;; fops for fixing up circularities
508 (define-fop (fop-rplaca 200 :pushp nil)
509 (let ((obj (ref-fop-table (read-word-arg)))
510 (idx (read-word-arg))
511 (val (pop-stack)))
512 (setf (car (nthcdr idx obj)) val)))
514 (define-fop (fop-rplacd 201 :pushp nil)
515 (let ((obj (ref-fop-table (read-word-arg)))
516 (idx (read-word-arg))
517 (val (pop-stack)))
518 (setf (cdr (nthcdr idx obj)) val)))
520 (define-fop (fop-svset 202 :pushp nil)
521 (let* ((obi (read-word-arg))
522 (obj (ref-fop-table obi))
523 (idx (read-word-arg))
524 (val (pop-stack)))
525 (if (%instancep obj)
526 (setf (%instance-ref obj idx) val)
527 (setf (svref obj idx) val))))
529 (define-fop (fop-structset 204 :pushp nil)
530 (setf (%instance-ref (ref-fop-table (read-word-arg))
531 (read-word-arg))
532 (pop-stack)))
534 ;;; In the original CMUCL code, this actually explicitly declared PUSHP
535 ;;; to be T, even though that's what it defaults to in DEFINE-FOP.
536 (define-fop (fop-nthcdr 203)
537 (nthcdr (read-word-arg) (pop-stack)))
539 ;;;; fops for loading functions
541 ;;; (In CMU CL there was a FOP-CODE-FORMAT (47) which was
542 ;;; conventionally placed at the beginning of each fasl file to test
543 ;;; for compatibility between the fasl file and the CMU CL which
544 ;;; loaded it. In SBCL, this functionality has been replaced by
545 ;;; putting the implementation and version in required fields in the
546 ;;; fasl file header.)
548 (define-fop (fop-code 58 :stackp nil)
549 (load-code (read-word-arg) (read-word-arg)))
551 (define-fop (fop-small-code 59 :stackp nil)
552 (load-code (read-byte-arg) (read-halfword-arg)))
554 (define-fop (fop-fdefinition 60) ; should probably be 'fop-fdefn'
555 (find-or-create-fdefn (pop-stack)))
557 (define-fop (fop-known-fun 65)
558 (%coerce-name-to-fun (pop-stack)))
560 #!-(or x86 x86-64)
561 (define-fop (fop-sanctify-for-execution 61)
562 (let ((component (pop-stack)))
563 (sb!vm:sanctify-for-execution component)
564 component))
566 (define-fop (fop-fset 74 :pushp nil)
567 ;; Ordinary, not-for-cold-load code shouldn't need to mess with this
568 ;; at all, since it's only used as part of the conspiracy between
569 ;; the cross-compiler and GENESIS to statically link FDEFINITIONs
570 ;; for cold init.
571 (warn "~@<FOP-FSET seen in ordinary load (not cold load) -- quite strange! ~
572 If you didn't do something strange to cause this, please report it as a ~
573 bug.~:@>")
574 ;; Unlike CMU CL, we don't treat this as a no-op in ordinary code.
575 ;; If the user (or, more likely, developer) is trying to reload
576 ;; compiled-for-cold-load code into a warm SBCL, we'll do a warm
577 ;; assignment. (This is partly for abstract tidiness, since the warm
578 ;; assignment is the closest analogy to what happens at cold load,
579 ;; and partly because otherwise our compiled-for-cold-load code will
580 ;; fail, since in SBCL things like compiled-for-cold-load %DEFUN
581 ;; depend more strongly than in CMU CL on FOP-FSET actually doing
582 ;; something.)
583 (let ((fn (pop-stack))
584 (name (pop-stack)))
585 (setf (fdefinition name) fn)))
587 (define-fop (fop-note-debug-source 174 :pushp nil)
588 (warn "~@<FOP-NOTE-DEBUG-SOURCE seen in ordinary load (not cold load) -- ~
589 very strange! If you didn't do something to cause this, please report it as ~
590 a bug.~@:>")
591 ;; as with COLD-FSET above, we are going to be lenient with coming
592 ;; across this fop in a warm SBCL.
593 (let ((debug-source (pop-stack)))
594 (setf (sb!c::debug-source-compiled debug-source) (get-universal-time)
595 (sb!c::debug-source-created debug-source)
596 (file-write-date (sb!c::debug-source-namestring debug-source)))))
598 ;;; Modify a slot in a CONSTANTS object.
599 (define-cloned-fops (fop-alter-code 140 :pushp nil) (fop-byte-alter-code 141)
600 (let ((value (pop-stack))
601 (code (pop-stack)))
602 (setf (code-header-ref code (clone-arg)) value)
603 (values)))
605 (define-fop (fop-fun-entry 142)
606 #+sb-xc-host ; since xc host doesn't know how to compile %PRIMITIVE
607 (error "FOP-FUN-ENTRY can't be defined without %PRIMITIVE.")
608 #-sb-xc-host
609 (let ((info (pop-stack))
610 (type (pop-stack))
611 (arglist (pop-stack))
612 (name (pop-stack))
613 (code-object (pop-stack))
614 (offset (read-word-arg)))
615 (declare (type index offset))
616 (unless (zerop (logand offset sb!vm:lowtag-mask))
617 (bug "unaligned function object, offset = #X~X" offset))
618 (let ((fun (%primitive sb!c:compute-fun code-object offset)))
619 (setf (%simple-fun-self fun) fun)
620 (setf (%simple-fun-next fun) (%code-entry-points code-object))
621 (setf (%code-entry-points code-object) fun)
622 (setf (%simple-fun-name fun) name)
623 (setf (%simple-fun-arglist fun) arglist)
624 (setf (%simple-fun-type fun) type)
625 (setf (%simple-fun-info fun) info)
626 ;; FIXME: See the comment about *LOAD-PRINT* in FOP-EVAL.
627 #+nil (when *load-print*
628 (load-fresh-line)
629 (format t "~S defined~%" fun))
630 fun)))
632 ;;;; Some Dylan FOPs used to live here. By 1 November 1998 the code
633 ;;;; was sufficiently stale that the functions it called were no
634 ;;;; longer defined, so I (William Harold Newman) deleted it.
635 ;;;;
636 ;;;; In case someone in the future is trying to make sense of FOP layout,
637 ;;;; it might be worth recording that the Dylan FOPs were
638 ;;;; 100 FOP-DYLAN-SYMBOL-SAVE
639 ;;;; 101 FOP-SMALL-DYLAN-SYMBOL-SAVE
640 ;;;; 102 FOP-DYLAN-KEYWORD-SAVE
641 ;;;; 103 FOP-SMALL-DYLAN-KEYWORD-SAVE
642 ;;;; 104 FOP-DYLAN-VARINFO-VALUE
644 ;;;; assemblerish fops
646 (define-fop (fop-assembler-code 144)
647 (error "cannot load assembler code except at cold load"))
649 (define-fop (fop-assembler-routine 145)
650 (error "cannot load assembler code except at cold load"))
652 (define-fop (fop-symbol-tls-fixup 146)
653 (let* ((symbol (pop-stack))
654 (kind (pop-stack))
655 (code-object (pop-stack)))
656 (sb!vm:fixup-code-object code-object
657 (read-word-arg)
658 (ensure-symbol-tls-index symbol)
659 kind)
660 code-object))
662 (define-fop (fop-foreign-fixup 147)
663 (let* ((kind (pop-stack))
664 (code-object (pop-stack))
665 (len (read-byte-arg))
666 (sym (make-string len :element-type 'base-char)))
667 (read-n-bytes *fasl-input-stream* sym 0 len)
668 (sb!vm:fixup-code-object code-object
669 (read-word-arg)
670 (foreign-symbol-address sym)
671 kind)
672 code-object))
674 (define-fop (fop-assembler-fixup 148)
675 (let ((routine (pop-stack))
676 (kind (pop-stack))
677 (code-object (pop-stack)))
678 (multiple-value-bind (value found) (gethash routine *assembler-routines*)
679 (unless found
680 (error "undefined assembler routine: ~S" routine))
681 (sb!vm:fixup-code-object code-object (read-word-arg) value kind))
682 code-object))
684 (define-fop (fop-code-object-fixup 149)
685 (let ((kind (pop-stack))
686 (code-object (pop-stack)))
687 ;; Note: We don't have to worry about GC moving the code-object after
688 ;; the GET-LISP-OBJ-ADDRESS and before that value is deposited, because
689 ;; we can only use code-object fixups when code-objects don't move.
690 (sb!vm:fixup-code-object code-object (read-word-arg)
691 (get-lisp-obj-address code-object) kind)
692 code-object))
694 #!+linkage-table
695 (define-fop (fop-foreign-dataref-fixup 150)
696 (let* ((kind (pop-stack))
697 (code-object (pop-stack))
698 (len (read-byte-arg))
699 (sym (make-string len :element-type 'base-char)))
700 (read-n-bytes *fasl-input-stream* sym 0 len)
701 (sb!vm:fixup-code-object code-object
702 (read-word-arg)
703 (foreign-symbol-address sym t)
704 kind)
705 code-object))
707 ;;; FOPs needed for implementing an IF operator in a FASL
709 ;;; Skip until a FOP-MAYBE-STOP-SKIPPING with the same POSITION is
710 ;;; executed. While skipping, we execute most FOPs normally, except
711 ;;; for ones that a) funcall/eval b) start skipping. This needs to
712 ;;; be done to ensure that the fop table gets populated correctly
713 ;;; regardless of the execution path.
714 (define-fop (fop-skip 151 :pushp nil)
715 (let ((position (pop-stack)))
716 (unless *skip-until*
717 (setf *skip-until* position)))
718 (values))
720 ;;; As before, but only start skipping if the top of the FOP stack is NIL.
721 (define-fop (fop-skip-if-false 152 :pushp nil)
722 (let ((condition (pop-stack))
723 (position (pop-stack)))
724 (unless (or condition
725 *skip-until*)
726 (setf *skip-until* position)))
727 (values))
729 ;;; If skipping, pop the top of the stack and discard it. Needed for
730 ;;; ensuring that the stack stays balanced when skipping.
731 (define-fop (fop-drop-if-skipping 153 :pushp nil)
732 (when *skip-until*
733 (pop-stack))
734 (values))
736 ;;; If skipping, push a dummy value on the stack. Needed for
737 ;;; ensuring that the stack stays balanced when skipping.
738 (define-fop (fop-push-nil-if-skipping 154 :pushp nil)
739 (when *skip-until*
740 (push-stack nil))
741 (values))
743 ;;; Stop skipping if the top of the stack matches *SKIP-UNTIL*
744 (define-fop (fop-maybe-stop-skipping 155 :pushp nil)
745 (let ((label (pop-stack)))
746 (when (eql *skip-until* label)
747 (setf *skip-until* nil)))
748 (values))