l0_c_statements::CStatements class

Defined in module l0_c_statements (l0_c_statements.py).

C statement, control-flow, and initialization syntax.

Public static attributes

static CNames names
static CEmitterState state
static CTypes types
static CValues values

Public functions

auto emit_expr_stmt(self, str c_expr) -> None
Emit an expression as a statement.
auto emit_return_stmt(self, str|None c_value) -> None
Emit a C return statement.
auto emit_exit_switch(self) -> None
Emit a C break statement to exit a switch block.
auto emit_label(self, str label) -> None
Emit a C label followed by a null statement.
auto emit_goto(self, str label) -> None
Emit a C goto statement.
auto emit_block_start(self) -> None
Emit an opening brace and increase indentation.
auto emit_block_end(self) -> None
Emit a closing brace and decrease indentation.
auto emit_while_header(self, str c_cond) -> None
Emit a C while loop header.
auto emit_if_header(self, str c_cond) -> None
Emit a C if statement header.
auto emit_else(self) -> None
Emit a C else keyword.
auto emit_for_loop_start(self) -> None
Emit a decorative comment and opening brace for a for loop block.
auto emit_for_loop_end(self) -> None
Emit closing brace for a for loop block.
auto emit_let_decl(self, str c_type, str c_var_name, str c_init) -> None
Emit a C local variable declaration with initializer.
auto emit_assignment(self, str c_target, str c_value) -> None
Emit a simple C assignment statement.
auto emit_pointer_assignment(self, str c_ptr_name, str c_value) -> None
Emit a C assignment through a pointer.
auto emit_checked_pointer_assignment(self, str c_ptr_name, str c_base_type, str c_value) -> None
Emit an assignment through a runtime-checked object pointer.
auto emit_temp_decl(self, str c_type, str c_temp_name, str c_value) -> None
Emit a C temporary variable declaration with initializer.
auto emit_comment(self, str comment) -> None
Emit a C block comment.
auto emit_match_scrutinee_decl(self, str c_type, str c_expr) -> None
Emit the scrutinee declaration for a match/case statement.
auto emit_switch_start(self, str c_expr) -> None
Emit a C switch statement header and opening brace.
auto emit_match_switch_start(self, str scrutinee_name) -> None
Emit a match switch over an enum tag.
auto emit_switch_end(self) -> None
Emit a C switch statement closing brace.
auto emit_case_label(self, str c_tag_value) -> None
Emit a C case label.
auto emit_default_label(self) -> None
Emit a C default case label.
auto emit_null_assignment(self, str c_var) -> None
Emit a NULL assignment to a variable.
auto emit_struct_init(self, str c_temp_name, str c_base_type, str c_init_str) -> None
Emit an object initialization through a pointer.
auto emit_struct_init_from_fields(self, str c_temp_name, Type base_type, list] field_inits[tuple[str, str]) -> None
Emit struct initialization using positional field values.
auto emit_enum_variant_init(self, str c_temp_name, EnumType enum_type, str variant_name, list] payload_inits[tuple[str, str]) -> None
Emit enum variant initialization for a heap-allocated enum.
auto emit_zero_init(self, str c_temp_name, str c_base_type) -> None
Emit zero-initialization through a pointer.
auto emit_try_check_niche(self, str c_tmp, str ret_none) -> None
Emit a NULL check for a niche-optimized optional.
auto emit_try_check_value(self, str c_tmp, str ret_none) -> None
Emit a has_value check for a value-optional.
auto emit_try_extract_value(self, str c_tmp) -> str
Emit C code to extract the inner value from an optional.

Function documentation

None l0_c_statements::CStatements::emit_expr_stmt(self, str c_expr)

Emit an expression as a statement.

Parameters
c_expr C expression string.

None l0_c_statements::CStatements::emit_return_stmt(self, str|None c_value)

Emit a C return statement.

Parameters
c_value Optional C expression string to return.

None l0_c_statements::CStatements::emit_label(self, str label)

Emit a C label followed by a null statement.

Parameters
label C label identifier.

None l0_c_statements::CStatements::emit_goto(self, str label)

Emit a C goto statement.

Parameters
label Target C label identifier.

None l0_c_statements::CStatements::emit_while_header(self, str c_cond)

