Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import at.petrak.hexcasting.api.casting.iota.*
import at.petrak.hexcasting.api.casting.math.HexPattern
import at.petrak.hexcasting.api.casting.mishaps.MishapInvalidIota
import at.petrak.hexcasting.api.casting.mishaps.MishapNotEnoughArgs
import at.petrak.hexcasting.api.utils.TreeList
import at.petrak.hexcasting.api.utils.asTranslatedComponent
import com.mojang.datafixers.util.Either
import net.minecraft.core.BlockPos
Expand Down Expand Up @@ -41,7 +42,7 @@ fun List<Iota>.getEntity(idx: Int, argc: Int = 0): Entity {
}
}

fun List<Iota>.getList(idx: Int, argc: Int = 0): SpellList {
fun List<Iota>.getList(idx: Int, argc: Int = 0): TreeList<Iota> {
val x = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) }
if (x is ListIota) {
return x.list
Expand Down Expand Up @@ -269,7 +270,7 @@ fun List<Iota>.getNumOrVec(idx: Int, argc: Int = 0): Either<Double, Vec3> {
}
}

fun List<Iota>.getLongOrList(idx: Int, argc: Int = 0): Either<Long, SpellList> {
fun List<Iota>.getLongOrList(idx: Int, argc: Int = 0): Either<Long, TreeList<Iota>> {
val datum = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) }
if (datum is DoubleIota) {
val double = datum.double
Expand All @@ -287,7 +288,7 @@ fun List<Iota>.getLongOrList(idx: Int, argc: Int = 0): Either<Long, SpellList> {
)
}

