This commit is contained in:
2025-01-18 13:56:46 +05:00
parent bd8215fd73
commit dbe8569a3b
11 changed files with 143 additions and 75 deletions

View File

@@ -5,30 +5,32 @@
///@returns number of bytes read
typedef i32 (*InstructionImplFunc_t)(VM* vm);
typedef enum __attribute__((__packed__)) Opcode {
Opcode_NOP,
Opcode_PUSH,
Opcode_MOV,
Opcode_ADD,
Opcode_SUB,
Opcode_MUL,
Opcode_DIV,
Opcode_MOD,
Opcode_SYS,
Opcode_EXIT,
} Opcode;
typedef struct Instruction {
cstr name;
InstructionImplFunc_t implementation;
Opcode opcode;
} Instruction;
#define Instruction_construct(NAME) {\
.name = #NAME, \
.implementation = NAME##_impl \
.implementation = NAME##_impl, \
.opcode = Opcode_##NAME\
}
/// @brief get instruction info from table
/// @param opcode any byte
/// @return ptr to struct or NULL
const Instruction* NULLABLE(Instruction_getFromOpcode)(u8 opcode);
i32 NOP_impl(VM* vm);
i32 PUSH_impl(VM* vm);
i32 MOV_impl(VM* vm);
i32 ADD_impl(VM* vm);
i32 SUB_impl(VM* vm);
i32 MUL_impl(VM* vm);
i32 DIV_impl(VM* vm);
i32 MOD_impl(VM* vm);
i32 SYS_impl(VM* vm);
i32 EXIT_impl(VM* vm);
i32 JMP_impl(VM* vm);
i32 CALL_impl(VM* vm);
const Instruction* NULLABLE(Instruction_getFromOpcode)(Opcode opcode);