lowering.l0

lowering.l0

Module: backend.lowering

Source: compiler/stage2_l0/src/backend/lowering.l0 Language: Dea/L0

Imports / Includes

  • backend.lifetime
  • backend.state
  • types
  • symbols
  • scope_context
  • std.hashmap
  • std.text
  • c_emitter.state
  • signatures
  • ast
  • c_emitter.names
  • sem_context
  • c_emitter.types
  • backend.convert
  • c_emitter.lifetime
  • c_emitter.declarations
  • c_emitter.values
  • std.vector
  • c_emitter.statements

Symbols

Function be_emit_with_cleanup_header_let_predecl

1
func be_emit_with_cleanup_header_let_predecl(self: Backend*, stmt: StmtNode*) -> Type*?

Predeclare a nullable cleanup-block header let to its null literal.

Parameters:

  • self: Backend state to update.
  • stmt: Parsed let statement from a with header.

Returns: Resolved nullable type when predeclared, otherwise null.

Function be_emit_with_cleanup_header_let_assign

1
func be_emit_with_cleanup_header_let_assign(self: Backend*, stmt: StmtNode*, var_ty: Type*)

Emit the initializer assignment for a predeclared cleanup-block header let.

Parameters:

  • self: Backend state to update.
  • stmt: Parsed let statement from a with header.
  • var_ty: Resolved type of the predeclared variable.

Function be_emit_expr_with_expected_type

1
func be_emit_expr_with_expected_type(self: Backend*, expr_id: ExprId, expected: Type*) -> string

Emit one expression with implicit conversion to an expected type.

Parameters:

  • self: Backend state to inspect.
  • expr_id: Expression to lower.
  • expected: Expected destination type.

Returns: Lowered expression string.

Function be_emit_owned_expr_with_expected_type

1
func be_emit_owned_expr_with_expected_type(self: Backend*, expr_id: ExprId, expected: Type*) -> string

Emit one expression for a context that creates a new owner.

Parameters:

  • self: Backend state to inspect.
  • expr_id: Expression to lower.
  • expected: Expected destination type.

Returns: Lowered expression string, with retain-on-copy when required.

Function be_emit_lvalue

1
func be_emit_lvalue(self: Backend*, expr_id: ExprId) -> string

Emit one local or module lvalue.

Parameters:

  • self: Backend state to inspect.
  • expr_id: Target expression id.

Returns: Lowered lvalue expression.

Function be_emit_binary_op

1
func be_emit_binary_op(self: Backend*, expr_id: ExprId) -> string

Emit one binary operation.

Parameters:

  • self: Backend state to inspect.
  • expr_id: Binary expression id.

Returns: Lowered binary expression.

Function be_emit_condition_expr

1
func be_emit_condition_expr(self: Backend*, expr_id: ExprId) -> string

Emit one top-level condition expression for direct statement headers.

Only the outermost condition operator is unwrapped; child expressions keep the normal expression emitter so precedence-preserving inner parentheses stay intact.

Parameters:

  • self: Backend state to inspect.
  • expr_id: Expression id to lower.

Returns: Lowered condition expression.

Function be_emit_constructor_call

1
func be_emit_constructor_call(self: Backend*, expr_id: ExprId, sym: Symbol*, result_ty: Type*) -> string

Emit one struct or enum-variant constructor.

Parameters:

  • self: Backend state to inspect.
  • expr_id: Call expression id.
  • sym: Resolved constructor symbol.
  • result_ty: Inferred result type of the call.

Returns: Lowered constructor expression.

Function be_emit_call

1
func be_emit_call(self: Backend*, expr_id: ExprId) -> string

Emit one call expression.

Parameters:

  • self: Backend state to inspect.
  • expr_id: Call expression id.

Returns: Lowered call expression.

Function be_emit_new_expr

1
func be_emit_new_expr(self: Backend*, expr_id: ExprId) -> string

Emit one heap-allocation new expression.

Parameters:

  • self: Backend state to inspect.
  • expr_id: New-expression id.

Returns: Lowered pointer expression.

Function be_emit_expr

1
func be_emit_expr(self: Backend*, expr_id: ExprId) -> string

Emit one expression.

Parameters:

  • self: Backend state to inspect.
  • expr_id: Expression id to lower.

Returns: Lowered expression string.

Function be_emit_with_cleanup_from_scope

1
func be_emit_with_cleanup_from_scope(self: Backend*, scope: ScopeContext*)

Emit with cleanup recorded on one scope.

Parameters:

  • self: Backend state to update.
  • scope: Scope carrying with cleanup state.

Function be_register_inline_with_cleanup

1
func be_register_inline_with_cleanup(scope: ScopeContext*, item: WithItem*)

Register one inline with cleanup item in LIFO order.

