Provide dynamic operations currying for Algebra<T> instead of eager calls and add JS code generation support #162
@ -2,7 +2,7 @@ package kscience.kmath.estree
|
|||||||
|
|
||||||
import kscience.kmath.ast.MST
|
import kscience.kmath.ast.MST
|
||||||
import kscience.kmath.ast.MstExpression
|
import kscience.kmath.ast.MstExpression
|
||||||
import kscience.kmath.estree.internal.JSBuilder
|
import kscience.kmath.estree.internal.ESTreeBuilder
|
||||||
import kscience.kmath.estree.internal.estree.BaseExpression
|
import kscience.kmath.estree.internal.estree.BaseExpression
|
||||||
import kscience.kmath.expressions.Expression
|
import kscience.kmath.expressions.Expression
|
||||||
import kscience.kmath.operations.Algebra
|
import kscience.kmath.operations.Algebra
|
||||||
@ -11,7 +11,7 @@ import kscience.kmath.operations.RealField
|
|||||||
|
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
internal fun <T> MST.compileWith(algebra: Algebra<T>): Expression<T> {
|
internal fun <T> MST.compileWith(algebra: Algebra<T>): Expression<T> {
|
||||||
fun JSBuilder<T>.visit(node: MST): BaseExpression = when (node) {
|
fun ESTreeBuilder<T>.visit(node: MST): BaseExpression = when (node) {
|
||||||
is MST.Symbolic -> {
|
is MST.Symbolic -> {
|
||||||
val symbol = try {
|
val symbol = try {
|
||||||
algebra.symbol(node.value)
|
algebra.symbol(node.value)
|
||||||
@ -57,7 +57,7 @@ internal fun <T> MST.compileWith(algebra: Algebra<T>): Expression<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return JSBuilder<T> { visit(this@compileWith) }.instance
|
return ESTreeBuilder<T> { visit(this@compileWith) }.instance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -5,7 +5,7 @@ import kscience.kmath.estree.internal.estree.*
|
|||||||
import kscience.kmath.expressions.Expression
|
import kscience.kmath.expressions.Expression
|
||||||
import kscience.kmath.expressions.Symbol
|
import kscience.kmath.expressions.Symbol
|
||||||
|
|
||||||
internal class JSBuilder<T>(val bodyCallback: JSBuilder<T>.() -> BaseExpression) {
|
internal class ESTreeBuilder<T>(val bodyCallback: ESTreeBuilder<T>.() -> BaseExpression) {
|
||||||
private class GeneratedExpression<T>(val executable: dynamic, val constants: Array<dynamic>) : Expression<T> {
|
private class GeneratedExpression<T>(val executable: dynamic, val constants: Array<dynamic>) : Expression<T> {
|
||||||
@Suppress("UNUSED_VARIABLE")
|
@Suppress("UNUSED_VARIABLE")
|
||||||
override fun invoke(arguments: Map<Symbol, T>): T {
|
override fun invoke(arguments: Map<Symbol, T>): T {
|
Loading…
Reference in New Issue
Block a user