♻️ refactor: split up the VM from the CLI program
							parent
							
								
									51b04be1ab
								
							
						
					
					
						commit
						ffb1950f80
					
				|  | @ -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", | ||||
| ] | ||||
|  |  | |||
							
								
								
									
										26
									
								
								Cargo.toml
								
								
								
								
							
							
						
						
									
										26
									
								
								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", | ||||
| ] | ||||
|  |  | |||
|  | @ -0,0 +1,5 @@ | |||
| fn main () -> Result <(), ()> { | ||||
| 	println! ("Embedding"); | ||||
| 	
 | ||||
| 	Ok (()) | ||||
| } | ||||
|  | @ -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 | ||||
|  | @ -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 (()); | ||||
| 			}, | ||||
|  | @ -0,0 +1,6 @@ | |||
| [package] | ||||
| name = "lunar_wave_vm" | ||||
| description = "A Lua virtual machine implementation" | ||||
| version = "0.1.0" | ||||
| edition = "2021" | ||||
| author = "ReactorScram" | ||||
|  | @ -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; | ||||
|  | @ -8,7 +8,7 @@ use crate::{ | |||
| 	} | ||||
| }; | ||||
| 
 | ||||
| pub (crate) fn compile_bytecode_from_file (path: &str) -> Vec <u8> { | ||||
| pub fn compile_bytecode_from_file (path: &str) -> Vec <u8> { | ||||
| 	use std::{ | ||||
| 		process::{ | ||||
| 			Command, | ||||
		Loading…
	
		Reference in New Issue
	
	 _
						_