TCPU/src/instructions/instructions.h
2025-02-03 22:30:56 +05:00

39 lines
930 B
C

#pragma once
#include "../VM/VM.h"
///@param program_pos position in vm->program next afrer opcode
///@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 {
str name;
InstructionImplFunc_t implementation;
Opcode opcode;
} Instruction;
#define Instruction_construct(NAME) {\
.name = STR(#NAME), \
.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_getByOpcode)(Opcode opcode);
const Instruction* NULLABLE(Instruction_getByName)(str name);
void Instruction_freeSearchStructs();