From 856c0f95ce364cc95632e5d213c8bed1a17b986d Mon Sep 17 00:00:00 2001 From: greg Date: Tue, 28 May 2019 03:07:35 -0700 Subject: [PATCH] Wrap schala pass inputs in token struct --- schala-lang/language/src/lib.rs | 40 ++++++++++++++++----------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/schala-lang/language/src/lib.rs b/schala-lang/language/src/lib.rs index 5e4de2c..c7425fc 100644 --- a/schala-lang/language/src/lib.rs +++ b/schala-lang/language/src/lib.rs @@ -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 + } - fn output_wrapper( - n: usize, - func: F, - input: Input, - schala: &mut Schala, - stage_durations: &mut Vec<(String, Duration)>, - sw: &Stopwatch, - debug_requests: &HashSet) -> Result - where F: Fn(Input, &mut Schala, Option<&mut PassDebugArtifact>) -> Result, + fn output_wrapper(n: usize, func: F, input: Input, tok: &mut PassToken) -> Result + where F: Fn(Input, &mut Schala, Option<&mut PassDebugArtifact>) -> Result { 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 = 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 {