parent
1518781753
commit
4fd412b415
|
@ -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,)),
|
||||
|
|
|
@ -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) => {
|
||||
|
|
|
@ -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 ()]),
|
||||
|
|
Binary file not shown.
|
@ -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.
|
@ -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
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue