parent
1518781753
commit
4fd412b415
|
@ -30,6 +30,7 @@ pub fn parse_inst (buf: [u8; 4]) -> Option <Inst>
|
||||||
0x0b => Inst::GetTabUp (a, b, c),
|
0x0b => Inst::GetTabUp (a, b, c),
|
||||||
0x0d => Inst::GetI (a, b, c),
|
0x0d => Inst::GetI (a, b, c),
|
||||||
0x22 => Inst::Add (a, b, c),
|
0x22 => Inst::Add (a, b, c),
|
||||||
|
0x24 => Inst::Mul (a, b, c),
|
||||||
0x2e => Inst::MmBin (a, b, c),
|
0x2e => Inst::MmBin (a, b, c),
|
||||||
0x3c => Inst::EqK (a, b, c),
|
0x3c => Inst::EqK (a, b, c),
|
||||||
0x38 => Inst::Jmp (s_j),
|
0x38 => Inst::Jmp (s_j),
|
||||||
|
@ -207,8 +208,10 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_header () {
|
fn parse_header () {
|
||||||
for (input, expected) in [
|
for (input, expected) in [
|
||||||
// Bytes 0 and 1 are line and column for debugging
|
// Bytes 0 and 1 are first line and last line for debugging
|
||||||
// Byte 4 is slot count
|
// Byte 2 is numparams
|
||||||
|
// Byte 3 is is_vararg
|
||||||
|
// Byte 4 is slot count / max stack size
|
||||||
// Byte 5 is instruction count
|
// Byte 5 is instruction count
|
||||||
|
|
||||||
([0x80, 0x80, 0x00, 0x01, 0x04, 0x92], (18,)),
|
([0x80, 0x80, 0x00, 0x01, 0x04, 0x92], (18,)),
|
||||||
|
|
|
@ -487,7 +487,7 @@ impl State {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Return from the entire program
|
// 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) => {
|
Instruction::Return1 (a) => {
|
||||||
|
|
|
@ -157,6 +157,7 @@ fn fma () {
|
||||||
let bytecode = include_bytes! ("../test_vectors/fma.luac");
|
let bytecode = include_bytes! ("../test_vectors/fma.luac");
|
||||||
let mut rdr = std::io::Cursor::new (bytecode);
|
let mut rdr = std::io::Cursor::new (bytecode);
|
||||||
let file = crate::loader::parse_chunk (&mut rdr).unwrap ();
|
let file = crate::loader::parse_chunk (&mut rdr).unwrap ();
|
||||||
|
assert_eq! (file.blocks.len (), 4);
|
||||||
|
|
||||||
for (arg, expected) in [
|
for (arg, expected) in [
|
||||||
(vec! ["_exe_name"], vec! [122.into ()]),
|
(vec! ["_exe_name"], vec! [122.into ()]),
|
||||||
|
|
Binary file not shown.
|
@ -6,4 +6,6 @@ local function make_closure (x)
|
||||||
end
|
end
|
||||||
|
|
||||||
local f = make_closure (11)
|
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)
|
local function add (aa, bb)
|
||||||
return a + b
|
return aa + bb
|
||||||
end
|
end
|
||||||
|
|
||||||
local function mul (a, b)
|
local function mul (cc, dd)
|
||||||
return a * b
|
return cc * dd
|
||||||
end
|
end
|
||||||
|
|
||||||
local function fma (a, b, c)
|
local function fma (ee, ff, gg)
|
||||||
return add (mul (a, b), c)
|
return add (mul (ee, ff), gg)
|
||||||
end
|
end
|
||||||
|
|
||||||
local x = fma (10, 11, 12)
|
local hh = fma (10, 11, 12)
|
||||||
print (x)
|
print (hh)
|
||||||
return x
|
return hh
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue