summaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2018-05-07 06:35:09 -0700
committerKaz Kylheku <kaz@kylheku.com>2018-05-07 06:35:09 -0700
commitc9ffbddd284ab9fbb5c2198f4c2a7072448b7988 (patch)
treeda7e1363b9fb2f694748fd83aede581cb9e9e8f5 /share
parentd4d26ed0e32faa1ab8c2fbe78661a48f4f801d89 (diff)
downloadtxr-c9ffbddd284ab9fbb5c2198f4c2a7072448b7988.tar.gz
txr-c9ffbddd284ab9fbb5c2198f4c2a7072448b7988.tar.bz2
txr-c9ffbddd284ab9fbb5c2198f4c2a7072448b7988.zip
compiler: warn on misleading references in load-time.
If code does something like this, we produce a warning: (let ((var 42)) (load-time (+ var 3))) A load-time form occurs in an empty lexical environment, so this code appears right but actually cannot work; the appearance is a mere trompe d'oeil. * share/txr/stdlib/compiler.tl (misleading-ref-check): New function. (compiler comp-load-time-lit): Apply misleading-ref-check.
Diffstat (limited to 'share')
-rw-r--r--share/txr/stdlib/compiler.tl9
1 files changed, 9 insertions, 0 deletions
diff --git a/share/txr/stdlib/compiler.tl b/share/txr/stdlib/compiler.tl
index 8af7384f..d734fccf 100644
--- a/share/txr/stdlib/compiler.tl
+++ b/share/txr/stdlib/compiler.tl
@@ -1146,6 +1146,14 @@
(end ,bfrag.oreg))
bfrag.fvars bfrag.ffuns)))))
+(defun misleading-ref-check (frag env form)
+ (each ((v frag.fvars))
+ (when env.(lookup-var v)
+ (compile-warning form "cannot refer to lexical variable ~s" v)))
+ (each ((f frag.ffuns))
+ (when env.(lookup-fun f)
+ (compile-warning form "cannot refer to lexical function ~s" f))))
+
(defmeth compiler comp-load-time-lit (me oreg env form)
(mac-param-bind form (op loaded-p exp) form
(if loaded-p
@@ -1159,6 +1167,7 @@
(mov ,dreg ,exp.oreg))
exp.fvars
exp.ffuns))))
+ (misleading-ref-check exp env form)
me.(free-treg oreg)
(push lt-frag me.lt-frags)
(new (frag dreg nil)))))))