From a89d6c82e981fec7d6e4c975e083d2b9e04467ad Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Mon, 1 May 2023 07:56:42 -0700 Subject: Rewrite most of the compiler. This represents a major step back in terms of functionality, and amount of code. The latter I think constitutes a major win. Next steps are to reimplement syntax-rules, call/cc, and call-with-values. --- bytecode/src/main.rs | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'bytecode/src/main.rs') diff --git a/bytecode/src/main.rs b/bytecode/src/main.rs index 8315d5a..89e205a 100644 --- a/bytecode/src/main.rs +++ b/bytecode/src/main.rs @@ -3,8 +3,42 @@ mod data; mod encoding; mod heap; +use std::fs::File; + +fn usage() { + println!("Usage: bytecode "); +} + fn main() { - let prog = encoding::decode(&mut std::io::stdin().lock()).unwrap(); - let exit_code = bytecode::eval(&prog).unwrap(); + let filepath = match std::env::args().nth(1) { + Some(x) => x, + None => { + usage(); + std::process::exit(255); + } + }; + let prog = { + let mut file = match File::open(filepath) { + Ok(x) => x, + Err(err) => { + println!("Can't open file for reading: {}", err); + std::process::exit(255); + } + }; + match encoding::decode(&mut file) { + Ok(x) => x, + Err(err) => { + println!("Invalid bytecode: {}", err); + std::process::exit(255); + } + } + }; + let exit_code = match bytecode::eval(&prog) { + Ok(x) => x, + Err(err) => { + println!("{}", err); + std::process::exit(255); + } + }; std::process::exit(i32::from(exit_code)); } -- cgit v1.3.1