From 5f336ec1a92a5e236df37444fbb429697cddfb98 Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 5 Aug 2018 18:19:48 -0700 Subject: [PATCH] Add lookup_by_name to symbol table --- schala-lang/src/eval.rs | 2 +- schala-lang/src/reduced_ast.rs | 2 +- schala-lang/src/symbol_table.rs | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/schala-lang/src/eval.rs b/schala-lang/src/eval.rs index 33c0bc5..02da78d 100644 --- a/schala-lang/src/eval.rs +++ b/schala-lang/src/eval.rs @@ -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, .. } => { diff --git a/schala-lang/src/reduced_ast.rs b/schala-lang/src/reduced_ast.rs index 5eaab7e..9697b7f 100644 --- a/schala-lang/src/reduced_ast.rs +++ b/schala-lang/src/reduced_ast.rs @@ -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(), diff --git a/schala-lang/src/symbol_table.rs b/schala-lang/src/symbol_table.rs index 01589c2..ef6b50d 100644 --- a/schala-lang/src/symbol_table.rs +++ b/schala-lang/src/symbol_table.rs @@ -17,6 +17,10 @@ impl SymbolTable { pub fn new() -> SymbolTable { SymbolTable { values: HashMap::new() } } + + pub fn lookup_by_name(&self, name: &Rc) -> Option<&Symbol> { + self.values.get(name) + } } #[derive(Debug)]