This commit is contained in:
greg 2018-05-14 09:46:25 -07:00
parent a08134a747
commit 97df2fa344
3 changed files with 8 additions and 4 deletions

View File

@ -11,7 +11,7 @@ use typechecking::TypeContext;
pub struct State<'a> {
values: StateStack<'a, Rc<String>, ValueEntry>,
type_context_handle: Option<Rc<RefCell<TypeContext>>>,
type_context_handle: Rc<RefCell<TypeContext>>,
}
macro_rules! builtin_binding {
@ -21,7 +21,7 @@ macro_rules! builtin_binding {
}
impl<'a> State<'a> {
pub fn new(type_context_handle: Option<Rc<RefCell<TypeContext>>>) -> State<'a> {
pub fn new(type_context_handle: Rc<RefCell<TypeContext>>) -> State<'a> {
let mut values = StateStack::new(Some(format!("global")));
builtin_binding!("print", values);
builtin_binding!("println", values);
@ -261,6 +261,10 @@ impl<'a> State<'a> {
use self::ValueEntry::*;
//TODO add a layer of indirection here to talk to the symbol table first, and only then look up
//in the values table
let type_context = self.type_context_handle.borrow();
type_context.symbol_table
match self.values.lookup(&name) {
None => return Err(format!("Value {} not found", *name)),
Some(lookup) => match lookup {

View File

@ -42,7 +42,7 @@ impl Schala {
let type_context = Rc::new(RefCell::new(typechecking::TypeContext::new()));
Schala {
type_context: type_context.clone(),
state: eval::State::new(Some(type_context)),
state: eval::State::new(type_context),
}
}
}

View File

@ -11,7 +11,7 @@ use parsing;
pub struct TypeContext {
type_var_count: u64,
bindings: HashMap<Rc<String>, Type>,
symbol_table: SymbolTable
pub symbol_table: SymbolTable
}
//cf. p. 150 or so of Language Implementation Patterns