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/bytecode/src/instrs.rs b/bytecode/src/instrs.rs new file mode 100644 index 0000000..022583f --- /dev/null +++ b/bytecode/src/instrs.rs @@ -0,0 +1,904 @@ +#![allow(dead_code)] #![allow(clippy::upper_case_acronyms)] +use crate::*; +#[derive(Clone, Copy, Debug)] +#[repr(packed)] +pub struct OpsN(); +unsafe impl BytecodeItem for OpsN {} +#[derive(Clone, Copy, Debug)] +#[repr(packed)] +pub struct OpsRRR(pub OpR,pub OpR,pub OpR); +unsafe impl BytecodeItem for OpsRRR {} +#[derive(Clone, Copy, Debug)] +#[repr(packed)] +pub struct OpsRRRR(pub OpR,pub OpR,pub OpR,pub OpR); +unsafe impl BytecodeItem for OpsRRRR {} +#[derive(Clone, Copy, Debug)] +#[repr(packed)] +pub struct OpsRR(pub OpR,pub OpR); +unsafe impl BytecodeItem for OpsRR {} +#[derive(Clone, Copy, Debug)] +#[repr(packed)] +pub struct OpsRRB(pub OpR,pub OpR,pub OpB); +unsafe impl BytecodeItem for OpsRRB {} +#[derive(Clone, Copy, Debug)] +#[repr(packed)] +pub struct OpsRRH(pub OpR,pub OpR,pub OpH); +unsafe impl BytecodeItem for OpsRRH {} +#[derive(Clone, Copy, Debug)] +#[repr(packed)] +pub struct OpsRRW(pub OpR,pub OpR,pub OpW); +unsafe impl BytecodeItem for OpsRRW {} +#[derive(Clone, Copy, Debug)] +#[repr(packed)] +pub struct OpsRRD(pub OpR,pub OpR,pub OpD); +unsafe impl BytecodeItem for OpsRRD {} +#[derive(Clone, Copy, Debug)] +#[repr(packed)] +pub struct OpsRB(pub OpR,pub OpB); +unsafe impl BytecodeItem for OpsRB {} +#[derive(Clone, Copy, Debug)] +#[repr(packed)] +pub struct OpsRH(pub OpR,pub OpH); +unsafe impl BytecodeItem for OpsRH {} +#[derive(Clone, Copy, Debug)] +#[repr(packed)] +pub struct OpsRW(pub OpR,pub OpW); +unsafe impl BytecodeItem for OpsRW {} +#[derive(Clone, Copy, Debug)] +#[repr(packed)] +pub struct OpsRD(pub OpR,pub OpD); +unsafe impl BytecodeItem for OpsRD {} +#[derive(Clone, Copy, Debug)] +#[repr(packed)] +pub struct OpsRRO(pub OpR,pub OpR,pub OpO); +unsafe impl BytecodeItem for OpsRRO {} +#[derive(Clone, Copy, Debug)] +#[repr(packed)] +pub struct OpsRRAH(pub OpR,pub OpR,pub OpA,pub OpH); +unsafe impl BytecodeItem for OpsRRAH {} +#[derive(Clone, Copy, Debug)] +#[repr(packed)] +pub struct OpsRROH(pub OpR,pub OpR,pub OpO,pub OpH); +unsafe impl BytecodeItem for OpsRROH {} +#[derive(Clone, Copy, Debug)] +#[repr(packed)] +pub struct OpsO(pub OpO); +unsafe impl BytecodeItem for OpsO {} +#[derive(Clone, Copy, Debug)] +#[repr(packed)] +pub struct OpsRRA(pub OpR,pub OpR,pub OpA); +unsafe impl BytecodeItem for OpsRRA {} +#[derive(Clone, Copy, Debug)] +#[repr(packed)] +pub struct OpsRRP(pub OpR,pub OpR,pub OpP); +unsafe impl BytecodeItem for OpsRRP {} +#[derive(Clone, Copy, Debug)] +#[repr(packed)] +pub struct OpsRRPH(pub OpR,pub OpR,pub OpP,pub OpH); +unsafe impl BytecodeItem for OpsRRPH {} +#[derive(Clone, Copy, Debug)] +#[repr(packed)] +pub struct OpsP(pub OpP); +unsafe impl BytecodeItem for OpsP {} +pub const MAX_SIZE: usize = 13; +/// Cause an unreachable code trap +pub fn un() -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(N(0x00, )) } +} +/// Termiante execution +pub fn tx() -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(N(0x01, )) } +} +/// Do nothing +pub fn nop() -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(N(0x02, )) } +} +/// Addition (8b) +pub fn add8(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x03, reg0, reg1, reg2)) } +} +/// Addition (16b) +pub fn add16(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x04, reg0, reg1, reg2)) } +} +/// Addition (32b) +pub fn add32(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x05, reg0, reg1, reg2)) } +} +/// Addition (64b) +pub fn add64(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x06, reg0, reg1, reg2)) } +} +/// Subtraction (8b) +pub fn sub8(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x07, reg0, reg1, reg2)) } +} +/// Subtraction (16b) +pub fn sub16(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x08, reg0, reg1, reg2)) } +} +/// Subtraction (32b) +pub fn sub32(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x09, reg0, reg1, reg2)) } +} +/// Subtraction (64b) +pub fn sub64(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x0A, reg0, reg1, reg2)) } +} +/// Multiplication (8b) +pub fn mul8(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x0B, reg0, reg1, reg2)) } +} +/// Multiplication (16b) +pub fn mul16(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x0C, reg0, reg1, reg2)) } +} +/// Multiplication (32b) +pub fn mul32(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x0D, reg0, reg1, reg2)) } +} +/// Multiplication (64b) +pub fn mul64(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x0E, reg0, reg1, reg2)) } +} +/// Bitand +pub fn and(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x0F, reg0, reg1, reg2)) } +} +/// Bitor +pub fn or(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x10, reg0, reg1, reg2)) } +} +/// Bitxor +pub fn xor(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x11, reg0, reg1, reg2)) } +} +/// Unsigned left bitshift (8b) +pub fn slu8(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x12, reg0, reg1, reg2)) } +} +/// Unsigned left bitshift (16b) +pub fn slu16(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x13, reg0, reg1, reg2)) } +} +/// Unsigned left bitshift (32b) +pub fn slu32(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x14, reg0, reg1, reg2)) } +} +/// Unsigned left bitshift (64b) +pub fn slu64(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x15, reg0, reg1, reg2)) } +} +/// Unsigned right bitshift (8b) +pub fn sru8(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x16, reg0, reg1, reg2)) } +} +/// Unsigned right bitshift (16b) +pub fn sru16(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x17, reg0, reg1, reg2)) } +} +/// Unsigned right bitshift (32b) +pub fn sru32(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x18, reg0, reg1, reg2)) } +} +/// Unsigned right bitshift (64b) +pub fn sru64(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x19, reg0, reg1, reg2)) } +} +/// Signed right bitshift (8b) +pub fn srs8(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x1A, reg0, reg1, reg2)) } +} +/// Signed right bitshift (16b) +pub fn srs16(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x1B, reg0, reg1, reg2)) } +} +/// Signed right bitshift (32b) +pub fn srs32(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x1C, reg0, reg1, reg2)) } +} +/// Signed right bitshift (64b) +pub fn srs64(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x1D, reg0, reg1, reg2)) } +} +/// Unsigned comparsion +pub fn cmpu(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x1E, reg0, reg1, reg2)) } +} +/// Signed comparsion +pub fn cmps(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x1F, reg0, reg1, reg2)) } +} +/// Merged divide-remainder (unsigned 8b) +pub fn diru8(reg0: u8, reg1: u8, reg2: u8, reg3: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRRR(0x20, reg0, reg1, reg2, reg3)) } +} +/// Merged divide-remainder (unsigned 16b) +pub fn diru16(reg0: u8, reg1: u8, reg2: u8, reg3: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRRR(0x21, reg0, reg1, reg2, reg3)) } +} +/// Merged divide-remainder (unsigned 32b) +pub fn diru32(reg0: u8, reg1: u8, reg2: u8, reg3: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRRR(0x22, reg0, reg1, reg2, reg3)) } +} +/// Merged divide-remainder (unsigned 64b) +pub fn diru64(reg0: u8, reg1: u8, reg2: u8, reg3: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRRR(0x23, reg0, reg1, reg2, reg3)) } +} +/// Merged divide-remainder (signed 8b) +pub fn dirs8(reg0: u8, reg1: u8, reg2: u8, reg3: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRRR(0x24, reg0, reg1, reg2, reg3)) } +} +/// Merged divide-remainder (signed 16b) +pub fn dirs16(reg0: u8, reg1: u8, reg2: u8, reg3: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRRR(0x25, reg0, reg1, reg2, reg3)) } +} +/// Merged divide-remainder (signed 32b) +pub fn dirs32(reg0: u8, reg1: u8, reg2: u8, reg3: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRRR(0x26, reg0, reg1, reg2, reg3)) } +} +/// Merged divide-remainder (signed 64b) +pub fn dirs64(reg0: u8, reg1: u8, reg2: u8, reg3: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRRR(0x27, reg0, reg1, reg2, reg3)) } +} +/// Bit negation +pub fn neg(reg0: u8, reg1: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RR(0x28, reg0, reg1)) } +} +/// Logical negation +pub fn not(reg0: u8, reg1: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RR(0x29, reg0, reg1)) } +} +/// Sign extend 8b to 64b +pub fn sxt8(reg0: u8, reg1: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RR(0x2A, reg0, reg1)) } +} +/// Sign extend 16b to 64b +pub fn sxt16(reg0: u8, reg1: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RR(0x2B, reg0, reg1)) } +} +/// Sign extend 32b to 64b +pub fn sxt32(reg0: u8, reg1: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RR(0x2C, reg0, reg1)) } +} +/// Addition with immediate (8b) +pub fn addi8(reg0: u8, reg1: u8, imm2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRB(0x2D, reg0, reg1, imm2)) } +} +/// Addition with immediate (16b) +pub fn addi16(reg0: u8, reg1: u8, imm2: u16) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRH(0x2E, reg0, reg1, imm2)) } +} +/// Addition with immediate (32b) +pub fn addi32(reg0: u8, reg1: u8, imm2: u32) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRW(0x2F, reg0, reg1, imm2)) } +} +/// Addition with immediate (64b) +pub fn addi64(reg0: u8, reg1: u8, imm2: u64) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRD(0x30, reg0, reg1, imm2)) } +} +/// Multiplication with immediate (8b) +pub fn muli8(reg0: u8, reg1: u8, imm2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRB(0x31, reg0, reg1, imm2)) } +} +/// Multiplication with immediate (16b) +pub fn muli16(reg0: u8, reg1: u8, imm2: u16) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRH(0x32, reg0, reg1, imm2)) } +} +/// Multiplication with immediate (32b) +pub fn muli32(reg0: u8, reg1: u8, imm2: u32) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRW(0x33, reg0, reg1, imm2)) } +} +/// Multiplication with immediate (64b) +pub fn muli64(reg0: u8, reg1: u8, imm2: u64) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRD(0x34, reg0, reg1, imm2)) } +} +/// Bitand with immediate +pub fn andi(reg0: u8, reg1: u8, imm2: u64) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRD(0x35, reg0, reg1, imm2)) } +} +/// Bitor with immediate +pub fn ori(reg0: u8, reg1: u8, imm2: u64) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRD(0x36, reg0, reg1, imm2)) } +} +/// Bitxor with immediate +pub fn xori(reg0: u8, reg1: u8, imm2: u64) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRD(0x37, reg0, reg1, imm2)) } +} +/// Unsigned left bitshift with immedidate (8b) +pub fn slui8(reg0: u8, reg1: u8, imm2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRB(0x38, reg0, reg1, imm2)) } +} +/// Unsigned left bitshift with immedidate (16b) +pub fn slui16(reg0: u8, reg1: u8, imm2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRB(0x39, reg0, reg1, imm2)) } +} +/// Unsigned left bitshift with immedidate (32b) +pub fn slui32(reg0: u8, reg1: u8, imm2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRB(0x3A, reg0, reg1, imm2)) } +} +/// Unsigned left bitshift with immedidate (64b) +pub fn slui64(reg0: u8, reg1: u8, imm2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRB(0x3B, reg0, reg1, imm2)) } +} +/// Unsigned right bitshift with immediate (8b) +pub fn srui8(reg0: u8, reg1: u8, imm2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRB(0x3C, reg0, reg1, imm2)) } +} +/// Unsigned right bitshift with immediate (16b) +pub fn srui16(reg0: u8, reg1: u8, imm2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRB(0x3D, reg0, reg1, imm2)) } +} +/// Unsigned right bitshift with immediate (32b) +pub fn srui32(reg0: u8, reg1: u8, imm2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRB(0x3E, reg0, reg1, imm2)) } +} +/// Unsigned right bitshift with immediate (64b) +pub fn srui64(reg0: u8, reg1: u8, imm2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRB(0x3F, reg0, reg1, imm2)) } +} +/// Signed right bitshift with immediate +pub fn srsi8(reg0: u8, reg1: u8, imm2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRB(0x40, reg0, reg1, imm2)) } +} +/// Signed right bitshift with immediate +pub fn srsi16(reg0: u8, reg1: u8, imm2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRB(0x41, reg0, reg1, imm2)) } +} +/// Signed right bitshift with immediate +pub fn srsi32(reg0: u8, reg1: u8, imm2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRB(0x42, reg0, reg1, imm2)) } +} +/// Signed right bitshift with immediate +pub fn srsi64(reg0: u8, reg1: u8, imm2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRB(0x43, reg0, reg1, imm2)) } +} +/// Unsigned compare with immediate +pub fn cmpui(reg0: u8, reg1: u8, imm2: u64) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRD(0x44, reg0, reg1, imm2)) } +} +/// Signed compare with immediate +pub fn cmpsi(reg0: u8, reg1: u8, imm2: u64) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRD(0x45, reg0, reg1, imm2)) } +} +/// Copy register +pub fn cp(reg0: u8, reg1: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RR(0x46, reg0, reg1)) } +} +/// Swap registers +pub fn swa(reg0: u8, reg1: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RR(0x47, reg0, reg1)) } +} +/// Load immediate (8b) +pub fn li8(reg0: u8, imm1: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RB(0x48, reg0, imm1)) } +} +/// Load immediate (16b) +pub fn li16(reg0: u8, imm1: u16) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RH(0x49, reg0, imm1)) } +} +/// Load immediate (32b) +pub fn li32(reg0: u8, imm1: u32) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RW(0x4A, reg0, imm1)) } +} +/// Load immediate (64b) +pub fn li64(reg0: u8, imm1: u64) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RD(0x4B, reg0, imm1)) } +} +/// Load relative address +pub fn lra(reg0: u8, reg1: u8, offset2: i32) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRO(0x4C, reg0, reg1, offset2)) } +} +/// Load from absolute address +pub fn ld(reg0: u8, reg1: u8, addr2: u64, imm3: u16) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRAH(0x4D, reg0, reg1, addr2, imm3)) } +} +/// Store to absolute address +pub fn st(reg0: u8, reg1: u8, addr2: u64, imm3: u16) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRAH(0x4E, reg0, reg1, addr2, imm3)) } +} +/// Load from relative address +pub fn ldr(reg0: u8, reg1: u8, offset2: i32, imm3: u16) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RROH(0x4F, reg0, reg1, offset2, imm3)) } +} +/// Store to relative address +pub fn str(reg0: u8, reg1: u8, offset2: i32, imm3: u16) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RROH(0x50, reg0, reg1, offset2, imm3)) } +} +/// Copy block of memory +pub fn bmc(reg0: u8, reg1: u8, imm2: u16) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRH(0x51, reg0, reg1, imm2)) } +} +/// Copy register block +pub fn brc(reg0: u8, reg1: u8, imm2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRB(0x52, reg0, reg1, imm2)) } +} +/// Relative jump +pub fn jmp(offset0: i32) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(O(0x53, offset0)) } +} +/// Linking relative jump +pub fn jal(reg0: u8, reg1: u8, offset2: i32) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRO(0x54, reg0, reg1, offset2)) } +} +/// Linking absolute jump +pub fn jala(reg0: u8, reg1: u8, addr2: u64) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRA(0x55, reg0, reg1, addr2)) } +} +/// Branch on equal +pub fn jeq(reg0: u8, reg1: u8, offset2: i16) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRP(0x56, reg0, reg1, offset2)) } +} +/// Branch on nonequal +pub fn jne(reg0: u8, reg1: u8, offset2: i16) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRP(0x57, reg0, reg1, offset2)) } +} +/// Branch on lesser-than (unsigned) +pub fn jltu(reg0: u8, reg1: u8, offset2: i16) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRP(0x58, reg0, reg1, offset2)) } +} +/// Branch on greater-than (unsigned) +pub fn jgtu(reg0: u8, reg1: u8, offset2: i16) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRP(0x59, reg0, reg1, offset2)) } +} +/// Branch on lesser-than (signed) +pub fn jlts(reg0: u8, reg1: u8, offset2: i16) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRP(0x5A, reg0, reg1, offset2)) } +} +/// Branch on greater-than (signed) +pub fn jgts(reg0: u8, reg1: u8, offset2: i16) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRP(0x5B, reg0, reg1, offset2)) } +} +/// Environment call trap +pub fn eca() -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(N(0x5C, )) } +} +/// Environment breakpoint +pub fn ebp() -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(N(0x5D, )) } +} +/// Floating point addition (32b) +pub fn fadd32(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x5E, reg0, reg1, reg2)) } +} +/// Floating point addition (64b) +pub fn fadd64(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x5F, reg0, reg1, reg2)) } +} +/// Floating point subtraction (32b) +pub fn fsub32(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x60, reg0, reg1, reg2)) } +} +/// Floating point subtraction (64b) +pub fn fsub64(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x61, reg0, reg1, reg2)) } +} +/// Floating point multiply (32b) +pub fn fmul32(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x62, reg0, reg1, reg2)) } +} +/// Floating point multiply (64b) +pub fn fmul64(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x63, reg0, reg1, reg2)) } +} +/// Floating point division (32b) +pub fn fdiv32(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x64, reg0, reg1, reg2)) } +} +/// Floating point division (64b) +pub fn fdiv64(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x65, reg0, reg1, reg2)) } +} +/// Float fused multiply-add (32b) +pub fn fma32(reg0: u8, reg1: u8, reg2: u8, reg3: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRRR(0x66, reg0, reg1, reg2, reg3)) } +} +/// Float fused multiply-add (64b) +pub fn fma64(reg0: u8, reg1: u8, reg2: u8, reg3: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRRR(0x67, reg0, reg1, reg2, reg3)) } +} +/// Float reciprocal (32b) +pub fn finv32(reg0: u8, reg1: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RR(0x68, reg0, reg1)) } +} +/// Float reciprocal (64b) +pub fn finv64(reg0: u8, reg1: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RR(0x69, reg0, reg1)) } +} +/// Flaot compare less than (32b) +pub fn fcmplt32(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x6A, reg0, reg1, reg2)) } +} +/// Flaot compare less than (64b) +pub fn fcmplt64(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x6B, reg0, reg1, reg2)) } +} +/// Flaot compare greater than (32b) +pub fn fcmpgt32(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x6C, reg0, reg1, reg2)) } +} +/// Flaot compare greater than (64b) +pub fn fcmpgt64(reg0: u8, reg1: u8, reg2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRR(0x6D, reg0, reg1, reg2)) } +} +/// Int to 32 bit float +pub fn itf32(reg0: u8, reg1: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RR(0x6E, reg0, reg1)) } +} +/// Int to 64 bit float +pub fn itf64(reg0: u8, reg1: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RR(0x6F, reg0, reg1)) } +} +/// Float 32 to int +pub fn fti32(reg0: u8, reg1: u8, imm2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRB(0x70, reg0, reg1, imm2)) } +} +/// Float 64 to int +pub fn fti64(reg0: u8, reg1: u8, imm2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRB(0x71, reg0, reg1, imm2)) } +} +/// Float 64 to Float 32 +pub fn fc32t64(reg0: u8, reg1: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RR(0x72, reg0, reg1)) } +} +/// Float 32 to Float 64 +pub fn fc64t32(reg0: u8, reg1: u8, imm2: u8) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRB(0x73, reg0, reg1, imm2)) } +} +/// Load relative immediate (16 bit) +pub fn lra16(reg0: u8, reg1: u8, offset2: i16) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRP(0x74, reg0, reg1, offset2)) } +} +/// Load from relative address (16 bit) +pub fn ldr16(reg0: u8, reg1: u8, offset2: i16, imm3: u16) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRPH(0x75, reg0, reg1, offset2, imm3)) } +} +/// Store to relative address (16 bit) +pub fn str16(reg0: u8, reg1: u8, offset2: i16, imm3: u16) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(RRPH(0x76, reg0, reg1, offset2, imm3)) } +} +/// Relative jump (16 bit) +pub fn jmp16(offset0: i16) -> (usize, [u8; MAX_SIZE]) { + unsafe { crate::encode(P(0x77, offset0)) } +} +#[repr(packed)] pub struct N(u8, ); +#[repr(packed)] pub struct RRR(u8, u8, u8, u8); +#[repr(packed)] pub struct RRRR(u8, u8, u8, u8, u8); +#[repr(packed)] pub struct RR(u8, u8, u8); +#[repr(packed)] pub struct RRB(u8, u8, u8, u8); +#[repr(packed)] pub struct RRH(u8, u8, u8, u16); +#[repr(packed)] pub struct RRW(u8, u8, u8, u32); +#[repr(packed)] pub struct RRD(u8, u8, u8, u64); +#[repr(packed)] pub struct RB(u8, u8, u8); +#[repr(packed)] pub struct RH(u8, u8, u16); +#[repr(packed)] pub struct RW(u8, u8, u32); +#[repr(packed)] pub struct RD(u8, u8, u64); +#[repr(packed)] pub struct RRO(u8, u8, u8, i32); +#[repr(packed)] pub struct RRAH(u8, u8, u8, u64, u16); +#[repr(packed)] pub struct RROH(u8, u8, u8, i32, u16); +#[repr(packed)] pub struct O(u8, i32); +#[repr(packed)] pub struct RRA(u8, u8, u8, u64); +#[repr(packed)] pub struct RRP(u8, u8, u8, i16); +#[repr(packed)] pub struct RRPH(u8, u8, u8, i16, u16); +#[repr(packed)] pub struct P(u8, i16); +pub const COUNT: u8 = 120; +#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[repr(u8)] +pub enum Instr { + UN = 0x00, + TX = 0x01, + NOP = 0x02, + ADD8 = 0x03, + ADD16 = 0x04, + ADD32 = 0x05, + ADD64 = 0x06, + SUB8 = 0x07, + SUB16 = 0x08, + SUB32 = 0x09, + SUB64 = 0x0A, + MUL8 = 0x0B, + MUL16 = 0x0C, + MUL32 = 0x0D, + MUL64 = 0x0E, + AND = 0x0F, + OR = 0x10, + XOR = 0x11, + SLU8 = 0x12, + SLU16 = 0x13, + SLU32 = 0x14, + SLU64 = 0x15, + SRU8 = 0x16, + SRU16 = 0x17, + SRU32 = 0x18, + SRU64 = 0x19, + SRS8 = 0x1A, + SRS16 = 0x1B, + SRS32 = 0x1C, + SRS64 = 0x1D, + CMPU = 0x1E, + CMPS = 0x1F, + DIRU8 = 0x20, + DIRU16 = 0x21, + DIRU32 = 0x22, + DIRU64 = 0x23, + DIRS8 = 0x24, + DIRS16 = 0x25, + DIRS32 = 0x26, + DIRS64 = 0x27, + NEG = 0x28, + NOT = 0x29, + SXT8 = 0x2A, + SXT16 = 0x2B, + SXT32 = 0x2C, + ADDI8 = 0x2D, + ADDI16 = 0x2E, + ADDI32 = 0x2F, + ADDI64 = 0x30, + MULI8 = 0x31, + MULI16 = 0x32, + MULI32 = 0x33, + MULI64 = 0x34, + ANDI = 0x35, + ORI = 0x36, + XORI = 0x37, + SLUI8 = 0x38, + SLUI16 = 0x39, + SLUI32 = 0x3A, + SLUI64 = 0x3B, + SRUI8 = 0x3C, + SRUI16 = 0x3D, + SRUI32 = 0x3E, + SRUI64 = 0x3F, + SRSI8 = 0x40, + SRSI16 = 0x41, + SRSI32 = 0x42, + SRSI64 = 0x43, + CMPUI = 0x44, + CMPSI = 0x45, + CP = 0x46, + SWA = 0x47, + LI8 = 0x48, + LI16 = 0x49, + LI32 = 0x4A, + LI64 = 0x4B, + LRA = 0x4C, + LD = 0x4D, + ST = 0x4E, + LDR = 0x4F, + STR = 0x50, + BMC = 0x51, + BRC = 0x52, + JMP = 0x53, + JAL = 0x54, + JALA = 0x55, + JEQ = 0x56, + JNE = 0x57, + JLTU = 0x58, + JGTU = 0x59, + JLTS = 0x5A, + JGTS = 0x5B, + ECA = 0x5C, + EBP = 0x5D, + FADD32 = 0x5E, + FADD64 = 0x5F, + FSUB32 = 0x60, + FSUB64 = 0x61, + FMUL32 = 0x62, + FMUL64 = 0x63, + FDIV32 = 0x64, + FDIV64 = 0x65, + FMA32 = 0x66, + FMA64 = 0x67, + FINV32 = 0x68, + FINV64 = 0x69, + FCMPLT32 = 0x6A, + FCMPLT64 = 0x6B, + FCMPGT32 = 0x6C, + FCMPGT64 = 0x6D, + ITF32 = 0x6E, + ITF64 = 0x6F, + FTI32 = 0x70, + FTI64 = 0x71, + FC32T64 = 0x72, + FC64T32 = 0x73, + LRA16 = 0x74, + LDR16 = 0x75, + STR16 = 0x76, + JMP16 = 0x77, +} +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Oper { + R(u8), + B(u8), + H(u16), + W(u32), + D(u64), + O(i32), + A(u64), + P(i16), +} +/// This assumes the instruction byte is still at the beginning of the buffer +#[cfg(feature = "disasm")] +pub fn parse_args(bytes: &mut &[u8], kind: Instr, buf: &mut alloc::vec::Vec) -> Option<()> { + match kind { + | Instr::TX + | Instr::NOP + | Instr::UN + | Instr::ECA + | Instr::EBP => { + crate::decode::(bytes)?; + } + | Instr::JMP => { + let data = crate::decode::(bytes)?; + buf.extend([Oper::O(data.1)]); + } + | Instr::JMP16 => { + let data = crate::decode::

