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

View File

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