1 ;;;; This file implements LOAD-TIME-VALUE.
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
14 (defknown %load-time-value (t) t (flushable movable))
16 (def-ir1-translator load-time-value ((form &optional read-only-p) start cont)
18 "Arrange for FORM to be evaluated at load-time and use the value produced
19 as if it were a constant. If READ-ONLY-P is non-NIL, then the resultant
20 object is guaranteed to never be modified, so it can be put in read-only
22 (if (producing-fasl-file)
23 (multiple-value-bind (handle type)
24 (compile-load-time-value (if read-only-p
26 `(make-value-cell ,form)))
27 (declare (ignore type))
28 (ir1-convert start cont
30 `(%load-time-value ',handle)
31 `(value-cell-ref (%load-time-value ',handle)))))
33 (handler-case (eval form)
35 (compiler-error "(during EVAL of LOAD-TIME-VALUE)~%~A"
37 (ir1-convert start cont
40 `(value-cell-ref ',(make-value-cell value)))))))
42 (defoptimizer (%load-time-value ir2-convert) ((handle) node block)
43 (assert (constant-continuation-p handle))
44 (let ((cont (node-cont node))
45 (tn (make-load-time-value-tn (continuation-value handle)
47 (move-continuation-result node block (list tn) cont)))