diff options
author | SoniEx2 <endermoneymod@gmail.com> | 2025-03-15 22:47:10 -0300 |
---|---|---|
committer | SoniEx2 <endermoneymod@gmail.com> | 2025-03-15 22:47:10 -0300 |
commit | 1b4e672a4580e2d38edcd06510dabb45359f162b (patch) | |
tree | e8991c94e57c61fd1287f31a71261230c71b4f18 /src/main/kotlin | |
parent | 2aa1dea5126290ee6dadc0884a3d8e2791be04ef (diff) |
Make flite work
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() { +} |