summaryrefslogtreecommitdiff
path: root/vm.c
diff options
context:
space:
mode:
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/vm.c b/vm.c
index 205e0fd..70aca3d 100644
--- a/vm.c
+++ b/vm.c
@@ -55,6 +55,7 @@ int runvm(State *S) {
disasm_chunk(ch);
#define RBYTE() (ch->bc.d[th->ip++])
+#define RSHORT() (th->ip += 2, (uint16_t)( ch->bc.d[th->ip-2] | ch->bc.d[th->ip-1] << 8 ))
#define PUSH(v) th->stack[th->sp++] = v;
#define POP() (th->stack[--th->sp])
@@ -85,6 +86,24 @@ int runvm(State *S) {
--th->sp;
break;
+ case OP_SKIP: {
+ uint16_t offset = RSHORT();
+ th->ip += offset;
+ break;
+ }
+ case OP_REDO: {
+ uint16_t offset = RSHORT();
+ th->ip -= offset;
+ break;
+ }
+ case OP_0BRANCH: {
+ uint16_t offset = RSHORT();
+ bool cond = is_truthy(POP());
+ if (!cond)
+ th->ip += offset;
+ break;
+ }
+
case OP_GETGLOBAL: {
uint8_t cix = RBYTE();
Val varname = ch->consts.d[cix];
@@ -134,12 +153,16 @@ int runvm(State *S) {
case OP_TRUE: PUSH(VAL_TRUE); break;
case OP_FALSE: PUSH(VAL_FALSE); break;
-
}
}
done:;
return status;
}
+#undef RBYTE
+#undef RSHORT
+#undef PUSH
+#undef POP
+#undef PEEK