summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2018-03-23 07:44:52 -0700
committerKaz Kylheku <kaz@kylheku.com>2018-03-23 07:44:52 -0700
commit0e9adb0fd7c861f6f03ddb44c713153d2109a07f (patch)
tree7f2f1dc17041b37dee483e10705afa8827540851
parente04e3677661a1ddb8dda4ea64bbb83c68c4724ba (diff)
downloadtxr-0e9adb0fd7c861f6f03ddb44c713153d2109a07f.tar.gz
txr-0e9adb0fd7c861f6f03ddb44c713153d2109a07f.tar.bz2
txr-0e9adb0fd7c861f6f03ddb44c713153d2109a07f.zip
compiler: basic optimization in progn.
* share/txr/stdlib/compiler.tl (compiler comp-progn): Eliminate any form which is a constant or a symbol, unless it appears in the last position.
-rw-r--r--share/txr/stdlib/compiler.tl8
1 files changed, 6 insertions, 2 deletions
diff --git a/share/txr/stdlib/compiler.tl b/share/txr/stdlib/compiler.tl
index 5704e590..573d4e37 100644
--- a/share/txr/stdlib/compiler.tl
+++ b/share/txr/stdlib/compiler.tl
@@ -516,13 +516,17 @@
(defmeth compiler comp-progn (me oreg env args)
(let* (ffuns fvars
- (nargs (len args))
+ (lead-forms (butlastn 1 args))
+ (last-form (nthlast 1 args))
+ (eff-lead-forms (remove-if [orf constantp symbolp] lead-forms))
+ (forms (append eff-lead-forms last-form))
+ (nargs (len forms))
lastfrag
(oreg-discard (if (eq (car oreg) t)
oreg
me.(alloc-treg)))
(code (build
- (each ((form args)
+ (each ((form forms)
(n (range 1)))
(let ((islast (eql n nargs)))
(let ((frag me.(compile (if islast oreg oreg-discard)