state.l0

state.l0

Module: backend.state

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

Imports / Includes

  • types
  • type_resolve
  • scope_context
  • std.assert
  • std.vector
  • std.hashmap
  • std.hashset
  • std.string
  • std.text
  • ast
  • util.log
  • c_emitter.state
  • codegen_options
  • symbols
  • driver
  • c_emitter.names
  • sem_context
  • name_resolver

Symbols

Function be_ice

1
func be_ice(message: string)

Abort on an internal backend error.

Parameters:

  • message: ICE message to report.

Function be_ice_string

1
func be_ice_string(message: string) -> string

Abort on an internal backend error from a string-returning helper.

Parameters:

  • message: ICE message to report.

Returns: Dummy return used only to satisfy control-flow typing.

Function be_create

1
func be_create(result: AnalysisResult*, opts: CodegenOptions*, cfg: LogConfig*) -> Backend*

Create a backend state for one code-generation pass.

Parameters:

  • result: Borrowed semantic analysis result.
  • opts: Borrowed codegen options.
  • cfg: Borrowed log configuration.

Returns: New backend state.

Function be_free

1
func be_free(self: Backend*)

Free a backend state.

Parameters:

Function be_type_key

1
func be_type_key(module_name: string, type_name: string) -> string

Build a stable key for one user-defined type.

Parameters:

  • module_name: Defining module name.
  • type_name: Struct or enum name.

Returns: Key in module::type form.

Function be_type_key_module

1
func be_type_key_module(key: string) -> string

Return the module portion of a type key.

Parameters:

  • key: Type key in module::type form.

Returns: Module-name portion of the key.

Function be_type_key_name

1
func be_type_key_name(key: string) -> string

Return the type-name portion of a type key.

Parameters:

  • key: Type key in module::type form.

Returns: Type-name portion of the key.

Function be_current_env

1
func be_current_env(self: Backend*) -> ModuleEnv*

Return the current module environment.

Parameters:

Returns: Borrowed module environment.

Function be_current_unit

1
func be_current_unit(self: Backend*) -> DriverUnit*

Return the current unit.

Parameters:

Returns: Borrowed driver unit.

Function be_current_expr_arena

1
func be_current_expr_arena(self: Backend*) -> ExprArena*

Return the current expression arena.

Parameters:

Returns: Borrowed expression arena.

Function be_current_stmt_arena

1
func be_current_stmt_arena(self: Backend*) -> StmtArena*

Return the current statement arena.

Parameters:

Returns: Borrowed statement arena.

Function be_find_unit

1
func be_find_unit(self: Backend*, module_name: string) -> DriverUnit*?

Return a loaded driver unit by module name.

Parameters:

Returns: Matching loaded unit, or null if absent.

Function be_find_env

1
func be_find_env(self: Backend*, module_name: string) -> ModuleEnv*?

Return a module environment by name.

Parameters:

Returns: Matching module environment, or null if absent.

Function be_resolve_type_ref

1
func be_resolve_type_ref(self: Backend*, tref: TypeRef*) -> Type*?

Resolve one parsed type reference in the current module environment.

Parameters:

  • self: Backend state to inspect.
  • tref: Parsed type reference.

Returns: Resolved type, or null if resolution fails.

Function be_lookup_symbol

1
func be_lookup_symbol(self: Backend*, name: string, module_path: StringVector*?, name_qualifier: StringVector*?) -> Symbol*?

Look up a visible symbol from the current module.

Parameters:

  • self: Backend state to inspect.
  • name: Symbol name.
  • module_path: Optional explicit module path.
  • name_qualifier: Optional enum-name qualifier.

Returns: Matching symbol, or null if absent.

Function be_expr_type

1
func be_expr_type(self: Backend*, expr_id: ExprId) -> Type*?

Return the inferred type of an expression.

Parameters:

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

Returns: Cloned inferred type, or null if missing.

Function be_type_ptr_vec_temp_free

1
func be_type_ptr_vec_temp_free(items: VectorBase*?)

Free a temporary vector of optional owned Type* values.

Parameters:

  • items: Vector to free. Null entries are ignored.

Function be_type_ptr_map_temp_free

1
func be_type_ptr_map_temp_free(items: StringPtrMap*?)

Free a temporary map of owned Type* values.

Parameters:

  • items: Map to free.

Function be_resolve_let_type

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

Resolve the type of one local let declaration.

Parameters:

  • self: Backend state to inspect.
  • stmt: Parsed let statement.

Returns: Resolved type.

Function be_fresh_label

1
func be_fresh_label(self: Backend*, prefix: string) -> string

Return a fresh backend label name.

Parameters:

  • self: Backend state to update.
  • prefix: Label prefix.

Returns: Unique label string.

Function be_push_scope

1
func be_push_scope(self: Backend*) -> ScopeContext*

Push one lexical scope and make it current.

Parameters:

Returns: New current scope.

Function be_pop_scope

1
func be_pop_scope(self: Backend*)

Pop the current lexical scope.

Parameters:

Function be_push_loop_labels

1
func be_push_loop_labels(self: Backend*, break_label: string, continue_label: string)

Push one active loop-label frame.

Parameters:

  • self: Backend state to update.
  • break_label: Break target label.
  • continue_label: Continue target label.

Function be_pop_loop_labels

1
func be_pop_loop_labels(self: Backend*)

Pop one active loop-label frame.

Parameters:

Function be_push_loop_cleanup_scopes

1
func be_push_loop_cleanup_scopes(self: Backend*, continue_scope: ScopeContext*, break_scope: ScopeContext*)

