Skip to content

Commit b841420

Browse files
committed
Implement stack size mishap in executeNextDebugStep
1 parent d23efd2 commit b841420

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

Common/src/main/kotlin/gay/object/hexdebug/debugger/HexDebugger.kt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation.NotDone
1010
import at.petrak.hexcasting.api.casting.iota.*
1111
import at.petrak.hexcasting.api.casting.mishaps.Mishap
1212
import at.petrak.hexcasting.api.casting.mishaps.MishapInternalException
13+
import at.petrak.hexcasting.api.casting.mishaps.MishapStackSize
1314
import at.petrak.hexcasting.common.casting.actions.eval.OpEval
1415
import at.petrak.hexcasting.common.lib.hex.HexEvalSounds
1516
import gay.`object`.hexdebug.adapter.LaunchArgs
@@ -486,7 +487,9 @@ class HexDebugger(
486487

487488
fun executeOnce() = executeNextDebugStep(getVM())
488489

489-
// Copy of CastingVM.queueExecuteAndWrapIotas to allow stepping by one pattern at a time.
490+
/**
491+
* Copy of [CastingVM.queueExecuteAndWrapIotas] to allow stepping by one pattern at a time.
492+
*/
490493
private fun executeNextDebugStep(
491494
vm: CastingVM,
492495
exactlyOnce: Boolean = false,
@@ -514,7 +517,20 @@ class HexDebugger(
514517
}
515518

516519
// ...and execute it.
517-
val castResult = frame.evaluate(continuation.next, world, vm)
520+
val castResult = frame.evaluate(continuation.next, world, vm).let { result ->
521+
// if stack is unable to be serialized, have the result be an error
522+
val newData = result.newData
523+
if (newData != null && IotaType.isTooLargeToSerialize(newData.stack)) {
524+
result.copy(
525+
newData = null,
526+
sideEffects = listOf(OperatorSideEffect.DoMishap(MishapStackSize(), Mishap.Context(null, null))),
527+
resolutionType = ResolvedPatternType.ERRORED,
528+
sound = HexEvalSounds.MISHAP,
529+
)
530+
} else {
531+
result
532+
}
533+
}
518534

519535
val newImage = castResult.newData
520536

0 commit comments

Comments
 (0)