diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2018-03-23 07:44:52 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2018-03-23 07:44:52 -0700 |
commit | 5b98c5370370a84001eb701f59062297bd929f10 (patch) | |
tree | 7f2f1dc17041b37dee483e10705afa8827540851 | |
parent | 1ef5cd7360b8e8a922522fa6f4fd7b2d016bbc38 (diff) | |
download | txr-5b98c5370370a84001eb701f59062297bd929f10.tar.gz txr-5b98c5370370a84001eb701f59062297bd929f10.tar.bz2 txr-5b98c5370370a84001eb701f59062297bd929f10.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.tl | 8 |
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) |