File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed
backend/jvm/src/main/kotlin/dev/suresh/wasm Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ package dev.suresh.wasm
3
3
import com.dylibso.chicory.experimental.aot.AotMachine
4
4
import com.dylibso.chicory.runtime.HostFunction
5
5
import com.dylibso.chicory.runtime.Instance
6
- import com.dylibso.chicory.wasm.Module
7
6
import com.dylibso.chicory.wasm.Parser
8
7
import com.dylibso.chicory.wasm.types.ValueType
9
8
import io.ktor.server.response.respondText
@@ -14,18 +13,19 @@ import io.ktor.server.routing.*
14
13
* - [wasm-corpus](https://github.com/dylibso/chicory/tree/main/wasm-corpus/src/main/resources/compiled)
15
14
* - [extism](https://github.com/extism/plugins/releases)
16
15
*/
17
- val factWasmMod : Module by lazy {
16
+ val factWasmInst : Instance by lazy {
18
17
val wasmRes = Thread .currentThread().contextClassLoader.getResourceAsStream(" wasm/factorial.wasm" )
19
18
// val wasmRes = object {}.javaClass.getResourceAsStream("wasm/factorial.wasm")
20
- Parser .parse(wasmRes)
19
+ val wasmMod = Parser .parse(wasmRes)
20
+ Instance .builder(wasmMod).withMachineFactory(::AotMachine ).build()
21
21
}
22
22
23
23
fun Routing.wasm () {
24
24
route(" /wasm" ) {
25
25
get(" fact" ) {
26
26
val num = call.parameters[" num" ]?.toLongOrNull() ? : 5
27
- val inst = Instance .builder(factWasmMod).withMachineFactory(:: AotMachine ).build()
28
- val iterFact = inst .export(" iterFact" )
27
+
28
+ val iterFact = factWasmInst .export(" iterFact" )
29
29
val fact = iterFact.apply (num)[0 ]
30
30
31
31
call.respondText(" WASM: Factorial($num ): $fact " )
You can’t perform that action at this time.
0 commit comments