https://github.com/mdn/watify
Compile WAT to WASM with WASM 🙇
https://github.com/mdn/watify
Last synced: 4 months ago
JSON representation
Compile WAT to WASM with WASM 🙇
- Host: GitHub
- URL: https://github.com/mdn/watify
- Owner: mdn
- License: mpl-2.0
- Created: 2025-02-26T11:57:24.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-26T12:04:05.000Z (12 months ago)
- Last Synced: 2025-06-01T12:56:16.188Z (12 months ago)
- Language: HTML
- Size: 481 KB
- Stars: 0
- Watchers: 5
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# Watify
Compile WAT to WASM with WASM 🙇
## Usage
For local testing, build the package, then server the project root
by running an http server. THe `index.html` file has this example.
The output can be seen in the browser's console.
```javascript
import init, { watify } from "watify";
const w = `
(module
(func $fac (export "fac") (param $x i64) (result i64)
(return_call $fac-aux (local.get $x) (i64.const 1))
)
(func $fac-aux (param $x i64) (param $r i64) (result i64)
(if (result i64) (i64.eqz (local.get $x))
(then (return (local.get $r)))
(else
(return_call $fac-aux
(i64.sub (local.get $x) (i64.const 1))
(i64.mul (local.get $x) (local.get $r))
)
)
)
)
)`;
init().then(() => {
const wasm = watify(w);
console.log(wasm);
WebAssembly.instantiate(wasm, {}).then((result) => {
const fac = result.instance.exports.fac;
console.log(fac(5n));
});
});
```