🐛 bug: impl opcodes

main
_ 2023-09-30 10:01:30 -05:00
parent 1943f0a40b
commit e59dd85246
3 changed files with 25 additions and 1 deletions

View File

@ -52,6 +52,8 @@ pub enum Instruction {
// MetaMethod, Binary
MmBin (u8, u8, u8),
MmBinI (u8, i8, u8, bool),
MmBinK (u8, u8, u8, bool),
ModK (u8, u8, u8),
@ -82,6 +84,8 @@ pub enum Instruction {
SetTabUp (u8, u8, u8),
Sub (u8, u8, u8),
TailCall (u8, u8, u8, bool),
Test (u8, bool),

View File

@ -84,7 +84,6 @@ pub fn parse_inst (buf: [u8; 4]) -> Option <Inst>
let b = buf [2];
let ax = a as u32 + ((b as u32) << 8);
let c = buf [3];
let s_c = c - 0x80;
let bx =
(((buf [1] >> 7) as u32) << 0) |
((buf [2] as u32) << 1) |
@ -114,8 +113,10 @@ pub fn parse_inst (buf: [u8; 4]) -> Option <Inst>
0x18 => Inst::MulK (a, b, c),
0x19 => Inst::ModK (a, b, c),
0x22 => Inst::Add (a, b, c),
0x23 => Inst::Sub (a, b, c),
0x24 => Inst::Mul (a, b, c),
0x2e => Inst::MmBin (a, b, c),
0x2f => Inst::MmBinI (a, i_sb (buf)?, c, k),
0x30 => Inst::MmBinK (a, b, c, k),
0x33 => Inst::Not (a, b),
0x34 => Inst::Len (a, b),

View File

@ -448,6 +448,9 @@ impl <'a> State <'a> {
panic! ("Not sure how to implememtn OP_MMBIN for these 2 values {a:?}, {b:?}");
}
},
Instruction::MmBinI (_a, _s_b, _c, _k) => {
// Ignore
},
Instruction::MmBinK (_a, _b, _c, _k) => {
// Ignore
},
@ -633,6 +636,22 @@ impl <'a> State <'a> {
}
},
Instruction::SetTabUp (_a, _b, _c) => unimplemented! (),
Instruction::Sub (a, b, c) => {
let v_b = self.reg (*b);
let v_c = self.reg (*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::TailCall (a, b, _c, k) => {
assert! (!k, "closing over values in tail calls not implemented");