Push one active loop-cleanup frame.

Parameters:

  • self: Backend state to update.
  • continue_scope: Scope to clean for continue.
  • break_scope: Scope to clean for break.

Function be_pop_loop_cleanup_scopes

1
func be_pop_loop_cleanup_scopes(self: Backend*)

Pop one active loop-cleanup frame.

Parameters:

Function be_lookup_local_var_type

1
func be_lookup_local_var_type(self: Backend*, var_name: string) -> Type*?

Return the type of a declared local binding when present.

Parameters:

  • self: Backend state to inspect.
  • var_name: Source-level variable name.

Returns: Borrowed declared type, or null if absent.

Function be_lookup_owned_local_name

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

Return the mangled name when a local variable is currently tracked as owned.

Parameters:

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

Returns: Mangled local name, or null when not owned by the current scope chain.

Function be_is_place_expr

1
func be_is_place_expr(self: Backend*, expr_id: ExprId) -> bool

Report whether an expression refers to an existing place.

Parameters:

  • self: Backend state to inspect.
  • expr_id: Expression to classify.

Returns: true for local/module places, dereferences, indexes, and fields.

Function be_has_side_effects

1
func be_has_side_effects(self: Backend*, expr_id: ExprId) -> bool

Report whether an expression may have side effects when evaluated.

Parameters:

  • self: Backend state to inspect.
  • expr_id: Expression to classify.

Returns: true when the expression should be cached before reuse.

Function be_pointer_type_or_null

1
func be_pointer_type_or_null(ty: Type*?) -> Type*?

Return the represented pointer type for pointer-shaped values.

Parameters:

  • ty: Type to inspect.

Returns: Pointer type, or null when not pointer-shaped.

Function be_scope_chain_has_cleanup

1
func be_scope_chain_has_cleanup(self: Backend*) -> bool

Report whether any scope in the current chain has pending cleanup work.

Parameters:

Returns: true when owned values or with cleanup are present.

Function be_is_int_assignable

1
func be_is_int_assignable(ty: Type*?) -> bool

Return whether a type behaves like an integer.

Parameters:

  • ty: Type to inspect.

Returns: true for int and byte.

Function be_int_type_size

1
func be_int_type_size(ty: Type*) -> int

Return the byte width of an integer builtin.

Parameters:

  • ty: Type to inspect.

Returns: Byte width for supported integer types.

Function type_free_opt

1
func type_free_opt(ty: Type*?)

Free an optional cloned type.

Parameters:

  • ty: Optional type to free.

Function be_find_struct_decl

1
func be_find_struct_decl(self: Backend*, module_name: string, struct_name: string) -> StructDecl*?

Look up a top-level struct declaration.

Parameters:

  • self: Backend state to inspect.
  • module_name: Defining module name.
  • struct_name: Struct name.

Returns: Matching declaration, or null if absent.

Function be_find_enum_decl

1
func be_find_enum_decl(self: Backend*, module_name: string, enum_name: string) -> EnumDecl*?

Look up a top-level enum declaration.

Parameters:

  • self: Backend state to inspect.
  • module_name: Defining module name.
  • enum_name: Enum name.

Returns: Matching declaration, or null if absent.

Function be_find_variant_decl

1
func be_find_variant_decl(self: Backend*, module_name: string, enum_name: string, variant_name: string) -> EnumVariant*?

Look up an enum variant declaration.

Parameters:

  • self: Backend state to inspect.
  • module_name: Defining module name.
  • enum_name: Enum name.
  • variant_name: Variant name.

Returns: Matching variant declaration, or null if absent.

Function be_emit_line_directive

1
func be_emit_line_directive(self: Backend*, span: Span)

Emit a #line directive for a declaration or statement when enabled.

Parameters:

  • self: Backend state to update.
  • span: Source span to report.

Struct Backend

Represents one Stage 2 backend generation session.

Backend Field result

1
result: AnalysisResult*

Backend Field opts

1
opts: CodegenOptions*

Backend Field cfg

1
cfg: LogConfig*

Backend Field emitter

1
emitter: CEmitter*

Backend Field current_module

1
current_module: string?

Backend Field current_unit

1
current_unit: DriverUnit*?

Backend Field current_env

1
current_env: ModuleEnv*?

Backend Field current_func_result

1
current_func_result: Type*?

Backend Field current_scope

1
current_scope: ScopeContext*?

Backend Field scope_stack

1
scope_stack: VectorBase*

Backend Field current_loop_labels

1
current_loop_labels: LoopLabels*?

Backend Field current_loop_cleanup_scopes

1
current_loop_cleanup_scopes: LoopCleanupScopes*?

Backend Field scope_counter

1
scope_counter: int

Backend Field label_counter

1
label_counter: int

Backend Field next_stmt_unreachable

1
next_stmt_unreachable: bool

Struct LoopLabels

Represents one active loop label pair.

LoopLabels Field parent

1
parent: LoopLabels*?

LoopLabels Field break_label

1
break_label: string

LoopLabels Field continue_label

1
continue_label: string

Struct LoopCleanupScopes

Represents the cleanup targets for one active loop.

LoopCleanupScopes Field parent

1
parent: LoopCleanupScopes*?

LoopCleanupScopes Field continue_scope

1
continue_scope: ScopeContext*

LoopCleanupScopes Field break_scope

1
break_scope: ScopeContext*

LoopCleanupScopes Field continue_scope_id

1
continue_scope_id: int

LoopCleanupScopes Field break_scope_id

1
break_scope_id: int