aboutsummaryrefslogtreecommitdiffstats
path: root/bytecode/src/main.rs
diff options
context:
space:
mode:
authorRose Hogenson <rhogenson@posteo.net>2023-05-01 07:56:42 -0700
committerRose Hogenson <rhogenson@posteo.net>2023-05-01 07:56:42 -0700
commita89d6c82e981fec7d6e4c975e083d2b9e04467ad (patch)
treed5445ceb797473dd45ac006c337d990e5dd6f0d4 /bytecode/src/main.rs
parent112ce5291da35e54c38c4ff1d7a2408a64a98e71 (diff)
downloadchromatopelma-a89d6c82e981fec7d6e4c975e083d2b9e04467ad.tar.zst
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.
Diffstat (limited to 'bytecode/src/main.rs')
-rw-r--r--bytecode/src/main.rs38
1 files changed, 36 insertions, 2 deletions
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 <file>");
+}
+
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));
}