pub struct Environment { /* private fields */ }
Expand description
Implements a nested lexical scope
Implementations§
Source§impl Environment
impl Environment
pub fn new() -> Environment
Sourcepub fn no_builtins() -> Environment
pub fn no_builtins() -> Environment
Creates an Environment with no builtins
Sourcepub 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
Sourcepub 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 interpreter’s scope, and returns the result
Sourcepub fn bind(&mut self, name: &str, value: impl Into<ConValue>)
pub fn bind(&mut self, name: &str, value: impl Into<ConValue>)
Binds a value to the given name in the current scope.
Sourcepub fn globals(&self) -> &HashMap<Interned<'static, str>, Option<ConValue>>
pub fn globals(&self) -> &HashMap<Interned<'static, str>, Option<ConValue>>
Gets all registered globals, bound or unbound.
Sourcepub 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>, Option<ConValue>>, )
pub fn pop_frame( &mut self, ) -> Option<(HashMap<Interned<'static, str>, Option<ConValue>>, &'static str)>
Sourcepub 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
.
Sourcepub fn get_mut(
&mut self,
name: Interned<'static, str>,
) -> Result<&mut Option<ConValue>, Error>
pub fn get_mut( &mut self, name: Interned<'static, str>, ) -> Result<&mut Option<ConValue>, Error>
Resolves a variable mutably.
Returns a mutable reference to the variable’s record, if it exists.
Sourcepub 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.
Sourcepub fn id_of(&self, name: Interned<'static, str>) -> Result<Place, Error>
pub fn id_of(&self, name: Interned<'static, str>) -> Result<Place, Error>
Resolves the Place associated with a [Sym]
pub fn get_id(&self, at: Place) -> Option<&ConValue>
pub fn get_id_mut(&mut self, at: Place) -> Option<&mut Option<ConValue>>
Sourcepub fn insert(&mut self, k: Interned<'static, str>, v: Option<ConValue>)
pub fn insert(&mut self, k: Interned<'static, str>, v: Option<ConValue>)
Inserts a new ConValue into this Environment
Sourcepub 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
Sourcepub 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
pub fn bind_raw( &mut self, name: Interned<'static, str>, id: usize, ) -> Option<()>
impl Environment
Functions which aid in the implementation of Frame
Trait Implementations§
Source§impl Clone for Environment
impl Clone for Environment
Source§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