🚧 wip: I'm not handling nested functions in luac files properly

will fix soon
main
_ 2023-09-25 01:57:57 -05:00
parent 1518781753
commit 4fd412b415
8 changed files with 19 additions and 13 deletions

View File

@ -30,6 +30,7 @@ pub fn parse_inst (buf: [u8; 4]) -> Option <Inst>
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,)),

View File

@ -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) => {

View File

@ -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 ()]),

BIN
test_vectors/bools.luac Normal file

Binary file not shown.

View File

@ -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

Binary file not shown.

View File

@ -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

BIN
test_vectors/fma.luac Normal file

Binary file not shown.