forked from AbleOS/holey-bytes
making ableos path resolver public
Signed-off-by: Jakub Doka <jakub.doka2@gmail.com>
This commit is contained in:
parent
3f6ebdd009
commit
cf672beb79
|
@ -8,6 +8,7 @@ use {
|
||||||
core::{fmt::Write, num::NonZeroUsize, ops::Deref},
|
core::{fmt::Write, num::NonZeroUsize, ops::Deref},
|
||||||
hashbrown::hash_map,
|
hashbrown::hash_map,
|
||||||
std::{
|
std::{
|
||||||
|
borrow::ToOwned,
|
||||||
collections::VecDeque,
|
collections::VecDeque,
|
||||||
eprintln,
|
eprintln,
|
||||||
ffi::OsStr,
|
ffi::OsStr,
|
||||||
|
@ -36,6 +37,33 @@ impl log::Log for Logger {
|
||||||
fn flush(&self) {}
|
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)]
|
#[derive(Default)]
|
||||||
pub struct Options<'a> {
|
pub struct Options<'a> {
|
||||||
pub fmt: bool,
|
pub fmt: bool,
|
||||||
|
|
|
@ -1,42 +1,11 @@
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
fn main() {
|
fn main() {
|
||||||
use std::{
|
use std::io::Write;
|
||||||
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 })
|
|
||||||
};
|
|
||||||
|
|
||||||
fn run(out: &mut Vec<u8>, warnings: &mut String) -> std::io::Result<()> {
|
fn run(out: &mut Vec<u8>, warnings: &mut String) -> std::io::Result<()> {
|
||||||
let args = std::env::args().collect::<Vec<_>>();
|
let args = std::env::args().collect::<Vec<_>>();
|
||||||
let args = args.iter().map(String::as_str).collect::<Vec<_>>();
|
let args = args.iter().map(String::as_str).collect::<Vec<_>>();
|
||||||
let resolvers = &[("ableos", ABLEOS_PATH_RESOLVER)];
|
let resolvers = &[("ableos", hblang::ABLEOS_PATH_RESOLVER)];
|
||||||
let opts = hblang::Options::from_args(&args, out, resolvers)?;
|
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");
|
let file = args.iter().filter(|a| !a.starts_with('-')).nth(1).copied().unwrap_or("main.hb");
|
||||||
|
|
||||||
|
|
|
@ -175,24 +175,6 @@ impl HbvmBackend {
|
||||||
graph[d as usize] = s;
|
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() {
|
'o: for &mut [d, s, ref mut depth] in moves.iter_mut() {
|
||||||
let mut c = s;
|
let mut c = s;
|
||||||
loop {
|
loop {
|
||||||
|
|
Loading…
Reference in a new issue