From 3a181dd0ac359ab44c95a4780077611a105f7a4c Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 29 Apr 2018 21:15:19 -0700 Subject: [PATCH] Add passing debug into via &mut pointer --- schala-lang/src/lib.rs | 15 ++++++++++++++- schala-repl/src/language.rs | 6 ++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/schala-lang/src/lib.rs b/schala-lang/src/lib.rs index 8cb6f25..7f19032 100644 --- a/schala-lang/src/lib.rs +++ b/schala-lang/src/lib.rs @@ -41,11 +41,24 @@ impl Schala { } fn tokenizing_stage(_handle: &mut Schala, input: &str, comp: Option<&mut UnfinishedComputation>) -> Result, ()> { + let tokens = tokenizing::tokenize(input); + comp.map(|comp| { + println!("This should only be evaluated when debugging tokens and not other times!!!"); + let token_string = tokens.iter().map(|t| format!("{:?}", t.token_type, t.offset.0, t.offset.1)).join(", "); + comp.add_artifact(TraceArtifact::new("tokens", token_string)); + }); Ok(tokenizing::tokenize(input)) } fn parsing_stage(_handle: &mut Schala, input: Vec, comp: Option<&mut UnfinishedComputation>) -> Result { - parsing::parse(input).0 + + let (ast, trace) = parsing::parse(input); + comp.map(|comp| { + //TODO need to control which of these debug stages get added + comp.add_artifact(TraceArtifact::new_parse_trace(trace)); + comp.add_artifact(TraceArtifact::new("ast", format!("{:#?}", ast))); + }); + ast } fn symbol_table_stage(handle: &mut Schala, input: parsing::AST, comp: Option<&mut UnfinishedComputation>) -> Result { diff --git a/schala-repl/src/language.rs b/schala-repl/src/language.rs index 72d6986..00fc18c 100644 --- a/schala-repl/src/language.rs +++ b/schala-repl/src/language.rs @@ -208,8 +208,10 @@ macro_rules! pass_chain_helper { { let pass_name = stringify!($pass); println!("Running pass {}", pass_name); - let debug_pointer: Option<&mut UnfinishedComputation> = None; - let output = $pass($state, $input, debug_pointer); + let output = { + let debug_pointer: Option<&mut UnfinishedComputation> = Some(&mut $comp); + $pass($state, $input, debug_pointer) + }; match output { Ok(result) => pass_chain_helper! { $state, $comp; result $(, $rest)* }, Err(err) => {