locals.l0

locals.l0

Module: locals

Source: compiler/stage2_l0/src/locals.l0 Language: Dea/L0

Imports / Includes

  • driver
  • ast
  • util.diag
  • std.vector
  • std.text
  • std.string
  • util.strings
  • std.hashmap

Symbols

Enum LocalKind

1
LocalKind

Defines the LocalKind enumeration.

Variants:

  • LK_PARAM
  • LK_LOCAL
  • LK_PATTERN_VAR

Function lc_key

1
func lc_key(module_name: string, func_name: string) -> string

Build a fully qualified function-scope key.

Parameters:

  • module_name: Defining module name.
  • func_name: Function name.

Returns: Key in module::func form.

Function lc_scope_create

1
func lc_scope_create(parent: Scope*?) -> Scope*

Create a local scope with an optional parent scope.

Parameters:

  • parent: Parent scope, or null for the root scope.

Returns: New scope.

Function lc_scope_define

1
func lc_scope_define(self: Scope*, name: string, kind: LocalKind, decl_ptr: void*, decl_id: int, binding_slot: int)

Define a local symbol in the current scope if absent.

Parameters:

  • self: Scope to update.
  • name: Local name to bind.
  • kind: Kind of local binding.
  • decl_ptr: AST pointer associated with the binding.
  • decl_id: Owning statement, pattern, or parameter index.
  • binding_slot: Pattern binder slot, or -1 for other bindings.

Function lc_scope_lookup

1
func lc_scope_lookup(self: Scope*?, name: string) -> LocalSymbol*?

Look up a local symbol through the scope chain.

Parameters:

  • self: Starting scope, or null.
  • name: Local name to look up.

Returns: Matching symbol, or null if not found.

Function lc_scope_free

1
func lc_scope_free(self: Scope*)

Free a scope and its local-symbol table.

Parameters:

Function lc_func_env_free

1
func lc_func_env_free(self: FunctionEnv*)

Free one function-local environment.

Parameters:

  • self: Function environment to free.

Function locals_free

1
func locals_free(self: LocalsResult*)

Free the full locals-resolution result.

Parameters:

  • self: Locals result to free.

Function locals_env_count

1
func locals_env_count(self: LocalsResult*) -> int

Return the number of function environments in the locals result.

Parameters:

  • self: Locals result to inspect.

Returns: Function-environment count.

Function locals_env_get

1
func locals_env_get(self: LocalsResult*, index: int) -> FunctionEnv*

Return a function environment by index.

Parameters:

  • self: Locals result to inspect.
  • index: Zero-based function-environment index.

Returns: Function environment at index.

Function locals_env_find

1
func locals_env_find(self: LocalsResult*, module_name: string, func_name: string) -> FunctionEnv*?

Find a function environment by module and function name.

Parameters:

  • self: Locals result to inspect.
  • module_name: Module name.
  • func_name: Function name.

Returns: Matching function environment, or null if absent.

Function lc_func_env_get_block_scope

1
func lc_func_env_get_block_scope(self: FunctionEnv*, stmt_id: StmtId) -> Scope*?

Return the scope associated with a block statement.

Parameters:

  • self: Function environment to inspect.
  • stmt_id: Block statement id.

Returns: Scope for stmt_id, or null if none is recorded.

Function lc_func_env_get_match_arm_scope

1
func lc_func_env_get_match_arm_scope(self: FunctionEnv*, arm: MatchArm*) -> Scope*?

Return the scope associated with a match arm.

Parameters:

  • self: Function environment to inspect.
  • arm: Match arm to look up.

Returns: Scope for arm, or null if none is recorded.

Function lc_scope_track

1
func lc_scope_track(env: FunctionEnv*, scope: Scope*)

Record a scope so the function environment can free it later.

Parameters:

  • env: Function environment being populated.
  • scope: Scope to record.

Function lc_scope_set_block

1
func lc_scope_set_block(env: FunctionEnv*, stmt_id: StmtId, scope: Scope*)

Associate a block statement id with a scope.

Parameters:

  • env: Function environment being populated.
  • stmt_id: Block statement id.
  • scope: Scope to attach.

Function lc_bind_pattern

1
func lc_bind_pattern(env: FunctionEnv*, pattern_id: PatternId, scope: Scope*)

Bind pattern variables for a match arm into a scope.

Parameters:

  • env: Function environment providing the pattern arena.
  • pattern_id: Pattern to inspect.
  • scope: Scope to receive bindings.

Function lc_visit_block

