wasm-c-api
wasm-c-api copied to clipboard
Why the Extern hierarchy?
It just doesn't add anything. And only feels like oop for the sake of oop.
User code will want to grab the underlying type directly. And forcing everyone through a generic exports() accessor will just hurt performance and usability.
Most of your examples already expose a helper function for it that take hardcoded magic indices for what they need. If the order of exports ever change then they will fail.
They correspond to the "extern values" in the spec. In particular, that's what module instances take as lists for imports and exports. So you need a common type.
The examples are not necessarily representative of the general case. For example, a generic loader will not have static knowledge about their individual types.
At some level either the engine or the embedder will have to do that downcast, so the cost as a wash. The actual instantiation is orders of magnitude more expensive anyway.
See also #119.