🐛 bug: implement OP_MULK

main
_ 2023-09-30 09:52:42 -05:00
parent 64384e7ca5
commit 81743108c3
3 changed files with 19 additions and 0 deletions

View File

@ -59,6 +59,8 @@ pub enum Instruction {
Mul (u8, u8, u8), Mul (u8, u8, u8),
MulK (u8, u8, u8),
NewTable (u8), NewTable (u8),
Not (u8, u8), Not (u8, u8),

View File

@ -104,6 +104,7 @@ pub fn parse_inst (buf: [u8; 4]) -> Option <Inst>
0x11 => Inst::SetI (a, b, c, k), 0x11 => Inst::SetI (a, b, c, k),
0x12 => Inst::SetField (a, b, c, k), 0x12 => Inst::SetField (a, b, c, k),
0x13 => Inst::NewTable (a), 0x13 => Inst::NewTable (a),
0x18 => Inst::MulK (a, b, c),
0x19 => Inst::ModK (a, b, c), 0x19 => Inst::ModK (a, b, c),
0x22 => Inst::Add (a, b, c), 0x22 => Inst::Add (a, b, c),
0x24 => Inst::Mul (a, b, c), 0x24 => Inst::Mul (a, b, c),

View File

@ -465,6 +465,22 @@ impl <'a> State <'a> {
*self.reg_mut (*a) = x; *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) => { Instruction::NewTable (a) => {
*self.reg_mut (*a) = Value::Table (Default::default ()); *self.reg_mut (*a) = Value::Table (Default::default ());
}, },