summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-09-09 06:16:00 -0700
committerKaz Kylheku <kaz@kylheku.com>2016-09-09 06:16:00 -0700
commit384c23c02dee3d9523b7a60ea367374c88941251 (patch)
tree4e5e598fbc771883b57230a811defdbcc20d06c5
parente5459a644be8f64a54c07e70675c5b5637ff2992 (diff)
downloadtxr-384c23c02dee3d9523b7a60ea367374c88941251.tar.gz
txr-384c23c02dee3d9523b7a60ea367374c88941251.tar.bz2
txr-384c23c02dee3d9523b7a60ea367374c88941251.zip
awk macro: fix buggy range semantics.
* share/txr/stdlib/awk.tl (sys:awk-let): The closing expression of an awk range only applies when the range is active. Refactor generated code with local flags to eliminate duplicating the end range expression. Avoid evaluating the start range expression if the range is already active.
-rw-r--r--share/txr/stdlib/awk.tl14
1 files changed, 9 insertions, 5 deletions
diff --git a/share/txr/stdlib/awk.tl b/share/txr/stdlib/awk.tl
index 4c40494a..f3b80a79 100644
--- a/share/txr/stdlib/awk.tl
+++ b/share/txr/stdlib/awk.tl
@@ -143,13 +143,17 @@
(let ((ix (pinc (qref ,awc nranges)))
(rng-temp (gensym))
(from-expr-ex (sys:expand from-expr e))
- (to-expr-ex (sys:expand to-expr e)))
+ (to-expr-ex (sys:expand to-expr e))
+ (flag-old (gensym))
+ (flag-new (gensym)))
(push rng-temp (qref ,awc rng-expr-temps))
(push ^(placelet ((flag (vecref (qref ,',aws-sym rng-vec) ,ix)))
- (cond
- (,from-expr-ex (set flag t))
- (,to-expr-ex (zap flag) t)
- (flag)))
+ (let* ((,flag-old flag) ,flag-new)
+ (when (or ,flag-old ,from-expr-ex)
+ (set ,flag-new t))
+ (when (and ,flag-new ,to-expr-ex)
+ (set ,flag-new nil))
+ (or (set flag ,flag-new) ,flag-old)))
(qref ,awc rng-exprs))
rng-temp)))
,*body)))