aboutsummaryrefslogtreecommitdiffstats
path: root/clox/src/debug.c
diff options
context:
space:
mode:
Diffstat (limited to 'clox/src/debug.c')
-rw-r--r--clox/src/debug.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/clox/src/debug.c b/clox/src/debug.c
index b564aac..f175030 100644
--- a/clox/src/debug.c
+++ b/clox/src/debug.c
@@ -1,6 +1,7 @@
#include <stdio.h>
#include "debug.h"
+#include "object.h"
#include "value.h"
void disassembleChunk(Chunk *chunk, const char *name) {
@@ -68,6 +69,10 @@ int disassembleInstruction(Chunk *chunk, int offset) {
return constantInstruction("OP_DEFINE_GLOBAL", chunk, offset);
case OP_SET_GLOBAL:
return constantInstruction("OP_SET_GLOBAL", chunk, offset);
+ case OP_GET_UPVALUE:
+ return byteInstruction("OP_GET_UPVALUE", chunk, offset);
+ case OP_SET_UPVALUE:
+ return byteInstruction("OP_SET_UPVALUE", chunk, offset);
case OP_EQUAL:
return simpleInstruction("OP_EQUAL", offset);
case OP_GREATER:
@@ -102,6 +107,15 @@ int disassembleInstruction(Chunk *chunk, int offset) {
printf("%-16s %4d", "OP_CLOSURE", constant);
printValue(chunk->constants.values[constant]);
printf("\n");
+
+ ObjFunction *function = AS_FUNCTION(chunk->constants.values[constant]);
+ for (int j = 0; j < function->upvalueCount; j++) {
+ int isLocal = chunk->code[offset++];
+ int index = chunk->code[offset++];
+ printf("%04d | %s %d\n", offset - 2,
+ isLocal ? "local" : "upvalue", index);
+ }
+
return offset;
}
case OP_RETURN: