From 481afb0f87e2a9e84d13eab813b987d86d65660e Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 11 May 2018 02:33:19 -0700 Subject: [PATCH] Fix debugging and debug eval --- schala-lang/src/eval.rs | 4 ++++ schala-lang/src/lib.rs | 4 ++-- schala-repl/src/language.rs | 13 ++++++------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/schala-lang/src/eval.rs b/schala-lang/src/eval.rs index 8354cf3..d3d0e87 100644 --- a/schala-lang/src/eval.rs +++ b/schala-lang/src/eval.rs @@ -14,6 +14,10 @@ impl<'a> State<'a> { pub fn new() -> State<'a> { State { values: StateStack::new(Some(format!("global"))) } } + + pub fn debug_print(&self) -> String { + format!("Values: {:?}", self.values) + } } #[derive(Debug)] diff --git a/schala-lang/src/lib.rs b/schala-lang/src/lib.rs index 7545e26..689c648 100644 --- a/schala-lang/src/lib.rs +++ b/schala-lang/src/lib.rs @@ -99,8 +99,8 @@ fn ast_reducing(handle: &mut Schala, input: parsing::AST, comp: Option<&mut Unfi Ok((output, input)) } -fn eval(handle: &mut Schala, input: TempASTReduction, _comp: Option<&mut UnfinishedComputation>) -> Result { - +fn eval(handle: &mut Schala, input: TempASTReduction, comp: Option<&mut UnfinishedComputation>) -> Result { + comp.map(|comp| comp.add_artifact(TraceArtifact::new("value_state", handle.state.debug_print()))); let new_input = input.0; let evaluation_outputs = handle.state.evaluate_new(new_input, true); let text_output: Result, String> = evaluation_outputs diff --git a/schala-repl/src/language.rs b/schala-repl/src/language.rs index ce3b381..5f55ad5 100644 --- a/schala-repl/src/language.rs +++ b/schala-repl/src/language.rs @@ -52,14 +52,13 @@ impl UnfinishedComputation { impl FinishedComputation { pub fn to_repl(&self) -> String { 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(); - } + for (stage, artifact) in self.artifacts.iter() { + 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(); } + match self.text_output { Ok(ref output) => write!(&mut buf, "{}", output).unwrap(), Err(ref err) => write!(&mut buf, "{} {}", "Error: ".red().bold(), err).unwrap(),