Small opts + halt
This commit is contained in:
parent
d701fafff1
commit
f2687b9e88
3 changed files with 36 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue