Provisional API: This reference documents current compiler behavior. Compatibility is not yet promised.
src/comptime.x
Translating a compile-time x2c function into Lisp.
Functions
| Function | Summary |
|---|---|
Compiler.check_meta_call | Refuses a run-time call to a meta function this compiler derived compile-time only. |
Compiler.fold_meta_call | Answers a call to a meta function from its compile-time form when every argument is a compile-time constant of the parameter’s own type, or returns NULL to leave the call alone. |
Compiler.inherit_shared_meta | Restores the shared definitions’ derived call restrictions into a fresh compiler pass. |
Compiler.install_comptime | Lowers fn and evaluates the result in the macro session, so the function is callable from compile-time Lisp under its own name. |
Compiler.lower_comptime | Lowers one compile-time function into the forms the macro session evaluates, or returns NULL when the substitution cannot carry it. |
Compiler.lower_declined | Returns why the last Compiler.lower_comptime declined, or NULL. |
Compiler.lower_reached_globals | Returns whether the last Compiler.install_comptime reached file-scope state, directly or through a callee already recorded as reaching it. |
Compiler.lower_reached_meta | Returns whether the last Compiler.install_comptime reached a Meta operation, directly or through a callee already recorded as reaching one. |
Compiler.meta_is_comptime_only | Returns whether fn is a meta function this compiler recorded as compile-time only, whose runtime form the unit does not emit. |
Compiler
Compiler.check_meta_call
void Compiler.check_meta_call(Compiler c, List callee, Token origin)
Refuses a run-time call to a meta function this compiler derived
compile-time only.
Such a function reaches a Meta operation, so it exists only inside a
compiler and the unit emits no definition for it. The call used to reach
the linker as an undefined symbol, which names the C spelling and not the
source. Another meta function may call it: calling one is what makes
the caller compile-time only too, so a body being parsed under the marker
is left alone.
Source: src/comptime.x:2124
Compiler.fold_meta_call
List Compiler.fold_meta_call( Compiler c, List callee, Type signature, Type result, List arguments)
Answers a call to a meta function from its compile-time form when every
argument is a compile-time constant of the parameter’s own type, or
returns NULL to leave the call alone.
callee is the resolved callee expression, signature its function type
and result the call’s type. Only a meta function this compiler
installed folds, so an import’s runtime definition keeps the run-time
call that designates the unit emitting it. Evaluation runs in the macro
session; a raise there leaves the call.
Source: src/comptime.x:2146
Compiler.inherit_shared_meta
void Compiler.inherit_shared_meta(Compiler compiler)
Restores the shared definitions’ derived call restrictions into a fresh compiler pass. Reads existing process tables without opening Lisp or creating a lowering cache in the unit’s Context.
Source: src/comptime.x:1968
Compiler.install_comptime
int Compiler.install_comptime(Compiler compiler, List fn)
Lowers fn and evaluates the result in the macro session, so the
function is callable from compile-time Lisp under its own name.
Returns whether the lowering succeeded. This method mutates the macro
session and does not open a semantic transaction.
Source: src/comptime.x:2023
Compiler.lower_comptime
List Compiler.lower_comptime(Compiler compiler, List fn)
Lowers one compile-time function into the forms the macro session
evaluates, or returns NULL when the substitution cannot carry it.
The result is the loop definitions the body needed followed by the
function’s own, in evaluation order. This method does not open a
semantic transaction.
Source: src/comptime.x:1868
Compiler.lower_declined
String Compiler.lower_declined(Compiler compiler)
Returns why the last Compiler.lower_comptime declined, or NULL.
Source: src/comptime.x:1927
Compiler.lower_reached_globals
int Compiler.lower_reached_globals(Compiler compiler)
Returns whether the last Compiler.install_comptime reached file-scope
state, directly or through a callee already recorded as reaching it.
Source: src/comptime.x:2063
Compiler.lower_reached_meta
int Compiler.lower_reached_meta(Compiler compiler)
Returns whether the last Compiler.install_comptime reached a Meta
operation, directly or through a callee already recorded as reaching one.
Source: src/comptime.x:2071
Compiler.meta_is_comptime_only
int Compiler.meta_is_comptime_only(Compiler c, List fn)
Returns whether fn is a meta function this compiler recorded as
compile-time only, whose runtime form the unit does not emit.
Source: src/comptime.x:2079
Design notes
A function marked for compile-time use is lowered here into the Lisp the
macro session evaluates. A call in tail position reuses the frame it
stands in, so a loop runs in constant space when its recursive call is
in tail position and nothing accumulates around it. A block is therefore
reduced by substitution to one expression per live local, and an
iteration ends in (loop e1 e2 ...) directly.
Locals are Lisp values held in an environment mapping each binding id to the expression that currently produces it. A value the substitution cannot carry is bound with a real lambda when it is off a loop’s iteration path, and declines the function when it is on one.