initial commit: overall class structure and small maven-compatible tornadofx app
This commit is contained in:
43
befunge/befunge.iml
Normal file
43
befunge/befunge.iml
Normal file
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="kotlin-language" name="Kotlin">
|
||||
<configuration version="3" platform="JVM 1.8" useProjectSettings="false">
|
||||
<compilerSettings />
|
||||
<compilerArguments>
|
||||
<option name="jvmTarget" value="1.8" />
|
||||
<option name="languageVersion" value="1.3" />
|
||||
<option name="apiVersion" value="1.3" />
|
||||
<option name="pluginOptions">
|
||||
<array />
|
||||
</option>
|
||||
<option name="pluginClasspaths">
|
||||
<array />
|
||||
</option>
|
||||
</compilerArguments>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/kotlin" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/kotlin" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/../ide/src/main/resources" type="java-resource" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<content url="file://$MODULE_DIR$/../ide/src/main/resources" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib:1.3.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib-common:1.3.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jetbrains:annotations:13.0" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.jetbrains.kotlin:kotlin-test-junit:1.3.0" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.jetbrains.kotlin:kotlin-test-annotations-common:1.3.0" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.jetbrains.kotlin:kotlin-test:1.3.0" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.jetbrains.kotlin:kotlin-test-common:1.3.0" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
71
befunge/pom.xml
Normal file
71
befunge/pom.xml
Normal file
@@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>befide</groupId>
|
||||
<artifactId>befunge</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>befide befunge</name>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<kotlin.version>1.3.0</kotlin.version>
|
||||
<junit.version>4.12</junit.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-test-junit</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>src/main/kotlin</sourceDirectory>
|
||||
<!--<testSourceDirectory>src/test/kotlin</testSourceDirectory>-->
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>test-compile</id>
|
||||
<phase>test-compile</phase>
|
||||
<goals>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<jvmTarget>1.8</jvmTarget>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
26
befunge/src/main/kotlin/befide/befunge/b93/B93Funge.kt
Normal file
26
befunge/src/main/kotlin/befide/befunge/b93/B93Funge.kt
Normal file
@@ -0,0 +1,26 @@
|
||||
package befide.befunge.b93
|
||||
|
||||
import befide.befunge.core.*
|
||||
import befide.befunge.state.*
|
||||
|
||||
class B93Funge : Funge {
|
||||
override val width = 80
|
||||
override val height = 25
|
||||
|
||||
override fun get(vec: Vec): Value {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
override fun set(vec: Vec, value: Value) {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
override fun nextVec(vec: Vec, delta: Vec): Vec {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
override fun setString(data: String) {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
|
||||
29
befunge/src/main/kotlin/befide/befunge/b93/B93Interpreter.kt
Normal file
29
befunge/src/main/kotlin/befide/befunge/b93/B93Interpreter.kt
Normal file
@@ -0,0 +1,29 @@
|
||||
package befide.befunge.b93
|
||||
|
||||
import befide.befunge.core.Interpreter
|
||||
import befide.befunge.events.Event
|
||||
import befide.befunge.events.FungeEvent
|
||||
import befide.befunge.events.IpEvent
|
||||
import befide.befunge.events.StackEvent
|
||||
import befide.befunge.state.IpMode
|
||||
import befide.befunge.state.Value
|
||||
import befide.befunge.state.Vec
|
||||
import java.util.*
|
||||
|
||||
class B93Interpreter : Interpreter {
|
||||
override val funge = B93Funge()
|
||||
override val stack = Stack<Value>()
|
||||
override val ip = B93Pointer(Vec(0, 0), Vec(1, 0), IpMode.Normal)
|
||||
|
||||
override val fungeChanged: Event<FungeEvent> = Event()
|
||||
override val stackChanged: Event<StackEvent> = Event()
|
||||
override val ipChanged: Event<IpEvent> = Event()
|
||||
|
||||
override fun step(): Boolean {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
override fun reset() {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
7
befunge/src/main/kotlin/befide/befunge/b93/B93Pointer.kt
Normal file
7
befunge/src/main/kotlin/befide/befunge/b93/B93Pointer.kt
Normal file
@@ -0,0 +1,7 @@
|
||||
package befide.befunge.b93
|
||||
|
||||
import befide.befunge.core.Pointer
|
||||
import befide.befunge.state.IpMode
|
||||
import befide.befunge.state.Vec
|
||||
|
||||
data class B93Pointer(override val pos: Vec, override val delta: Vec, override val mode: IpMode) : Pointer
|
||||
33
befunge/src/main/kotlin/befide/befunge/core/Funge.kt
Normal file
33
befunge/src/main/kotlin/befide/befunge/core/Funge.kt
Normal file
@@ -0,0 +1,33 @@
|
||||
package befide.befunge.core
|
||||
|
||||
import befide.befunge.events.Event
|
||||
import befide.befunge.events.FungeEvent
|
||||
import befide.befunge.state.Value
|
||||
import befide.befunge.state.Vec
|
||||
|
||||
interface Funge {
|
||||
val width: Int
|
||||
val height: Int
|
||||
|
||||
operator fun get(vec: Vec): Value
|
||||
operator fun set(vec: Vec, value: Value)
|
||||
|
||||
fun nextVec(vec: Vec, delta: Vec): Vec
|
||||
|
||||
fun setString(data: String)
|
||||
|
||||
fun nextVecs(vec: Vec, delta: Vec): Iterable<Vec> {
|
||||
return generateSequence(vec) {
|
||||
nextVec(it, delta)
|
||||
}.asIterable()
|
||||
}
|
||||
|
||||
fun setMany(vec: Vec, delta: Vec, data: List<Value>) {
|
||||
for ((e, v) in data.zip(nextVecs(vec, delta)))
|
||||
set(v, e)
|
||||
}
|
||||
|
||||
fun getMany(vec: Vec, delta: Vec, count: Int): Iterable<Value> {
|
||||
return nextVecs(vec, delta).take(count).map(this::get).asIterable()
|
||||
}
|
||||
}
|
||||
22
befunge/src/main/kotlin/befide/befunge/core/Interpreter.kt
Normal file
22
befunge/src/main/kotlin/befide/befunge/core/Interpreter.kt
Normal file
@@ -0,0 +1,22 @@
|
||||
package befide.befunge.core
|
||||
|
||||
import befide.befunge.events.Event
|
||||
import befide.befunge.events.FungeEvent
|
||||
import befide.befunge.events.IpEvent
|
||||
import befide.befunge.events.StackEvent
|
||||
import befide.befunge.state.Value
|
||||
import java.util.*
|
||||
|
||||
interface Interpreter {
|
||||
val funge: Funge
|
||||
val stack: Stack<Value>
|
||||
val ip: Pointer
|
||||
|
||||
val fungeChanged: Event<FungeEvent>
|
||||
val stackChanged: Event<StackEvent>
|
||||
val ipChanged: Event<IpEvent>
|
||||
|
||||
fun step(): Boolean
|
||||
fun reset()
|
||||
}
|
||||
|
||||
12
befunge/src/main/kotlin/befide/befunge/core/Pointer.kt
Normal file
12
befunge/src/main/kotlin/befide/befunge/core/Pointer.kt
Normal file
@@ -0,0 +1,12 @@
|
||||
package befide.befunge.core
|
||||
|
||||
import befide.befunge.events.Event
|
||||
import befide.befunge.events.IpEvent
|
||||
import befide.befunge.state.IpMode
|
||||
import befide.befunge.state.Vec
|
||||
|
||||
interface Pointer {
|
||||
val pos: Vec
|
||||
val delta: Vec
|
||||
val mode: IpMode
|
||||
}
|
||||
57
befunge/src/main/kotlin/befide/befunge/events/Event.kt
Normal file
57
befunge/src/main/kotlin/befide/befunge/events/Event.kt
Normal file
@@ -0,0 +1,57 @@
|
||||
package befide.befunge.events
|
||||
|
||||
/**
|
||||
* Source is pulled unmodified from https://github.com/notiocide/kotlin-events, under the MIT licence
|
||||
*/
|
||||
|
||||
import java.util.function.Consumer
|
||||
|
||||
typealias Handler<EventType> = Consumer<EventType>
|
||||
|
||||
internal operator fun <T> Handler<T>.invoke(t: T) = accept(t)
|
||||
|
||||
class Event<T> : Iterable<MutableMap.MutableEntry<String, Handler<T>>> {
|
||||
|
||||
private val list = LinkedHashMap<String, Handler<T>>()
|
||||
|
||||
var nextUnnamedIndex = 0L
|
||||
private set
|
||||
|
||||
val size: Int @JvmName("size") get() = list.size
|
||||
val listeners: MutableCollection<MutableMap.MutableEntry<String, Handler<T>>> get() = list.entries
|
||||
|
||||
fun clear() = list.clear()
|
||||
|
||||
override operator fun iterator() = list.iterator()
|
||||
|
||||
@JvmName("add")
|
||||
operator fun plusAssign(handler: Handler<T>) {
|
||||
list.put("${nextUnnamedIndex++}", handler)
|
||||
}
|
||||
|
||||
@JvmName("put")
|
||||
operator fun set(name: String, handler: Handler<T>) {
|
||||
list.put(name, handler)
|
||||
}
|
||||
|
||||
@JvmName("add")
|
||||
inline operator fun plusAssign(crossinline handler: (T) -> Unit) {
|
||||
this += Handler { handler(it) }
|
||||
}
|
||||
|
||||
@JvmName("put")
|
||||
inline operator fun set(name: String, crossinline handler: (T) -> Unit) {
|
||||
this[name] = Handler { handler(it) }
|
||||
}
|
||||
|
||||
@JvmName("remove")
|
||||
operator fun minusAssign(name: String) {
|
||||
list.remove(name)
|
||||
}
|
||||
|
||||
@JvmName("handle")
|
||||
operator fun invoke(data: T) {
|
||||
for ((_, value) in this) value(data)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package befide.befunge.events
|
||||
|
||||
import befide.befunge.state.Value
|
||||
import befide.befunge.state.Vec
|
||||
|
||||
data class FungeEvent(val vec: Vec, val from: Value, val to: Value)
|
||||
5
befunge/src/main/kotlin/befide/befunge/events/IpEvent.kt
Normal file
5
befunge/src/main/kotlin/befide/befunge/events/IpEvent.kt
Normal file
@@ -0,0 +1,5 @@
|
||||
package befide.befunge.events
|
||||
|
||||
import befide.befunge.core.Pointer
|
||||
|
||||
data class IpEvent(val from: Pointer, val to: Pointer)
|
||||
@@ -0,0 +1,7 @@
|
||||
package befide.befunge.events
|
||||
|
||||
enum class StackAction {
|
||||
Push,
|
||||
Pop,
|
||||
Clear
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package befide.befunge.events
|
||||
|
||||
import befide.befunge.state.Value
|
||||
|
||||
data class StackEvent(val op: StackAction, val values: List<Value>)
|
||||
7
befunge/src/main/kotlin/befide/befunge/state/IpMode.kt
Normal file
7
befunge/src/main/kotlin/befide/befunge/state/IpMode.kt
Normal file
@@ -0,0 +1,7 @@
|
||||
package befide.befunge.state
|
||||
|
||||
enum class IpMode {
|
||||
Normal,
|
||||
String,
|
||||
Char
|
||||
}
|
||||
7
befunge/src/main/kotlin/befide/befunge/state/Value.kt
Normal file
7
befunge/src/main/kotlin/befide/befunge/state/Value.kt
Normal file
@@ -0,0 +1,7 @@
|
||||
package befide.befunge.state
|
||||
|
||||
data class Value(val value: Int) {
|
||||
constructor(value: Char) : this(value.toInt())
|
||||
|
||||
val asChar: Char? = if (value in (32..126)) value.toChar() else null
|
||||
}
|
||||
6
befunge/src/main/kotlin/befide/befunge/state/Vec.kt
Normal file
6
befunge/src/main/kotlin/befide/befunge/state/Vec.kt
Normal file
@@ -0,0 +1,6 @@
|
||||
package befide.befunge.state
|
||||
|
||||
data class Vec(val x: Int, val y: Int) {
|
||||
operator fun plus(other: Vec) = Vec(x + other.x, y + other.y)
|
||||
operator fun times(c: Int) = Vec(x * c, y * c)
|
||||
}
|
||||
Reference in New Issue
Block a user