Skip to content

Commit a0cb154

Browse files
s5bugSirius902
andcommitted
Remove SpellList
Co-authored-by: Sirius902 <10891979+Sirius902@users.noreply.github.com>
1 parent 012e07e commit a0cb154

File tree

15 files changed

+36
-139
lines changed

15 files changed

+36
-139
lines changed

Common/src/main/java/at/petrak/hexcasting/api/casting/ActionUtils.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ inline val Boolean.asActionResult get() = listOf(BooleanIota(this))
313313
inline val Double.asActionResult get() = listOf(DoubleIota(this))
314314
inline val Number.asActionResult get() = listOf(DoubleIota(this.toDouble()))
315315

316-
inline val SpellList.asActionResult get() = listOf(ListIota(Vector.from(this)))
317316
inline val List<Iota>.asActionResult get() = listOf(ListIota(Vector.from(this)))
318317

319318
inline val BlockPos.asActionResult get() = listOf(Vec3Iota(Vec3.atCenterOf(this)))

Common/src/main/java/at/petrak/hexcasting/api/casting/SpellList.kt

Lines changed: 0 additions & 93 deletions
This file was deleted.

Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/CastingVM.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package at.petrak.hexcasting.api.casting.eval.vm
22

33
import at.petrak.hexcasting.api.HexAPI
44
import at.petrak.hexcasting.api.casting.PatternShapeMatch.*
5-
import at.petrak.hexcasting.api.casting.SpellList
65
import at.petrak.hexcasting.api.casting.eval.*
76
import at.petrak.hexcasting.api.casting.eval.sideeffects.OperatorSideEffect
87
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage.ParenthesizedIota
@@ -40,7 +39,7 @@ class CastingVM(var image: CastingImage, val env: CastingEnvironment) {
4039
*/
4140
fun queueExecuteAndWrapIotas(iotas: List<Iota>, world: ServerLevel): ExecutionClientView {
4241
// Initialize the continuation stack to a single top-level eval for all iotas.
43-
var continuation = SpellContinuation.Done.pushFrame(FrameEvaluate(SpellList.LList(0, iotas), false))
42+
var continuation = SpellContinuation.Done.pushFrame(FrameEvaluate(Vector.from(iotas), false))
4443
// Begin aggregating info
4544
val info = TempControllerInfo(earlyExit = false)
4645
var lastResolutionType = ResolvedPatternType.UNRESOLVED

Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/ContinuationFrame.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package at.petrak.hexcasting.api.casting.eval.vm
22

3-
import at.petrak.hexcasting.api.casting.SpellList
43
import at.petrak.hexcasting.api.casting.eval.CastResult
54
import at.petrak.hexcasting.api.casting.iota.Iota
5+
import at.petrak.hexcasting.api.utils.Vector
66
import at.petrak.hexcasting.common.lib.hex.HexContinuationTypes
77
import net.minecraft.nbt.CompoundTag
88
import net.minecraft.nbt.Tag
@@ -60,10 +60,10 @@ interface ContinuationFrame {
6060
*/
6161
@JvmStatic
6262
fun fromNBT(tag: CompoundTag, world: ServerLevel): ContinuationFrame {
63-
val type = getTypeFromTag(tag) ?: return FrameEvaluate(SpellList.LList(0, listOf()), false)
63+
val type = getTypeFromTag(tag) ?: return FrameEvaluate(Vector.empty(), false)
6464

6565
return (tag.get(HexContinuationTypes.KEY_DATA) as? CompoundTag)?.let { type.deserializeFromNBT(it, world) }
66-
?: FrameEvaluate(SpellList.LList(0, listOf()), false)
66+
?: FrameEvaluate(Vector.empty(), false)
6767
}
6868

6969
/**

Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/FrameEvaluate.kt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package at.petrak.hexcasting.api.casting.eval.vm
22

3-
import at.petrak.hexcasting.api.casting.SpellList
43
import at.petrak.hexcasting.api.casting.eval.CastResult
54
import at.petrak.hexcasting.api.casting.eval.ResolvedPatternType
65
import at.petrak.hexcasting.api.casting.iota.Iota
@@ -20,7 +19,7 @@ import net.minecraft.server.level.ServerLevel
2019
* @property list the *remaining* list of patterns to be evaluated
2120
* @property isMetacasting only for sound effects, if this is being cast from a hermes / iris
2221
*/
23-
data class FrameEvaluate(val list: SpellList, val isMetacasting: Boolean) : ContinuationFrame {
22+
data class FrameEvaluate(val list: Vector<Iota>, val isMetacasting: Boolean) : ContinuationFrame {
2423
// Discard this frame and keep discarding frames.
2524
override fun breakDownwards(stack: List<Iota>) = false to stack
2625

@@ -31,21 +30,21 @@ data class FrameEvaluate(val list: SpellList, val isMetacasting: Boolean) : Cont
3130
harness: CastingVM
3231
): CastResult {
3332
// If there are patterns left...
34-
return if (list.nonEmpty) {
35-
val newCont = if (list.cdr.nonEmpty) { // yay TCO
33+
return if (!list.isEmpty()) {
34+
val newCont = if (!list.tail().isEmpty()) { // yay TCO
3635
// ...enqueue the evaluation of the rest of the patterns...
37-
continuation.pushFrame(FrameEvaluate(list.cdr, this.isMetacasting))
36+
continuation.pushFrame(FrameEvaluate(list.tail(), this.isMetacasting))
3837
} else continuation
3938
// ...before evaluating the first one in the list.
40-
val update = harness.executeInner(list.car, level, newCont)
39+
val update = harness.executeInner(list.head(), level, newCont)
4140
if (this.isMetacasting && update.sound != HexEvalSounds.MISHAP) {
4241
update.copy(sound = HexEvalSounds.HERMES)
4342
} else {
4443
update
4544
}
4645
} else {
4746
// If there are no patterns (e.g. empty Hermes), just return OK.
48-
CastResult(ListIota(Vector.from(list)), continuation, null, listOf(), ResolvedPatternType.EVALUATED, HexEvalSounds.HERMES)
47+
CastResult(ListIota(list), continuation, null, listOf(), ResolvedPatternType.EVALUATED, HexEvalSounds.HERMES)
4948
}
5049
}
5150

@@ -54,7 +53,7 @@ data class FrameEvaluate(val list: SpellList, val isMetacasting: Boolean) : Cont
5453
"isMetacasting" %= isMetacasting
5554
}
5655

57-
override fun size() = list.size()
56+
override fun size() = list.size
5857

5958
override val type: ContinuationFrame.Type<*> = TYPE
6059

@@ -63,10 +62,10 @@ data class FrameEvaluate(val list: SpellList, val isMetacasting: Boolean) : Cont
6362
val TYPE: ContinuationFrame.Type<FrameEvaluate> = object : ContinuationFrame.Type<FrameEvaluate> {
6463
override fun deserializeFromNBT(tag: CompoundTag, world: ServerLevel): FrameEvaluate {
6564
return FrameEvaluate(
66-
SpellList.LList(0, HexIotaTypes.LIST.deserialize(
65+
HexIotaTypes.LIST.deserialize(
6766
tag.getList("patterns", Tag.TAG_COMPOUND),
6867
world
69-
)!!.list),
68+
)!!.list,
7069
tag.getBoolean("isMetacasting"))
7170
}
7271

Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/FrameForEach.kt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package at.petrak.hexcasting.api.casting.eval.vm
22

3-
import at.petrak.hexcasting.api.casting.SpellList
43
import at.petrak.hexcasting.api.casting.eval.CastResult
54
import at.petrak.hexcasting.api.casting.eval.ResolvedPatternType
65
import at.petrak.hexcasting.api.casting.iota.Iota
@@ -26,8 +25,8 @@ import net.minecraft.server.level.ServerLevel
2625
* @property acc concatenated list of final stack states after Thoth exit
2726
*/
2827
data class FrameForEach(
29-
val data: SpellList,
30-
val code: SpellList,
28+
val data: Vector<Iota>,
29+
val code: Vector<Iota>,
3130
val baseStack: List<Iota>?,
3231
val acc: Vector<Iota>
3332
) : ContinuationFrame {
@@ -54,14 +53,14 @@ data class FrameForEach(
5453
}
5554

5655
// If we still have data to process...
57-
val (stackTop, newImage, newCont) = if (data.nonEmpty) {
56+
val (stackTop, newImage, newCont) = if (!data.isEmpty()) {
5857
// push the next datum to the top of the stack,
5958
val cont2 = continuation
6059
// put the next Thoth object back on the stack for the next Thoth cycle,
61-
.pushFrame(FrameForEach(data.cdr, code, stack, nextAcc))
60+
.pushFrame(FrameForEach(data.tail(), code, stack, nextAcc))
6261
// and prep the Thoth'd code block for evaluation.
6362
.pushFrame(FrameEvaluate(code, true))
64-
Triple(data.car, harness.image.withUsedOp(), cont2)
63+
Triple(data.head(), harness.image.withUsedOp(), cont2)
6564
} else {
6665
// Else, dump our final list onto the stack.
6766
Triple(ListIota(nextAcc), harness.image, continuation)
@@ -87,7 +86,7 @@ data class FrameForEach(
8786
"accumulator" %= acc.toList().serializeToNBT()
8887
}
8988

90-
override fun size() = data.size() + code.size() + acc.size + (baseStack?.size ?: 0)
89+
override fun size() = data.size + code.size + acc.size + (baseStack?.size ?: 0)
9190

9291
override val type: ContinuationFrame.Type<*> = TYPE
9392

@@ -96,8 +95,8 @@ data class FrameForEach(
9695
val TYPE: ContinuationFrame.Type<FrameForEach> = object : ContinuationFrame.Type<FrameForEach> {
9796
override fun deserializeFromNBT(tag: CompoundTag, world: ServerLevel): FrameForEach {
9897
return FrameForEach(
99-
SpellList.LList(0, HexIotaTypes.LIST.deserialize(tag.getList("data", Tag.TAG_COMPOUND), world)!!.list),
100-
SpellList.LList(0, HexIotaTypes.LIST.deserialize(tag.getList("code", Tag.TAG_COMPOUND), world)!!.list),
98+
HexIotaTypes.LIST.deserialize(tag.getList("data", Tag.TAG_COMPOUND), world)!!.list,
99+
HexIotaTypes.LIST.deserialize(tag.getList("code", Tag.TAG_COMPOUND), world)!!.list,
101100
if (tag.hasList("base", Tag.TAG_COMPOUND))
102101
HexIotaTypes.LIST.deserialize(tag.getList("base", Tag.TAG_COMPOUND), world)!!.list.toList()
103102
else

Common/src/main/java/at/petrak/hexcasting/common/casting/actions/eval/OpEval.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package at.petrak.hexcasting.common.casting.actions.eval
22

3-
import at.petrak.hexcasting.api.casting.SpellList
43
import at.petrak.hexcasting.api.casting.castables.Action
54
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
65
import at.petrak.hexcasting.api.casting.eval.OperationResult
@@ -11,6 +10,7 @@ import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation
1110
import at.petrak.hexcasting.api.casting.evaluatable
1211
import at.petrak.hexcasting.api.casting.iota.Iota
1312
import at.petrak.hexcasting.api.casting.mishaps.MishapNotEnoughArgs
13+
import at.petrak.hexcasting.api.utils.Vector
1414
import at.petrak.hexcasting.common.lib.hex.HexEvalSounds
1515

1616
object OpEval : Action {
@@ -30,7 +30,7 @@ object OpEval : Action {
3030
continuation.pushFrame(FrameFinishEval) // install a break-boundary after eval
3131
}
3232

33-
val instrsList = instrs.map({ SpellList.LList(0, listOf(it)) }, { SpellList.LList(0, it) })
33+
val instrsList = instrs.map({ Vector.from(listOf(it)) }, { Vector.from(it) })
3434
val frame = FrameEvaluate(instrsList, true)
3535

3636
val image2 = image.withUsedOp().copy(stack = newStack)

Common/src/main/java/at/petrak/hexcasting/common/casting/actions/eval/OpForEach.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package at.petrak.hexcasting.common.casting.actions.eval
22

3-
import at.petrak.hexcasting.api.casting.SpellList
43
import at.petrak.hexcasting.api.casting.castables.Action
54
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
65
import at.petrak.hexcasting.api.casting.eval.OperationResult
@@ -24,7 +23,7 @@ object OpForEach : Action {
2423
stack.removeLastOrNull()
2524
stack.removeLastOrNull()
2625

27-
val frame = FrameForEach(SpellList.LList(0, datums), SpellList.LList(0, instrs), null, Vector.empty())
26+
val frame = FrameForEach(datums, instrs, null, Vector.empty())
2827
val image2 = image.withUsedOp().copy(stack = stack)
2928

3029
return OperationResult(image2, listOf(), continuation.pushFrame(frame), HexEvalSounds.THOTH)

Common/src/main/java/at/petrak/hexcasting/common/casting/actions/lists/OpCons.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package at.petrak.hexcasting.common.casting.actions.lists
22

3-
import at.petrak.hexcasting.api.casting.SpellList
43
import at.petrak.hexcasting.api.casting.asActionResult
54
import at.petrak.hexcasting.api.casting.castables.ConstMediaAction
65
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
@@ -12,6 +11,6 @@ object OpCons : ConstMediaAction {
1211
override fun execute(args: List<Iota>, env: CastingEnvironment): List<Iota> {
1312
val bottom = args.getList(0, argc)
1413
val top = args[1]
15-
return SpellList.LPair(top, SpellList.LList(0, bottom)).asActionResult
14+
return bottom.prepended(top).asActionResult
1615
}
1716
}

Common/src/main/java/at/petrak/hexcasting/common/casting/actions/lists/OpModifyInPlace.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package at.petrak.hexcasting.common.casting.actions.lists
22

3-
import at.petrak.hexcasting.api.casting.SpellList
43
import at.petrak.hexcasting.api.casting.asActionResult
54
import at.petrak.hexcasting.api.casting.castables.ConstMediaAction
65
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
@@ -14,6 +13,6 @@ object OpModifyInPlace : ConstMediaAction {
1413
val list = args.getList(0, argc)
1514
val index = args.getPositiveIntUnder(1, list.size, argc)
1615
val iota = args[2]
17-
return SpellList.LList(0, list).modifyAt(index) { SpellList.LPair(iota, it.cdr) }.asActionResult
16+
return list.updated(index, iota).asActionResult
1817
}
1918
}

0 commit comments

Comments
 (0)