summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-09-24 07:16:33 -0700
committerKaz Kylheku <kaz@kylheku.com>2016-09-24 07:16:33 -0700
commitc09e167c5425a26cd0bdec72fa573db0124c2d39 (patch)
tree1b4253c322f297c27e37ed0ecc4d10da5bf66f85
parent4789a3d00a453752d2c7b1e5ca4b79bee26b959e (diff)
downloadtxr-c09e167c5425a26cd0bdec72fa573db0124c2d39.tar.gz
txr-c09e167c5425a26cd0bdec72fa573db0124c2d39.tar.bz2
txr-c09e167c5425a26cd0bdec72fa573db0124c2d39.zip
awk macro: exit if no cond-action clauses.
* share/txr/stdlib/awk.tl: If there are no cond-action clauses in the macro, do not generate the main record processing lambda, or the begin-file and end-file lambdas, and do not generate the call to the awk state object's loop method.
-rw-r--r--share/txr/stdlib/awk.tl26
1 files changed, 14 insertions, 12 deletions
diff --git a/share/txr/stdlib/awk.tl b/share/txr/stdlib/awk.tl
index 07a5f3bc..eccef632 100644
--- a/share/txr/stdlib/awk.tl
+++ b/share/txr/stdlib/awk.tl
@@ -230,26 +230,28 @@
rng-n (macro-time (qref ,awc nranges))))
,*(if awc.output
^((*stdout* (qref ,aws-sym output))))
- ,*(if awc.begin-file-actions
+ ,*(if (and awc.cond-actions awc.begin-file-actions)
^((,awk-begf-fun (lambda (,aws-sym)
,*awc.begin-file-actions))))
- ,*(if awc.end-file-actions
+ ,*(if (and awc.cond-actions awc.end-file-actions)
^((,awk-endf-fun (lambda (,aws-sym)
,*awc.end-file-actions))))
- (,awk-fun (lambda (,aws-sym)
- ,(if awc.rng-exprs
- ^(let* ((,awc.rng-rec-temp rec)
- ,*(nreverse
- (zip awc.rng-expr-temps
- awc.rng-exprs)))
- ,p-actions-xform)
- p-actions-xform))))
+ ,*(if awc.cond-actions
+ ^((,awk-fun (lambda (,aws-sym)
+ ,(if awc.rng-exprs
+ ^(let* ((,awc.rng-rec-temp rec)
+ ,*(nreverse
+ (zip awc.rng-expr-temps
+ awc.rng-exprs)))
+ ,p-actions-xform)
+ p-actions-xform))))))
,*awc.begin-actions
(unwind-protect
- (qref ,aws-sym (loop ,awk-fun
+ ,(if awc.cond-actions
+ ^(qref ,aws-sym (loop ,awk-fun
,(if awc.begin-file-actions
awk-begf-fun)
,(if awc.end-file-actions
- awk-endf-fun)))
+ awk-endf-fun))))
(set ,awk-retval (progn ,*awc.end-actions)))
,awk-retval))))))))