Struct VValFun

Source
pub struct VValFun {
    pub fun: FunType,
    pub upvalue_pos: Rc<Vec<VarPos>>,
    pub upvalues: Vec<VVal>,
    pub local_size: usize,
    pub min_args: Option<usize>,
    pub max_args: Option<usize>,
    pub err_arg_ok: bool,
    pub syn_pos: Option<SynPos>,
    pub label: VVal,
}
Expand description

This structure is the runtime representation of a WLambda function value.

Fields§

§fun: FunType

The closure or vm program that runs the function.

§upvalue_pos: Rc<Vec<VarPos>>

The positions of the upvalues that are being captured by this 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.

§label: VVal

The return label of the function:

Implementations§

Source§

impl VValFun

Source

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>,

Creates a new VVal containing the given closure with the given minimum and maximum parameters (see also add_func of GlobalEnv).

There is also a new more convenient (because provided by VVal itself) function: VVal::new_fun which has the same parameters.

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")
Source

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>,

Source

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>, upvalue_pos: Rc<Vec<VarPos>>, ) -> VVal

Internal utility function. Use at your own risk, API might change.

Source

pub fn new_prog( prog: Rc<Prog>, upvalues: Vec<VVal>, env_size: usize, min_args: Option<usize>, max_args: Option<usize>, err_arg_ok: bool, syn_pos: Option<SynPos>, upvalue_pos: Rc<Vec<VarPos>>, label: VVal, ) -> VVal

Internal utility function. Use at your own risk, API might change.

Source

pub fn new_dummy() -> Rc<VValFun>

Returns a dummy function that does nothing.

Source

pub fn dump_upvals(&self) -> VVal

Dumps captured up values of this function. Useful only if you want to debug functions/closures creates by WLambda code.

Trait Implementations§

Source§

impl Clone for VValFun

Source§

fn clone(&self) -> VValFun

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for VValFun

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for VValFun

§

impl !RefUnwindSafe for VValFun

§

impl !Send for VValFun

§

impl !Sync for VValFun

§

impl Unpin for VValFun

§

impl !UnwindSafe for VValFun

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.