bfy/src/main.rs

49 lines
1.3 KiB
Rust
Raw Normal View History

2022-10-07 18:17:21 +00:00
mod arguments;
mod interpreter;
2022-10-07 19:54:49 +00:00
mod utils;
2022-10-07 22:28:14 +00:00
mod repl;
2022-10-07 18:17:21 +00:00
use clap::Parser;
2022-10-07 18:17:21 +00:00
extern crate pretty_env_logger;
#[macro_use]
extern crate log;
2022-10-07 18:17:21 +00:00
use arguments::Args;
fn main() {
pretty_env_logger::init();
info!("Initialized logger");
info!("Parsing command line arguments");
let args = Args::parse();
info!("Parsed command line arguments: {:?}", args);
2022-10-07 19:54:49 +00:00
info!("Initializing interpreter");
let mut interpreter = interpreter::Interpreter::new(
args.array_size,
2022-10-07 22:28:14 +00:00
utils::read_brainfuck_code_if_any(&args.source),
args.features.unwrap_or_else(|| vec![])
);
2022-10-07 19:54:49 +00:00
2022-10-07 18:17:21 +00:00
match args.source {
Some(source) => {
info!("Running brainfuck source code from file: {}", source);
2022-10-07 22:28:14 +00:00
match interpreter.run(None) {
Ok(exit_code) => {
println!("Successfully ran brainfuck source code from file: {}", source);
println!("Exiting with code: {exit_code}");
std::process::exit(0);
}
Err((e, code)) => {
error!("Failed to run brainfuck source code from file: {}", e);
std::process::exit(code);
2022-10-07 19:54:49 +00:00
}
}
}
2022-10-07 22:28:14 +00:00
None => {
repl::start(interpreter)
2022-10-07 18:17:21 +00:00
}
}
}
2022-10-07 22:28:14 +00:00