Complete conversion to kotlin

Resolves #5 and #16
This commit is contained in:
Mike Cifelli 2018-11-18 08:42:51 -05:00
parent 698df036ff
commit 5c183e94fb
10 changed files with 8 additions and 62 deletions

40
pom.xml
View File

@ -10,7 +10,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.version>1.3.0</kotlin.version>
<kotlin.version>1.3.10</kotlin.version>
<junit5.version>5.3.1</junit5.version>
<skipTests>false</skipTests>
</properties>
@ -57,7 +57,6 @@
</configuration>
</plugin>
<!-- TODO - remove when everything is converted to kotlin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
@ -75,14 +74,14 @@
</execution>
<execution>
<id>java-compile</id>
<phase>compile</phase>
<phase>none</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<phase>none</phase>
<goals>
<goal>testCompile</goal>
</goals>
@ -97,25 +96,9 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit5.version}</version>
</dependency>
<!-- TODO - remove when all test cases converted to junit 5 -->
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit5.version}</version>
</dependency>
</dependencies>
<version>3.0.0-M1</version>
<configuration>
<skipTests>${skipTests}</skipTests>
<!-- TODO - this is a workaround for a bug, remove when surefire is updated to 3.x -->
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
@ -190,26 +173,19 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
<!-- TODO - remove when all test cases converted to junit 5 -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
<!-- TODO - remove when test cases all converted to junit 5 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.fitnesse</groupId>
<artifactId>fitnesse</artifactId>

View File

