From 1d605f0a476e7c5f82a071bc040e93c937f608a3 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 20 Apr 2020 06:34:57 -0700 Subject: 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. --- share/txr/stdlib/compiler.tl | 4 ++-- 1 file 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))) -- cgit v1.2.3