[][src]Struct wlambda::compiler::SymbolTable

pub struct SymbolTable { /* fields omitted */ }

Stores symbols and values for a WLambda module that can be added to a GlobalEnv with set_module.

 use wlambda::{SymbolTable, GlobalEnv, EvalContext, Env};

 let mut st = SymbolTable::new();

 let outbuf = std::rc::Rc::new(std::cell::RefCell::new(String::from("")));

 let captured_outbuf = outbuf.clone();

 st.fun("print", move |e: &mut Env, _argc: usize| {
     std::mem::replace(&mut *captured_outbuf.borrow_mut(), e.arg(0).s());
     println!("MY PRINT: {}", e.arg(0).s());
     Ok(e.arg(0).clone())
 }, Some(1), Some(1), false);

 let global_env = GlobalEnv::new_default();
 global_env.borrow_mut().set_module("my", st);

 let mut ctx = EvalContext::new(global_env);
 ctx.eval("!@import my my; my:print 1337");

 assert_eq!(outbuf.borrow().clone(), "1337");

Methods

impl SymbolTable[src]

pub fn new() -> Self[src]

pub fn list(&self) -> Vec<String>[src]

This function returns all symbols defined in this SymbolTable. It's mainly used for tests.

pub fn set(&mut self, name: &str, value: VVal)[src]

Sets the entry name to the value. So that the value can be imported.

pub fn fun<T>(
    &mut self,
    fnname: &str,
    fun: T,
    min_args: Option<usize>,
    max_args: Option<usize>,
    err_arg_ok: bool
) where
    T: 'static + Fn(&mut Env, usize) -> Result<VVal, StackAction>, 
[src]

Helper function for building symbol tables with functions in them.

See also VValFun::new_fun for more details.

 use wlambda::VVal;
 let mut st = wlambda::compiler::SymbolTable::new();
 st.fun("nothing",
        |e: &mut wlambda::vval::Env, _argc: usize| Ok(VVal::Nul),
        None, None, false);

Trait Implementations

impl Clone for SymbolTable[src]

impl Debug for SymbolTable[src]

impl Default for SymbolTable[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.