Source: src/codegen/codegen_expr.lx
Expression codegen for the C backend.
Dispatches an expression AST node and writes the corresponding C expression into the output buffer: literals, operators, calls, member access, struct/array literals, casts, and builtins.
Result of resolving a member against a struct: whether a field or method was found, its type, the dotted C path from the struct root, and (for methods) the struct that actually owns the method.
| Field | Type | Description |
|---|---|---|
found |
bool | |
is_method |
bool | |
type_node |
*AST::AstNode | |
c_path |
*byte | |
owner |
*byte |
pub gen_expr -> fn(
ctx: *CG::CodegenContext,
buf: *CG::Buf,
expr: *AST::AstNode
) void
static_type_of -> fn(
ctx: *CG::CodegenContext,
expr: *AST::AstNode
) *AST::AstNode
Returns t's pointee type if it is a pointer type, else t unchanged.
strip_ptr -> fn(
t: *AST::AstNode
) *AST::AstNode
Returns the input helper C function name backing input<T>(...) for
type t, or null if T isn't one of the readable types yet.
input_helper_name -> fn(
t: *AST::AstNode
) *byte
Returns a FieldLookup with found false.
not_found -> fn(
) FieldLookup
Looks member up on struct_name — direct public/private fields and
methods first, then recursively through ...Type, embedded members.
Returns the describing FieldLookup, or a not-found lookup.
resolve_field -> fn(
ctx: *CG::CodegenContext,
struct_name: *byte,
member: *byte
) FieldLookup
Dotted C path from struct_name down to an ...target, embedded member
of type target (direct or nested), or null if not embedded anywhere.
Drives explicit base-method dispatch. Caller owns the result.
#returns_ownership
find_embedded_path -> fn(
ctx: *CG::CodegenContext,
struct_name: *byte,
target: *byte
) *byte
Static type of an arbitrary expression, used to drive member access and
method-call resolution; falls back to expr.resolved_type where the
embedding-aware walk isn't needed.
static_type_of -> fn(
ctx: *CG::CodegenContext,
expr: *AST::AstNode
) *AST::AstNode
Writes s as a C string literal, escaping quotes, backslashes, and the
common control characters.
emit_c_string_literal -> fn(
buf: *CG::Buf,
s: *byte
) void
Writes the byte c as a C char literal, escaping quotes, backslashes, and
the common control characters.
emit_c_char_literal -> fn(
buf: *CG::Buf,
c: byte
) void
Writes the C argument expression for one output(...) argument, cast to
match its printf format (bool -> "true"/"false", byte -> int, floats ->
double, pointers as-is, else long long).
gen_output_arg -> fn(
ctx: *CG::CodegenContext,
buf: *CG::Buf,
arg: *AST::AstNode
) void
Returns the printf format specifier matching one output(...) argument's
static type.
output_fmt_for -> fn(
ctx: *CG::CodegenContext,
arg: *AST::AstNode
) *byte
Writes one printf(...) statement per output(...) argument.
pub gen_output_call -> fn(
ctx: *CG::CodegenContext,
buf: *CG::Buf,
args: **AST::AstNode,
arg_count: i64
) void
Emits a call expression: output/outputln lowered to printf, plain identifier calls, module-qualified and static-method calls, explicit base-method dispatch, instance-method calls (self passed by pointer), and a function-pointer fallthrough.
gen_call -> fn(
ctx: *CG::CodegenContext,
buf: *CG::Buf,
expr: *AST::AstNode
) void
Emits a member access: module-qualified globals/functions and enum members
(compiletime), embedding-aware field paths, and plain ./-> field
access.
gen_member -> fn(
ctx: *CG::CodegenContext,
buf: *CG::Buf,
expr: *AST::AstNode
) void
Emits a C compound literal for a struct expression, routing promoted
...Embedded fields to their dotted C paths.
gen_struct_literal -> fn(
ctx: *CG::CodegenContext,
buf: *CG::Buf,
expr: *AST::AstNode
) void
Returns the C operator string for a BinaryOp, or null for operators
with no direct C spelling (pow, range).
binop_str -> fn(
op: i64
) *byte
Emits a binary expression: ** lowers to a pow() call, .. to a
__luma_range_t{ ... } value, everything else to a parenthesized infix
C expression.
gen_binary -> fn(
ctx: *CG::CodegenContext,
buf: *CG::Buf,
expr: *AST::AstNode
) void
Emits a unary expression: postfix/prefix inc/dec and the prefix !, -,
+, ~ operators as parenthesized C.
gen_unary -> fn(
ctx: *CG::CodegenContext,
buf: *CG::Buf,
expr: *AST::AstNode
) void
Emits an array literal: a bare { ... } brace list for initializer
position, or a C99 compound literal (T[]){ ... } for expression
position.
pub gen_array_literal -> fn(
ctx: *CG::CodegenContext,
buf: *CG::Buf,
expr: *AST::AstNode,
as_compound_literal: bool
) void
Top-level expression dispatcher: routes an expression node by kind to the
per-node generators, emitting the C expression into buf.
pub gen_expr -> fn(
ctx: *CG::CodegenContext,
buf: *CG::Buf,
expr: *AST::AstNode
) void