|
Luma 0.1.0
A low-level compiled alternative to C, C++, and more!
|
Implementation of scope and symbol table management functions. More...

Functions | |
| void | init_scope (Scope *scope, Scope *parent, const char *name, ArenaAllocator *arena) |
| Initialize a scope structure with enhanced metadata. | |
| Symbol * | scope_lookup_with_visibility (Scope *scope, const char *name, Scope *requesting_module_scope) |
| const char * | get_current_function_name (Scope *scope) |
| bool | scope_add_symbol_with_ownership (Scope *scope, const char *name, AstNode *type, bool is_public, bool is_mutable, bool returns_ownership, bool takes_ownership, ArenaAllocator *arena) |
| bool | scope_add_symbol (Scope *scope, const char *name, AstNode *type, bool is_public, bool is_mutable, ArenaAllocator *arena) |
| Scope * | find_containing_module (Scope *scope) |
| Find the containing module scope for a given scope. | |
| Symbol * | scope_lookup (Scope *scope, const char *name) |
| Original scope_lookup - now wraps the visibility version. | |
| Symbol * | scope_lookup_current_only_with_visibility (Scope *scope, const char *name, Scope *requesting_module_scope) |
| Look up a symbol only in the current scope with visibility rules. | |
| Symbol * | scope_lookup_current_only (Scope *scope, const char *name) |
| Original scope_lookup_current_only - now wraps the visibility version. | |
| Scope * | create_child_scope (Scope *parent, const char *name, ArenaAllocator *arena) |
| Create a new child scope under the specified parent. | |
Implementation of scope and symbol table management functions.
This file contains the implementation of the hierarchical scope system for symbol table management. It provides functionality for creating, managing, and searching through nested scopes with proper parent-child relationships and symbol resolution.
The scope system supports:
| Scope * create_child_scope | ( | Scope * | parent, |
| const char * | name, | ||
| ArenaAllocator * | arena | ||
| ) |
Create a new child scope under the specified parent.
Allocates and initializes a new scope as a child of the given parent, automatically establishing the parent-child relationship and adding the new scope to the parent's children list.
| parent | Parent scope for the new child (NULL for root scope) |
| name | Descriptive name for the new scope |
| arena | Arena allocator for memory management |
Creation process:
| const char * get_current_function_name | ( | Scope * | scope | ) |
| void init_scope | ( | Scope * | scope, |
| Scope * | parent, | ||
| const char * | name, | ||
| ArenaAllocator * | arena | ||
| ) |
Initialize a scope structure with enhanced metadata.
Sets up a new scope with proper initialization of all fields, including parent-child relationships, depth calculation, and growable arrays for symbols and children. The scope is fully prepared for symbol addition and child scope creation.
| scope | Pointer to the scope structure to initialize (must be pre-allocated) |
| parent | Parent scope for hierarchical lookup (NULL for global scope) |
| name | Descriptive name for debugging and identification (NULL becomes "unnamed") |
| arena | Arena allocator for all memory allocations within this scope |
Initialization includes:
| bool scope_add_symbol | ( | Scope * | scope, |
| const char * | name, | ||
| AstNode * | type, | ||
| bool | is_public, | ||
| bool | is_mutable, | ||
| ArenaAllocator * | arena | ||
| ) |
| bool scope_add_symbol_with_ownership | ( | Scope * | scope, |
| const char * | name, | ||
| AstNode * | type, | ||
| bool | is_public, | ||
| bool | is_mutable, | ||
| bool | returns_ownership, | ||
| bool | takes_ownership, | ||
| ArenaAllocator * | arena | ||
| ) |
Original scope_lookup - now wraps the visibility version.
Original scope_lookup_current_only - now wraps the visibility version.
| Symbol * scope_lookup_current_only_with_visibility | ( | Scope * | scope, |
| const char * | name, | ||
| Scope * | requesting_module_scope | ||
| ) |
Look up a symbol only in the current scope with visibility rules.