diff --git a/src/interpreter.rs b/src/interpreter.rs index 7e6ac50..1c89cf4 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -14,8 +14,8 @@ pub struct Interpreter { } impl Interpreter { - pub fn new(input: String) -> Interpreter { - Interpreter { + pub fn new(input: String) -> Self { + Self { input, vars: HashMap::new(), pos: 1, @@ -219,8 +219,8 @@ impl Interpreter { fn input(&self, value: &String) -> Value { let mut input = String::new(); print!("{}", value); - io::stdout().flush().unwrap_or_default(); - io::stdin().read_line(&mut input).unwrap_or_default(); + io::stdout().flush().expect("Couldn't flush Stdout"); + io::stdin().read_line(&mut input).expect("Couldn't read from Stdin"); Value::String(input.trim_end().to_string()) } diff --git a/src/main.rs b/src/main.rs index 812ec7c..fc2e8f9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +#![feature(box_syntax, panic_info_message)] + use clap::Parser; use std::fs; use std::time::Instant; @@ -15,6 +17,15 @@ mod interpreter; use interpreter::Interpreter; fn main() { + std::panic::set_hook( + box |info| { + eprint!("{msg}", msg = match info.message() { + None => "Program panicked!".to_owned(), + Some(x) => x.to_string() + }); + } + ); + let start = Instant::now(); let args = Args::parse();