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) } }