summaryrefslogtreecommitdiffstats
path: root/stdlib
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
commit7889af8ff0eb30aa4e8657fe336af92abd571b5f (patch)
treea21aca3595b9dcd556512f4bd2da4fc1b5c6f5ac /stdlib
parent1bf0ffecaf481e70dad272d28ae3a59e063b0fec (diff)
downloadtxr-7889af8ff0eb30aa4e8657fe336af92abd571b5f.tar.gz
txr-7889af8ff0eb30aa4e8657fe336af92abd571b5f.tar.bz2
txr-7889af8ff0eb30aa4e8657fe336af92abd571b5f.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.
Diffstat (limited to 'stdlib')
-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