♻️ refactor: invoke luac during tests so I don't have to version artifacts
parent
0d88653c21
commit
d9469b4440
|
@ -2,6 +2,61 @@
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "arrayref"
|
||||||
|
version = "0.3.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "arrayvec"
|
||||||
|
version = "0.7.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "blake3"
|
||||||
|
version = "1.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0231f06152bf547e9c2b5194f247cd97aacf6dcd8b15d8e5ec0663f64580da87"
|
||||||
|
dependencies = [
|
||||||
|
"arrayref",
|
||||||
|
"arrayvec",
|
||||||
|
"cc",
|
||||||
|
"cfg-if",
|
||||||
|
"constant_time_eq",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cc"
|
||||||
|
version = "1.0.83"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "constant_time_eq"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.148"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lunar_wave_vm"
|
name = "lunar_wave_vm"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"blake3",
|
||||||
|
]
|
||||||
|
|
|
@ -5,3 +5,8 @@ version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
|
||||||
|
# blake3, used to hash test vectors
|
||||||
|
blake3 = "1.5.0"
|
||||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -8,11 +8,10 @@ fn main() {
|
||||||
use state::State;
|
use state::State;
|
||||||
|
|
||||||
let lua_file = {
|
let lua_file = {
|
||||||
let data = std::fs::read ("test_vectors/closure.luac").unwrap ();
|
let data = std::fs::read ("test_vectors/fma.luac").unwrap ();
|
||||||
let mut rdr = std::io::Cursor::new (data);
|
let mut rdr = std::io::Cursor::new (data);
|
||||||
loader::parse_chunk (&mut rdr).unwrap ()
|
loader::parse_chunk (&mut rdr).unwrap ()
|
||||||
};
|
};
|
||||||
assert_eq! (lua_file.blocks.len (), 3);
|
|
||||||
|
|
||||||
let mut vm = State::default ();
|
let mut vm = State::default ();
|
||||||
if std::env::var("LUA_DEBUG").is_ok() {
|
if std::env::var("LUA_DEBUG").is_ok() {
|
||||||
|
@ -22,12 +21,8 @@ fn main() {
|
||||||
let upvalues = State::upvalues_from_args (std::env::args ());
|
let upvalues = State::upvalues_from_args (std::env::args ());
|
||||||
|
|
||||||
vm.breakpoints.push (state::Breakpoint {
|
vm.breakpoints.push (state::Breakpoint {
|
||||||
block_idx: 2,
|
block_idx: 3,
|
||||||
program_counter: 3,
|
program_counter: 0,
|
||||||
});
|
|
||||||
vm.breakpoints.push (state::Breakpoint {
|
|
||||||
block_idx: 0,
|
|
||||||
program_counter: 10,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
println! ("Returned: {:?}", vm.execute_chunk (&lua_file, &upvalues));
|
println! ("Returned: {:?}", vm.execute_chunk (&lua_file, &upvalues));
|
||||||
|
|
40
src/tests.rs
40
src/tests.rs
|
@ -5,6 +5,39 @@ use crate::state::{
|
||||||
State,
|
State,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Invoke `luac` as a subprocess
|
||||||
|
// Luckily luac is single-pass, so we can just pipe in and out
|
||||||
|
|
||||||
|
fn compile_bytecode (source: Vec <u8>) -> Vec <u8> {
|
||||||
|
use std::{
|
||||||
|
io::Write,
|
||||||
|
process::{
|
||||||
|
Command,
|
||||||
|
Stdio,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut child = Command::new ("luac")
|
||||||
|
.arg ("-o") // Output to...
|
||||||
|
.arg ("-") // Standard output
|
||||||
|
.arg ("-") // Input from standard input
|
||||||
|
.stdin (Stdio::piped ())
|
||||||
|
.stdout (Stdio::piped ())
|
||||||
|
.spawn ()
|
||||||
|
.expect ("failed to execute `luac`. Is Lua installed?");
|
||||||
|
|
||||||
|
let mut stdin = child.stdin.take ().expect ("failed to get stdin");
|
||||||
|
std::thread::spawn (move || {
|
||||||
|
stdin.write_all (&source).expect ("failed to write to stdin");
|
||||||
|
});
|
||||||
|
|
||||||
|
let output = child
|
||||||
|
.wait_with_output ()
|
||||||
|
.expect ("failed to wait on child");
|
||||||
|
|
||||||
|
output.stdout.as_slice ().to_vec ()
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn bools () {
|
fn bools () {
|
||||||
/*
|
/*
|
||||||
|
@ -170,7 +203,12 @@ fn fma () {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_93 () {
|
fn is_93 () {
|
||||||
let bytecode = include_bytes! ("../test_vectors/is_93.luac");
|
let source = include_bytes! ("../test_vectors/is_93.lua");
|
||||||
|
assert_eq! (&blake3::hash (source).to_hex (), "a058869ed5142cbc8ccb2372991ef8b37657af38dc3f5e34814a7274b14d1e52");
|
||||||
|
|
||||||
|
let bytecode = compile_bytecode (source.to_vec ());
|
||||||
|
assert_eq! (&blake3::hash (&bytecode).to_hex (), "b59ce3e054500beb109c247e784cc4a0ff09ac42f8086dc5cdbf711bce1ba071");
|
||||||
|
|
||||||
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 ();
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
-- This one fails :( I haven't implemented closures properly yet.
|
||||||
|
|
||||||
local function add (aa, bb)
|
local function add (aa, bb)
|
||||||
return aa + bb
|
return aa + bb
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
|
||||||
|
main <test_vectors/fma.lua:0,0> (14 instructions at 0x55789d62dc90)
|
||||||
|
0+ params, 7 slots, 1 upvalue, 4 locals, 1 constant, 3 functions
|
||||||
|
1 [1] VARARGPREP 0
|
||||||
|
2 [3] CLOSURE 0 0 ; 0x55789d62de30
|
||||||
|
3 [7] CLOSURE 1 1 ; 0x55789d62df90
|
||||||
|
4 [11] CLOSURE 2 2 ; 0x55789d62e0f0
|
||||||
|
5 [13] MOVE 3 2
|
||||||
|
6 [13] LOADI 4 10
|
||||||
|
7 [13] LOADI 5 11
|
||||||
|
8 [13] LOADI 6 12
|
||||||
|
9 [13] CALL 3 4 2 ; 3 in 1 out
|
||||||
|
10 [14] GETTABUP 4 0 0 ; _ENV "print"
|
||||||
|
11 [14] MOVE 5 3
|
||||||
|
12 [14] CALL 4 2 1 ; 1 in 0 out
|
||||||
|
13 [15] RETURN 3 2 1k ; 1 out
|
||||||
|
14 [15] RETURN 4 1 1k ; 0 out
|
||||||
|
constants (1) for 0x55789d62dc90:
|
||||||
|
0 S "print"
|
||||||
|
locals (4) for 0x55789d62dc90:
|
||||||
|
0 add 3 15
|
||||||
|
1 mul 4 15
|
||||||
|
2 fma 5 15
|
||||||
|
3 hh 10 15
|
||||||
|
upvalues (1) for 0x55789d62dc90:
|
||||||
|
0 _ENV 1 0
|
||||||
|
|
||||||
|
function <test_vectors/fma.lua:1,3> (4 instructions at 0x55789d62de30)
|
||||||
|
2 params, 3 slots, 0 upvalues, 2 locals, 0 constants, 0 functions
|
||||||
|
1 [2] ADD 2 0 1
|
||||||
|
2 [2] MMBIN 0 1 6 ; __add
|
||||||
|
3 [2] RETURN1 2
|
||||||
|
4 [3] RETURN0
|
||||||
|
constants (0) for 0x55789d62de30:
|
||||||
|
locals (2) for 0x55789d62de30:
|
||||||
|
0 aa 1 5
|
||||||
|
1 bb 1 5
|
||||||
|
upvalues (0) for 0x55789d62de30:
|
||||||
|
|
||||||
|
function <test_vectors/fma.lua:5,7> (4 instructions at 0x55789d62df90)
|
||||||
|
2 params, 3 slots, 0 upvalues, 2 locals, 0 constants, 0 functions
|
||||||
|
1 [6] MUL 2 0 1
|
||||||
|
2 [6] MMBIN 0 1 8 ; __mul
|
||||||
|
3 [6] RETURN1 2
|
||||||
|
4 [7] RETURN0
|
||||||
|
constants (0) for 0x55789d62df90:
|
||||||
|
locals (2) for 0x55789d62df90:
|
||||||
|
0 cc 1 5
|
||||||
|
1 dd 1 5
|
||||||
|
upvalues (0) for 0x55789d62df90:
|
||||||
|
|
||||||
|
function <test_vectors/fma.lua:9,11> (9 instructions at 0x55789d62e0f0)
|
||||||
|
3 params, 7 slots, 2 upvalues, 3 locals, 0 constants, 0 functions
|
||||||
|
1 [10] GETUPVAL 3 0 ; add
|
||||||
|
2 [10] GETUPVAL 4 1 ; mul
|
||||||
|
3 [10] MOVE 5 0
|
||||||
|
4 [10] MOVE 6 1
|
||||||
|
5 [10] CALL 4 3 2 ; 2 in 1 out
|
||||||
|
6 [10] MOVE 5 2
|
||||||
|
7 [10] TAILCALL 3 3 0 ; 2 in
|
||||||
|
8 [10] RETURN 3 0 0 ; all out
|
||||||
|
9 [11] RETURN0
|
||||||
|
constants (0) for 0x55789d62e0f0:
|
||||||
|
locals (3) for 0x55789d62e0f0:
|
||||||
|
0 ee 1 10
|
||||||
|
1 ff 1 10
|
||||||
|
2 gg 1 10
|
||||||
|
upvalues (2) for 0x55789d62e0f0:
|
||||||
|
0 add 1 0
|
||||||
|
1 mul 1 1
|
Binary file not shown.
|
@ -2,4 +2,5 @@ local function add (a, b)
|
||||||
return a + b
|
return a + b
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
print (("1 + 2 = %i"):format (add (1, 2)))
|
print (("1 + 2 = %i"):format (add (1, 2)))
|
||||||
|
|
Loading…
Reference in New Issue