Merge remote-tracking branch 'mipt-npm/adv-expr' into adv-expr-asm
# Conflicts: # kmath-ast/build.gradle.kts # kmath-ast/src/commonMain/kotlin/scientifik/kmath/ast/parser.kt # kmath-ast/src/jvmMain/kotlin/scientifik/kmath/ast/Parser.kt # kmath-ast/src/jvmMain/kotlin/scientifik/kmath/ast/parser.kt
This commit is contained in:
commit
cedfd3fe09
@ -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(kotlin("test"))
|
implementation("com.github.h0tk3y.betterParse:better-parse-js:0.4.0-alpha-3")
|
||||||
implementation(kotlin("test-junit5"))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType<Test> { useJUnitPlatform() }
|
|
||||||
|
@ -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 -> {
|
||||||
|
@ -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)
|
||||||
|
@ -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]
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user