Skip to content

Commit 523eeda

Browse files
committed
Start a WASM folder
1 parent bd41e23 commit 523eeda

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

wasm/example.wasm

120 Bytes
Binary file not shown.

wasm/example.wat

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
(module
2+
(import "env" "print"
3+
(func $print (param f64)))
4+
(import "env" "pow"
5+
(func $pow (param f64) (param f64) (result f64)))
6+
7+
(func $prev (param $x f64) (result f64)
8+
(local.get $x) (f64.const 1) (f64.sub)
9+
)
10+
11+
(func (export "main")
12+
(local $x f64) (f64.const 5) (local.set $x)
13+
(local.get $x) (f64.const 21) (call $pow)
14+
(call $prev) (call $print)
15+
)
16+
)

wasm/runwasm.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as fs from "fs";
2+
3+
const buffer = fs.readFileSync(process.argv[2]);
4+
const env = {
5+
print: (x) => console.log(x),
6+
pow: (x, y) => x ** y,
7+
};
8+
const wasmModule = await WebAssembly.instantiate(buffer, { env });
9+
wasmModule.instance.exports.main();

0 commit comments

Comments
 (0)