When thinking of the why a interpeter work:
parse code -> producer machine byte code -> allocate exec mem -> run
how can it be done in wasm?
thanks!
If you are actually implementing an interpreter then you don't need to generate machine code at runtime, so everything can stay within Wasm.
What you actually seem to have in mind is a just-in-time compiler. For that, you indeed have to call back into the embedder (i.e., JavaScript in the browser) and create and compile new Wasm modules there on the fly, and link them into the running program -- e.g., by adding new functions to an existing table. The synchronous compilation/instantiation interface exists for this use case.
In future versions it may be possible to invoke the compilation API directly from within Wasm, but for now going through JavaScript is the intended approach.
Compile a JIT based lang to Webassembly