diff --git a/src/loader.rs b/src/loader.rs index ab26d07..ff5ce88 100644 --- a/src/loader.rs +++ b/src/loader.rs @@ -30,6 +30,7 @@ pub fn parse_inst (buf: [u8; 4]) -> Option 0x0b => Inst::GetTabUp (a, b, c), 0x0d => Inst::GetI (a, b, c), 0x22 => Inst::Add (a, b, c), + 0x24 => Inst::Mul (a, b, c), 0x2e => Inst::MmBin (a, b, c), 0x3c => Inst::EqK (a, b, c), 0x38 => Inst::Jmp (s_j), @@ -207,8 +208,10 @@ mod tests { #[test] fn parse_header () { for (input, expected) in [ - // Bytes 0 and 1 are line and column for debugging - // Byte 4 is slot count + // Bytes 0 and 1 are first line and last line for debugging + // Byte 2 is numparams + // Byte 3 is is_vararg + // Byte 4 is slot count / max stack size // Byte 5 is instruction count ([0x80, 0x80, 0x00, 0x01, 0x04, 0x92], (18,)), diff --git a/src/state.rs b/src/state.rs index 8d831ea..3b98641 100644 --- a/src/state.rs +++ b/src/state.rs @@ -487,7 +487,7 @@ impl State { } else { // Return from the entire program - return self.registers [a..(a + b + c - 1)].to_vec(); + return self.registers [a..(a + b - 1)].to_vec(); } }, Instruction::Return1 (a) => { diff --git a/src/tests.rs b/src/tests.rs index 187ea6f..7371af3 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -157,6 +157,7 @@ fn fma () { let bytecode = include_bytes! ("../test_vectors/fma.luac"); let mut rdr = std::io::Cursor::new (bytecode); let file = crate::loader::parse_chunk (&mut rdr).unwrap (); + assert_eq! (file.blocks.len (), 4); for (arg, expected) in [ (vec! ["_exe_name"], vec! [122.into ()]), diff --git a/test_vectors/bools.luac b/test_vectors/bools.luac new file mode 100644 index 0000000..b63d506 Binary files /dev/null and b/test_vectors/bools.luac differ diff --git a/test_vectors/closure.lua b/test_vectors/closure.lua index 8e4250c..d15dfb3 100644 --- a/test_vectors/closure.lua +++ b/test_vectors/closure.lua @@ -6,4 +6,6 @@ local function make_closure (x) end local f = make_closure (11) -print (f (12)) +local x = f (12) +print (x) +return x diff --git a/test_vectors/closure.luac b/test_vectors/closure.luac index b9ae82c..da75907 100644 Binary files a/test_vectors/closure.luac and b/test_vectors/closure.luac differ diff --git a/test_vectors/fma.lua b/test_vectors/fma.lua index 7525a54..f807eef 100644 --- a/test_vectors/fma.lua +++ b/test_vectors/fma.lua @@ -1,15 +1,15 @@ -local function add (a, b) - return a + b +local function add (aa, bb) + return aa + bb end -local function mul (a, b) - return a * b +local function mul (cc, dd) + return cc * dd end -local function fma (a, b, c) - return add (mul (a, b), c) +local function fma (ee, ff, gg) + return add (mul (ee, ff), gg) end -local x = fma (10, 11, 12) -print (x) -return x +local hh = fma (10, 11, 12) +print (hh) +return hh diff --git a/test_vectors/fma.luac b/test_vectors/fma.luac new file mode 100644 index 0000000..e36b422 Binary files /dev/null and b/test_vectors/fma.luac differ