diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/bytecode/bytecode.h | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/include/bytecode/bytecode.h b/include/bytecode/bytecode.h index e5a70e9..600c9f2 100644 --- a/include/bytecode/bytecode.h +++ b/include/bytecode/bytecode.h @@ -8,12 +8,46 @@ #include <setjmp.h> +/*doc(Opcode) + # Opcode + Variable length opcodes. Sizes range from 1 to 4 bytes. + # Instruction formats + Instructions can be in 6 different formats: + 1. 1 byte: Opcode + 2. 2 bytes: Opcode + register + 3. 3 bytes: Opcode + register + register + 4. 3 bytes:\ + 4.1 Opcode + intermediate\ + 4.2 Opcode + data\ + 4.3 Opcode + index\ + 4.4 Opcode + offset + 5. 4 bytes: Opcode + register + register + register + 6. 4 bytes: Opcode + register + offset +*/ typedef enum { - NOP /* To allow hot-patching */ - -} BytecodeInstruction; + AMAL_OP_NOP, /* No operation. This can be used for patching */ + AMAL_OP_SETZ, /* setz reg - Set register value to 0 */ + AMAL_OP_MOV, /* mov dst, src - move src register to dst register */ + AMAL_OP_MOVI, /* movi dst, src - move src intermediate to dst register */ + AMAL_OP_MOVD, /* movd dst, src - move src data to dst register */ + AMAL_OP_ADD, /* add dst, reg1, reg2 */ + AMAL_OP_SUB, /* sub dst, reg1, reg2 */ + AMAL_OP_MUL, /* mul dst, reg1, reg2 */ + AMAL_OP_DIV, /* div dst, reg1, reg2 */ + AMAL_OP_PUSH, /* push reg - Push register onto stack */ + AMAL_OP_PUSHI, /* pushi int - Push intermediate onto stack */ + AMAL_OP_PUSHD, /* pushd data - Push data onto stack */ + AMAL_OP_CALL, /* call fi - Call a function using function index (fi). fi is u16 */ + AMAL_OP_CALLR, /* callr reg - Call a function using a register. Used for function pointers */ + AMAL_OP_CMP, /* cmp dst, reg1, reg2 - Set dst to 1 if reg1 equals reg2, otherwise set it to 0 */ + AMAL_OP_JZ, /* jz reg, offset - jump to offset if reg is zero. offset is i16 */ + AMAL_OP_JMP, /* jmp offset - unconditional jump to offset. offset is i16 */ + AMAL_OP_RET, /* ret */ + AMAL_OP_FUNC_START, /* func_start */ + AMAL_OP_FUNC_END /* func_end */ +} AmalOpcode; -typedef u8 BytecodeInstructionType; +typedef u8 AmalOpcodeType; typedef struct { Buffer/*<instruction data>*/ instructions; |