Compare commits

..

No commits in common. "ab41d49a3d2d5f689de880faf5f7c21f54df6c38" and "8984dce0e7d72be3624931a19e0e93ca712c9fe5" have entirely different histories.

3 changed files with 52 additions and 44 deletions

1
.gitignore vendored
View file

@ -2,4 +2,3 @@
/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,19 +1,24 @@
#![feature( #![feature(vec_pop_if)]
let_chains, #![feature(get_many_mut)]
if_let_guard, #![feature(core_intrinsics)]
macro_metavar_expr, #![feature(new_uninit)]
anonymous_lifetime_in_impl_trait, #![feature(anonymous_lifetime_in_impl_trait)]
core_intrinsics, #![feature(inline_const_pat)]
new_uninit, #![feature(pattern)]
never_type, #![feature(never_type)]
unwrap_infallible, #![feature(unwrap_infallible)]
slice_partition_dedup, #![feature(if_let_guard)]
portable_simd, #![feature(slice_partition_dedup)]
iter_collect_into, #![feature(noop_waker)]
ptr_metadata, #![feature(portable_simd)]
slice_ptr_get #![feature(iter_collect_into)]
)] #![feature(macro_metavar_expr)]
#![allow(internal_features, clippy::format_collect)] #![feature(let_chains)]
#![feature(ptr_metadata)]
#![feature(const_mut_refs)]
#![feature(slice_ptr_get)]
#![allow(internal_features)]
#![allow(clippy::format_collect)]
use { use {
parser::Ast, parser::Ast,
@ -212,7 +217,7 @@ impl<T> TaskQueueInner<T> {
} }
} }
pub fn parse_from_fs(extra_threads: usize, root: &str) -> io::Result<Vec<Ast>> { pub fn parse_from_fs(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> {
@ -222,6 +227,7 @@ pub fn parse_from_fs(extra_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>> },
} }
@ -233,7 +239,8 @@ pub fn parse_from_fs(extra_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 {
"rel" | "" => Ok(Self::Rel { path }), "" => Ok(Self::Root { 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)?;
@ -259,22 +266,24 @@ pub fn parse_from_fs(extra_threads: usize, root: &str) -> io::Result<Vec<Ast>> {
} }
impl<'a> ImportPath<'a> { impl<'a> ImportPath<'a> {
fn resolve(&self, from: &str) -> Result<PathBuf, CantLoadFile> { fn resolve(&self, from: &str, root: &str) -> Result<PathBuf, CantLoadFile> {
let path = match self { let path = match self {
Self::Rel { path } => match Path::new(from).parent() { Self::Root { path } => {
Some(parent) => PathBuf::from_iter([parent, Path::new(path)]), PathBuf::from_iter([Path::new(root).parent().unwrap(), 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 {
path.canonicalize().map_err(|source| CantLoadFile { file_name: path,
path, directory: PathBuf::from(root),
from: PathBuf::from(from), from: PathBuf::from(from),
source, source: e,
}) })
} }
} }
@ -306,14 +315,21 @@ pub fn parse_from_fs(extra_threads: usize, root: &str) -> io::Result<Vec<Ast>> {
#[derive(Debug)] #[derive(Debug)]
struct CantLoadFile { struct CantLoadFile {
path: PathBuf, file_name: 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!(f, "can't load file: {} (from: {})", self.path.display(), self.from.display(),) write!(
f,
"can't load file: {} (dir: {}) (from: {})",
self.file_name.display(),
self.directory.display(),
self.from.display(),
)
} }
} }
@ -353,13 +369,13 @@ pub fn parse_from_fs(extra_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(extra_threads); let tasks = TaskQueue::<Task>::new(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)?; let physiscal_path = path.resolve(from, root)?;
let id = { let id = {
let mut seen = seen.lock().unwrap(); let mut seen = seen.lock().unwrap();
@ -444,11 +460,7 @@ pub fn parse_from_fs(extra_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));
if extra_threads == 0 { std::thread::scope(|s| (0..threads).for_each(|_| _ = s.spawn(thread)));
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<_>>>()
} }
@ -539,7 +551,6 @@ 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(
@ -547,7 +558,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(options.extra_threads, root_file)?; let parsed = parse_from_fs(1, 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)?;
@ -607,6 +618,7 @@ 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,8 +3,5 @@ name = "xtask"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies.argh] [dependencies]
git = "https://github.com/google/argh.git" argh = { git = "https://github.com/google/argh.git", branch = "master", default-features = false, features = ["help"] }
branch = "master"
default-features = false
features = ["help"]