Very experimental WASM code generation by MST in contexts of Int and Real #158

Closed
CommanderTvis wants to merge 16 commits from feature/binaryen into dev
3 changed files with 43 additions and 2 deletions
Showing only changes of commit 51945bf58c - Show all commits

View File

@ -1,4 +1,4 @@
package kscience.kmath.ast package kscience.kmath.wasm.internal
internal val f64StandardFunctions by lazy { Base64.toUint8Array(B) } internal val f64StandardFunctions by lazy { Base64.toUint8Array(B) }

View File

@ -1,4 +1,4 @@
package kscience.kmath.ast package kscience.kmath.wasm.internal
import WebAssembly.Instance import WebAssembly.Instance
import binaryen.* import binaryen.*

View File

@ -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<Double> =
RealWasmBuilder(mst).instance
/**
* Compiles an [MST] to WASM in the context of integers.
*
* @author Iaroslav Postovalov.
*/
public fun IntRing.expression(mst: MST): Expression<Int> =
IntWasmBuilder(mst).instance
/**
* Optimizes performance of an [MstExpression] using WASM codegen in the context of reals.
*
* @author Iaroslav Postovalov.
*/
public fun MstExpression<Double, RealField>.compile(): Expression<Double> =
RealWasmBuilder(mst).instance
/**
* Optimizes performance of an [MstExpression] using WASM codegen in the context of integers.
*
* @author Iaroslav Postovalov.
*/
public fun MstExpression<Int, IntRing>.compile(): Expression<Int> =
IntWasmBuilder(mst).instance