(bytes)?; + buf.extend([Oper::P(data.1)]); + } + | Instr::LI8 => { + let data = crate::decode::(bytes)?; + buf.extend([Oper::R(data.1), Oper::B(data.2)]); + } + | Instr::LI64 => { + let data = crate::decode::(bytes)?; + buf.extend([Oper::R(data.1), Oper::D(data.2)]); + } + | Instr::LI16 => { + let data = crate::decode::(bytes)?; + buf.extend([Oper::R(data.1), Oper::H(data.2)]); + } + | Instr::NEG + | Instr::NOT + | Instr::SXT8 + | Instr::SXT16 + | Instr::SXT32 + | Instr::CP + | Instr::SWA + | Instr::FINV32 + | Instr::FINV64 + | Instr::ITF32 + | Instr::ITF64 + | Instr::FC32T64 => { + let data = crate::decode::(bytes)?; + buf.extend([Oper::R(data.1), Oper::R(data.2)]); + } + | Instr::JALA => { + let data = crate::decode::(bytes)?; + buf.extend([Oper::R(data.1), Oper::R(data.2), Oper::A(data.3)]); + } + | Instr::LD + | Instr::ST => { + let data = crate::decode::(bytes)?; + buf.extend([Oper::R(data.1), Oper::R(data.2), Oper::A(data.3), Oper::H(data.4)]); + } + | Instr::SRSI8 + | Instr::ADDI8 + | Instr::MULI8 + | Instr::SLUI8 + | Instr::SLUI16 + | Instr::SLUI32 + | Instr::SLUI64 + | Instr::SRUI8 + | Instr::SRUI16 + | Instr::SRUI32 + | Instr::SRUI64 + | Instr::SRSI16 + | Instr::SRSI32 + | Instr::BRC + | Instr::FTI32 + | Instr::FTI64 + | Instr::FC64T32 + | Instr::SRSI64 => { + let data = crate::decode::(bytes)?; + buf.extend([Oper::R(data.1), Oper::R(data.2), Oper::B(data.3)]); + } + | Instr::ADDI64 + | Instr::CMPUI + | Instr::CMPSI + | Instr::MULI64 + | Instr::ANDI + | Instr::ORI + | Instr::XORI => { + let data = crate::decode::(bytes)?; + buf.extend([Oper::R(data.1), Oper::R(data.2), Oper::D(data.3)]); + } + | Instr::ADDI16 + | Instr::MULI16 + | Instr::BMC => { + let data = crate::decode::(bytes)?; + buf.extend([Oper::R(data.1), Oper::R(data.2), Oper::H(data.3)]); + } + | Instr::LRA + | Instr::JAL => { + let data = crate::decode::(bytes)?; + buf.extend([Oper::R(data.1), Oper::R(data.2), Oper::O(data.3)]); + } + | Instr::LDR + | Instr::STR => { + let data = crate::decode::(bytes)?; + buf.extend([Oper::R(data.1), Oper::R(data.2), Oper::O(data.3), Oper::H(data.4)]); + } + | Instr::JEQ + | Instr::JNE + | Instr::JLTU + | Instr::JGTU + | Instr::JLTS + | Instr::JGTS + | Instr::LRA16 => { + let data = crate::decode::(bytes)?; + buf.extend([Oper::R(data.1), Oper::R(data.2), Oper::P(data.3)]); + } + | Instr::STR16 + | Instr::LDR16 => { + let data = crate::decode::(bytes)?; + buf.extend([Oper::R(data.1), Oper::R(data.2), Oper::P(data.3), Oper::H(data.4)]); + } + | Instr::SUB32 + | Instr::CMPU + | Instr::CMPS + | Instr::SRS8 + | Instr::SUB64 + | Instr::MUL8 + | Instr::MUL16 + | Instr::MUL32 + | Instr::MUL64 + | Instr::AND + | Instr::OR + | Instr::XOR + | Instr::ADD8 + | Instr::ADD16 + | Instr::SRS16 + | Instr::SLU8 + | Instr::SLU16 + | Instr::FADD32 + | Instr::FADD64 + | Instr::FSUB32 + | Instr::FSUB64 + | Instr::FMUL32 + | Instr::FMUL64 + | Instr::FDIV32 + | Instr::FDIV64 + | Instr::SLU32 + | Instr::SLU64 + | Instr::FCMPLT32 + | Instr::FCMPLT64 + | Instr::FCMPGT32 + | Instr::FCMPGT64 + | Instr::SRU8 + | Instr::SRU16 + | Instr::ADD64 + | Instr::SUB8 + | Instr::SRU32 + | Instr::SUB16 + | Instr::SRS32 + | Instr::SRS64 + | Instr::SRU64 + | Instr::ADD32 => { + let data = crate::decode::(bytes)?; + buf.extend([Oper::R(data.1), Oper::R(data.2), Oper::R(data.3)]); + } + | Instr::DIRU8 + | Instr::DIRS16 + | Instr::DIRS32 + | Instr::DIRS64 + | Instr::DIRU16 + | Instr::DIRU32 + | Instr::FMA32 + | Instr::FMA64 + | Instr::DIRU64 + | Instr::DIRS8 => { + let data = crate::decode::(bytes)?; + buf.extend([Oper::R(data.1), Oper::R(data.2), Oper::R(data.3), Oper::R(data.4)]); + } + | Instr::MULI32 + | Instr::ADDI32 => { + let data = crate::decode::(bytes)?; + buf.extend([Oper::R(data.1), Oper::R(data.2), Oper::W(data.3)]); + } + | Instr::LI32 => { + let data = crate::decode::(bytes)?; + buf.extend([Oper::R(data.1), Oper::W(data.2)]); + } + } + Some(()) +} 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);