fun evaluatable(datum: Iota, reverseIdx: Int): Either<Iota, SpellList> =
fun evaluatable(datum: Iota, reverseIdx: Int): Either<Iota, TreeList<Iota>> =
when (datum) {
is ListIota -> Either.right(datum.list)
else -> if (datum.executable()) Either.left(datum) else throw MishapInvalidIota(
Expand All @@ -312,7 +313,7 @@ inline val Boolean.asActionResult get() = listOf(BooleanIota(this))
inline val Double.asActionResult get() = listOf(DoubleIota(this))
inline val Number.asActionResult get() = listOf(DoubleIota(this.toDouble()))

inline val SpellList.asActionResult get() = listOf(ListIota(this))
inline val TreeList<Iota>.asActionResult get() = listOf(ListIota(this))
inline val List<Iota>.asActionResult get() = listOf(ListIota(this))

inline val BlockPos.asActionResult get() = listOf(Vec3Iota(Vec3.atCenterOf(this)))
Expand Down
93 changes: 0 additions & 93 deletions Common/src/main/java/at/petrak/hexcasting/api/casting/SpellList.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package at.petrak.hexcasting.api.casting.eval.vm

import at.petrak.hexcasting.api.HexAPI
import at.petrak.hexcasting.api.casting.PatternShapeMatch.*
import at.petrak.hexcasting.api.casting.SpellList
import at.petrak.hexcasting.api.casting.eval.*
import at.petrak.hexcasting.api.casting.eval.sideeffects.OperatorSideEffect
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage.ParenthesizedIota
Expand Down Expand Up @@ -40,7 +39,7 @@ class CastingVM(var image: CastingImage, val env: CastingEnvironment) {
*/
fun queueExecuteAndWrapIotas(iotas: List<Iota>, world: ServerLevel): ExecutionClientView {
// Initialize the continuation stack to a single top-level eval for all iotas.
var continuation = SpellContinuation.Done.pushFrame(FrameEvaluate(SpellList.LList(0, iotas), false))
var continuation = SpellContinuation.Done.pushFrame(FrameEvaluate(TreeList.from(iotas), false))
// Begin aggregating info
val info = TempControllerInfo(earlyExit = false)
var lastResolutionType = ResolvedPatternType.UNRESOLVED
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package at.petrak.hexcasting.api.casting.eval.vm

import at.petrak.hexcasting.api.casting.SpellList
import at.petrak.hexcasting.api.casting.eval.CastResult
import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.utils.TreeList
import at.petrak.hexcasting.common.lib.hex.HexContinuationTypes
import net.minecraft.nbt.CompoundTag
import net.minecraft.nbt.Tag
Expand Down Expand Up @@ -60,10 +60,10 @@ interface ContinuationFrame {
*/
@JvmStatic
fun fromNBT(tag: CompoundTag, world: ServerLevel): ContinuationFrame {
val type = getTypeFromTag(tag) ?: return FrameEvaluate(SpellList.LList(0, listOf()), false)
val type = getTypeFromTag(tag) ?: return FrameEvaluate(TreeList.empty(), false)

return (tag.get(HexContinuationTypes.KEY_DATA) as? CompoundTag)?.let { type.deserializeFromNBT(it, world) }
?: FrameEvaluate(SpellList.LList(0, listOf()), false)
?: FrameEvaluate(TreeList.empty(), false)
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package at.petrak.hexcasting.api.casting.eval.vm

import at.petrak.hexcasting.api.casting.SpellList
import at.petrak.hexcasting.api.casting.eval.CastResult
import at.petrak.hexcasting.api.casting.eval.ResolvedPatternType
import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.casting.iota.ListIota
import at.petrak.hexcasting.api.utils.NBTBuilder
import at.petrak.hexcasting.api.utils.TreeList
import at.petrak.hexcasting.api.utils.getList
import at.petrak.hexcasting.api.utils.serializeToNBT
import at.petrak.hexcasting.common.lib.hex.HexEvalSounds
Expand All @@ -19,7 +19,7 @@ import net.minecraft.server.level.ServerLevel
* @property list the *remaining* list of patterns to be evaluated
* @property isMetacasting only for sound effects, if this is being cast from a hermes / iris
*/
data class FrameEvaluate(val list: SpellList, val isMetacasting: Boolean) : ContinuationFrame {
data class FrameEvaluate(val list: TreeList<Iota>, val isMetacasting: Boolean) : ContinuationFrame {
// Discard this frame and keep discarding frames.
override fun breakDownwards(stack: List<Iota>) = false to stack

Expand All @@ -30,13 +30,13 @@ data class FrameEvaluate(val list: SpellList, val isMetacasting: Boolean) : Cont
harness: CastingVM
): CastResult {
// If there are patterns left...
return if (list.nonEmpty) {
val newCont = if (list.cdr.nonEmpty) { // yay TCO
return if (!list.isEmpty()) {
val newCont = if (!list.tail().isEmpty()) { // yay TCO
// ...enqueue the evaluation of the rest of the patterns...
continuation.pushFrame(FrameEvaluate(list.cdr, this.isMetacasting))
continuation.pushFrame(FrameEvaluate(list.tail(), this.isMetacasting))
} else continuation
// ...before evaluating the first one in the list.
val update = harness.executeInner(list.car, level, newCont)
val update = harness.executeInner(list.head(), level, newCont)
if (this.isMetacasting && update.sound != HexEvalSounds.MISHAP) {
update.copy(sound = HexEvalSounds.HERMES)
} else {
Expand All @@ -53,7 +53,7 @@ data class FrameEvaluate(val list: SpellList, val isMetacasting: Boolean) : Cont
"isMetacasting" %= isMetacasting
}

override fun size() = list.size()
override fun size() = list.size

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package at.petrak.hexcasting.api.casting.eval.vm

import at.petrak.hexcasting.api.casting.SpellList
import at.petrak.hexcasting.api.casting.eval.CastResult
import at.petrak.hexcasting.api.casting.eval.ResolvedPatternType
import at.petrak.hexcasting.api.casting.iota.Iota
Expand All @@ -26,16 +25,16 @@ import net.minecraft.server.level.ServerLevel
* @property immutableAcc concatenated list of final stack states after Thoth exit
*/
data class FrameForEach(
val data: SpellList,
val code: SpellList,
val data: TreeList<Iota>,
val code: TreeList<Iota>,
val baseStack: List<Iota>?,
val immutableAcc: TreeList<Iota>
) : ContinuationFrame {

@Deprecated("use the primary constructor that accepts a TreeList instead")
constructor(
data: SpellList,
code: SpellList,
data: TreeList<Iota>,
code: TreeList<Iota>,
baseStack: List<Iota>?,
acc: MutableList<Iota>
) : this(data, code, baseStack, TreeList.from(acc))
Expand Down Expand Up @@ -66,14 +65,14 @@ data class FrameForEach(
}

// If we still have data to process...
val (stackTop, newImage, newCont) = if (data.nonEmpty) {
val (stackTop, newImage, newCont) = if (!data.isEmpty()) {
// push the next datum to the top of the stack,
val cont2 = continuation
// put the next Thoth object back on the stack for the next Thoth cycle,
.pushFrame(FrameForEach(data.cdr, code, stack, newAcc))
.pushFrame(FrameForEach(data.tail(), code, stack, newAcc))
// and prep the Thoth'd code block for evaluation.
.pushFrame(FrameEvaluate(code, true))
Triple(data.car, harness.image.withUsedOp(), cont2)
Triple(data.head(), harness.image.withUsedOp(), cont2)
} else {
// Else, dump our final list onto the stack.
Triple(ListIota(immutableAcc), harness.image, continuation)
Expand All @@ -99,7 +98,7 @@ data class FrameForEach(
"accumulator" %= immutableAcc.serializeToNBT()
}

override fun size() = data.size() + code.size() + immutableAcc.size + (baseStack?.size ?: 0)
override fun size() = data.size + code.size + immutableAcc.size + (baseStack?.size ?: 0)

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package at.petrak.hexcasting.api.casting.iota;

import at.petrak.hexcasting.api.casting.SpellList;
import at.petrak.hexcasting.api.utils.HexUtils;
import at.petrak.hexcasting.api.utils.TreeList;
import at.petrak.hexcasting.common.lib.hex.HexIotaTypes;
import at.petrak.hexcasting.api.mod.HexConfig;
import java.util.ListIterator;
import net.minecraft.ChatFormatting;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
Expand All @@ -20,13 +20,13 @@
import static java.lang.Math.max;

/**
* This is a <i>wrapper</i> for {@link SpellList}.
* This is a <i>wrapper</i> for {@link TreeList} of {@link Iota}.
*/
public class ListIota extends Iota {
private final int depth;
private final int size;

public ListIota(@NotNull SpellList list) {
public ListIota(@NotNull TreeList<Iota> list) {
super(HexIotaTypes.LIST, list);
int maxChildDepth = 0;
int totalSize = 1;
Expand All @@ -38,21 +38,18 @@ public ListIota(@NotNull SpellList list) {
size = totalSize;
}

public ListIota(@NotNull TreeList<Iota> list) {
this(new SpellList.LList(list));
}

public ListIota(@NotNull List<Iota> list) {
this(new SpellList.LList(list));
this(TreeList.from(list));
}

public SpellList getList() {
return (SpellList) this.payload;
@SuppressWarnings("unchecked")
public TreeList<Iota> getList() {
return (TreeList<Iota>) this.payload;
}

@Override
public boolean isTruthy() {
return this.getList().getNonEmpty();
return !this.getList().isEmpty();
}

@Override
Expand All @@ -66,7 +63,7 @@ public boolean toleratesOther(Iota that) {
}
var b = list.getList();

SpellList.SpellListIterator aIter = a.iterator(), bIter = b.iterator();
ListIterator<Iota> aIter = a.iterator(), bIter = b.iterator();
for (; ; ) {
if (!aIter.hasNext() && !bIter.hasNext()) {
// we ran out together!
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package at.petrak.hexcasting.common.casting.actions.eval

import at.petrak.hexcasting.api.casting.SpellList
import at.petrak.hexcasting.api.casting.castables.Action
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.eval.OperationResult
Expand All @@ -11,6 +10,7 @@ import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation
import at.petrak.hexcasting.api.casting.evaluatable
import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.casting.mishaps.MishapNotEnoughArgs
import at.petrak.hexcasting.api.utils.TreeList
import at.petrak.hexcasting.common.lib.hex.HexEvalSounds

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

val instrsList = instrs.map({ SpellList.LList(0, listOf(it)) }, { it })
val instrsList = instrs.map({ TreeList.from(listOf(it)) }, { it })
val frame = FrameEvaluate(instrsList, true)

val image2 = image.withUsedOp().copy(stack = newStack)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package at.petrak.hexcasting.common.casting.actions.lists

import at.petrak.hexcasting.api.casting.SpellList
import at.petrak.hexcasting.api.casting.asActionResult
import at.petrak.hexcasting.api.casting.castables.ConstMediaAction
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
Expand All @@ -12,6 +11,6 @@ object OpCons : ConstMediaAction {
override fun execute(args: List<Iota>, env: CastingEnvironment): List<Iota> {
val bottom = args.getList(0, argc)
val top = args[1]
return SpellList.LPair(top, bottom).asActionResult
return bottom.prepended(top).asActionResult
}
}
Loading
Loading