[−][src]Struct wlambda::vval::VValFun
This structure is the runtime representation of a WLambda function value.
Fields
fun: ClosNodeRef
The closure that runs the function.
upvalues: Vec<VVal>
Contains any caught upvalues.
local_size: usize
The number of local variables defined in this functions.
This value is used to reserve stack space for storing them.
min_args: Option<usize>
Min number of arguments this functions requires.
max_args: Option<usize>
Max number of arguments this functions requires.
err_arg_ok: bool
If true, then this function accepts error values without panic. Functions by default don't accept errors as argument. It needs to be explicitly enabled.
syn_pos: Option<SynPos>
The location of the definition of this function.
Methods
impl VValFun
[src]
pub fn new_fun<T>(
fun: T,
min_args: Option<usize>,
max_args: Option<usize>,
err_arg_ok: bool
) -> VVal where
T: 'static + Fn(&mut Env, usize) -> Result<VVal, StackAction>,
[src]
fun: T,
min_args: Option<usize>,
max_args: Option<usize>,
err_arg_ok: bool
) -> VVal where
T: 'static + Fn(&mut Env, usize) -> Result<VVal, StackAction>,
Creates a new VVal containing the given closure with the given minimum
and maximum parameters (see also add_func
of GlobalEnv).
The err_arg_ok
parameter specifies whether the function accepts
error values as arguments. If it doesn't, the program will panic
once an error value is encountered. This makes programs more maintainable.
This is usually useful if you want to add functions to the EvalContext. at runtime.
use wlambda::compiler::EvalContext; use wlambda::vval::{VVal, VValFun, Env}; let mut ctx = wlambda::compiler::EvalContext::new_empty_global_env(); ctx.set_global_var("xyz", &VValFun::new_fun( move |env: &mut Env, argc: usize| { Ok(VVal::new_str("xyz")) }, None, None, false)); assert_eq!(ctx.eval("xyz[]").unwrap().s_raw(), "xyz")
pub fn new_fun_with_pos<T>(
fun: T,
min_args: Option<usize>,
max_args: Option<usize>,
err_arg_ok: bool,
spos: SynPos
) -> VVal where
T: 'static + Fn(&mut Env, usize) -> Result<VVal, StackAction>,
[src]
fun: T,
min_args: Option<usize>,
max_args: Option<usize>,
err_arg_ok: bool,
spos: SynPos
) -> VVal where
T: 'static + Fn(&mut Env, usize) -> Result<VVal, StackAction>,
pub fn new_val(
fun: ClosNodeRef,
upvalues: Vec<VVal>,
env_size: usize,
min_args: Option<usize>,
max_args: Option<usize>,
err_arg_ok: bool,
syn_pos: Option<SynPos>
) -> VVal
[src]
fun: ClosNodeRef,
upvalues: Vec<VVal>,
env_size: usize,
min_args: Option<usize>,
max_args: Option<usize>,
err_arg_ok: bool,
syn_pos: Option<SynPos>
) -> VVal
Internal utility function. Use at your own risk, API might change.
pub fn new_dummy() -> Rc<VValFun>
[src]
Returns a dummy function that does nothing.
pub fn dump_upvals(&self) -> VVal
[src]
Dumps captured up values of this function. Useful only if you want to debug functions/closures creates by WLambda code.
Trait Implementations
Auto Trait Implementations
impl !Send for VValFun
impl !Sync for VValFun
impl Unpin for VValFun
impl !UnwindSafe for VValFun
impl !RefUnwindSafe for VValFun
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, 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,