fix: use correct idx into memory for loops

This commit is contained in:
2025-04-22 09:27:59 +09:00
parent 7286f3ac3f
commit 638c2a0e96

View File

@@ -22,7 +22,7 @@ fn interpret(code: &str) {
}
'[' => {
// loop start
if memory[pc] == 0 {
if memory[head] == 0 {
let mut count_brackets = 1;
// find nested brackets
@@ -47,7 +47,8 @@ fn interpret(code: &str) {
}
']' => {
// loop terminator
if memory[pc] != 0 {
if memory[head] != 0 {
// jump back to loop beginning
if let Some(start_pc) = loop_stack.last() {
pc = *start_pc;
} else {