Parameters:

  • scope: Scope carrying inline cleanup state.
  • item: Parsed with item whose cleanup should be registered.

Function be_emit_cleanup_for_return

1
func be_emit_cleanup_for_return(self: Backend*, returned_var: string?)

Emit cleanup required before returning from the current function.

Parameters:

  • self: Backend state to update.
  • returned_var: Optional owned local to keep alive across cleanup.

Function be_emit_cleanup_for_loop_exit

1
func be_emit_cleanup_for_loop_exit(self: Backend*, is_break: bool)

Emit cleanup required before breaking or continuing out of the innermost loop.

Parameters:

  • self: Backend state to update.
  • is_break: true for break, false for continue.

Function be_emit_return_stmt_with_inline_cleanup

1
func be_emit_return_stmt_with_inline_cleanup(self: Backend*, stmt: StmtNode*, inline_scope: ScopeContext*?, inline_cleanup: StmtId)

Emit a return statement, optionally registering one inline with-item cleanup first.

Parameters:

  • self: Backend state to update.
  • stmt: Parsed return statement.
  • inline_scope: Optional with scope for a committed inline header return.
  • inline_cleanup: Cleanup statement to register when inline_scope is present.

Function be_emit_pattern_bindings

1
func be_emit_pattern_bindings(self: Backend*, pattern_id: PatternId, enum_type: Type*, arm_scope: ScopeContext*)

Emit one match-pattern payload binding set.

Parameters:

  • self: Backend state to update.
  • pattern_id: Pattern id to inspect.
  • enum_type: Scrutinee enum type.
  • arm_scope: Arm scope receiving borrowed bindings.

Function be_emit_case_literal

1
func be_emit_case_literal(self: Backend*, expr_id: ExprId) -> string

Emit one case literal.

Parameters:

  • self: Backend state to inspect.
  • expr_id: Literal expression id.

Returns: Lowered constant expression.

Function be_emit_match_stmt

1
func be_emit_match_stmt(self: Backend*, stmt: StmtNode*)

Emit a match statement.

Parameters:

  • self: Backend state to update.
  • stmt: Parsed match statement.

Function be_emit_case_stmt

1
func be_emit_case_stmt(self: Backend*, stmt: StmtNode*)

Emit a case statement.

Parameters:

  • self: Backend state to update.
  • stmt: Parsed case statement.

Function be_emit_inline_with_header_item

1
func be_emit_inline_with_header_item(self: Backend*, item: WithItem*, with_scope: ScopeContext*)

Emit one inline with header item and register cleanup at the committed point.

Parameters:

  • self: Backend state to update.
  • item: Parsed inline with item.
  • with_scope: Scope carrying inline cleanup state.

Function be_emit_with_stmt

1
func be_emit_with_stmt(self: Backend*, stmt: StmtNode*)

Emit a with statement.

Parameters:

  • self: Backend state to update.
  • stmt: Parsed with statement.

Function be_emit_block_sequence

1
func be_emit_block_sequence(self: Backend*, block_id: StmtId)

Emit one block body sequence without outer braces.

Parameters:

  • self: Backend state to update.
  • block_id: Block statement id.

Function be_emit_block_stmt

1
func be_emit_block_stmt(self: Backend*, stmt_id: StmtId)

Emit one lexical block statement.

Parameters:

  • self: Backend state to update.
  • stmt_id: Block statement id.

Function be_emit_condition_branch

1
func be_emit_condition_branch(self: Backend*, expr_id: ExprId, true_label: string, false_label: string)

Emit control flow for one statement condition with short-circuit semantics.

ARC temps produced while lowering condition leaves stay inside the emitted condition block instead of being hoisted into an enclosing control-flow header.

Parameters:

  • self: Backend state to update.
  • expr_id: Condition expression to lower.
  • true_label: Jump target when the condition is true.
  • false_label: Jump target when the condition is false.

Function be_emit_condition_value

1
func be_emit_condition_value(self: Backend*, expr_id: ExprId) -> string

Evaluate one statement condition into a stable boolean temp.

The returned temp is safe to reference from an if / while header because condition ARC temps are scoped to the emitted condition block and cleaned before control continues.

Parameters:

  • self: Backend state to update.
  • expr_id: Condition expression to lower.

Returns: Name of the generated boolean temp.

Function be_emit_if_branch

1
func be_emit_if_branch(self: Backend*, stmt_id: StmtId) -> bool

Emit one if branch and report whether it ends unreachable.

Parameters:

  • self: Backend state to update.
  • stmt_id: Statement id for the branch.

Returns: true when control cannot fall through the branch.

Function be_emit_stmt

1
func be_emit_stmt(self: Backend*, stmt_id: StmtId)

Emit one statement.

Parameters:

  • self: Backend state to update.
  • stmt_id: Statement id to lower.