aboutsummaryrefslogtreecommitdiffstats
path: root/clox/src/vm.c
diff options
context:
space:
mode:
Diffstat (limited to 'clox/src/vm.c')
-rw-r--r--clox/src/vm.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/clox/src/vm.c b/clox/src/vm.c
index d869527..49a162d 100644
--- a/clox/src/vm.c
+++ b/clox/src/vm.c
@@ -73,6 +73,7 @@ static void concatenate() {
static InterpretResult run() {
#define READ_BYTE() (*vm.ip++)
#define READ_CONSTANT() (vm.chunk->constants.values[READ_BYTE()])
+#define READ_SHORT() (vm.ip += 2, (uint16_t)((vm.ip[-2] << 8) | vm.ip[-1]))
#define READ_STRING() AS_STRING(READ_CONSTANT())
#define BINARY_OP(valueType, op) \
do { \
@@ -199,6 +200,17 @@ static InterpretResult run() {
printf("\n");
break;
}
+ case OP_JUMP: {
+ uint16_t offset = READ_SHORT();
+ vm.ip += offset;
+ break;
+ }
+ case OP_JUMP_IF_FALSE: {
+ uint16_t offset = READ_SHORT();
+ if (isFalsey(peek(0)))
+ vm.ip += offset;
+ break;
+ }
case OP_RETURN: {
/* The book said to remove this, but when I do I get an infinite loop and
then a segfault because it keeps trying to add the constant 1 to the
@@ -211,6 +223,7 @@ static InterpretResult run() {
}
#undef READ_BYTE
+#undef READ_SHORT
#undef READ_CONSTANT
#undef READ_STRING
#undef BINARY_OP