-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
39 lines (37 loc) · 955 Bytes
/
index.html
File metadata and controls
39 lines (37 loc) · 955 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<!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>