l0_c_values::CValues class

Defined in module l0_c_values (l0_c_values.py).

C value, pointer-access, lvalue, and constructor syntax.

Public static attributes

static CNames names
static CEmitterState state
static CTypes types

Public functions

auto emit_ord(self, str c_enum_expr) -> str
Emit C code for ord(enum_value) intrinsic.
auto emit_widen_int(self, str c_expr, BuiltinType src_type, BuiltinType dst_type) -> str
Emit C code for implicit integer widening.
auto emit_int_literal(self, int value) -> str
Emit C code for an integer literal.
auto emit_byte_literal(self, str value) -> str
Emit C code for a byte literal.
auto emit_string_literal(self, str value) -> str
Emit C code for an ARC string literal.
auto emit_const_string_literal(self, str value) -> str
Emit C code for a static string literal initializer.
auto emit_bool_literal(self, bool value) -> str
Emit C code for a boolean literal expression.
auto emit_const_bool_literal(self, bool value) -> str
Emit C code for a boolean literal in a static initializer.
auto emit_var_ref(self, str c_name) -> str
Emit C code for a variable reference identifier.
auto emit_unary_op(self, str op, str c_operand) -> str
Emit C code for a unary operation.
auto emit_negated_condition(self, str c_cond) -> str
Emit a negated condition expression for control-flow lowering.
auto emit_binary_op(self, str op, str c_left, str c_right) -> str
Emit C code for a simple binary operation.
auto emit_condition_binary_op(self, str op, str c_left, str c_right) -> str
Emit a top-level binary condition for direct statement headers.
auto emit_checked_int_div(self, str c_left, str c_right) -> str
Emit C code for checked integer division runtime call.
auto emit_checked_int_mod(self, str c_left, str c_right) -> str
Emit C code for checked integer modulo runtime call.
auto emit_checked_int_mul(self, str c_left, str c_right) -> str
Emit C code for checked integer multiplication runtime call.
auto emit_checked_int_add(self, str c_left, str c_right) -> str
Emit C code for checked integer addition runtime call.
auto emit_checked_int_sub(self, str c_left, str c_right) -> str
Emit C code for checked integer subtraction runtime call.
auto emit_function_call(self, str c_func_name, str c_args) -> str
Emit C code for a function call.
auto emit_field_access(self, str c_obj, str field_name, bool is_pointer) -> str
Emit C code for field access using '.
auto emit_paren_expr(self, str c_inner) -> str
Emit C code for a parenthesized expression.
auto emit_cast(self, str c_type, str c_inner) -> str
Emit C code for a type cast.
auto emit_checked_ptr_access(self, str c_ptr_expr, str c_ptr_type, str c_required_size, str c_required_align, str access_mode = "_RT_ACCESS_READ") -> str
Emit a runtime-checked pointer access expression.
auto emit_checked_ptr_index_access(self, str c_base_expr, str c_index_expr, str c_ptr_type, str c_element_size, str c_required_align, str access_mode = "_RT_ACCESS_READ") -> str
Emit a runtime-checked indexed pointer access expression.
auto emit_checked_ptr_access_for_base(self, str c_ptr_expr, str c_base_type, str access_mode = "_RT_ACCESS_READ") -> str
Emit a runtime-checked pointer to a complete object of c_base_type.
auto emit_drop_begin_expr(self, str c_ptr_expr, str c_ptr_type, str c_required_size, str c_required_align) -> str
Emit the expression that validates and begins a generated drop.
auto emit_checked_narrow_cast(self, str c_dst_type, str c_inner) -> str
Emit C code for a checked narrowing cast runtime call.
auto emit_unwrap_ptr(self, str c_dst_type, str c_inner, str type_str) -> str
Emit C code for unwrapping a pointer-shaped optional runtime check.
auto emit_unwrap_opt(self, str c_src_type, str c_inner, str type_str) -> str
Emit C code for unwrapping a value-optional runtime check.
auto emit_null_check_eq(self, str c_expr) -> str
Emit C code for null equality check (opt == null).
auto emit_null_check_ne(self, str c_expr) -> str
Emit C code for null inequality check (opt != null).
auto emit_pointer_null_check(self, str c_expr, str op) -> str
Emit C code for pointer null comparison.
auto emit_condition_pointer_null_check(self, str c_expr, str op) -> str
Emit a top-level pointer null comparison for direct statement headers.
auto emit_optional_has_value(self, str c_expr) -> str
Emit C code for reading an optional wrapper's has-value flag.
auto emit_optional_value(self, str c_expr) -> str
Emit C code for reading an optional wrapper's payload value.
auto emit_enum_tag_access(self, str c_expr) -> str
Emit C code for reading an enum tag.
auto emit_enum_payload_field_access(self, str c_expr, str variant, str field) -> str
Emit C code for reading a field from an enum payload.
auto emit_string_equals_call(self, str lhs, str rhs) -> str
Emit the runtime string-equality helper call.
auto emit_string_concat_call(self, str lhs, str rhs) -> str
Emit the runtime string-concatenation helper call.
auto emit_string_compare_call(self, str op, str lhs, str rhs) -> str
Emit the runtime string-compare helper call wrapped in a relational check.
auto emit_condition_string_compare_call(self, str op, str lhs, str rhs) -> str
Emit a top-level string relational check for direct statement headers.
auto emit_discard_expr(self, str c_expr) -> str
Emit a statement-context discard wrapper for an expression.
auto emit_deref_lvalue(self, str ptr_expr) -> str
Emit C code for a dereference lvalue: (*ptr).
auto emit_field_lvalue(self, str obj, str field, bool is_pointer) -> str
Emit C code for a field access lvalue.
auto emit_index_lvalue(self, str base, str index) -> str
Emit C code for an index lvalue: base[idx].
auto emit_struct_constructor(self, str c_struct_name, list] field_inits[tuple[str, str]) -> str
Emit C code for a struct compound literal constructor.
auto emit_struct_static_initializer(self, list] field_inits[tuple[str, str]) -> str
Emit a brace-only struct initializer for static storage duration.
auto emit_struct_constructor_for_type(self, StructType struct_type, list] field_inits[tuple[str, str]) -> str
Emit a C struct constructor for an L0 struct type.
auto emit_struct_static_initializer_for_type(self, StructType struct_type, list] field_inits[tuple[str, str]) -> str
Emit a static-storage struct initializer for an L0 struct type.
auto emit_variant_constructor(self, str c_enum_name, str variant_name, str tag_value, list] payload_inits[tuple[str, str]) -> str
Emit C code for an enum variant tagged union literal.
auto emit_variant_static_initializer(self, str variant_name, str tag_value, list] payload_inits[tuple[str, str]) -> str
Emit a brace-only enum tagged-union initializer for static storage duration.
auto emit_variant_constructor_for_type(self, EnumType enum_type, str variant_name, list] payload_inits[tuple[str, str]) -> str
Emit a tagged union constructor for a given L0 enum type.
auto emit_variant_static_initializer_for_type(self, EnumType enum_type, str variant_name, list] payload_inits[tuple[str, str]) -> str
Emit a static-storage tagged union initializer for a given L0 enum type.
auto emit_pattern_binding_init(self, str scrutinee, str variant, str field) -> str
Emit C code for accessing a variant field during pattern matching.

