From e1a83b5de37c2b108726e828bff1fb4afe6c342e Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 19 Sep 2019 03:34:09 -0700 Subject: [PATCH] Start to use table lookups instead of Meta For fqsn --- schala-lang/language/src/eval/test.rs | 4 ++-- schala-lang/language/src/reduced_ast.rs | 5 +++-- schala-lang/language/src/schala.rs | 4 ++-- schala-lang/language/src/scope_resolution.rs | 8 +++++--- schala-lang/language/src/symbol_table.rs | 2 +- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/schala-lang/language/src/eval/test.rs b/schala-lang/language/src/eval/test.rs index e77f2a8..59a84de 100644 --- a/schala-lang/language/src/eval/test.rs +++ b/schala-lang/language/src/eval/test.rs @@ -14,8 +14,8 @@ fn evaluate_all_outputs(input: &str) -> Vec> { let mut ast = crate::util::quick_ast(input); state.symbol_table_handle.borrow_mut().add_top_level_symbols(&ast).unwrap(); { - let t = &state.symbol_table_handle.borrow(); - let mut scope_resolver = crate::scope_resolution::ScopeResolver::new(&t); + let mut t = &mut state.symbol_table_handle.borrow_mut(); + let mut scope_resolver = crate::scope_resolution::ScopeResolver::new(&mut t); let _ = scope_resolver.resolve(&mut ast); } diff --git a/schala-lang/language/src/reduced_ast.rs b/schala-lang/language/src/reduced_ast.rs index c42d104..91cbe39 100644 --- a/schala-lang/language/src/reduced_ast.rs +++ b/schala-lang/language/src/reduced_ast.rs @@ -158,8 +158,9 @@ impl<'a> Reducer<'a> { BinExp(binop, lhs, rhs) => self.binop(binop, lhs, rhs), PrefixExp(op, arg) => self.prefix(op, arg), Value(qualified_name) => { - let ref sym_name = match expr.fqsn { - Some(ref fqsn) => fqsn, + let ref id = qualified_name.node().id; + let ref sym_name = match symbol_table.get_fqsn_from_id(id) { + Some(fqsn) => fqsn, None => return Expr::ReductionError(format!("FQSN lookup for Value {:?} failed", qualified_name)), }; //TODO this probably needs to change diff --git a/schala-lang/language/src/schala.rs b/schala-lang/language/src/schala.rs index 7b02593..5d9d137 100644 --- a/schala-lang/language/src/schala.rs +++ b/schala-lang/language/src/schala.rs @@ -145,8 +145,8 @@ fn symbol_table(input: ast::AST, handle: &mut Schala, comp: Option<&mut PassDebu } fn scope_resolution(mut input: ast::AST, handle: &mut Schala, _com: Option<&mut PassDebugArtifact>) -> Result { - let symbol_table = handle.symbol_table.borrow(); - let mut resolver = crate::scope_resolution::ScopeResolver::new(&symbol_table); + let mut symbol_table = handle.symbol_table.borrow_mut(); + let mut resolver = crate::scope_resolution::ScopeResolver::new(&mut symbol_table); let () = resolver.resolve(&mut input)?; Ok(input) } diff --git a/schala-lang/language/src/scope_resolution.rs b/schala-lang/language/src/scope_resolution.rs index 64b2c0e..140cdcf 100644 --- a/schala-lang/language/src/scope_resolution.rs +++ b/schala-lang/language/src/scope_resolution.rs @@ -2,11 +2,11 @@ use crate::symbol_table::{SymbolTable, ScopeSegment, ScopeSegmentKind, FullyQual use crate::ast::*; pub struct ScopeResolver<'a> { - symbol_table: &'a SymbolTable + symbol_table: &'a mut SymbolTable } impl<'a> ScopeResolver<'a> { - pub fn new(symbol_table: &'a SymbolTable) -> ScopeResolver { + pub fn new(symbol_table: &'a mut SymbolTable) -> ScopeResolver { ScopeResolver { symbol_table } } pub fn resolve(&mut self, ast: &mut AST) -> Result<(), String> { @@ -43,7 +43,9 @@ impl<'a> ScopeResolver<'a> { match &mut inner_expr.kind { ExpressionKind::Value(qualified_name) => { let fqsn = lookup_name_in_scope(&qualified_name.node()); - expr.fqsn = Some(fqsn); + let ref id = qualified_name.node().id; + self.symbol_table.map_id_to_fqsn(id, fqsn); + //expr.fqsn = Some(fqsn); }, NamedStruct { name, .. } => { let fqsn = lookup_name_in_scope(&name.node()); diff --git a/schala-lang/language/src/symbol_table.rs b/schala-lang/language/src/symbol_table.rs index de595cc..1950e96 100644 --- a/schala-lang/language/src/symbol_table.rs +++ b/schala-lang/language/src/symbol_table.rs @@ -97,7 +97,7 @@ impl SymbolTable { self.id_to_fqsn.insert(id.clone(), fqsn); } - pub fn get_fqsn_from_id(&mut self, id: &ItemId) -> Option { + pub fn get_fqsn_from_id(&self, id: &ItemId) -> Option { self.id_to_fqsn.get(&id).cloned() }