From 4244efa55d29d3fa20d5fcba3ada1f423f87ec52 Mon Sep 17 00:00:00 2001 From: mryouse Date: Thu, 8 Jun 2023 22:11:32 -0400 Subject: bugfix (probably wrong): this *seems* to stop the offset issues on stack B, but I'm not sure why --- vm.d | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/vm.d b/vm.d index 69a16dc..2287f87 100644 --- a/vm.d +++ b/vm.d @@ -93,8 +93,9 @@ class VM { if (offset >= this.bTop) { writefln("peekB() offset of %d greater than stack size %d", offset, this.bTop); } - return this.bStack[this.bTop - offset]; - //return this.bStack[this.bTop - offset - 1]; + //return this.bStack[this.bTop]; + //return this.bStack[this.bTop - offset]; + return this.bStack[this.bTop - offset - 1]; } Value popB() { @@ -275,6 +276,7 @@ class VM { } while (true) { if (DEBUG) { + writefln(" atop: %d, btop: %d", this.aTop, this.bTop); writeln(" Stacks:"); write(" A> "); for (int i = 0; i < this.aTop; i++) { @@ -385,7 +387,7 @@ class VM { //pushA(current.slots[current.frameStart + slot + 1]); //pushA(this.current.slots[this.current.frameStart + slot]); - pushA(this.peekB(this.bTop - (this.current.frameStart + slot))); + pushA(this.peekB(this.bTop - (this.current.frameStart + slot) - 1)); break; case OpCode.OP_SET_LOCAL: ubyte slot = this.readByte(); -- cgit v1.2.3