summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-02-10 05:04:36 -0800
committerKaz Kylheku <kaz@kylheku.com>2017-02-10 05:04:36 -0800
commit0175beb2feb977a6cbf716cb310046ca438dc34e (patch)
treeb938025e506579df69e004fcf806192c07b1572c
parent89ca05c2a82d0f842956a345a85a3e80817f60a2 (diff)
downloadtxr-0175beb2feb977a6cbf716cb310046ca438dc34e.tar.gz
txr-0175beb2feb977a6cbf716cb310046ca438dc34e.tar.bz2
txr-0175beb2feb977a6cbf716cb310046ca438dc34e.zip
awk macro: warn about invalid function use in rng.
Improving the new feature to handle functions also, and improve the diagnostic by reporting the specific to or from subform of which contains the reference. * share/txr/stdlib/awk.tl (sys:awk-code-move-check): Take a an argument indicating the kinds of bindings being checked, symbols or functions, and an extra form argument. (sys:awk-mac-let): Pass new arguments to sys:awk-code-move-check and also call it two more times to report on functions also.
-rw-r--r--share/txr/stdlib/awk.tl37
1 files changed, 26 insertions, 11 deletions
diff --git a/share/txr/stdlib/awk.tl b/share/txr/stdlib/awk.tl
index 4808cb45..5b19e706 100644
--- a/share/txr/stdlib/awk.tl
+++ b/share/txr/stdlib/awk.tl
@@ -268,12 +268,13 @@
awc.cond-actions (nreverse awc.cond-actions))
awc))
-(defun sys:awk-code-move-check (awc aws-sym form suspicious-vars)
+(defun sys:awk-code-move-check (awc aws-sym mainform subform
+ suspicious-vars kind)
(when suspicious-vars
- (compile-warning form "~!form ~s\n\
- is moved out of the apparent scope\n\
- and thus cannot refer to variables ~s"
- form suspicious-vars)))
+ (compile-warning mainform "~!form ~s\n\
+ is moved out of the apparent scope\n\
+ and thus cannot refer to ~s ~s"
+ subform kind suspicious-vars)))
(defmacro sys:awk-mac-let (awc aws-sym . body)
^(symacrolet ((rec (rslot ,aws-sym 'rec 'rec-to-f))
@@ -303,16 +304,30 @@
(flag-old (gensym))
(flag-new (gensym)))
(tree-bind ((from-expr-ex fe-fv fe-ff fe-ev fe-ef)
- (to-expr-ex te-fv te-ff te-ev te-ef))
+ (to-expr-ex te-fv te-ff te-ev te-ef)
+ (from-expr-orig to-expr-orig))
(list
(sys:expand-with-free-refs from-expr e
,awc.outer-env)
(sys:expand-with-free-refs to-expr e
- ,awc.outer-env))
- (sys:awk-code-move-check ,awc ',aws-sym form
- (set-diff fe-ev fe-fv))
- (sys:awk-code-move-check ,awc ',aws-sym form
- (set-diff te-ev te-fv))
+ ,awc.outer-env)
+ (list (cadr form) (caddr form)))
+ (sys:awk-code-move-check ,awc ',aws-sym
+ form from-expr-orig
+ (set-diff fe-ev fe-fv)
+ 'variables)
+ (sys:awk-code-move-check ,awc ',aws-sym
+ form from-expr-orig
+ (set-diff fe-ef fe-ff)
+ 'functions)
+ (sys:awk-code-move-check ,awc ',aws-sym
+ form to-expr-orig
+ (set-diff te-ev te-fv)
+ 'variables)
+ (sys:awk-code-move-check ,awc ',aws-sym
+ form to-expr-orig
+ (set-diff te-ef te-ff)
+ 'functions)
(push rng-temp (qref ,awc rng-expr-temps))
(push ^(placelet ((flag (vecref (qref ,',aws-sym rng-vec) ,ix)))
(let* ((,flag-old flag) ,flag-new)