diff options
-rw-r--r-- | share/txr/stdlib/compiler.tl | 33 | ||||
-rw-r--r-- | txr.1 | 46 |
2 files changed, 65 insertions, 14 deletions
diff --git a/share/txr/stdlib/compiler.tl b/share/txr/stdlib/compiler.tl index ca86db11..f1c4ca09 100644 --- a/share/txr/stdlib/compiler.tl +++ b/share/txr/stdlib/compiler.tl @@ -199,6 +199,8 @@ (defvar *dedup*) +(defvar *load-time*) + (defun dedup (obj) (cond ((null obj) nil) @@ -815,7 +817,8 @@ (defmeth compiler comp-lambda (me oreg env form) (mac-param-bind form (op par-syntax . body) form - (let* ((pars (new (fun-param-parser par-syntax form))) + (let* ((*load-time* nil) + (pars (new (fun-param-parser par-syntax form))) (need-frame (or (plusp pars.nfix) pars.rest)) (nenv (if need-frame (new env up env co me) env)) lexsyms fvars specials need-dframe) @@ -1239,19 +1242,21 @@ (defmeth compiler comp-load-time-lit (me oreg env form) (mac-param-bind form (op loaded-p exp) form - (if loaded-p - me.(compile oreg env ^(quote ,exp)) - (compile-in-toplevel me - (let* ((dreg me.(alloc-dreg)) - (exp me.(compile dreg (new env co me) exp)) - (lt-frag (new (frag dreg - ^(,*exp.code - ,*(maybe-mov dreg exp.oreg)) - exp.fvars - exp.ffuns)))) - (misleading-ref-check exp env form) - (push lt-frag me.lt-frags) - (new (frag dreg nil))))))) + (cond + (loaded-p me.(compile oreg env ^(quote ,exp))) + (*load-time* me.(compile oreg env exp)) + (t (compile-in-toplevel me + (let* ((*load-time* t) + (dreg me.(alloc-dreg)) + (exp me.(compile dreg (new env co me) exp)) + (lt-frag (new (frag dreg + ^(,*exp.code + ,*(maybe-mov dreg exp.oreg)) + exp.fvars + exp.ffuns)))) + (misleading-ref-check exp env form) + (push lt-frag me.lt-frags) + (new (frag dreg nil)))))))) (defun maybe-mov (to-reg from-reg) (if (nequal to-reg from-reg) @@ -71443,6 +71443,52 @@ the immediately enclosing form which surrounds the .code load-time form. +A +.code load-time +form may be nested inside another +.code load-time +form. In this situation, two cases occur. + +If the two forms are not embedded in a +.codn lambda , +or else are embedded in the same +.codn lambda , +then the inner +.code load-time +form is superfluous due to the presence of the outer +.codn load-time . +That is to say, the inner +.mono +.meti (load-time << form ) +.onom +expression is equivalent to +.metn form , +because the outer form already establishes its evaluation to be in a load-time +context. + +If the inner +.code load-time +form occurs in a +.codn lambda , +but the outer form occurs outside of that +.codn lambda , +then the semantics of the inner +.code load-time +form is relevant and necessary. This is because expressions occurring in a +.code lambda +are evaluated when the +.code lambda +is called, which may take place from a non-load-time context, even if the +.code lambda +itself was produced in a load-time context. + +An expression being embedded in a +.code lambda +means that it appears either in the +.code lambda +body, or else in the parameter list as the initializing +expression for an optional parameter. + .TP* Notes: When interpreted code containing |