Add lookup_by_name to symbol table

This commit is contained in:
greg 2018-08-05 18:19:48 -07:00
parent da59fae0d3
commit 5f336ec1a9
3 changed files with 6 additions and 2 deletions

View File

@ -290,7 +290,7 @@ impl<'a> State<'a> {
//in the values table
let symbol_table = self.symbol_table_handle.borrow();
let value = symbol_table.values.get(&name);
let value = symbol_table.lookup_by_name(&name);
Ok(match value {
Some(Symbol { name, spec }) => match spec {
SymbolSpec::DataConstructor { type_name, type_args, .. } => {

View File

@ -117,7 +117,7 @@ impl Expression {
BinExp(binop, lhs, rhs) => binop.reduce(symbol_table, lhs, rhs),
PrefixExp(op, arg) => op.reduce(symbol_table, arg),
Value(name) => {
match symbol_table.values.get(name) {
match symbol_table.lookup_by_name(name) {
Some(Symbol { spec: SymbolSpec::DataConstructor { index, type_args, type_name}, .. }) => Expr::NewConstructor {
type_name: type_name.clone(),
name: name.clone(),

View File

@ -17,6 +17,10 @@ impl SymbolTable {
pub fn new() -> SymbolTable {
SymbolTable { values: HashMap::new() }
}
pub fn lookup_by_name(&self, name: &Rc<String>) -> Option<&Symbol> {
self.values.get(name)
}
}
#[derive(Debug)]