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
17 ((form &optional read-only-p) start next result)
19 "Arrange for FORM to be evaluated at load-time and use the value produced
20 as if it were a constant. If READ-ONLY-P is non-NIL, then the resultant
21 object is guaranteed to never be modified, so it can be put in read-only
23 (if (producing-fasl-file)
24 (multiple-value-bind (handle type)
25 (compile-load-time-value (if read-only-p
27 `(make-value-cell ,form)))
28 (declare (ignore type))
29 (ir1-convert start next result
31 `(%load-time-value ',handle)
32 `(value-cell-ref (%load-time-value ',handle)))))
34 (handler-case (eval form)
36 (compiler-error "(during EVAL of LOAD-TIME-VALUE)~%~A"
38 (ir1-convert start next result
41 `(value-cell-ref ',(make-value-cell value)))))))
43 (defoptimizer (%load-time-value ir2-convert) ((handle) node block)
44 (aver (constant-lvar-p handle))
45 (let ((lvar (node-lvar node))
46 (tn (make-load-time-value-tn (lvar-value handle)
48 (move-lvar-result node block (list tn) lvar)))