Skip to content

dqn/towa

Repository files navigation

towa

CI

Toy wat to wasm compiler

Installation

$ npm install towa
# or
$ yarn add towa
# or
$ pnpm add towa

Usage

$ npx towa path/to/file.wat
# => file.wasm

API

import { parse, generate } from "towa";

const wat = `
(module
  (func $add (param $lhs i32) (param $rhs i32) (result i32)
    local.get $lhs
    local.get $rhs
    i32.add)
  (export "add" (func $add))
)
`.trim();

const result = parse([...wat]);

if (result.success) {
  const buf = generate(result.data);

  WebAssembly.instantiate(buf).then((wasmModule) => {
    const { add } = wasmModule.instance.exports;
    const sum = (add as any)(1, 2);
    console.log(sum); // 3
  });
}

License

MIT

About

Toy wat to wasm compiler

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published