56 lines
1.1 KiB
Rust
56 lines
1.1 KiB
Rust
mod repl;
|
|
mod run;
|
|
|
|
use crate::repl::repl;
|
|
use crate::run::compile_and_run_script;
|
|
use clap::{Parser, Subcommand};
|
|
use std::io;
|
|
use std::path::PathBuf;
|
|
|
|
#[derive(Debug, Parser)]
|
|
#[command(name = "dm", about = "Deimos", version = "0.1.0", long_about = None)]
|
|
struct Cli {
|
|
#[command(subcommand)]
|
|
sub_command: SubCommand,
|
|
}
|
|
|
|
#[derive(Debug, Subcommand)]
|
|
enum SubCommand {
|
|
Run {
|
|
script: PathBuf,
|
|
|
|
#[arg(long)]
|
|
show_asm: bool,
|
|
|
|
#[arg(long)]
|
|
show_ir: bool,
|
|
},
|
|
Repl,
|
|
}
|
|
|
|
fn main() {
|
|
let register_count = std::env::var("DVM_REGISTER_COUNT")
|
|
.map(|v| v.parse::<usize>())
|
|
.unwrap_or(Ok(8))
|
|
.unwrap();
|
|
|
|
let args = Cli::parse();
|
|
match &args.sub_command {
|
|
SubCommand::Run {
|
|
script,
|
|
show_asm,
|
|
show_ir,
|
|
} => {
|
|
compile_and_run_script(script, *show_asm, *show_ir, register_count);
|
|
}
|
|
SubCommand::Repl => {
|
|
repl(
|
|
&mut io::stdin().lock(),
|
|
&mut io::stdout().lock(),
|
|
&mut io::stderr().lock(),
|
|
register_count,
|
|
);
|
|
}
|
|
}
|
|
}
|