pub struct Environment {
values: Vec<ConValue>,
frames: Vec<EnvFrame>,
types: HashMap<Symbol, Type>,
impls: Vec<HashMap<Symbol, ConValue>>,
}Expand description
Implements a nested lexical scope
Fields§
§values: Vec<ConValue>§frames: Vec<EnvFrame>§types: HashMap<Symbol, Type>§impls: Vec<HashMap<Symbol, ConValue>>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: Symbol, args: &[ConValue]) -> IResult<ConValue>
pub fn call(&mut self, name: Symbol, args: &[ConValue]) -> IResult<ConValue>
Calls a function inside the Environment’s scope, and returns the result
Sourcepub fn bind(&mut self, name: impl Into<Symbol>, value: impl Into<ConValue>)
pub fn bind(&mut self, name: impl Into<Symbol>, value: impl Into<ConValue>)
Binds a value to the given name in the current scope.
pub fn bind_raw(&mut self, name: Symbol, id: usize) -> Option<()>
pub fn backtrace(&self) -> Backtrace<'_>
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: StackFrame)
pub fn pop_frame(&mut self) -> Option<(StackFrame, &'static str)>
Sourcepub fn frame(&mut self, name: &'static str, span: Option<Span>) -> Frame<'_>
pub fn frame(&mut self, name: &'static str, span: Option<Span>) -> Frame<'_>
Enters a nested scope, returning a Frame stack-guard.
Frame implements Deref/DerefMut for Environment.
Sourcepub fn with_frame<'e>(
&'e mut self,
name: &'static str,
frame: StackFrame,
) -> Frame<'e>
pub fn with_frame<'e>( &'e mut self, name: &'static str, frame: StackFrame, ) -> Frame<'e>
Enters a nested scope, assigning the contents of frame,
and returning a Frame stack-guard.
Frame implements Deref/DerefMut for Environment.
Sourcepub fn get_mut(&mut self, name: Symbol) -> IResult<&mut ConValue>
pub fn get_mut(&mut self, name: Symbol) -> IResult<&mut ConValue>
Resolves a variable mutably.
Returns a mutable reference to the variable’s record, if it exists.
Sourcepub fn get(&self, name: Symbol) -> IResult<ConValue>
pub fn get(&self, name: Symbol) -> IResult<ConValue>
Resolves a variable immutably.
Returns a reference to the variable’s contents, if it is defined and initialized.
Sourcepub fn id_of(&self, name: Symbol) -> IResult<usize>
pub fn id_of(&self, name: Symbol) -> IResult<usize>
Resolves the index associated with a Symbol
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 def_type(&mut self, name: Symbol, model: Model) -> Type
pub fn get_type(&self, name: Symbol) -> Option<Type>
Sourcepub fn stack_alloc(&mut self, value: ConValue) -> IResult<usize>
pub fn stack_alloc(&mut self, value: ConValue) -> IResult<usize>
Allocates a local variable
Trait Implementations§
Source§impl Clone for Environment
impl Clone for Environment
Source§fn clone(&self) -> Environment
fn clone(&self) -> Environment
Returns a duplicate 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