fix another VM instruction bug
authorcassowarii <cassowary@cassowary.me>
Tue, 7 Jul 2026 06:49:09 +0000 (23:49 -0700)
committercassowarii <cassowary@cassowary.me>
Tue, 7 Jul 2026 06:49:09 +0000 (23:49 -0700)
src/vm/exec.c
src/vm/operations.c
src/vm/operations.h

index 648ca74..7360e36 100644 (file)
@@ -210,13 +210,20 @@ void swap_stack_top(hVm vm) {
   hV *first_x = &((hV*)vm->xsp)[-1];
   hV *second_x = &((hV*)vm->xsp)[-2];
 
+  hV xtmp = *first_x;
+  if (*first_v == first_x) {
+    *first_x = *second_x;
+    *first_v = second_x;
+  }
+
+  if (*second_v == second_x) {
+    *second_x = xtmp;
+    *second_v = first_x;
+  }
+
   hV *vtmp = *first_v;
   *first_v = *second_v;
   *second_v = vtmp;
-
-  hV xtmp = *first_x;
-  *first_x = *second_x;
-  *second_x = xtmp;
 }
 
 hV *peek_stack(hVm vm, isize offset) {
index 83c4765..adbf206 100644 (file)
@@ -59,17 +59,17 @@ hV sbV_floordiv(const hV *a, const hV *b) {
   }
 }
 
-hV sbV_incr(const hV *a) {
+void sbV_incr(hV *a) {
   if (a->type == IT_INTEGER) {
-    return sbV_int(a->integer + 1);
+    a->integer += 1;
   } else {
     PANIC("todo");
   }
 }
 
-hV sbV_decr(const hV *a) {
+void sbV_decr(hV *a) {
   if (a->type == IT_INTEGER) {
-    return sbV_int(a->integer - 1);
+    a->integer -= 1;
   } else {
     PANIC("todo");
   }
index e9e28af..8fa8778 100644 (file)
@@ -10,9 +10,9 @@ hV sbV_mul(const hV *a, const hV *b);
 
 hV sbV_floordiv(const hV *a, const hV *b);
 
-hV sbV_incr(const hV *a);
+void sbV_incr(hV *a);
 
-hV sbV_decr(const hV *a);
+void sbV_decr(hV *a);
 
 hV sbV_eq(const hV *a, const hV *b);