bfy/src/main.rs

51 lines
1.5 KiB
Rust
Raw Normal View History

2022-10-07 18:17:21 +00:00
mod arguments;
2022-10-07 22:28:14 +00:00
mod repl;
2022-10-07 23:06:35 +00:00
mod utils;
2022-10-08 10:01:28 +00:00
mod bf_interpreter;
2022-10-07 18:17:21 +00:00
use clap::Parser;
extern crate pretty_env_logger;
#[macro_use]
extern crate log;
2022-10-07 18:17:21 +00:00
use arguments::Args;
2022-10-08 10:01:28 +00:00
use bf_interpreter::interpreter::Interpreter;
2022-10-07 18:17:21 +00:00
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-08 10:01:28 +00:00
info!("Initializing bf_interpreter");
let mut interpreter = Interpreter::new(
2022-10-07 19:54:49 +00:00
args.array_size,
2022-10-07 23:06:35 +00:00
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-10 20:55:50 +00:00
match interpreter.run(utils::read_brainfuck_code(&source)) {
2022-10-07 22:28:14 +00:00
Ok(exit_code) => {
2022-10-08 07:35:40 +00:00
info!("Finished running brainfuck source code from file: {}", source);
if !args.without_tiles {
println!(
"Successfully ran brainfuck source code from file: {}",
source
);
println!("Exiting with code: {exit_code}");
std::process::exit(0);
}
2022-10-07 22:28:14 +00:00
}
2022-10-07 23:05:21 +00:00
Err(e) => {
2022-10-07 22:28:14 +00:00
error!("Failed to run brainfuck source code from file: {}", e);
2022-10-07 23:05:21 +00:00
std::process::exit(e.code);
2022-10-07 19:54:49 +00:00
}
}
}
2022-10-07 23:06:35 +00:00
None => repl::start(interpreter),
2022-10-07 18:17:21 +00:00
}
}