A prototype of a Metaprogram Plugin for compiling Jai to wasm64 (and maybe wasm32).
- The Metaprogram Plugin sets the LLVM target triple to
wasm64
. - It then strips all procedure bodies that contain inline assembly (we need to provide non-asm alternatives in the future).
- After, it links the WASM binary with the
wasm-ld
. - Optionally, it uses the wasm64232 tool to convert the 64 WASM binary to 32 one (this is currently untested).
- A tiny change in
Basic/Print.jai:3
is needed. Change it fromUSE_SIMD :: true;
toUSE_SIMD :: CPU == .X64;
. - Include the WASM Metaprogram Plugin in your
build.jai
. - Or compile your program with the following command
jai main.jai -plug wasm --- import_dir /path/to/wasm/plugin
Define foreign JavaScript functions with a foreign directive in the following way:
alert :: (s: string) #foreign WASM;
Export Jai procedures with #program_export
directive. Optionally you can specify the export name #program_export "export_name"
.
#program_export
render :: () {
...
}
When compilation output is set to executable
main is automatically exported.
- Compile
main.jai
with the WASM metaprogram plugin with the following commandjai main.jai -plug wasm --- import_dir /path/to/wasm/plugin
. - Serve
public
folder with local HTTP server.
This approach is based on jai-wasm thanks!