holey-bytes/hblang/src/main.rs

32 lines
1.1 KiB
Rust
Raw Normal View History

2024-09-30 12:09:17 -05:00
#[cfg(feature = "std")]
2024-06-01 13:30:07 -05:00
fn main() -> std::io::Result<()> {
2024-09-30 12:09:17 -05:00
use std::{io::Write, num::NonZeroUsize};
2024-06-25 14:41:12 -05:00
let args = std::env::args().collect::<Vec<_>>();
let args = args.iter().map(String::as_str).collect::<Vec<_>>();
2024-05-12 17:02:32 -05:00
2024-06-25 14:41:12 -05:00
if args.contains(&"--help") || args.contains(&"-h") {
println!("Usage: hbc [OPTIONS...] <FILE>");
println!(include_str!("../command-help.txt"));
return Err(std::io::ErrorKind::Other.into());
}
2024-05-12 17:02:32 -05:00
2024-09-30 12:09:17 -05:00
let mut out = Vec::new();
2024-07-06 07:58:50 -05:00
hblang::run_compiler(
2024-09-28 09:28:05 -05:00
args.iter().filter(|a| !a.starts_with('-')).nth(1).copied().unwrap_or("main.hb"),
2024-07-06 07:58:50 -05:00
hblang::Options {
2024-07-08 00:22:53 -05:00
fmt: args.contains(&"--fmt"),
fmt_stdout: args.contains(&"--fmt-stdout"),
2024-09-04 10:56:59 -05:00
dump_asm: args.contains(&"--dump-asm"),
2024-07-08 04:00:35 -05:00
extra_threads: args
.iter()
.position(|&a| a == "--threads")
.map(|i| args[i + 1].parse::<NonZeroUsize>().expect("--threads expects integer"))
.map_or(1, NonZeroUsize::get)
- 1,
2024-07-06 07:58:50 -05:00
},
2024-09-30 12:09:17 -05:00
&mut out,
)?;
std::io::stdout().write_all(&out)
2024-05-12 17:02:32 -05:00
}