Skip to content

Commit

Permalink
Fix bug in disassemble
Browse files Browse the repository at this point in the history
  • Loading branch information
bamless committed Jan 31, 2021
1 parent 34200ad commit 473ba18
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/disassemble.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,27 @@ static uint16_t readShortAt(const uint8_t* code, size_t i) {

static size_t countInstructions(Code* c) {
size_t count = 0;
for(size_t i = 0; i < c->count; i += opcodeArgsNumber(c->bytecode[i]) + 1) {
for(size_t i = 0; i < c->count;) {
count++;
if(c->bytecode[i] == OP_CLOSURE) {
Opcode instr = c->bytecode[i];
if(instr == OP_CLOSURE) {
Value func = c->consts.arr[readShortAt(c->bytecode, i + 1)];
i += AS_FUNC(func)->upvalueCount * 2;
}
i += opcodeArgsNumber(instr) + 1;
}
return count;
}

static void disassembleCode(Code* c, int indent) {
for(size_t i = 0; i < c->count; i += opcodeArgsNumber(c->bytecode[i]) + 1) {
for(size_t i = 0; i < c->count;) {
disassembleIstr(c, indent, i);
if(c->bytecode[i] == OP_CLOSURE) {
Opcode instr = c->bytecode[i];
if(instr == OP_CLOSURE) {
Value func = c->consts.arr[readShortAt(c->bytecode, i + 1)];
i += AS_FUNC(func)->upvalueCount * 2;
}
i += opcodeArgsNumber(instr) + 1;
}
}

Expand Down

0 comments on commit 473ba18

Please sign in to comment.