Debug stuff

This commit is contained in:
greg 2019-06-19 03:27:18 -07:00
parent 2ec3b21ebf
commit e3bd108e6c
4 changed files with 29 additions and 25 deletions

View File

@ -137,21 +137,15 @@ fn parsing(input: Vec<tokenizing::Token>, handle: &mut Schala, comp: Option<&mut
}; };
let ast = parser.parse(); let ast = parser.parse();
let _trace = parser.format_parse_trace(); let trace = parser.format_parse_trace();
comp.map(|comp| { comp.map(|comp| {
comp.add_artifact(format!("{:#?}", ast)); let debug_info = match comp.parsing.as_ref().unwrap_or(&ParsingDebugType::CompactAST) {
/* ParsingDebugType::CompactAST => format!("{:?}", ast),
//TODO need to control which of these debug stages get added ParsingDebugType::ExpandedAST => format!("{:#?}", ast),
let opt = comp.cur_debug_options.get(0).map(|s| s.clone()); ParsingDebugType::Trace => format!("{}", trace[0]) //TODO fix this
match opt {
None => comp.add_artifact(TraceArtifact::new("ast", format!("{:?}", ast))),
Some(ref s) if s == "compact" => comp.add_artifact(TraceArtifact::new("ast", format!("{:?}", ast))),
Some(ref s) if s == "expanded" => comp.add_artifact(TraceArtifact::new("ast", format!("{:#?}", ast))),
Some(ref s) if s == "trace" => comp.add_artifact(TraceArtifact::new_parse_trace(trace)),
Some(ref x) => println!("Bad parsing debug option: {}", x),
}; };
*/ comp.add_artifact(debug_info);
}); });
ast.map_err(|err| format_parse_error(err, handle)) ast.map_err(|err| format_parse_error(err, handle))
} }
@ -236,9 +230,17 @@ impl SourceReference {
} }
} }
enum ParsingDebugType {
CompactAST,
ExpandedAST,
Trace
}
#[derive(Default)] #[derive(Default)]
struct PassDebugArtifact { struct PassDebugArtifact {
parsing: Option<ParsingDebugType>,
artifacts: Vec<String> artifacts: Vec<String>
} }
impl PassDebugArtifact { impl PassDebugArtifact {
fn add_artifact(&mut self, artifact: String) { fn add_artifact(&mut self, artifact: String) {
@ -276,7 +278,12 @@ impl ProgrammingLanguageInterface for Schala {
{ {
let stage_names = stage_names(); let stage_names = stage_names();
let ask = DebugAsk::ByStage { stage_name: stage_names[n].to_string() }; let ask = DebugAsk::ByStage { stage_name: stage_names[n].to_string() };
let mut debug_artifact = tok.debug_requests.get(&ask).map(|_| PassDebugArtifact::default()); let mut debug_artifact = tok.debug_requests.get(&ask).map(|_|
PassDebugArtifact {
parsing: if stage_names[n] == "parsing" { Some(ParsingDebugType::CompactAST) } else { None },
..Default::default()
}
);
let output = func(input, tok.schala, debug_artifact.as_mut()); let output = func(input, tok.schala, debug_artifact.as_mut());
tok.stage_durations.push((stage_names[n].to_string(), tok.sw.elapsed())); tok.stage_durations.push((stage_names[n].to_string(), tok.sw.elapsed()));

View File

@ -38,7 +38,7 @@ pub struct GlobalOutputStats {
#[derive(Debug, Clone, Hash, Eq, PartialEq, Deserialize, Serialize)] #[derive(Debug, Clone, Hash, Eq, PartialEq, Deserialize, Serialize)]
pub enum DebugAsk { pub enum DebugAsk {
Timing, Timing,
ByStage { stage_name: String }, ByStage { stage_name: String, token: Option<String> },
} }
pub struct DebugResponse { pub struct DebugResponse {

View File

@ -52,15 +52,12 @@ impl DirectiveAction {
Some(s) => s.to_string(), Some(s) => s.to_string(),
None => return Some(format!("Must specify a thing to debug")), None => return Some(format!("Must specify a thing to debug")),
}; };
let meta = LangMetaRequest::ImmediateDebug(DebugAsk::ByStage { stage_name: stage_name.clone() }); let meta = LangMetaRequest::ImmediateDebug(DebugAsk::ByStage { stage_name: stage_name.clone(), token: None });
let meta_response = cur_state.request_meta(meta);
let response = match cur_state.request_meta(meta) { let response = match meta_response {
LangMetaResponse::ImmediateDebug(DebugResponse { ask, value }) => { LangMetaResponse::ImmediateDebug(DebugResponse { ask: DebugAsk::ByStage { stage_name: this_stage_name, .. }, value }) if this_stage_name == stage_name =>
if (ask != DebugAsk::ByStage { stage_name: stage_name }) { value,
return Some(format!("Didn't get debug stage requested"));
}
value
},
_ => return Some(format!("Invalid language meta response")), _ => return Some(format!("Invalid language meta response")),
}; };
Some(response) Some(response)
@ -70,7 +67,7 @@ impl DirectiveAction {
Some(s) => s.to_string(), Some(s) => s.to_string(),
None => return Some(format!("Must specify a stage to show")), None => return Some(format!("Must specify a stage to show")),
}; };
let ask = DebugAsk::ByStage { stage_name }; let ask = DebugAsk::ByStage { stage_name, token: None };
repl.options.debug_asks.insert(ask); repl.options.debug_asks.insert(ask);
None None
}, },
@ -79,7 +76,7 @@ impl DirectiveAction {
Some(s) => s.to_string(), Some(s) => s.to_string(),
None => return Some(format!("Must specify a stage to hide")), None => return Some(format!("Must specify a stage to hide")),
}; };
let ask = DebugAsk::ByStage { stage_name }; let ask = DebugAsk::ByStage { stage_name, token: None };
repl.options.debug_asks.remove(&ask); repl.options.debug_asks.remove(&ask);
None None
}, },

View File

@ -149,7 +149,7 @@ impl Repl {
for debug_resp in response.debug_responses { for debug_resp in response.debug_responses {
let stage_name = match debug_resp.ask { let stage_name = match debug_resp.ask {
DebugAsk::ByStage { stage_name } => stage_name, DebugAsk::ByStage { stage_name, .. } => stage_name,
_ => continue, _ => continue,
}; };
let s = format!("{} - {}\n", stage_name, debug_resp.value); let s = format!("{} - {}\n", stage_name, debug_resp.value);