diff --git a/src/instruction.rs b/src/instruction.rs index 0ff3568..cedb35d 100644 --- a/src/instruction.rs +++ b/src/instruction.rs @@ -59,6 +59,8 @@ pub enum Instruction { Mul (u8, u8, u8), + MulK (u8, u8, u8), + NewTable (u8), Not (u8, u8), diff --git a/src/loader.rs b/src/loader.rs index fffb4e0..712527b 100644 --- a/src/loader.rs +++ b/src/loader.rs @@ -104,6 +104,7 @@ pub fn parse_inst (buf: [u8; 4]) -> Option 0x11 => Inst::SetI (a, b, c, k), 0x12 => Inst::SetField (a, b, c, k), 0x13 => Inst::NewTable (a), + 0x18 => Inst::MulK (a, b, c), 0x19 => Inst::ModK (a, b, c), 0x22 => Inst::Add (a, b, c), 0x24 => Inst::Mul (a, b, c), diff --git a/src/state.rs b/src/state.rs index 4a40e19..40d85f8 100644 --- a/src/state.rs +++ b/src/state.rs @@ -465,6 +465,22 @@ impl <'a> State <'a> { *self.reg_mut (*a) = x; }, + Instruction::MulK (a, b, c) => { + let v_b = self.reg (*b); + let v_c = &k [usize::from (*c)]; + + let x = if let (Some (v_b), Some (v_c)) = (v_b.as_int (), v_c.as_int ()) + { + Value::from (v_b * v_c) + } + else { + let v_b = v_b.as_float ().unwrap_or_else (|| panic! ("{v_b}")); + let v_c = v_c.as_float ().unwrap_or_else (|| panic! ("{v_c}")); + Value::from (v_b * v_c) + }; + + *self.reg_mut (*a) = x; + }, Instruction::NewTable (a) => { *self.reg_mut (*a) = Value::Table (Default::default ()); },