0.9.2.45:
[sbcl/lichteblau.git] / src / compiler / ltv.lisp
blob9ed48c8743a07206013ffd7327bc954e8bb759b4
1 ;;;; This file implements LOAD-TIME-VALUE.
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
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.
12 (in-package "SB!C")
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)
18 #!+sb-doc
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
22 storage."
23 (if (producing-fasl-file)
24 (multiple-value-bind (handle type)
25 (compile-load-time-value (if read-only-p
26 form
27 `(make-value-cell ,form)))
28 (declare (ignore type))
29 (ir1-convert start next result
30 (if read-only-p
31 `(%load-time-value ',handle)
32 `(value-cell-ref (%load-time-value ',handle)))))
33 (let ((value
34 (handler-case (eval form)
35 (error (condition)
36 (compiler-error "(during EVAL of LOAD-TIME-VALUE)~%~A"
37 condition)))))
38 (ir1-convert start next result
39 (if read-only-p
40 `',value
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)
47 *universal-type*)))
48 (move-lvar-result node block (list tn) lvar)))