@ -101,7 +101,6 @@ class Eval(name: String) : LispFunction() {
private fun lookupEval() = lookupFunction("EVAL") as Eval
@JvmStatic
fun eval(sExpression: SExpression): SExpression {
try {
return lookupEval().call(makeList(sExpression))
@ -111,14 +110,11 @@ class Eval(name: String) : LispFunction() {
}
}
@JvmStatic
fun applyFunction(function: LispFunction, argumentList: Cons) =
lookupEval().applyFunctionWithoutEvaluatingArguments(function, argumentList)
@JvmStatic
fun evaluateFunctionArgumentList(argumentList: Cons) = lookupEval().evaluateArgumentList(argumentList)
@JvmStatic
fun lookupSymbol(symbolName: String) = when {
symbolName == "NIL" -> Nil
symbolName == "T" -> T
@ -126,7 +122,6 @@ class Eval(name: String) : LispFunction() {
else -> ExecutionContext.lookupSymbolValue(symbolName)
}
@JvmStatic
fun lookupFunctionOrLambda(functionExpression: SExpression): LispFunction {
val function = lookupFunction(functionExpression.toString())

View File

@ -46,7 +46,6 @@ class Set(name: String) : LispFunction() {
companion object {
@JvmStatic
fun set(argumentList: Cons) = lookupFunction("SET")!!.call(argumentList)
}
}

View File

@ -53,7 +53,6 @@ class Append(name: String) : LispFunction() {
companion object {
@JvmStatic
fun append(firstList: Cons, secondList: Cons): Cons {
return lookupAppend().appendLists(firstList, secondList)
}

View File

@ -20,7 +20,6 @@ class List(name: String) : LispFunction() {
companion object {
@JvmStatic
fun makeList(sexpr: SExpression): Cons {
return Cons(sexpr, Nil)
}

View File

@ -2,12 +2,10 @@ package recursion
object TailCalls {
@JvmStatic
fun <T> tailCall(nextCall: () -> TailCall<T>) = object : TailCall<T> {
override fun apply() = nextCall()
}
@JvmStatic
fun <T> done(value: T) = object : TailCall<T> {
override fun isComplete() = true
override fun result() = value

View File

@ -45,7 +45,6 @@ class ControlSequenceHandler {
companion object {
@JvmStatic
fun isEscape(c: Char): Boolean {
return c == UNICODE_ESCAPE
}

View File

@ -47,7 +47,6 @@ enum class SelectGraphicRendition : ControlSequence {
companion object {
@JvmStatic
val SGR_COMMAND = 'm'
}
}

View File

@ -16,10 +16,8 @@ import java.util.Arrays
object TestUtilities {
@JvmStatic
fun createInputStreamFromString(string: String) = ByteArrayInputStream(string.toByteArray())
@JvmStatic
fun createIOExceptionThrowingInputStream() = object : InputStream() {
override fun read(): Int {
@ -31,7 +29,6 @@ object TestUtilities {
}
}
@JvmStatic
fun createIOExceptionThrowingOutputStream() = object : OutputStream() {
override fun write(b: ByteArray) {
@ -51,17 +48,14 @@ object TestUtilities {
}
}
@JvmStatic
fun evaluateString(input: String): SExpression = eval(parseString(input))
@JvmStatic
fun parseString(input: String): SExpression {
val stringInputStream = TestUtilities.createInputStreamFromString(input)
return LispParser(stringInputStream, "testFile").nextSExpression()
}
@JvmStatic
fun makeList(vararg expressionList: SExpression): Cons {
if (expressionList.isEmpty())
return Nil
@ -71,17 +65,14 @@ object TestUtilities {
return Cons(expressionList[0], rest)
}
@JvmStatic
fun assertSExpressionsMatch(expected: SExpression, actual: SExpression) {
assertThat(actual.toString()).isEqualTo(expected.toString())
}
@JvmStatic
fun assertSExpressionsDoNotMatch(unexpected: SExpression, actual: SExpression) {
assertThat(actual.toString()).isNotEqualTo(unexpected.toString())
}
@JvmStatic
fun assertIsErrorWithMessage(e: LispException) {
assertThat(e.severity).isEqualTo(ERROR)
assertThat(e.message).isNotEmpty()

View File

@ -7,7 +7,6 @@ import sexpression.Symbol.Companion.T
object TypeAssertions {
@JvmStatic
fun assertList(sExpression: SExpression) {
assertThat(sExpression.isAtom).isFalse()
assertThat(sExpression.isCons).isTrue()
@ -22,7 +21,6 @@ object TypeAssertions {
assertThat(sExpression.isAtSign).isFalse()
}
@JvmStatic
fun assertNil(sExpression: SExpression) {
assertThat(sExpression).isEqualTo(Nil)
@ -39,7 +37,6 @@ object TypeAssertions {
assertThat(sExpression.isAtSign).isFalse()
}
@JvmStatic
fun assertNumber(sExpression: SExpression) {
assertThat(sExpression.isAtom).isTrue()
assertThat(sExpression.isCons).isFalse()
@ -54,7 +51,6 @@ object TypeAssertions {
assertThat(sExpression.isAtSign).isFalse()
}
@JvmStatic
fun assertString(sExpression: SExpression) {
assertThat(sExpression.isAtom).isTrue()
assertThat(sExpression.isCons).isFalse()
@ -69,7 +65,6 @@ object TypeAssertions {
assertThat(sExpression.isAtSign).isFalse()
}
@JvmStatic
fun assertSymbol(sExpression: SExpression) {
assertThat(sExpression.isAtom).isTrue()
assertThat(sExpression.isCons).isFalse()
@ -84,12 +79,10 @@ object TypeAssertions {
assertThat(sExpression.isAtSign).isFalse()
}
@JvmStatic
fun assertT(sExpression: SExpression) {
assertThat(sExpression).isEqualTo(T)
}
@JvmStatic
fun assertBackTickExpression(sExpression: SExpression) {
assertThat(sExpression.isAtom).isFalse()
assertThat(sExpression.isCons).isFalse()
@ -104,7 +97,6 @@ object TypeAssertions {
assertThat(sExpression.isAtSign).isFalse()
}
@JvmStatic
fun assertCommaExpression(sExpression: SExpression) {
assertThat(sExpression.isAtom).isFalse()
assertThat(sExpression.isCons).isFalse()
@ -119,7 +111,6 @@ object TypeAssertions {
assertThat(sExpression.isAtSign).isFalse()
}
@JvmStatic
fun assertAtSignExpression(sExpression: SExpression) {
assertThat(sExpression.isAtom).isFalse()
assertThat(sExpression.isCons).isFalse()