Implementation of the UM-32 "Universal Machine" as described by the Cult of the Bound Variable

feature gate the assembler

tjh 2b7cfbac 2bc3488f

Changed files
+23 -2
src
+8 -1
Cargo.toml
··· 9 9 10 10 [dependencies] 11 11 smallvec = { version = "1.13.2" } 12 - logos = { version = "0.14.2" } 12 + logos = { version = "0.14.2", optional = true } 13 13 14 14 [features] 15 15 default = [] 16 + asm = ["dep:logos"] 16 17 17 18 [profile.release] 18 19 lto = "fat" 19 20 codegen-units = 1 21 + 22 + 23 + [[bin]] 24 + name = "uasm" 25 + path = "src/bin/uasm.rs" 26 + required-features = ["asm"]
+1 -1
deny.toml
··· 1 1 [graph] 2 - all-features = false 2 + all-features = true 3 3 no-default-features = false 4 4 5 5 [output]
+11
src/bin/um.rs
··· 46 46 } 47 47 } 48 48 49 + #[cfg(feature = "asm")] 49 50 fn load_program(path: &Path) -> std::io::Result<Vec<u32>> { 50 51 match path.extension().map(|ext| ext.as_encoded_bytes()) { 52 + // In an ideal world we would just add `#[cfg(feature = "asm")]` here. 53 + // Unfortunately this leads some wierd code generation fuckery which 54 + // makes the version without the 'asm' feature ~1-2 seconds slower 55 + // when running the sandmark program. 51 56 Some(b"uasm") | Some(b"asm") => { 52 57 let source = std::fs::read_to_string(path)?; 53 58 Ok(um::asm::assemble(&source)) ··· 58 63 } 59 64 } 60 65 } 66 + 67 + #[cfg(not(feature = "asm"))] 68 + fn load_program(path: &Path) -> std::io::Result<Vec<u32>> { 69 + let program = std::fs::read(path)?; 70 + Ok(um::conv::bytes_to_program(&program).unwrap()) 71 + }
+3
src/lib.rs
··· 15 15 use smallvec::SmallVec; 16 16 use std::io::{Read, Write}; 17 17 18 + #[cfg(feature = "asm")] 18 19 pub mod asm; 19 20 pub mod conv; 20 21 pub mod ops; ··· 324 325 } 325 326 326 327 #[test] 328 + #[cfg(feature = "asm")] 327 329 fn hello_world() { 328 330 let program = asm::assemble(include_str!("../files/hello-world.asm")); 329 331 let mut buffer = Vec::new(); ··· 332 334 } 333 335 334 336 #[test] 337 + #[cfg(feature = "asm")] 335 338 fn cat() { 336 339 let program = asm::assemble(include_str!("../files/cat.asm")); 337 340 let input = include_bytes!("lib.rs");