Struct endbasic_core::syms::Symbols
source · pub struct Symbols { /* private fields */ }
Expand description
Storage for all symbols that exist at runtime.
Implementations§
source§impl Symbols
impl Symbols
sourcepub fn add_command(&mut self, command: Rc<dyn Command>)
pub fn add_command(&mut self, command: Rc<dyn Command>)
Registers the given builtin command.
Given that commands cannot be defined at runtime, specifying a non-unique name results in a panic.
sourcepub fn add_function(&mut self, function: Rc<dyn Function>)
pub fn add_function(&mut self, function: Rc<dyn Function>)
Registers the given builtin function.
Given that functions cannot be defined at runtime, specifying a non-unique name results in a panic.
sourcepub fn as_hashmap(&self) -> &HashMap<String, Symbol>
pub fn as_hashmap(&self) -> &HashMap<String, Symbol>
Returns the mapping of all symbols.
sourcepub fn dim(&mut self, name: &str, vartype: VarType) -> Result<(), Error>
pub fn dim(&mut self, name: &str, vartype: VarType) -> Result<(), Error>
Defines a new variable name
of type vartype
. The variable must not yet exist.
sourcepub fn dim_array(
&mut self,
name: &str,
subtype: VarType,
dimensions: Vec<usize>
) -> Result<(), Error>
pub fn dim_array(
&mut self,
name: &str,
subtype: VarType,
dimensions: Vec<usize>
) -> Result<(), Error>
Defines a new array name
of type subtype
with dimensions
. The array must not yet
exist, and the name may not overlap function or variable names.
sourcepub fn get(&self, vref: &VarRef) -> Result<Option<&Symbol>, Error>
pub fn get(&self, vref: &VarRef) -> Result<Option<&Symbol>, Error>
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.
sourcepub fn get_auto(&self, var: &str) -> Option<&Symbol>
pub fn get_auto(&self, var: &str) -> Option<&Symbol>
Obtains the value of a symbol or None
if it is not defined.
sourcepub fn get_mut(&mut self, vref: &VarRef) -> Result<Option<&mut Symbol>, Error>
pub fn get_mut(&mut self, vref: &VarRef) -> Result<Option<&mut Symbol>, Error>
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.
sourcepub fn get_var(&self, vref: &VarRef) -> Result<&Value, Error>
pub fn get_var(&self, vref: &VarRef) -> Result<&Value, Error>
Obtains the value of a variable.
Returns an error if the variable is not defined, if the referenced symbol is not a variable, or if the type annotation in the variable reference does not match the type of the value that the variable contains.
sourcepub fn qualify_varref(&self, vref: &VarRef) -> Result<VarRef, Error>
pub fn qualify_varref(&self, vref: &VarRef) -> Result<VarRef, Error>
Adds a type annotation to the symbol reference if the symbol is already defined and the reference lacks one.
sourcepub fn set_var(&mut self, vref: &VarRef, value: Value) -> Result<(), Error>
pub fn set_var(&mut self, vref: &VarRef, value: Value) -> Result<(), Error>
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.