get_bit returns error kind which makes the error spanned

This commit is contained in:
Erin 2022-05-05 00:36:13 +02:00 committed by ondra05
parent 7b5a9aed89
commit edb03dec94
2 changed files with 11 additions and 8 deletions

View file

@ -61,11 +61,8 @@ impl Display for ErrorKind {
} }
} }
impl From<io::Error> for Error { impl From<io::Error> for ErrorKind {
fn from(e: io::Error) -> Self { fn from(e: io::Error) -> Self {
Self { Self::IOError(e)
kind: ErrorKind::IOError(e),
span: 0..0,
}
} }
} }

View file

@ -220,7 +220,10 @@ impl ExecEnv {
println!("{value}"); println!("{value}");
} else { } else {
print!("{value}"); print!("{value}");
stdout().lock().flush()?; stdout()
.lock()
.flush()
.map_err(|e| Error::new(e.into(), stmt.span.clone()))?;
} }
} }
Stmt::Dim { ident, init } => { Stmt::Dim { ident, init } => {
@ -313,7 +316,10 @@ impl ExecEnv {
let mut value = 0; let mut value = 0;
for _ in 0..READ_BITS { for _ in 0..READ_BITS {
value <<= 1; 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))?; self.assign(assignable, Value::Int(value))?;
@ -517,7 +523,7 @@ impl ExecEnv {
/// Get a single bit from the bit buffer, or refill it from /// Get a single bit from the bit buffer, or refill it from
/// standard input if it is empty. /// standard input if it is empty.
fn get_bit(&mut self) -> Result<bool, Error> { fn get_bit(&mut self) -> Result<bool, ErrorKind> {
const BITS_PER_BYTE: u8 = 8; const BITS_PER_BYTE: u8 = 8;
if self.read_buf.is_empty() { if self.read_buf.is_empty() {