From 2490aaf3f41220c1794f8c70868fe3e71a8611cd Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 11 Mar 2019 01:36:11 -0700 Subject: [PATCH] Add types necessary for refactor of Symbol table --- schala-lang/language/src/symbol_table.rs | 28 ++++++++++++++++-------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/schala-lang/language/src/symbol_table.rs b/schala-lang/language/src/symbol_table.rs index 160a392..ef0a12c 100644 --- a/schala-lang/language/src/symbol_table.rs +++ b/schala-lang/language/src/symbol_table.rs @@ -13,14 +13,23 @@ type LineNumber = u32; type SymbolTrackTable = HashMap, LineNumber>; #[derive(PartialEq, Eq, Hash, Debug)] -struct SymbolPath { - name: Rc, - enclosing_scopes: Vec> +struct PathToSymbol(Vec>); + +#[derive(Debug)] +struct SymbolPathSegment { + segment_name: Rc, + segment_type: SymbolPathSegmentKind +} + +#[derive(Debug)] +enum SymbolPathSegmentKind { + NamedScope, + TypeVariant } //cf. p. 150 or so of Language Implementation Patterns pub struct SymbolTable { - values: HashMap, + values: HashMap, } //TODO add various types of lookups here, maybe multiple hash tables internally? @@ -32,10 +41,9 @@ impl SymbolTable { } fn add_new_symbol(&mut self, name: &Rc, path: &Vec>, symbol: Symbol) { - let symbol_path = SymbolPath { - name: name.clone(), - enclosing_scopes: path.clone(), - }; + let mut vec = path.clone(); + vec.push(name.clone()); + let symbol_path = PathToSymbol(vec); self.values.insert(symbol_path, symbol); } @@ -44,7 +52,9 @@ impl SymbolTable { } pub fn lookup_by_path(&self, name: &Rc, path: &Vec>) -> Option<&Symbol> { - let symbol_path = SymbolPath { name: name.clone(), enclosing_scopes: path.clone() }; + let mut vec = path.clone(); + vec.push(name.clone()); + let symbol_path = PathToSymbol(vec); self.values.get(&symbol_path) } }