pub struct Environment { /* private fields */ }
Expand description
Implements a nested lexical scope
Implementations§
Source§impl Environment
impl Environment
pub fn new() -> Self
Sourcepub fn no_builtins() -> Self
pub fn no_builtins() -> Self
Creates an Environment with no builtins
Sourcepub fn eval(&mut self, node: &impl Interpret) -> IResult<ConValue>
pub fn eval(&mut self, node: &impl Interpret) -> IResult<ConValue>
Reflexively evaluates a node
Sourcepub fn call(&mut self, name: Sym, args: &[ConValue]) -> IResult<ConValue>
pub fn call(&mut self, name: Sym, args: &[ConValue]) -> IResult<ConValue>
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<Sym, Option<ConValue>>
pub fn globals(&self) -> &HashMap<Sym, Option<ConValue>>
Gets all registered globals, bound or unbound.
Sourcepub fn add_builtins(&mut self, builtins: &'static [Builtin]) -> &mut Self
pub fn add_builtins(&mut self, builtins: &'static [Builtin]) -> &mut Self
pub fn push_frame( &mut self, name: &'static str, frame: HashMap<Sym, Option<ConValue>>, )
pub fn pop_frame( &mut self, ) -> Option<(HashMap<Sym, 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: Sym) -> IResult<&mut Option<ConValue>>
pub fn get_mut(&mut self, name: Sym) -> IResult<&mut Option<ConValue>>
Resolves a variable mutably.
Returns a mutable reference to the variable’s record, if it exists.
Sourcepub fn get(&self, name: Sym) -> IResult<ConValue>
pub fn get(&self, name: Sym) -> IResult<ConValue>
Resolves a variable immutably.
Returns a reference to the variable’s contents, if it is defined and initialized.
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: Sym, v: Option<ConValue>)
pub fn insert(&mut self, k: Sym, v: Option<ConValue>)
Inserts a new ConValue into this Environment
Sourcepub fn insert_fn(&mut self, decl: &FnDecl)
pub fn insert_fn(&mut self, decl: &FnDecl)
A convenience function for registering a [FnDecl] as a Function
Sourcepub fn stack_alloc(&mut self, value: ConValue) -> IResult<usize>
pub fn stack_alloc(&mut self, value: ConValue) -> IResult<usize>
Allocates a local variable
pub fn bind_raw(&mut self, name: Sym, id: usize) -> Option<()>
Trait Implementations§
Source§impl Clone for Environment
impl Clone for Environment
Source§fn clone(&self) -> Environment
fn clone(&self) -> Environment
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for Environment
impl Debug for Environment
Source§impl Default for Environment
impl Default for Environment
Auto Trait Implementations§
impl Freeze for Environment
impl !RefUnwindSafe for Environment
impl !Send for Environment
impl !Sync for Environment
impl Unpin for Environment
impl !UnwindSafe for Environment
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