[−][src]Struct wlambda::vval::Env
The runtime environment of the evaluator.
Fields
args: Vec<VVal>The argument stack, initialized to a size of START_STACK_SIZE.
call_stack: Vec<Rc<VValFun>>A stack of the currently called functions.
Used for accessing the up values, backtrace and other details about the function.
unwind_stack: Vec<UnwindAction>A stack that holds cleanup routines that need to be handled:
current_self: VValHolds the object of the currently called method:
bp: usizeThe basepointer to reference arguments and local variables.
bp + n (n >= 0)references a local variablebp - n (n > 0)references an argument
sp: usizeThe current stack pointer.
argc: usizeThe 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: FnvHashMap<Symbol, VVal>The exported names of this module.
stdio: StdioThis is the standard output used for any functions in
WLambda that print something. Such as std:displayln
or std:writeln.
accum_val: VValCurrent accumulator value:
accum_fun: VValCurrent accumulator function:
global: GlobalEnvRefA pointer to the global environment, holding stuff like the module loader and thread creator.
vm_nest: usizeA counter that counts the nesting depth in vm() calls
loop_info: LoopInfoHolds information to process 'next' and 'break' for loop constructs:
iter: Option<Rc<RefCell<VValIter>>>Holds the current iterator for the 'iter' construct.
Implementations
impl Env[src]
pub fn new(global: GlobalEnvRef) -> Env[src]
pub fn new_with_user(global: GlobalEnvRef, user: Rc<RefCell<dyn Any>>) -> Env[src]
pub fn set_stdio(&mut self, stdio: Stdio)[src]
Sets a custom stdio procedure. This can be used to redirect the standard input/output operations of WLambda to other sinks and sources. For instance writing and reading from a Buffer when using WASM or some other embedded application:
use wlambda::*; use std::rc::Rc; use std::cell::RefCell; let new_output : Rc<RefCell<Vec<u8>>> = Rc::new(RefCell::new(vec![])); let new_input = Rc::new(RefCell::new(std::io::Cursor::new("abc\ndef\n1 2 3 4\n" .to_string().as_bytes().to_vec()))); let memory_stdio = vval::Stdio::new_from_mem(new_input, new_output.clone()); let mut ctx = EvalContext::new_default(); ctx.local.borrow_mut().set_stdio(memory_stdio); ctx.eval("std:displayln :TEST 123").unwrap(); let output = String::from_utf8(new_output.borrow().clone()).unwrap(); assert_eq!(output, "TEST 123\n"); let out_lines = ctx.eval("!l = $[]; std:io:lines \\std:push l _; l").unwrap().s(); assert_eq!(out_lines, "$[\"abc\\n\",\"def\\n\",\"1 2 3 4\\n\"]");
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::None) }, 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 self_object(&self) -> VVal[src]
pub fn with_object<T>(
&mut self,
object: VVal,
f: T
) -> Result<VVal, StackAction> where
T: Fn(&mut Env) -> Result<VVal, StackAction>, [src]
&mut self,
object: VVal,
f: T
) -> Result<VVal, StackAction> where
T: Fn(&mut Env) -> Result<VVal, StackAction>,
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_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 push_sp(&mut self, n: usize)[src]
pub fn push(&mut self, v: VVal) -> usize[src]
pub fn stk(&self, offs: usize) -> &VVal[src]
pub fn stk_i(&self, offs: usize) -> i64[src]
pub fn inc_local(&mut self, idx: usize, inc: i16) -> i64[src]
pub fn pop(&mut self) -> VVal[src]
pub fn null_locals(&mut self, from: usize, to: 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(&self) -> VVal[src]
pub fn argv_ref(&self) -> &[VVal][src]
pub fn get_up_raw(&mut self, i: usize) -> VVal[src]
pub fn get_up_captured_ref(&self, i: usize) -> VVal[src]
pub fn get_up(&self, i: usize) -> 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_up_promotion(&mut self, i: usize) -> VVal[src]
pub fn get_local_captured_ref(&self, i: usize) -> VVal[src]
pub fn reg(&self, i: i32) -> VVal[src]
pub fn get_local(&self, i: usize) -> VVal[src]
pub fn assign_ref_up(&mut self, i: usize, value: VVal)[src]
pub fn assign_ref_local(&mut self, i: usize, value: VVal)[src]
pub fn set_up(&mut self, index: usize, value: VVal)[src]
pub fn set_consume(&mut self, i: usize, value: VVal)[src]
pub fn unwind_depth(&self) -> usize[src]
pub fn push_unwind(&mut self, uwa: UnwindAction)[src]
pub fn unwind_to_depth(&mut self, depth: usize)[src]
pub fn push_fun_call(&mut self, fu: Rc<VValFun>, argc: usize)[src]
pub fn push_clear_locals(&mut self, from: usize, to: usize)[src]
pub fn push_unwind_self(&mut self, new_self: VVal)[src]
pub fn cleanup_loop(&mut self)[src]
pub fn push_loop_info(
&mut self,
current_pc: usize,
break_pc: usize,
uw_depth_offs: usize
)[src]
&mut self,
current_pc: usize,
break_pc: usize,
uw_depth_offs: usize
)
pub fn push_iter(&mut self, iter: Rc<RefCell<VValIter>>)[src]
pub fn dump_unwind_stack(&self) -> String[src]
pub fn unwind(&mut self, ua: UnwindAction)[src]
pub fn unwind_one(&mut self)[src]
pub fn setup_accumulator(&mut self, v: VVal)[src]
pub fn with_accum<T>(&mut self, v: VVal, acfun: T) -> Result<VVal, StackAction> where
T: Fn(&mut Env) -> Result<VVal, StackAction>, [src]
T: Fn(&mut Env) -> Result<VVal, StackAction>,
pub fn get_accum_value(&self) -> VVal[src]
pub fn get_accum_function(&self) -> VVal[src]
pub fn new_err(&self, s: String) -> VVal[src]
Creates a new error VVal with the given string as error message. Takes care to annotate the error value with the current function information.
use wlambda::compiler::EvalContext; use wlambda::vval::{VVal, VValFun, Env}; let mut ctx = EvalContext::new_default(); ctx.set_global_var("xyz", &VValFun::new_fun( move |env: &mut Env, argc: usize| { let ok = false; if !ok { Ok(env.new_err( format!("Something was not ok!"))) } else { Ok(VVal::Bol(true)) } }, None, None, false));
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Env
impl !Send for Env
impl !Sync for Env
impl Unpin for Env
impl !UnwindSafe for Env
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
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> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
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>,