Debug stages from command line

This commit is contained in:
greg 2018-03-27 00:50:31 -07:00
parent 7f21b70e3f
commit c11ae3b50d
3 changed files with 27 additions and 3 deletions

View File

@ -86,8 +86,10 @@ impl ProgrammingLanguageInterface for Schala {
match self.type_context.add_top_level_types(&ast) {
Ok(()) => (),
Err(msg) => {
if options.debug.type_checking {
evaluation.add_artifact(TraceArtifact::new("type_check", msg));
}
}
};
//typechecking

View File

@ -111,7 +111,18 @@ impl FinishedComputation {
}
pub fn to_noninteractive(&self) -> Option<String> {
match self.text_output {
Ok(_) => None,
Ok(_) => {
let mut buf = String::new();
for stage in ["tokens", "parse_trace", "ast", "symbol_table", "type_check"].iter() {
if let Some(artifact) = self.artifacts.get(&stage.to_string()) {
let color = artifact.text_color;
let stage = stage.color(color).bold();
let output = artifact.debug_output.color(color);
write!(&mut buf, "{}: {}\n", stage, output).unwrap();
}
}
if buf == "" { None } else { Some(buf) }
},
Err(ref s) => Some(format!("{} {}", "Error: ".red().bold(), s))
}
}

View File

@ -62,13 +62,20 @@ pub fn repl_main(generators: Vec<PLIGenerator>) {
exit(0);
}
let mut options = EvalOptions::default();
if let Some(ref ltrs) = option_matches.opt_str("debug") {
options.debug.tokens = ltrs.contains("l");
options.debug.ast = ltrs.contains("a");
options.debug.parse_tree = ltrs.contains("r");
options.debug.symbol_table = ltrs.contains("s");
}
let language_names: Vec<String> = languages.iter().map(|lang| {lang.get_language_name()}).collect();
let initial_index: usize =
option_matches.opt_str("lang")
.and_then(|lang| { language_names.iter().position(|x| { x.to_lowercase() == lang.to_lowercase() }) })
.unwrap_or(0);
let mut options = EvalOptions::default();
options.execution_method = match option_matches.opt_str("eval-style") {
Some(ref s) if s == "compile" => ExecutionMethod::Compile,
_ => ExecutionMethod::Interpret,
@ -368,5 +375,9 @@ fn program_options() -> getopts::Options {
options.optflag("w",
"webapp",
"Start up web interpreter");
options.optopt("d",
"debug",
"Debug a stage (l = tokenizer, a = AST, r = parse trace, s = symbol table)",
"[l|a|r|s]");
options
}