pub struct SymbolTable<'gc, C: CustomTypes<S>, S: System<C>>(/* private fields */);
Expand description
Holds a collection of variables in an execution context.
SymbolTable
has utilities to extract variables from an abstract syntax tree, or to explicitly define variables.
Simple methods are provided to perform value lookups in the table.
Implementations§
Source§impl<'gc, C: CustomTypes<S>, S: System<C>> SymbolTable<'gc, C, S>
impl<'gc, C: CustomTypes<S>, S: System<C>> SymbolTable<'gc, C, S>
Sourcepub fn define_or_redefine(
&mut self,
var: &str,
value: Shared<'gc, Value<'gc, C, S>>,
)
pub fn define_or_redefine( &mut self, var: &str, value: Shared<'gc, Value<'gc, C, S>>, )
Defines or redefines a value in the symbol table to a new instance of Shared<Value>
.
If a variable named var
already existed and was Shared::Aliased
, its value is not modified.
Sourcepub fn lookup<'a>(
&'a self,
var: &str,
) -> Option<&'a Shared<'gc, Value<'gc, C, S>>>
pub fn lookup<'a>( &'a self, var: &str, ) -> Option<&'a Shared<'gc, Value<'gc, C, S>>>
Looks up the given variable in the symbol table.
If a variable with the given name does not exist, returns None
.
Sourcepub fn lookup_mut<'a>(
&'a mut self,
var: &str,
) -> Option<&'a mut Shared<'gc, Value<'gc, C, S>>>
pub fn lookup_mut<'a>( &'a mut self, var: &str, ) -> Option<&'a mut Shared<'gc, Value<'gc, C, S>>>
Equivalent to SymbolTable::lookup
except that it returns a mutable reference.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Checks if the symbol table is currently empty (no defined symbols).
Trait Implementations§
Source§impl<'gc, C: CustomTypes<S>, S: System<C>> Clone for SymbolTable<'gc, C, S>
impl<'gc, C: CustomTypes<S>, S: System<C>> Clone for SymbolTable<'gc, C, S>
Source§impl<'gc, C: CustomTypes<S>, S: System<C>> Collect for SymbolTable<'gc, C, S>
impl<'gc, C: CustomTypes<S>, S: System<C>> Collect for SymbolTable<'gc, C, S>
Source§fn needs_trace() -> bool
fn needs_trace() -> bool
As an optimization, if this type can never hold a
Gc
pointer and trace
is unnecessary
to call, you may implement this method and return false. The default implementation returns
true, signaling that Collect::trace
must be called.Source§fn trace(&self, cc: &Collection)
fn trace(&self, cc: &Collection)
Must call
Collect::trace
on all held Gc
pointers. If this type holds inner types that
implement Collect
, a valid implementation would simply call Collect::trace
on all the
held values to ensure this.Source§impl<'gc, C: CustomTypes<S>, S: System<C>> Debug for SymbolTable<'gc, C, S>
impl<'gc, C: CustomTypes<S>, S: System<C>> Debug for SymbolTable<'gc, C, S>
Source§impl<'gc, C: CustomTypes<S>, S: System<C>> Default for SymbolTable<'gc, C, S>
impl<'gc, C: CustomTypes<S>, S: System<C>> Default for SymbolTable<'gc, C, S>
Auto Trait Implementations§
impl<'gc, C, S> Freeze for SymbolTable<'gc, C, S>
impl<'gc, C, S> !RefUnwindSafe for SymbolTable<'gc, C, S>
impl<'gc, C, S> !Send for SymbolTable<'gc, C, S>
impl<'gc, C, S> !Sync for SymbolTable<'gc, C, S>
impl<'gc, C, S> Unpin for SymbolTable<'gc, C, S>
impl<'gc, C, S> !UnwindSafe for SymbolTable<'gc, C, S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more