fix a couple bytecode compiler bugs
authorcassowarii <cassowary@cassowary.me>
Tue, 30 Jun 2026 13:32:40 +0000 (06:32 -0700)
committercassowarii <cassowary@cassowary.me>
Tue, 30 Jun 2026 13:32:40 +0000 (06:32 -0700)
src/compile/emit.c
src/vm/exec.c

index e37f528..7e906cf 100644 (file)
@@ -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
index 6491a0c..b51e653 100644 (file)
@@ -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: