l0_c_values.py
Module: l0_c_values
Source: compiler/stage1_py/l0_c_values.py Language: Python
Symbols
Namespace l0_c_values
Class l0_c_values::CValues
C value, pointer-access, lvalue, and constructor syntax.
Member Data l0_c_values.CValues.names
1
CNames names
Member Data l0_c_values.CValues.state
1
CEmitterState state
Member Data l0_c_values.CValues.types
1
CTypes types
Function l0_c_values.CValues.emit_ord
1
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.
Function l0_c_values.CValues.emit_widen_int
1
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.
Function l0_c_values.CValues.emit_int_literal
1
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).
Function l0_c_values.CValues.emit_byte_literal
1
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.
Function l0_c_values.CValues.emit_string_literal
1
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.
Function l0_c_values.CValues.emit_const_string_literal
1
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.
Function l0_c_values.CValues.emit_bool_literal
1
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.
Function l0_c_values.CValues.emit_const_bool_literal
1
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”.
Function l0_c_values.CValues.emit_var_ref
1
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.
Function l0_c_values.CValues.emit_unary_op
1
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.
Function l0_c_values.CValues.emit_negated_condition
1
str l0_c_values.CValues.emit_negated_condition(self, str c_cond)
Emit a negated condition expression for control-flow lowering.
Function l0_c_values.CValues.emit_binary_op
1
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.
Function l0_c_values.CValues.emit_condition_binary_op
1
str l0_c_values.CValues.emit_condition_binary_op(self, str op, str c_left, str c_right)
Emit a top-level binary condition for direct statement headers.
Function l0_c_values.CValues.emit_checked_int_div
1
str l0_c_values.CValues.emit_checked_int_div(self, str c_left, str c_right)
Emit C code for checked integer division runtime call.
Function l0_c_values.CValues.emit_checked_int_mod
1
str l0_c_values.CValues.emit_checked_int_mod(self, str c_left, str c_right)
Emit C code for checked integer modulo runtime call.
Function l0_c_values.CValues.emit_checked_int_mul
1
str l0_c_values.CValues.emit_checked_int_mul(self, str c_left, str c_right)
Emit C code for checked integer multiplication runtime call.
Function l0_c_values.CValues.emit_checked_int_add
1
str l0_c_values.CValues.emit_checked_int_add(self, str c_left, str c_right)
Emit C code for checked integer addition runtime call.
Function l0_c_values.CValues.emit_checked_int_sub
1
str l0_c_values.CValues.emit_checked_int_sub(self, str c_left, str c_right)
Emit C code for checked integer subtraction runtime call.
Function l0_c_values.CValues.emit_function_call
1
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.
Function l0_c_values.CValues.emit_field_access
1
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 ‘.
’ or ‘->’.
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.
Function l0_c_values.CValues.emit_paren_expr
1
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.
Function l0_c_values.CValues.emit_cast
1
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.
Function l0_c_values.CValues.emit_checked_ptr_access
1
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.
Function l0_c_values.CValues.emit_checked_ptr_index_access
1
str l0_c_values.CValues.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")
Emit a runtime-checked indexed pointer access expression.
Function l0_c_values.CValues.emit_checked_ptr_access_for_base
1
str l0_c_values.CValues.emit_checked_ptr_access_for_base(self, str c_ptr_expr, str c_base_type, str access_mode="_RT_ACCESS_READ")
Emit a runtime-checked pointer to a complete object of c_base_type .
Function l0_c_values.CValues.emit_drop_begin_expr
1
str l0_c_values.CValues.emit_drop_begin_expr(self, str c_ptr_expr, str c_ptr_type, str c_required_size, str c_required_align)
Emit the expression that validates and begins a generated drop.
Function l0_c_values.CValues.emit_checked_narrow_cast
1
str l0_c_values.CValues.emit_checked_narrow_cast(self, str c_dst_type, str c_inner)
Emit C code for a checked narrowing cast runtime call.
Function l0_c_values.CValues.emit_unwrap_ptr
1
str l0_c_values.CValues.emit_unwrap_ptr(self, str c_dst_type, str c_inner, str type_str)
Emit C code for unwrapping a pointer-shaped optional runtime check.
Function l0_c_values.CValues.emit_unwrap_opt
1
str l0_c_values.CValues.emit_unwrap_opt(self, str c_src_type, str c_inner, str type_str)
Emit C code for unwrapping a value-optional runtime check.
Function l0_c_values.CValues.emit_null_check_eq
1
str l0_c_values.CValues.emit_null_check_eq(self, str c_expr)
Emit C code for null equality check (opt == null).
Function l0_c_values.CValues.emit_null_check_ne
1
str l0_c_values.CValues.emit_null_check_ne(self, str c_expr)
Emit C code for null inequality check (opt != null).
Function l0_c_values.CValues.emit_pointer_null_check
1
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.
Function l0_c_values.CValues.emit_condition_pointer_null_check
1
str l0_c_values.CValues.emit_condition_pointer_null_check(self, str c_expr, str op)
Emit a top-level pointer null comparison for direct statement headers.
Function l0_c_values.CValues.emit_optional_has_value
1
str l0_c_values.CValues.emit_optional_has_value(self, str c_expr)
Emit C code for reading an optional wrapper’s has-value flag.
Function l0_c_values.CValues.emit_optional_value
1
str l0_c_values.CValues.emit_optional_value(self, str c_expr)
Emit C code for reading an optional wrapper’s payload value.
Function l0_c_values.CValues.emit_enum_tag_access
1
str l0_c_values.CValues.emit_enum_tag_access(self, str c_expr)
Emit C code for reading an enum tag.
Function l0_c_values.CValues.emit_enum_payload_field_access
1
str l0_c_values.CValues.emit_enum_payload_field_access(self, str c_expr, str variant, str field)
Emit C code for reading a field from an enum payload.
Function l0_c_values.CValues.emit_string_equals_call
1
str l0_c_values.CValues.emit_string_equals_call(self, str lhs, str rhs)
Emit the runtime string-equality helper call.
Function l0_c_values.CValues.emit_string_concat_call
1
str l0_c_values.CValues.emit_string_concat_call(self, str lhs, str rhs)
Emit the runtime string-concatenation helper call.
Function l0_c_values.CValues.emit_string_compare_call
1
str l0_c_values.CValues.emit_string_compare_call(self, str op, str lhs, str rhs)
Emit the runtime string-compare helper call wrapped in a relational check.
Function l0_c_values.CValues.emit_condition_string_compare_call
1
str l0_c_values.CValues.emit_condition_string_compare_call(self, str op, str lhs, str rhs)
Emit a top-level string relational check for direct statement headers.
Function l0_c_values.CValues.emit_discard_expr
1
str l0_c_values.CValues.emit_discard_expr(self, str c_expr)
Emit a statement-context discard wrapper for an expression.
Function l0_c_values.CValues.emit_deref_lvalue
1
str l0_c_values.CValues.emit_deref_lvalue(self, str ptr_expr)
Emit C code for a dereference lvalue: (*ptr).
Function l0_c_values.CValues.emit_field_lvalue
1
str l0_c_values.CValues.emit_field_lvalue(self, str obj, str field, bool is_pointer)
Emit C code for a field access lvalue.
Function l0_c_values.CValues.emit_index_lvalue
1
str l0_c_values.CValues.emit_index_lvalue(self, str base, str index)
Emit C code for an index lvalue: base[idx].
Function l0_c_values.CValues.emit_struct_constructor
1
str l0_c_values.CValues.emit_struct_constructor(self, str c_struct_name, list[tuple[str, str]] field_inits)
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 }.
Function l0_c_values.CValues.emit_struct_static_initializer
1
str l0_c_values.CValues.emit_struct_static_initializer(self, list[tuple[str, str]] field_inits)
Emit a brace-only struct initializer for static storage duration.
Function l0_c_values.CValues.emit_struct_constructor_for_type
1
str l0_c_values.CValues.emit_struct_constructor_for_type(self, StructType struct_type, list[tuple[str, str]] field_inits)
Emit a C struct constructor for an L0 struct type.
Function l0_c_values.CValues.emit_struct_static_initializer_for_type
1
str l0_c_values.CValues.emit_struct_static_initializer_for_type(self, StructType struct_type, list[tuple[str, str]] field_inits)
Emit a static-storage struct initializer for an L0 struct type.
Function l0_c_values.CValues.emit_variant_constructor
1
str l0_c_values.CValues.emit_variant_constructor(self, str c_enum_name, str variant_name, str tag_value, list[tuple[str, str]] payload_inits)
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.
Function l0_c_values.CValues.emit_variant_static_initializer
1
str l0_c_values.CValues.emit_variant_static_initializer(self, str variant_name, str tag_value, list[tuple[str, str]] payload_inits)
Emit a brace-only enum tagged-union initializer for static storage duration.
Function l0_c_values.CValues.emit_variant_constructor_for_type
1
str l0_c_values.CValues.emit_variant_constructor_for_type(self, EnumType enum_type, str variant_name, list[tuple[str, str]] payload_inits)
Emit a tagged union constructor for a given L0 enum type.
Function l0_c_values.CValues.emit_variant_static_initializer_for_type
1
str l0_c_values.CValues.emit_variant_static_initializer_for_type(self, EnumType enum_type, str variant_name, list[tuple[str, str]] payload_inits)
Emit a static-storage tagged union initializer for a given L0 enum type.
Function l0_c_values.CValues.emit_pattern_binding_init
1
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.
Function l0_c_values.CValues._string_token_to_c_bytes_and_len
1
tuple[str, int] l0_c_values.CValues._string_token_to_c_bytes_and_len(self, str value)
Decode an L0 string token payload and encode as C string-literal bytes.