lunar_wave/src/main.rs

64 lines
1.2 KiB
Rust
Raw Normal View History

mod loader;
mod state;
2023-09-24 21:34:28 +00:00
#[cfg (test)]
mod tests;
2023-09-24 21:34:28 +00:00
fn main() {
2023-09-25 00:47:17 +00:00
use state::{
Block,
Chunk,
Instruction as Inst,
State,
};
2023-09-25 00:47:17 +00:00
let chunk = Chunk {
blocks: vec! [
Block {
instructions: vec! [
Inst::VarArgPrep (0),
Inst::Closure (0, 0),
Inst::Move (1, 0),
Inst::Call (1, 1, 2),
2023-09-25 00:47:17 +00:00
Inst::GetTabUp (2, 0, 0),
Inst::Move (3, 1),
Inst::Call (3, 1, 0),
Inst::Call (2, 0, 1),
Inst::Return (2, 1, 1, false),
2023-09-25 00:47:17 +00:00
],
constants: vec! [
"print".into (),
],
upvalue_count: 1,
},
Block {
instructions: vec! [
Inst::LoadI (0, 5),
Inst::Closure (1, 0),
Inst::Return (1, 2, 0, true), // k?
Inst::Return (1, 1, 0, true), // k?
],
constants: vec! [],
upvalue_count: 0,
2023-09-25 00:47:17 +00:00
},
Block {
instructions: vec! [
Inst::GetUpVal (0, 0),
Inst::Return1 (0),
2023-09-25 00:47:17 +00:00
Inst::Return0,
],
constants: vec! [],
upvalue_count: 1,
2023-09-25 00:47:17 +00:00
},
2023-09-24 22:34:38 +00:00
],
};
let mut vm = State::default ();
2023-09-25 00:47:17 +00:00
if std::env::var("LUA_DEBUG").is_ok() {
vm.debug_print = true;
}
let upvalues = State::upvalues_from_args (std::env::args ());
2023-09-24 21:57:12 +00:00
println! ("Returned: {:?}", vm.execute_chunk (&chunk, &upvalues));
}