diff options
Diffstat (limited to 'src/main/kotlin')
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() { +} |