Protected functions

auto _string_token_to_c_bytes_and_len(self, str value) -> tuple[str, int]
Decode an L0 string token payload and encode as C string-literal bytes.

Function documentation

str l0_c_values::CValues::emit_ord(self, str c_enum_expr)

Emit C code for ord(enum_value) intrinsic.

Parameters
c_enum_expr C expression evaluating to an enum value.
Returns A C expression that extracts the tag field and casts to l0_int.

str l0_c_values::CValues::emit_widen_int(self, str c_expr, BuiltinType src_type, BuiltinType dst_type)

Emit C code for implicit integer widening.

Parameters
c_expr C expression evaluating to the source value.
src_type The smaller source type.
dst_type The larger destination type.
Returns C code string for the widening cast.
Exceptions
InternalCompilerError If the widening path is unsupported.

str l0_c_values::CValues::emit_int_literal(self, int value)

Emit C code for an integer literal.

Parameters
value The integer value.
Returns C literal string (handles INT32_MIN edge case).

str l0_c_values::CValues::emit_byte_literal(self, str value)

Emit C code for a byte literal.

Parameters
value The byte literal character.
Returns C casted character literal.

str l0_c_values::CValues::emit_string_literal(self, str value)

Emit C code for an ARC string literal.

Parameters
value The L0 string token payload.
Returns C L0_STRING_CONST expression.

