diff --git a/.gitignore b/.gitignore index 975a922..401d09f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ /target -/hbbytecode/src/instrs.rs +/bytecode/src/instrs.rs /.rgignore rustc-ice-* db.sqlite diff --git a/Cargo.lock b/Cargo.lock index 9586145..f2cdd2a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -271,10 +271,6 @@ dependencies = [ name = "hbbytecode" version = "0.1.0" -[[package]] -name = "hbjit" -version = "0.1.0" - [[package]] name = "hblang" version = "0.1.0" @@ -309,18 +305,18 @@ checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] name = "htmlm" -version = "0.3.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91eeb833c1f091f72c22c2d213d8acb12b953cea20fd911a2f636e806858a391" +checksum = "a95b97f2c13991e486bf95be6d19c6c3d1fef4f8ec1e298e40aaf98769789295" dependencies = [ "htmlm-macro", ] [[package]] name = "htmlm-macro" -version = "0.1.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3607a5606a3432058fa765bc4dec74ab8d103282cf16f35df7be838a674ebaa9" +checksum = "7f881f4929b944a9566f12d8ac3bf9881325c77c11b9b0adcdc6944018b55ac7" [[package]] name = "http" @@ -809,6 +805,10 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasm-hbc" +version = "0.1.0" + [[package]] name = "wasm-hbfmt" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index f184c54..f1861be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,19 +1,27 @@ [workspace] resolver = "2" members = [ - "hbbytecode", - "hbvm", - "hbxrt", + "bytecode", + "vm", + "xrt", "xtask", - "hblang", - "hbjit", + "lang", "depell", - "depell/wasm-hbfmt" + "depell/wasm-fmt", + "depell/wasm-hbc", ] +[workspace.dependencies] +hbbytecode = { path = "bytecode", default-features = false } +hbvm = { path = "vm" } +hbxrt = { path = "xrt" } +hblang = { path = "lang", default-features = false } +hbjit = { path = "jit" } + [profile.release] lto = true debug = true +#strip = true codegen-units = 1 panic = "abort" diff --git a/hbbytecode/Cargo.toml b/bytecode/Cargo.toml similarity index 100% rename from hbbytecode/Cargo.toml rename to bytecode/Cargo.toml diff --git a/hbbytecode/build.rs b/bytecode/build.rs similarity index 99% rename from hbbytecode/build.rs rename to bytecode/build.rs index dd41617..1f5382d 100644 --- a/hbbytecode/build.rs +++ b/bytecode/build.rs @@ -159,7 +159,7 @@ fn comma_sep(items: impl Iterator) -> String { } fn instructions() -> impl Iterator { - include_str!("../hbbytecode/instructions.in") + include_str!("instructions.in") .lines() .filter_map(|line| line.strip_suffix(';')) .map(|line| line.splitn(4, ',').map(str::trim).next_chunk().unwrap()) diff --git a/hbbytecode/hbbytecode.h b/bytecode/hbbytecode.h similarity index 100% rename from hbbytecode/hbbytecode.h rename to bytecode/hbbytecode.h diff --git a/hbbytecode/instructions.in b/bytecode/instructions.in similarity index 100% rename from hbbytecode/instructions.in rename to bytecode/instructions.in diff --git a/hbbytecode/src/lib.rs b/bytecode/src/lib.rs similarity index 100% rename from hbbytecode/src/lib.rs rename to bytecode/src/lib.rs diff --git a/depell/Cargo.toml b/depell/Cargo.toml index f8b2d75..7931fa3 100644 --- a/depell/Cargo.toml +++ b/depell/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [dependencies] axum = "0.7.7" getrandom = "0.2.15" -htmlm = "0.3.0" +htmlm = "0.5.0" log = "0.4.22" rusqlite = "0.32.1" serde = { version = "1.0.210", features = ["derive"] } diff --git a/depell/src/main.rs b/depell/src/main.rs index 51ea77a..6592caac 100644 --- a/depell/src/main.rs +++ b/depell/src/main.rs @@ -1,12 +1,13 @@ use { axum::{ + body::Bytes, http::{header::COOKIE, request::Parts}, response::{AppendHeaders, Html}, }, core::fmt, htmlm::{html, write_html}, serde::{Deserialize, Serialize}, - std::net::Ipv4Addr, + std::{fmt::Write, net::Ipv4Addr}, }; const MAX_NAME_LENGTH: usize = 32; @@ -16,6 +17,17 @@ const SESSION_DURATION_SECS: u64 = 60 * 60; type Redirect = AppendHeaders<[(&'static str, &'static str); COUNT]>; +macro_rules! static_asset { + ($mime:literal, $body:literal) => { + get(|| async { + axum::http::Response::builder() + .header("content-type", $mime) + .body(axum::body::Body::from(Bytes::from_static(include_bytes!($body)))) + .unwrap() + }) + }; +} + async fn amain() { use axum::routing::{delete, get, post}; @@ -30,15 +42,10 @@ async fn amain() { .route("/", get(Index::page)) .route( "/hbfmt.wasm", - get(|| async move { - axum::http::Response::builder() - .header("content-type", "application/wasm") - .body(axum::body::Body::from( - include_bytes!("../../target/wasm32-unknown-unknown/small/wasm_hbfmt.wasm") - .to_vec(), - )) - .unwrap() - }), + static_asset!( + "application/wasm", + "../../target/wasm32-unknown-unknown/small/wasm_hbfmt.wasm" + ), ) .route("/index-view", get(Index::get)) .route("/feed", get(Index::page)) @@ -71,19 +78,31 @@ async fn amain() { } trait PublicPage: Default { - fn render(self) -> String; + fn render_to_buf(self, buf: &mut String); + + fn render(self) -> String { + let mut str = String::new(); + Self::default().render_to_buf(&mut str); + str + } async fn get() -> Html { Html(Self::default().render()) } async fn page(session: Option) -> Html { - base(Self::default().render(), session).await + base(|s| Self::default().render_to_buf(s), session.as_ref()).await } } trait Page: Default { - fn render(self, session: &Session) -> String; + fn render_to_buf(self, session: &Session, buf: &mut String); + + fn render(self, session: &Session) -> String { + let mut str = String::new(); + Self::default().render_to_buf(session, &mut str); + str + } async fn get(session: Session) -> Html { Html(Self::default().render(&session)) @@ -91,7 +110,9 @@ trait Page: Default { async fn page(session: Option) -> Result, axum::response::Redirect> { match session { - Some(session) => Ok(base(Self::default().render(&session), Some(session)).await), + Some(session) => { + Ok(base(|f| Self::default().render_to_buf(&session, f), Some(&session)).await) + } None => Err(axum::response::Redirect::permanent("/login")), } } @@ -101,8 +122,8 @@ trait Page: Default { struct Index; impl PublicPage for Index { - fn render(self) -> String { - include_str!("welcome-page.html").to_string() + fn render_to_buf(self, buf: &mut String) { + buf.push_str(include_str!("welcome-page.html")); } } @@ -124,9 +145,9 @@ struct Post { } impl Page for Post { - fn render(self, session: &Session) -> String { + fn render_to_buf(self, session: &Session, buf: &mut String) { let Self { name, code, error, .. } = self; - html! { + write_html! { (buf)
if let Some(e) = error {
e
} @@ -197,7 +218,7 @@ impl fmt::Display for Post { struct Profile; impl Page for Profile { - fn render(self, session: &Session) -> String { + fn render_to_buf(self, session: &Session, buf: &mut String) { db::with(|db| { let iter = db .get_user_posts @@ -214,7 +235,7 @@ impl Page for Profile { .into_iter() .flatten() .filter_map(|p| p.inspect_err(|e| log::error!("{e}")).ok()); - html! { + write_html! { (buf) for post in iter { !{post} } else { @@ -235,9 +256,9 @@ struct Login { } impl PublicPage for Login { - fn render(self) -> String { + fn render_to_buf(self, buf: &mut String) { let Login { name, password, error } = self; - html! { + write_html! { (buf) if let Some(e) = error {
e
} String { + fn render_to_buf(self, buf: &mut String) { let Signup { name, new_password, confirm_password, error } = self; - html! { + write_html! { (buf) if let Some(e) = error {
e
} ) -> Html { - let username = session.map(|s| s.name); +async fn base(body: impl FnOnce(&mut String), session: Option<&Session>) -> Html { + let username = session.map(|s| &s.name); - Html(htmlm::html! { - "" + Html(html! { + "" @@ -377,7 +398,7 @@ async fn base(body: String, session: Option) -> Html {
-
!{body}
+
|f|{body(f)}
diff --git a/depell/wasm-hbfmt/Cargo.toml b/depell/wasm-fmt/Cargo.toml similarity index 52% rename from depell/wasm-hbfmt/Cargo.toml rename to depell/wasm-fmt/Cargo.toml index 558e7b0..1f873ec 100644 --- a/depell/wasm-hbfmt/Cargo.toml +++ b/depell/wasm-fmt/Cargo.toml @@ -7,4 +7,4 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -hblang = { version = "0.1.0", path = "../../hblang", default-features = false, features = ["no_log"] } +hblang = { workspace = true, features = ["no_log"] } diff --git a/depell/wasm-hbfmt/src/lib.rs b/depell/wasm-fmt/src/lib.rs similarity index 96% rename from depell/wasm-hbfmt/src/lib.rs rename to depell/wasm-fmt/src/lib.rs index 2b88927..63924fb 100644 --- a/depell/wasm-hbfmt/src/lib.rs +++ b/depell/wasm-fmt/src/lib.rs @@ -120,7 +120,8 @@ unsafe extern "C" fn fmt() { let arena = hblang::parser::Arena::with_capacity(code.len() * hblang::parser::SOURCE_TO_AST_FACTOR); let mut ctx = ParserCtx::default(); - let exprs = hblang::parser::Parser::parse(&mut ctx, code, "source.hb", &|_, _| Ok(0), &arena); + let exprs = + hblang::parser::Parser::parse(&mut ctx, code, "source.hb", &mut |_, _| Ok(0), &arena); let mut f = Write(&mut OUTPUT[..]); hblang::fmt::fmt_file(exprs, code, &mut f).unwrap(); diff --git a/hbjit/Cargo.toml b/depell/wasm-hbc/Cargo.toml similarity index 77% rename from hbjit/Cargo.toml rename to depell/wasm-hbc/Cargo.toml index 884ff16..81927e1 100644 --- a/hbjit/Cargo.toml +++ b/depell/wasm-hbc/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "hbjit" +name = "wasm-hbc" version = "0.1.0" edition = "2021" diff --git a/depell/wasm-hbc/src/lib.rs b/depell/wasm-hbc/src/lib.rs new file mode 100644 index 0000000..b93cf3f --- /dev/null +++ b/depell/wasm-hbc/src/lib.rs @@ -0,0 +1,14 @@ +pub fn add(left: u64, right: u64) -> u64 { + left + right +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); + } +} diff --git a/hbjit/src/main.rs b/hbjit/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/hbjit/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/hblang/Cargo.toml b/lang/Cargo.toml similarity index 81% rename from hblang/Cargo.toml rename to lang/Cargo.toml index c3773d2..1cdc6de 100644 --- a/hblang/Cargo.toml +++ b/lang/Cargo.toml @@ -9,8 +9,8 @@ path = "src/main.rs" [dependencies] hashbrown = { version = "0.15.0", default-features = false, features = ["raw-entry"] } -hbbytecode = { version = "0.1.0", path = "../hbbytecode" } -hbvm = { path = "../hbvm", features = ["nightly"] } +hbbytecode = { workspace = true, features = ["disasm"] } +hbvm = { workspace = true, features = ["nightly"] } log = { version = "0.4.22", features = ["release_max_level_error"] } [dependencies.regalloc2] diff --git a/hblang/README.md b/lang/README.md similarity index 100% rename from hblang/README.md rename to lang/README.md diff --git a/hblang/command-help.txt b/lang/command-help.txt similarity index 100% rename from hblang/command-help.txt rename to lang/command-help.txt diff --git a/hblang/src/codegen.rs b/lang/src/codegen.rs similarity index 100% rename from hblang/src/codegen.rs rename to lang/src/codegen.rs diff --git a/hblang/src/fmt.rs b/lang/src/fmt.rs similarity index 99% rename from hblang/src/fmt.rs rename to lang/src/fmt.rs index 489637c..ff559ea 100644 --- a/hblang/src/fmt.rs +++ b/lang/src/fmt.rs @@ -449,7 +449,7 @@ pub mod test { let len = crate::fmt::minify(&mut minned); minned.truncate(len); - let ast = parser::Ast::new(ident, minned, &mut ParserCtx::default(), &|_, _| Ok(0)); + let ast = parser::Ast::new(ident, minned, &mut ParserCtx::default(), &mut |_, _| Ok(0)); log::error!( "{} / {} = {} | {} / {} = {}", ast.mem.size(), diff --git a/hblang/src/fs.rs b/lang/src/fs.rs similarity index 89% rename from hblang/src/fs.rs rename to lang/src/fs.rs index b34185a..3384b69 100644 --- a/hblang/src/fs.rs +++ b/lang/src/fs.rs @@ -188,13 +188,14 @@ impl TaskQueueInner { } pub fn parse_from_fs(extra_threads: usize, root: &str) -> io::Result> { - fn resolve(path: &str, from: &str) -> Result { - let path = match Path::new(from).parent() { - Some(parent) => PathBuf::from_iter([parent, Path::new(path)]), - None => PathBuf::from(path), + fn resolve(path: &str, from: &str, tmp: &mut PathBuf) -> Result { + tmp.clear(); + match Path::new(from).parent() { + Some(parent) => tmp.extend([parent, Path::new(path)]), + None => tmp.push(path), }; - path.canonicalize().map_err(|source| CantLoadFile { path, source }) + tmp.canonicalize().map_err(|source| CantLoadFile { path: std::mem::take(tmp), source }) } #[derive(Debug)] @@ -227,7 +228,7 @@ pub fn parse_from_fs(extra_threads: usize, root: &str) -> io::Result> { let tasks = TaskQueue::::new(extra_threads + 1); let ast = Mutex::new(Vec::>::new()); - let loader = |path: &str, from: &str| { + let loader = |path: &str, from: &str, tmp: &mut _| { if path.starts_with("rel:") { return Err(io::Error::new( io::ErrorKind::Other, @@ -236,17 +237,17 @@ pub fn parse_from_fs(extra_threads: usize, root: &str) -> io::Result> { )); } - let physiscal_path = resolve(path, from)?; + let mut physiscal_path = resolve(path, from, tmp)?; let id = { let mut seen = seen.lock().unwrap(); let len = seen.len(); - match seen.entry(physiscal_path.clone()) { + match seen.entry(physiscal_path) { hash_map::Entry::Occupied(entry) => { return Ok(*entry.get()); } hash_map::Entry::Vacant(entry) => { - entry.insert(len as _); + physiscal_path = entry.insert_entry(len as _).key().clone(); len as u32 } } @@ -263,22 +264,23 @@ pub fn parse_from_fs(extra_threads: usize, root: &str) -> io::Result> { Ok(id) }; - let execute_task = |ctx: &mut _, (_, path): Task| { + let execute_task = |ctx: &mut _, (_, path): Task, tmp: &mut _| { let path = path.to_str().ok_or_else(|| { io::Error::new( io::ErrorKind::InvalidData, format!("path contains invalid characters: {}", display_rel_path(&path)), ) })?; - Ok(Ast::new(path, std::fs::read_to_string(path)?, ctx, &|path, from| { - loader(path, from).map_err(|e| e.to_string()) + Ok(Ast::new(path, std::fs::read_to_string(path)?, ctx, &mut |path, from| { + loader(path, from, tmp).map_err(|e| e.to_string()) })) }; let thread = || { let mut ctx = ParserCtx::default(); + let mut tmp = PathBuf::new(); while let Some(task @ (indx, ..)) = tasks.pop() { - let res = execute_task(&mut ctx, task); + let res = execute_task(&mut ctx, task, &mut tmp); let mut ast = ast.lock().unwrap(); let len = ast.len().max(indx as usize + 1); ast.resize_with(len, || Err(io::ErrorKind::InvalidData.into())); @@ -286,7 +288,9 @@ pub fn parse_from_fs(extra_threads: usize, root: &str) -> io::Result> { } }; - let path = Path::new(root).canonicalize()?; + let path = Path::new(root).canonicalize().map_err(|e| { + io::Error::new(e.kind(), format!("can't canonicalize root file path ({root})")) + })?; seen.lock().unwrap().insert(path.clone(), 0); tasks.push((0, path)); diff --git a/hblang/src/lexer.rs b/lang/src/lexer.rs similarity index 100% rename from hblang/src/lexer.rs rename to lang/src/lexer.rs diff --git a/hblang/src/lib.rs b/lang/src/lib.rs similarity index 99% rename from hblang/src/lib.rs rename to lang/src/lib.rs index 0891abc..e80f376 100644 --- a/hblang/src/lib.rs +++ b/lang/src/lib.rs @@ -1348,7 +1348,7 @@ fn test_parse_files(ident: &'static str, input: &'static str) -> Vec Vec; pub type FileId = u32; pub type IdentIndex = u16; pub type LoaderError = String; -pub type Loader<'a> = &'a (dyn Fn(&str, &str) -> Result + 'a); +pub type Loader<'a> = &'a mut (dyn FnMut(&str, &str) -> Result + 'a); pub const SOURCE_TO_AST_FACTOR: usize = 7 * (core::mem::size_of::() / 4) + 1; @@ -1068,7 +1068,7 @@ impl Ast { impl Default for Ast { fn default() -> Self { - Self(AstInner::new("".into(), "", &mut ParserCtx::default(), &no_loader)) + Self(AstInner::new("".into(), "", &mut ParserCtx::default(), &mut no_loader)) } } diff --git a/hblang/src/son.rs b/lang/src/son.rs similarity index 100% rename from hblang/src/son.rs rename to lang/src/son.rs diff --git a/hblang/src/vc.rs b/lang/src/vc.rs similarity index 100% rename from hblang/src/vc.rs rename to lang/src/vc.rs diff --git a/hblang/tests/codegen_tests_arithmetic.txt b/lang/tests/codegen_tests_arithmetic.txt similarity index 100% rename from hblang/tests/codegen_tests_arithmetic.txt rename to lang/tests/codegen_tests_arithmetic.txt diff --git a/hblang/tests/codegen_tests_arrays.txt b/lang/tests/codegen_tests_arrays.txt similarity index 100% rename from hblang/tests/codegen_tests_arrays.txt rename to lang/tests/codegen_tests_arrays.txt diff --git a/hblang/tests/codegen_tests_c_strings.txt b/lang/tests/codegen_tests_c_strings.txt similarity index 100% rename from hblang/tests/codegen_tests_c_strings.txt rename to lang/tests/codegen_tests_c_strings.txt diff --git a/hblang/tests/codegen_tests_comments.txt b/lang/tests/codegen_tests_comments.txt similarity index 100% rename from hblang/tests/codegen_tests_comments.txt rename to lang/tests/codegen_tests_comments.txt diff --git a/hblang/tests/codegen_tests_comptime_function_from_another_file.txt b/lang/tests/codegen_tests_comptime_function_from_another_file.txt similarity index 100% rename from hblang/tests/codegen_tests_comptime_function_from_another_file.txt rename to lang/tests/codegen_tests_comptime_function_from_another_file.txt diff --git a/hblang/tests/codegen_tests_comptime_min_reg_leak.txt b/lang/tests/codegen_tests_comptime_min_reg_leak.txt similarity index 100% rename from hblang/tests/codegen_tests_comptime_min_reg_leak.txt rename to lang/tests/codegen_tests_comptime_min_reg_leak.txt diff --git a/hblang/tests/codegen_tests_different_types.txt b/lang/tests/codegen_tests_different_types.txt similarity index 100% rename from hblang/tests/codegen_tests_different_types.txt rename to lang/tests/codegen_tests_different_types.txt diff --git a/hblang/tests/codegen_tests_directives.txt b/lang/tests/codegen_tests_directives.txt similarity index 100% rename from hblang/tests/codegen_tests_directives.txt rename to lang/tests/codegen_tests_directives.txt diff --git a/hblang/tests/codegen_tests_fb_driver.txt b/lang/tests/codegen_tests_fb_driver.txt similarity index 100% rename from hblang/tests/codegen_tests_fb_driver.txt rename to lang/tests/codegen_tests_fb_driver.txt diff --git a/hblang/tests/codegen_tests_functions.txt b/lang/tests/codegen_tests_functions.txt similarity index 100% rename from hblang/tests/codegen_tests_functions.txt rename to lang/tests/codegen_tests_functions.txt diff --git a/hblang/tests/codegen_tests_generic_functions.txt b/lang/tests/codegen_tests_generic_functions.txt similarity index 100% rename from hblang/tests/codegen_tests_generic_functions.txt rename to lang/tests/codegen_tests_generic_functions.txt diff --git a/hblang/tests/codegen_tests_generic_types.txt b/lang/tests/codegen_tests_generic_types.txt similarity index 100% rename from hblang/tests/codegen_tests_generic_types.txt rename to lang/tests/codegen_tests_generic_types.txt diff --git a/hblang/tests/codegen_tests_global_variables.txt b/lang/tests/codegen_tests_global_variables.txt similarity index 100% rename from hblang/tests/codegen_tests_global_variables.txt rename to lang/tests/codegen_tests_global_variables.txt diff --git a/hblang/tests/codegen_tests_hex_octal_binary_literals.txt b/lang/tests/codegen_tests_hex_octal_binary_literals.txt similarity index 100% rename from hblang/tests/codegen_tests_hex_octal_binary_literals.txt rename to lang/tests/codegen_tests_hex_octal_binary_literals.txt diff --git a/hblang/tests/codegen_tests_idk.txt b/lang/tests/codegen_tests_idk.txt similarity index 100% rename from hblang/tests/codegen_tests_idk.txt rename to lang/tests/codegen_tests_idk.txt diff --git a/hblang/tests/codegen_tests_if_statements.txt b/lang/tests/codegen_tests_if_statements.txt similarity index 100% rename from hblang/tests/codegen_tests_if_statements.txt rename to lang/tests/codegen_tests_if_statements.txt diff --git a/hblang/tests/codegen_tests_inline.txt b/lang/tests/codegen_tests_inline.txt similarity index 100% rename from hblang/tests/codegen_tests_inline.txt rename to lang/tests/codegen_tests_inline.txt diff --git a/hblang/tests/codegen_tests_inline_test.txt b/lang/tests/codegen_tests_inline_test.txt similarity index 100% rename from hblang/tests/codegen_tests_inline_test.txt rename to lang/tests/codegen_tests_inline_test.txt diff --git a/hblang/tests/codegen_tests_integer_inference_issues.txt b/lang/tests/codegen_tests_integer_inference_issues.txt similarity index 100% rename from hblang/tests/codegen_tests_integer_inference_issues.txt rename to lang/tests/codegen_tests_integer_inference_issues.txt diff --git a/hblang/tests/codegen_tests_loops.txt b/lang/tests/codegen_tests_loops.txt similarity index 100% rename from hblang/tests/codegen_tests_loops.txt rename to lang/tests/codegen_tests_loops.txt diff --git a/hblang/tests/codegen_tests_pointers.txt b/lang/tests/codegen_tests_pointers.txt similarity index 100% rename from hblang/tests/codegen_tests_pointers.txt rename to lang/tests/codegen_tests_pointers.txt diff --git a/hblang/tests/codegen_tests_request_page.txt b/lang/tests/codegen_tests_request_page.txt similarity index 100% rename from hblang/tests/codegen_tests_request_page.txt rename to lang/tests/codegen_tests_request_page.txt diff --git a/hblang/tests/codegen_tests_some_generic_code.txt b/lang/tests/codegen_tests_some_generic_code.txt similarity index 100% rename from hblang/tests/codegen_tests_some_generic_code.txt rename to lang/tests/codegen_tests_some_generic_code.txt diff --git a/hblang/tests/codegen_tests_something_somehow.txt b/lang/tests/codegen_tests_something_somehow.txt similarity index 100% rename from hblang/tests/codegen_tests_something_somehow.txt rename to lang/tests/codegen_tests_something_somehow.txt diff --git a/hblang/tests/codegen_tests_sort_something_viredly.txt b/lang/tests/codegen_tests_sort_something_viredly.txt similarity index 100% rename from hblang/tests/codegen_tests_sort_something_viredly.txt rename to lang/tests/codegen_tests_sort_something_viredly.txt diff --git a/hblang/tests/codegen_tests_struct_operators.txt b/lang/tests/codegen_tests_struct_operators.txt similarity index 100% rename from hblang/tests/codegen_tests_struct_operators.txt rename to lang/tests/codegen_tests_struct_operators.txt diff --git a/hblang/tests/codegen_tests_struct_patterns.txt b/lang/tests/codegen_tests_struct_patterns.txt similarity index 100% rename from hblang/tests/codegen_tests_struct_patterns.txt rename to lang/tests/codegen_tests_struct_patterns.txt diff --git a/hblang/tests/codegen_tests_struct_return_from_module_function.txt b/lang/tests/codegen_tests_struct_return_from_module_function.txt similarity index 100% rename from hblang/tests/codegen_tests_struct_return_from_module_function.txt rename to lang/tests/codegen_tests_struct_return_from_module_function.txt diff --git a/hblang/tests/codegen_tests_structs.txt b/lang/tests/codegen_tests_structs.txt similarity index 100% rename from hblang/tests/codegen_tests_structs.txt rename to lang/tests/codegen_tests_structs.txt diff --git a/hblang/tests/codegen_tests_tests_ptr_to_ptr_copy.txt b/lang/tests/codegen_tests_tests_ptr_to_ptr_copy.txt similarity index 100% rename from hblang/tests/codegen_tests_tests_ptr_to_ptr_copy.txt rename to lang/tests/codegen_tests_tests_ptr_to_ptr_copy.txt diff --git a/hblang/tests/codegen_tests_variables.txt b/lang/tests/codegen_tests_variables.txt similarity index 100% rename from hblang/tests/codegen_tests_variables.txt rename to lang/tests/codegen_tests_variables.txt diff --git a/hblang/tests/codegen_tests_wide_ret.txt b/lang/tests/codegen_tests_wide_ret.txt similarity index 100% rename from hblang/tests/codegen_tests_wide_ret.txt rename to lang/tests/codegen_tests_wide_ret.txt diff --git a/hblang/tests/codegen_tests_writing_into_string.txt b/lang/tests/codegen_tests_writing_into_string.txt similarity index 100% rename from hblang/tests/codegen_tests_writing_into_string.txt rename to lang/tests/codegen_tests_writing_into_string.txt diff --git a/hblang/tests/son_tests_arithmetic.txt b/lang/tests/son_tests_arithmetic.txt similarity index 100% rename from hblang/tests/son_tests_arithmetic.txt rename to lang/tests/son_tests_arithmetic.txt diff --git a/hblang/tests/son_tests_branch_assignments.txt b/lang/tests/son_tests_branch_assignments.txt similarity index 100% rename from hblang/tests/son_tests_branch_assignments.txt rename to lang/tests/son_tests_branch_assignments.txt diff --git a/hblang/tests/son_tests_comments.txt b/lang/tests/son_tests_comments.txt similarity index 100% rename from hblang/tests/son_tests_comments.txt rename to lang/tests/son_tests_comments.txt diff --git a/hblang/tests/son_tests_const_folding_with_arg.txt b/lang/tests/son_tests_const_folding_with_arg.txt similarity index 100% rename from hblang/tests/son_tests_const_folding_with_arg.txt rename to lang/tests/son_tests_const_folding_with_arg.txt diff --git a/hblang/tests/son_tests_exhaustive_loop_testing.txt b/lang/tests/son_tests_exhaustive_loop_testing.txt similarity index 100% rename from hblang/tests/son_tests_exhaustive_loop_testing.txt rename to lang/tests/son_tests_exhaustive_loop_testing.txt diff --git a/hblang/tests/son_tests_fb_driver.txt b/lang/tests/son_tests_fb_driver.txt similarity index 100% rename from hblang/tests/son_tests_fb_driver.txt rename to lang/tests/son_tests_fb_driver.txt diff --git a/hblang/tests/son_tests_functions.txt b/lang/tests/son_tests_functions.txt similarity index 100% rename from hblang/tests/son_tests_functions.txt rename to lang/tests/son_tests_functions.txt diff --git a/hblang/tests/son_tests_hex_octal_binary_literals.txt b/lang/tests/son_tests_hex_octal_binary_literals.txt similarity index 100% rename from hblang/tests/son_tests_hex_octal_binary_literals.txt rename to lang/tests/son_tests_hex_octal_binary_literals.txt diff --git a/hblang/tests/son_tests_if_statements.txt b/lang/tests/son_tests_if_statements.txt similarity index 100% rename from hblang/tests/son_tests_if_statements.txt rename to lang/tests/son_tests_if_statements.txt diff --git a/hblang/tests/son_tests_loops.txt b/lang/tests/son_tests_loops.txt similarity index 100% rename from hblang/tests/son_tests_loops.txt rename to lang/tests/son_tests_loops.txt diff --git a/hblang/tests/son_tests_pointer_opts.txt b/lang/tests/son_tests_pointer_opts.txt similarity index 100% rename from hblang/tests/son_tests_pointer_opts.txt rename to lang/tests/son_tests_pointer_opts.txt diff --git a/hblang/tests/son_tests_pointers.txt b/lang/tests/son_tests_pointers.txt similarity index 100% rename from hblang/tests/son_tests_pointers.txt rename to lang/tests/son_tests_pointers.txt diff --git a/hblang/tests/son_tests_structs.txt b/lang/tests/son_tests_structs.txt similarity index 100% rename from hblang/tests/son_tests_structs.txt rename to lang/tests/son_tests_structs.txt diff --git a/hblang/tests/son_tests_variables.txt b/lang/tests/son_tests_variables.txt similarity index 100% rename from hblang/tests/son_tests_variables.txt rename to lang/tests/son_tests_variables.txt diff --git a/hbvm/Cargo.toml b/vm/Cargo.toml similarity index 66% rename from hbvm/Cargo.toml rename to vm/Cargo.toml index a6e25b0..bc63d30 100644 --- a/hbvm/Cargo.toml +++ b/vm/Cargo.toml @@ -9,4 +9,4 @@ alloc = [] nightly = [] [dependencies] -hbbytecode = { path = "../hbbytecode", default-features = false } +hbbytecode = { workspace = true } diff --git a/hbvm/README.md b/vm/README.md similarity index 100% rename from hbvm/README.md rename to vm/README.md diff --git a/hbvm/assets/add.hb b/vm/assets/add.hb similarity index 100% rename from hbvm/assets/add.hb rename to vm/assets/add.hb diff --git a/hbvm/assets/celsius_converter.hb b/vm/assets/celsius_converter.hb similarity index 100% rename from hbvm/assets/celsius_converter.hb rename to vm/assets/celsius_converter.hb diff --git a/hbvm/assets/ecall.hb b/vm/assets/ecall.hb similarity index 100% rename from hbvm/assets/ecall.hb rename to vm/assets/ecall.hb diff --git a/hbvm/assets/inf_loop.hb b/vm/assets/inf_loop.hb similarity index 100% rename from hbvm/assets/inf_loop.hb rename to vm/assets/inf_loop.hb diff --git a/hbvm/assets/memory.hb b/vm/assets/memory.hb similarity index 100% rename from hbvm/assets/memory.hb rename to vm/assets/memory.hb diff --git a/hbvm/fuzz/.gitignore b/vm/fuzz/.gitignore similarity index 100% rename from hbvm/fuzz/.gitignore rename to vm/fuzz/.gitignore diff --git a/hbvm/fuzz/Cargo.toml b/vm/fuzz/Cargo.toml similarity index 100% rename from hbvm/fuzz/Cargo.toml rename to vm/fuzz/Cargo.toml diff --git a/hbvm/fuzz/fuzz_targets/vm.rs b/vm/fuzz/fuzz_targets/vm.rs similarity index 100% rename from hbvm/fuzz/fuzz_targets/vm.rs rename to vm/fuzz/fuzz_targets/vm.rs diff --git a/hbvm/src/bmc.rs b/vm/src/bmc.rs similarity index 100% rename from hbvm/src/bmc.rs rename to vm/src/bmc.rs diff --git a/hbvm/src/float/aarch64.rs b/vm/src/float/aarch64.rs similarity index 100% rename from hbvm/src/float/aarch64.rs rename to vm/src/float/aarch64.rs diff --git a/hbvm/src/float/mod.rs b/vm/src/float/mod.rs similarity index 100% rename from hbvm/src/float/mod.rs rename to vm/src/float/mod.rs diff --git a/hbvm/src/float/riscv64.rs b/vm/src/float/riscv64.rs similarity index 100% rename from hbvm/src/float/riscv64.rs rename to vm/src/float/riscv64.rs diff --git a/hbvm/src/float/unsupported.rs b/vm/src/float/unsupported.rs similarity index 100% rename from hbvm/src/float/unsupported.rs rename to vm/src/float/unsupported.rs diff --git a/hbvm/src/float/x86_64.rs b/vm/src/float/x86_64.rs similarity index 100% rename from hbvm/src/float/x86_64.rs rename to vm/src/float/x86_64.rs diff --git a/hbvm/src/lib.rs b/vm/src/lib.rs similarity index 100% rename from hbvm/src/lib.rs rename to vm/src/lib.rs diff --git a/hbvm/src/mem/addr.rs b/vm/src/mem/addr.rs similarity index 100% rename from hbvm/src/mem/addr.rs rename to vm/src/mem/addr.rs diff --git a/hbvm/src/mem/mod.rs b/vm/src/mem/mod.rs similarity index 100% rename from hbvm/src/mem/mod.rs rename to vm/src/mem/mod.rs diff --git a/hbvm/src/mem/softpaging/icache.rs b/vm/src/mem/softpaging/icache.rs similarity index 100% rename from hbvm/src/mem/softpaging/icache.rs rename to vm/src/mem/softpaging/icache.rs diff --git a/hbvm/src/mem/softpaging/lookup.rs b/vm/src/mem/softpaging/lookup.rs similarity index 100% rename from hbvm/src/mem/softpaging/lookup.rs rename to vm/src/mem/softpaging/lookup.rs diff --git a/hbvm/src/mem/softpaging/mapping.rs b/vm/src/mem/softpaging/mapping.rs similarity index 100% rename from hbvm/src/mem/softpaging/mapping.rs rename to vm/src/mem/softpaging/mapping.rs diff --git a/hbvm/src/mem/softpaging/mod.rs b/vm/src/mem/softpaging/mod.rs similarity index 100% rename from hbvm/src/mem/softpaging/mod.rs rename to vm/src/mem/softpaging/mod.rs diff --git a/hbvm/src/mem/softpaging/paging.rs b/vm/src/mem/softpaging/paging.rs similarity index 100% rename from hbvm/src/mem/softpaging/paging.rs rename to vm/src/mem/softpaging/paging.rs diff --git a/hbvm/src/utils.rs b/vm/src/utils.rs similarity index 100% rename from hbvm/src/utils.rs rename to vm/src/utils.rs diff --git a/hbvm/src/value.rs b/vm/src/value.rs similarity index 100% rename from hbvm/src/value.rs rename to vm/src/value.rs diff --git a/hbvm/src/vmrun.rs b/vm/src/vmrun.rs similarity index 100% rename from hbvm/src/vmrun.rs rename to vm/src/vmrun.rs diff --git a/hbxrt/Cargo.toml b/xrt/Cargo.toml similarity index 85% rename from hbxrt/Cargo.toml rename to xrt/Cargo.toml index 73c98b7..2d26202 100644 --- a/hbxrt/Cargo.toml +++ b/xrt/Cargo.toml @@ -5,5 +5,5 @@ edition = "2021" default-run = "hbxrt" [dependencies] -hbvm.path = "../hbvm" +hbvm.workspace = true memmap2 = "0.9" diff --git a/hbxrt/src/main.rs b/xrt/src/main.rs similarity index 100% rename from hbxrt/src/main.rs rename to xrt/src/main.rs diff --git a/hbxrt/src/mem.rs b/xrt/src/mem.rs similarity index 100% rename from hbxrt/src/mem.rs rename to xrt/src/mem.rs diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 164582c..0016d82 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -13,10 +13,30 @@ fn root() -> &'static Path { Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap() } +fn exec(cmd: impl AsRef) -> io::Result<()> { + let mut args = cmd.as_ref().split_whitespace(); + let mut c = std::process::Command::new(args.next().unwrap()); + for arg in args { + c.arg(arg); + } + if !c.status()?.success() { + return Err(io::Error::other(format!("command failed: {}", cmd.as_ref()))); + } + Ok(()) +} + fn main() -> io::Result<()> { - let args = std::env::args().collect::>(); + let args = std::env::args().skip(1).collect::>(); match args[0].as_str() { "fmt" => fmt(args[1] == "-r" || args[1] == "--renumber"), + "build-depell" => { + exec( + "cargo build -p wasm-hbfmt --target wasm32-unknown-unknown \ + --profile=small -Zbuild-std=core,alloc", + )?; + exec("cargo build -p depell --release")?; + Ok(()) + } _ => Ok(()), } } @@ -25,7 +45,7 @@ pub fn fmt(renumber: bool) -> io::Result<()> { let mut file = File::options() .read(true) .write(true) - .open(crate::root().join("hbbytecode/instructions.in"))?; + .open(crate::root().join("bytecode/instructions.in"))?; // Extract records let reader = BufReader::new(&file);