We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent bd41e23 commit 523eedaCopy full SHA for 523eeda
wasm/example.wasm
120 Bytes
wasm/example.wat
@@ -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
@@ -0,0 +1,9 @@
+import * as fs from "fs";
+const buffer = fs.readFileSync(process.argv[2]);
+const env = {
+ print: (x) => console.log(x),
+ pow: (x, y) => x ** y,
+};
+const wasmModule = await WebAssembly.instantiate(buffer, { env });
+wasmModule.instance.exports.main();
0 commit comments