From 3d6447abb48ab3a0ec2c6b44479d0427e720f3b8 Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 21 Aug 2019 10:08:39 -0700 Subject: [PATCH] Start work on symbol table lookup by type name --- schala-lang/language/src/symbol_table.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/schala-lang/language/src/symbol_table.rs b/schala-lang/language/src/symbol_table.rs index af43168..042e41f 100644 --- a/schala-lang/language/src/symbol_table.rs +++ b/schala-lang/language/src/symbol_table.rs @@ -28,14 +28,16 @@ enum ScopeSegmentKind { //cf. p. 150 or so of Language Implementation Patterns pub struct SymbolTable { - values: HashMap, + symbol_path_to_symbol: HashMap, + type_name_to_symbol: HashMap, PathToSymbol> } //TODO add various types of lookups here, maybe multiple hash tables internally? impl SymbolTable { pub fn new() -> SymbolTable { SymbolTable { - values: HashMap::new(), + symbol_path_to_symbol: HashMap::new(), + type_name_to_symbol: HashMap::new(), } } @@ -44,7 +46,7 @@ impl SymbolTable { vec.push(name.clone()); let symbol_path = PathToSymbol(vec); let symbol = Symbol { name: name.clone(), scopes: scope_path.to_vec(), spec }; - self.values.insert(symbol_path, symbol); + self.symbol_path_to_symbol.insert(symbol_path, symbol); } pub fn lookup_by_name(&self, name: &Rc) -> Option<&Symbol> { @@ -55,7 +57,11 @@ impl SymbolTable { let mut vec = path.clone(); vec.push(name.clone()); let symbol_path = PathToSymbol(vec); - self.values.get(&symbol_path) + self.symbol_path_to_symbol.get(&symbol_path) + } + + pub fn lookup_by_type_and_tag(&self, type_name: &Rc, tag: usize) -> Option<&Symbol> { + unimplemented!() } } @@ -163,7 +169,7 @@ impl SymbolTable { } pub fn debug_symbol_table(&self) -> String { let mut output = format!("Symbol table\n"); - for (name, sym) in &self.values { + for (name, sym) in &self.symbol_path_to_symbol { write!(output, "{:?} -> {}\n", name, sym).unwrap(); } output