Added better error-reporting to the emulator.

This commit is contained in:
jan 2024-12-22 13:17:41 +01:00
parent ed7ca9a227
commit 890c2b7b79
4 changed files with 10 additions and 7 deletions

2
Cargo.lock generated
View File

@ -1813,7 +1813,7 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "svc16"
version = "0.6.0"
version = "0.6.1"
dependencies = [
"anyhow",
"clap",

View File

@ -1,6 +1,6 @@
[package]
name = "svc16"
version = "0.6.0"
version = "0.6.1"
edition = "2021"
authors = ["Jan Neuendorf"]
description = "An emulator for a simple virtual computer"

View File

@ -36,8 +36,8 @@ pub enum EngineError {
#[error("Division by zero")]
ZeroDivision,
#[error("Invalid instruction")]
InvalidInstruction,
#[error("Invalid instruction {0}")]
InvalidInstruction(u16),
}
impl Engine {
@ -216,7 +216,7 @@ impl Engine {
}
self.advance_inst_ptr();
}
_ => return Err(EngineError::InvalidInstruction),
_ => return Err(EngineError::InvalidInstruction(opcode)),
}
Ok(())
}

View File

@ -87,8 +87,11 @@ fn main() -> Result<()> {
let engine_start = Instant::now();
while !engine.wants_to_sync() && ipf <= cli.max_ipf && !paused {
match engine.step() {
Err(_) => {
handle_event_loop_error(&elwt, "Invalid operation");
Err(e) => {
handle_event_loop_error(
&elwt,
format!("{} (after {} instructions)", e, ipf),
);
return;
}
_ => {}