Struct endbasic_core::syms::Symbols

source ·
pub struct Symbols { /* private fields */ }
Expand description

Storage for all symbols that exist at runtime.

Symbols are represented as a two-layer map: the globals map contains all symbols that are visible by all scopes, and the scope contains all symbols that are only visible within a given scope.

The collection of symbols that is visible at any given point in time is thus the union of the global symbols and the symbols in the last scope.

Scopes are represented as a stack in order to support nested function calls.

Implementations§

source§

impl Symbols

source

pub fn add_callable(&mut self, callable: Rc<dyn Callable>)

Registers the given builtin callable as a global symbol.

Given that callables cannot be defined at runtime, specifying a non-unique name results in a panic.

source

pub fn callables(&self) -> HashMap<&SymbolKey, Rc<dyn Callable>>

Returns the mapping of all callables.

source

pub fn locals(&self) -> &HashMap<SymbolKey, Symbol>

Returns the mapping of all symbols in the current scope that are not globals.

source

pub fn clear(&mut self)

Clears all user-defined symbols.

source

pub fn dim(&mut self, key: SymbolKey, etype: ExprType)

Defines a new local variable key of type etype. The variable must not yet exist.

source

pub fn dim_shared(&mut self, key: SymbolKey, etype: ExprType)

Defines a new global variable key of type etype. The variable must not yet exist.

source

pub fn dim_array( &mut self, key: SymbolKey, subtype: ExprType, dimensions: Vec<usize>, )

Defines a new array key of type subtype with dimensions. The array must not yet exist, and the name may not overlap function or variable names.

source

pub fn dim_shared_array( &mut self, key: SymbolKey, subtype: ExprType, dimensions: Vec<usize>, )

Defines a new global array key of type subtype with dimensions. The array must not yet exist, and the name may not overlap function or variable names.

source

pub fn get(&self, vref: &VarRef) -> Result<Option<&Symbol>>

Obtains the value of a symbol or None if it is not defined.

Returns an error if the type annotation in the symbol reference does not match its type.

source

pub fn get_auto(&self, var: &str) -> Option<&Symbol>

Obtains the value of a symbol or None if it is not defined.

source

pub fn get_mut(&mut self, vref: &VarRef) -> Result<Option<&mut Symbol>>

Obtains the value of a symbol or None if it is not defined.

Returns an error if the type annotation in the symbol reference does not match its type.

source

pub fn set_var(&mut self, vref: &VarRef, value: Value) -> Result<()>

Sets the value of a variable.

If vref contains a type annotation, the type of the value must be compatible with that type annotation.

If the variable is already defined, then the type of the new value must be compatible with the existing variable. In other words: a variable cannot change types while it’s alive.

Trait Implementations§

source§

impl Default for Symbols

source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl Freeze for Symbols

§

impl !RefUnwindSafe for Symbols

§

impl !Send for Symbols

§

impl !Sync for Symbols

§

impl Unpin for Symbols

§

impl !UnwindSafe for Symbols

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.