Fix debugging and debug eval
This commit is contained in:
parent
01986e7474
commit
481afb0f87
@ -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)]
|
||||
|
@ -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<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 evaluation_outputs = handle.state.evaluate_new(new_input, true);
|
||||
let text_output: Result<Vec<String>, String> = evaluation_outputs
|
||||
|
@ -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(),
|
||||
|
Loading…
Reference in New Issue
Block a user