Fix debugging and debug eval

This commit is contained in:
greg 2018-05-11 02:33:19 -07:00
parent 01986e7474
commit 481afb0f87
3 changed files with 12 additions and 9 deletions

View File

@ -14,6 +14,10 @@ impl<'a> State<'a> {
pub fn new() -> State<'a> { pub fn new() -> State<'a> {
State { values: StateStack::new(Some(format!("global"))) } State { values: StateStack::new(Some(format!("global"))) }
} }
pub fn debug_print(&self) -> String {
format!("Values: {:?}", self.values)
}
} }
#[derive(Debug)] #[derive(Debug)]

View File

@ -99,8 +99,8 @@ fn ast_reducing(handle: &mut Schala, input: parsing::AST, comp: Option<&mut Unfi
Ok((output, input)) Ok((output, input))
} }
fn eval(handle: &mut Schala, input: TempASTReduction, _comp: Option<&mut UnfinishedComputation>) -> Result<String, String> { fn eval(handle: &mut Schala, input: TempASTReduction, comp: Option<&mut UnfinishedComputation>) -> Result<String, String> {
comp.map(|comp| comp.add_artifact(TraceArtifact::new("value_state", handle.state.debug_print())));
let new_input = input.0; let new_input = input.0;
let evaluation_outputs = handle.state.evaluate_new(new_input, true); let evaluation_outputs = handle.state.evaluate_new(new_input, true);
let text_output: Result<Vec<String>, String> = evaluation_outputs let text_output: Result<Vec<String>, String> = evaluation_outputs

View File

@ -52,14 +52,13 @@ impl UnfinishedComputation {
impl FinishedComputation { impl FinishedComputation {
pub fn to_repl(&self) -> String { pub fn to_repl(&self) -> String {
let mut buf = String::new(); let mut buf = String::new();
for stage in ["tokens", "parse_trace", "ast", "symbol_table", "type_check"].iter() { for (stage, artifact) in self.artifacts.iter() {
if let Some(artifact) = self.artifacts.get(&stage.to_string()) { let color = artifact.text_color;
let color = artifact.text_color; let stage = stage.color(color).bold();
let stage = stage.color(color).bold(); let output = artifact.debug_output.color(color);
let output = artifact.debug_output.color(color); write!(&mut buf, "{}: {}\n", stage, output).unwrap();
write!(&mut buf, "{}: {}\n", stage, output).unwrap();
}
} }
match self.text_output { match self.text_output {
Ok(ref output) => write!(&mut buf, "{}", output).unwrap(), Ok(ref output) => write!(&mut buf, "{}", output).unwrap(),
Err(ref err) => write!(&mut buf, "{} {}", "Error: ".red().bold(), err).unwrap(), Err(ref err) => write!(&mut buf, "{} {}", "Error: ".red().bold(), err).unwrap(),