Infrastructure to debug symbol table

This commit is contained in:
greg 2017-10-08 13:57:43 -07:00
parent 3f9ae5fac3
commit bb57da564d
4 changed files with 11 additions and 1 deletions

View File

@ -20,6 +20,7 @@ pub struct EvalOptions {
pub debug_tokens: bool, pub debug_tokens: bool,
pub debug_parse: bool, pub debug_parse: bool,
pub debug_type: bool, pub debug_type: bool,
pub debug_symbol_table: bool,
pub show_llvm_ir: bool, pub show_llvm_ir: bool,
pub trace_evaluation: bool, pub trace_evaluation: bool,
pub compile: bool, pub compile: bool,

View File

@ -230,7 +230,7 @@ impl Repl {
println!("Commands:"); println!("Commands:");
println!("exit | quit"); println!("exit | quit");
println!("lang [show|next|previous]"); println!("lang [show|next|previous]");
println!("set [show|hide] [tokens|parse|eval|llvm]"); println!("set [show|hide] [tokens|parse|symbols|eval|llvm]");
} }
"lang" => { "lang" => {
match commands.get(1) { match commands.get(1) {
@ -271,6 +271,7 @@ impl Repl {
match commands.get(2) { match commands.get(2) {
Some(&"tokens") => self.options.debug_tokens = show, Some(&"tokens") => self.options.debug_tokens = show,
Some(&"parse") => self.options.debug_parse = show, Some(&"parse") => self.options.debug_parse = show,
Some(&"symbols") => self.options.debug_symbol_table = show,
Some(&"eval") => { Some(&"eval") => {
//let ref mut language = self.languages[self.current_language_index]; //let ref mut language = self.languages[self.current_language_index];
//language.set_option("trace_evaluation", show); //language.set_option("trace_evaluation", show);

View File

@ -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 evaluation_output = self.state.evaluate(ast);
let mut acc = String::new(); let mut acc = String::new();
let mut iter = evaluation_output.iter().peekable(); let mut iter = evaluation_output.iter().peekable();

View File

@ -55,6 +55,9 @@ impl TypeContext {
pub fn new() -> TypeContext { pub fn new() -> TypeContext {
TypeContext { symbol_table: SymbolTable::new() } TypeContext { symbol_table: SymbolTable::new() }
} }
pub fn debug_symbol_table(&self) -> String {
format!("Symbol table:\n {:?}", self.symbol_table.map)
}
} }
pub struct SchalaType { pub struct SchalaType {