Small opts + halt

This commit is contained in:
Alwinfy 2022-05-23 10:49:34 -04:00
parent d701fafff1
commit f2687b9e88
No known key found for this signature in database
GPG key ID: 2CCB99445F0C949E
3 changed files with 36 additions and 2 deletions

View file

@ -6,7 +6,7 @@ import at.petrak.hexcasting.api.spell.casting.CastingHarness.CastResult
import net.minecraft.server.level.ServerLevel
/**
* A single frame of evaluation during the
* A single frame of evaluation during the execution of a spell.
*/
sealed interface ContinuationFrame {
fun evaluate(continuation: MutableList<ContinuationFrame>, level: ServerLevel, harness: CastingHarness): CastResult

View file

@ -17,7 +17,10 @@ object OpEval : Operator {
ctx.incDepth()
continuation.add(ContinuationFrame.FinishEval()) // boundary for break
// if not installed already...
if (!(continuation.isNotEmpty() && continuation.last() is ContinuationFrame.FinishEval)) {
continuation.add(ContinuationFrame.FinishEval()) // install a break-boundary after eval
}
continuation.add(ContinuationFrame.Evaluate(instrs))
return OperationResult(stack, local, listOf())

View file

@ -0,0 +1,31 @@
package at.petrak.hexcasting.common.casting.operators.eval
import at.petrak.hexcasting.api.spell.OperationResult
import at.petrak.hexcasting.api.spell.Operator
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.casting.CastingHarness
import at.petrak.hexcasting.api.spell.casting.ContinuationFrame
import at.petrak.hexcasting.api.spell.casting.OperatorSideEffect
object OpHalt : Operator {
override fun operate(continuation: MutableList<ContinuationFrame>, stack: MutableList<SpellDatum<*>>, local: SpellDatum<*>, ctx: CastingContext): OperationResult {
var newStack = stack
var done = false
while (!done && continuation.isNotEmpty() && !done) {
// Kotlin Y U NO destructuring assignment
val newInfo = continuation.removeLast().breakDownwards(newStack)
newStack = newInfo.first
done = newInfo.second
}
// if we hit no continuation boundaries (i.e. thoth/hermes exits), we've TOTALLY cleared the itinerary...
if (!done) {
// bomb the stack so we exit
newStack = listOf()
}
return OperationResult(newStack, local, listOf())
}
}