diff --git a/schala-lang/language/src/lib.rs b/schala-lang/language/src/lib.rs index c7425fc..c38ecac 100644 --- a/schala-lang/language/src/lib.rs +++ b/schala-lang/language/src/lib.rs @@ -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 + debug_requests: &'a HashSet, + debug_responses: &'a mut Vec, } fn output_wrapper(n: usize, func: F, input: Input, tok: &mut PassToken) -> Result @@ -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 = 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, } } diff --git a/schala-repl/src/repl/mod.rs b/schala-repl/src/repl/mod.rs index 41aa993..658a0ca 100644 --- a/schala-repl/src/repl/mod.rs +++ b/schala-repl/src/repl/mod.rs @@ -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)