2024-09-30 12:09:17 -05:00
|
|
|
#[cfg(feature = "std")]
|
2024-11-08 01:36:00 -06:00
|
|
|
fn main() {
|
2024-11-30 11:57:29 -06:00
|
|
|
use std::{
|
|
|
|
io::Write,
|
|
|
|
path::{Path, PathBuf},
|
|
|
|
};
|
|
|
|
|
|
|
|
static ABLEOS_PATH_RESOLVER: hblang::PathResolver =
|
|
|
|
&|mut path: &str, mut from: &str, tmp: &mut PathBuf| {
|
|
|
|
tmp.clear();
|
|
|
|
|
|
|
|
path = match path {
|
|
|
|
"stn" => {
|
|
|
|
from = "";
|
|
|
|
"./sysdata/libraries/stn/src/lib.hb"
|
|
|
|
}
|
|
|
|
_ => path,
|
|
|
|
};
|
|
|
|
|
|
|
|
match path.split_once(':') {
|
|
|
|
Some(("lib", p)) => tmp.extend(["./sysdata/libraries", p, "src/lib.hb"]),
|
|
|
|
Some(("stn", p)) => {
|
|
|
|
tmp.extend(["./sysdata/libraries/stn/src", &(p.to_owned() + ".hb")])
|
|
|
|
}
|
|
|
|
Some(("sysdata", p)) => tmp.extend(["./sysdata", p]),
|
|
|
|
None => match Path::new(from).parent() {
|
|
|
|
Some(parent) => tmp.extend([parent, Path::new(path)]),
|
|
|
|
None => tmp.push(path),
|
|
|
|
},
|
|
|
|
_ => panic!("path: '{path}' is invalid: unexpected ':'"),
|
|
|
|
};
|
|
|
|
tmp.canonicalize()
|
|
|
|
.map_err(|source| hblang::CantLoadFile { path: std::mem::take(tmp), source })
|
|
|
|
};
|
2024-09-30 12:09:17 -05:00
|
|
|
|
2024-11-17 11:15:58 -06:00
|
|
|
fn run(out: &mut Vec<u8>, warnings: &mut String) -> std::io::Result<()> {
|
2024-11-08 01:36:00 -06:00
|
|
|
let args = std::env::args().collect::<Vec<_>>();
|
|
|
|
let args = args.iter().map(String::as_str).collect::<Vec<_>>();
|
2024-11-30 11:57:29 -06:00
|
|
|
let resolvers = &[("ableos", ABLEOS_PATH_RESOLVER)];
|
|
|
|
let opts = hblang::Options::from_args(&args, out, resolvers)?;
|
2024-11-08 01:36:00 -06:00
|
|
|
let file = args.iter().filter(|a| !a.starts_with('-')).nth(1).copied().unwrap_or("main.hb");
|
2024-09-30 14:55:34 -05:00
|
|
|
|
2024-11-17 11:15:58 -06:00
|
|
|
hblang::run_compiler(file, opts, out, warnings)
|
2024-11-08 01:36:00 -06:00
|
|
|
}
|
2024-05-12 17:02:32 -05:00
|
|
|
|
2024-11-08 01:40:14 -06:00
|
|
|
log::set_logger(&hblang::fs::Logger).unwrap();
|
|
|
|
log::set_max_level(log::LevelFilter::Error);
|
|
|
|
|
2024-09-30 12:09:17 -05:00
|
|
|
let mut out = Vec::new();
|
2024-11-17 11:15:58 -06:00
|
|
|
let mut warnings = String::new();
|
|
|
|
match run(&mut out, &mut warnings) {
|
|
|
|
Ok(_) => {
|
|
|
|
std::io::stderr().write_all(warnings.as_bytes()).unwrap();
|
|
|
|
std::io::stdout().write_all(&out).unwrap()
|
|
|
|
}
|
2024-11-08 14:53:24 -06:00
|
|
|
Err(_) => {
|
2024-11-17 11:15:58 -06:00
|
|
|
std::io::stderr().write_all(warnings.as_bytes()).unwrap();
|
2024-11-08 14:53:24 -06:00
|
|
|
std::io::stderr().write_all(&out).unwrap();
|
|
|
|
std::process::exit(1);
|
|
|
|
}
|
2024-11-08 01:36:00 -06:00
|
|
|
}
|
2024-05-12 17:02:32 -05:00
|
|
|
}
|