bfy/src/main.rs

65 lines
2 KiB
Rust
Raw Normal View History

2022-10-07 18:17:21 +00:00
mod arguments;
2022-10-12 16:59:12 +00:00
mod bf_interpreter;
2022-10-07 22:28:14 +00:00
mod repl;
2022-10-07 23:06:35 +00:00
mod utils;
2022-10-12 16:56:26 +00:00
2022-10-07 18:17:21 +00:00
use clap::Parser;
extern crate pretty_env_logger;
#[macro_use]
extern crate log;
2022-10-12 11:50:22 +00:00
use colored::Colorize;
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-12 11:50:22 +00:00
info!("Initializing interpreter");
let mut interpreter = Interpreter::new(
args.array_size,
args.features.unwrap_or_else(|| vec![]),
2022-10-13 16:47:28 +00:00
console::Term::stdout(),
);
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-12 16:59:12 +00:00
info!(
"Finished running brainfuck source code from file: {}",
source
);
2022-10-08 07:35:40 +00:00
if !args.without_tiles {
2022-10-12 16:59:12 +00:00
println!(
"{}",
format!(
2022-10-13 16:47:28 +00:00
"Successfully run brainfuck source code from file: {}",
2022-10-12 16:59:12 +00:00
source
)
.bold()
.green()
);
println!(
"{}{}",
"Exiting with code: ".truecolor(33, 97, 61),
exit_code.to_string().bold().green()
);
2022-10-12 16:31:07 +00:00
std::process::exit(exit_code);
2022-10-08 07:35:40 +00:00
}
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
}
}
}
None => repl::start_repl::start(interpreter),
2022-10-07 18:17:21 +00:00
}
}