VM exceptions

pull/1/head
ondra05 2023-06-08 00:27:53 +02:00
parent e57fcdf89a
commit 36b3ee2bb5
No known key found for this signature in database
GPG Key ID: 0DA6D2BB2285E881
1 changed files with 4 additions and 4 deletions

View File

@ -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 {