-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Goals:
- Vite plugin, enabling
import { func } from "./something.mite"funcshould be able to return arbitrary numerical-based struct/num/etc- arbitrary numerical-based struct would be (wasm/mite-side) heap allocated
- maybe a special part of the heap with sizeof(struct)-sized chunks for faster alloc?
- automatically allocated (memcpy) w/ returned stack variables
- property accessing is just getter/setter wrapping
dataview.set<somenum>or nested struct - free'd with
FinalizationRegistry
- arbitrary numerical-based struct would be (wasm/mite-side) heap allocated
- Typescript type gen
- Handle v128 somehow
- Should generate something like
declare const wasm_memory: WebAssembly.Memory;
declare const _free: (ptr: number) => void;
const freedom = new FinalizationRegistry<number>((ptr) => _free(ptr));
class MyStruct {
#view: DataView;
static sizeof = 12;
constructor(ptr: number) {
this.#view = new DataView(wasm_memory.buffer, ptr, MyStruct.sizeof);
freedom.register(this, ptr);
}
get x(): number {
return this.#view.getUint32(0, true);
}
set x(value: number) {
this.#view.setUint32(0, value, true);
}
get y(): bigint {
return this.#view.getBigInt64(0, true);
}
set y(value: bigint) {
this.#view.setBigInt64(0, value, true);
}
}for
struct MyStruct {
u32 x;
i64 y;
}- special case primitive arrays into their corresponding
TypedArrayrepresentation - otherwise just use something like
Array.from({ length: returned_length }, (_, i) => new MyStruct(base + i * MyStruct.sizeof))
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels