diff --git a/hbvm/src/bytecode/mod.rs b/hbvm/src/bytecode/mod.rs index 414c60d2..73d06871 100644 --- a/hbvm/src/bytecode/mod.rs +++ b/hbvm/src/bytecode/mod.rs @@ -1,2 +1,39 @@ -pub mod ops; -pub mod types; +mod validate; + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[repr(u8)] +pub enum Instruction { + Nop = 0, + Add(Register, Register, Register), + Sub(Register, Register, Register) = 2, + Mul(Register, Register, Register) = 3, + Div(Register, Register, Register) = 4, + Mod(Register, Register, Register) = 5, + + And(Register, Register, Register) = 6, + Or(Register, Register, Register) = 7, + Xor(Register, Register, Register) = 8, + Not(Register, Register) = 9, + + Li(Register, u64) = 10, + Ld(Register, u64) = 15, + St(Register, u64) = 16, + + MapPage = 17, + UnmapPage = 18, + + Jmp = 100, + JumpCond = 101, + Ret = 103, + Ecall = 255, +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[repr(u8)] +#[rustfmt::skip] +pub enum Register { + X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, + X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35, X36, X37, X38, X39, + X40, X41, X42, X43, X44, X45, X46, X47, X48, X49, X50, X51, X52, X53, X54, X55, X56, X57, X58, + X59, +} diff --git a/hbvm/src/bytecode/ops.rs b/hbvm/src/bytecode/ops.rs deleted file mode 100644 index 2b23ae8a..00000000 --- a/hbvm/src/bytecode/ops.rs +++ /dev/null @@ -1,68 +0,0 @@ -#[repr(u8)] -pub enum Operations { - NOP = 0, - - ADD = 1, - SUB = 2, - MUL = 3, - DIV = 4, - MOD = 5, - - AND = 6, - OR = 7, - XOR = 8, - NOT = 9, - - // LOADs a memory address/constant into a register - LOAD = 15, - // STOREs a register/constant into a memory address - STORE = 16, - - MapPage = 17, - UnmapPage = 18, - - // SHIFT LEFT 16 A0 - Shift = 20, - - JUMP = 100, - JumpCond = 101, - RET = 103, - - EnviromentCall = 255, -} - -pub enum PageMapTypes { - // Have the host make a new VMPage - VMPage = 0, - // Ask the host to map a RealPage into memory - RealPage = 1, -} - -pub enum MathOpSubTypes { - Unsigned = 0, - Signed = 1, - FloatingPoint = 2, -} - -pub enum MathOpSides { - RegisterConstant = 0, - RegisterRegister = 1, - ConstantConstant = 2, - ConstantRegister = 3, -} - -pub enum RWSubTypes { - AddrToReg = 0, - RegToAddr, - ConstToReg, - ConstToAddr, -} - -pub enum JumpConditionals { - Equal = 0, - NotEqual = 1, - LessThan = 2, - LessThanOrEqualTo = 3, - GreaterThan = 4, - GreaterThanOrEqualTo = 5, -} diff --git a/hbvm/src/bytecode/types.rs b/hbvm/src/bytecode/types.rs deleted file mode 100644 index 1e98c23b..00000000 --- a/hbvm/src/bytecode/types.rs +++ /dev/null @@ -1,9 +0,0 @@ - -pub const CONST_U8: u8 = 0x00; -pub const CONST_I8: i8 = 0x01; - -pub const CONST_U64: u8 = 0x02; -pub const CONST_I64: u8 = 0x03; -pub const CONST_F64: u8 = 0x04; - -pub const ADDRESS: u8 = 0x05; diff --git a/hbvm/src/bytecode/validate.rs b/hbvm/src/bytecode/validate.rs new file mode 100644 index 00000000..e69de29b diff --git a/hbvm/src/main.rs b/hbvm/src/main.rs index a873e577..a5462df6 100644 --- a/hbvm/src/main.rs +++ b/hbvm/src/main.rs @@ -1,5 +1,5 @@ use hbvm::{ - bytecode::ops::{Operations::*}, + bytecode::Instruction, engine::Engine, RuntimeErrors, HaltStatus, }; @@ -8,8 +8,6 @@ fn main() -> Result<(), RuntimeErrors> { // TODO: Grab program from cmdline #[rustfmt::skip] let prog: Vec = vec![ - NOP as u8, - JUMP as u8, 0, 0, 0, 0, 0, 0, 0, 0, ]; let mut eng = Engine::new(prog);