watr test npm bundle size npm

Light & fast WAT compiler.
Useful for high-level languages or dynamic (in-browser) compilation.
Supports full spec text syntax and official testsuite.

REPL

Usage

Compile

Compile wasm text or syntax tree into wasm binary.

import { compile } from 'watr'
const buffer = compile(`(func (export "double")
 (param f64) (result f64)
 (f64.mul (local.get 0) (f64.const 2))
)`)
const module = new WebAssembly.Module(buffer)
const instance = new WebAssembly.Instance(module)
const {double} = instance.exports
double(108) // 216

Parse

Parse input wasm text into syntax tree.

import { parse } from 'watr'
parse(`(func (export "double") (param f64) (result f64) (f64.mul (local.get 0) (f64.const 2)))`)
// [
// 'func', ['export', '"double"'], ['param', 'f64'], ['result', 'f64'],
// ['f64.mul', ['local.get', 0], ['f64.const', 2]]
// ]

Print

Format input wasm text or syntax tree into minified or pretty form.

import { print } from 'watr'
const src = `(func (export "double")
 (param f64) (result f64)
 (f64.mul (local.get 0) (f64.const 2))
)`
// pretty-print (default)
print(src, {
 indent: '',
 newline: '\n',
})
// (func
// (export "double")
// (param f64)
// (result f64)
// (f64.mul (local.get 0) (f64.const 2))
// )
// minify
print(src, {
 indent: false,
 newline: false
})
// (func(export "double")(param f64)(result f64)(f64.mul(local.get 0)(f64.const 2)))

Status

Alternatives

Size (gzipped) Performance
watr 7.5 kb 6.0 op/s
spec/wast.js 216 kb 2.2 op/s
wabt 282 kb 1.2 op/s
wat-compiler 7.7 kb 0.7 op/s

πŸ•‰

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /