Debug stages from command line

This commit is contained in:
greg 2018-03-27 00:50:31 -07:00
parent eb987bb5b0
commit 7d2bc4188d
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) { match self.type_context.add_top_level_types(&ast) {
Ok(()) => (), Ok(()) => (),
Err(msg) => { Err(msg) => {
if options.debug.type_checking {
evaluation.add_artifact(TraceArtifact::new("type_check", msg)); evaluation.add_artifact(TraceArtifact::new("type_check", msg));
} }
}
}; };
//typechecking //typechecking

View File

@ -111,7 +111,18 @@ impl FinishedComputation {
} }
pub fn to_noninteractive(&self) -> Option<String> { pub fn to_noninteractive(&self) -> Option<String> {
match self.text_output { 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)) Err(ref s) => Some(format!("{} {}", "Error: ".red().bold(), s))
} }
} }

View File

@ -62,13 +62,20 @@ pub fn repl_main(generators: Vec<PLIGenerator>) {
exit(0); 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 language_names: Vec<String> = languages.iter().map(|lang| {lang.get_language_name()}).collect();
let initial_index: usize = let initial_index: usize =
option_matches.opt_str("lang") option_matches.opt_str("lang")
.and_then(|lang| { language_names.iter().position(|x| { x.to_lowercase() == lang.to_lowercase() }) }) .and_then(|lang| { language_names.iter().position(|x| { x.to_lowercase() == lang.to_lowercase() }) })
.unwrap_or(0); .unwrap_or(0);
let mut options = EvalOptions::default();
options.execution_method = match option_matches.opt_str("eval-style") { options.execution_method = match option_matches.opt_str("eval-style") {
Some(ref s) if s == "compile" => ExecutionMethod::Compile, Some(ref s) if s == "compile" => ExecutionMethod::Compile,
_ => ExecutionMethod::Interpret, _ => ExecutionMethod::Interpret,
@ -368,5 +375,9 @@ fn program_options() -> getopts::Options {
options.optflag("w", options.optflag("w",
"webapp", "webapp",
"Start up web interpreter"); "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 options
} }