diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-02-09 19:18:20 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-02-09 19:18:20 -0800 |
commit | 70c07bc501f560f09fa52c6a754fabc8f905860f (patch) | |
tree | d7e0f59d0abe5a647bf6cda8dde1bdc609aa5849 /txr.1 | |
parent | 42e924796096757b05bb2a2a6b205699e5f292ee (diff) | |
download | txr-70c07bc501f560f09fa52c6a754fabc8f905860f.tar.gz txr-70c07bc501f560f09fa52c6a754fabc8f905860f.tar.bz2 txr-70c07bc501f560f09fa52c6a754fabc8f905860f.zip |
awk macro: warn about invalid var use in rng forms.
The awk macro abruptly relocates rng forms out of their
apparent scope. Therefore, code like this is wrong:
(awk ((let ((x t))
(rng t x))
(action)))
The rng form is transformed and relocated to a scope in which
the let is not visible. This is a problem worth warning about.
In the above case, there will also be a warning about the
variable x being unbound, which might alerts the programmer
to the problem. However, in cases where there is yet another
binding of x introduced via :let or outside of awk, that
warning wll not occur: the code motion will silently cause
x to refer to the wrong x:
(awk (:let (x nil))
((let ((x t))
(rng 1 x)) ;; refers to the (x nil) binding!!!
(action)))
(let ((x nil))
(awk ((let ((x t))
(rng 1 x)) ;; refers to the (x 4) binding!!!
(action))))
Now there is a warning for this situation.
* share/txr/stdlib/awk.tl (sys:awk-compile-time): New slot,
outer-env.
(sys:awk-expander): Takes an env parameter, which is stored
into the new slot of the awk-compile-time structure.
(sys:awk-code-move-check): New function.
(sys:awk-mac-let): Use sys:expand-with-free-refs to expand
the rng forms, capturing the extra information which enables
the implementation of the warning. The rng variants are
refactored to pass the original form to the sys:rng
expander. This allows the diagnostic to display the original
rng form.
(awk): Parameter e renamed to outer-env, and passed to
sys:awk-expander.
Diffstat (limited to 'txr.1')
0 files changed, 0 insertions, 0 deletions