pub struct SymbolTable { /* private fields */ }Expand description
A hierarchical symbol table supporting scoped lookup.
Implementations§
Source§impl SymbolTable
impl SymbolTable
pub fn new() -> Self
Sourcepub fn child(parent: SymbolTable) -> Self
pub fn child(parent: SymbolTable) -> Self
Create a child scope that inherits from this table.
Sourcepub fn define(&mut self, name: String, kind: SymbolKind)
pub fn define(&mut self, name: String, kind: SymbolKind)
Define a symbol in this scope.
Sourcepub fn define_local(
&mut self,
name: String,
var_type: Type,
is_array: bool,
) -> i32
pub fn define_local( &mut self, name: String, var_type: Type, is_array: bool, ) -> i32
Define a local variable and auto-assign a slot.
is_array should be true for array declarations — arrays are excluded from
the local count in the trailer (matching the reference compiler).
Sourcepub fn define_param(&mut self, name: String, param_type: Type) -> i32
pub fn define_param(&mut self, name: String, param_type: Type) -> i32
Define a script parameter and auto-assign a slot.
Sourcepub fn lookup(&self, name: &str) -> Option<&Symbol>
pub fn lookup(&self, name: &str) -> Option<&Symbol>
Look up a symbol by name, searching up through parent scopes.
Sourcepub fn lookup_local(&self, name: &str) -> Option<&Symbol>
pub fn lookup_local(&self, name: &str) -> Option<&Symbol>
Look up a symbol only in this scope (not parents).
Sourcepub fn contains(&self, name: &str) -> bool
pub fn contains(&self, name: &str) -> bool
Check if a symbol exists in this scope or parent scopes.
Sourcepub fn save_slots(&self) -> (i32, i32, i32)
pub fn save_slots(&self) -> (i32, i32, i32)
Save the current slot counters. Used before entering a block scope.
Sourcepub fn restore_slots(&mut self, saved: (i32, i32, i32))
pub fn restore_slots(&mut self, saved: (i32, i32, i32))
Restore slot counters to a saved state, but only if higher counters haven’t been set by a sibling scope. This is used between sibling blocks (if/else) so each branch starts from the same slot baseline.
Sourcepub fn merge_slots(&mut self, other: (i32, i32, i32))
pub fn merge_slots(&mut self, other: (i32, i32, i32))
Advance slot counters to be at least as high as the given values. Used after a block scope to ensure the next sibling doesn’t reuse slots.
Sourcepub fn merge_decls(&mut self, child: &SymbolTable)
pub fn merge_decls(&mut self, child: &SymbolTable)
Merge total declaration counts from a child scope.
Sourcepub fn int_local_count(&self) -> u16
pub fn int_local_count(&self) -> u16
Get the total int local count (includes redeclarations, matching Java compiler).
Sourcepub fn string_local_count(&self) -> u16
pub fn string_local_count(&self) -> u16
Get the total string local count.
Sourcepub fn long_local_count(&self) -> u16
pub fn long_local_count(&self) -> u16
Get the total long local count.
Sourcepub fn reset_locals(&mut self)
pub fn reset_locals(&mut self)
Reset local variable counters (for starting a new script).
Trait Implementations§
Source§impl Clone for SymbolTable
impl Clone for SymbolTable
Source§fn clone(&self) -> SymbolTable
fn clone(&self) -> SymbolTable
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more