inline-wast
Inline WebAssembly in your JavaScript
Motivations
The idea is (almost) the same than the built-in asm
(or __asm__
) function in C.
Express your computation using the WebAssembly backend or an interpreter.
WAST is a superset of WATF (.wat
) and is not part of the WebAssembly specification but we use it for convenience.
Example
Instructions
const wastInstructions = ; { const fn = wastInstructions` (i32.const ) (i32.const ) (i32.add) `; return ;} console; // 2
Function declaration
const wast = ; { const exports = ; return exports;} console; // 2
Native
If you want to use the native WebAssembly backend the usage remains the same, but you need to use:
const wastInstructions wast = ;
It's not recommended for now, the WAST to WASM conversion needs to be refactored.