Compare commits

...

2 commits

Author SHA1 Message Date
mlokr ab41d49a3d
some stuff 2024-07-08 10:14:38 +02:00
mlokr 11cb875882
some stuff 2024-07-08 10:13:50 +02:00
3 changed files with 44 additions and 52 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@
/hbbytecode/src/opcode.rs /hbbytecode/src/opcode.rs
/hbbytecode/src/ops.rs /hbbytecode/src/ops.rs
/hblang/src/instrs.rs /hblang/src/instrs.rs
rust-ice-*

View file

@ -1,24 +1,19 @@
#![feature(vec_pop_if)] #![feature(
#![feature(get_many_mut)] let_chains,
#![feature(core_intrinsics)] if_let_guard,
#![feature(new_uninit)] macro_metavar_expr,
#![feature(anonymous_lifetime_in_impl_trait)] anonymous_lifetime_in_impl_trait,
#![feature(inline_const_pat)] core_intrinsics,
#![feature(pattern)] new_uninit,
#![feature(never_type)] never_type,
#![feature(unwrap_infallible)] unwrap_infallible,
#![feature(if_let_guard)] slice_partition_dedup,
#![feature(slice_partition_dedup)] portable_simd,
#![feature(noop_waker)] iter_collect_into,
#![feature(portable_simd)] ptr_metadata,
#![feature(iter_collect_into)] slice_ptr_get
#![feature(macro_metavar_expr)] )]
#![feature(let_chains)] #![allow(internal_features, clippy::format_collect)]
#![feature(ptr_metadata)]
#![feature(const_mut_refs)]
#![feature(slice_ptr_get)]
#![allow(internal_features)]
#![allow(clippy::format_collect)]
use { use {
parser::Ast, parser::Ast,
@ -217,7 +212,7 @@ impl<T> TaskQueueInner<T> {
} }
} }
pub fn parse_from_fs(threads: usize, root: &str) -> io::Result<Vec<Ast>> { pub fn parse_from_fs(extra_threads: usize, root: &str) -> io::Result<Vec<Ast>> {
const GIT_DEPS_DIR: &str = "git-deps"; const GIT_DEPS_DIR: &str = "git-deps";
enum Chk<'a> { enum Chk<'a> {
@ -227,7 +222,6 @@ pub fn parse_from_fs(threads: usize, root: &str) -> io::Result<Vec<Ast>> {
} }
enum ImportPath<'a> { enum ImportPath<'a> {
Root { path: &'a str },
Rel { path: &'a str }, Rel { path: &'a str },
Git { link: &'a str, path: &'a str, chk: Option<Chk<'a>> }, Git { link: &'a str, path: &'a str, chk: Option<Chk<'a>> },
} }
@ -239,8 +233,7 @@ pub fn parse_from_fs(threads: usize, root: &str) -> io::Result<Vec<Ast>> {
let (prefix, path) = value.split_once(':').unwrap_or(("", value)); let (prefix, path) = value.split_once(':').unwrap_or(("", value));
match prefix { match prefix {
"" => Ok(Self::Root { path }), "rel" | "" => Ok(Self::Rel { path }),
"rel" => Ok(Self::Rel { path }),
"git" => { "git" => {
let (link, path) = let (link, path) =
path.split_once(':').ok_or(ParseImportError::ExpectedPath)?; path.split_once(':').ok_or(ParseImportError::ExpectedPath)?;
@ -266,24 +259,22 @@ pub fn parse_from_fs(threads: usize, root: &str) -> io::Result<Vec<Ast>> {
} }
impl<'a> ImportPath<'a> { impl<'a> ImportPath<'a> {
fn resolve(&self, from: &str, root: &str) -> Result<PathBuf, CantLoadFile> { fn resolve(&self, from: &str) -> Result<PathBuf, CantLoadFile> {
let path = match self { let path = match self {
Self::Root { path } => { Self::Rel { path } => match Path::new(from).parent() {
PathBuf::from_iter([Path::new(root).parent().unwrap(), Path::new(path)]) Some(parent) => PathBuf::from_iter([parent, Path::new(path)]),
} None => PathBuf::from(path),
Self::Rel { path } => { },
PathBuf::from_iter([Path::new(from).parent().unwrap(), Path::new(path)])
}
Self::Git { path, link, .. } => { Self::Git { path, link, .. } => {
let link = preprocess_git(link); let link = preprocess_git(link);
PathBuf::from_iter([GIT_DEPS_DIR, link, path]) PathBuf::from_iter([GIT_DEPS_DIR, link, path])
} }
}; };
path.canonicalize().map_err(|e| CantLoadFile {
file_name: path, path.canonicalize().map_err(|source| CantLoadFile {
directory: PathBuf::from(root), path,
from: PathBuf::from(from), from: PathBuf::from(from),
source: e, source,
}) })
} }
} }
@ -315,21 +306,14 @@ pub fn parse_from_fs(threads: usize, root: &str) -> io::Result<Vec<Ast>> {
#[derive(Debug)] #[derive(Debug)]
struct CantLoadFile { struct CantLoadFile {
file_name: PathBuf, path: PathBuf,
directory: PathBuf,
from: PathBuf, from: PathBuf,
source: io::Error, source: io::Error,
} }
impl std::fmt::Display for CantLoadFile { impl std::fmt::Display for CantLoadFile {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!( write!(f, "can't load file: {} (from: {})", self.path.display(), self.from.display(),)
f,
"can't load file: {} (dir: {}) (from: {})",
self.file_name.display(),
self.directory.display(),
self.from.display(),
)
} }
} }
@ -369,13 +353,13 @@ pub fn parse_from_fs(threads: usize, root: &str) -> io::Result<Vec<Ast>> {
type Task = (u32, PathBuf, Option<std::process::Command>); type Task = (u32, PathBuf, Option<std::process::Command>);
let seen = Mutex::new(HashMap::<PathBuf, u32>::default()); let seen = Mutex::new(HashMap::<PathBuf, u32>::default());
let tasks = TaskQueue::<Task>::new(threads); let tasks = TaskQueue::<Task>::new(extra_threads);
let ast = Mutex::new(Vec::<io::Result<Ast>>::new()); let ast = Mutex::new(Vec::<io::Result<Ast>>::new());
let loader = |path: &str, from: &str| { let loader = |path: &str, from: &str| {
let path = ImportPath::try_from(path)?; let path = ImportPath::try_from(path)?;
let physiscal_path = path.resolve(from, root)?; let physiscal_path = path.resolve(from)?;
let id = { let id = {
let mut seen = seen.lock().unwrap(); let mut seen = seen.lock().unwrap();
@ -460,7 +444,11 @@ pub fn parse_from_fs(threads: usize, root: &str) -> io::Result<Vec<Ast>> {
seen.lock().unwrap().insert(path.clone(), 0); seen.lock().unwrap().insert(path.clone(), 0);
tasks.push((0, path, None)); tasks.push((0, path, None));
std::thread::scope(|s| (0..threads).for_each(|_| _ = s.spawn(thread))); if extra_threads == 0 {
thread();
} else {
std::thread::scope(|s| (0..extra_threads + 1).for_each(|_| _ = s.spawn(thread)));
}
ast.into_inner().unwrap().into_iter().collect::<io::Result<Vec<_>>>() ast.into_inner().unwrap().into_iter().collect::<io::Result<Vec<_>>>()
} }
@ -551,6 +539,7 @@ pub fn run_test(
pub struct Options { pub struct Options {
pub fmt: bool, pub fmt: bool,
pub fmt_current: bool, pub fmt_current: bool,
pub extra_threads: usize,
} }
pub fn run_compiler( pub fn run_compiler(
@ -558,7 +547,7 @@ pub fn run_compiler(
options: Options, options: Options,
out: &mut impl std::io::Write, out: &mut impl std::io::Write,
) -> io::Result<()> { ) -> io::Result<()> {
let parsed = parse_from_fs(1, root_file)?; let parsed = parse_from_fs(options.extra_threads, root_file)?;
fn format_to_stdout(ast: parser::Ast) -> std::io::Result<()> { fn format_to_stdout(ast: parser::Ast) -> std::io::Result<()> {
let source = std::fs::read_to_string(&*ast.path)?; let source = std::fs::read_to_string(&*ast.path)?;
@ -618,7 +607,6 @@ mod test {
std::thread::spawn(move || { std::thread::spawn(move || {
for _ in 0..100 { for _ in 0..100 {
queue.extend([queue.pop().unwrap()]); queue.extend([queue.pop().unwrap()]);
//dbg!();
} }
}) })
}) })

View file

@ -3,5 +3,8 @@ name = "xtask"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies.argh]
argh = { git = "https://github.com/google/argh.git", branch = "master", default-features = false, features = ["help"] } git = "https://github.com/google/argh.git"
branch = "master"
default-features = false
features = ["help"]