Skip to main content

SymbolTable

Struct SymbolTable 

Source
pub struct SymbolTable { /* private fields */ }
Expand description

A hierarchical symbol table supporting scoped lookup.

Implementations§

Source§

impl SymbolTable

Source

pub fn new() -> Self

Source

pub fn child(parent: SymbolTable) -> Self

Create a child scope that inherits from this table.

Source

pub fn new_child(&self) -> Self

Create a child scope without consuming the parent (cloning).

Source

pub fn define(&mut self, name: String, kind: SymbolKind)

Define a symbol in this scope.

Source

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).

Source

pub fn define_param(&mut self, name: String, param_type: Type) -> i32

Define a script parameter and auto-assign a slot.

Source

pub fn lookup(&self, name: &str) -> Option<&Symbol>

Look up a symbol by name, searching up through parent scopes.

Source

pub fn lookup_local(&self, name: &str) -> Option<&Symbol>

Look up a symbol only in this scope (not parents).

Source

pub fn contains(&self, name: &str) -> bool

Check if a symbol exists in this scope or parent scopes.

Source

pub fn save_slots(&self) -> (i32, i32, i32)

Save the current slot counters. Used before entering a block scope.

Source

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.

Source

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.

Source

pub fn merge_decls(&mut self, child: &SymbolTable)

Merge total declaration counts from a child scope.

Source

pub fn int_local_count(&self) -> u16

Get the total int local count (includes redeclarations, matching Java compiler).

Source

pub fn string_local_count(&self) -> u16

Get the total string local count.

Source

pub fn long_local_count(&self) -> u16

Get the total long local count.

Source

pub fn reset_locals(&mut self)

Reset local variable counters (for starting a new script).

Source

pub fn iter(&self) -> impl Iterator<Item = (&String, &Symbol)>

Iterate over all symbols in this scope.

Trait Implementations§

Source§

impl Clone for SymbolTable

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SymbolTable

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SymbolTable

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more