ASM Bytecode Generation to unwrap Expressions of adv-expr API #94

Merged
CommanderTvis merged 44 commits from adv-expr into adv-expr 2020-06-13 21:07:15 +03:00
6 changed files with 22 additions and 21 deletions
Showing only changes of commit cedfd3fe09 - Show all commits

View File

@ -1,29 +1,27 @@
plugins { id("scientifik.mpp") } plugins {
repositories { maven("https://dl.bintray.com/hotkeytlt/maven") } id("scientifik.mpp")
}
repositories{
maven("https://dl.bintray.com/hotkeytlt/maven")
}
kotlin.sourceSets { kotlin.sourceSets {
commonMain { commonMain {
dependencies { dependencies {
api(project(":kmath-core")) api(project(":kmath-core"))
implementation("com.github.h0tk3y.betterParse:better-parse-multiplatform:0.4.0-alpha-3") implementation("com.github.h0tk3y.betterParse:better-parse-multiplatform:0.4.0-alpha-3")
implementation("com.github.h0tk3y.betterParse:better-parse-multiplatform-metadata:0.4.0-alpha-3")
} }
} }
jvmMain{
jvmMain { dependencies{
dependencies {
implementation("com.github.h0tk3y.betterParse:better-parse-jvm:0.4.0-alpha-3") implementation("com.github.h0tk3y.betterParse:better-parse-jvm:0.4.0-alpha-3")
implementation("org.ow2.asm:asm:8.0.1")
implementation("org.ow2.asm:asm-commons:8.0.1")
implementation(kotlin("reflect"))
} }
} }
jsMain{
jvmTest { dependencies{
dependencies { implementation("com.github.h0tk3y.betterParse:better-parse-js:0.4.0-alpha-3")
implementation(kotlin("test"))
implementation(kotlin("test-junit5"))
} }
} }
} }
tasks.withType<Test> { useJUnitPlatform() }

View File

@ -43,7 +43,7 @@ sealed class MST {
fun <T> NumericAlgebra<T>.evaluate(node: MST): T { fun <T> NumericAlgebra<T>.evaluate(node: MST): T {
return when (node) { return when (node) {
is MST.Numeric -> number(node.value) is MST.Numeric -> number(node.value)
is MST.Singular -> raw(node.value) is MST.Singular -> symbol(node.value)
is MST.Unary -> unaryOperation(node.operation, evaluate(node.value)) is MST.Unary -> unaryOperation(node.operation, evaluate(node.value))
is MST.Binary -> when { is MST.Binary -> when {
node.left is MST.Numeric && node.right is MST.Numeric -> { node.left is MST.Numeric && node.right is MST.Numeric -> {

View File

@ -12,7 +12,7 @@ class MSTExpression<T>(val algebra: NumericAlgebra<T>, val mst: MST) : Expressio
* Substitute algebra raw value * Substitute algebra raw value
*/ */
private inner class InnerAlgebra(val arguments: Map<String, T>) : NumericAlgebra<T> by algebra { private inner class InnerAlgebra(val arguments: Map<String, T>) : NumericAlgebra<T> by algebra {
override fun raw(value: String): T = arguments[value] ?: super.raw(value) override fun symbol(value: String): T = arguments[value] ?: super.symbol(value)
} }
override fun invoke(arguments: Map<String, T>): T = InnerAlgebra(arguments).evaluate(mst) override fun invoke(arguments: Map<String, T>): T = InnerAlgebra(arguments).evaluate(mst)

View File

@ -10,7 +10,10 @@ interface Algebra<T> {
/** /**
* Wrap raw string or variable * Wrap raw string or variable
*/ */
fun raw(value: String): T = error("Wrapping of '$value' is not supported in $this") fun symbol(value: String): T = error("Wrapping of '$value' is not supported in $this")
@Deprecated("Symbol is more concise",replaceWith = ReplaceWith("symbol"))
fun raw(value: String): T = symbol(value)
/** /**
* Dynamic call of unary operation with name [operation] on [arg] * Dynamic call of unary operation with name [operation] on [arg]

View File

@ -51,10 +51,10 @@ object ComplexField : ExtendedField<Complex> {
operator fun Double.times(c: Complex) = Complex(c.re * this, c.im * this) operator fun Double.times(c: Complex) = Complex(c.re * this, c.im * this)
override fun raw(value: String): Complex = if (value == "i") { override fun symbol(value: String): Complex = if (value == "i") {
i i
} else { } else {
super.raw(value) super.symbol(value)
} }
} }