From edb03dec94481a59927a40e91ce93df775b9388d Mon Sep 17 00:00:00 2001 From: Erin Date: Thu, 5 May 2022 00:36:13 +0200 Subject: [PATCH] get_bit returns error kind which makes the error spanned --- ablescript/src/error.rs | 7 ++----- ablescript/src/interpret.rs | 12 +++++++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/ablescript/src/error.rs b/ablescript/src/error.rs index 3b276696..00b90339 100644 --- a/ablescript/src/error.rs +++ b/ablescript/src/error.rs @@ -61,11 +61,8 @@ impl Display for ErrorKind { } } -impl From for Error { +impl From for ErrorKind { fn from(e: io::Error) -> Self { - Self { - kind: ErrorKind::IOError(e), - span: 0..0, - } + Self::IOError(e) } } diff --git a/ablescript/src/interpret.rs b/ablescript/src/interpret.rs index 9da76ecc..83075afc 100644 --- a/ablescript/src/interpret.rs +++ b/ablescript/src/interpret.rs @@ -220,7 +220,10 @@ impl ExecEnv { println!("{value}"); } else { print!("{value}"); - stdout().lock().flush()?; + stdout() + .lock() + .flush() + .map_err(|e| Error::new(e.into(), stmt.span.clone()))?; } } Stmt::Dim { ident, init } => { @@ -313,7 +316,10 @@ impl ExecEnv { let mut value = 0; for _ in 0..READ_BITS { value <<= 1; - value += self.get_bit()? as isize; + value += self + .get_bit() + .map_err(|e| Error::new(e, stmt.span.clone()))? + as isize; } self.assign(assignable, Value::Int(value))?; @@ -517,7 +523,7 @@ impl ExecEnv { /// Get a single bit from the bit buffer, or refill it from /// standard input if it is empty. - fn get_bit(&mut self) -> Result { + fn get_bit(&mut self) -> Result { const BITS_PER_BYTE: u8 = 8; if self.read_buf.is_empty() {