From 0e9adb0fd7c861f6f03ddb44c713153d2109a07f Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 23 Mar 2018 07:44:52 -0700 Subject: 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. --- share/txr/stdlib/compiler.tl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'share') 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) -- cgit v1.2.3