From d9bba9fc07f2b67b01bc73466de69eb0f7975d18 Mon Sep 17 00:00:00 2001 From: _ <_@_> Date: Wed, 27 Sep 2023 14:12:29 -0500 Subject: [PATCH] :pencil: doc: make it obvious that LWVM only handles bytecode for now --- README.md | 2 +- src/main.rs | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cb0edf4..2001e19 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ LunarWaveVM is a Lua 5.4 virtual machine written in Rust. LunarWaveVM relies on the PUC-Rio implementation of `luac` to compile bytecode. -`cargo run -- --script test_vectors/fizz_buzz.lua` +`luac5.4 -o - test_vectors/fizz_buzz.lua | cargo run -- --pipe-bytecode` ``` 1 diff --git a/src/main.rs b/src/main.rs index bcac3d4..f007ec5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,24 +11,33 @@ mod tests; fn main () { use state::State; - let mut script = String::from ("test_vectors/hello.lua"); + let mut pipe_bytecode = false; + let mut script = None; let mut args = std::env::args (); let exe_name = args.next ().unwrap (); while let Some (arg) = args.next () { match arg.as_str () { - "--script" => script = args.next ().unwrap (), + "--pipe-bytecode" => pipe_bytecode = true, + "--script" => script = Some (args.next ().unwrap ()), "--" => break, _ => panic! ("can't parse args"), } } - let lua_file = { + let lua_file = if let Some (script) = script { let source = std::fs::read (script).expect ("couldn't load Lua source code"); let bytecode = loader::compile_bytecode(source); let mut rdr = std::io::Cursor::new (bytecode); loader::parse_chunk (&mut rdr).unwrap () + } + else if pipe_bytecode { + let mut stdin = std::io::stdin ().lock (); + loader::parse_chunk (&mut stdin).unwrap () + } + else { + unimplemented!(); }; let mut vm = State::default ();