[orx-expression-evaluator] Remove all Kotlin JVM specific code, fix sourceset dependencies

This commit is contained in:
Edwin Jakobs
2024-01-05 12:57:01 +01:00
parent 456596aba7
commit 31c14c35cb
2 changed files with 10 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
import com.strumenta.antlrkotlin.gradle.AntlrKotlinTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
plugins {
org.openrndr.extra.convention.`kotlin-multiplatform`
@@ -29,9 +29,6 @@ val generateKotlinGrammarSource = tasks.register<AntlrKotlinTask>("generateKotli
outputDirectory = layout.buildDirectory.dir(outDir).get().asFile
}
tasks.withType<KotlinCompile> {
kotlinOptions.freeCompilerArgs = listOf("-opt-in=kotlin.RequiresOptIn")
}
kotlin {
sourceSets {
@@ -61,6 +58,6 @@ kotlin {
}
}
tasks.withType<KotlinCompile> {
tasks.withType<KotlinCompile<*>> {
dependsOn(generateKotlinGrammarSource)
}

View File

@@ -5,13 +5,14 @@ package org.openrndr.extra.expressions
import org.antlr.v4.kotlinruntime.*
import org.antlr.v4.kotlinruntime.tree.ParseTreeWalker
import org.antlr.v4.kotlinruntime.tree.TerminalNode
import org.openrndr.collections.pop
import org.openrndr.collections.push
import org.openrndr.expressions.parser.KeyLangLexer
import org.openrndr.expressions.parser.KeyLangParser
import org.openrndr.expressions.parser.KeyLangParserBaseListener
import org.openrndr.extra.noise.uniform
import org.openrndr.math.*
import java.util.*
import kotlin.math.*
typealias Function0 = () -> Double
@@ -49,14 +50,14 @@ internal class ExpressionListener(
val constants: Map<String, Double> = mapOf()
) :
KeyLangParserBaseListener() {
val doubleStack = Stack<Double>()
val functionStack = Stack<(DoubleArray) -> Double>()
val doubleStack = ArrayDeque<Double>()
val functionStack = ArrayDeque<(DoubleArray) -> Double>()
val idTypeStack = Stack<IDType>()
val idTypeStack = ArrayDeque<IDType>()
var lastExpressionResult: Double? = null
val exceptionStack = Stack<ExpressionException>()
val exceptionStack = ArrayDeque<ExpressionException>()
override fun exitExpressionStatement(ctx: KeyLangParser.ExpressionStatementContext) {
@@ -280,8 +281,8 @@ internal class ExpressionListener(
val function: (DoubleArray) -> Double =
when (name) {
"sqrt" -> { x -> sqrt(x[0]) }
"radians" -> { x -> Math.toRadians(x[0]) }
"degrees" -> { x -> Math.toDegrees(x[0]) }
"radians" -> { x -> x[0].asRadians }
"degrees" -> { x -> x[0].asDegrees }
"cos" -> { x -> cos(x[0]) }
"sin" -> { x -> sin(x[0]) }
"tan" -> { x -> tan(x[0]) }