summary refs log tree commit diff stats
path: root/src/main/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin')
-rw-r--r--src/main/kotlin/space/autistic/radio/reflection/MemoryReflection.kt14
-rw-r--r--src/main/kotlin/space/autistic/radio/wasm/Bindings.kt5
-rw-r--r--src/main/kotlin/space/autistic/radio/wasm/WasmExitException.kt4
3 files changed, 23 insertions, 0 deletions
diff --git a/src/main/kotlin/space/autistic/radio/reflection/MemoryReflection.kt b/src/main/kotlin/space/autistic/radio/reflection/MemoryReflection.kt
new file mode 100644
index 0000000..78961da
--- /dev/null
+++ b/src/main/kotlin/space/autistic/radio/reflection/MemoryReflection.kt
@@ -0,0 +1,14 @@
+package space.autistic.radio.reflection
+
+import com.dylibso.chicory.runtime.ByteBufferMemory
+import java.lang.invoke.MethodHandles
+import java.nio.ByteBuffer
+
+fun ByteBufferMemory.getBuffer(): ByteBuffer {
+    return MemoryReflection.buffer.get(this) as ByteBuffer
+}
+
+object MemoryReflection {
+    val buffer = MethodHandles.privateLookupIn(ByteBufferMemory::class.java, MethodHandles.lookup())
+        .findVarHandle(ByteBufferMemory::class.java, "buffer", ByteBuffer::class.java)
+}
\ No newline at end of file
diff --git a/src/main/kotlin/space/autistic/radio/wasm/Bindings.kt b/src/main/kotlin/space/autistic/radio/wasm/Bindings.kt
index cc123a1..5ff4102 100644
--- a/src/main/kotlin/space/autistic/radio/wasm/Bindings.kt
+++ b/src/main/kotlin/space/autistic/radio/wasm/Bindings.kt
@@ -141,6 +141,11 @@ class Bindings {
                     Value.EMPTY_VALUES
                 }
 
+                Void::class.java -> HostFunction(module, name, wasmParameters, emptyList()) { instance, args ->
+                    handle.invokeExact(instance, args)
+                    throw IllegalStateException("unreachable")
+                }
+
                 Int::class.java -> HostFunction(module, name, wasmParameters, listOf(ValueType.I32)) { instance, args ->
                     val result: Int = handle.invokeExact(instance, args) as Int
                     longArrayOf(result.toLong())
diff --git a/src/main/kotlin/space/autistic/radio/wasm/WasmExitException.kt b/src/main/kotlin/space/autistic/radio/wasm/WasmExitException.kt
new file mode 100644
index 0000000..43c08be
--- /dev/null
+++ b/src/main/kotlin/space/autistic/radio/wasm/WasmExitException.kt
@@ -0,0 +1,4 @@
+package space.autistic.radio.wasm
+
+class WasmExitException(val status: Int) : Exception() {
+}