bellard / quickjs

Public repository of the QuickJS Javascript Engine.
https://bellard.org/quickjs
Other
8.35k stars 867 forks source link

Web Assembly output #237

Open JohnnyOpcode opened 7 months ago

JohnnyOpcode commented 7 months ago

How much effort to make this output WASM.

Web Assembly has such an interesting future including in containers. QuickJS would be a potent tool in the developers toolbox.

saghul commented 7 months ago

I ported QuickJS to WASI a few years ago: https://github.com/saghul/wasi-lab/blob/master/qjs-wasi/README.md

It's not a lot of work, you can probably take some inspiration from there.

chqrlie commented 7 months ago

There are 3 potential directions here:

The last direction is on my list, but not a high priority. It would allow instantiating modules compiled from other languages or for which source code is kept private.

Producing WASM directly from JS code is difficult because the language semantics are not well suited to generate typed stack machine byte code, unless the source code uses very specific operators as in asm.js, but no sane programmer produces such code directly, asm.js code is produced by compiler back-end, just like WASM.

WASM is very similar to Java byte code without the class information and with a more flexible interface to call into or be called from the host environment.