Skip to content

Commit

Permalink
copy result instead of casting to mutable list
Browse files Browse the repository at this point in the history
  • Loading branch information
Toby Vestal committed Aug 20, 2024
1 parent 765ed92 commit 9600a8f
Showing 1 changed file with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,30 @@ class CastingVM(var image: CastingImage, val env: CastingEnvironment) {
// ...and execute it.
// TODO there used to be error checking code here; I'm pretty sure any and all mishaps should already
// get caught and folded into CastResult by evaluate.
val image2 = next.evaluate(continuation.next, world, this)
val image2 = next.evaluate(continuation.next, world, this).let { result ->
// if stack is unable to be serialized, have the result be an error
if (result.newData != null && isTooLargeToSerialize(result.newData.stack)) {
result.copy(
newData = null,
sideEffects = result.sideEffects + OperatorSideEffect.DoMishap(MishapStackSize(), Mishap.Context(null, null)),
resolutionType = ResolvedPatternType.ERRORED,
sound = HexEvalSounds.MISHAP,
)
} else {
result
}
}

// Then write all pertinent data back to the harness for the next iteration.
if (image2.newData != null) {
if (isTooLargeToSerialize(image2.newData.stack)){
// Ugly cast, probably need to rethink location
(image2.sideEffects as MutableList<OperatorSideEffect>).add(OperatorSideEffect.DoMishap(MishapStackSize(), Mishap.Context(null, null)))
lastResolutionType = ResolvedPatternType.ERRORED
}else {
continuation = image2.continuation
lastResolutionType = image2.resolutionType
this.image = image2.newData
}
this.image = image2.newData
}

this.env.postExecution(image2)

continuation = image2.continuation
lastResolutionType = image2.resolutionType

try {
performSideEffects(info, image2.sideEffects)
} catch (e: Exception) {
Expand Down

0 comments on commit 9600a8f

Please sign in to comment.