From 9a4255021d0828fbb067b77dccdbb7689506cc47 Mon Sep 17 00:00:00 2001 From: tjh <14987462+thomhayward@users.noreply.github.com> Date: Sun, 24 Nov 2024 17:30:16 +0000 Subject: [PATCH] panic on illegal operations --- src/main.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 901fb30..940c87a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -73,6 +73,7 @@ enum Op { a: Register, value: u32, }, + IllegalInstruction, } impl From for Op { @@ -100,7 +101,7 @@ impl From for Op { let value = value & 0x01ffffff; Self::Orthography { a, value } } - _ => Self::Halt, + _ => Self::IllegalInstruction, } } } @@ -340,6 +341,8 @@ impl Um { Op::Orthography { a, value } => { self.save_register(a, value); } + + Op::IllegalInstruction => self.panic(), } self.program_counter += 1; @@ -401,4 +404,12 @@ impl Um { self.memory[block as usize] = vec![]; } } + + #[inline(never)] + fn panic(&self) -> ! { + panic!( + "universal machine failure: instruction: {:08x}, program_counter: {:08x}, registers: {:08x?}", + self.memory[0][self.program_counter as usize], self.program_counter, self.registers + ) + } } -- 2.51.2