From 935e56bdeca329e8affdb03f20a31736f10ed834 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 24 Sep 2016 07:16:33 -0700 Subject: 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. --- share/txr/stdlib/awk.tl | 26 ++++++++++++++------------ 1 file 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)))))))) -- cgit v1.2.3