Research on the topic: JS syntax that compiles to pure WASM. No runtime, no GC, no overhead.
import jz from 'jz'
// 3 lines of JS → 120 bytes of WASM, compiles in <1ms
const { exports } = await WebAssembly.instantiate(jz(`
let { sin, PI } = Math
export let sine = (out, freq, t) => {
for (let i = 0; i < out.length; i++) out[i] = sin((t + i) * freq * PI * 2 / 44100)
}
`))
// Real-time audio at native speed, zero GC pauses
exports.sine(audioBuffer, 440, sampleOffset)import jz from 'jz'
const wasm = jz(`export const add = (a, b) => a + b`)
const { exports } = await WebAssembly.instantiate(wasm)
exports.add(2, 3) // 5# Install globally
npm install -g jz
# Evaluate expression (requires watr)
jz "1 + 2"
# Output: 3
# Compile to WAT (default)
jz compile program.js -o program.wat
# Compile to WASM binary (requires watr)
jz compile program.js -o program.wasm
# Run compiled program (requires watr)
jz run program.js
# Show help
jz --help- Numbers:
0.1,1.2e+3,0xabc,0b101,0o357 - Strings:
"abc",'abc' - Values:
true,false,null,NaN,Infinity,PI,E - Access:
a.b,a[b],a(b),a?.b - Arithmetic:
+a,-a,a + b,a - b,a * b,a / b,a % b,a ** b - Comparison:
a < b,a <= b,a > b,a >= b,a == b,a != b - Bitwise:
~a,a & b,a ^ b,a | b,a << b,a >> b,a >>> b - Logic:
!a,a && b,a || b,a ?? b,a ? b : c - Assignment:
a = b,a += b,a -= b,a *= b,a /= b,a %= b - Arrays:
[a, b],arr[i],arr[i] = x,arr.length - TypedArrays:
new Float32Array(n),buf[i],buf.length,buf.byteLength - Objects:
{a: b},{a, b},obj.prop - Boxed primitives:
Object.assign(42, {prop}),Object.assign("str", {prop}),Object.assign([arr], {prop}) - Functions:
(a, b) => c,a => b,() => c - Currying:
add = x => y => x + y; add(5)(3) - Comments:
// foo,/* bar */ - Declarations:
let,const, block scope - Strict equality:
===,!== - Closures: capture outer variables
- Rest/spread:
...args,[...arr] - Destructuring params:
({ x }) => x - Regex:
/pattern/.test(str)- compile-time regex, native WASM matching - More array/string methods