aboutsummaryrefslogtreecommitdiff
path: root/lib/inst.h
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-11-02 21:01:21 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-11-02 21:01:21 +0000
commit86977fe3c140e6b5d6c09bc1d26d9f97d89a6488 (patch)
treea55acd39b074f472c0173b48b067c9abcb7440e8 /lib/inst.h
parent9afeed6d617da4841a031423286a0b3f3804f774 (diff)
downloadovm-86977fe3c140e6b5d6c09bc1d26d9f97d89a6488.tar.gz
ovm-86977fe3c140e6b5d6c09bc1d26d9f97d89a6488.tar.bz2
ovm-86977fe3c140e6b5d6c09bc1d26d9f97d89a6488.zip
Introduced instructions to engage with a call stack
Essentially you may "call" an absolute program address, which pushes the current address onto the call stack. CALL_STACK does the same thing but the absolute program address is taken from the data stack. RET pops an address off the call stack then jumps to that address.
Diffstat (limited to 'lib/inst.h')
-rw-r--r--lib/inst.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/inst.h b/lib/inst.h
index 55c062f..3877a2b 100644
--- a/lib/inst.h
+++ b/lib/inst.h
@@ -148,6 +148,10 @@ typedef enum
OP_JUMP_IF_BYTE,
OP_JUMP_IF_HWORD,
OP_JUMP_IF_WORD,
+ // Subroutines
+ OP_CALL,
+ OP_CALL_STACK,
+ OP_RET,
// Should not be an opcode
NUMBER_OF_OPCODES,
@@ -231,6 +235,9 @@ inst_t *insts_read_bytecode_file(FILE *, size_t *);
#define INST_JUMP_STACK ((inst_t){.opcode = OP_JUMP_STACK})
#define INST_JUMP_IF(TYPE, OP) \
((inst_t){.opcode = OP_JUMP_IF_##TYPE, .operand = DWORD(OP)})
+#define INST_CALL(OP) ((inst_t){.opcode = OP_CALL, .operand = DWORD(OP)})
+#define INST_CALL_STACK ((inst_t){.opcode = OP_CALL_STACK})
+#define INST_RET ((inst_t){.opcode = OP_RET})
#define INST_PRINT(TYPE) ((inst_t){.opcode = OP_PRINT_##TYPE})
#endif