diff --git a/lang/src/fs.rs b/lang/src/fs.rs index 9744692b..5106330e 100644 --- a/lang/src/fs.rs +++ b/lang/src/fs.rs @@ -8,6 +8,7 @@ use { core::{fmt::Write, num::NonZeroUsize, ops::Deref}, hashbrown::hash_map, std::{ + borrow::ToOwned, collections::VecDeque, eprintln, ffi::OsStr, @@ -36,6 +37,33 @@ impl log::Log for Logger { fn flush(&self) {} } +pub const ABLEOS_PATH_RESOLVER: 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| CantLoadFile { path: std::mem::take(tmp), source }) + }; + #[derive(Default)] pub struct Options<'a> { pub fmt: bool, diff --git a/lang/src/main.rs b/lang/src/main.rs index 3cb48f6f..dfc9103a 100644 --- a/lang/src/main.rs +++ b/lang/src/main.rs @@ -1,42 +1,11 @@ #[cfg(feature = "std")] fn main() { - 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 }) - }; + use std::io::Write; fn run(out: &mut Vec, warnings: &mut String) -> std::io::Result<()> { let args = std::env::args().collect::>(); let args = args.iter().map(String::as_str).collect::>(); - let resolvers = &[("ableos", ABLEOS_PATH_RESOLVER)]; + let resolvers = &[("ableos", hblang::ABLEOS_PATH_RESOLVER)]; let opts = hblang::Options::from_args(&args, out, resolvers)?; let file = args.iter().filter(|a| !a.starts_with('-')).nth(1).copied().unwrap_or("main.hb"); diff --git a/lang/src/son/hbvm/regalloc.rs b/lang/src/son/hbvm/regalloc.rs index 2fe62f06..7ac01e42 100644 --- a/lang/src/son/hbvm/regalloc.rs +++ b/lang/src/son/hbvm/regalloc.rs @@ -175,24 +175,6 @@ impl HbvmBackend { graph[d as usize] = s; } - // [3, 2, 0] - - // cp 0, 1 = 3 - // cp 1, 2 = 2 - // cp 2, 0 = 1 - // - // swp a, b - // swp b, c - - // cp a, b - // cp b, c - // cp c, d - // cp d, a - // - // swp a, b - // swp b, c - // swp c, d - 'o: for &mut [d, s, ref mut depth] in moves.iter_mut() { let mut c = s; loop {