Add passing debug into via &mut pointer

This commit is contained in:
greg 2018-04-29 21:15:19 -07:00
parent 1d1a5fb6fc
commit 3a181dd0ac
2 changed files with 18 additions and 3 deletions

View File

@ -41,11 +41,24 @@ impl Schala {
}
fn tokenizing_stage(_handle: &mut Schala, input: &str, comp: Option<&mut UnfinishedComputation>) -> Result<Vec<tokenizing::Token>, ()> {
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!("{:?}<L:{},C:{}>", 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<tokenizing::Token>, comp: Option<&mut UnfinishedComputation>) -> Result<parsing::AST, parsing::ParseError> {
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<parsing::AST, String> {

View File

@ -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) => {