summaryrefslogtreecommitdiffstats
path: root/share/txr
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
commit7d6eb419494d58ce8dba4ab2582793a1c04f3854 (patch)
tree4e5e598fbc771883b57230a811defdbcc20d06c5 /share/txr
parent86f99969e159e3e800794e609490694317d13adb (diff)
downloadtxr-7d6eb419494d58ce8dba4ab2582793a1c04f3854.tar.gz
txr-7d6eb419494d58ce8dba4ab2582793a1c04f3854.tar.bz2
txr-7d6eb419494d58ce8dba4ab2582793a1c04f3854.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.
Diffstat (limited to 'share/txr')
-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)))