Wrap schala pass inputs in token struct

This commit is contained in:
greg 2019-05-28 03:07:35 -07:00
parent 3fa624bef4
commit 856c0f95ce
1 changed files with 20 additions and 20 deletions

View File

@ -262,40 +262,40 @@ impl ProgrammingLanguageInterface for Schala {
fn get_source_file_suffix(&self) -> String { format!("schala") }
fn run_computation(&mut self, request: ComputationRequest) -> ComputationResponse {
let ComputationRequest { source, debug_requests } = request;
self.source_reference.load_new_source(source);
struct PassToken<'a> {
schala: &'a mut Schala,
stage_durations: &'a mut Vec<(String, Duration)>,
sw: &'a Stopwatch,
debug_requests: &'a HashSet<DebugAsk>
}
fn output_wrapper<Input, Output, F>(
n: usize,
func: F,
input: Input,
schala: &mut Schala,
stage_durations: &mut Vec<(String, Duration)>,
sw: &Stopwatch,
debug_requests: &HashSet<DebugAsk>) -> Result<Output, String>
where F: Fn(Input, &mut Schala, Option<&mut PassDebugArtifact>) -> Result<Output, String>,
fn output_wrapper<Input, Output, F>(n: usize, func: F, input: Input, tok: &mut PassToken) -> Result<Output, String>
where F: Fn(Input, &mut Schala, Option<&mut PassDebugArtifact>) -> Result<Output, String>
{
let stage_names = stage_names();
let mut debug_artifact = if debug_requests.contains(&DebugAsk::ByStage { stage_name: stage_names[n].to_string() }) {
let mut debug_artifact = if tok.debug_requests.contains(&DebugAsk::ByStage { stage_name: stage_names[n].to_string() }) {
Some(PassDebugArtifact::default())
} else {
None
};
let output = func(input, schala, debug_artifact.as_mut());
stage_durations.push((stage_names[n].to_string(), sw.elapsed()));
let output = func(input, tok.schala, debug_artifact.as_mut());
tok.stage_durations.push((stage_names[n].to_string(), tok.sw.elapsed()));
output
}
let ComputationRequest { source, debug_requests } = request;
self.source_reference.load_new_source(source);
let sw = Stopwatch::start_new();
let mut stage_durations = Vec::new();
let mut tok = PassToken { schala: self, stage_durations: &mut stage_durations, sw: &sw, debug_requests: &debug_requests };
let main_output: Result<String, String> = Ok(source)
.and_then(|source| output_wrapper(0, tokenizing, source, self, &mut stage_durations, &sw, &debug_requests))
.and_then(|tokens| output_wrapper(1, parsing, tokens, self, &mut stage_durations, &sw, &debug_requests))
.and_then(|ast| output_wrapper(2, symbol_table, ast, self, &mut stage_durations, &sw, &debug_requests))
.and_then(|ast| output_wrapper(3, typechecking, ast, self, &mut stage_durations, &sw, &debug_requests))
.and_then(|ast| output_wrapper(4, ast_reducing, ast, self, &mut stage_durations, &sw, &debug_requests))
.and_then(|reduced_ast| output_wrapper(5, eval, reduced_ast, self, &mut stage_durations, &sw, &debug_requests));
.and_then(|source| output_wrapper(0, tokenizing, source, &mut tok))
.and_then(|tokens| output_wrapper(1, parsing, tokens, &mut tok))
.and_then(|ast| output_wrapper(2, symbol_table, ast, &mut tok))
.and_then(|ast| output_wrapper(3, typechecking, ast, &mut tok))
.and_then(|ast| output_wrapper(4, ast_reducing, ast, &mut tok))
.and_then(|reduced_ast| output_wrapper(5, eval, reduced_ast, &mut tok));
let total_duration = sw.elapsed();
let global_output_stats = GlobalOutputStats {