Provisional API: This reference documents current compiler behavior. Compatibility is not yet promised.
src/lambda.x
Lambda transformation helpers for the x2c compiler.
Functions
| Function | Summary |
|---|---|
Compiler.adapt_lambda_arg | Adapts a lowered noncapturing lambda helper to a typed callback. |
Compiler.check_lambda_captures | Rejects writes and reference access to read-only snapshot bindings. |
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 compiler, List argument, List expected_type)
Adapts a lowered noncapturing lambda helper to a typed callback.
argument must be a resolved (expr TYPE (ident BINDING)) produced by
Compiler.lower_lambda_expr, and 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/lambda.x:873
Compiler.check_lambda_captures
void Compiler.check_lambda_captures(Compiler c, List ast)
Rejects writes and reference access to read-only snapshot bindings. The body has already resolved identifiers and call arguments. Templates defer this check until expansion; nested lambdas check their own bodies.
Source: src/lambda.x:1047
Compiler.lift_func_expression
List Compiler.lift_func_expression(Compiler compiler, 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/lambda.x:823
Compiler.lower_lambda_expr
List Compiler.lower_lambda_expr(Compiler compiler, 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
Null, and synthesized declarations enter the early queue. Non-lambda
expressions pass through.
Source: src/lambda.x:1641
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/lambda.x:158
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/lambda.x:501
Compiler.prepare_lambda_cells
List Compiler.prepare_lambda_cells( Compiler compiler, 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/lambda.x:1323
Design notes
Lowers lambda literals into static helper functions, with
Func storage for
lexical captures, and synthesizes adapters when a receiving function
pointer differs from the canonical Var-based signature. Synthesized
declarations enter the Compiler’s early declaration queue.