diff options
author | Tom Willemse | 2021-10-25 21:49:54 -0700 |
---|---|---|
committer | Tom Willemse | 2021-10-25 21:49:54 -0700 |
commit | 65275bde8a82f54710a65d6e6563394bb850b7ef (patch) | |
tree | 5fce3c2af65f1b5ae55823b28bd139860ff05f5c /clox/src/debug.c | |
parent | 9de87f449518415a7cc181d4592f28185aa5d6a0 (diff) | |
download | crafting-interpreters-65275bde8a82f54710a65d6e6563394bb850b7ef.tar.gz crafting-interpreters-65275bde8a82f54710a65d6e6563394bb850b7ef.zip |
Chapter 22
Diffstat (limited to 'clox/src/debug.c')
-rw-r--r-- | clox/src/debug.c | 10 |
1 files changed, 10 insertions, 0 deletions
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: |