str l0_c_values::CValues::emit_const_string_literal(self, str value)

Emit C code for a static string literal initializer.

Parameters
value The L0 string token payload.
Returns C L0_STRING_CONST macro expression.

str l0_c_values::CValues::emit_bool_literal(self, bool value)

Emit C code for a boolean literal expression.

Parameters
value The boolean value.
Returns "1" for true, "0" for false.

str l0_c_values::CValues::emit_const_bool_literal(self, bool value)

Emit C code for a boolean literal in a static initializer.

Parameters
value The boolean value.
Returns "true" or "false".

str l0_c_values::CValues::emit_var_ref(self, str c_name)

Emit C code for a variable reference identifier.

Parameters
c_name Mangled C identifier.
Returns The identifier string.

str l0_c_values::CValues::emit_unary_op(self, str op, str c_operand)

Emit C code for a unary operation.

Parameters
op C unary operator string.
c_operand C expression for the operand.
Returns C unary expression string.

str l0_c_values::CValues::emit_binary_op(self, str op, str c_left, str c_right)

Emit C code for a simple binary operation.

Parameters
op C binary operator string.
c_left C expression for left operand.
c_right C expression for right operand.
Returns C binary expression string.

str l0_c_values::CValues::emit_function_call(self, str c_func_name, str c_args)

Emit C code for a function call.

Parameters
c_func_name C identifier or expression for the function.
c_args Comma-separated C expression string for arguments.
Returns C function call expression string.

str l0_c_values::CValues::emit_field_access(self, str c_obj, str field_name, bool is_pointer)

Emit C code for field access using '.

Parameters
c_obj C expression for the object.
field_name The field identifier.
is_pointer True if the object is a pointer.
Returns C field access expression string.

' or '->'.

str l0_c_values::CValues::emit_paren_expr(self, str c_inner)

Emit C code for a parenthesized expression.

Parameters
c_inner The inner C expression string.
Returns Parenthesized expression string.

str l0_c_values::CValues::emit_cast(self, str c_type, str c_inner)

Emit C code for a type cast.

Parameters
c_type Target C type string.
c_inner Expression to cast.
Returns C cast expression string.

str l0_c_values::CValues::emit_checked_ptr_access(self, str c_ptr_expr, str c_ptr_type, str c_required_size, str c_required_align, str access_mode = "_RT_ACCESS_READ")

Emit a runtime-checked pointer access expression.

Declares one static per-call-site cache slot so the runtime validates repeated accesses from the same site with a single range check.

str l0_c_values::CValues::emit_pointer_null_check(self, str c_expr, str op)

Emit C code for pointer null comparison.

Parameters
c_expr C expression for the pointer.
op Comparison operator (e.g., "==", "!=").
Returns C comparison expression string.

str l0_c_values::CValues::emit_struct_constructor(self, str c_struct_name, list] field_inits[tuple[str, str])

Emit C code for a struct compound literal constructor.

Parameters
c_struct_name Mangled C struct name.
field_inits List of (field_name, c_value) tuples.
Returns C compound literal: (struct name){ .f1 = v1, .f2 = v2 }.

str l0_c_values::CValues::emit_variant_constructor(self, str c_enum_name, str variant_name, str tag_value, list] payload_inits[tuple[str, str])

Emit C code for an enum variant tagged union literal.

Parameters
c_enum_name Mangled C enum name.
variant_name Name of the variant.
tag_value C tag value.
payload_inits List of (field_name, c_value) tuples for payload.
Returns C tagged union literal string.

str l0_c_values::CValues::emit_pattern_binding_init(self, str scrutinee, str variant, str field)

Emit C code for accessing a variant field during pattern matching.

Parameters
scrutinee Name of the scrutinee variable.
variant Name of the variant being matched.
field Name of the payload field being extracted.
Returns C field access expression string.