From fce7a96e502f32b86d3ddeb636beaa251581c859 Mon Sep 17 00:00:00 2001 From: Erin Date: Thu, 8 Jun 2023 00:27:53 +0200 Subject: [PATCH] VM exceptions --- hbvm/src/vm/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hbvm/src/vm/mod.rs b/hbvm/src/vm/mod.rs index 69fe6b6f..40b4d625 100644 --- a/hbvm/src/vm/mod.rs +++ b/hbvm/src/vm/mod.rs @@ -36,7 +36,7 @@ macro_rules! load { *$self.reg_mut(tg) = $self .memory .load::<$size>($self.reg(a0).int() + offset) - .unwrap(); + .ok_or(Exception::LoadAccess)?; }}; } @@ -46,7 +46,7 @@ macro_rules! store { $self .memory .store::<$size>($self.reg(a0).int() + offset, *$self.reg(src)) - .unwrap(); + .map_err(|_| Exception::StoreAccess)?; }}; } @@ -74,11 +74,11 @@ impl<'a> Vm<'a> { Ok(unsafe { Self::new_unchecked(program) }) } - pub fn run(&mut self) { + pub fn run(&mut self) -> Result<(), Exception> { use hbbytecode::opcode::*; loop { let Some(&opcode) = self.program.get(self.pc) - else { return }; + else { return Ok(()) }; unsafe { match opcode {