Put back rudimentary debug output

This commit is contained in:
greg 2019-05-28 03:41:49 -07:00
parent 856c0f95ce
commit 78d1e93e4b
2 changed files with 25 additions and 4 deletions

View File

@ -266,7 +266,8 @@ impl ProgrammingLanguageInterface for Schala {
schala: &'a mut Schala,
stage_durations: &'a mut Vec<(String, Duration)>,
sw: &'a Stopwatch,
debug_requests: &'a HashSet<DebugAsk>
debug_requests: &'a HashSet<DebugAsk>,
debug_responses: &'a mut Vec<DebugResponse>,
}
fn output_wrapper<Input, Output, F>(n: usize, func: F, input: Input, tok: &mut PassToken) -> Result<Output, String>
@ -280,6 +281,15 @@ impl ProgrammingLanguageInterface for Schala {
};
let output = func(input, tok.schala, debug_artifact.as_mut());
tok.stage_durations.push((stage_names[n].to_string(), tok.sw.elapsed()));
if let Some(artifact) = debug_artifact {
for value in artifact.artifacts.into_iter() {
let resp = DebugResponse {
ask: DebugAsk::ByStage { stage_name: stage_names[n].to_string() },
value,
};
tok.debug_responses.push(resp);
}
}
output
}
@ -287,7 +297,8 @@ impl ProgrammingLanguageInterface for Schala {
self.source_reference.load_new_source(source);
let sw = Stopwatch::start_new();
let mut stage_durations = Vec::new();
let mut tok = PassToken { schala: self, stage_durations: &mut stage_durations, sw: &sw, debug_requests: &debug_requests };
let mut debug_responses = Vec::new();
let mut tok = PassToken { schala: self, stage_durations: &mut stage_durations, sw: &sw, debug_requests: &debug_requests, debug_responses: &mut debug_responses };
let main_output: Result<String, String> = Ok(source)
.and_then(|source| output_wrapper(0, tokenizing, source, &mut tok))
@ -305,7 +316,7 @@ impl ProgrammingLanguageInterface for Schala {
ComputationResponse {
main_output,
global_output_stats,
debug_responses: vec![],
debug_responses,
}
}

View File

@ -5,7 +5,7 @@ use std::collections::HashSet;
use colored::*;
use crate::language::{ProgrammingLanguageInterface,
ComputationRequest, ComputationResponse,
LangMetaRequest, LangMetaResponse};
DebugAsk};
mod command_tree;
use self::command_tree::{CommandTree, BoxedCommandFunction};
@ -202,6 +202,16 @@ impl Repl {
buf.push_str(&format!("{:?}\n", response.global_output_stats.stage_durations));
}
for debug_resp in response.debug_responses {
let stage_name = match debug_resp.ask {
DebugAsk::ByStage { stage_name } => stage_name,
_ => continue,
};
let s = format!("{} - {}\n", stage_name, debug_resp.value);
buf.push_str(&s);
}
buf.push_str(&match response.main_output {
Ok(s) => s,
Err(e) => format!("{} {}", "Error".red(), e)