diff --git a/schala-lang/language/src/lib.rs b/schala-lang/language/src/lib.rs index 70e191a..57dcab6 100644 --- a/schala-lang/language/src/lib.rs +++ b/schala-lang/language/src/lib.rs @@ -267,8 +267,7 @@ impl ProgrammingLanguageInterface for Schala { .and_then(|ast| ast_reducing(ast, self, reducing_debug_artifact)) .and_then(|reduced_ast| eval(reduced_ast, self, eval_debug_artifact)); - let total_duration = Some(sw.elapsed()); - + let total_duration = sw.elapsed(); let global_output_stats = GlobalOutputStats { total_duration, stage_durations: None, }; diff --git a/schala-repl/src/language.rs b/schala-repl/src/language.rs index 6aae266..f60257b 100644 --- a/schala-repl/src/language.rs +++ b/schala-repl/src/language.rs @@ -30,7 +30,7 @@ pub struct ComputationResponse { #[derive(Default, Debug)] pub struct GlobalOutputStats { - pub total_duration: Option, + pub total_duration: time::Duration, pub stage_durations: Option> } diff --git a/schala-repl/src/repl/mod.rs b/schala-repl/src/repl/mod.rs index de5258c..13b6ad5 100644 --- a/schala-repl/src/repl/mod.rs +++ b/schala-repl/src/repl/mod.rs @@ -1,6 +1,5 @@ use std::fmt::Write as FmtWrite; use std::sync::Arc; -use std::collections::HashSet; use colored::*; use itertools::Itertools; @@ -12,7 +11,7 @@ DebugRequest, DebugAsk, DebugResponse}; mod command_tree; use self::command_tree::{CommandTree, BoxedCommandFunction}; mod repl_options; -use repl_options::SaveOptions; +use repl_options::ReplOptions; const HISTORY_SAVE_FILE: &'static str = ".schala_history"; const OPTIONS_SAVE_FILE: &'static str = ".schala_repl"; @@ -21,7 +20,7 @@ pub struct Repl { interpreter_directive_sigil: char, line_reader: ::linefeed::interface::Interface<::linefeed::terminal::DefaultTerminal>, language_states: Vec>, - debug_asks: HashSet, + options: ReplOptions, } impl Repl { @@ -34,7 +33,7 @@ impl Repl { interpreter_directive_sigil, line_reader, language_states: initial_states, - debug_asks: HashSet::new(), + options: ReplOptions::new(), } } @@ -49,9 +48,9 @@ impl Repl { fn load_options(&mut self) { self.line_reader.load_history(HISTORY_SAVE_FILE).unwrap_or(()); - match SaveOptions::load_from_file(OPTIONS_SAVE_FILE) { + match ReplOptions::load_from_file(OPTIONS_SAVE_FILE) { Ok(options) => { - self.debug_asks = options.debug_asks; + self.options = options; }, Err(()) => () }; @@ -91,10 +90,7 @@ impl Repl { fn save_before_exit(&self) { self.line_reader.save_history(HISTORY_SAVE_FILE).unwrap_or(()); - let options = SaveOptions { - debug_asks: self.debug_asks.clone() - }; - options.save_to_file(OPTIONS_SAVE_FILE); + self.options.save_to_file(OPTIONS_SAVE_FILE); } fn get_function_from_directives<'a>(directives: &'a CommandTree, commands: &Vec<&str>) -> Result<(&'a BoxedCommandFunction, usize), String> { @@ -179,7 +175,7 @@ impl Repl { fn handle_input(&mut self, input: &str) -> String { let mut debug_requests = vec![]; - for ask in self.debug_asks.iter() { + for ask in self.options.debug_asks.iter() { debug_requests.push(DebugRequest { ask: ask.clone() }); } @@ -197,8 +193,8 @@ impl Repl { fn handle_computation_response(&mut self, response: ComputationResponse) -> String { let mut buf = String::new(); - if let Some(total_duration) = response.global_output_stats.total_duration { - buf.push_str(&format!("Total duration: {:?}\n", total_duration)); + if self.options.show_total_time { + buf.push_str(&format!("Total duration: {:?}\n", response.global_output_stats.total_duration)); } buf.push_str(&match response.main_output { @@ -288,16 +284,16 @@ impl Repl { }; let ask = DebugAsk::ByStage { stage_name }; if cmd == Some(&"show") { - repl.debug_asks.insert(ask); + repl.options.debug_asks.insert(ask); } else { - repl.debug_asks.remove(&ask); + repl.options.debug_asks.remove(&ask); } None }, Some(&"timing") => { match cmds.get(1) { - Some(&"on") => repl.debug_asks.insert(DebugAsk::Timing), - Some(&"off") => repl.debug_asks.remove(&DebugAsk::Timing), + Some(&"on") => repl.options.debug_asks.insert(DebugAsk::Timing), + Some(&"off") => repl.options.debug_asks.remove(&DebugAsk::Timing), _ => return Some(format!("Must specify 'on' or 'off'")), }; None diff --git a/schala-repl/src/repl/repl_options.rs b/schala-repl/src/repl/repl_options.rs index 54e8591..2f07bf0 100644 --- a/schala-repl/src/repl/repl_options.rs +++ b/schala-repl/src/repl/repl_options.rs @@ -5,11 +5,19 @@ use std::collections::HashSet; use std::fs::File; #[derive(Serialize, Deserialize)] -pub struct SaveOptions { - pub debug_asks: HashSet +pub struct ReplOptions { + pub debug_asks: HashSet, + pub show_total_time: bool, } -impl SaveOptions { +impl ReplOptions { + pub fn new() -> ReplOptions { + ReplOptions { + debug_asks: HashSet::new(), + show_total_time: true, + } + } + pub fn save_to_file(&self, filename: &str) { let res = File::create(filename) .and_then(|mut file| { @@ -21,7 +29,7 @@ impl SaveOptions { } } - pub fn load_from_file(filename: &str) -> Result { + pub fn load_from_file(filename: &str) -> Result { File::open(filename) .and_then(|mut file| { let mut contents = String::new(); @@ -29,7 +37,7 @@ impl SaveOptions { Ok(contents) }) .and_then(|contents| { - let output: SaveOptions = crate::serde_json::from_str(&contents)?; + let output: ReplOptions = crate::serde_json::from_str(&contents)?; Ok(output) }) .map_err(|_| ())