fix: use correct idx into memory for loops
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user