Struct Environment
pub struct Environment { /* private fields */ }Expand description
Implements a nested lexical scope
Implementations§
§impl Environment
 
impl Environment
pub fn new() -> Environment
pub fn no_builtins() -> Environment
pub fn no_builtins() -> Environment
Creates an Environment with no builtins
pub fn eval(&mut self, node: &impl Interpret) -> Result<ConValue, Error>
pub fn eval(&mut self, node: &impl Interpret) -> Result<ConValue, Error>
Reflexively evaluates a node
pub fn call(
    &mut self,
    name: Interned<'static, str>,
    args: &[ConValue],
) -> Result<ConValue, Error>
pub fn call( &mut self, name: Interned<'static, str>, args: &[ConValue], ) -> Result<ConValue, Error>
Calls a function inside the Environment’s scope, and returns the result
pub fn modules_mut(&mut self) -> &mut ModuleTree
pub fn modules(&self) -> &ModuleTree
pub fn bind(
    &mut self,
    name: impl Into<Interned<'static, str>>,
    value: impl Into<ConValue>,
)
pub fn bind( &mut self, name: impl Into<Interned<'static, str>>, value: impl Into<ConValue>, )
Binds a value to the given name in the current scope.
pub fn bind_raw( &mut self, name: Interned<'static, str>, id: usize, ) -> Option<()>
pub fn add_builtins(&mut self, builtins: &'static [Builtin]) -> &mut Environment
pub fn add_builtins(&mut self, builtins: &'static [Builtin]) -> &mut Environment
pub fn push_frame( &mut self, name: &'static str, frame: HashMap<Interned<'static, str>, ConValue>, )
pub fn pop_frame( &mut self, ) -> Option<(HashMap<Interned<'static, str>, ConValue>, &'static str)>
pub fn frame(&mut self, name: &'static str) -> Frame<'_>
pub fn frame(&mut self, name: &'static str) -> Frame<'_>
Enters a nested scope, returning a [Frame] stack-guard.
[Frame] implements Deref/DerefMut for Environment.
pub fn with_frame<'e>(
    &'e mut self,
    name: &'static str,
    frame: HashMap<Interned<'static, str>, ConValue>,
) -> Frame<'e>
pub fn with_frame<'e>( &'e mut self, name: &'static str, frame: HashMap<Interned<'static, str>, ConValue>, ) -> Frame<'e>
Enters a nested scope, assigning the contents of frame,
and returning a [Frame] stack-guard.
[Frame] implements Deref/DerefMut for Environment.
pub fn get_mut(
    &mut self,
    name: Interned<'static, str>,
) -> Result<&mut ConValue, Error>
pub fn get_mut( &mut self, name: Interned<'static, str>, ) -> Result<&mut ConValue, Error>
Resolves a variable mutably.
Returns a mutable reference to the variable’s record, if it exists.
pub fn get(&self, name: Interned<'static, str>) -> Result<ConValue, Error>
pub fn get(&self, name: Interned<'static, str>) -> Result<ConValue, Error>
Resolves a variable immutably.
Returns a reference to the variable’s contents, if it is defined and initialized.
pub fn id_of(&self, name: Interned<'static, str>) -> Result<usize, Error>
pub fn id_of(&self, name: Interned<'static, str>) -> Result<usize, Error>
Resolves the index associated with a [Sym]
pub fn get_id(&self, id: usize) -> Option<&ConValue>
pub fn get_id_mut(&mut self, id: usize) -> Option<&mut ConValue>
pub fn get_slice(&self, start: usize, len: usize) -> Option<&[ConValue]>
pub fn get_slice_mut( &mut self, start: usize, len: usize, ) -> Option<&mut [ConValue]>
pub fn insert(&mut self, k: Interned<'static, str>, v: ConValue)
pub fn insert(&mut self, k: Interned<'static, str>, v: ConValue)
Inserts a new ConValue into this Environment
pub fn insert_fn(&mut self, decl: &Function)
pub fn insert_fn(&mut self, decl: &Function)
A convenience function for registering a [FnDecl] as a [Function]
pub fn insert_tup_constructor( &mut self, name: Interned<'static, str>, arity: usize, )
pub fn stack_alloc(&mut self, value: ConValue) -> Result<usize, Error>
pub fn stack_alloc(&mut self, value: ConValue) -> Result<usize, Error>
Allocates a local variable
Trait Implementations§
§impl Clone for Environment
 
impl Clone for Environment
§fn clone(&self) -> Environment
 
fn clone(&self) -> Environment
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
 
fn clone_from(&mut self, source: &Self)
source. Read more