diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2025-06-19 21:28:26 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2025-06-19 21:28:26 -0700 |
commit | 53f92425856734cb680525f3d4ede2a7b3e3dde3 (patch) | |
tree | c37397d4afba0f9183573d7230f9a311cae4d37a /stdlib/compiler.tl | |
parent | c03f27f7d282dffb35b1746fd067ab24e0354421 (diff) | |
download | txr-53f92425856734cb680525f3d4ede2a7b3e3dde3.tar.gz txr-53f92425856734cb680525f3d4ede2a7b3e3dde3.tar.bz2 txr-53f92425856734cb680525f3d4ede2a7b3e3dde3.zip |
compiler: opt-tail-calls compiler option.
* stdlib/comp-opts.tl (compile-opts): New slot, opt-tail-calls.
(%warning-syms%): Variable removed; this just lists the slots
of compile-opts, which can be obtained with the slots function.
Moreover, it is badly named, since there is now a non-diagnostic
option.
(*compile-opts*): Specify an initial value of : for opt-tail-calls.
This means that *opt-level* controls whether it is enabled.
* stdlib/compiler.tl: Update comment about optimization
levels, since level 2 now does tail calls.
(compiler comp-lambda-impl): Only enable tail calls if
the option has the default value : and *opt-level* is at
least two, or else if the option has value t.
(with-compile-opts): Recognize : as valid option value.
Don't refer to %warning-syms% but the slots of compile-opts.
We use load-time to avoid calculating this repeatedly.
The wording of the error message has to be adjusted since
not all options are diagnosic any more.
* autoload.c (compiler_set_entries): Add opt-tail-calls to
slot-name autoload triggers for the compiler module.
* txr.1: Mention tail calls and the opt-tail-calls option
in the description of *opt-level* 2. Document opt-tail-calls
under compile-opts section. We describe what tail calls are
there and also adjust the wording since not all options
diagnostic. Describe the three-valued system for code
generation options.
Diffstat (limited to 'stdlib/compiler.tl')
-rw-r--r-- | stdlib/compiler.tl | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/stdlib/compiler.tl b/stdlib/compiler.tl index 37c5df56..6a49551a 100644 --- a/stdlib/compiler.tl +++ b/stdlib/compiler.tl @@ -342,7 +342,7 @@ ;; 0 - no optimization ;; 1 - constant folding, algebraics. -;; 2 - block elimination, frame elimination +;; 2 - block elimination, frame elimination, self tail calls ;; 3 - lambda/combinator lifting ;; 4 - control-flow: jump-threading, dead code ;; 5 - data-flow: dead registers, useless regisers @@ -1127,6 +1127,7 @@ (*top-level* nil) (tfn *tail-fun*) (tpos nil) + (tco *compile-opts*.opt-tail-calls) (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)) @@ -1134,7 +1135,10 @@ (when (> pars.nfix %max-lambda-fixed-args%) (compile-warning form "~s arguments in a lambda (max is ~s)" pars.nfix %max-lambda-fixed-args%)) - (when (and tfn (eq tfn.lambda form)) + (when (and (caseq tco + (: (>= *opt-level* 2)) + ((t) t)) + tfn (eq tfn.lambda form)) (set tfn.env nenv tfn.label (gensym "l") tpos t)) @@ -2846,11 +2850,11 @@ (defmacro usr:with-compile-opts (:form form . clauses) (match-case clauses (() ()) - (((@(as op @(or nil t :warn :error @(integerp))) . @syms) . @rest) + (((@(as op @(or nil t :warn :error : @(integerp))) . @syms) . @rest) (each ((s syms)) - (unless (member s %warning-syms%) + (unless (member s (load-time (slots 'compile-opts))) (compile-error form - "~s isn't a recognized warning option" s))) + "~s isn't a recognized compile option" s))) ^(compiler-let ((*compile-opts* (let ((co (copy *compile-opts*))) (set ,*(mappend (ret ^(co.,@1 ,op)) syms)) |