summary refs log tree commit diff
path: root/src/interpreter.rs
diff options
context:
space:
mode:
authorAshelyn Rose <git@ashen.earth>2024-12-24 17:42:11 -0700
committerAshelyn Rose <git@ashen.earth>2024-12-24 17:42:11 -0700
commitced4757324d0eac5a26f14da7de4abc875019af1 (patch)
tree21ea3f95194fc20f7eb9d9e69f2e2939e88b1313 /src/interpreter.rs
parent9a2c2bc2d9ff45b9bd96c570b8c5fc0b03067ccc (diff)
Fix stack local access
Diffstat (limited to 'src/interpreter.rs')
-rw-r--r--src/interpreter.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/interpreter.rs b/src/interpreter.rs
index 9f226ae..686a3ff 100644
--- a/src/interpreter.rs
+++ b/src/interpreter.rs
@@ -280,9 +280,9 @@ impl Interpreter {
             Operand::Constant(value) => *value as u32,
             Operand::PopStack => self.pop_stack(),
             Operand::FrameIndirect(offset) => {
-                let start_of_locals = self.get_word(self.reg_frame, ReadWriteDest::Stack);
-                assert!(start_of_locals + offset < self.reg_stack, "Frame offset out of frame");
-                self.get_word(start_of_locals + offset, ReadWriteDest::Stack)
+                let locals_pos = self.get_word(self.reg_frame + 4, ReadWriteDest::Stack);
+                assert!(self.reg_frame + locals_pos + offset < self.reg_stack, "Frame offset out of frame");
+                self.get_word(self.reg_frame + locals_pos + offset, ReadWriteDest::Stack)
             },
             Operand::MemIndirect(address) => {
                 // TODO: Handle heap
@@ -304,9 +304,9 @@ impl Interpreter {
             Operand::Constant(constant_dst) => panic!("Cannot store to constant operand {constant_dst}"),
             Operand::PopStack => self.push_stack(value),
             Operand::FrameIndirect(offset) => {
-                let start_of_locals = self.get_word(self.reg_frame, ReadWriteDest::Stack);
-                assert!(start_of_locals + offset < self.reg_stack, "Frame offset out of frame");
-                self.write_word(start_of_locals + offset, ReadWriteDest::Stack, value)
+                let locals_pos = self.get_word(self.reg_frame + 4, ReadWriteDest::Stack);
+                assert!(self.reg_frame + locals_pos + offset < self.reg_stack, "Frame offset out of frame");
+                self.write_word(self.reg_frame + locals_pos + offset, ReadWriteDest::Stack, value)
             },
             Operand::MemIndirect(address) => {
                 assert!(*address >= self.mem_writeable, "Cannot write to ROM");