Add object layout, object parsing, instruction layout
* Object layout and parsing are done in the vm::obj module * Add MemCursor, a wrapper around the std::io::Cursor type for walking through VM memory * Add vm::tick module for containing the Vm::tick() method implementation, since it's pretty big * Instructions are now variable-sized, and are read lazily, one-at-a-time directly from memory. * Add VM runtime error structure * Probably some other stuff I forgot Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -1,33 +1,39 @@
|
||||
use crate::vm::reg::*;
|
||||
macro_rules! instructions {
|
||||
{
|
||||
$($variant:ident = $value:expr),* $(,)?
|
||||
} => {
|
||||
pub type InstOp = u16;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[allow(dead_code)]
|
||||
pub enum Inst {
|
||||
Add(Reg, Reg),
|
||||
Mul(Reg, Reg),
|
||||
Div(Reg, Reg),
|
||||
Mod(Reg, Reg),
|
||||
INeg(Reg),
|
||||
And(Reg, Reg),
|
||||
Or(Reg, Reg),
|
||||
Xor(Reg, Reg),
|
||||
Shl(Reg, Reg),
|
||||
Shr(Reg, Reg),
|
||||
|
||||
CmpEq(Reg, Reg),
|
||||
CmpLt(Reg, Reg),
|
||||
Jmp(Reg),
|
||||
Jz(Reg),
|
||||
Jnz(Reg),
|
||||
|
||||
Load(Reg, Reg),
|
||||
Store(Reg, Reg),
|
||||
StoreImm(Reg, u64),
|
||||
MemCopy(Reg, Reg),
|
||||
RegCopy(Reg, Reg),
|
||||
|
||||
Nop,
|
||||
Halt,
|
||||
$(
|
||||
pub const $variant: InstOp = $value;
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
||||
// https://crates.io/crates/packed_struct
|
||||
instructions! {
|
||||
ADD = 0x0000,
|
||||
MUL = 0x0001,
|
||||
DIV = 0x0002,
|
||||
MOD = 0x0003,
|
||||
INEG = 0x0004,
|
||||
AND = 0x0005,
|
||||
OR = 0x0006,
|
||||
INV = 0x0007,
|
||||
NOT = 0x0008,
|
||||
XOR = 0x0009,
|
||||
SHL = 0x000a,
|
||||
SHR = 0x000b,
|
||||
CMPEQ = 0x1000,
|
||||
CMPLT = 0x1001,
|
||||
JMP = 0x1100,
|
||||
JZ = 0x1101,
|
||||
JNZ = 0x1102,
|
||||
LOAD = 0x2000,
|
||||
REGCOPY = 0x2001,
|
||||
STOREIMM64 = 0x2100,
|
||||
STOREIMM32 = 0x2101,
|
||||
MEMCOPY = 0x2200,
|
||||
STORE = 0x2201,
|
||||
HALT = 0xF000,
|
||||
NOP = 0xF001,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user