From 062c6e6a2df781c74160c91884ddc85cc2db5612 Mon Sep 17 00:00:00 2001 From: _ <_@_> Date: Tue, 26 Sep 2023 23:19:12 -0500 Subject: [PATCH] :bug: bug: fix loader bug --- src/loader.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/loader.rs b/src/loader.rs index 108e6c4..056eeef 100644 --- a/src/loader.rs +++ b/src/loader.rs @@ -43,13 +43,17 @@ pub (crate) fn compile_bytecode (source: Vec ) -> Vec { output.stdout.as_slice ().to_vec () } +fn i_sb (buf: [u8; 4]) -> Option { + let b = buf [2]; + i8::try_from (i32::try_from (b).ok ()? - 127).ok () +} + pub fn parse_inst (buf: [u8; 4]) -> Option { let opcode = buf [0] & 0x7f; let a = (buf [0] >> 7) | ((buf [1] & 0x7f) << 1); let b = buf [2]; - let sb = i8::try_from (b).ok ()? - 127; let ax = a as u32 + ((b as u32) << 8); let c = buf [3]; let bx = @@ -84,7 +88,7 @@ pub fn parse_inst (buf: [u8; 4]) -> Option 0x30 => Inst::MmBinK (a, b, c, k), 0x33 => Inst::Not (a, b), 0x3c => Inst::EqK (a, b, k), - 0x3d => Inst::EqI (a, sb, k), + 0x3d => Inst::EqI (a, i_sb (buf)?, k), 0x38 => Inst::Jmp (s_j), 0x42 => Inst::Test (a, k), 0x44 => Inst::Call (a, b, c),