pub struct SymbolTable { /* private fields */ }
Expand description

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

Implementations

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

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

Retrieves a value from the SymbolTable, if present.

use wlambda::{VVal, EvalContext};
let mut ctx = EvalContext::new_default();
ctx.eval("!@export to_rust = 42.0;");

assert_eq!(ctx.get_exports().get("to_rust").cloned(), Some(VVal::Flt(42.0)));

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::None),
        None, None, false);

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.