diff --git a/Cargo.lock b/Cargo.lock index 93d6461..66640e1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,60 +3,12 @@ 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" +name = "lunar_wave_cli" +version = "0.1.0" dependencies = [ - "arrayref", - "arrayvec", - "cc", - "cfg-if", - "constant_time_eq", + "lunar_wave_vm", ] -[[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]] name = "lunar_wave_vm" version = "0.1.0" -dependencies = [ - "blake3", -] diff --git a/Cargo.toml b/Cargo.toml index 62cc3b1..e7d464b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,21 +1,5 @@ -[package] -name = "lunar_wave_vm" -description = "A Lua virtual machine implementation" -version = "0.1.0" -edition = "2021" - -[dependencies] - -[dev-dependencies] - -# blake3, used to hash test vectors -blake3 = "1.5.0" - -[target.x86_64-unknown-linux-gnu] -linker = "/usr/bin/clang" -# Recommended for flamegraph -rustflags = ["-Clink-arg=-fuse-ld=lld", "-Clink-arg=-Wl,--no-rosegment"] - -[profile.release] -# Recommended for profiling, e.g. flamegraph -debug = true +[workspace] +members = [ + "lunar_wave_cli", + "lunar_wave_vm", +] diff --git a/examples/embedding.rs b/examples/embedding.rs new file mode 100644 index 0000000..4f1f8e2 --- /dev/null +++ b/examples/embedding.rs @@ -0,0 +1,5 @@ +fn main () -> Result <(), ()> { + println! ("Embedding"); + + Ok (()) +} diff --git a/lunar_wave_cli/Cargo.toml b/lunar_wave_cli/Cargo.toml new file mode 100644 index 0000000..d071eb1 --- /dev/null +++ b/lunar_wave_cli/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "lunar_wave_cli" +description = "A Lua CLI implementation" +version = "0.1.0" +edition = "2021" +author = "ReactorScram" + +[dependencies] +lunar_wave_vm = { path = "../lunar_wave_vm" } + +[target.x86_64-unknown-linux-gnu] +linker = "/usr/bin/clang" +# Recommended for flamegraph +rustflags = ["-Clink-arg=-fuse-ld=lld", "-Clink-arg=-Wl,--no-rosegment"] + +[profile.release] +# Recommended for profiling, e.g. flamegraph +debug = true diff --git a/src/main.rs b/lunar_wave_cli/src/main.rs similarity index 76% rename from src/main.rs rename to lunar_wave_cli/src/main.rs index c6182e7..e983175 100644 --- a/src/main.rs +++ b/lunar_wave_cli/src/main.rs @@ -1,16 +1,8 @@ -// cargo run -- --script test_vectors/fizz_buzz.lua +// cargo run -- --script lunar_wave_vm/test_vectors/fizz_buzz.lua -mod instruction; -mod loader; -mod state; -mod value; +use lunar_wave_vm as lwvm; -#[cfg (test)] -mod tests; - -fn main () -> Result <(), state::StepError> { - use state::State; - +fn main () -> Result <(), lwvm::StepError> { let mut list_bytecode = false; let mut pipe_bytecode = false; let mut script = None; @@ -27,7 +19,7 @@ fn main () -> Result <(), state::StepError> { let block_idx = str::parse (block_idx).unwrap (); let program_counter = str::parse (program_counter).unwrap (); - breakpoints.push (state::Breakpoint { + breakpoints.push (lwvm::Breakpoint { block_idx, program_counter, }); @@ -41,13 +33,13 @@ fn main () -> Result <(), state::StepError> { } let chunk = if let Some (script) = script { - let bytecode = loader::compile_bytecode_from_file (&script); + let bytecode = lwvm::compile_bytecode_from_file (&script); let mut rdr = std::io::Cursor::new (bytecode); - loader::parse_chunk (&mut rdr).unwrap () + lwvm::parse_chunk (&mut rdr).unwrap () } else if pipe_bytecode { let mut stdin = std::io::stdin ().lock (); - loader::parse_chunk (&mut stdin).unwrap () + lwvm::parse_chunk (&mut stdin).unwrap () } else { unimplemented!(); @@ -57,9 +49,9 @@ fn main () -> Result <(), state::StepError> { dbg! (&chunk); } - let upvalues = State::upvalues_from_args ([exe_name].into_iter ().chain (args)); + let upvalues = lwvm::State::upvalues_from_args ([exe_name].into_iter ().chain (args)); - let mut vm = State::new (&chunk, &upvalues); + let mut vm = lwvm::State::new (&chunk, &upvalues); if std::env::var("LWVM_DEBUG").is_ok() { vm.debug_print = true; } @@ -93,7 +85,7 @@ fn main () -> Result <(), state::StepError> { "s" => { match vm.step ()? { None => (), - Some (state::StepOutput::ChunkReturned (x)) => { + Some (lwvm::StepOutput::ChunkReturned (x)) => { dbg! (x); return Ok (()); }, @@ -106,7 +98,7 @@ fn main () -> Result <(), state::StepError> { match vm.step ()? { None => (), - Some (state::StepOutput::ChunkReturned (x)) => { + Some (lwvm::StepOutput::ChunkReturned (x)) => { dbg! (x); return Ok (()); }, diff --git a/lunar_wave_vm/Cargo.toml b/lunar_wave_vm/Cargo.toml new file mode 100644 index 0000000..cbc609a --- /dev/null +++ b/lunar_wave_vm/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "lunar_wave_vm" +description = "A Lua virtual machine implementation" +version = "0.1.0" +edition = "2021" +author = "ReactorScram" diff --git a/src/instruction.rs b/lunar_wave_vm/src/instruction.rs similarity index 100% rename from src/instruction.rs rename to lunar_wave_vm/src/instruction.rs diff --git a/lunar_wave_vm/src/lib.rs b/lunar_wave_vm/src/lib.rs new file mode 100644 index 0000000..b180ef1 --- /dev/null +++ b/lunar_wave_vm/src/lib.rs @@ -0,0 +1,14 @@ +mod instruction; +mod loader; +mod state; +mod value; + +pub use loader::compile_bytecode_from_file as compile_bytecode_from_file; +pub use loader::parse_chunk as parse_chunk; +pub use state::Breakpoint as Breakpoint; +pub use state::State as State; +pub use state::StepError as StepError; +pub use state::StepOutput as StepOutput; + +#[cfg (test)] +mod tests; diff --git a/src/loader.rs b/lunar_wave_vm/src/loader.rs similarity index 99% rename from src/loader.rs rename to lunar_wave_vm/src/loader.rs index 8b1ead7..8a55acb 100644 --- a/src/loader.rs +++ b/lunar_wave_vm/src/loader.rs @@ -8,7 +8,7 @@ use crate::{ } }; -pub (crate) fn compile_bytecode_from_file (path: &str) -> Vec { +pub fn compile_bytecode_from_file (path: &str) -> Vec { use std::{ process::{ Command, diff --git a/src/state.rs b/lunar_wave_vm/src/state.rs similarity index 100% rename from src/state.rs rename to lunar_wave_vm/src/state.rs diff --git a/src/tests.rs b/lunar_wave_vm/src/tests.rs similarity index 100% rename from src/tests.rs rename to lunar_wave_vm/src/tests.rs diff --git a/src/value.rs b/lunar_wave_vm/src/value.rs similarity index 100% rename from src/value.rs rename to lunar_wave_vm/src/value.rs diff --git a/test_vectors/bools.lua b/lunar_wave_vm/test_vectors/bools.lua similarity index 100% rename from test_vectors/bools.lua rename to lunar_wave_vm/test_vectors/bools.lua diff --git a/test_vectors/bools.luac b/lunar_wave_vm/test_vectors/bools.luac similarity index 100% rename from test_vectors/bools.luac rename to lunar_wave_vm/test_vectors/bools.luac diff --git a/test_vectors/closure.lua b/lunar_wave_vm/test_vectors/closure.lua similarity index 100% rename from test_vectors/closure.lua rename to lunar_wave_vm/test_vectors/closure.lua diff --git a/test_vectors/combined.luac b/lunar_wave_vm/test_vectors/combined.luac similarity index 100% rename from test_vectors/combined.luac rename to lunar_wave_vm/test_vectors/combined.luac diff --git a/test_vectors/error.lua b/lunar_wave_vm/test_vectors/error.lua similarity index 100% rename from test_vectors/error.lua rename to lunar_wave_vm/test_vectors/error.lua diff --git a/test_vectors/error.luac b/lunar_wave_vm/test_vectors/error.luac similarity index 100% rename from test_vectors/error.luac rename to lunar_wave_vm/test_vectors/error.luac diff --git a/test_vectors/fizz_buzz.lua b/lunar_wave_vm/test_vectors/fizz_buzz.lua similarity index 100% rename from test_vectors/fizz_buzz.lua rename to lunar_wave_vm/test_vectors/fizz_buzz.lua diff --git a/test_vectors/floats.lua b/lunar_wave_vm/test_vectors/floats.lua similarity index 100% rename from test_vectors/floats.lua rename to lunar_wave_vm/test_vectors/floats.lua diff --git a/test_vectors/fma.lua b/lunar_wave_vm/test_vectors/fma.lua similarity index 100% rename from test_vectors/fma.lua rename to lunar_wave_vm/test_vectors/fma.lua diff --git a/test_vectors/functions.lua b/lunar_wave_vm/test_vectors/functions.lua similarity index 100% rename from test_vectors/functions.lua rename to lunar_wave_vm/test_vectors/functions.lua diff --git a/test_vectors/functions.luac b/lunar_wave_vm/test_vectors/functions.luac similarity index 100% rename from test_vectors/functions.luac rename to lunar_wave_vm/test_vectors/functions.luac diff --git a/test_vectors/functions.txt b/lunar_wave_vm/test_vectors/functions.txt similarity index 100% rename from test_vectors/functions.txt rename to lunar_wave_vm/test_vectors/functions.txt diff --git a/test_vectors/hello.lua b/lunar_wave_vm/test_vectors/hello.lua similarity index 100% rename from test_vectors/hello.lua rename to lunar_wave_vm/test_vectors/hello.lua diff --git a/test_vectors/hello.txt b/lunar_wave_vm/test_vectors/hello.txt similarity index 100% rename from test_vectors/hello.txt rename to lunar_wave_vm/test_vectors/hello.txt diff --git a/test_vectors/long_named_file.lua b/lunar_wave_vm/test_vectors/long_named_file.lua similarity index 100% rename from test_vectors/long_named_file.lua rename to lunar_wave_vm/test_vectors/long_named_file.lua diff --git a/test_vectors/long_named_file.luac b/lunar_wave_vm/test_vectors/long_named_file.luac similarity index 100% rename from test_vectors/long_named_file.luac rename to lunar_wave_vm/test_vectors/long_named_file.luac diff --git a/test_vectors/math.lua b/lunar_wave_vm/test_vectors/math.lua similarity index 100% rename from test_vectors/math.lua rename to lunar_wave_vm/test_vectors/math.lua diff --git a/test_vectors/math.luac b/lunar_wave_vm/test_vectors/math.luac similarity index 100% rename from test_vectors/math.luac rename to lunar_wave_vm/test_vectors/math.luac diff --git a/test_vectors/math_2.lua b/lunar_wave_vm/test_vectors/math_2.lua similarity index 100% rename from test_vectors/math_2.lua rename to lunar_wave_vm/test_vectors/math_2.lua diff --git a/test_vectors/math_2.luac b/lunar_wave_vm/test_vectors/math_2.luac similarity index 100% rename from test_vectors/math_2.luac rename to lunar_wave_vm/test_vectors/math_2.luac diff --git a/test_vectors/n_body.lua b/lunar_wave_vm/test_vectors/n_body.lua similarity index 100% rename from test_vectors/n_body.lua rename to lunar_wave_vm/test_vectors/n_body.lua diff --git a/test_vectors/n_body_new_stuff.lua b/lunar_wave_vm/test_vectors/n_body_new_stuff.lua similarity index 100% rename from test_vectors/n_body_new_stuff.lua rename to lunar_wave_vm/test_vectors/n_body_new_stuff.lua diff --git a/test_vectors/varint.lua b/lunar_wave_vm/test_vectors/varint.lua similarity index 100% rename from test_vectors/varint.lua rename to lunar_wave_vm/test_vectors/varint.lua