Provisional API: This reference documents current compiler behavior. Compatibility is not yet promised.
src/callables.x
Callable values lowered to C helpers.
Functions
| Function | Summary |
|---|---|
Compiler.adapt_lambda_arg | Adapts a lowered noncapturing lambda helper to a typed callback. |
Compiler.capture_environment | Binds the file-static context type name with the field rows fields, for captured lambdas and callable defers. |
Compiler.func_signature | Returns the canonical signature shared by native and meta Func adapters. |
Compiler.lift_func_expression | Converts a resolved function-like expression to Func when supported. |
Compiler.lower_lambda_expr | Lowers a resolved lambda expression to emitter-ready helper references. |
Compiler.lower_typed_adapter_expr | Lowers a resolved tadapt expression to a typed callback helper. |
Compiler.maybe_adapt_func_arg | Adapts a direct native function argument when FuncAdapter is expected. |
Compiler.prepare_lambda_cells | Prepares one resolved function body for shared mutable lambda captures. |
Compiler
Compiler.adapt_lambda_arg
List Compiler.adapt_lambda_arg(Compiler c, List argument, List expected_type)
Adapts a lowered noncapturing lambda helper to a typed callback.
argument must be a resolved helper reference produced by
Compiler.lower_lambda_expr, optionally wrapped in parentheses.
expected_type must describe a fixed, nonvariadic function. Unless its
parameters and result are already Var,
a queued static helper converts callback arguments to the lowered lambda’s
original parameter types before calling it, then converts its Var result
to the expected return type. Already compatible or unsupported shapes pass
through unchanged.
Source: src/callables.x:1394
Compiler.capture_environment
List Compiler.capture_environment(Compiler c, List name, List fields)
Binds the file-static context type name with the field rows fields,
for captured lambdas and callable defers. The complete typedef is bound
at once, so each field keeps its member type.
Source: src/callables.x:178
Compiler.func_signature
List Compiler.func_signature(Compiler c, Type type)
Returns the canonical signature shared by native and meta Func adapters.
Source: src/callables.x:1211
Compiler.lift_func_expression
List Compiler.lift_func_expression(Compiler c, List expression)
Converts a resolved function-like expression to Func when supported.
Existing Func values pass through. Direct fixed functions reuse a
file-static handle; other function-typed and function-pointer expressions
are evaluated once and copied into a new context-bound Func, with null
pointers producing null Func. Lambda expressions are lowered first, and
unrelated expressions pass through unchanged. Public inline functions
reach the queued helpers through generated bridge functions.
Source: src/callables.x:630
Compiler.lower_lambda_expr
List Compiler.lower_lambda_expr(Compiler c, List expression)
Lowers a resolved lambda expression to emitter-ready helper references.
expression must retain the resolved expr, lambda, params, and
optional captures rows. A noncapturing lambda becomes a static
Var-returning helper. A lambda with capture rows becomes a FuncAdapter
helper and a Func whose copied context stores value snapshots and typed
reference addresses; capture expressions run once from left to right.
Nested lambdas lower inside out, block fallthrough and bare returns produce
no value, and synthesized declarations enter the early queue. Parentheses
remain around lowered helpers; other non-lambda expressions pass through.
Source: src/callables.x:55
Compiler.lower_typed_adapter_expr
List Compiler.lower_typed_adapter_expr(Compiler c, List expression)
Lowers a resolved tadapt expression to a typed callback helper.
expression must have the resolved shape
(expr TARGET (tadapt ORIGIN (expr SOURCE (ident BINDING)))).
Compatible helpers are cached by source binding and target type, queued
with Compiler.add_early, and returned as typed identifiers; other
expressions pass through unchanged.
Source: src/callables.x:1283
Compiler.maybe_adapt_func_arg
List Compiler.maybe_adapt_func_arg( Compiler c, List argument, List expected_type)
Adapts a direct native function argument when FuncAdapter is expected.
A noncapturing lambda is lowered to its direct function designator. Other
arguments must be resolved direct designators, possibly parenthesized,
cast, or addressed; an indirect function-pointer value is rejected.
A function already having the adapter’s pointee type passes through,
and new helpers are cached and queued with Compiler.add_early.
Source: src/callables.x:985
Compiler.prepare_lambda_cells
List Compiler.prepare_lambda_cells(Compiler c, List declarator, List body)
Prepares one resolved function body for shared mutable lambda captures.
declarator must carry a resolved bind with fnmod parameters, and
body must agree with the automatic-binding and type facts in Compiler.
Before normal body transformation, the method rewrites explicitly shared
parameters and locals to Scope-owned cells, prepares nested bodies,
and returns the rewritten body with declaration and initializer order
preserved.
Source: src/callables.x:378
Design notes
A callable value that C cannot spell directly becomes a static helper
queued with Compiler.add_early. Every Func helper shares one
FuncAdapter ABI: arguments are read in index order from the argument
vector, and the result is boxed into a Var. A capturing lambda copies
its snapshots and reference addresses into a file-static context, and
the bindings it shares by reference move into Scope cells before the
enclosing function body is normalized.