From 58753c1fcf5b4b7b8aada97a8524e7fb23c3e816 Mon Sep 17 00:00:00 2001 From: Simon Forsberg Date: Sat, 10 Dec 2016 20:37:44 +0100 Subject: [PATCH] Fix StepContinueStrategy bugs --- .../zomis/brainf/model/run/StepContinueStrategy.groovy | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/groovy/net/zomis/brainf/model/run/StepContinueStrategy.groovy b/src/main/groovy/net/zomis/brainf/model/run/StepContinueStrategy.groovy index fef79b0..099cf6f 100644 --- a/src/main/groovy/net/zomis/brainf/model/run/StepContinueStrategy.groovy +++ b/src/main/groovy/net/zomis/brainf/model/run/StepContinueStrategy.groovy @@ -24,12 +24,15 @@ class StepContinueStrategy implements RunStrategy { startingEnteredTreesCount = runner.code.enteredTrees.size() if (!runner.isOnRootTree()) { currentLoop = runner.code.getCurrentTree().tree + } else if (runner.code.currentSyntax instanceof SyntaxTree) { + currentLoop = runner.code.currentSyntax as SyntaxTree } def pos = runner.code.getCurrentTree().iteratorCopy(); while (pos.hasNext()) { Syntax syntax = pos.next(); if (syntax instanceof SyntaxTree) { nextLoop = syntax; + break; } } performedOnce = false @@ -47,11 +50,12 @@ class StepContinueStrategy implements RunStrategy { if (currentLoop) { // if inside loop, either end the loop or go to beginning of loop boolean loopHasEnded = runner.code.enteredTrees.size() < startingEnteredTreesCount - boolean startOfLoop = runner.code.currentTree.currentIndex == 0 + boolean startOfLoop = runner.code.currentTree.tree == this.currentLoop && + runner.code.currentTree.currentIndex == 0 boolean perform = !loopHasEnded && !startOfLoop if (!performedOnce) { perform = true - performedOnce = true + performedOnce = !(runner.code.currentSyntax instanceof SyntaxTree) // Perform again if started on WHILE } if (perform) { runner.runSyntax()