From 65275bde8a82f54710a65d6e6563394bb850b7ef Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Mon, 25 Oct 2021 21:49:54 -0700 Subject: Chapter 22 --- clox/src/debug.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'clox/src/debug.c') diff --git a/clox/src/debug.c b/clox/src/debug.c index 61deb52..5a3cedc 100644 --- a/clox/src/debug.c +++ b/clox/src/debug.c @@ -24,6 +24,12 @@ static int simpleInstruction(const char *name, int offset) { return offset + 1; } +static int byteInstruction(const char *name, Chunk *chunk, int offset) { + uint8_t slot = chunk->code[offset + 1]; + printf("%-16s %4d\n", name, slot); + return offset + 2; +} + int disassembleInstruction(Chunk *chunk, int offset) { printf("%04d ", offset); if (offset > 0 && chunk->lines[offset] == chunk->lines[offset - 1]) { @@ -44,6 +50,10 @@ int disassembleInstruction(Chunk *chunk, int offset) { return simpleInstruction("OP_FALSE", offset); case OP_POP: return simpleInstruction("OP_POP", offset); + case OP_GET_LOCAL: + return byteInstruction("OP_GET_LOCAL", chunk, offset); + case OP_SET_LOCAL: + return byteInstruction("OP_SET_LOCAL", chunk, offset); case OP_GET_GLOBAL: return constantInstruction("OP_GET_GLOBAL", chunk, offset); case OP_DEFINE_GLOBAL: -- cgit v1.2.3-54-g00ecf