[−][src]Struct wlambda::vval::Env
The runtime environment of the evaluator.
Fields
args: Vec<VVal>
The argument stack, limited to STACK_SIZE
.
fun: Rc<VValFun>
A reference to the currently executed function.
Used for accessing the up values and other details about the function.
bp: usize
The basepointer to reference arguments and local variables.
bp + n (n >= 0)
references a local variablebp - n (n > 0)
references an argument
sp: usize
The current stack pointer.
argc: usize
The argument count to the current call.
user: Rc<RefCell<dyn Any>>
A user defined variable that holds user context information. See also the with_user_do function.
exports: HashMap<String, VVal>
The exported names of this module.
Methods
impl Env
[src]
pub fn new() -> Env
[src]
pub fn new_with_user(user: Rc<RefCell<dyn Any>>) -> Env
[src]
pub fn get_user(&self) -> Rc<RefCell<dyn Any>>
[src]
Returns the passed in user context value.
pub fn with_user_do<T: 'static, F, X>(&mut self, f: F) -> X where
F: Fn(&mut T) -> X,
[src]
F: Fn(&mut T) -> X,
Easier access to the user data field in Env
In the following example the user supplies a registry vector for storing VVals. A callback is stored, which is then later executed.
use wlambda::{VVal, EvalContext, GlobalEnv}; use wlambda::vval::Env; use std::rc::Rc; use std::cell::RefCell; let global = GlobalEnv::new_default(); global.borrow_mut().add_func("reg", |env: &mut Env, _argc: usize| { let fun = env.arg(0); env.with_user_do(|v: &mut Vec<VVal>| v.push(fun.clone())); Ok(VVal::Nul) }, Some(1), Some(1)); let reg : Rc<RefCell<Vec<VVal>>> = Rc::new(RefCell::new(Vec::new())); let mut ctx = EvalContext::new_with_user(global, reg.clone()); ctx.eval("reg { _ + 10 }").unwrap(); let n = reg.borrow_mut()[0].clone(); let ret = ctx.call(&n, &vec![VVal::Int(11)]).unwrap(); assert_eq!(ret.i(), 21);
pub fn export_name(&mut self, name: &str, value: &VVal)
[src]
pub fn set_bp(&mut self, env_size: usize) -> usize
[src]
pub fn reset_bp(&mut self, env_size: usize, oldbp: usize)
[src]
pub fn with_local_call_info<T>(
&mut self,
argc: usize,
f: T
) -> Result<VVal, StackAction> where
T: Fn(&mut Env) -> Result<VVal, StackAction>,
[src]
&mut self,
argc: usize,
f: T
) -> Result<VVal, StackAction> where
T: Fn(&mut Env) -> Result<VVal, StackAction>,
pub fn with_fun_info<T>(
&mut self,
fu: Rc<VValFun>,
argc: usize,
f: T
) -> Result<VVal, StackAction> where
T: Fn(&mut Env) -> Result<VVal, StackAction>,
[src]
&mut self,
fu: Rc<VValFun>,
argc: usize,
f: T
) -> Result<VVal, StackAction> where
T: Fn(&mut Env) -> Result<VVal, StackAction>,
pub fn with_restore_sp<T>(&mut self, f: T) -> Result<VVal, StackAction> where
T: Fn(&mut Env) -> Result<VVal, StackAction>,
[src]
T: Fn(&mut Env) -> Result<VVal, StackAction>,
pub fn with_pushed_sp<T>(&mut self, n: usize, f: T) -> Result<VVal, StackAction> where
T: Fn(&mut Env) -> Result<VVal, StackAction>,
[src]
T: Fn(&mut Env) -> Result<VVal, StackAction>,
pub fn push_sp(&mut self, n: usize)
[src]
pub fn push(&mut self, v: VVal) -> usize
[src]
pub fn popn(&mut self, n: usize)
[src]
pub fn dump_stack(&self)
[src]
Prints a dump of the stack state.
pub fn argv(&mut self) -> VVal
[src]
pub fn get_up_raw(&mut self, i: usize) -> VVal
[src]
pub fn get_up(&mut self, i: usize) -> VVal
[src]
pub fn set_arg(&mut self, i: usize, v: VVal)
[src]
pub fn arg_ref(&self, i: usize) -> Option<&VVal>
[src]
pub fn arg_err_internal(&self, i: usize) -> Option<VVal>
[src]
pub fn arg(&self, i: usize) -> VVal
[src]
pub fn get_local(&mut self, i: usize) -> VVal
[src]
pub fn set_up(&mut self, index: usize, value: &VVal)
[src]
pub fn set_local(&mut self, i: usize, value: &VVal)
[src]
pub fn set_consume(&mut self, i: usize, value: VVal)
[src]
Trait Implementations
Auto Trait Implementations
impl !Send for Env
impl !Sync for Env
impl Unpin for Env
impl !UnwindSafe for Env
impl !RefUnwindSafe for Env
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,