summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-11-01 23:38:56 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-11-01 23:38:56 -0700
commit3f53b5cec29b18fb9bbf8451414d590ae7be9574 (patch)
treea21aca3595b9dcd556512f4bd2da4fc1b5c6f5ac
parent280e73c1b0293e8352ca79d1d323f87cad406a03 (diff)
downloadtxr-3f53b5cec29b18fb9bbf8451414d590ae7be9574.tar.gz
txr-3f53b5cec29b18fb9bbf8451414d590ae7be9574.tar.bz2
txr-3f53b5cec29b18fb9bbf8451414d590ae7be9574.zip
compiler: don't lift top-level lambdas.
The compiler is lifting top-level lambdas, such as those generated by defun, using the load-time mechanism. This has the undesireable effect of unnecessarily placing the lambdas into a D register. * stdlib/compiler.tl (*top-level*): New special variable. This indicates that the compiler is compiling code that is outside of any lambda. (compiler comp-lambda-impl): Bind *top-level* to nil when compiling lambda, so its interior is no longer at the top level. (compiler comp-lambda): Suppress the unnecessary lifting optimization if the lambda expression is in the top-level, outside of any other lambda, indicated by *top-level* being true. (compile-toplevel): Bind *top-level* to t.
-rw-r--r--stdlib/compiler.tl6
1 files changed, 5 insertions, 1 deletions
diff --git a/stdlib/compiler.tl b/stdlib/compiler.tl
index c27cc040..69696b15 100644
--- a/stdlib/compiler.tl
+++ b/stdlib/compiler.tl
@@ -308,6 +308,8 @@
(defvar *load-time*)
+(defvar *top-level*)
+
;; 0 - no optimization
;; 1 - constant folding, algebraics.
;; 2 - block elimination, frame elimination
@@ -1039,6 +1041,7 @@
closure-spies me.closure-spies)
(compile-with-fresh-tregs me
(let* ((*load-time* nil)
+ (*top-level* nil)
(pars (new (fun-param-parser par-syntax form)))
(need-frame (or (plusp pars.nfix) pars.rest))
(nenv (if need-frame (new env up env co me) env))
@@ -1144,7 +1147,7 @@
pars)))))))))))
(defmeth compiler comp-lambda (me oreg env form)
- (if (or *load-time* (< *opt-level* 3))
+ (if (or *load-time* *top-level* (< *opt-level* 3))
me.(comp-lambda-impl oreg env form)
(let* ((snap me.(snapshot))
(lambda-frag me.(comp-lambda-impl oreg env form))
@@ -2106,6 +2109,7 @@
(as (new assembler))
(*dedup* (or *dedup* (hash)))
(*load-time* nil)
+ (*top-level* t)
(*opt-level* (or *opt-level* 0)))
(let* ((oreg co.(alloc-treg))
(xexp (if expanded-p