UNPKG

@mdn/bob

Version:

Builder of Bits aka The MDN Web Docs interactive examples, example builder

40 lines (37 loc) 955 B
<!doctype html> <html lang="en-US"> <head> <meta charset="utf-8" /> <title>hello-wasm example</title> </head> <body> <script type="module"> import init, { watify } from "./pkg/watify.js"; 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)); }); }); </script> </body> </html>