diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2020-04-20 06:34:57 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2020-04-20 06:34:57 -0700 |
commit | ca6020cff56c12958b6be1e75fa5fde29557649a (patch) | |
tree | d974c0a4ffcdcd158b8ab3a5ddf471089b1e70f2 /share | |
parent | c99dd869357f2afd0b79dfc24f9e9953d9129837 (diff) | |
download | txr-ca6020cff56c12958b6be1e75fa5fde29557649a.tar.gz txr-ca6020cff56c12958b6be1e75fa5fde29557649a.tar.bz2 txr-ca6020cff56c12958b6be1e75fa5fde29557649a.zip |
compiler: bugfix: constant test in 2 or 3 arg if.
* share/txr/stdlib/compiler.tl (compiler comp-if): The two and
three argument cases assume that if the test is a constant
expression, the consequent "then" should be unconditionally
taken. The correct behavior is to evaluate the constant,
which could yield nil. I checked which library code changes
after this fix, and found that a number of (defset ...)
forms are generating different, shorter code.
This is due to (if ',restpar (if (consp ,restpar) ...))
in defset-expander. The intent there was to eliminate the
inner if code entirely if respar is nil (there is no rest
parameter); due to this bug, the code elimination didn't
happen. The behavior is nevertheless correct because the
code does nothing if restpar is nil.
Diffstat (limited to 'share')
-rw-r--r-- | share/txr/stdlib/compiler.tl | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/share/txr/stdlib/compiler.tl b/share/txr/stdlib/compiler.tl index f510d892..5c397a4a 100644 --- a/share/txr/stdlib/compiler.tl +++ b/share/txr/stdlib/compiler.tl @@ -429,7 +429,7 @@ ((null test) me.(compile oreg env else)) ((constantp test) - me.(compile oreg env then)) + me.(compile oreg env (if (eval test) then else))) ((and (consp test) (member (car test) %test-funs%)) me.(compile oreg env ^(ift ,(car test) ,(cadr test) ,(caddr test) ,then ,else))) @@ -457,7 +457,7 @@ (cond ((null test) me.(compile oreg env nil)) ((constantp test) - me.(compile oreg env then)) + me.(compile oreg env (if (eval test) then))) ((and (consp test) (member (car test) %test-funs%)) me.(compile oreg env ^(ift ,(car test) ,(cadr test) ,(caddr test) ,then))) |