5 ;;; Bind STACK-VAR and PTR-VAR to the start of a subsequence of
6 ;;; the fop stack of length COUNT, then execute BODY.
7 ;;; Within the body, FOP-STACK-REF is used in lieu of SVREF
8 ;;; to elide bounds checking.
9 (defmacro with-fop-stack
(((stack-var &optional stack-expr
) ptr-var count
)
11 `(let* (,@(when stack-expr
12 (list `(,stack-var
(the simple-vector
,stack-expr
))))
13 (,ptr-var
(truly-the index
(fop-stack-pop-n ,stack-var
,count
))))
14 (macrolet ((fop-stack-ref (i)
17 (declare (optimize (sb!c
::insert-array-bounds-checks
0)))
18 (svref ,',stack-var
(truly-the index
,i
)))))
21 ;;; Define NAME as a fasl operation, with op-code FOP-CODE. PUSHP
22 ;;; describes what the body does to the fop stack:
24 ;;; The body might pop the fop stack. The result of the body is
25 ;;; pushed on the fop stack.
27 ;;; The body might pop the fop stack. The result of the body is
30 (defmacro !define-fop
(fop-code (name &optional arglist
(pushp t
)) &body forms
)
31 (aver (member pushp
'(nil t
)))
32 (multiple-value-bind (operands stack-args
)
33 (if (consp (car arglist
))
35 (:operands
(values (cdar arglist
) (cdr arglist
))))
37 (assert (<= (length operands
) 2))
39 (defun ,name
(.fasl-input.
,@operands
)
40 (declare (ignorable .fasl-input.
))
41 (macrolet ((fasl-input () '(truly-the fasl-input .fasl-input.
))
42 (fasl-input-stream () '(%fasl-input-stream
(fasl-input)))
43 (operand-stack () '(%fasl-input-stack
(fasl-input)))
44 (skip-until () '(%fasl-input-skip-until
(fasl-input))))
45 ,@(if (null stack-args
)
47 (with-unique-names (stack ptr
)
48 `((with-fop-stack ((,stack
(operand-stack))
49 ,ptr
,(length stack-args
))
50 (multiple-value-bind ,stack-args
51 (values ,@(loop for i below
(length stack-args
)
52 collect
`(fop-stack-ref (+ ,ptr
,i
))))
54 (!%define-fop
',name
,fop-code
,(length operands
) ,(if pushp
1 0)))))
56 (defun !%define-fop
(name base-opcode n-operands pushp
)
57 (declare (type (mod 3) n-operands
)) ; 0, 1, or 2 are allowed
58 (let ((n-slots (expt 4 n-operands
)))
59 (unless (zerop (mod base-opcode n-slots
))
60 (error "Opcode for fop ~S must be a multiple of ~D" name n-slots
))
61 (loop for opcode from base-opcode below
(+ base-opcode n-slots
)
62 when
(functionp (svref **fop-funs
** opcode
))
63 do
(let ((oname (svref **fop-names
** opcode
)))
64 (when (and oname
(not (eq oname name
)))
65 (error "fop ~S with opcode ~D conflicts with fop ~S."
67 (let ((existing-opcode (get name
'opcode
)))
68 (when (and existing-opcode
(/= existing-opcode base-opcode
))
69 (error "multiple codes for fop name ~S: ~D and ~D"
70 name base-opcode existing-opcode
)))
71 (setf (get name
'opcode
) base-opcode
)
72 ;; The low 2 bits of the opcode comprise the length modifier if there is
73 ;; exactly one operand. Such opcodes are aligned in blocks of 4.
74 ;; 2-operand fops occupy 16 slots in a reserved range of the function table.
76 (let ((opcode (+ base-opcode j
)))
77 (setf (svref **fop-names
** opcode
) name
78 (svref **fop-funs
** opcode
) (symbol-function name
)
79 (sbit (car **fop-signatures
**) (ash opcode -
2)) (signum n-operands
)
80 (sbit (cdr **fop-signatures
**) opcode
) pushp
))))
83 ;;; a helper function for reading string values from FASL files: sort
84 ;;; of like READ-SEQUENCE specialized for files of (UNSIGNED-BYTE 8),
85 ;;; with an automatic conversion from (UNSIGNED-BYTE 8) into CHARACTER
86 ;;; for each element read
87 (defun read-string-as-bytes (stream string
&optional
(length (length string
)))
88 (declare (type (simple-array character
(*)) string
)
91 (with-fast-read-byte ((unsigned-byte 8) stream
)
94 (sb!xc
:code-char
(fast-read-byte)))))
96 (defun read-base-string-as-bytes (stream string
&optional
(length (length string
)))
97 (declare (type (simple-array base-char
(*)) string
)
100 (with-fast-read-byte ((unsigned-byte 8) stream
)
102 (setf (aref string i
)
103 (sb!xc
:code-char
(fast-read-byte)))))
106 (defun read-string-as-unsigned-byte-32
107 (stream string
&optional
(length (length string
)))
108 (declare (type (simple-array character
(*)) string
)
111 #+sb-xc-host
(bug "READ-STRING-AS-UNSIGNED-BYTE-32 called")
112 (with-fast-read-byte ((unsigned-byte 8) stream
)
114 (setf (aref string i
)
115 (sb!xc
:code-char
(fast-read-u-integer 4)))))
118 ;;;; miscellaneous fops
120 ;;; Setting this variable causes execution of a FOP-NOP4 to produce
121 ;;; output to *DEBUG-IO*. This can be handy when trying to follow the
122 ;;; progress of FASL loading.
124 (defvar *show-fop-nop4-p
* nil
)
126 ;;; CMU CL had a single no-op fop, FOP-NOP, with fop code 0. Since 0
127 ;;; occurs disproportionately often in fasl files for other reasons,
128 ;;; FOP-NOP is less than ideal for writing human-readable patterns
129 ;;; into fasl files for debugging purposes. There's no shortage of
130 ;;; unused fop codes, so we add this second NOP, which reads 4
131 ;;; arbitrary bytes and discards them.
132 (!define-fop
137 (fop-nop4 () nil
)
133 (let ((arg (read-arg 4 (fasl-input-stream))))
134 (declare (ignorable arg
))
136 (when *show-fop-nop4-p
*
137 (format *debug-io
* "~&/FOP-NOP4 ARG=~W=#X~X~%" arg arg
))))
139 (!define-fop
0 (fop-nop () nil
))
140 (!define-fop
1 (fop-pop (x) nil
) (push-fop-table x
(fasl-input)))
141 (!define-fop
2 (fop-empty-list) nil
)
142 (!define-fop
3 (fop-truth) t
)
143 (!define-fop
4 (fop-push ((:operands index
)))
144 (ref-fop-table (fasl-input) index
))
146 ;;; CMU CL had FOP-POP-FOR-EFFECT as fop 65, but it was never used and seemed
147 ;;; to have no possible use.
148 (!define-fop
66 (fop-misc-trap)
149 #+sb-xc-host
; since xc host doesn't know how to compile %PRIMITIVE
150 (error "FOP-MISC-TRAP can't be defined without %PRIMITIVE.")
152 (%primitive sb
!c
:make-unbound-marker
))
154 (!define-fop
76 (fop-character ((:operands char-code
)))
155 (code-char char-code
))
157 (!define-fop
48 (fop-struct ((:operands size
) layout
))
158 (let* ((res (%make-instance size
)) ; number of words excluding header
159 ;; Compute count of elements to pop from stack, sans layout.
160 ;; If instance-data-start is 0, then size is the count,
161 ;; otherwise subtract 1 because the layout consumes a slot.
162 (n-data-words (- size sb
!vm
:instance-data-start
)))
163 (declare (type index size
))
164 (with-fop-stack ((stack (operand-stack)) ptr n-data-words
)
165 (let ((ptr (+ ptr n-data-words
)))
166 (declare (type index ptr
))
167 (setf (%instance-layout res
) layout
)
168 #!-interleaved-raw-slots
169 (let* ((nuntagged (layout-n-untagged-slots layout
))
170 (ntagged (- size nuntagged
)))
171 (dotimes (n (1- ntagged
))
172 (declare (type index n
))
173 (setf (%instance-ref res
(1+ n
)) (fop-stack-ref (decf ptr
))))
174 (dotimes (n nuntagged
)
175 (declare (type index n
))
176 (setf (%raw-instance-ref
/word res
(- nuntagged n
1))
177 (fop-stack-ref (decf ptr
)))))
178 #!+interleaved-raw-slots
179 (let ((metadata (layout-untagged-bitmap layout
)))
180 (do ((i sb
!vm
:instance-data-start
(1+ i
)))
182 (declare (type index i
))
183 (let ((val (fop-stack-ref (decf ptr
))))
184 (if (logbitp i metadata
)
185 (setf (%raw-instance-ref
/word res i
) val
)
186 (setf (%instance-ref res i
) val
)))))))
189 (!define-fop
45 (fop-layout (name inherits depthoid length metadata
))
190 (find-and-init-or-check-layout name length inherits depthoid metadata
))
192 ;; Allocate a CLOS object. This is used when the compiler detects that
193 ;; MAKE-LOAD-FORM returned a simple use of MAKE-LOAD-FORM-SAVING-SLOTS,
194 ;; or possibly a hand-written equivalent (however unlikely).
195 (!define-fop
68 (fop-allocate-instance (name) nil
)
196 (let ((instance (allocate-instance (find-class (the symbol name
)))))
197 (push-fop-table instance
(fasl-input))))
199 ;; Fill in object slots as dictated by the second return value from
200 ;; MAKE-LOAD-FORM-SAVING-SLOTS.
201 ;; This wants a 'count' as the first item in the SLOT-NAMES argument
202 ;; rather than using read-arg because many calls of this might share
203 ;; the list, which must be constructed into the fop-table no matter what.
204 (!define-fop
69 (fop-initialize-instance (slot-names obj
) nil
)
205 (let* ((n-slots (pop slot-names
))
206 (stack (operand-stack))
207 (ptr (fop-stack-pop-n stack n-slots
)))
209 (let ((val (svref stack
(+ ptr i
)))
210 (slot-name (pop slot-names
)))
211 (if (eq val
'sb
!pcl
::..slot-unbound..
)
212 ;; SLOT-MAKUNBOUND-USING-CLASS might do something nonstandard.
213 (slot-makunbound obj slot-name
)
214 ;; FIXME: the DEFSETF for this isn't defined until warm load
215 (sb!pcl
::set-slot-value obj slot-name val
))))))
217 (!define-fop
64 (fop-end-group () nil
)
218 (/show0
"THROWing FASL-GROUP-END")
219 (throw 'fasl-group-end t
))
221 ;;; We used to have FOP-NORMAL-LOAD as 81 and FOP-MAYBE-COLD-LOAD as
222 ;;; 82 until GENESIS learned how to work with host symbols and
223 ;;; packages directly instead of piggybacking on the host code.
225 (!define-fop
62 (fop-verify-table-size () nil
)
226 (let ((expected-index (read-word-arg (fasl-input-stream))))
227 (unless (= (svref (%fasl-input-table
(fasl-input)) 0) expected-index
)
228 (bug "fasl table of improper size"))))
229 (!define-fop
63 (fop-verify-empty-stack () nil
)
230 (unless (fop-stack-empty-p (operand-stack))
231 (bug "fasl stack not empty when it should be")))
233 ;;;; fops for loading symbols
235 (defstruct (undefined-package
239 (declaim (freeze-type undefined-package
))
241 (defun aux-fop-intern (size package fasl-input
)
242 (declare (optimize speed
))
243 (let ((input-stream (%fasl-input-stream fasl-input
))
244 (buffer (make-string size
)))
246 (read-string-as-bytes input-stream buffer size
)
250 (read-string-as-unsigned-byte-32 input-stream buffer size
)
252 (read-string-as-bytes input-stream buffer size
))
253 (if (undefined-package-p package
)
254 (error 'simple-package-error
255 :format-control
"Error finding package for symbol ~s:~% ~a"
257 (list (subseq buffer
0 size
)
258 (undefined-package-error package
)))
259 (push-fop-table (without-package-locks
263 :no-copy t
)) fasl-input
))))
265 (!define-fop
80 (fop-lisp-symbol-save ((:operands namelen
)))
266 (aux-fop-intern namelen
*cl-package
* (fasl-input)))
267 (!define-fop
84 (fop-keyword-symbol-save ((:operands namelen
)))
268 (aux-fop-intern namelen
*keyword-package
* (fasl-input)))
270 ;; But srsly? Most of the space is wasted by UCS4 encoding of ASCII.
271 ;; An extra word per symbol for the package is nothing by comparison.
272 ;; FIXME: Because we don't have FOP-SYMBOL-SAVE any more, an
273 ;; enormous number of symbols will fall through to this case,
274 ;; probably resulting in bloated fasl files. A new
275 ;; FOP-SYMBOL-IN-LAST-PACKAGE-SAVE/FOP-SMALL-SYMBOL-IN-LAST-PACKAGE-SAVE
276 ;; cloned fop pair could undo some of this bloat.
277 (!define-fop
#xF0
(fop-symbol-in-package-save ((:operands pkg-index namelen
)))
278 (aux-fop-intern namelen
(ref-fop-table (fasl-input) pkg-index
) (fasl-input)))
280 (!define-fop
96 (fop-uninterned-symbol-save ((:operands namelen
)))
281 (let ((res (make-string namelen
)))
283 (read-string-as-bytes (fasl-input-stream) res
)
285 (read-string-as-unsigned-byte-32 (fasl-input-stream) res
)
286 (push-fop-table (make-symbol res
) (fasl-input))))
288 (!define-fop
104 (fop-copy-symbol-save ((:operands table-index
)))
289 (push-fop-table (copy-symbol (ref-fop-table (fasl-input) table-index
))
292 (!define-fop
44 (fop-package (pkg-designator))
293 (find-undeleted-package-or-lose pkg-designator
))
295 (!define-fop
156 (fop-named-package-save ((:operands length
)) nil
)
296 (let ((package-name (make-string length
)))
298 (read-string-as-bytes (fasl-input-stream) package-name
)
302 (read-string-as-bytes (fasl-input-stream) package-name
)
304 (read-string-as-unsigned-byte-32 (fasl-input-stream) package-name
))
306 (handler-case (find-undeleted-package-or-lose package-name
)
307 (simple-package-error (c)
308 (make-undefined-package :error
(princ-to-string c
))))
311 ;;;; fops for loading numbers
313 ;;; Load a signed integer LENGTH bytes long from FASL-INPUT-STREAM.
314 (defun load-s-integer (length fasl-input-stream
)
315 (declare (fixnum length
)
317 (with-fast-read-byte ((unsigned-byte 8) fasl-input-stream
)
318 (do* ((index length
(1- index
))
319 (byte 0 (fast-read-byte))
320 (result 0 (+ result
(ash byte bits
)))
323 (if (logbitp 7 byte
) ; look at sign bit
324 (- result
(ash 1 bits
))
326 (declare (fixnum index byte bits
)))))
328 (!define-fop
36 (fop-integer ((:operands n-bytes
)))
329 (load-s-integer n-bytes
(fasl-input-stream)))
331 (!define-fop
34 (fop-word-integer)
332 (with-fast-read-byte ((unsigned-byte 8) (fasl-input-stream))
333 (fast-read-s-integer #.sb
!vm
:n-word-bytes
)))
335 (!define-fop
35 (fop-byte-integer)
336 ;; FIXME: WITH-FAST-READ-BYTE for exactly 1 byte is not really faster/better
337 ;; than regular READ-BYTE. The expansion of READ-ARG corroborates this claim.
338 (with-fast-read-byte ((unsigned-byte 8) (fasl-input-stream))
339 (fast-read-s-integer 1)))
341 (!define-fop
70 (fop-ratio (num den
)) (%make-ratio num den
))
343 (!define-fop
71 (fop-complex (realpart imagpart
))
344 (%make-complex realpart imagpart
))
346 (macrolet ((fast-read-single-float ()
347 '(make-single-float (fast-read-s-integer 4)))
348 (fast-read-double-float ()
349 '(let ((lo (fast-read-u-integer 4)))
350 (make-double-float (fast-read-s-integer 4) lo
))))
351 (macrolet ((define-complex-fop (opcode name type
)
352 (let ((reader (symbolicate "FAST-READ-" type
)))
353 `(!define-fop
,opcode
(,name
)
354 (with-fast-read-byte ((unsigned-byte 8) (fasl-input-stream))
355 (complex (,reader
) (,reader
))))))
356 (define-float-fop (opcode name type
)
357 (let ((reader (symbolicate "FAST-READ-" type
)))
358 `(!define-fop
,opcode
(,name
)
359 (with-fast-read-byte ((unsigned-byte 8) (fasl-input-stream))
361 (define-complex-fop 72 fop-complex-single-float single-float
)
362 (define-complex-fop 73 fop-complex-double-float double-float
)
364 (define-complex-fop 67 fop-complex-long-float long-float
)
365 (define-float-fop 46 fop-single-float single-float
)
366 (define-float-fop 47 fop-double-float double-float
)
368 (define-float-fop 52 fop-long-float long-float
)))
371 (!define-fop
88 (fop-simd-pack)
372 (with-fast-read-byte ((unsigned-byte 8) (fasl-input-stream))
373 (%make-simd-pack
(fast-read-s-integer 8)
374 (fast-read-u-integer 8)
375 (fast-read-u-integer 8))))
379 (defun fop-list-from-stack (stack n
)
380 ;; N is 0-255 when called from FOP-LIST,
381 ;; but it is as large as ARRAY-RANK-LIMIT in FOP-ARRAY.
382 (declare (type (unsigned-byte 16) n
)
383 (optimize (speed 3)))
384 (with-fop-stack ((stack) ptr n
)
385 (do* ((i (+ ptr n
) (1- i
))
386 (res () (cons (fop-stack-ref i
) res
)))
388 (declare (type index i
)))))
390 (!define-fop
33 (fop-list)
391 (fop-list-from-stack (operand-stack) (read-byte-arg (fasl-input-stream))))
392 (!define-fop
16 (fop-list*)
393 ;; N is the number of cons cells (0 is ok)
394 (let ((n (read-byte-arg (fasl-input-stream))))
395 (with-fop-stack ((stack (operand-stack)) ptr
(1+ n
))
396 (do* ((i (+ ptr n
) (1- i
))
397 (res (fop-stack-ref (+ ptr n
))
398 (cons (fop-stack-ref i
) res
)))
400 (declare (type index i
))))))
402 (macrolet ((frob (name op fun n
)
403 (let ((args (make-gensym-list n
)))
404 `(!define-fop
,op
(,name
,args
) (,fun
,@args
)))))
406 (frob fop-list-1
17 list
1)
407 (frob fop-list-2
18 list
2)
408 (frob fop-list-3
19 list
3)
409 (frob fop-list-4
20 list
4)
410 (frob fop-list-5
21 list
5)
411 (frob fop-list-6
22 list
6)
412 (frob fop-list-7
23 list
7)
413 (frob fop-list-8
24 list
8)
415 (frob fop-list
*-
1 25 list
* 2)
416 (frob fop-list
*-
2 26 list
* 3)
417 (frob fop-list
*-
3 27 list
* 4)
418 (frob fop-list
*-
4 28 list
* 5)
419 (frob fop-list
*-
5 29 list
* 6)
420 (frob fop-list
*-
6 30 list
* 7)
421 (frob fop-list
*-
7 31 list
* 8)
422 (frob fop-list
*-
8 32 list
* 9))
424 ;;;; fops for loading arrays
426 (!define-fop
100 (fop-base-string ((:operands length
)))
427 (let ((res (make-string length
:element-type
'base-char
)))
428 (read-base-string-as-bytes (fasl-input-stream) res
)
432 ;; FIXME: can save space by UTF-8 encoding, or use 1 bit to indicate pure ASCII
433 ;; in the fasl even though the result will be a non-base string.
436 (!define-fop
160 (fop-character-string ((:operands length
)))
437 length
; touch the argument to avoid style-warning
438 (bug "CHARACTER-STRING FOP encountered"))
441 (!define-fop
160 (fop-character-string ((:operands length
)))
442 (let ((res (make-string length
)))
443 (read-string-as-unsigned-byte-32 (fasl-input-stream) res
)
446 (!define-fop
92 (fop-vector ((:operands size
)))
447 (let ((res (make-array size
))
448 (stack (operand-stack)))
449 (declare (fixnum size
))
451 (let ((ptr (fop-stack-pop-n stack size
)))
452 (replace res stack
:start2 ptr
)))
455 (!define-fop
89 (fop-array (vec))
456 (let* ((rank (read-word-arg (fasl-input-stream)))
457 (length (length vec
))
458 (res (make-array-header sb
!vm
:simple-array-widetag rank
)))
459 (declare (simple-array vec
)
460 (type (unsigned-byte #.
(- sb
!vm
:n-word-bits sb
!vm
:n-widetag-bits
)) rank
))
461 (set-array-header res vec length nil
0
462 (fop-list-from-stack (operand-stack) rank
)
466 (defglobal **saetp-bits-per-length
**
467 (let ((array (make-array (1+ sb
!vm
:widetag-mask
)
468 :element-type
'(unsigned-byte 8)
469 :initial-element
255)))
470 (loop for saetp across sb
!vm
:*specialized-array-element-type-properties
*
472 (setf (aref array
(sb!vm
:saetp-typecode saetp
))
473 (sb!vm
:saetp-n-bits saetp
)))
476 "255 means bad entry.")
477 (declaim (type (simple-array (unsigned-byte 8) (#.
(1+ sb
!vm
:widetag-mask
)))
478 **saetp-bits-per-length
**))
480 (!define-fop
43 (fop-spec-vector)
481 (let* ((length (read-word-arg (fasl-input-stream)))
482 (widetag (read-byte-arg (fasl-input-stream)))
483 (bits-per-length (aref **saetp-bits-per-length
** widetag
))
484 (bits (progn (aver (< bits-per-length
255))
485 (* length bits-per-length
)))
486 (bytes (ceiling bits sb
!vm
:n-byte-bits
))
487 (words (ceiling bytes sb
!vm
:n-word-bytes
))
488 (vector (allocate-vector widetag length words
)))
489 (declare (type index length bytes words
)
491 (read-n-bytes (fasl-input-stream) vector
0 bytes
)
494 (!define-fop
53 (fop-eval (expr)) ; This seems to be unused
499 (!define-fop
54 (fop-eval-for-effect (expr) nil
) ; This seems to be unused
504 (defun fop-funcall* (input-stream stack skipping
)
505 (let ((argc (read-byte-arg input-stream
)))
506 (with-fop-stack ((stack) ptr
(1+ argc
))
508 (do ((i (+ ptr argc
))
510 ((= i ptr
) (apply (fop-stack-ref i
) args
))
511 (declare (type index i
))
512 (push (fop-stack-ref i
) args
)
515 ;; FIXME: there should be a syntax to share these identical bodies
516 (!define-fop
55 (fop-funcall)
517 (fop-funcall* (fasl-input-stream) (operand-stack) (skip-until)))
518 (!define-fop
56 (fop-funcall-for-effect () nil
)
519 (fop-funcall* (fasl-input-stream) (operand-stack) (skip-until)))
521 ;;;; fops for fixing up circularities
523 (!define-fop
200 (fop-rplaca (val) nil
)
524 (let ((obj (ref-fop-table (fasl-input) (read-word-arg (fasl-input-stream))))
525 (idx (read-word-arg (fasl-input-stream))))
526 (setf (car (nthcdr idx obj
)) val
)))
528 (!define-fop
201 (fop-rplacd (val) nil
)
529 (let ((obj (ref-fop-table (fasl-input) (read-word-arg (fasl-input-stream))))
530 (idx (read-word-arg (fasl-input-stream))))
531 (setf (cdr (nthcdr idx obj
)) val
)))
533 (!define-fop
202 (fop-svset (val) nil
)
534 (let* ((obi (read-word-arg (fasl-input-stream)))
535 (obj (ref-fop-table (fasl-input) obi
))
536 (idx (read-word-arg (fasl-input-stream))))
537 (if (%instancep obj
) ; suspicious. should have been FOP-STRUCTSET
538 (setf (%instance-ref obj idx
) val
)
539 (setf (svref obj idx
) val
))))
541 (!define-fop
204 (fop-structset (val) nil
)
542 (setf (%instance-ref
(ref-fop-table (fasl-input)
543 (read-word-arg (fasl-input-stream)))
544 (read-word-arg (fasl-input-stream)))
547 ;;; In the original CMUCL code, this actually explicitly declared PUSHP
548 ;;; to be T, even though that's what it defaults to in DEFINE-FOP.
549 (!define-fop
203 (fop-nthcdr (obj))
550 (nthcdr (read-word-arg (fasl-input-stream)) obj
))
552 ;;;; fops for loading functions
554 ;;; (In CMU CL there was a FOP-CODE-FORMAT (47) which was
555 ;;; conventionally placed at the beginning of each fasl file to test
556 ;;; for compatibility between the fasl file and the CMU CL which
557 ;;; loaded it. In SBCL, this functionality has been replaced by
558 ;;; putting the implementation and version in required fields in the
559 ;;; fasl file header.)
561 (!define-fop
#xE0
(fop-code ((:operands n-boxed-words n-unboxed-bytes
)))
562 (with-fop-stack ((stack (operand-stack)) ptr
(1+ n-boxed-words
))
563 (load-code n-boxed-words n-unboxed-bytes stack ptr
(fasl-input-stream))))
565 ;; this gets you an #<fdefn> object, not the result of (FDEFINITION x)
566 (!define-fop
60 (fop-fdefn (name))
567 (awhen (deprecated-thing-p :function name
) ; returns the stage of deprecation
568 (pushnew (list* it name
:function
)
569 (%fasl-input-deprecated-stuff
(fasl-input)) :test
'equal
))
570 (find-or-create-fdefn name
))
572 (!define-fop
65 (fop-known-fun (name))
573 (%coerce-name-to-fun name
))
576 (!define-fop
61 (fop-sanctify-for-execution (component))
577 (sb!vm
:sanctify-for-execution component
)
580 (!define-fop
174 (fop-note-debug-source (debug-source) nil
)
581 (warn "~@<FOP-NOTE-DEBUG-SOURCE seen in ordinary load (not cold load) -- ~
582 very strange! If you didn't do something to cause this, please report it as ~
584 ;; we are going to be lenient with coming across this fop in a warm SBCL.
585 (setf (sb!c
::debug-source-compiled debug-source
) (get-universal-time)
586 (sb!c
::debug-source-created debug-source
)
587 (file-write-date (sb!c
::debug-source-namestring debug-source
))))
589 ;;; Modify a slot in a CONSTANTS object.
590 (!define-fop
140 (fop-alter-code ((:operands index
) code value
) nil
)
591 (setf (code-header-ref code index
) value
)
594 (!define-fop
139 (fop-fun-entry (code-object name arglist type info
))
595 #+sb-xc-host
; since xc host doesn't know how to compile %PRIMITIVE
596 (progn code-object name arglist type info
; touch the arguments
597 (error "FOP-FUN-ENTRY can't be defined without %PRIMITIVE."))
599 (let ((offset (read-word-arg (fasl-input-stream))))
600 (declare (type index offset
))
601 (unless (zerop (logand offset sb
!vm
:lowtag-mask
))
602 (bug "unaligned function object, offset = #X~X" offset
))
603 (let ((fun (%primitive sb
!c
:compute-fun code-object offset
)))
604 (setf (%simple-fun-self fun
) fun
)
605 (setf (%simple-fun-next fun
) (%code-entry-points code-object
))
606 (setf (%code-entry-points code-object
) fun
)
607 (setf (%simple-fun-name fun
) name
)
608 (setf (%simple-fun-arglist fun
) arglist
)
609 (setf (%simple-fun-type fun
) type
)
610 (setf (%simple-fun-info fun
) info
)
613 ;;;; Some Dylan FOPs used to live here. By 1 November 1998 the code
614 ;;;; was sufficiently stale that the functions it called were no
615 ;;;; longer defined, so I (William Harold Newman) deleted it.
617 ;;;; In case someone in the future is trying to make sense of FOP layout,
618 ;;;; it might be worth recording that the Dylan FOPs were
619 ;;;; 100 FOP-DYLAN-SYMBOL-SAVE
620 ;;;; 101 FOP-SMALL-DYLAN-SYMBOL-SAVE
621 ;;;; 102 FOP-DYLAN-KEYWORD-SAVE
622 ;;;; 103 FOP-SMALL-DYLAN-KEYWORD-SAVE
623 ;;;; 104 FOP-DYLAN-VARINFO-VALUE
625 ;;;; assemblerish fops
627 (!define-fop
144 (fop-assembler-code)
628 (error "cannot load assembler code except at cold load"))
630 (!define-fop
145 (fop-assembler-routine)
631 (error "cannot load assembler code except at cold load"))
633 (!define-fop
146 (fop-symbol-tls-fixup (code-object kind symbol
))
634 (sb!vm
:fixup-code-object code-object
635 (read-word-arg (fasl-input-stream))
636 (ensure-symbol-tls-index symbol
)
640 (!define-fop
147 (fop-foreign-fixup (code-object kind
))
641 (let* ((len (read-byte-arg (fasl-input-stream)))
642 (sym (make-string len
:element-type
'base-char
)))
643 (read-n-bytes (fasl-input-stream) sym
0 len
)
644 (sb!vm
:fixup-code-object code-object
645 (read-word-arg (fasl-input-stream))
646 (foreign-symbol-address sym
)
650 (!define-fop
148 (fop-assembler-fixup (code-object kind routine
))
651 (multiple-value-bind (value found
) (gethash routine
*assembler-routines
*)
653 (error "undefined assembler routine: ~S" routine
))
654 (sb!vm
:fixup-code-object code-object
(read-word-arg (fasl-input-stream))
658 (!define-fop
149 (fop-code-object-fixup (code-object kind
))
659 ;; Note: We don't have to worry about GC moving the code-object after
660 ;; the GET-LISP-OBJ-ADDRESS and before that value is deposited, because
661 ;; we can only use code-object fixups when code-objects don't move.
662 (sb!vm
:fixup-code-object code-object
(read-word-arg (fasl-input-stream))
663 (get-lisp-obj-address code-object
) kind
)
667 (!define-fop
150 (fop-foreign-dataref-fixup (code-object kind
))
668 (let* ((len (read-byte-arg (fasl-input-stream)))
669 (sym (make-string len
:element-type
'base-char
)))
670 (read-n-bytes (fasl-input-stream) sym
0 len
)
671 (sb!vm
:fixup-code-object code-object
672 (read-word-arg (fasl-input-stream))
673 (foreign-symbol-address sym t
)
677 ;;; FOPs needed for implementing an IF operator in a FASL
679 ;;; Skip until a FOP-MAYBE-STOP-SKIPPING with the same POSITION is
680 ;;; executed. While skipping, we execute most FOPs normally, except
681 ;;; for ones that a) funcall/eval b) start skipping. This needs to
682 ;;; be done to ensure that the fop table gets populated correctly
683 ;;; regardless of the execution path.
684 (!define-fop
151 (fop-skip (position) nil
)
686 (setf (skip-until) position
))
689 ;;; As before, but only start skipping if the top of the FOP stack is NIL.
690 (!define-fop
152 (fop-skip-if-false (position condition
) nil
)
691 (unless (or condition
(skip-until))
692 (setf (skip-until) position
))
695 ;;; If skipping, pop the top of the stack and discard it. Needed for
696 ;;; ensuring that the stack stays balanced when skipping.
697 (!define-fop
153 (fop-drop-if-skipping () nil
)
699 (fop-stack-pop-n (operand-stack) 1))
702 ;;; If skipping, push a dummy value on the stack. Needed for
703 ;;; ensuring that the stack stays balanced when skipping.
704 (!define-fop
154 (fop-push-nil-if-skipping () nil
)
706 (push-fop-stack nil
(fasl-input)))
709 ;;; Stop skipping if the top of the stack matches SKIP-UNTIL
710 (!define-fop
155 (fop-maybe-stop-skipping (label) nil
)
711 (when (eql (skip-until) label
)
712 (setf (skip-until) nil
))
715 ;;; Primordial layouts.
716 ;;; At the rate the opcode space is filling up, it might be wise to
717 ;;; rethink using 16 each for FOP-CODE and -SYMBOL-IN-PACKAGE-SAVE.
718 (macrolet ((frob (&rest specs
)
720 (defun known-layout-fop (name)
722 ,@(mapcar (lambda (spec) `((,(cadr spec
)) ,(car spec
)))
724 ,@(mapcar (lambda (spec)
725 `(!define-fop
,(car spec
)
726 (,(symbolicate "FOP-LAYOUT-OF-"
728 (find-layout ',(cadr spec
))))
731 (#x6d structure-object
)
732 (#x6e structure
!object
)
733 (#x6f definition-source-location
)
734 (#x70 sb
!c
::debug-fun
)
735 (#x71 sb
!c
::compiled-debug-fun
)
736 (#x72 sb
!c
::debug-info
)
737 (#x73 sb
!c
::compiled-debug-info
)
738 (#x74 sb
!c
::debug-source
)
739 (#x75 defstruct-description
)
740 (#x76 defstruct-slot-description
)))