wagon
wagon copied to clipboard
wasm: ExecInitExpr is done too early
The execution of case getGlobal in ExecInitExpr depends on runtime imports to work correctly. We don't have that information before imports get resolved and therefore cannot execute init expressions ahead of time.
In the docs it says:
In the MVP, to keep things simple while still supporting the basic needs of dynamic linking, initializer expressions are restricted to the following nullary operators:
- the four constant operators; and
- get_global, where the global index must refer to an immutable import.
The current implementation appears to work for globals that are defined before the global referencing it is defined (index-wise) - does that not suit?
I guess we could re-order module initialization or do two passes to resolve this if necessary.