consistency tweaks
This commit is contained in:
@@ -20,9 +20,6 @@ class Interpreter93(stdinSrc: PipedWriter, stdoutDest: PipedReader)
|
||||
|
||||
override fun stackDefault() = LongData.ZERO
|
||||
|
||||
override val onIpChange = Event<IpChange<Vec2, PointerMode>>()
|
||||
override val onStackChange = Event<StackChange<LongData>>()
|
||||
|
||||
override val stdin: PipedReader = PipedReader(stdinSrc)
|
||||
override val stdout: PipedWriter = PipedWriter(stdoutDest)
|
||||
|
||||
@@ -40,16 +37,16 @@ fun main(args: Array<String>) {
|
||||
|
||||
val int = Interpreter93(stdinSrc, stdoutDest)
|
||||
|
||||
int.onIpChange += {
|
||||
println(it.to.pos)
|
||||
}
|
||||
// int.onIpChange += {
|
||||
// println(it.to.pos)
|
||||
// }
|
||||
|
||||
// int.funge.src = """2>:3g" "-!v\ g30 <
|
||||
// |!`"O":+1_:.:03p>03g+:"O"`|
|
||||
// @ ^ p3\" ":<
|
||||
//2 234567890123456789012345678901234567890123456789012345678901234567890123456789"""
|
||||
|
||||
int.funge.src = """048ce.....@"""
|
||||
int.funge.src = """fedcba987654321>:#._@"""
|
||||
|
||||
while (int.ip.mode != PointerMode.Terminated) {
|
||||
int.step()
|
||||
|
||||
@@ -36,17 +36,17 @@ class B93Instructions : InstructionSet<Vec2, LongData, PointerMode> {
|
||||
'?' -> delta = Vec2.DIRS.chooseOne()
|
||||
'#' -> move()
|
||||
|
||||
'_' -> pop().let { n -> delta = if (n.data == 0L) Vec2.RIGHT else Vec2.LEFT }
|
||||
'|' -> pop().let { n -> delta = if (n.data == 0L) Vec2.DOWN else Vec2.UP }
|
||||
'_' -> pop(1).let { (n) -> delta = if (n.data == 0L) Vec2.RIGHT else Vec2.LEFT }
|
||||
'|' -> pop(1).let { (n) -> delta = if (n.data == 0L) Vec2.DOWN else Vec2.UP }
|
||||
|
||||
'"' -> mode = PointerMode.String
|
||||
|
||||
':' -> pop().let { n -> push(n, n) }
|
||||
':' -> pop(1).let { (n) -> push(n, n) }
|
||||
'\\' -> pop(2).let { (b, a) -> push(b, a) }
|
||||
'$' -> pop()
|
||||
'$' -> pop(1)
|
||||
|
||||
'.' -> pop().let { n -> stdout.write("${n.data} ") }
|
||||
',' -> pop().let { ch -> stdout.write(ch.data.toChar().toString()) }
|
||||
'.' -> pop(1).let { (n) -> stdout.write("${n.data} ") }
|
||||
',' -> pop(1).let { (ch) -> stdout.write(ch.data.toChar().toString()) }
|
||||
|
||||
'p' -> pop(3).let { (y, x, n) -> funge[Vec2(x.data.toInt(), y.data.toInt())] = n }
|
||||
'g' -> pop(2).let { (y, x) -> push(funge[Vec2(x.data.toInt(), y.data.toInt())]) }
|
||||
@@ -3,10 +3,6 @@ package befide.befunge.b93.state
|
||||
import befide.befunge.core.state.MutablePointer
|
||||
import befide.befunge.core.state.Pointer
|
||||
|
||||
enum class PointerMode {
|
||||
Normal, String, Terminated
|
||||
}
|
||||
|
||||
data class Pointer93(override var pos: Vec2 = Vec2.ZERO,
|
||||
override var delta: Vec2 = Vec2.RIGHT,
|
||||
override var mode: PointerMode = PointerMode.Normal)
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package befide.befunge.b93.state
|
||||
|
||||
enum class PointerMode {
|
||||
Normal, String, Terminated
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import befide.befunge.core.events.StackOp
|
||||
import befide.befunge.core.state.Data
|
||||
import befide.befunge.core.state.MutableFunge
|
||||
import befide.befunge.core.state.MutablePointer
|
||||
import befide.befunge.core.util.Event
|
||||
import java.util.*
|
||||
|
||||
abstract class MutableInterpreter<V, D : Data, M : Enum<M>>
|
||||
@@ -16,6 +17,9 @@ abstract class MutableInterpreter<V, D : Data, M : Enum<M>>
|
||||
|
||||
abstract val instructionSet: InstructionSet<V, D, M>
|
||||
|
||||
override val onIpChange: Event<IpChange<V, M>> = Event()
|
||||
override val onStackChange: Event<StackChange<D>> = Event()
|
||||
|
||||
override fun step() {
|
||||
instructionSet.step(this)
|
||||
move()
|
||||
@@ -51,11 +55,11 @@ abstract class MutableInterpreter<V, D : Data, M : Enum<M>>
|
||||
}
|
||||
|
||||
fun pop(): D = notifyStack(StackOp.Pop) {
|
||||
if (stack.empty()) stackDefault() else stack.pop()
|
||||
return@notifyStack if (stack.empty()) stackDefault() else stack.pop()
|
||||
}
|
||||
|
||||
fun pop(n: Int): List<D> {
|
||||
return (0 until n).map { notifyStack(StackOp.Pop) { stack.pop() } }
|
||||
return (0 until n).map { pop() }
|
||||
}
|
||||
|
||||
fun push(vararg data: D) {
|
||||
|
||||
Reference in New Issue
Block a user