Make it work, regenerate bindings

This commit is contained in:
Iaroslav Postovalov 2020-11-11 02:24:33 +07:00
parent d0be846caf
commit 68d8a7382d
No known key found for this signature in database
GPG Key ID: 46E15E4A31B3BCD7
12 changed files with 600 additions and 5187 deletions

View File

@ -2,6 +2,24 @@ plugins {
id("ru.mipt.npm.mpp")
}
kotlin.js {
nodejs { // or `browser`
testTask {
useMocha {
timeout = "0"// mochaTimeout here as string
}
}
}
browser { // or `browser`
testTask {
useMocha {
timeout = "0"// mochaTimeout here as string
}
}
}
}
kotlin.sourceSets {
commonMain {
dependencies {
@ -21,6 +39,7 @@ kotlin.sourceSets {
dependencies {
implementation(npm("binaryen", "98.0.0"))
implementation(npm("js-base64", "3.6.0"))
implementation(npm("webassembly", "0.11.0"))
}
}
}

View File

@ -1,7 +1,15 @@
@file:Suppress(
"INTERFACE_WITH_SUPERCLASS", "OVERRIDING_FINAL_MEMBER", "RETURN_TYPE_MISMATCH_ON_OVERRIDE", "CONFLICTING_OVERLOADS",
"NO_EXPLICIT_VISIBILITY_IN_API_MODE_WARNING", "KDocMissingDocumentation", "SortModifiers", "SpellCheckingInspection",
"ClassName"
"INTERFACE_WITH_SUPERCLASS",
"OVERRIDING_FINAL_MEMBER",
"RETURN_TYPE_MISMATCH_ON_OVERRIDE",
"CONFLICTING_OVERLOADS",
"PackageDirectoryMismatch",
"NO_EXPLICIT_VISIBILITY_IN_API_MODE_WARNING",
"KDocMissingDocumentation",
"PropertyName",
"ClassName",
"SortModifiers",
"SpellCheckingInspection",
)
@file:JsModule("binaryen")
@ -12,21 +20,35 @@ import org.khronos.webgl.Uint8Array
import kotlin.js.Promise
external var isReady: Boolean
external var ready: Promise<Any>
external var none: Type
external var i32: Type
external var i64: Type
external var f32: Type
external var f64: Type
external var v128: Type
external var funcref: Type
external var anyref: Type
external var nullref: Type
external var exnref: Type
external var unreachable: Type
external var auto: Type
external fun createType(types: Array<Type>): Type
external fun expandType(type: Type): Array<Type>
external enum class ExpressionIds {
@ -1180,19 +1202,18 @@ external var WidenHighUVecI16x8ToVecI32x4: Operations
external var SwizzleVec8x16: Operations
external interface `T$0` {
external interface `T$2` {
fun get(index: Number, type: Type): ExpressionRef
fun set(index: Number, value: ExpressionRef): ExpressionRef
fun tee(index: Number, value: ExpressionRef, type: Type): ExpressionRef
}
external interface `T$1` {
external interface `T$3` {
fun get(name: String, type: Type): ExpressionRef
fun set(name: String, value: ExpressionRef): ExpressionRef
}
external interface `T$2` {
external interface `T$4` {
fun size(): ExpressionRef
fun grow(value: ExpressionRef): ExpressionRef
fun init(segment: Number, dest: ExpressionRef, offset: ExpressionRef, size: ExpressionRef): ExpressionRef
@ -1200,16 +1221,16 @@ external interface `T$2` {
fun fill(dest: ExpressionRef, value: ExpressionRef, size: ExpressionRef): ExpressionRef
}
external interface `T$3` {
external interface `T$5` {
fun drop(segment: Number): ExpressionRef
}
external interface `T$4` {
external interface `T$6` {
fun f32(value: ExpressionRef): ExpressionRef
fun f64(value: ExpressionRef): ExpressionRef
}
external interface `T$5` {
external interface `T$7` {
fun add(offset: Number, ptr: ExpressionRef, value: ExpressionRef): ExpressionRef
fun sub(offset: Number, ptr: ExpressionRef, value: ExpressionRef): ExpressionRef
fun and(offset: Number, ptr: ExpressionRef, value: ExpressionRef): ExpressionRef
@ -1219,20 +1240,20 @@ external interface `T$5` {
fun cmpxchg(offset: Number, ptr: ExpressionRef, expected: ExpressionRef, replacement: ExpressionRef): ExpressionRef
}
external interface `T$6` {
external interface `T$8` {
fun load(offset: Number, ptr: ExpressionRef): ExpressionRef
fun load8_u(offset: Number, ptr: ExpressionRef): ExpressionRef
fun load16_u(offset: Number, ptr: ExpressionRef): ExpressionRef
fun store(offset: Number, ptr: ExpressionRef, value: ExpressionRef): ExpressionRef
fun store8(offset: Number, ptr: ExpressionRef, value: ExpressionRef): ExpressionRef
fun store16(offset: Number, ptr: ExpressionRef, value: ExpressionRef): ExpressionRef
var rmw: `T$5`
var rmw8_u: `T$5`
var rmw16_u: `T$5`
var rmw: `T$7`
var rmw8_u: `T$7`
var rmw16_u: `T$7`
fun wait(ptr: ExpressionRef, expected: ExpressionRef, timeout: ExpressionRef): ExpressionRef
}
external interface `T$7` {
external interface `T$9` {
fun load(offset: Number, align: Number, ptr: ExpressionRef): ExpressionRef
fun load8_s(offset: Number, align: Number, ptr: ExpressionRef): ExpressionRef
fun load8_u(offset: Number, align: Number, ptr: ExpressionRef): ExpressionRef
@ -1246,10 +1267,10 @@ external interface `T$7` {
fun ctz(value: ExpressionRef): ExpressionRef
fun popcnt(value: ExpressionRef): ExpressionRef
fun eqz(value: ExpressionRef): ExpressionRef
var trunc_s: `T$4`
var trunc_u: `T$4`
var trunc_s_sat: `T$4`
var trunc_u_sat: `T$4`
var trunc_s: `T$6`
var trunc_u: `T$6`
var trunc_s_sat: `T$6`
var trunc_u_sat: `T$6`
fun reinterpret(value: ExpressionRef): ExpressionRef
fun extend8_s(value: ExpressionRef): ExpressionRef
fun extend16_s(value: ExpressionRef): ExpressionRef
@ -1279,11 +1300,11 @@ external interface `T$7` {
fun gt_u(left: ExpressionRef, right: ExpressionRef): ExpressionRef
fun ge_s(left: ExpressionRef, right: ExpressionRef): ExpressionRef
fun ge_u(left: ExpressionRef, right: ExpressionRef): ExpressionRef
var atomic: `T$6`
var atomic: `T$8`
fun pop(): ExpressionRef
}
external interface `T$8` {
external interface `T$10` {
fun load(offset: Number, ptr: ExpressionRef): ExpressionRef
fun load8_u(offset: Number, ptr: ExpressionRef): ExpressionRef
fun load16_u(offset: Number, ptr: ExpressionRef): ExpressionRef
@ -1292,14 +1313,14 @@ external interface `T$8` {
fun store8(offset: Number, ptr: ExpressionRef, value: ExpressionRef): ExpressionRef
fun store16(offset: Number, ptr: ExpressionRef, value: ExpressionRef): ExpressionRef
fun store32(offset: Number, ptr: ExpressionRef, value: ExpressionRef): ExpressionRef
var rmw: `T$5`
var rmw8_u: `T$5`
var rmw16_u: `T$5`
var rmw32_u: `T$5`
var rmw: `T$7`
var rmw8_u: `T$7`
var rmw16_u: `T$7`
var rmw32_u: `T$7`
fun wait(ptr: ExpressionRef, expected: ExpressionRef, timeout: ExpressionRef): ExpressionRef
}
external interface `T$9` {
external interface `T$11` {
fun load(offset: Number, align: Number, ptr: ExpressionRef): ExpressionRef
fun load8_s(offset: Number, align: Number, ptr: ExpressionRef): ExpressionRef
fun load8_u(offset: Number, align: Number, ptr: ExpressionRef): ExpressionRef
@ -1316,10 +1337,10 @@ external interface `T$9` {
fun ctz(value: ExpressionRef): ExpressionRef
fun popcnt(value: ExpressionRef): ExpressionRef
fun eqz(value: ExpressionRef): ExpressionRef
var trunc_s: `T$4`
var trunc_u: `T$4`
var trunc_s_sat: `T$4`
var trunc_u_sat: `T$4`
var trunc_s: `T$6`
var trunc_u: `T$6`
var trunc_s_sat: `T$6`
var trunc_u_sat: `T$6`
fun reinterpret(value: ExpressionRef): ExpressionRef
fun extend8_s(value: ExpressionRef): ExpressionRef
fun extend16_s(value: ExpressionRef): ExpressionRef
@ -1351,11 +1372,11 @@ external interface `T$9` {
fun gt_u(left: ExpressionRef, right: ExpressionRef): ExpressionRef
fun ge_s(left: ExpressionRef, right: ExpressionRef): ExpressionRef
fun ge_u(left: ExpressionRef, right: ExpressionRef): ExpressionRef
var atomic: `T$8`
var atomic: `T$10`
fun pop(): ExpressionRef
}
external interface `T$10` {
external interface `T$12` {
fun load(offset: Number, align: Number, ptr: ExpressionRef): ExpressionRef
fun store(offset: Number, align: Number, ptr: ExpressionRef, value: ExpressionRef): ExpressionRef
fun const(value: Number): ExpressionRef
@ -1368,8 +1389,8 @@ external interface `T$10` {
fun nearest(value: ExpressionRef): ExpressionRef
fun sqrt(value: ExpressionRef): ExpressionRef
fun reinterpret(value: ExpressionRef): ExpressionRef
var convert_s: `T$4`
var convert_u: `T$4`
var convert_s: `T$6`
var convert_u: `T$6`
fun demote(value: ExpressionRef): ExpressionRef
fun add(left: ExpressionRef, right: ExpressionRef): ExpressionRef
fun sub(left: ExpressionRef, right: ExpressionRef): ExpressionRef
@ -1387,7 +1408,7 @@ external interface `T$10` {
fun pop(): ExpressionRef
}
external interface `T$11` {
external interface `T$13` {
fun load(offset: Number, align: Number, ptr: ExpressionRef): ExpressionRef
fun store(offset: Number, align: Number, ptr: ExpressionRef, value: ExpressionRef): ExpressionRef
fun const(value: Number): ExpressionRef
@ -1400,8 +1421,8 @@ external interface `T$11` {
fun nearest(value: ExpressionRef): ExpressionRef
fun sqrt(value: ExpressionRef): ExpressionRef
fun reinterpret(value: ExpressionRef): ExpressionRef
var convert_s: `T$4`
var convert_u: `T$4`
var convert_s: `T$6`
var convert_u: `T$6`
fun promote(value: ExpressionRef): ExpressionRef
fun add(left: ExpressionRef, right: ExpressionRef): ExpressionRef
fun sub(left: ExpressionRef, right: ExpressionRef): ExpressionRef
@ -1419,7 +1440,7 @@ external interface `T$11` {
fun pop(): ExpressionRef
}
external interface `T$12` {
external interface `T$14` {
fun load(offset: Number, align: Number, ptr: ExpressionRef): ExpressionRef
fun store(offset: Number, align: Number, ptr: ExpressionRef, value: ExpressionRef): ExpressionRef
fun const(value: Number): ExpressionRef
@ -1432,7 +1453,7 @@ external interface `T$12` {
fun pop(): ExpressionRef
}
external interface `T$13` {
external interface `T$15` {
fun splat(value: ExpressionRef): ExpressionRef
fun extract_lane_s(vec: ExpressionRef, index: ExpressionRef): ExpressionRef
fun extract_lane_u(vec: ExpressionRef, index: ExpressionRef): ExpressionRef
@ -1469,7 +1490,7 @@ external interface `T$13` {
fun narrow_i16x8_u(left: ExpressionRef, right: ExpressionRef): ExpressionRef
}
external interface `T$14` {
external interface `T$16` {
fun splat(value: ExpressionRef): ExpressionRef
fun extract_lane_s(vec: ExpressionRef, index: ExpressionRef): ExpressionRef
fun extract_lane_u(vec: ExpressionRef, index: ExpressionRef): ExpressionRef
@ -1512,7 +1533,7 @@ external interface `T$14` {
fun load8x8_u(offset: Number, align: Number, ptr: ExpressionRef): ExpressionRef
}
external interface `T$15` {
external interface `T$17` {
fun splat(value: ExpressionRef): ExpressionRef
fun extract_lane(vec: ExpressionRef, index: ExpressionRef): ExpressionRef
fun replace_lane(vec: ExpressionRef, index: ExpressionRef, value: ExpressionRef): ExpressionRef
@ -1545,7 +1566,7 @@ external interface `T$15` {
fun load16x4_u(offset: Number, align: Number, ptr: ExpressionRef): ExpressionRef
}
external interface `T$16` {
external interface `T$18` {
fun splat(value: ExpressionRef): ExpressionRef
fun extract_lane(vec: ExpressionRef, index: ExpressionRef): ExpressionRef
fun replace_lane(vec: ExpressionRef, index: ExpressionRef, value: ExpressionRef): ExpressionRef
@ -1563,7 +1584,7 @@ external interface `T$16` {
fun load32x2_u(offset: Number, align: Number, ptr: ExpressionRef): ExpressionRef
}
external interface `T$17` {
external interface `T$19` {
fun splat(value: ExpressionRef): ExpressionRef
fun extract_lane(vec: ExpressionRef, index: ExpressionRef): ExpressionRef
fun replace_lane(vec: ExpressionRef, index: ExpressionRef, value: ExpressionRef): ExpressionRef
@ -1588,42 +1609,42 @@ external interface `T$17` {
fun convert_i32x4_u(value: ExpressionRef): ExpressionRef
}
external interface `T$18` {
external interface `T$20` {
fun shuffle(left: ExpressionRef, right: ExpressionRef, mask: Array<Number>): ExpressionRef
fun swizzle(left: ExpressionRef, right: ExpressionRef): ExpressionRef
fun load_splat(offset: Number, align: Number, ptr: ExpressionRef): ExpressionRef
}
external interface `T$19` {
external interface `T$21` {
fun load_splat(offset: Number, align: Number, ptr: ExpressionRef): ExpressionRef
}
external interface `T$20` {
external interface `T$22` {
fun pop(): ExpressionRef
}
external interface `T$21` {
external interface `T$23` {
fun `null`(): ExpressionRef
fun is_null(value: ExpressionRef): ExpressionRef
fun func(name: String): ExpressionRef
}
external interface `T$22` {
external interface `T$24` {
fun notify(ptr: ExpressionRef, notifyCount: ExpressionRef): ExpressionRef
fun fence(): ExpressionRef
}
external interface `T$23` {
external interface `T$25` {
fun make(elements: Array<ExportRef>): ExpressionRef
fun extract(tuple: ExpressionRef, index: Number): ExpressionRef
}
external interface `T$24` {
external interface `T$26` {
var imported: Boolean
var segments: Array<TableElement>
}
external interface `T$25` {
external interface `T$27` {
var binary: Uint8Array
var sourceMap: String?
}
@ -1673,32 +1694,32 @@ external open class Module {
results: Type
): ExpressionRef
open var local: `T$0`
open var global: `T$1`
open var memory: `T$2`
open var data: `T$3`
open var i32: `T$7`
open var i64: `T$9`
open var f32: `T$10`
open var f64: `T$11`
open var v128: `T$12`
open var i8x16: `T$13`
open var i16x8: `T$14`
open var i32x4: `T$15`
open var i64x2: `T$16`
open var f32x4: `T$17`
open var f64x2: `T$17`
open var v8x16: `T$18`
open var v16x8: `T$19`
open var v32x4: `T$19`
open var v64x2: `T$19`
open var funcref: `T$20`
open var anyref: `T$20`
open var nullref: `T$20`
open var exnref: `T$20`
open var ref: `T$21`
open var atomic: `T$22`
open var tuple: `T$23`
open var local: `T$2`
open var global: `T$3`
open var memory: `T$4`
open var data: `T$5`
open var i32: `T$9`
open var i64: `T$11`
open var f32: `T$12`
open var f64: `T$13`
open var v128: `T$14`
open var i8x16: `T$15`
open var i16x8: `T$16`
open var i32x4: `T$17`
open var i64x2: `T$18`
open var f32x4: `T$19`
open var f64x2: `T$19`
open var v8x16: `T$20`
open var v16x8: `T$21`
open var v32x4: `T$21`
open var v64x2: `T$21`
open var funcref: `T$22`
open var anyref: `T$22`
open var nullref: `T$22`
open var exnref: `T$22`
open var ref: `T$23`
open var atomic: `T$24`
open var tuple: `T$25`
open fun `try`(body: ExpressionRef, catchBody: ExpressionRef): ExpressionRef
open fun `throw`(event: String, operands: Array<ExpressionRef>): ExpressionRef
open fun rethrow(exnref: ExpressionRef): ExpressionRef
@ -1767,7 +1788,7 @@ external open class Module {
offset: ExpressionRef = definedExternally
)
open fun getFunctionTable(): `T$24`
open fun getFunctionTable(): `T$26`
open fun setMemory(
initial: Number,
maximum: Number,
@ -1796,7 +1817,7 @@ external open class Module {
open fun autoDrop()
open fun dispose()
open fun emitBinary(): Uint8Array
open fun emitBinary(sourceMapUrl: String?): `T$25`
open fun emitBinary(sourceMapUrl: String?): `T$27`
open fun interpret()
open fun addDebugInfoFileName(filename: String): Number
open fun getDebugInfoFileName(index: Number): String?
@ -1921,13 +1942,13 @@ external interface StoreInfo : ExpressionInfo {
var value: ExpressionRef
}
external interface `T$26` {
external interface `T$28` {
var low: Number
var high: Number
}
external interface ConstInfo : ExpressionInfo {
var value: dynamic /* Number | `T$26` */
var value: dynamic /* Number | `T$28` */
get() = definedExternally
set(value) = definedExternally
}

View File

@ -1,11 +1,11 @@
@file:Suppress("NO_EXPLICIT_VISIBILITY_IN_API_MODE_WARNING", "KDocMissingDocumentation")
@file:Suppress("PackageDirectoryMismatch", "NO_EXPLICIT_VISIBILITY_IN_API_MODE_WARNING", "KDocMissingDocumentation")
package binaryen
typealias Type = Number
typealias RelooperBlockRef = Number
typealias ExpressionRef = Number
typealias FunctionRef = Number
typealias GlobalRef = Number
typealias ExportRef = Number
typealias EventRef = Number
typealias RelooperBlockRef = Number

File diff suppressed because one or more lines are too long

View File

@ -1,14 +1,13 @@
package kscience.kmath.ast
import kscience.kmath.expressions.Expression
import kscience.kmath.expressions.StringSymbol
import kscience.kmath.operations.*
private const val ARGS_PTR = 0
private const val ARGS_SIZE = 1
public fun compileMstToWasmF64(mst: MST) {
public fun compileMstToWasmF64(mst: MST): Expression<Double> {
val keys = mutableListOf<String>()
val bin = with(binaryen.parseText(INITIAL)) {
val bin = with(binaryen.readBinary(INITIAL)) {
fun MST.visit(): binaryen.ExpressionRef = when (this) {
is MST.Symbolic -> {
var idx = keys.indexOf(value)
@ -18,7 +17,7 @@ public fun compileMstToWasmF64(mst: MST) {
idx = keys.lastIndex
}
f64.load(idx * Double.SIZE_BYTES, 0, local.get(ARGS_PTR, binaryen.i32))
local.get(idx, binaryen.f64)
}
is MST.Numeric -> f64.const(value)
@ -28,6 +27,19 @@ public fun compileMstToWasmF64(mst: MST) {
SpaceOperations.PLUS_OPERATION -> value.visit()
PowerOperations.SQRT_OPERATION -> f64.sqrt(value.visit())
TrigonometricOperations.SIN_OPERATION -> call("sin", arrayOf(value.visit()), binaryen.f64)
TrigonometricOperations.COS_OPERATION -> call("cos", arrayOf(value.visit()), binaryen.f64)
TrigonometricOperations.TAN_OPERATION -> call("tan", arrayOf(value.visit()), binaryen.f64)
TrigonometricOperations.ASIN_OPERATION -> call("asin", arrayOf(value.visit()), binaryen.f64)
TrigonometricOperations.ACOS_OPERATION -> call("acos", arrayOf(value.visit()), binaryen.f64)
TrigonometricOperations.ATAN_OPERATION -> call("atan", arrayOf(value.visit()), binaryen.f64)
HyperbolicOperations.SINH_OPERATION -> call("sinh", arrayOf(value.visit()), binaryen.f64)
HyperbolicOperations.COSH_OPERATION -> call("cosh", arrayOf(value.visit()), binaryen.f64)
HyperbolicOperations.TANH_OPERATION -> call("tanh", arrayOf(value.visit()), binaryen.f64)
HyperbolicOperations.ASINH_OPERATION -> call("asinh", arrayOf(value.visit()), binaryen.f64)
HyperbolicOperations.ACOSH_OPERATION -> call("acosh", arrayOf(value.visit()), binaryen.f64)
HyperbolicOperations.ATANH_OPERATION -> call("atanh", arrayOf(value.visit()), binaryen.f64)
ExponentialOperations.EXP_OPERATION -> call("exp", arrayOf(value.visit()), binaryen.f64)
ExponentialOperations.LN_OPERATION -> call("log", arrayOf(value.visit()), binaryen.f64)
else -> throw UnsupportedOperationException()
}
@ -35,28 +47,35 @@ public fun compileMstToWasmF64(mst: MST) {
SpaceOperations.PLUS_OPERATION -> f64.add(left.visit(), right.visit())
RingOperations.TIMES_OPERATION -> f64.mul(left.visit(), right.visit())
FieldOperations.DIV_OPERATION -> f64.div(left.visit(), right.visit())
PowerOperations.POW_OPERATION -> call("pow", arrayOf(left.visit(), right.visit()), binaryen.f64)
else -> throw UnsupportedOperationException()
}
}
val expr = mst.visit()
addFunction(
"executable",
binaryen.createType(arrayOf(binaryen.i32, binaryen.i32)),
binaryen.createType(Array(keys.size) { binaryen.f64 }),
binaryen.f64,
arrayOf(),
mst.visit()
expr
)
// setMemory(0, 10000)
binaryen.setOptimizeLevel(3)
// optimizeFunction("executable")
addFunctionExport("executable", "executable")
optimize()
if (!validate().unsafeCast<Boolean>())
error("Invalid module produced.")
println(emitText())
emitBinary()
val res = emitBinary()
dispose()
res
}
val c = WebAssembly.Module(bin)
val i = WebAssembly.Instance(c, js("{}") as Any)
return Expression { args ->
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
}
}

View File

@ -0,0 +1,211 @@
@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",
"Reformat", "ClassName", "SortModifiers"
)
package WebAssembly
import org.khronos.webgl.ArrayBuffer
import org.khronos.webgl.ArrayBufferView
import org.khronos.webgl.Uint8Array
import org.w3c.fetch.Response
import tsstdlib.PromiseLike
import kotlin.js.Promise
@Suppress("NESTED_CLASS_IN_EXTERNAL_INTERFACE")
external interface CompileError {
companion object {
var prototype: CompileError
}
}
@Suppress("NESTED_CLASS_IN_EXTERNAL_INTERFACE")
external interface Global {
var value: Any
fun valueOf(): Any
companion object {
var prototype: Global
}
}
@Suppress("NESTED_CLASS_IN_EXTERNAL_INTERFACE")
@JsName("Instance")
external interface Instance1 {
var exports: Exports
companion object {
var prototype: Instance
}
}
@Suppress("NESTED_CLASS_IN_EXTERNAL_INTERFACE")
external interface LinkError {
companion object {
var prototype: LinkError
}
}
@Suppress("NESTED_CLASS_IN_EXTERNAL_INTERFACE")
external interface Memory {
var buffer: ArrayBuffer
fun grow(delta: Number): Number
companion object {
var prototype: Memory
}
}
@Suppress("NESTED_CLASS_IN_EXTERNAL_INTERFACE")
@JsName("Module")
external interface Module1 {
companion object {
var prototype: Module
fun customSections(moduleObject: Module, sectionName: String): Array<ArrayBuffer>
fun exports(moduleObject: Module): Array<ModuleExportDescriptor>
fun imports(moduleObject: Module): Array<ModuleImportDescriptor>
}
}
@Suppress("NESTED_CLASS_IN_EXTERNAL_INTERFACE")
external interface RuntimeError {
companion object {
var prototype: RuntimeError
}
}
@Suppress("NESTED_CLASS_IN_EXTERNAL_INTERFACE")
external interface Table {
var length: Number
fun get(index: Number): Function<*>?
fun grow(delta: Number): Number
fun set(index: Number, value: Function<*>?)
companion object {
var prototype: Table
}
}
external interface GlobalDescriptor {
var mutable: Boolean?
get() = definedExternally
set(value) = definedExternally
var value: String /* "f32" | "f64" | "i32" | "i64" */
}
external interface MemoryDescriptor {
var initial: Number
var maximum: Number?
get() = definedExternally
set(value) = definedExternally
}
external interface ModuleExportDescriptor {
var kind: String /* "function" | "global" | "memory" | "table" */
var name: String
}
external interface ModuleImportDescriptor {
var kind: String /* "function" | "global" | "memory" | "table" */
var module: String
var name: String
}
external interface TableDescriptor {
var element: String /* "anyfunc" */
var initial: Number
var maximum: Number?
get() = definedExternally
set(value) = definedExternally
}
external interface WebAssemblyInstantiatedSource {
var instance: Instance
var module: Module
}
external fun compile(bytes: ArrayBufferView): Promise<Module>
external fun compile(bytes: ArrayBuffer): Promise<Module>
external fun compileStreaming(source: 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): Promise<WebAssemblyInstantiatedSource>
external fun instantiate(bytes: ArrayBuffer, importObject: Imports = definedExternally): dynamic /* Promise | Promise */
external fun instantiate(bytes: ArrayBuffer): dynamic /* Promise | Promise */
external fun instantiate(moduleObject: Module, importObject: Imports = definedExternally): Promise<Instance>
external fun instantiate(moduleObject: Module): Promise<Instance>
external fun instantiateStreaming(response: Response, importObject: Imports = definedExternally): 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>): Promise<WebAssemblyInstantiatedSource>
external fun validate(bytes: ArrayBufferView): Boolean
external fun validate(bytes: ArrayBuffer): Boolean
external interface `T$0` {
var name: String
var kind: String
}
external interface `T$1` {
var module: String
var name: String
var kind: String
}
external open class Module {
constructor(bufferSource: ArrayBuffer)
constructor(bufferSource: Uint8Array)
companion object {
fun customSections(module: Module, sectionName: String): Array<ArrayBuffer>
fun exports(module: Module): Array<`T$0`>
fun imports(module: Module): Array<`T$1`>
}
}
@JsName("Instance")
external open class Instance(module: Module, importObject: Any = definedExternally) {
open var exports: Any
}
@JsName("Memory")
external open class Memory1(memoryDescriptor: MemoryDescriptor) {
open var buffer: ArrayBuffer
open fun grow(numPages: Number): Number
}
@JsName("Table")
external open class Table1(tableDescriptor: TableDescriptor) {
open var length: Number
open fun get(index: Number): Function<*>
open fun grow(numElements: Number): Number
open fun set(index: Number, value: Function<*>)
}
external fun compile(bufferSource: Uint8Array): Promise<Module>
external interface ResultObject {
var module: Module
var instance: Instance
}
external fun instantiate(bufferSource: Uint8Array, importObject: Any = definedExternally): Promise<ResultObject>
external fun instantiate(bufferSource: Uint8Array): Promise<ResultObject>
external fun validate(bufferSource: Uint8Array): Boolean

View File

@ -0,0 +1,54 @@
@file:Suppress("INTERFACE_WITH_SUPERCLASS", "OVERRIDING_FINAL_MEMBER", "RETURN_TYPE_MISMATCH_ON_OVERRIDE", "CONFLICTING_OVERLOADS")
package tsstdlib
import kotlin.js.*
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> {
var done: Boolean?
get() = definedExternally
set(value) = definedExternally
var value: TYield
}
external interface IteratorReturnResult<TReturn> {
var done: Boolean
var value: TReturn
}
external interface Iterator<T, TReturn, TNext> {
fun next(vararg args: Any /* JsTuple<> | JsTuple<TNext> */): dynamic /* IteratorYieldResult<T> | IteratorReturnResult<TReturn> */
val `return`: ((value: TReturn) -> dynamic)?
val `throw`: ((e: Any) -> dynamic)?
}
typealias Iterator__1<T> = Iterator<T, Any, Nothing?>
external interface Iterable<T>
external interface IterableIterator<T> : Iterator__1<T>
external interface PromiseConstructor {
var prototype: Promise<Any>
fun all(values: Any /* JsTuple<Any?, Any?, Any?, Any?, Any?, Any?, Any?, Any?, Any?, Any?> | JsTuple<Any?, Any?, Any?, Any?, Any?, Any?, Any?, Any?, Any?> | JsTuple<Any?, Any?, Any?, Any?, Any?, Any?, Any?, Any?> | JsTuple<Any?, Any?, Any?, Any?, Any?, Any?, Any?> | JsTuple<Any?, Any?, Any?, Any?, Any?, Any?> | JsTuple<Any?, Any?, Any?, Any?, Any?> | JsTuple<Any?, Any?, Any?, Any?> | JsTuple<Any?, Any?, Any?> | JsTuple<Any?, Any?> */): Promise<dynamic /* JsTuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> | JsTuple<T1, T2, T3, T4, T5, T6, T7, T8, T9> | JsTuple<T1, T2, T3, T4, T5, T6, T7, T8> | JsTuple<T1, T2, T3, T4, T5, T6, T7> | JsTuple<T1, T2, T3, T4, T5, T6> | JsTuple<T1, T2, T3, T4, T5> | JsTuple<T1, T2, T3, T4> | JsTuple<T1, T2, T3> | JsTuple<T1, T2> */>
fun <T> all(values: Array<Any? /* T | PromiseLike<T> */>): Promise<Array<T>>
fun <T> race(values: Array<T>): Promise<Any>
fun <T> reject(reason: Any = definedExternally): Promise<T>
fun <T> resolve(value: T): Promise<T>
fun <T> resolve(value: PromiseLike<T>): Promise<T>
fun resolve(): Promise<Unit>
fun <T> all(values: Iterable<Any? /* T | PromiseLike<T> */>): Promise<Array<T>>
fun <T> race(values: Iterable<T>): Promise<Any>
fun <T> race(values: Iterable<Any? /* T | PromiseLike<T> */>): Promise<T>
}

View File

@ -1,11 +1,35 @@
@file:Suppress("INTERFACE_WITH_SUPERCLASS", "OVERRIDING_FINAL_MEMBER", "RETURN_TYPE_MISMATCH_ON_OVERRIDE", "CONFLICTING_OVERLOADS",
"NO_EXPLICIT_VISIBILITY_IN_API_MODE_WARNING", "DEPRECATION", "KDocMissingDocumentation", "PropertyName",
"PropertyName", "Reformat"
)
@file:Suppress("INTERFACE_WITH_SUPERCLASS", "OVERRIDING_FINAL_MEMBER", "RETURN_TYPE_MISMATCH_ON_OVERRIDE", "CONFLICTING_OVERLOADS")
package tsstdlib
import org.khronos.webgl.ArrayBuffer
import org.khronos.webgl.Uint8Array
import kotlin.js.*
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 FunctionConstructor {
@nativeInvoke
operator fun invoke(vararg args: String): Function<*>
var prototype: Function<*>
}
external interface ErrorConstructor {
@nativeInvoke
operator fun invoke(message: String = definedExternally): Error
var prototype: Error
}
external interface PromiseLike<T> {
fun then(onfulfilled: ((value: T) -> Any?)? = definedExternally, onrejected: ((reason: Any) -> Any?)? = definedExternally): PromiseLike<dynamic /* TResult1 | TResult2 */>
}
external interface ArrayLike<T> {
var length: Number
@ -15,6 +39,8 @@ external interface ArrayLike<T> {
operator fun set(n: Number, value: T)
}
typealias Record<K, T> = Any
external interface ArrayBufferTypes {
var ArrayBuffer: ArrayBuffer
}
@ -34,4 +60,4 @@ external interface Uint8ArrayConstructor {
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): Uint8Array
}
}

View File

@ -0,0 +1,32 @@
@file:Suppress("INTERFACE_WITH_SUPERCLASS", "OVERRIDING_FINAL_MEMBER", "RETURN_TYPE_MISMATCH_ON_OVERRIDE", "CONFLICTING_OVERLOADS",
"UnusedImport", "PackageDirectoryMismatch", "PackageName", "NO_EXPLICIT_VISIBILITY_IN_API_MODE_WARNING",
"KDocMissingDocumentation"
)
package WebAssembly
import kotlin.js.*
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.*
import tsstdlib.Record
typealias Exports = Record<String, dynamic /* Function<*> | Global | Memory | Table */>
typealias ModuleImports = Record<String, dynamic /* Function<*> | Global | Memory | Table | Number */>
typealias Imports = Record<String, ModuleImports>
typealias CompileError1 = Error
typealias LinkError1 = Error
typealias RuntimeError1 = Error

View File

@ -1,31 +0,0 @@
@file:Suppress(
"INTERFACE_WITH_SUPERCLASS", "OVERRIDING_FINAL_MEMBER", "RETURN_TYPE_MISMATCH_ON_OVERRIDE", "CONFLICTING_OVERLOADS",
"NO_EXPLICIT_VISIBILITY_IN_API_MODE_WARNING", "NO_EXPLICIT_VISIBILITY_IN_API_MODE_WARNING",
"KDocMissingDocumentation"
)
package tsstdlib
external interface IteratorYieldResult<TYield> {
var done: Boolean?
get() = definedExternally
set(value) = definedExternally
var value: TYield
}
external interface IteratorReturnResult<TReturn> {
var done: Boolean
var value: TReturn
}
external interface Iterator<T, TReturn, TNext> {
fun next(vararg args: Any /* JsTuple<> | JsTuple<TNext> */): dynamic /* IteratorYieldResult<T> | IteratorReturnResult<TReturn> */
val `return`: ((value: TReturn) -> dynamic)?
val `throw`: ((e: Any) -> dynamic)?
}
typealias Iterator__1<T> = Iterator<T, Any, Nothing?>
external interface Iterable<T>
external interface IterableIterator<T> : Iterator__1<T>

View File

@ -0,0 +1,102 @@
/**
* WebAssembly v1 (MVP) declaration file for TypeScript
* Definitions by: 01alchemist (https://twitter.com/01alchemist)
*/
declare namespace WebAssembly {
/**
* WebAssembly.Module
**/
class Module {
constructor (bufferSource: ArrayBuffer | Uint8Array);
static customSections(module: Module, sectionName: string): ArrayBuffer[];
static exports(module: Module): {
name: string;
kind: string;
}[];
static imports(module: Module): {
module: string;
name: string;
kind: string;
}[];
}
/**
* WebAssembly.Instance
**/
class Instance {
readonly exports: any;
constructor (module: Module, importObject?: any);
}
/**
* WebAssembly.Memory
* Note: A WebAssembly page has a constant size of 65,536 bytes, i.e., 64KiB.
**/
interface MemoryDescriptor {
initial: number;
maximum?: number;
}
class Memory {
readonly buffer: ArrayBuffer;
constructor (memoryDescriptor: MemoryDescriptor);
grow(numPages: number): number;
}
/**
* WebAssembly.Table
**/
interface TableDescriptor {
element: "anyfunc",
initial: number;
maximum?: number;
}
class Table {
readonly length: number;
constructor (tableDescriptor: TableDescriptor);
get(index: number): Function;
grow(numElements: number): number;
set(index: number, value: Function): void;
}
/**
* Errors
*/
class CompileError extends Error {
readonly fileName: string;
readonly lineNumber: string;
readonly columnNumber: string;
constructor (message?:string, fileName?:string, lineNumber?:number);
toString(): string;
}
class LinkError extends Error {
readonly fileName: string;
readonly lineNumber: string;
readonly columnNumber: string;
constructor (message?:string, fileName?:string, lineNumber?:number);
toString(): string;
}
class RuntimeError extends Error {
readonly fileName: string;
readonly lineNumber: string;
readonly columnNumber: string;
constructor (message?:string, fileName?:string, lineNumber?:number);
toString(): string;
}
function compile(bufferSource: ArrayBuffer | Uint8Array): Promise<Module>;
interface ResultObject {
module: Module;
instance: Instance;
}
function instantiate(bufferSource: ArrayBuffer | Uint8Array, importObject?: any): Promise<ResultObject>;
function instantiate(module: Module, importObject?: any): Promise<Instance>;
function validate(bufferSource: ArrayBuffer | Uint8Array): boolean;
}

View File

@ -1,11 +1,16 @@
package kscience.kmath.ast
import kscience.kmath.expressions.invoke
import kscience.kmath.operations.invoke
import kotlin.test.Test
import kotlin.time.measureTime
internal class Test {
@Test
fun c() {
compileMstToWasmF64(MstExtendedField { sin(symbol("x")) })
measureTime {
val expr = compileMstToWasmF64(MstExtendedField { sin(symbol("x")) + cos(symbol("x")).pow(2) })
println(expr("x" to 3.0))
}.also { println(it) }
}
}