i'm trying to wrap my head around wasm representation of different structures. how would one define/represent an object definition in wasm? would that be a module? or would a module more closely align with the application itself?
i.e., is a module an application? or does an application consist of multiple modules linked together? it feels more like the former.
In the pre-components world, a WASI "command" module is an application
There are various ways to link modules together, but nothing really standardized
The component model aims to standardize a particular way of linking modules together
ok so that sounds like roughly object == module in that sense. (coming from a jvm background)
reading through various wast examples seem to support that.
A closer analog for JVM would be a package, probably. There aren't any (native) "objects" in wasm
maybe via name mangling and paramater passing i can fake out the instance method scenario.
yeah. i've been trying to figure out how to emulate that.
There will be "resource types" Pretty Soon which are intended to model things like that. In the meantime I think the most common approach has been to represent object references with integer handles that are manually tracked in a table
a key distinction between Wasm and the JVM (or other OOP runtimes like .NET) is its memory storage model -- Wasm gives each module a linear store ("C-style addressed memory") and the main approach in core Wasm so far has been to put the runtime on top of that
e.g. with SpiderMonkey-on-Wasm, JS objects are managed by the usual SpiderMonkey GC, and this lives inside of the module and allocates storage out of the linear address space
interesting. like off-heap storage in the jvm.
a challenge with a module-is-an-object mapping instead will be that there are no first-class instances; i.e. there's no direct mapping for "new T"
See for example: https://github.com/WebAssembly/wasi-http/blob/main/wit/types.wit#L76-L93
rather the shape of the instance graph is static and fixed as defined in the component
some funky stuff there. i love it.
Last updated: Nov 22 2024 at 16:03 UTC