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))
81 read-string-as-bytes
#!+sb-unicode read-string-as-words
))
82 (defun read-string-as-bytes (stream string
&optional
(length (length string
)))
85 (sb!xc
:code-char
(read-byte stream
))))
86 ;; FIXME: The classic CMU CL code to do this was
87 ;; (READ-N-BYTES FILE STRING START END).
88 ;; It was changed for SBCL because we needed a portable version for
89 ;; bootstrapping. Benchmark the non-portable version and see whether it's
90 ;; significantly better than the portable version here. If it is, then use
91 ;; it as an alternate definition, protected with #-SB-XC-HOST.
94 (defun read-string-as-words (stream string
&optional
(length (length string
)))
95 #+sb-xc-host
(bug "READ-STRING-AS-WORDS called")
99 ;; FIXME: is this the same as READ-WORD-ARG?
100 (dotimes (k sb
!vm
:n-word-bytes
(sb!xc
:code-char code
))
101 (setf code
(logior code
(ash (read-byte stream
)
102 (* k sb
!vm
:n-byte-bits
))))))))
105 ;;;; miscellaneous fops
107 ;;; FIXME: POP-STACK should be called something more mnemonic. (POP-FOP-STACK?
108 ;;; But that would conflict with PUSH-FOP-TABLE. Something, anyway..)
110 ;;; Setting this variable causes execution of a FOP-NOP4 to produce
111 ;;; output to *DEBUG-IO*. This can be handy when trying to follow the
112 ;;; progress of FASL loading.
114 (defvar *show-fop-nop4-p
* nil
)
116 ;;; CMU CL had a single no-op fop, FOP-NOP, with fop code 0. Since 0
117 ;;; occurs disproportionately often in fasl files for other reasons,
118 ;;; FOP-NOP is less than ideal for writing human-readable patterns
119 ;;; into fasl files for debugging purposes. There's no shortage of
120 ;;; unused fop codes, so we add this second NOP, which reads 4
121 ;;; arbitrary bytes and discards them.
122 (define-fop (fop-nop4 137 :stackp nil
)
123 (let ((arg (read-arg 4)))
124 (declare (ignorable arg
))
126 (when *show-fop-nop4-p
*
127 (format *debug-io
* "~&/FOP-NOP4 ARG=~W=#X~X~%" arg arg
))))
129 (define-fop (fop-nop 0 :stackp nil
))
130 (define-fop (fop-pop 1 :pushp nil
) (push-fop-table (pop-stack)))
131 (define-fop (fop-push 2) (svref *current-fop-table
* (read-word-arg)))
132 (define-fop (fop-byte-push 3) (svref *current-fop-table
* (read-byte-arg)))
134 (define-fop (fop-empty-list 4) ())
135 (define-fop (fop-truth 5) t
)
136 ;;; CMU CL had FOP-POP-FOR-EFFECT as fop 65, but it was never used and seemed
137 ;;; to have no possible use.
138 (define-fop (fop-misc-trap 66)
139 #+sb-xc-host
; since xc host doesn't know how to compile %PRIMITIVE
140 (error "FOP-MISC-TRAP can't be defined without %PRIMITIVE.")
142 (%primitive sb
!c
:make-other-immediate-type
0 sb
!vm
:unbound-marker-widetag
))
144 (define-cloned-fops (fop-character 68) (fop-short-character 69)
145 (code-char (clone-arg)))
147 (define-cloned-fops (fop-struct 48) (fop-small-struct 49)
148 (let* ((size (clone-arg))
149 (res (%make-instance size
)))
150 (declare (type index size
))
151 (let* ((layout (pop-stack))
152 (nuntagged (layout-n-untagged-slots layout
))
153 (ntagged (- size nuntagged
)))
154 (setf (%instance-ref res
0) layout
)
155 (dotimes (n (1- ntagged
))
156 (declare (type index n
))
157 (setf (%instance-ref res
(1+ n
)) (pop-stack)))
158 (dotimes (n nuntagged
)
159 (declare (type index n
))
160 (setf (%raw-instance-ref
/word res
(- nuntagged n
1)) (pop-stack))))
163 (define-fop (fop-layout 45)
164 (let ((nuntagged (pop-stack))
166 (depthoid (pop-stack))
167 (inherits (pop-stack))
169 (find-and-init-or-check-layout name length inherits depthoid nuntagged
)))
171 (define-fop (fop-end-group 64 :stackp nil
)
172 (/show0
"THROWing FASL-GROUP-END")
173 (throw 'fasl-group-end t
))
175 ;;; In the normal loader, we just ignore these. GENESIS overwrites
176 ;;; FOP-MAYBE-COLD-LOAD with something that knows whether to revert to
177 ;;; cold-loading or not.
178 (define-fop (fop-normal-load 81 :stackp nil
))
179 (define-fop (fop-maybe-cold-load 82 :stackp nil
))
181 (define-fop (fop-verify-table-size 62 :stackp nil
)
182 (let ((expected-index (read-word-arg)))
183 (unless (= *current-fop-table-index
* expected-index
)
184 (bug "fasl table of improper size"))))
185 (define-fop (fop-verify-empty-stack 63 :stackp nil
)
186 (unless (zerop (length *fop-stack
*))
187 (bug "fasl stack not empty when it should be")))
189 ;;;; fops for loading symbols
191 (macrolet (;; FIXME: Should all this code really be duplicated inside
192 ;; each fop? Perhaps it would be better for this shared
193 ;; code to live in FLET FROB1 and FLET FROB4 (for the
194 ;; two different sizes of counts).
195 (frob (name code name-size package
)
196 (let ((n-package (gensym))
199 `(define-fop (,name
,code
)
200 (prepare-for-fast-read-byte *fasl-input-stream
*
201 (let ((,n-package
,package
)
202 (,n-size
(fast-read-u-integer ,name-size
)))
203 (when (> ,n-size
(length *fasl-symbol-buffer
*))
204 (setq *fasl-symbol-buffer
*
205 (make-string (* ,n-size
2))))
206 (done-with-fast-read-byte)
207 (let ((,n-buffer
*fasl-symbol-buffer
*))
209 (read-string-as-bytes *fasl-input-stream
*
213 (#!+sb-unicode read-string-as-words
214 #!-sb-unicode read-string-as-bytes
218 (push-fop-table (without-package-locks
223 ;; Note: CMU CL had FOP-SYMBOL-SAVE and FOP-SMALL-SYMBOL-SAVE, but
224 ;; since they made the behavior of the fasloader depend on the
225 ;; *PACKAGE* variable, not only were they a pain to support (because
226 ;; they required various hacks to handle *PACKAGE*-manipulation
227 ;; forms) they were basically broken by design, because ANSI gives
228 ;; the user so much flexibility in manipulating *PACKAGE* at
229 ;; load-time that no reasonable hacks could possibly make things
230 ;; work right. The ones used in CMU CL certainly didn't, as shown by
232 ;; (IN-PACKAGE :CL-USER)
233 ;; (DEFVAR CL::*FOO* 'FOO-VALUE)
234 ;; (EVAL-WHEN (:COMPILE-TOPLEVEL :LOAD-TOPLEVEL :EXECUTE)
235 ;; (SETF *PACKAGE* (FIND-PACKAGE :CL)))
236 ;; which in CMU CL 2.4.9 defines a variable CL-USER::*FOO* instead of
237 ;; defining CL::*FOO*. Therefore, we don't use those fops in SBCL.
238 ;;(frob fop-symbol-save 6 4 *package*)
239 ;;(frob fop-small-symbol-save 7 1 *package*)
241 (frob fop-lisp-symbol-save
75 #.sb
!vm
:n-word-bytes
*cl-package
*)
242 (frob fop-lisp-small-symbol-save
76 1 *cl-package
*)
243 (frob fop-keyword-symbol-save
77 #.sb
!vm
:n-word-bytes
*keyword-package
*)
244 (frob fop-keyword-small-symbol-save
78 1 *keyword-package
*)
246 ;; FIXME: Because we don't have FOP-SYMBOL-SAVE any more, an enormous number
247 ;; of symbols will fall through to this case, probably resulting in bloated
249 ;; FOP-SYMBOL-IN-LAST-PACKAGE-SAVE/FOP-SMALL-SYMBOL-IN-LAST-PACKAGE-SAVE
250 ;; cloned fop pair could undo some of this bloat.
251 (frob fop-symbol-in-package-save
8 #.sb
!vm
:n-word-bytes
252 (svref *current-fop-table
* (fast-read-u-integer #.sb
!vm
:n-word-bytes
)))
253 (frob fop-small-symbol-in-package-save
9 1
254 (svref *current-fop-table
* (fast-read-u-integer #.sb
!vm
:n-word-bytes
)))
255 (frob fop-symbol-in-byte-package-save
10 #.sb
!vm
:n-word-bytes
256 (svref *current-fop-table
* (fast-read-u-integer 1)))
257 (frob fop-small-symbol-in-byte-package-save
11 1
258 (svref *current-fop-table
* (fast-read-u-integer 1))))
260 (define-cloned-fops (fop-uninterned-symbol-save 12)
261 (fop-uninterned-small-symbol-save 13)
262 (let* ((arg (clone-arg))
263 (res (make-string arg
)))
265 (read-string-as-bytes *fasl-input-stream
* res
)
267 (read-string-as-words *fasl-input-stream
* res
)
268 (push-fop-table (make-symbol res
))))
270 (define-fop (fop-package 14)
271 (find-undeleted-package-or-lose (pop-stack)))
273 ;;;; fops for loading numbers
275 ;;; Load a signed integer LENGTH bytes long from *FASL-INPUT-STREAM*.
276 (defun load-s-integer (length)
277 (declare (fixnum length
))
278 ;; #+cmu (declare (optimize (inhibit-warnings 2)))
279 (do* ((index length
(1- index
))
280 (byte 0 (read-byte *fasl-input-stream
*))
281 (result 0 (+ result
(ash byte bits
)))
284 (if (logbitp 7 byte
) ; look at sign bit
285 (- result
(ash 1 bits
))
287 (declare (fixnum index byte bits
))))
289 (define-cloned-fops (fop-integer 33) (fop-small-integer 34)
290 (load-s-integer (clone-arg)))
292 (define-fop (fop-word-integer 35)
293 (prepare-for-fast-read-byte *fasl-input-stream
*
295 (fast-read-s-integer #.sb
!vm
:n-word-bytes
)
296 (done-with-fast-read-byte))))
298 (define-fop (fop-byte-integer 36)
299 (prepare-for-fast-read-byte *fasl-input-stream
*
301 (fast-read-s-integer 1)
302 (done-with-fast-read-byte))))
304 (define-fop (fop-ratio 70)
305 (let ((den (pop-stack)))
306 (%make-ratio
(pop-stack) den
)))
308 (define-fop (fop-complex 71)
309 (let ((im (pop-stack)))
310 (%make-complex
(pop-stack) im
)))
312 (macrolet ((fast-read-single-float ()
313 '(make-single-float (fast-read-s-integer 4)))
314 (fast-read-double-float ()
315 '(let ((lo (fast-read-u-integer 4)))
316 (make-double-float (fast-read-s-integer 4) lo
))))
317 (macrolet ((define-complex-fop (name fop-code type
)
318 (let ((reader (symbolicate "FAST-READ-" type
)))
319 `(define-fop (,name
,fop-code
)
320 (prepare-for-fast-read-byte *fasl-input-stream
*
322 (complex (,reader
) (,reader
))
323 (done-with-fast-read-byte))))))
324 (define-float-fop (name fop-code type
)
325 (let ((reader (symbolicate "FAST-READ-" type
)))
326 `(define-fop (,name
,fop-code
)
327 (prepare-for-fast-read-byte *fasl-input-stream
*
330 (done-with-fast-read-byte)))))))
331 (define-complex-fop fop-complex-single-float
72 single-float
)
332 (define-complex-fop fop-complex-double-float
73 double-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
)
338 (define-float-fop fop-long-float
52 long-float
)))
343 (define-fop (fop-list 15)
344 (do ((res () (cons (pop-stack) res
))
345 (n (read-byte-arg) (1- n
)))
347 (declare (type index n
))))
349 (define-fop (fop-list* 16)
350 (do ((res (pop-stack) (cons (pop-stack) res
))
351 (n (read-byte-arg) (1- n
)))
353 (declare (type index n
))))
355 (macrolet ((frob (name op fun n
)
356 `(define-fop (,name
,op
)
357 (call-with-popped-args ,fun
,n
))))
359 (frob fop-list-1
17 list
1)
360 (frob fop-list-2
18 list
2)
361 (frob fop-list-3
19 list
3)
362 (frob fop-list-4
20 list
4)
363 (frob fop-list-5
21 list
5)
364 (frob fop-list-6
22 list
6)
365 (frob fop-list-7
23 list
7)
366 (frob fop-list-8
24 list
8)
368 (frob fop-list
*-
1 25 list
* 2)
369 (frob fop-list
*-
2 26 list
* 3)
370 (frob fop-list
*-
3 27 list
* 4)
371 (frob fop-list
*-
4 28 list
* 5)
372 (frob fop-list
*-
5 29 list
* 6)
373 (frob fop-list
*-
6 30 list
* 7)
374 (frob fop-list
*-
7 31 list
* 8)
375 (frob fop-list
*-
8 32 list
* 9))
377 ;;;; fops for loading arrays
379 (define-cloned-fops (fop-base-string 37) (fop-small-base-string 38)
380 (let* ((arg (clone-arg))
381 (res (make-string arg
:element-type
'base-char
)))
382 (read-string-as-bytes *fasl-input-stream
* res
)
388 (define-cloned-fops (fop-character-string 161) (fop-small-character-string 162)
389 (bug "CHARACTER-STRING FOP encountered"))
392 (define-cloned-fops (fop-character-string 161) (fop-small-character-string 162)
393 (let* ((arg (clone-arg))
394 (res (make-string arg
)))
395 (read-string-as-words *fasl-input-stream
* res
)
398 (define-cloned-fops (fop-vector 39) (fop-small-vector 40)
399 (let* ((size (clone-arg))
400 (res (make-array size
)))
401 (declare (fixnum size
))
402 (do ((n (1- size
) (1- n
)))
404 (setf (svref res n
) (pop-stack)))
407 (define-fop (fop-array 83)
408 (let* ((rank (read-word-arg))
410 (length (length vec
))
411 (res (make-array-header sb
!vm
:simple-array-widetag rank
)))
412 (declare (simple-array vec
)
413 (type (unsigned-byte #.
(- sb
!vm
:n-word-bits sb
!vm
:n-widetag-bits
)) rank
))
414 (set-array-header res vec length nil
0
416 (dimensions () (cons (pop-stack) dimensions
)))
417 ((zerop i
) dimensions
)
418 (declare (type index i
)))
422 (define-fop (fop-single-float-vector 84)
423 (let* ((length (read-word-arg))
424 (result (make-array length
:element-type
'single-float
)))
425 (read-n-bytes *fasl-input-stream
* result
0 (* length
4))
428 (define-fop (fop-double-float-vector 85)
429 (let* ((length (read-word-arg))
430 (result (make-array length
:element-type
'double-float
)))
431 (read-n-bytes *fasl-input-stream
* result
0 (* length
8))
434 (define-fop (fop-complex-single-float-vector 86)
435 (let* ((length (read-word-arg))
436 (result (make-array length
:element-type
'(complex single-float
))))
437 (read-n-bytes *fasl-input-stream
* result
0 (* length
8))
440 (define-fop (fop-complex-double-float-vector 87)
441 (let* ((length (read-word-arg))
442 (result (make-array length
:element-type
'(complex double-float
))))
443 (read-n-bytes *fasl-input-stream
* result
0 (* length
16))
447 ;;; *** NOT *** the FOP-INT-VECTOR as currently documented in rtguts.
448 ;;; Size must be a directly supported I-vector element size, with no
449 ;;; extra bits. This must be packed according to the local
450 ;;; byte-ordering, allowing us to directly read the bits.
451 (define-fop (fop-int-vector 43)
452 (prepare-for-fast-read-byte *fasl-input-stream
*
453 (let* ((len (fast-read-u-integer #.sb
!vm
:n-word-bytes
))
454 (size (fast-read-byte))
456 (0 (make-array len
:element-type
'nil
))
457 (1 (make-array len
:element-type
'bit
))
458 (2 (make-array len
:element-type
'(unsigned-byte 2)))
459 (4 (make-array len
:element-type
'(unsigned-byte 4)))
460 (7 (prog1 (make-array len
:element-type
'(unsigned-byte 7))
462 (8 (make-array len
:element-type
'(unsigned-byte 8)))
463 (15 (prog1 (make-array len
:element-type
'(unsigned-byte 15))
465 (16 (make-array len
:element-type
'(unsigned-byte 16)))
466 (31 (prog1 (make-array len
:element-type
'(unsigned-byte 31))
468 (32 (make-array len
:element-type
'(unsigned-byte 32)))
469 #!+#.
(cl:if
(cl:= 64 sb
!vm
:n-word-bits
) '(and) '(or))
470 (63 (prog1 (make-array len
:element-type
'(unsigned-byte 63))
472 (64 (make-array len
:element-type
'(unsigned-byte 64)))
473 (t (bug "losing i-vector element size: ~S" size
)))))
474 (declare (type index len
))
475 (done-with-fast-read-byte)
476 (read-n-bytes *fasl-input-stream
*
479 (ceiling (the index
(* size len
)) sb
!vm
:n-byte-bits
))
482 ;;; This is the same as FOP-INT-VECTOR, except this is for signed
484 (define-fop (fop-signed-int-vector 50)
485 (prepare-for-fast-read-byte *fasl-input-stream
*
486 (let* ((len (fast-read-u-integer #.sb
!vm
:n-word-bytes
))
487 (size (fast-read-byte))
489 (8 (make-array len
:element-type
'(signed-byte 8)))
490 (16 (make-array len
:element-type
'(signed-byte 16)))
491 #!+#.
(cl:if
(cl:= 32 sb
!vm
:n-word-bits
) '(and) '(or))
492 (29 (prog1 (make-array len
:element-type
'(unsigned-byte 29))
494 #!+#.
(cl:if
(cl:= 32 sb
!vm
:n-word-bits
) '(and) '(or))
495 (30 (prog1 (make-array len
:element-type
'(signed-byte 30))
497 (32 (make-array len
:element-type
'(signed-byte 32)))
498 #!+#.
(cl:if
(cl:= 64 sb
!vm
:n-word-bits
) '(and) '(or))
499 (60 (prog1 (make-array len
:element-type
'(unsigned-byte 60))
501 #!+#.
(cl:if
(cl:= 64 sb
!vm
:n-word-bits
) '(and) '(or))
502 (61 (prog1 (make-array len
:element-type
'(signed-byte 61))
504 #!+#.
(cl:if
(cl:= 64 sb
!vm
:n-word-bits
) '(and) '(or))
505 (64 (make-array len
:element-type
'(signed-byte 64)))
506 (t (bug "losing si-vector element size: ~S" size
)))))
507 (declare (type index len
))
508 (done-with-fast-read-byte)
509 (read-n-bytes *fasl-input-stream
*
512 (ceiling (the index
(* size len
)) sb
!vm
:n-byte-bits
))
515 (define-fop (fop-eval 53)
518 (let ((result (eval (pop-stack))))
519 ;; FIXME: CMU CL had this code here:
520 ;; (when *load-print*
524 ;; Unfortunately, this dependence on the *LOAD-PRINT* global
525 ;; variable is non-ANSI, so for now we've just punted printing in
529 (define-fop (fop-eval-for-effect 54 :pushp nil
)
532 (let ((result (eval (pop-stack))))
533 ;; FIXME: See the comment about *LOAD-PRINT* in FOP-EVAL.
534 (declare (ignore result
))
535 #+nil
(when *load-print
*
540 (define-fop (fop-funcall 55)
541 (let ((arg (read-byte-arg)))
543 (dotimes (i (1+ arg
))
546 (funcall (pop-stack))
547 (do ((args () (cons (pop-stack) args
))
549 ((zerop n
) (apply (pop-stack) args
))
550 (declare (type index n
)))))))
552 (define-fop (fop-funcall-for-effect 56 :pushp nil
)
553 (let ((arg (read-byte-arg)))
555 (dotimes (i (1+ arg
))
558 (funcall (pop-stack))
559 (do ((args () (cons (pop-stack) args
))
561 ((zerop n
) (apply (pop-stack) args
))
562 (declare (type index n
)))))))
564 ;;;; fops for fixing up circularities
566 (define-fop (fop-rplaca 200 :pushp nil
)
567 (let ((obj (svref *current-fop-table
* (read-word-arg)))
568 (idx (read-word-arg))
570 (setf (car (nthcdr idx obj
)) val
)))
572 (define-fop (fop-rplacd 201 :pushp nil
)
573 (let ((obj (svref *current-fop-table
* (read-word-arg)))
574 (idx (read-word-arg))
576 (setf (cdr (nthcdr idx obj
)) val
)))
578 (define-fop (fop-svset 202 :pushp nil
)
579 (let* ((obi (read-word-arg))
580 (obj (svref *current-fop-table
* obi
))
581 (idx (read-word-arg))
584 (setf (%instance-ref obj idx
) val
)
585 (setf (svref obj idx
) val
))))
587 (define-fop (fop-structset 204 :pushp nil
)
588 (setf (%instance-ref
(svref *current-fop-table
* (read-word-arg))
592 ;;; In the original CMUCL code, this actually explicitly declared PUSHP
593 ;;; to be T, even though that's what it defaults to in DEFINE-FOP.
594 (define-fop (fop-nthcdr 203)
595 (nthcdr (read-word-arg) (pop-stack)))
597 ;;;; fops for loading functions
599 ;;; (In CMU CL there was a FOP-CODE-FORMAT (47) which was
600 ;;; conventionally placed at the beginning of each fasl file to test
601 ;;; for compatibility between the fasl file and the CMU CL which
602 ;;; loaded it. In SBCL, this functionality has been replaced by
603 ;;; putting the implementation and version in required fields in the
604 ;;; fasl file header.)
606 (define-fop (fop-code 58 :stackp nil
)
607 (load-code (read-word-arg) (read-word-arg)))
609 (define-fop (fop-small-code 59 :stackp nil
)
610 (load-code (read-byte-arg) (read-halfword-arg)))
612 (define-fop (fop-fdefinition 60)
613 (fdefinition-object (pop-stack) t
))
615 (define-fop (fop-sanctify-for-execution 61)
616 (let ((component (pop-stack)))
617 (sb!vm
:sanctify-for-execution component
)
620 (define-fop (fop-fset 74 :pushp nil
)
621 ;; Ordinary, not-for-cold-load code shouldn't need to mess with this
622 ;; at all, since it's only used as part of the conspiracy between
623 ;; the cross-compiler and GENESIS to statically link FDEFINITIONs
625 (warn "~@<FOP-FSET seen in ordinary load (not cold load) -- quite strange! ~
626 If you didn't do something strange to cause this, please report it as a ~
628 ;; Unlike CMU CL, we don't treat this as a no-op in ordinary code.
629 ;; If the user (or, more likely, developer) is trying to reload
630 ;; compiled-for-cold-load code into a warm SBCL, we'll do a warm
631 ;; assignment. (This is partly for abstract tidiness, since the warm
632 ;; assignment is the closest analogy to what happens at cold load,
633 ;; and partly because otherwise our compiled-for-cold-load code will
634 ;; fail, since in SBCL things like compiled-for-cold-load %DEFUN
635 ;; depend more strongly than in CMU CL on FOP-FSET actually doing
637 (let ((fn (pop-stack))
639 (setf (fdefinition name
) fn
)))
641 ;;; Modify a slot in a CONSTANTS object.
642 (define-cloned-fops (fop-alter-code 140 :pushp nil
) (fop-byte-alter-code 141)
643 (let ((value (pop-stack))
645 (setf (code-header-ref code
(clone-arg)) value
)
648 (define-fop (fop-fun-entry 142)
649 #+sb-xc-host
; since xc host doesn't know how to compile %PRIMITIVE
650 (error "FOP-FUN-ENTRY can't be defined without %PRIMITIVE.")
652 (let ((xrefs (pop-stack))
654 (arglist (pop-stack))
656 (code-object (pop-stack))
657 (offset (read-word-arg)))
658 (declare (type index offset
))
659 (unless (zerop (logand offset sb
!vm
:lowtag-mask
))
660 (bug "unaligned function object, offset = #X~X" offset
))
661 (let ((fun (%primitive sb
!c
:compute-fun code-object offset
)))
662 (setf (%simple-fun-self fun
) fun
)
663 (setf (%simple-fun-next fun
) (%code-entry-points code-object
))
664 (setf (%code-entry-points code-object
) fun
)
665 (setf (%simple-fun-name fun
) name
)
666 (setf (%simple-fun-arglist fun
) arglist
)
667 (setf (%simple-fun-type fun
) type
)
668 (setf (%simple-fun-xrefs fun
) xrefs
)
669 ;; FIXME: See the comment about *LOAD-PRINT* in FOP-EVAL.
670 #+nil
(when *load-print
*
672 (format t
"~S defined~%" fun
))
675 ;;;; Some Dylan FOPs used to live here. By 1 November 1998 the code
676 ;;;; was sufficiently stale that the functions it called were no
677 ;;;; longer defined, so I (William Harold Newman) deleted it.
679 ;;;; In case someone in the future is trying to make sense of FOP layout,
680 ;;;; it might be worth recording that the Dylan FOPs were
681 ;;;; 100 FOP-DYLAN-SYMBOL-SAVE
682 ;;;; 101 FOP-SMALL-DYLAN-SYMBOL-SAVE
683 ;;;; 102 FOP-DYLAN-KEYWORD-SAVE
684 ;;;; 103 FOP-SMALL-DYLAN-KEYWORD-SAVE
685 ;;;; 104 FOP-DYLAN-VARINFO-VALUE
687 ;;;; assemblerish fops
689 (define-fop (fop-assembler-code 144)
690 (error "cannot load assembler code except at cold load"))
692 (define-fop (fop-assembler-routine 145)
693 (error "cannot load assembler code except at cold load"))
695 (define-fop (fop-foreign-fixup 147)
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
703 (foreign-symbol-address sym
)
707 (define-fop (fop-assembler-fixup 148)
708 (let ((routine (pop-stack))
710 (code-object (pop-stack)))
711 (multiple-value-bind (value found
) (gethash routine
*assembler-routines
*)
713 (error "undefined assembler routine: ~S" routine
))
714 (sb!vm
:fixup-code-object code-object
(read-word-arg) value kind
))
717 (define-fop (fop-code-object-fixup 149)
718 (let ((kind (pop-stack))
719 (code-object (pop-stack)))
720 ;; Note: We don't have to worry about GC moving the code-object after
721 ;; the GET-LISP-OBJ-ADDRESS and before that value is deposited, because
722 ;; we can only use code-object fixups when code-objects don't move.
723 (sb!vm
:fixup-code-object code-object
(read-word-arg)
724 (get-lisp-obj-address code-object
) kind
)
728 (define-fop (fop-foreign-dataref-fixup 150)
729 (let* ((kind (pop-stack))
730 (code-object (pop-stack))
731 (len (read-byte-arg))
732 (sym (make-string len
:element-type
'base-char
)))
733 (read-n-bytes *fasl-input-stream
* sym
0 len
)
734 (sb!vm
:fixup-code-object code-object
736 (foreign-symbol-address sym t
)
740 ;;; FOPs needed for implementing an IF operator in a FASL
742 ;;; Skip until a FOP-MAYBE-STOP-SKIPPING with the same POSITION is
743 ;;; executed. While skipping, we execute most FOPs normally, except
744 ;;; for ones that a) funcall/eval b) start skipping. This needs to
745 ;;; be done to ensure that the fop table gets populated correctly
746 ;;; regardless of the execution path.
747 (define-fop (fop-skip 151 :pushp nil
)
748 (let ((position (pop-stack)))
750 (setf *skip-until
* position
)))
753 ;;; As before, but only start skipping if the top of the FOP stack is NIL.
754 (define-fop (fop-skip-if-false 152 :pushp nil
)
755 (let ((condition (pop-stack))
756 (position (pop-stack)))
757 (unless (or condition
759 (setf *skip-until
* position
)))
762 ;;; If skipping, pop the top of the stack and discard it. Needed for
763 ;;; ensuring that the stack stays balanced when skipping.
764 (define-fop (fop-drop-if-skipping 153 :pushp nil
)
769 ;;; If skipping, push a dummy value on the stack. Needed for
770 ;;; ensuring that the stack stays balanced when skipping.
771 (define-fop (fop-push-nil-if-skipping 154 :pushp nil
)
776 ;;; Stop skipping if the top of the stack matches *SKIP-UNTIL*
777 (define-fop (fop-maybe-stop-skipping 155 :pushp nil
)
778 (let ((label (pop-stack)))
779 (when (eql *skip-until
* label
)
780 (setf *skip-until
* nil
)))