1
func lc_visit_block(env: FunctionEnv*, block_id: StmtId, scope: Scope*)

Visits a block during AST traversal.

Parameters:

  • env: The current module environment.
  • block_id: The block id.
  • scope: The scope.

Function lc_visit_scoped_stmt

1
func lc_visit_scoped_stmt(env: FunctionEnv*, stmt_id: StmtId, scope: Scope*)

Visit a statement body under an already-created scope.

Parameters:

  • env: Current function environment.
  • stmt_id: Body statement id.
  • scope: Body scope.

Function lc_visit_match_arm

1
func lc_visit_match_arm(env: FunctionEnv*, arm: MatchArm*, parent_scope: Scope*)

Visits a arm during AST traversal.

Parameters:

  • env: The current module environment.
  • arm: The arm.
  • parent_scope: The parent scope.

Function lc_visit_case_arm

1
func lc_visit_case_arm(env: FunctionEnv*, arm: CaseArm*, parent_scope: Scope*)

Visits a arm during AST traversal.

Parameters:

  • env: The current module environment.
  • arm: The arm.
  • parent_scope: The parent scope.

Function lc_visit_case_else

1
func lc_visit_case_else(env: FunctionEnv*, arm: CaseElse*, parent_scope: Scope*)

Visits a else during AST traversal.

Parameters:

  • env: The current module environment.
  • arm: The arm.
  • parent_scope: The parent scope.

Function lc_visit_with

1
func lc_visit_with(env: FunctionEnv*, stmt_id: StmtId, stmt: StmtNode*, parent_scope: Scope*)

Visits a with during AST traversal.

Parameters:

  • env: The current module environment.
  • stmt_id: The with statement id.
  • stmt: The stmt.
  • parent_scope: The parent scope.

Function lc_visit_stmt

1
func lc_visit_stmt(env: FunctionEnv*, stmt_id: StmtId, scope: Scope*)

Visits a stmt during AST traversal.

Parameters:

  • env: The current module environment.
  • stmt_id: The stmt id.
  • scope: The scope.

Function lc_make_function_env

1
func lc_make_function_env(module_name: string, unit: DriverUnit*, decl: FuncDecl*) -> FunctionEnv*

Build locals metadata for one non-extern function.

Parameters:

  • module_name: Defining module name.
  • unit: Driver unit owning the function.
  • decl: Function declaration.

Returns: Populated function environment.

Function locals_resolve

1
func locals_resolve(driver_state: DriverState*, diags: DiagCollector*) -> LocalsResult*

Build local-scope environments for every non-extern function.

Parameters:

  • driver_state: Parsed driver state.
  • diags: Diagnostic collector.

Returns: Locals-resolution result.

Struct LocalSymbol

Represents the LocalSymbol structure.

LocalSymbol Field name

1
name: string

LocalSymbol Field kind

1
kind: LocalKind

LocalSymbol Field decl_ptr

1
decl_ptr: void*

LocalSymbol Field decl_id

1
decl_id: int

LocalSymbol Field binding_slot

1
binding_slot: int

Struct Scope

Represents the Scope structure.

Scope Field parent

1
parent: Scope*?

Scope Field symbols

1
symbols: StringPtrMap*

Struct MatchArmScopeEntry

Represents the MatchArmScopeEntry structure.

MatchArmScopeEntry Field arm

1
arm: MatchArm*

MatchArmScopeEntry Field scope

1
scope: Scope*

Struct ScopeSlot

Represents the ScopeSlot structure.

ScopeSlot Field scope

1
scope: Scope*?

Struct FunctionEnv

Represents the FunctionEnv structure.

FunctionEnv Field key

1
key: string

FunctionEnv Field module_name

1
module_name: string

FunctionEnv Field func_name

1
func_name: string

FunctionEnv Field func_decl

1
func_decl: FuncDecl*

FunctionEnv Field pattern_arena

1
pattern_arena: PatternArena*

FunctionEnv Field stmt_arena

1
stmt_arena: StmtArena*

FunctionEnv Field root_scope

1
root_scope: Scope*

FunctionEnv Field scopes

1
scopes: VectorBase*

FunctionEnv Field block_scopes

1
block_scopes: VectorBase*

FunctionEnv Field arm_scopes

1
arm_scopes: VectorBase*

Struct LocalsResult

Represents the LocalsResult structure.

LocalsResult Field envs

1
envs: VectorBase*

LocalsResult Field by_name

1
by_name: StringPtrMap*