From 18a830922a6ce1abd2a56440f61bde72470ac148 Mon Sep 17 00:00:00 2001 From: cassowarii Date: Tue, 30 Jun 2026 06:32:40 -0700 Subject: [PATCH] fix a couple bytecode compiler bugs --- src/compile/emit.c | 1 + src/vm/exec.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/compile/emit.c b/src/compile/emit.c index e37f528..7e906cf 100644 --- a/src/compile/emit.c +++ b/src/compile/emit.c @@ -102,6 +102,7 @@ void compile_chunk(sbVmCompiler *cm, sbIrChunk *chunk) { location_bytes[3] = (position >> 0) & 0xFF; sbVmCompiler_overwrite_code_at(cm, lp.offset, location_bytes, 4); } + sbBuffer_set_size(&cm->label_positions, 0); } /* when compiling one line at a time, we don't know the position diff --git a/src/vm/exec.c b/src/vm/exec.c index 6491a0c..b51e653 100644 --- a/src/vm/exec.c +++ b/src/vm/exec.c @@ -356,7 +356,8 @@ void execute_instruction(hVm vm) { /* have to set new rstack space to 0 so we don't accidentally decrement * the ref count of variables from a previous stack frame (or of just garbage) */ memset(vm->rp, 0, param * sizeof(hV)); - vm->rp += param * sizeof(hV); + /* we allocate one more variable at 0 for internal use */ + vm->rp += (param + 1) * sizeof(hV); vm->fp->num_locals += param; return; case BC_LIST_GATHER: -- 1.8.3.1