[−][src]Struct wlambda::compiler::SymbolTable
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]
&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>,
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]
fn clone(&self) -> SymbolTable
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for SymbolTable
[src]
impl Default for SymbolTable
[src]
fn default() -> SymbolTable
[src]
Auto Trait Implementations
impl !RefUnwindSafe for SymbolTable
impl !Send for SymbolTable
impl !Sync for SymbolTable
impl Unpin for SymbolTable
impl !UnwindSafe for SymbolTable
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> 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> 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>,