Remove symbol table from evaluator
This commit is contained in:
parent
e4a1a23f4d
commit
a2bd9a3985
@ -14,13 +14,12 @@ mod test;
|
|||||||
|
|
||||||
pub struct State<'a> {
|
pub struct State<'a> {
|
||||||
values: ScopeStack<'a, Rc<String>, ValueEntry>,
|
values: ScopeStack<'a, Rc<String>, ValueEntry>,
|
||||||
symbol_table_handle: SymbolTableHandle,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> State<'a> {
|
impl<'a> State<'a> {
|
||||||
pub fn new(symbol_table_handle: SymbolTableHandle) -> State<'a> {
|
pub fn new() -> State<'a> {
|
||||||
let values = ScopeStack::new(Some(format!("global")));
|
let values = ScopeStack::new(Some(format!("global")));
|
||||||
State { values, symbol_table_handle }
|
State { values }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn debug_print(&self) -> String {
|
pub fn debug_print(&self) -> String {
|
||||||
@ -30,7 +29,6 @@ impl<'a> State<'a> {
|
|||||||
fn new_frame(&'a self, items: &'a Vec<Node>, bound_vars: &BoundVars) -> State<'a> {
|
fn new_frame(&'a self, items: &'a Vec<Node>, bound_vars: &BoundVars) -> State<'a> {
|
||||||
let mut inner_state = State {
|
let mut inner_state = State {
|
||||||
values: self.values.new_scope(None),
|
values: self.values.new_scope(None),
|
||||||
symbol_table_handle: self.symbol_table_handle.clone(),
|
|
||||||
};
|
};
|
||||||
for (bound_var, val) in bound_vars.iter().zip(items.iter()) {
|
for (bound_var, val) in bound_vars.iter().zip(items.iter()) {
|
||||||
if let Some(bv) = bound_var.as_ref() {
|
if let Some(bv) = bound_var.as_ref() {
|
||||||
@ -263,7 +261,6 @@ impl<'a> State<'a> {
|
|||||||
}
|
}
|
||||||
let mut func_state = State {
|
let mut func_state = State {
|
||||||
values: self.values.new_scope(name.map(|n| format!("{}", n))),
|
values: self.values.new_scope(name.map(|n| format!("{}", n))),
|
||||||
symbol_table_handle: self.symbol_table_handle.clone(),
|
|
||||||
};
|
};
|
||||||
for (param, val) in params.into_iter().zip(args.into_iter()) {
|
for (param, val) in params.into_iter().zip(args.into_iter()) {
|
||||||
let val = func_state.expression(Node::Expr(val))?;
|
let val = func_state.expression(Node::Expr(val))?;
|
||||||
|
@ -12,14 +12,14 @@ fn evaluate_all_outputs(input: &str) -> Vec<Result<String, String>> {
|
|||||||
let (mut ast, source_map) = crate::util::quick_ast(input);
|
let (mut ast, source_map) = crate::util::quick_ast(input);
|
||||||
let source_map = Rc::new(RefCell::new(source_map));
|
let source_map = Rc::new(RefCell::new(source_map));
|
||||||
let symbol_table = Rc::new(RefCell::new(SymbolTable::new(source_map)));
|
let symbol_table = Rc::new(RefCell::new(SymbolTable::new(source_map)));
|
||||||
let mut state = State::new(symbol_table);
|
symbol_table.borrow_mut().add_top_level_symbols(&ast).unwrap();
|
||||||
state.symbol_table_handle.borrow_mut().add_top_level_symbols(&ast).unwrap();
|
|
||||||
{
|
{
|
||||||
let mut scope_resolver = ScopeResolver::new(state.symbol_table_handle.clone());
|
let mut scope_resolver = ScopeResolver::new(symbol_table.clone());
|
||||||
let _ = scope_resolver.resolve(&mut ast);
|
let _ = scope_resolver.resolve(&mut ast);
|
||||||
}
|
}
|
||||||
|
|
||||||
let reduced = reduce(&ast, &state.symbol_table_handle.borrow());
|
let reduced = reduce(&ast, &symbol_table.borrow());
|
||||||
|
let mut state = State::new();
|
||||||
let all_output = state.evaluate(reduced, true);
|
let all_output = state.evaluate(reduced, true);
|
||||||
all_output
|
all_output
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ impl Schala {
|
|||||||
symbol_table: symbols.clone(),
|
symbol_table: symbols.clone(),
|
||||||
source_map: source_map.clone(),
|
source_map: source_map.clone(),
|
||||||
resolver: crate::scope_resolution::ScopeResolver::new(symbols.clone()),
|
resolver: crate::scope_resolution::ScopeResolver::new(symbols.clone()),
|
||||||
state: eval::State::new(symbols),
|
state: eval::State::new(),
|
||||||
type_context: typechecking::TypeContext::new(),
|
type_context: typechecking::TypeContext::new(),
|
||||||
active_parser: parsing::Parser::new(source_map)
|
active_parser: parsing::Parser::new(source_map)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user