actually implement #291 ops with a generic-er class
This commit is contained in:
parent
399f8c5cad
commit
5258208585
6 changed files with 19 additions and 66 deletions
|
@ -90,23 +90,29 @@ public class RegisterPatterns {
|
|||
|
||||
// == Modify Stack ==
|
||||
|
||||
PatternRegistry.mapPattern(HexPattern.fromAngles("aawdd", HexDir.EAST), modLoc("swap"), OpSwap.INSTANCE);
|
||||
PatternRegistry.mapPattern(HexPattern.fromAngles("aawdd", HexDir.EAST), modLoc("swap"),
|
||||
new OpTwiddling(2, new int[]{1, 0}));
|
||||
PatternRegistry.mapPattern(HexPattern.fromAngles("aaeaa", HexDir.EAST), modLoc("rotate"),
|
||||
OpRotate.INSTANCE);
|
||||
new OpTwiddling(3, new int[]{1, 2, 0}));
|
||||
PatternRegistry.mapPattern(HexPattern.fromAngles("ddqdd", HexDir.NORTH_EAST), modLoc("rotate-reverse"),
|
||||
new OpTwiddling(3, new int[]{2, 0, 1}));
|
||||
PatternRegistry.mapPattern(HexPattern.fromAngles("aadaa", HexDir.EAST), modLoc("duplicate"),
|
||||
OpDuplicate.INSTANCE);
|
||||
PatternRegistry.mapPattern(HexPattern.fromAngles("aadaadaa", HexDir.EAST), modLoc("duplicate_n"),
|
||||
OpDuplicateN.INSTANCE);
|
||||
new OpTwiddling(1, new int[]{0, 0}));
|
||||
PatternRegistry.mapPattern(HexPattern.fromAngles("aaedd", HexDir.EAST), modLoc("over"),
|
||||
OpOver.INSTANCE);
|
||||
new OpTwiddling(2, new int[]{0, 1, 0}));
|
||||
PatternRegistry.mapPattern(HexPattern.fromAngles("ddqaa", HexDir.EAST), modLoc("tuck"),
|
||||
new OpTwiddling(2, new int[]{1, 0, 1}));
|
||||
PatternRegistry.mapPattern(HexPattern.fromAngles("aadadaaw", HexDir.EAST), modLoc("2dup"),
|
||||
new OpTwiddling(2, new int[]{0, 1, 0, 1}));
|
||||
|
||||
PatternRegistry.mapPattern(HexPattern.fromAngles("qwaeawqaeaqa", HexDir.NORTH_WEST), modLoc("stack_len"),
|
||||
OpStackSize.INSTANCE);
|
||||
PatternRegistry.mapPattern(HexPattern.fromAngles("aadaadaa", HexDir.EAST), modLoc("duplicate_n"),
|
||||
OpDuplicateN.INSTANCE);
|
||||
PatternRegistry.mapPattern(HexPattern.fromAngles("ddad", HexDir.WEST), modLoc("fisherman"),
|
||||
OpFisherman.INSTANCE);
|
||||
PatternRegistry.mapPattern(HexPattern.fromAngles("aada", HexDir.EAST), modLoc("fisherman/copy"),
|
||||
OpFishermanButItCopies.INSTANCE);
|
||||
PatternRegistry.mapPattern(HexPattern.fromAngles("wad", HexDir.EAST), modLoc("nip"),
|
||||
OpNip.INSTANCE);
|
||||
PatternRegistry.mapPattern(HexPattern.fromAngles("qaawdde", HexDir.SOUTH_EAST), modLoc("swizzle"),
|
||||
OpAlwinfyHasAscendedToABeingOfPureMath.INSTANCE);
|
||||
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.stack
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstMediaAction
|
||||
import at.petrak.hexcasting.api.spell.casting.CastingContext
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
|
||||
object OpNip : ConstMediaAction {
|
||||
override val argc: Int
|
||||
get() = 2
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> = listOf(args[1])
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.stack
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstMediaAction
|
||||
import at.petrak.hexcasting.api.spell.casting.CastingContext
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
|
||||
// Had never heard of this operation before i heard it from uxn, but turns out it's from forth
|
||||
// see also http://www.forth.org/Ting/Forth-for-the-Complete-Idiot/Forth-79-Handy-Reference.pdf
|
||||
// "fisherman's" is called "roll," apparently
|
||||
object OpOver : ConstMediaAction {
|
||||
override val argc: Int
|
||||
get() = 2
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> = listOf(args[0], args[1], args[0])
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.stack
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstMediaAction
|
||||
import at.petrak.hexcasting.api.spell.casting.CastingContext
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
|
||||
// more Forth
|
||||
object OpRotate : ConstMediaAction {
|
||||
override val argc: Int
|
||||
get() = 3
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> = listOf(args[1], args[2], args[0])
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package at.petrak.hexcasting.common.casting.operators.stack
|
||||
|
||||
import at.petrak.hexcasting.api.spell.ConstMediaAction
|
||||
import at.petrak.hexcasting.api.spell.casting.CastingContext
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
|
||||
object OpSwap : ConstMediaAction {
|
||||
override val argc: Int
|
||||
get() = 2
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
|
||||
return args.asReversed()
|
||||
}
|
||||
}
|
|
@ -4,9 +4,10 @@ import at.petrak.hexcasting.api.spell.ConstMediaAction
|
|||
import at.petrak.hexcasting.api.spell.casting.CastingContext
|
||||
import at.petrak.hexcasting.api.spell.iota.Iota
|
||||
|
||||
object OpDuplicate : ConstMediaAction {
|
||||
class OpTwiddling(val argumentCount: Int, val lookup: IntArray) : ConstMediaAction {
|
||||
override val argc: Int
|
||||
get() = 1
|
||||
get() = this.argumentCount
|
||||
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> = listOf(args[0], args[0])
|
||||
}
|
||||
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> =
|
||||
this.lookup.map(args::get)
|
||||
}
|
Loading…
Reference in a new issue