Emit a C while loop header.

Parameters
c_cond C expression for the loop condition.

None l0_c_statements::CStatements::emit_if_header(self, str c_cond)

Emit a C if statement header.

Parameters
c_cond C expression for the condition.

None l0_c_statements::CStatements::emit_let_decl(self, str c_type, str c_var_name, str c_init)

Emit a C local variable declaration with initializer.

Parameters
c_type C type string.
c_var_name C identifier.
c_init C initializer expression string.

None l0_c_statements::CStatements::emit_assignment(self, str c_target, str c_value)

Emit a simple C assignment statement.

Parameters
c_target C lvalue expression.
c_value C expression for the value.

None l0_c_statements::CStatements::emit_pointer_assignment(self, str c_ptr_name, str c_value)

Emit a C assignment through a pointer.

Parameters
c_ptr_name C expression evaluating to a pointer.
c_value C expression for the value.

None l0_c_statements::CStatements::emit_temp_decl(self, str c_type, str c_temp_name, str c_value)

Emit a C temporary variable declaration with initializer.

Parameters
c_type C type string.
c_temp_name C identifier for temporary.
c_value C initializer expression string.

None l0_c_statements::CStatements::emit_comment(self, str comment)

Emit a C block comment.

Parameters
comment The comment text.

None l0_c_statements::CStatements::emit_match_scrutinee_decl(self, str c_type, str c_expr)

Emit the scrutinee declaration for a match/case statement.

Parameters
c_type C type string of scrutinee.
c_expr C expression for scrutinee value.

None l0_c_statements::CStatements::emit_switch_start(self, str c_expr)

Emit a C switch statement header and opening brace.

Parameters
c_expr C expression to switch on.

None l0_c_statements::CStatements::emit_match_switch_start(self, str scrutinee_name)

Emit a match switch over an enum tag.

Parameters
scrutinee_name Identifier of the scrutinee variable.

None l0_c_statements::CStatements::emit_case_label(self, str c_tag_value)

Emit a C case label.

Parameters
c_tag_value The constant C tag identifier or literal.

None l0_c_statements::CStatements::emit_null_assignment(self, str c_var)

Emit a NULL assignment to a variable.

Parameters
c_var C lvalue expression.

None l0_c_statements::CStatements::emit_struct_init(self, str c_temp_name, str c_base_type, str c_init_str)

Emit an object initialization through a pointer.

Parameters
c_temp_name Name of the pointer variable.
c_base_type C base object type string.
c_init_str C compound initializer body.

None l0_c_statements::CStatements::emit_struct_init_from_fields(self, str c_temp_name, Type base_type, list] field_inits[tuple[str, str])

Emit struct initialization using positional field values.

Parameters
c_temp_name Name of the pointer variable.
base_type L0 base object type.
field_inits List of (field_name, c_value) tuples.

None l0_c_statements::CStatements::emit_enum_variant_init(self, str c_temp_name, EnumType enum_type, str variant_name, list] payload_inits[tuple[str, str])

Emit enum variant initialization for a heap-allocated enum.

Parameters
c_temp_name Name of the pointer variable.
enum_type L0 enum type.
variant_name Name of the active variant.
payload_inits List of (field_name, c_value) tuples for payload.

None l0_c_statements::CStatements::emit_zero_init(self, str c_temp_name, str c_base_type)

Emit zero-initialization through a pointer.

Parameters
c_temp_name Name of the pointer variable.
c_base_type C base object type string.

None l0_c_statements::CStatements::emit_try_check_niche(self, str c_tmp, str ret_none)

Emit a NULL check for a niche-optimized optional.

Parameters
c_tmp C identifier of the temporary holding the optional.
ret_none C expression for the 'none' return value.

None l0_c_statements::CStatements::emit_try_check_value(self, str c_tmp, str ret_none)

Emit a has_value check for a value-optional.

Parameters
c_tmp C identifier of the temporary holding the optional.
ret_none C expression for the 'none' return value.

str l0_c_statements::CStatements::emit_try_extract_value(self, str c_tmp)

Emit C code to extract the inner value from an optional.

Parameters
c_tmp C identifier of the temporary holding the optional.
Returns C expression string for the extracted value.