From 91077fec758a5a526ea950815f0a758e526f66d8 Mon Sep 17 00:00:00 2001 From: cassowarii Date: Mon, 6 Jul 2026 23:49:09 -0700 Subject: [PATCH] fix another VM instruction bug --- src/vm/exec.c | 15 +++++++++++---- src/vm/operations.c | 8 ++++---- src/vm/operations.h | 4 ++-- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/vm/exec.c b/src/vm/exec.c index 648ca74..7360e36 100644 --- a/src/vm/exec.c +++ b/src/vm/exec.c @@ -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) { diff --git a/src/vm/operations.c b/src/vm/operations.c index 83c4765..adbf206 100644 --- a/src/vm/operations.c +++ b/src/vm/operations.c @@ -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"); } diff --git a/src/vm/operations.h b/src/vm/operations.h index e9e28af..8fa8778 100644 --- a/src/vm/operations.h +++ b/src/vm/operations.h @@ -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); -- 1.8.3.1