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
7 changed files with 79 additions and 55 deletions
Showing only changes of commit 4fce91ae59 - Show all commits

View File

@ -1,10 +1,17 @@
@file:Suppress( @file:Suppress(
"INTERFACE_WITH_SUPERCLASS", "OVERRIDING_FINAL_MEMBER", "RETURN_TYPE_MISMATCH_ON_OVERRIDE", "INTERFACE_WITH_SUPERCLASS",
"CONFLICTING_OVERLOADS", "NO_EXPLICIT_VISIBILITY_IN_API_MODE_WARNING", "KDocMissingDocumentation", "ClassName", "OVERRIDING_FINAL_MEMBER",
"SpellCheckingInspection", "PackageName" "RETURN_TYPE_MISMATCH_ON_OVERRIDE",
"CONFLICTING_OVERLOADS",
"NO_EXPLICIT_VISIBILITY_IN_API_MODE_WARNING",
"KDocMissingDocumentation",
"ObjectPropertyName",
"ClassName",
"PackageDirectoryMismatch",
"PackageName",
) )
@file:JsModule("js-base64") @file:JsModule("js-base64")
@file:JsNonModule
package Base64 package Base64
import org.khronos.webgl.Uint8Array import org.khronos.webgl.Uint8Array

View File

@ -8,12 +8,11 @@
"KDocMissingDocumentation", "KDocMissingDocumentation",
"PropertyName", "PropertyName",
"ClassName", "ClassName",
"SortModifiers",
"SpellCheckingInspection",
) )
@file:JsModule("binaryen") @file:JsModule("binaryen")
@file:JsNonModule @file:JsNonModule
package binaryen package binaryen
import org.khronos.webgl.Uint8Array import org.khronos.webgl.Uint8Array
@ -1649,7 +1648,7 @@ external interface `T$27` {
var sourceMap: String? var sourceMap: String?
} }
external open class Module { open external class Module {
open var ptr: Number open var ptr: Number
open fun block(label: String, children: Array<ExpressionRef>, resultType: Type = definedExternally): ExpressionRef open fun block(label: String, children: Array<ExpressionRef>, resultType: Type = definedExternally): ExpressionRef
open fun `if`( open fun `if`(
@ -2222,7 +2221,7 @@ external fun setOneCallerInlineMaxSize(size: Number)
external fun exit(status: Number) external fun exit(status: Number)
external open class Relooper(module: Module) { open external class Relooper(module: Module) {
open fun addBlock(expression: ExpressionRef): RelooperBlockRef open fun addBlock(expression: ExpressionRef): RelooperBlockRef
open fun addBranch(from: RelooperBlockRef, to: RelooperBlockRef, condition: ExpressionRef, code: ExpressionRef) open fun addBranch(from: RelooperBlockRef, to: RelooperBlockRef, condition: ExpressionRef, code: ExpressionRef)
open fun addBlockWithSwitch(code: ExpressionRef, condition: ExpressionRef): RelooperBlockRef open fun addBlockWithSwitch(code: ExpressionRef, condition: ExpressionRef): RelooperBlockRef

View File

@ -4,6 +4,8 @@ import kscience.kmath.expressions.Expression
import kscience.kmath.expressions.StringSymbol import kscience.kmath.expressions.StringSymbol
import kscience.kmath.operations.* import kscience.kmath.operations.*
private val spreader = eval("(obj, args) => obj(...args)")
public fun compileMstToWasmF64(mst: MST): Expression<Double> { public fun compileMstToWasmF64(mst: MST): Expression<Double> {
val keys = mutableListOf<String>() val keys = mutableListOf<String>()
@ -75,7 +77,6 @@ public fun compileMstToWasmF64(mst: MST): Expression<Double> {
return Expression { args -> return Expression { args ->
val params = keys.map { StringSymbol(it) }.map { args.getValue(it) }.toTypedArray() val params = keys.map { StringSymbol(it) }.map { args.getValue(it) }.toTypedArray()
val spreader = eval("(obj, args) => obj(...args)")
spreader(i.exports.asDynamic().executable, params) as Double spreader(i.exports.asDynamic().executable, params) as Double
} }
} }

View File

@ -1,8 +1,16 @@
@file:JsQualifier("WebAssembly") @file:JsQualifier("WebAssembly")
@file:Suppress("INTERFACE_WITH_SUPERCLASS", "OVERRIDING_FINAL_MEMBER", "RETURN_TYPE_MISMATCH_ON_OVERRIDE", "CONFLICTING_OVERLOADS",
"NO_EXPLICIT_VISIBILITY_IN_API_MODE_WARNING", "KDocMissingDocumentation", "PackageDirectoryMismatch", "PackageName", @file:Suppress(
"Reformat", "ClassName", "SortModifiers" "INTERFACE_WITH_SUPERCLASS",
"OVERRIDING_FINAL_MEMBER",
"RETURN_TYPE_MISMATCH_ON_OVERRIDE",
"NO_EXPLICIT_VISIBILITY_IN_API_MODE_WARNING",
"KDocMissingDocumentation",
"PackageDirectoryMismatch",
"PackageName",
"ClassName",
) )
package WebAssembly package WebAssembly
import org.khronos.webgl.ArrayBuffer import org.khronos.webgl.ArrayBuffer
@ -132,7 +140,10 @@ external fun compileStreaming(source: Response): Promise<Module>
external fun compileStreaming(source: Promise<Response>): Promise<Module> external fun compileStreaming(source: Promise<Response>): Promise<Module>
external fun instantiate(bytes: ArrayBufferView, importObject: Imports = definedExternally): Promise<WebAssemblyInstantiatedSource> external fun instantiate(
bytes: ArrayBufferView,
importObject: Imports = definedExternally
): Promise<WebAssemblyInstantiatedSource>
external fun instantiate(bytes: ArrayBufferView): Promise<WebAssemblyInstantiatedSource> external fun instantiate(bytes: ArrayBufferView): Promise<WebAssemblyInstantiatedSource>
@ -144,11 +155,17 @@ external fun instantiate(moduleObject: Module, importObject: Imports = definedEx
external fun instantiate(moduleObject: Module): Promise<Instance> external fun instantiate(moduleObject: Module): Promise<Instance>
external fun instantiateStreaming(response: Response, importObject: Imports = definedExternally): Promise<WebAssemblyInstantiatedSource> external fun instantiateStreaming(
response: Response,
importObject: Imports = definedExternally
): Promise<WebAssemblyInstantiatedSource>
external fun instantiateStreaming(response: Response): Promise<WebAssemblyInstantiatedSource> external fun instantiateStreaming(response: Response): Promise<WebAssemblyInstantiatedSource>
external fun instantiateStreaming(response: PromiseLike<Response>, importObject: Imports = definedExternally): Promise<WebAssemblyInstantiatedSource> external fun instantiateStreaming(
response: PromiseLike<Response>,
importObject: Imports = definedExternally
): Promise<WebAssemblyInstantiatedSource>
external fun instantiateStreaming(response: PromiseLike<Response>): Promise<WebAssemblyInstantiatedSource> external fun instantiateStreaming(response: PromiseLike<Response>): Promise<WebAssemblyInstantiatedSource>
@ -167,7 +184,7 @@ external interface `T$1` {
var kind: String var kind: String
} }
external open class Module { open external class Module {
constructor(bufferSource: ArrayBuffer) constructor(bufferSource: ArrayBuffer)
constructor(bufferSource: Uint8Array) constructor(bufferSource: Uint8Array)
@ -179,18 +196,18 @@ external open class Module {
} }
@JsName("Instance") @JsName("Instance")
external open class Instance(module: Module, importObject: Any = definedExternally) { open external class Instance(module: Module, importObject: Any = definedExternally) {
open var exports: Any open var exports: Any
} }
@JsName("Memory") @JsName("Memory")
external open class Memory1(memoryDescriptor: MemoryDescriptor) { open external class Memory1(memoryDescriptor: MemoryDescriptor) {
open var buffer: ArrayBuffer open var buffer: ArrayBuffer
open fun grow(numPages: Number): Number open fun grow(numPages: Number): Number
} }
@JsName("Table") @JsName("Table")
external open class Table1(tableDescriptor: TableDescriptor) { open external class Table1(tableDescriptor: TableDescriptor) {
open var length: Number open var length: Number
open fun get(index: Number): Function<*> open fun get(index: Number): Function<*>
open fun grow(numElements: Number): Number open fun grow(numElements: Number): Number

View File

@ -1,19 +1,9 @@
@file:Suppress("INTERFACE_WITH_SUPERCLASS", "OVERRIDING_FINAL_MEMBER", "RETURN_TYPE_MISMATCH_ON_OVERRIDE", "CONFLICTING_OVERLOADS") @file:Suppress("INTERFACE_WITH_SUPERCLASS", "OVERRIDING_FINAL_MEMBER", "RETURN_TYPE_MISMATCH_ON_OVERRIDE", "CONFLICTING_OVERLOADS",
"NO_EXPLICIT_VISIBILITY_IN_API_MODE_WARNING", "PackageDirectoryMismatch", "KDocMissingDocumentation"
)
package tsstdlib package tsstdlib
import kotlin.js.* import kotlin.js.Promise
import org.khronos.webgl.*
import org.w3c.dom.*
import org.w3c.dom.events.*
import org.w3c.dom.parsing.*
import org.w3c.dom.svg.*
import org.w3c.dom.url.*
import org.w3c.fetch.*
import org.w3c.files.*
import org.w3c.notifications.*
import org.w3c.performance.*
import org.w3c.workers.*
import org.w3c.xhr.*
external interface IteratorYieldResult<TYield> { external interface IteratorYieldResult<TYield> {
var done: Boolean? var done: Boolean?

View File

@ -1,19 +1,13 @@
@file:Suppress("INTERFACE_WITH_SUPERCLASS", "OVERRIDING_FINAL_MEMBER", "RETURN_TYPE_MISMATCH_ON_OVERRIDE", "CONFLICTING_OVERLOADS") @file:Suppress(
"INTERFACE_WITH_SUPERCLASS", "OVERRIDING_FINAL_MEMBER", "RETURN_TYPE_MISMATCH_ON_OVERRIDE", "CONFLICTING_OVERLOADS",
"PackageDirectoryMismatch", "DEPRECATION", "NO_EXPLICIT_VISIBILITY_IN_API_MODE_WARNING", "KDocMissingDocumentation",
"UNUSED_TYPEALIAS_PARAMETER", "PropertyName"
)
package tsstdlib package tsstdlib
import kotlin.js.* import org.khronos.webgl.ArrayBuffer
import org.khronos.webgl.* import org.khronos.webgl.Uint8Array
import org.w3c.dom.*
import org.w3c.dom.events.*
import org.w3c.dom.parsing.*
import org.w3c.dom.svg.*
import org.w3c.dom.url.*
import org.w3c.fetch.*
import org.w3c.files.*
import org.w3c.notifications.*
import org.w3c.performance.*
import org.w3c.workers.*
import org.w3c.xhr.*
external interface FunctionConstructor { external interface FunctionConstructor {
@nativeInvoke @nativeInvoke
@ -28,13 +22,18 @@ external interface ErrorConstructor {
} }
external interface PromiseLike<T> { external interface PromiseLike<T> {
fun then(onfulfilled: ((value: T) -> Any?)? = definedExternally, onrejected: ((reason: Any) -> Any?)? = definedExternally): PromiseLike<dynamic /* TResult1 | TResult2 */> fun then(
onfulfilled: ((value: T) -> Any?)? = definedExternally,
onrejected: ((reason: Any) -> Any?)? = definedExternally
): PromiseLike<dynamic /* TResult1 | TResult2 */>
} }
external interface ArrayLike<T> { external interface ArrayLike<T> {
var length: Number var length: Number
@nativeGetter @nativeGetter
operator fun get(n: Number): T? operator fun get(n: Number): T?
@nativeSetter @nativeSetter
operator fun set(n: Number, value: T) operator fun set(n: Number, value: T)
} }
@ -51,13 +50,24 @@ external interface ArrayBufferConstructor {
} }
external interface Uint8ArrayConstructor { external interface Uint8ArrayConstructor {
fun from(arrayLike: Iterable<Number>, mapfn: (v: Number, k: Number) -> Number = definedExternally, thisArg: Any = definedExternally): Uint8Array fun from(
arrayLike: Iterable<Number>,
mapfn: (v: Number, k: Number) -> Number = definedExternally,
thisArg: Any = definedExternally
): Uint8Array
fun from(arrayLike: Iterable<Number>): Uint8Array fun from(arrayLike: Iterable<Number>): Uint8Array
fun from(arrayLike: Iterable<Number>, mapfn: (v: Number, k: Number) -> Number = definedExternally): Uint8Array fun from(arrayLike: Iterable<Number>, mapfn: (v: Number, k: Number) -> Number = definedExternally): Uint8Array
var prototype: Uint8Array var prototype: Uint8Array
var BYTES_PER_ELEMENT: Number var BYTES_PER_ELEMENT: Number
fun of(vararg items: Number): Uint8Array fun of(vararg items: Number): Uint8Array
fun from(arrayLike: ArrayLike<Number>): Uint8Array fun from(arrayLike: ArrayLike<Number>): Uint8Array
fun <T> from(arrayLike: ArrayLike<T>, mapfn: (v: T, k: Number) -> Number, thisArg: Any = definedExternally): Uint8Array
fun <T> from(
arrayLike: ArrayLike<T>,
mapfn: (v: T, k: Number) -> Number,
thisArg: Any = definedExternally
): Uint8Array
fun <T> from(arrayLike: ArrayLike<T>, mapfn: (v: T, k: Number) -> Number): Uint8Array fun <T> from(arrayLike: ArrayLike<T>, mapfn: (v: T, k: Number) -> Number): Uint8Array
} }