aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-10-15 20:56:02 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-10-15 20:59:26 +0100
commit7a820290f945f94bc38732d989746155883e151a (patch)
tree3b79072d6d1f6b3f51c0fc62d90125d804ebc1aa /src/main.c
parent40dfa5c25584a38566380229b016e8d5e495507e (diff)
downloadovm-7a820290f945f94bc38732d989746155883e151a.tar.gz
ovm-7a820290f945f94bc38732d989746155883e151a.tar.bz2
ovm-7a820290f945f94bc38732d989746155883e151a.zip
Make push opcodes a specific bit set and add a NOOP opcode
By default, a zero initialised set of instructions are NOOPs, which is great. Last two bits of a push opcode is always 01. Rest of the bits are used to distinguish between differing types of push. This makes it easier to inspect on the byte level what type of opcode we have.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/main.c b/src/main.c
index 9b744b2..4ccb42a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -121,11 +121,10 @@ void vm_execute(vm_t *vm)
// TODO: Error (Went past end of program)
return;
inst_t instruction = prog->instructions[prog->ptr];
- // NOTE: This is ballsy; I'm essentially saying I will never use the
- // last 2 bits unless it's a push routine
- if ((instruction.opcode & 0b11) != 0)
+
+ // Check if opcode is PUSH_LIKE
+ if (OPCODE_IS_PUSH(instruction.opcode))
{
- // Possible push routines
typedef void (*push_f)(vm_t *, data_t);
const push_f routines[] = {[OP_PUSH_BYTE] = vm_push_byte,
[OP_PUSH_WORD] = vm_push_word,