diff --git a/kmath-ast/src/jsMain/kotlin/kscience/kmath/ast/Initial.kt b/kmath-ast/src/jsMain/kotlin/kscience/kmath/wasm/internal/Initial.kt similarity index 99% rename from kmath-ast/src/jsMain/kotlin/kscience/kmath/ast/Initial.kt rename to kmath-ast/src/jsMain/kotlin/kscience/kmath/wasm/internal/Initial.kt index 2178b23d3..c50ad553d 100644 --- a/kmath-ast/src/jsMain/kotlin/kscience/kmath/ast/Initial.kt +++ b/kmath-ast/src/jsMain/kotlin/kscience/kmath/wasm/internal/Initial.kt @@ -1,4 +1,4 @@ -package kscience.kmath.ast +package kscience.kmath.wasm.internal internal val f64StandardFunctions by lazy { Base64.toUint8Array(B) } diff --git a/kmath-ast/src/jsMain/kotlin/kscience/kmath/ast/RealWasmBuilder.kt b/kmath-ast/src/jsMain/kotlin/kscience/kmath/wasm/internal/WasmBuilder.kt similarity index 99% rename from kmath-ast/src/jsMain/kotlin/kscience/kmath/ast/RealWasmBuilder.kt rename to kmath-ast/src/jsMain/kotlin/kscience/kmath/wasm/internal/WasmBuilder.kt index 20964e837..b5aa1a66e 100644 --- a/kmath-ast/src/jsMain/kotlin/kscience/kmath/ast/RealWasmBuilder.kt +++ b/kmath-ast/src/jsMain/kotlin/kscience/kmath/wasm/internal/WasmBuilder.kt @@ -1,4 +1,4 @@ -package kscience.kmath.ast +package kscience.kmath.wasm.internal import WebAssembly.Instance import binaryen.* diff --git a/kmath-ast/src/jsMain/kotlin/kscience/kmath/wasm/wasm.kt b/kmath-ast/src/jsMain/kotlin/kscience/kmath/wasm/wasm.kt new file mode 100644 index 000000000..1357fc3fe --- /dev/null +++ b/kmath-ast/src/jsMain/kotlin/kscience/kmath/wasm/wasm.kt @@ -0,0 +1,41 @@ +package kscience.kmath.wasm + +import kscience.kmath.ast.MST +import kscience.kmath.ast.MstExpression +import kscience.kmath.expressions.Expression +import kscience.kmath.operations.IntRing +import kscience.kmath.operations.RealField +import kscience.kmath.wasm.internal.IntWasmBuilder +import kscience.kmath.wasm.internal.RealWasmBuilder + +/** + * Compiles an [MST] to WASM in the context of reals. + * + * @author Iaroslav Postovalov. + */ +public fun RealField.expression(mst: MST): Expression = + RealWasmBuilder(mst).instance + +/** + * Compiles an [MST] to WASM in the context of integers. + * + * @author Iaroslav Postovalov. + */ +public fun IntRing.expression(mst: MST): Expression = + IntWasmBuilder(mst).instance + +/** + * Optimizes performance of an [MstExpression] using WASM codegen in the context of reals. + * + * @author Iaroslav Postovalov. + */ +public fun MstExpression.compile(): Expression = + RealWasmBuilder(mst).instance + +/** + * Optimizes performance of an [MstExpression] using WASM codegen in the context of integers. + * + * @author Iaroslav Postovalov. + */ +public fun MstExpression.compile(): Expression = + IntWasmBuilder(mst).instance