diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/CastingImage.kt b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/CastingImage.kt index d04b1c29c..3ffd771bc 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/CastingImage.kt +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/CastingImage.kt @@ -67,6 +67,11 @@ data class CastingImage private constructor( */ fun withOverriddenUsedOps(count: Long) = this.copy(opsConsumed = count) + /** + * Returns a copy of this with escape/paren-related fields cleared. + */ + fun withResetEscape() = this.copy(parenCount = 0, parenthesized = listOf(), escapeNext = false) + fun serializeToNbt() = NBTBuilder { TAG_STACK %= stack.serializeToNBT() diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/CastingVM.kt b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/CastingVM.kt index 04c34d774..8cbd8d51e 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/CastingVM.kt +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/CastingVM.kt @@ -188,7 +188,7 @@ class CastingVM(var image: CastingImage, val env: CastingEnvironment) { val newParenCount = this.image.parenCount + if (last == null || last.escaped || last.iota !is PatternIota) 0 else when (last.iota.pattern) { SpecialPatterns.INTROSPECTION -> -1 SpecialPatterns.RETROSPECTION -> 1 - else -> -1 + else -> 0 } this.image.copy(parenthesized = newParens, parenCount = newParenCount) to if (last == null) ResolvedPatternType.ERRORED else ResolvedPatternType.UNDONE } diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/FrameForEach.kt b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/FrameForEach.kt index ec587cb78..0221c1f36 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/FrameForEach.kt +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/FrameForEach.kt @@ -73,7 +73,8 @@ data class FrameForEach( return CastResult( ListIota(code), newCont, - newImage.copy(stack = tStack), + // reset escapes so they don't carry over to other iterations or out of thoth + newImage.withResetEscape().copy(stack = tStack), listOf(), ResolvedPatternType.EVALUATED, HexEvalSounds.THOTH,