pub mod bfic;
pub mod celltype;
pub mod interp;
mod error;
pub use bfic::BfCode;
pub use celltype::*;
pub use interp::{eval_file, eval_string};
pub use interp::{BfFrame, BfVm};
pub use error::*;
use clap::*;
use std::process::ExitCode;
#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
struct Args {
#[clap(subcommand)]
command: Commands,
}
#[derive(Subcommand, Debug)]
enum Commands {
Run {
#[clap(flatten)]
mode: RunMode,
#[clap(required(true))]
file_or_string: String,
#[clap(short, long, default_value_t = 30000)]
size: usize,
#[clap(short, long, default_value_t = 0)]
ptr: usize,
},
}
#[derive(Args, Debug)]
#[group(required = false, multiple = false)]
struct RunMode {
#[clap(long)]
file: bool,
#[clap(long)]
string: bool,
}
pub fn main_func() -> ExitCode {
let command = Args::parse().command;
let err = match command {
Commands::Run {
mode:
RunMode {
file: _, string: false,
},
file_or_string,
size,
ptr,
} => interp::eval_file(file_or_string, size, ptr),
Commands::Run {
mode: RunMode {
file: false,
string: true,
},
file_or_string,
size,
ptr,
} => interp::eval_string(file_or_string, size, ptr),
Commands::Run { .. } => unreachable!(),
};
if let Err(e) = err {
eprintln!("{e}");
ExitCode::FAILURE
} else {
ExitCode::SUCCESS
}
}