holey-bytes/hbvm/src/bytecode.rs

57 lines
1.2 KiB
Rust
Raw Normal View History

pub const REG_COUNT: usize = 60;
macro_rules! constmod {
($vis:vis $mname:ident($repr:ty) { $($cname:ident = $val:expr),* $(,)? }) => {
$vis mod $mname {
$(pub const $cname: $repr = $val;)*
}
};
}
constmod!(pub opcode(u8) {
2023-06-06 15:56:28 -05:00
NOP = 0, // N
ADD = 1, // RRR
SUB = 2, // RRR
MUL = 3, // RRR
DIV = 4, // RRR
REM = 5, // RRR
AND = 6, // RRR
OR = 7, // RRR
XOR = 8, // RRR
NOT = 9, // RR
// TODO: Add instruction for integer and float
// reg ← reg + imm instructions
ADDF = 10, // RRR
SUBF = 11, // RRR
MULF = 12, // RRR
DIVF = 13, // RRR
LI = 14, // RI
LD = 15, // RI
ST = 16, // RI
MAPPAGE = 17, // ?
UNMAPPAGE = 18, // ?
JMP = 100, // I
JMPCOND = 101, // I
2023-06-06 15:56:28 -05:00
RET = 103, // N
ECALL = 255, // N
});
#[repr(packed)] pub struct ParamRRR(pub u8, pub u8, pub u8);
#[repr(packed)] pub struct ParamRR(pub u8, pub u8);
#[repr(packed)] pub struct ParamRI(pub u8, pub u64);
/// # Safety
/// TODO.
pub unsafe trait OpParam {}
unsafe impl OpParam for ParamRRR {}
unsafe impl OpParam for ParamRR {}
unsafe impl OpParam for ParamRI {}
unsafe impl OpParam for u64 {}
unsafe impl OpParam for () {}