quickjs icon indicating copy to clipboard operation
quickjs copied to clipboard

Web Assembly output

Open JohnnyOpcode opened this issue 1 year ago • 2 comments

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.

JohnnyOpcode avatar Feb 11 '24 00:02 JohnnyOpcode

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.

saghul avatar Feb 11 '24 09:02 saghul

There are 3 potential directions here:

  • compiling QuickJS to WASM, which is what @saghul did in his wasi-lab project if I am not mistaken, and other projects too such as https://github.com/bytecodealliance/javy ;
  • making QuickJS produce WASM from JS source code without a full fledged run-time, which is non trivial;
  • adding support in QuickJS for WASM modules, with or without generation of executable code (JIT).

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.

chqrlie avatar Feb 11 '24 22:02 chqrlie