From 29ccb2c2b33dd4b8d628d0499fa46799f6762ddb Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 9 Oct 2015 21:38:07 -0700 Subject: Tweaking expansions of when and until. * eval.c (me_when): Expand to if if there aren't multiple body forms. (me_unless): Simplify progn. * tests/012/struct.tl: Update string representation in struct test case. --- eval.c | 12 ++++++++++-- tests/012/struct.tl | 8 ++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/eval.c b/eval.c index ad0b8bdd..23afd828 100644 --- a/eval.c +++ b/eval.c @@ -52,6 +52,7 @@ #include "txr.h" #include "combi.h" #include "lisplib.h" +#include "cadr.h" #include "eval.h" #define max(a, b) ((a) > (b) ? (a) : (b)) @@ -2080,13 +2081,20 @@ static val me_pprof(val form, val menv) static val me_when(val form, val menv) { (void) menv; - return cons(cond_s, cons(rest(form), nil)); + + return if3(cdddr(form), + cons(cond_s, cons(cdr(form), nil)), + cons(if_s, cdr(form))); } static val me_unless(val form, val menv) { + val test = cadr(form); + val body = cddr(form); + (void) menv; - return list(if_s, second(form), nil, cons(progn_s, rest(rest(form))), nao); + + return list(if_s, test, nil, maybe_progn(body), nao); } static val me_while(val form, val menv) diff --git a/tests/012/struct.tl b/tests/012/struct.tl index d9ecc325..cc4bd79b 100644 --- a/tests/012/struct.tl +++ b/tests/012/struct.tl @@ -74,11 +74,11 @@ \ '(x y) () (lambda (#:g0004)\n \ \ (let ((#:g0005 (struct-type #:g0004)))\n \ \ (if (static-slot-p #:g0005 'x)\n \ - \ () (progn (slotset #:g0004 'x\n \ - \ 0)))\n \ + \ () (slotset #:g0004 'x\n \ + \ 0))\n \ \ (if (static-slot-p #:g0005 'y)\n \ - \ () (progn (slotset #:g0004 'y\n \ - \ 0)))))\n \ + \ () (slotset #:g0004 'y\n \ + \ 0))))\n \ \ (lambda (#:g0004 #:g0006\n \ \ #:g0007)\n \ \ (slotset #:g0004 'x\n \ -- cgit v1.2.3