From bb57da564dfc6e5172ee6c4e960bc7bdc1363d95 Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 8 Oct 2017 13:57:43 -0700 Subject: [PATCH] Infrastructure to debug symbol table --- src/language.rs | 1 + src/main.rs | 3 ++- src/schala_lang/mod.rs | 5 +++++ src/schala_lang/type_check.rs | 3 +++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/language.rs b/src/language.rs index 06a94b1..4895de7 100644 --- a/src/language.rs +++ b/src/language.rs @@ -20,6 +20,7 @@ pub struct EvalOptions { pub debug_tokens: bool, pub debug_parse: bool, pub debug_type: bool, + pub debug_symbol_table: bool, pub show_llvm_ir: bool, pub trace_evaluation: bool, pub compile: bool, diff --git a/src/main.rs b/src/main.rs index dffd927..f33e657 100644 --- a/src/main.rs +++ b/src/main.rs @@ -230,7 +230,7 @@ impl Repl { println!("Commands:"); println!("exit | quit"); println!("lang [show|next|previous]"); - println!("set [show|hide] [tokens|parse|eval|llvm]"); + println!("set [show|hide] [tokens|parse|symbols|eval|llvm]"); } "lang" => { match commands.get(1) { @@ -271,6 +271,7 @@ impl Repl { match commands.get(2) { Some(&"tokens") => self.options.debug_tokens = show, Some(&"parse") => self.options.debug_parse = show, + Some(&"symbols") => self.options.debug_symbol_table = show, Some(&"eval") => { //let ref mut language = self.languages[self.current_language_index]; //language.set_option("trace_evaluation", show); diff --git a/src/schala_lang/mod.rs b/src/schala_lang/mod.rs index 87c194b..875088c 100644 --- a/src/schala_lang/mod.rs +++ b/src/schala_lang/mod.rs @@ -71,6 +71,11 @@ impl ProgrammingLanguageInterface for Schala { } } + if options.debug_symbol_table { + let text = self.type_context.debug_symbol_table(); + output.add_artifact(TraceArtifact::new("symbol_table", text)); + } + let evaluation_output = self.state.evaluate(ast); let mut acc = String::new(); let mut iter = evaluation_output.iter().peekable(); diff --git a/src/schala_lang/type_check.rs b/src/schala_lang/type_check.rs index 39cfeb8..e62072f 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 debug_symbol_table(&self) -> String { + format!("Symbol table:\n {:?}", self.symbol_table.map) + } } pub struct SchalaType {