From c4f0331d1a3f7c84d2346c188c1b3323d11d4972 Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 8 Oct 2017 16:24:44 -0700 Subject: [PATCH] Symbol table addition should be separate stage --- src/schala_lang/mod.rs | 2 ++ src/schala_lang/type_check.rs | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/schala_lang/mod.rs b/src/schala_lang/mod.rs index 9dc0d11..609e134 100644 --- a/src/schala_lang/mod.rs +++ b/src/schala_lang/mod.rs @@ -62,6 +62,8 @@ impl ProgrammingLanguageInterface for Schala { } }; + self.type_context.add_symbols(&ast); + if options.debug_symbol_table { let text = self.type_context.debug_symbol_table(); output.add_artifact(TraceArtifact::new("symbol_table", text)); diff --git a/src/schala_lang/type_check.rs b/src/schala_lang/type_check.rs index e62072f..ead7464 100644 --- a/src/schala_lang/type_check.rs +++ b/src/schala_lang/type_check.rs @@ -55,6 +55,9 @@ impl TypeContext { pub fn new() -> TypeContext { TypeContext { symbol_table: SymbolTable::new() } } + pub fn add_symbols(&mut self, ast: &AST) { + self.symbol_table.add_symbols(ast) + } pub fn debug_symbol_table(&self) -> String { format!("Symbol table:\n {:?}", self.symbol_table.map) } @@ -81,8 +84,6 @@ impl TypeContext { pub fn type_check(&mut self, ast: &AST) -> TypeCheckResult { use self::ExpressionType::*; - self.symbol_table.add_symbols(ast); - for statement in ast.0.iter() { match statement { &Statement::Declaration(ref _decl) => {