[−][src]Struct wlambda::compiler::GlobalEnv
Holds global environment variables.
This data structure is part of the API. It's there to make functions or values available to a WLambda program.
This environment structure is usually wrapped inside an EvalContext which augments it for calling the compiler and allows evaluation of the code.
See also GlobalEnv::add_func() of how to create a function and put it into the global variable. And GlobalEnv::set_var(). And GlobalEnv::get_var().
Methods
impl GlobalEnv
[src]
pub fn add_func<T>(
&mut self,
fnname: &str,
fun: T,
min_args: Option<usize>,
max_args: Option<usize>
) where
T: 'static + Fn(&mut Env, usize) -> Result<VVal, StackAction>,
[src]
&mut self,
fnname: &str,
fun: T,
min_args: Option<usize>,
max_args: Option<usize>
) where
T: 'static + Fn(&mut Env, usize) -> Result<VVal, StackAction>,
Adds a function to a GlobalEnv
.
This is an example of how to add a function:
use wlambda::compiler::GlobalEnv; use wlambda::vval::{Env, VVal}; let g = GlobalEnv::new(); g.borrow_mut().add_func( "push", |env: &mut Env, argc: usize| { if argc < 2 { return Ok(VVal::Nul); } let v = env.arg(0); v.push(env.arg(1).clone()); Ok(v.clone()) }, Some(2), Some(2));
pub fn set_var(&mut self, var: &str, val: &VVal)
[src]
Sets a global variable to a value.
See also EvalContext::set_global_var()
pub fn get_var(&mut self, var: &str) -> Option<VVal>
[src]
Returns the value of a global variable.
See also EvalContext::get_global_var()
pub fn set_resolver(&mut self, res: Rc<RefCell<dyn ModuleResolver>>)
[src]
pub fn new() -> GlobalEnvRef
[src]
Creates a new GlobalEnv.
Trait Implementations
Auto Trait Implementations
impl !Send for GlobalEnv
impl Unpin for GlobalEnv
impl !Sync for GlobalEnv
impl !UnwindSafe for GlobalEnv
impl !RefUnwindSafe for GlobalEnv
Blanket Implementations
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> 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> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,