From 485c3fd9b23be9e0553b4563b0594fa1979a8921 Mon Sep 17 00:00:00 2001 From: dcodeIO Date: Thu, 19 Apr 2018 17:32:23 +0200 Subject: [PATCH] Add mandelbrot example; Update game-of-life example --- README.md | 3 + examples/game-of-life/.gitignore | 1 - examples/game-of-life/README.md | 8 +- .../assembly/{game-of-life.ts => index.ts} | 0 examples/game-of-life/build/.gitignore | 3 + .../optimized.wasm} | Bin 453 -> 440 bytes examples/game-of-life/build/optimized.wat | 367 +++++++++++++++ examples/game-of-life/build/untouched.wat | 441 ++++++++++++++++++ examples/game-of-life/game-of-life.html | 76 --- .../game-of-life/game-of-life.optimized.wat | 367 --------------- .../game-of-life/game-of-life.untouched.wat | 441 ------------------ examples/game-of-life/index.html | 90 ++++ examples/game-of-life/package.json | 9 +- examples/game-of-life/server.js | 32 -- examples/mandelbrot/README.md | 21 + examples/mandelbrot/assembly/index.ts | 19 + examples/mandelbrot/assembly/tsconfig.json | 6 + examples/mandelbrot/build/.gitignore | 3 + examples/mandelbrot/build/optimized.wasm | Bin 0 -> 345 bytes examples/mandelbrot/build/optimized.wat | 261 +++++++++++ examples/mandelbrot/build/untouched.wat | 283 +++++++++++ examples/mandelbrot/index.html | 78 ++++ examples/mandelbrot/index.js | 6 + examples/mandelbrot/package.json | 14 + tests/compiler/game-of-life.optimized.wat | 54 +-- tests/compiler/game-of-life.ts | 2 +- tests/compiler/game-of-life.untouched.wat | 54 +-- tests/compiler/mandelbrot.optimized.wat | 196 ++++++++ tests/compiler/mandelbrot.ts | 1 + tests/compiler/mandelbrot.untouched.wat | 213 +++++++++ 30 files changed, 2069 insertions(+), 980 deletions(-) delete mode 100644 examples/game-of-life/.gitignore rename examples/game-of-life/assembly/{game-of-life.ts => index.ts} (100%) create mode 100644 examples/game-of-life/build/.gitignore rename examples/game-of-life/{game-of-life.optimized.wasm => build/optimized.wasm} (75%) create mode 100644 examples/game-of-life/build/optimized.wat create mode 100644 examples/game-of-life/build/untouched.wat delete mode 100644 examples/game-of-life/game-of-life.html delete mode 100644 examples/game-of-life/game-of-life.optimized.wat delete mode 100644 examples/game-of-life/game-of-life.untouched.wat create mode 100644 examples/game-of-life/index.html delete mode 100644 examples/game-of-life/server.js create mode 100644 examples/mandelbrot/README.md create mode 100644 examples/mandelbrot/assembly/index.ts create mode 100644 examples/mandelbrot/assembly/tsconfig.json create mode 100644 examples/mandelbrot/build/.gitignore create mode 100644 examples/mandelbrot/build/optimized.wasm create mode 100644 examples/mandelbrot/build/optimized.wat create mode 100644 examples/mandelbrot/build/untouched.wat create mode 100644 examples/mandelbrot/index.html create mode 100644 examples/mandelbrot/index.js create mode 100644 examples/mandelbrot/package.json create mode 100644 tests/compiler/mandelbrot.optimized.wat create mode 100644 tests/compiler/mandelbrot.ts create mode 100644 tests/compiler/mandelbrot.untouched.wat diff --git a/README.md b/README.md index 743ad4e1..5e6ee18a 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,9 @@ Examples * **[Conway's Game of Life](./examples/game-of-life)**
Continuously updates the cellular automaton and visualizes its state on a canvas. There's also [this WebAssembly Studio fiddle](https://webassembly.studio/?f=gvuw4enb3qk) of it. +* **[Mandelbrot Set](./examples/mandelbrot)**
+ Renders the Mandelbrot set to a canvas. + * **[i64 polyfill](./examples/i64-polyfill)**
Exposes WebAssembly's i64 operations to JavaScript using 32-bit integers (low and high bits). diff --git a/examples/game-of-life/.gitignore b/examples/game-of-life/.gitignore deleted file mode 100644 index c2658d7d..00000000 --- a/examples/game-of-life/.gitignore +++ /dev/null @@ -1 +0,0 @@ -node_modules/ diff --git a/examples/game-of-life/README.md b/examples/game-of-life/README.md index 164b853e..b64b9358 100644 --- a/examples/game-of-life/README.md +++ b/examples/game-of-life/README.md @@ -1,7 +1,7 @@ Conway's Game of Life ===================== -An [AssemblyScript](http://assemblyscript.org) example. Continuously updates the cellular automaton and visualizes its state on a canvas. Compiles to ~450 bytes of optimized WASM, no strings attached. +An [AssemblyScript](http://assemblyscript.org) example. Continuously updates the cellular automaton and visualizes its state on a canvas. Compiles to ~450 bytes of optimized WASM. Instructions ------------ @@ -12,10 +12,10 @@ First, install the development dependencies: $> npm install ``` -Now, to build [assembly/game-of-life.ts](./assembly/game-of-life.ts) to an untouched and an optimized `.wasm` including their respective `.wat` representations, run: +Now, to build [assembly/index.ts](./assembly/index.ts) to an untouched and an optimized `.wasm` including their respective `.wat` representations, run: ``` -$> npm run build +$> npm run asbuild ``` -Afterwards, run `node server` to start a local server. Should also automatically launch a browser. +Afterwards, run `npm run server` to start a local server. Should also automatically launch a browser. diff --git a/examples/game-of-life/assembly/game-of-life.ts b/examples/game-of-life/assembly/index.ts similarity index 100% rename from examples/game-of-life/assembly/game-of-life.ts rename to examples/game-of-life/assembly/index.ts diff --git a/examples/game-of-life/build/.gitignore b/examples/game-of-life/build/.gitignore new file mode 100644 index 00000000..22b2ed20 --- /dev/null +++ b/examples/game-of-life/build/.gitignore @@ -0,0 +1,3 @@ +*.wasm +*.wasm.map +*.asm.js diff --git a/examples/game-of-life/game-of-life.optimized.wasm b/examples/game-of-life/build/optimized.wasm similarity index 75% rename from examples/game-of-life/game-of-life.optimized.wasm rename to examples/game-of-life/build/optimized.wasm index aabc77bd8a24152b45217744ca9bff1f299895f6..fb45f111c309a41b7f87f8ecf6eba7f506542cd5 100644 GIT binary patch delta 45 zcmX@gyn}heWJXmLf#UqqqU2QH#Dap%y!6l@AEEq$lFZ!9s?-#{^2Fj?z1+kC0D3eK AssI20 delta 58 zcmdnNe3W^^WJV)Hf#UqqqU2QH#Dap%y!6l@ANlme+*IBCG~Jxcv{b$Pf|AVK%&OEB Nz4FB3T)o`H0swGk6=(ne diff --git a/examples/game-of-life/build/optimized.wat b/examples/game-of-life/build/optimized.wat new file mode 100644 index 00000000..4f7cbc77 --- /dev/null +++ b/examples/game-of-life/build/optimized.wat @@ -0,0 +1,367 @@ +(module + (type $iiv (func (param i32 i32))) + (type $v (func)) + (import "env" "memory" (memory $0 1)) + (global $assembly/index/w (mut i32) (i32.const 0)) + (global $assembly/index/h (mut i32) (i32.const 0)) + (global $assembly/index/s (mut i32) (i32.const 0)) + (export "init" (func $assembly/index/init)) + (export "step" (func $assembly/index/step)) + (export "memory" (memory $0)) + (func $assembly/index/init (; 0 ;) (type $iiv) (param $0 i32) (param $1 i32) + ;;@ assembly/index.ts:9:2 + (set_global $assembly/index/w + ;;@ assembly/index.ts:9:6 + (get_local $0) + ) + ;;@ assembly/index.ts:10:2 + (set_global $assembly/index/h + ;;@ assembly/index.ts:10:6 + (get_local $1) + ) + ;;@ assembly/index.ts:11:2 + (set_global $assembly/index/s + ;;@ assembly/index.ts:11:6 + (i32.mul + (get_local $0) + ;;@ assembly/index.ts:11:14 + (get_local $1) + ) + ) + ) + (func $assembly/index/step (; 1 ;) (type $v) + (local $0 i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (set_local $5 + ;;@ assembly/index.ts:16:12 + (i32.sub + (get_global $assembly/index/h) + ;;@ assembly/index.ts:16:16 + (i32.const 1) + ) + ) + (set_local $6 + ;;@ assembly/index.ts:17:12 + (i32.sub + (get_global $assembly/index/w) + ;;@ assembly/index.ts:17:16 + (i32.const 1) + ) + ) + (loop $continue|0 + (if + ;;@ assembly/index.ts:21:18 + (i32.lt_s + (get_local $0) + ;;@ assembly/index.ts:21:22 + (get_global $assembly/index/h) + ) + (block + (set_local $3 + ;;@ assembly/index.ts:23:14 + (if (result i32) + (get_local $0) + ;;@ assembly/index.ts:23:29 + (i32.sub + (get_local $0) + ;;@ assembly/index.ts:23:33 + (i32.const 1) + ) + ;;@ assembly/index.ts:23:23 + (get_local $5) + ) + ) + (set_local $4 + ;;@ assembly/index.ts:24:14 + (if (result i32) + (i32.eq + (get_local $0) + ;;@ assembly/index.ts:24:19 + (get_local $5) + ) + ;;@ assembly/index.ts:24:25 + (i32.const 0) + ;;@ assembly/index.ts:24:29 + (i32.add + (get_local $0) + ;;@ assembly/index.ts:24:33 + (i32.const 1) + ) + ) + ) + ;;@ assembly/index.ts:25:9 + (set_local $1 + ;;@ assembly/index.ts:25:17 + (i32.const 0) + ) + (loop $continue|1 + (if + ;;@ assembly/index.ts:25:20 + (i32.lt_s + (get_local $1) + ;;@ assembly/index.ts:25:24 + (get_global $assembly/index/w) + ) + (block + ;;@ assembly/index.ts:31:6 + (set_local $2 + ;;@ assembly/index.ts:31:27 + (i32.add + ;;@ assembly/index.ts:32:8 + (i32.add + (i32.add + (i32.add + (i32.add + (i32.add + (i32.add + (i32.load8_u + ;;@ assembly/index.ts:32:17 + (i32.add + (i32.mul + (get_local $3) + ;;@ assembly/index.ts:32:23 + (get_global $assembly/index/w) + ) + (tee_local $2 + ;;@ assembly/index.ts:26:16 + (if (result i32) + (get_local $1) + ;;@ assembly/index.ts:26:31 + (i32.sub + (get_local $1) + ;;@ assembly/index.ts:26:35 + (i32.const 1) + ) + ;;@ assembly/index.ts:26:25 + (get_local $6) + ) + ) + ) + ) + ;;@ assembly/index.ts:32:34 + (i32.load8_u + ;;@ assembly/index.ts:32:43 + (i32.add + (i32.mul + (get_local $3) + ;;@ assembly/index.ts:32:49 + (get_global $assembly/index/w) + ) + ;;@ assembly/index.ts:32:53 + (get_local $1) + ) + ) + ) + ;;@ assembly/index.ts:32:58 + (i32.load8_u + ;;@ assembly/index.ts:32:67 + (i32.add + (i32.mul + (get_local $3) + ;;@ assembly/index.ts:32:73 + (get_global $assembly/index/w) + ) + (tee_local $7 + ;;@ assembly/index.ts:27:16 + (if (result i32) + (i32.eq + (get_local $1) + ;;@ assembly/index.ts:27:21 + (get_local $6) + ) + ;;@ assembly/index.ts:27:27 + (i32.const 0) + ;;@ assembly/index.ts:27:31 + (i32.add + (get_local $1) + ;;@ assembly/index.ts:27:35 + (i32.const 1) + ) + ) + ) + ) + ) + ) + ;;@ assembly/index.ts:33:8 + (i32.load8_u + ;;@ assembly/index.ts:33:17 + (i32.add + (i32.mul + (get_local $0) + ;;@ assembly/index.ts:33:23 + (get_global $assembly/index/w) + ) + ;;@ assembly/index.ts:33:27 + (get_local $2) + ) + ) + ) + ;;@ assembly/index.ts:33:58 + (i32.load8_u + ;;@ assembly/index.ts:33:67 + (i32.add + (i32.mul + (get_local $0) + ;;@ assembly/index.ts:33:73 + (get_global $assembly/index/w) + ) + ;;@ assembly/index.ts:33:77 + (get_local $7) + ) + ) + ) + ;;@ assembly/index.ts:34:8 + (i32.load8_u + ;;@ assembly/index.ts:34:17 + (i32.add + (i32.mul + (get_local $4) + ;;@ assembly/index.ts:34:23 + (get_global $assembly/index/w) + ) + ;;@ assembly/index.ts:34:27 + (get_local $2) + ) + ) + ) + ;;@ assembly/index.ts:34:34 + (i32.load8_u + ;;@ assembly/index.ts:34:43 + (i32.add + (i32.mul + (get_local $4) + ;;@ assembly/index.ts:34:49 + (get_global $assembly/index/w) + ) + ;;@ assembly/index.ts:34:53 + (get_local $1) + ) + ) + ) + ;;@ assembly/index.ts:34:58 + (i32.load8_u + ;;@ assembly/index.ts:34:67 + (i32.add + (i32.mul + (get_local $4) + ;;@ assembly/index.ts:34:73 + (get_global $assembly/index/w) + ) + ;;@ assembly/index.ts:34:77 + (get_local $7) + ) + ) + ) + ) + ;;@ assembly/index.ts:38:6 + (if + ;;@ assembly/index.ts:37:18 + (i32.load8_u + ;;@ assembly/index.ts:37:27 + (i32.add + (i32.mul + (get_local $0) + ;;@ assembly/index.ts:37:31 + (get_global $assembly/index/w) + ) + ;;@ assembly/index.ts:37:35 + (get_local $1) + ) + ) + ;;@ assembly/index.ts:39:8 + (block $break|2 + (br_if $break|2 + (i32.eq + ;;@ assembly/index.ts:39:16 + (get_local $2) + ;;@ assembly/index.ts:44:15 + (i32.const 2) + ) + ) + (br_if $break|2 + (i32.eq + (get_local $2) + ;;@ assembly/index.ts:44:23 + (i32.const 3) + ) + ) + ;;@ assembly/index.ts:42:21 + (i32.store8 + ;;@ assembly/index.ts:42:31 + (i32.add + (i32.add + (get_global $assembly/index/s) + ;;@ assembly/index.ts:42:35 + (i32.mul + (get_local $0) + ;;@ assembly/index.ts:42:39 + (get_global $assembly/index/w) + ) + ) + ;;@ assembly/index.ts:42:43 + (get_local $1) + ) + ;;@ assembly/index.ts:42:46 + (i32.const 0) + ) + ) + (if + (i32.eq + ;;@ assembly/index.ts:47:16 + (get_local $2) + ;;@ assembly/index.ts:49:15 + (i32.const 3) + ) + ;;@ assembly/index.ts:49:20 + (i32.store8 + ;;@ assembly/index.ts:49:30 + (i32.add + (i32.add + (get_global $assembly/index/s) + ;;@ assembly/index.ts:49:34 + (i32.mul + (get_local $0) + ;;@ assembly/index.ts:49:38 + (get_global $assembly/index/w) + ) + ) + ;;@ assembly/index.ts:49:42 + (get_local $1) + ) + ;;@ assembly/index.ts:49:45 + (i32.const 1) + ) + ) + ) + ;;@ assembly/index.ts:25:27 + (set_local $1 + (i32.add + ;;@ assembly/index.ts:25:29 + (get_local $1) + (i32.const 1) + ) + ) + (br $continue|1) + ) + ) + ) + ;;@ assembly/index.ts:21:25 + (set_local $0 + (i32.add + ;;@ assembly/index.ts:21:27 + (get_local $0) + (i32.const 1) + ) + ) + (br $continue|0) + ) + ) + ) + ) +) diff --git a/examples/game-of-life/build/untouched.wat b/examples/game-of-life/build/untouched.wat new file mode 100644 index 00000000..4dcbfc03 --- /dev/null +++ b/examples/game-of-life/build/untouched.wat @@ -0,0 +1,441 @@ +(module + (type $iiv (func (param i32 i32))) + (type $v (func)) + (import "env" "memory" (memory $0 1)) + (global $assembly/index/w (mut i32) (i32.const 0)) + (global $assembly/index/h (mut i32) (i32.const 0)) + (global $assembly/index/s (mut i32) (i32.const 0)) + (global $HEAP_BASE i32 (i32.const 4)) + (export "init" (func $assembly/index/init)) + (export "step" (func $assembly/index/step)) + (export "memory" (memory $0)) + (func $assembly/index/init (; 0 ;) (type $iiv) (param $0 i32) (param $1 i32) + ;;@ assembly/index.ts:9:2 + (set_global $assembly/index/w + ;;@ assembly/index.ts:9:6 + (get_local $0) + ) + ;;@ assembly/index.ts:10:2 + (set_global $assembly/index/h + ;;@ assembly/index.ts:10:6 + (get_local $1) + ) + ;;@ assembly/index.ts:11:2 + (set_global $assembly/index/s + ;;@ assembly/index.ts:11:6 + (i32.mul + (get_local $0) + ;;@ assembly/index.ts:11:14 + (get_local $1) + ) + ) + ) + (func $assembly/index/step (; 1 ;) (type $v) + (local $0 i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i32) + (local $9 i32) + (local $10 i32) + ;;@ assembly/index.ts:16:2 + (block + (set_local $0 + ;;@ assembly/index.ts:16:12 + (i32.sub + (get_global $assembly/index/h) + ;;@ assembly/index.ts:16:16 + (i32.const 1) + ) + ) + (set_local $1 + ;;@ assembly/index.ts:17:12 + (i32.sub + (get_global $assembly/index/w) + ;;@ assembly/index.ts:17:16 + (i32.const 1) + ) + ) + ) + ;;@ assembly/index.ts:21:2 + (block $break|0 + ;;@ assembly/index.ts:21:7 + (set_local $2 + ;;@ assembly/index.ts:21:15 + (i32.const 0) + ) + (loop $continue|0 + (if + ;;@ assembly/index.ts:21:18 + (i32.lt_s + (get_local $2) + ;;@ assembly/index.ts:21:22 + (get_global $assembly/index/h) + ) + (block + (block + (block + (set_local $3 + ;;@ assembly/index.ts:23:14 + (if (result i32) + (i32.eq + (get_local $2) + ;;@ assembly/index.ts:23:19 + (i32.const 0) + ) + ;;@ assembly/index.ts:23:23 + (get_local $0) + ;;@ assembly/index.ts:23:29 + (i32.sub + (get_local $2) + ;;@ assembly/index.ts:23:33 + (i32.const 1) + ) + ) + ) + (set_local $4 + ;;@ assembly/index.ts:24:14 + (if (result i32) + (i32.eq + (get_local $2) + ;;@ assembly/index.ts:24:19 + (get_local $0) + ) + ;;@ assembly/index.ts:24:25 + (i32.const 0) + ;;@ assembly/index.ts:24:29 + (i32.add + (get_local $2) + ;;@ assembly/index.ts:24:33 + (i32.const 1) + ) + ) + ) + ) + ;;@ assembly/index.ts:25:4 + (block $break|1 + ;;@ assembly/index.ts:25:9 + (set_local $5 + ;;@ assembly/index.ts:25:17 + (i32.const 0) + ) + (loop $continue|1 + (if + ;;@ assembly/index.ts:25:20 + (i32.lt_s + (get_local $5) + ;;@ assembly/index.ts:25:24 + (get_global $assembly/index/w) + ) + (block + (block + (block + (set_local $6 + ;;@ assembly/index.ts:26:16 + (if (result i32) + (i32.eq + (get_local $5) + ;;@ assembly/index.ts:26:21 + (i32.const 0) + ) + ;;@ assembly/index.ts:26:25 + (get_local $1) + ;;@ assembly/index.ts:26:31 + (i32.sub + (get_local $5) + ;;@ assembly/index.ts:26:35 + (i32.const 1) + ) + ) + ) + (set_local $7 + ;;@ assembly/index.ts:27:16 + (if (result i32) + (i32.eq + (get_local $5) + ;;@ assembly/index.ts:27:21 + (get_local $1) + ) + ;;@ assembly/index.ts:27:27 + (i32.const 0) + ;;@ assembly/index.ts:27:31 + (i32.add + (get_local $5) + ;;@ assembly/index.ts:27:35 + (i32.const 1) + ) + ) + ) + ) + ;;@ assembly/index.ts:31:6 + (set_local $8 + ;;@ assembly/index.ts:31:27 + (i32.add + ;;@ assembly/index.ts:32:8 + (i32.add + (i32.add + (i32.add + (i32.add + (i32.add + (i32.add + (i32.load8_u + ;;@ assembly/index.ts:32:17 + (i32.add + (i32.mul + (get_local $3) + ;;@ assembly/index.ts:32:23 + (get_global $assembly/index/w) + ) + ;;@ assembly/index.ts:32:27 + (get_local $6) + ) + ) + ;;@ assembly/index.ts:32:34 + (i32.load8_u + ;;@ assembly/index.ts:32:43 + (i32.add + (i32.mul + (get_local $3) + ;;@ assembly/index.ts:32:49 + (get_global $assembly/index/w) + ) + ;;@ assembly/index.ts:32:53 + (get_local $5) + ) + ) + ) + ;;@ assembly/index.ts:32:58 + (i32.load8_u + ;;@ assembly/index.ts:32:67 + (i32.add + (i32.mul + (get_local $3) + ;;@ assembly/index.ts:32:73 + (get_global $assembly/index/w) + ) + ;;@ assembly/index.ts:32:77 + (get_local $7) + ) + ) + ) + ;;@ assembly/index.ts:33:8 + (i32.load8_u + ;;@ assembly/index.ts:33:17 + (i32.add + (i32.mul + (get_local $2) + ;;@ assembly/index.ts:33:23 + (get_global $assembly/index/w) + ) + ;;@ assembly/index.ts:33:27 + (get_local $6) + ) + ) + ) + ;;@ assembly/index.ts:33:58 + (i32.load8_u + ;;@ assembly/index.ts:33:67 + (i32.add + (i32.mul + (get_local $2) + ;;@ assembly/index.ts:33:73 + (get_global $assembly/index/w) + ) + ;;@ assembly/index.ts:33:77 + (get_local $7) + ) + ) + ) + ;;@ assembly/index.ts:34:8 + (i32.load8_u + ;;@ assembly/index.ts:34:17 + (i32.add + (i32.mul + (get_local $4) + ;;@ assembly/index.ts:34:23 + (get_global $assembly/index/w) + ) + ;;@ assembly/index.ts:34:27 + (get_local $6) + ) + ) + ) + ;;@ assembly/index.ts:34:34 + (i32.load8_u + ;;@ assembly/index.ts:34:43 + (i32.add + (i32.mul + (get_local $4) + ;;@ assembly/index.ts:34:49 + (get_global $assembly/index/w) + ) + ;;@ assembly/index.ts:34:53 + (get_local $5) + ) + ) + ) + ;;@ assembly/index.ts:34:58 + (i32.load8_u + ;;@ assembly/index.ts:34:67 + (i32.add + (i32.mul + (get_local $4) + ;;@ assembly/index.ts:34:73 + (get_global $assembly/index/w) + ) + ;;@ assembly/index.ts:34:77 + (get_local $7) + ) + ) + ) + ) + ;;@ assembly/index.ts:37:6 + (set_local $9 + ;;@ assembly/index.ts:37:18 + (i32.load8_u + ;;@ assembly/index.ts:37:27 + (i32.add + (i32.mul + (get_local $2) + ;;@ assembly/index.ts:37:31 + (get_global $assembly/index/w) + ) + ;;@ assembly/index.ts:37:35 + (get_local $5) + ) + ) + ) + ;;@ assembly/index.ts:38:6 + (if + ;;@ assembly/index.ts:38:10 + (get_local $9) + ;;@ assembly/index.ts:39:8 + (block $break|2 + (block $case2|2 + (block $case1|2 + (block $case0|2 + (set_local $10 + ;;@ assembly/index.ts:39:16 + (get_local $8) + ) + (br_if $case1|2 + (i32.eq + (get_local $10) + ;;@ assembly/index.ts:44:15 + (i32.const 2) + ) + ) + (br_if $case2|2 + (i32.eq + (get_local $10) + ;;@ assembly/index.ts:44:23 + (i32.const 3) + ) + ) + (br $case0|2) + ) + ;;@ assembly/index.ts:42:19 + (block + ;;@ assembly/index.ts:42:21 + (i32.store8 + ;;@ assembly/index.ts:42:31 + (i32.add + (i32.add + (get_global $assembly/index/s) + ;;@ assembly/index.ts:42:35 + (i32.mul + (get_local $2) + ;;@ assembly/index.ts:42:39 + (get_global $assembly/index/w) + ) + ) + ;;@ assembly/index.ts:42:43 + (get_local $5) + ) + ;;@ assembly/index.ts:42:46 + (i32.const 0) + ) + ;;@ assembly/index.ts:42:50 + (br $break|2) + ) + ) + ) + ) + ;;@ assembly/index.ts:47:8 + (block $break|3 + (block $case1|3 + (block $case0|3 + (set_local $10 + ;;@ assembly/index.ts:47:16 + (get_local $8) + ) + (br_if $case0|3 + (i32.eq + (get_local $10) + ;;@ assembly/index.ts:49:15 + (i32.const 3) + ) + ) + (br $case1|3) + ) + ;;@ assembly/index.ts:49:18 + (block + ;;@ assembly/index.ts:49:20 + (i32.store8 + ;;@ assembly/index.ts:49:30 + (i32.add + (i32.add + (get_global $assembly/index/s) + ;;@ assembly/index.ts:49:34 + (i32.mul + (get_local $2) + ;;@ assembly/index.ts:49:38 + (get_global $assembly/index/w) + ) + ) + ;;@ assembly/index.ts:49:42 + (get_local $5) + ) + ;;@ assembly/index.ts:49:45 + (i32.const 1) + ) + ;;@ assembly/index.ts:49:49 + (br $break|3) + ) + ) + ) + ) + ) + ;;@ assembly/index.ts:25:27 + (set_local $5 + (i32.add + ;;@ assembly/index.ts:25:29 + (get_local $5) + (i32.const 1) + ) + ) + (br $continue|1) + ) + ) + ) + ) + ) + ;;@ assembly/index.ts:21:25 + (set_local $2 + (i32.add + ;;@ assembly/index.ts:21:27 + (get_local $2) + (i32.const 1) + ) + ) + (br $continue|0) + ) + ) + ) + ) + ) +) diff --git a/examples/game-of-life/game-of-life.html b/examples/game-of-life/game-of-life.html deleted file mode 100644 index e0656ad9..00000000 --- a/examples/game-of-life/game-of-life.html +++ /dev/null @@ -1,76 +0,0 @@ - - - - - -

- Conway's Game Of Life in - AssemblyScript -

- - - - diff --git a/examples/game-of-life/game-of-life.optimized.wat b/examples/game-of-life/game-of-life.optimized.wat deleted file mode 100644 index a850dd5a..00000000 --- a/examples/game-of-life/game-of-life.optimized.wat +++ /dev/null @@ -1,367 +0,0 @@ -(module - (type $iiv (func (param i32 i32))) - (type $v (func)) - (import "env" "memory" (memory $0 1)) - (global $assembly/game-of-life/w (mut i32) (i32.const 0)) - (global $assembly/game-of-life/h (mut i32) (i32.const 0)) - (global $assembly/game-of-life/s (mut i32) (i32.const 0)) - (export "init" (func $assembly/game-of-life/init)) - (export "step" (func $assembly/game-of-life/step)) - (export "memory" (memory $0)) - (func $assembly/game-of-life/init (; 0 ;) (type $iiv) (param $0 i32) (param $1 i32) - ;;@ assembly/game-of-life.ts:9:2 - (set_global $assembly/game-of-life/w - ;;@ assembly/game-of-life.ts:9:6 - (get_local $0) - ) - ;;@ assembly/game-of-life.ts:10:2 - (set_global $assembly/game-of-life/h - ;;@ assembly/game-of-life.ts:10:6 - (get_local $1) - ) - ;;@ assembly/game-of-life.ts:11:2 - (set_global $assembly/game-of-life/s - ;;@ assembly/game-of-life.ts:11:6 - (i32.mul - (get_local $0) - ;;@ assembly/game-of-life.ts:11:14 - (get_local $1) - ) - ) - ) - (func $assembly/game-of-life/step (; 1 ;) (type $v) - (local $0 i32) - (local $1 i32) - (local $2 i32) - (local $3 i32) - (local $4 i32) - (local $5 i32) - (local $6 i32) - (local $7 i32) - (set_local $5 - ;;@ assembly/game-of-life.ts:16:12 - (i32.sub - (get_global $assembly/game-of-life/h) - ;;@ assembly/game-of-life.ts:16:16 - (i32.const 1) - ) - ) - (set_local $6 - ;;@ assembly/game-of-life.ts:17:12 - (i32.sub - (get_global $assembly/game-of-life/w) - ;;@ assembly/game-of-life.ts:17:16 - (i32.const 1) - ) - ) - (loop $continue|0 - (if - ;;@ assembly/game-of-life.ts:21:18 - (i32.lt_s - (get_local $0) - ;;@ assembly/game-of-life.ts:21:22 - (get_global $assembly/game-of-life/h) - ) - (block - (set_local $3 - ;;@ assembly/game-of-life.ts:23:14 - (if (result i32) - (get_local $0) - ;;@ assembly/game-of-life.ts:23:29 - (i32.sub - (get_local $0) - ;;@ assembly/game-of-life.ts:23:33 - (i32.const 1) - ) - ;;@ assembly/game-of-life.ts:23:23 - (get_local $5) - ) - ) - (set_local $4 - ;;@ assembly/game-of-life.ts:24:14 - (if (result i32) - (i32.eq - (get_local $0) - ;;@ assembly/game-of-life.ts:24:19 - (get_local $5) - ) - ;;@ assembly/game-of-life.ts:24:25 - (i32.const 0) - ;;@ assembly/game-of-life.ts:24:29 - (i32.add - (get_local $0) - ;;@ assembly/game-of-life.ts:24:33 - (i32.const 1) - ) - ) - ) - ;;@ assembly/game-of-life.ts:25:9 - (set_local $1 - ;;@ assembly/game-of-life.ts:25:17 - (i32.const 0) - ) - (loop $continue|1 - (if - ;;@ assembly/game-of-life.ts:25:20 - (i32.lt_s - (get_local $1) - ;;@ assembly/game-of-life.ts:25:24 - (get_global $assembly/game-of-life/w) - ) - (block - ;;@ assembly/game-of-life.ts:31:6 - (set_local $2 - ;;@ assembly/game-of-life.ts:31:27 - (i32.add - ;;@ assembly/game-of-life.ts:32:8 - (i32.add - (i32.add - (i32.add - (i32.add - (i32.add - (i32.add - (i32.load8_u - ;;@ assembly/game-of-life.ts:32:17 - (i32.add - (i32.mul - (get_local $3) - ;;@ assembly/game-of-life.ts:32:23 - (get_global $assembly/game-of-life/w) - ) - (tee_local $2 - ;;@ assembly/game-of-life.ts:26:16 - (if (result i32) - (get_local $1) - ;;@ assembly/game-of-life.ts:26:31 - (i32.sub - (get_local $1) - ;;@ assembly/game-of-life.ts:26:35 - (i32.const 1) - ) - ;;@ assembly/game-of-life.ts:26:25 - (get_local $6) - ) - ) - ) - ) - ;;@ assembly/game-of-life.ts:32:34 - (i32.load8_u - ;;@ assembly/game-of-life.ts:32:43 - (i32.add - (i32.mul - (get_local $3) - ;;@ assembly/game-of-life.ts:32:49 - (get_global $assembly/game-of-life/w) - ) - ;;@ assembly/game-of-life.ts:32:53 - (get_local $1) - ) - ) - ) - ;;@ assembly/game-of-life.ts:32:58 - (i32.load8_u - ;;@ assembly/game-of-life.ts:32:67 - (i32.add - (i32.mul - (get_local $3) - ;;@ assembly/game-of-life.ts:32:73 - (get_global $assembly/game-of-life/w) - ) - (tee_local $7 - ;;@ assembly/game-of-life.ts:27:16 - (if (result i32) - (i32.eq - (get_local $1) - ;;@ assembly/game-of-life.ts:27:21 - (get_local $6) - ) - ;;@ assembly/game-of-life.ts:27:27 - (i32.const 0) - ;;@ assembly/game-of-life.ts:27:31 - (i32.add - (get_local $1) - ;;@ assembly/game-of-life.ts:27:35 - (i32.const 1) - ) - ) - ) - ) - ) - ) - ;;@ assembly/game-of-life.ts:33:8 - (i32.load8_u - ;;@ assembly/game-of-life.ts:33:17 - (i32.add - (i32.mul - (get_local $0) - ;;@ assembly/game-of-life.ts:33:23 - (get_global $assembly/game-of-life/w) - ) - ;;@ assembly/game-of-life.ts:33:27 - (get_local $2) - ) - ) - ) - ;;@ assembly/game-of-life.ts:33:58 - (i32.load8_u - ;;@ assembly/game-of-life.ts:33:67 - (i32.add - (i32.mul - (get_local $0) - ;;@ assembly/game-of-life.ts:33:73 - (get_global $assembly/game-of-life/w) - ) - ;;@ assembly/game-of-life.ts:33:77 - (get_local $7) - ) - ) - ) - ;;@ assembly/game-of-life.ts:34:8 - (i32.load8_u - ;;@ assembly/game-of-life.ts:34:17 - (i32.add - (i32.mul - (get_local $4) - ;;@ assembly/game-of-life.ts:34:23 - (get_global $assembly/game-of-life/w) - ) - ;;@ assembly/game-of-life.ts:34:27 - (get_local $2) - ) - ) - ) - ;;@ assembly/game-of-life.ts:34:34 - (i32.load8_u - ;;@ assembly/game-of-life.ts:34:43 - (i32.add - (i32.mul - (get_local $4) - ;;@ assembly/game-of-life.ts:34:49 - (get_global $assembly/game-of-life/w) - ) - ;;@ assembly/game-of-life.ts:34:53 - (get_local $1) - ) - ) - ) - ;;@ assembly/game-of-life.ts:34:58 - (i32.load8_u - ;;@ assembly/game-of-life.ts:34:67 - (i32.add - (i32.mul - (get_local $4) - ;;@ assembly/game-of-life.ts:34:73 - (get_global $assembly/game-of-life/w) - ) - ;;@ assembly/game-of-life.ts:34:77 - (get_local $7) - ) - ) - ) - ) - ;;@ assembly/game-of-life.ts:38:6 - (if - ;;@ assembly/game-of-life.ts:37:18 - (i32.load8_u - ;;@ assembly/game-of-life.ts:37:27 - (i32.add - (i32.mul - (get_local $0) - ;;@ assembly/game-of-life.ts:37:31 - (get_global $assembly/game-of-life/w) - ) - ;;@ assembly/game-of-life.ts:37:35 - (get_local $1) - ) - ) - ;;@ assembly/game-of-life.ts:39:8 - (block $break|2 - (br_if $break|2 - (i32.eq - ;;@ assembly/game-of-life.ts:39:16 - (get_local $2) - ;;@ assembly/game-of-life.ts:44:15 - (i32.const 2) - ) - ) - (br_if $break|2 - (i32.eq - (get_local $2) - ;;@ assembly/game-of-life.ts:44:23 - (i32.const 3) - ) - ) - ;;@ assembly/game-of-life.ts:42:21 - (i32.store8 - ;;@ assembly/game-of-life.ts:42:31 - (i32.add - (i32.add - (get_global $assembly/game-of-life/s) - ;;@ assembly/game-of-life.ts:42:35 - (i32.mul - (get_local $0) - ;;@ assembly/game-of-life.ts:42:39 - (get_global $assembly/game-of-life/w) - ) - ) - ;;@ assembly/game-of-life.ts:42:43 - (get_local $1) - ) - ;;@ assembly/game-of-life.ts:42:46 - (i32.const 0) - ) - ) - (if - (i32.eq - ;;@ assembly/game-of-life.ts:47:16 - (get_local $2) - ;;@ assembly/game-of-life.ts:49:15 - (i32.const 3) - ) - ;;@ assembly/game-of-life.ts:49:20 - (i32.store8 - ;;@ assembly/game-of-life.ts:49:30 - (i32.add - (i32.add - (get_global $assembly/game-of-life/s) - ;;@ assembly/game-of-life.ts:49:34 - (i32.mul - (get_local $0) - ;;@ assembly/game-of-life.ts:49:38 - (get_global $assembly/game-of-life/w) - ) - ) - ;;@ assembly/game-of-life.ts:49:42 - (get_local $1) - ) - ;;@ assembly/game-of-life.ts:49:45 - (i32.const 1) - ) - ) - ) - ;;@ assembly/game-of-life.ts:25:27 - (set_local $1 - (i32.add - ;;@ assembly/game-of-life.ts:25:29 - (get_local $1) - (i32.const 1) - ) - ) - (br $continue|1) - ) - ) - ) - ;;@ assembly/game-of-life.ts:21:25 - (set_local $0 - (i32.add - ;;@ assembly/game-of-life.ts:21:27 - (get_local $0) - (i32.const 1) - ) - ) - (br $continue|0) - ) - ) - ) - ) -) diff --git a/examples/game-of-life/game-of-life.untouched.wat b/examples/game-of-life/game-of-life.untouched.wat deleted file mode 100644 index d8297daa..00000000 --- a/examples/game-of-life/game-of-life.untouched.wat +++ /dev/null @@ -1,441 +0,0 @@ -(module - (type $iiv (func (param i32 i32))) - (type $v (func)) - (import "env" "memory" (memory $0 1)) - (global $assembly/game-of-life/w (mut i32) (i32.const 0)) - (global $assembly/game-of-life/h (mut i32) (i32.const 0)) - (global $assembly/game-of-life/s (mut i32) (i32.const 0)) - (global $HEAP_BASE i32 (i32.const 4)) - (export "init" (func $assembly/game-of-life/init)) - (export "step" (func $assembly/game-of-life/step)) - (export "memory" (memory $0)) - (func $assembly/game-of-life/init (; 0 ;) (type $iiv) (param $0 i32) (param $1 i32) - ;;@ assembly/game-of-life.ts:9:2 - (set_global $assembly/game-of-life/w - ;;@ assembly/game-of-life.ts:9:6 - (get_local $0) - ) - ;;@ assembly/game-of-life.ts:10:2 - (set_global $assembly/game-of-life/h - ;;@ assembly/game-of-life.ts:10:6 - (get_local $1) - ) - ;;@ assembly/game-of-life.ts:11:2 - (set_global $assembly/game-of-life/s - ;;@ assembly/game-of-life.ts:11:6 - (i32.mul - (get_local $0) - ;;@ assembly/game-of-life.ts:11:14 - (get_local $1) - ) - ) - ) - (func $assembly/game-of-life/step (; 1 ;) (type $v) - (local $0 i32) - (local $1 i32) - (local $2 i32) - (local $3 i32) - (local $4 i32) - (local $5 i32) - (local $6 i32) - (local $7 i32) - (local $8 i32) - (local $9 i32) - (local $10 i32) - ;;@ assembly/game-of-life.ts:16:2 - (block - (set_local $0 - ;;@ assembly/game-of-life.ts:16:12 - (i32.sub - (get_global $assembly/game-of-life/h) - ;;@ assembly/game-of-life.ts:16:16 - (i32.const 1) - ) - ) - (set_local $1 - ;;@ assembly/game-of-life.ts:17:12 - (i32.sub - (get_global $assembly/game-of-life/w) - ;;@ assembly/game-of-life.ts:17:16 - (i32.const 1) - ) - ) - ) - ;;@ assembly/game-of-life.ts:21:2 - (block $break|0 - ;;@ assembly/game-of-life.ts:21:7 - (set_local $2 - ;;@ assembly/game-of-life.ts:21:15 - (i32.const 0) - ) - (loop $continue|0 - (if - ;;@ assembly/game-of-life.ts:21:18 - (i32.lt_s - (get_local $2) - ;;@ assembly/game-of-life.ts:21:22 - (get_global $assembly/game-of-life/h) - ) - (block - (block - (block - (set_local $3 - ;;@ assembly/game-of-life.ts:23:14 - (if (result i32) - (i32.eq - (get_local $2) - ;;@ assembly/game-of-life.ts:23:19 - (i32.const 0) - ) - ;;@ assembly/game-of-life.ts:23:23 - (get_local $0) - ;;@ assembly/game-of-life.ts:23:29 - (i32.sub - (get_local $2) - ;;@ assembly/game-of-life.ts:23:33 - (i32.const 1) - ) - ) - ) - (set_local $4 - ;;@ assembly/game-of-life.ts:24:14 - (if (result i32) - (i32.eq - (get_local $2) - ;;@ assembly/game-of-life.ts:24:19 - (get_local $0) - ) - ;;@ assembly/game-of-life.ts:24:25 - (i32.const 0) - ;;@ assembly/game-of-life.ts:24:29 - (i32.add - (get_local $2) - ;;@ assembly/game-of-life.ts:24:33 - (i32.const 1) - ) - ) - ) - ) - ;;@ assembly/game-of-life.ts:25:4 - (block $break|1 - ;;@ assembly/game-of-life.ts:25:9 - (set_local $5 - ;;@ assembly/game-of-life.ts:25:17 - (i32.const 0) - ) - (loop $continue|1 - (if - ;;@ assembly/game-of-life.ts:25:20 - (i32.lt_s - (get_local $5) - ;;@ assembly/game-of-life.ts:25:24 - (get_global $assembly/game-of-life/w) - ) - (block - (block - (block - (set_local $6 - ;;@ assembly/game-of-life.ts:26:16 - (if (result i32) - (i32.eq - (get_local $5) - ;;@ assembly/game-of-life.ts:26:21 - (i32.const 0) - ) - ;;@ assembly/game-of-life.ts:26:25 - (get_local $1) - ;;@ assembly/game-of-life.ts:26:31 - (i32.sub - (get_local $5) - ;;@ assembly/game-of-life.ts:26:35 - (i32.const 1) - ) - ) - ) - (set_local $7 - ;;@ assembly/game-of-life.ts:27:16 - (if (result i32) - (i32.eq - (get_local $5) - ;;@ assembly/game-of-life.ts:27:21 - (get_local $1) - ) - ;;@ assembly/game-of-life.ts:27:27 - (i32.const 0) - ;;@ assembly/game-of-life.ts:27:31 - (i32.add - (get_local $5) - ;;@ assembly/game-of-life.ts:27:35 - (i32.const 1) - ) - ) - ) - ) - ;;@ assembly/game-of-life.ts:31:6 - (set_local $8 - ;;@ assembly/game-of-life.ts:31:27 - (i32.add - ;;@ assembly/game-of-life.ts:32:8 - (i32.add - (i32.add - (i32.add - (i32.add - (i32.add - (i32.add - (i32.load8_u - ;;@ assembly/game-of-life.ts:32:17 - (i32.add - (i32.mul - (get_local $3) - ;;@ assembly/game-of-life.ts:32:23 - (get_global $assembly/game-of-life/w) - ) - ;;@ assembly/game-of-life.ts:32:27 - (get_local $6) - ) - ) - ;;@ assembly/game-of-life.ts:32:34 - (i32.load8_u - ;;@ assembly/game-of-life.ts:32:43 - (i32.add - (i32.mul - (get_local $3) - ;;@ assembly/game-of-life.ts:32:49 - (get_global $assembly/game-of-life/w) - ) - ;;@ assembly/game-of-life.ts:32:53 - (get_local $5) - ) - ) - ) - ;;@ assembly/game-of-life.ts:32:58 - (i32.load8_u - ;;@ assembly/game-of-life.ts:32:67 - (i32.add - (i32.mul - (get_local $3) - ;;@ assembly/game-of-life.ts:32:73 - (get_global $assembly/game-of-life/w) - ) - ;;@ assembly/game-of-life.ts:32:77 - (get_local $7) - ) - ) - ) - ;;@ assembly/game-of-life.ts:33:8 - (i32.load8_u - ;;@ assembly/game-of-life.ts:33:17 - (i32.add - (i32.mul - (get_local $2) - ;;@ assembly/game-of-life.ts:33:23 - (get_global $assembly/game-of-life/w) - ) - ;;@ assembly/game-of-life.ts:33:27 - (get_local $6) - ) - ) - ) - ;;@ assembly/game-of-life.ts:33:58 - (i32.load8_u - ;;@ assembly/game-of-life.ts:33:67 - (i32.add - (i32.mul - (get_local $2) - ;;@ assembly/game-of-life.ts:33:73 - (get_global $assembly/game-of-life/w) - ) - ;;@ assembly/game-of-life.ts:33:77 - (get_local $7) - ) - ) - ) - ;;@ assembly/game-of-life.ts:34:8 - (i32.load8_u - ;;@ assembly/game-of-life.ts:34:17 - (i32.add - (i32.mul - (get_local $4) - ;;@ assembly/game-of-life.ts:34:23 - (get_global $assembly/game-of-life/w) - ) - ;;@ assembly/game-of-life.ts:34:27 - (get_local $6) - ) - ) - ) - ;;@ assembly/game-of-life.ts:34:34 - (i32.load8_u - ;;@ assembly/game-of-life.ts:34:43 - (i32.add - (i32.mul - (get_local $4) - ;;@ assembly/game-of-life.ts:34:49 - (get_global $assembly/game-of-life/w) - ) - ;;@ assembly/game-of-life.ts:34:53 - (get_local $5) - ) - ) - ) - ;;@ assembly/game-of-life.ts:34:58 - (i32.load8_u - ;;@ assembly/game-of-life.ts:34:67 - (i32.add - (i32.mul - (get_local $4) - ;;@ assembly/game-of-life.ts:34:73 - (get_global $assembly/game-of-life/w) - ) - ;;@ assembly/game-of-life.ts:34:77 - (get_local $7) - ) - ) - ) - ) - ;;@ assembly/game-of-life.ts:37:6 - (set_local $9 - ;;@ assembly/game-of-life.ts:37:18 - (i32.load8_u - ;;@ assembly/game-of-life.ts:37:27 - (i32.add - (i32.mul - (get_local $2) - ;;@ assembly/game-of-life.ts:37:31 - (get_global $assembly/game-of-life/w) - ) - ;;@ assembly/game-of-life.ts:37:35 - (get_local $5) - ) - ) - ) - ;;@ assembly/game-of-life.ts:38:6 - (if - ;;@ assembly/game-of-life.ts:38:10 - (get_local $9) - ;;@ assembly/game-of-life.ts:39:8 - (block $break|2 - (block $case2|2 - (block $case1|2 - (block $case0|2 - (set_local $10 - ;;@ assembly/game-of-life.ts:39:16 - (get_local $8) - ) - (br_if $case1|2 - (i32.eq - (get_local $10) - ;;@ assembly/game-of-life.ts:44:15 - (i32.const 2) - ) - ) - (br_if $case2|2 - (i32.eq - (get_local $10) - ;;@ assembly/game-of-life.ts:44:23 - (i32.const 3) - ) - ) - (br $case0|2) - ) - ;;@ assembly/game-of-life.ts:42:19 - (block - ;;@ assembly/game-of-life.ts:42:21 - (i32.store8 - ;;@ assembly/game-of-life.ts:42:31 - (i32.add - (i32.add - (get_global $assembly/game-of-life/s) - ;;@ assembly/game-of-life.ts:42:35 - (i32.mul - (get_local $2) - ;;@ assembly/game-of-life.ts:42:39 - (get_global $assembly/game-of-life/w) - ) - ) - ;;@ assembly/game-of-life.ts:42:43 - (get_local $5) - ) - ;;@ assembly/game-of-life.ts:42:46 - (i32.const 0) - ) - ;;@ assembly/game-of-life.ts:42:50 - (br $break|2) - ) - ) - ) - ) - ;;@ assembly/game-of-life.ts:47:8 - (block $break|3 - (block $case1|3 - (block $case0|3 - (set_local $10 - ;;@ assembly/game-of-life.ts:47:16 - (get_local $8) - ) - (br_if $case0|3 - (i32.eq - (get_local $10) - ;;@ assembly/game-of-life.ts:49:15 - (i32.const 3) - ) - ) - (br $case1|3) - ) - ;;@ assembly/game-of-life.ts:49:18 - (block - ;;@ assembly/game-of-life.ts:49:20 - (i32.store8 - ;;@ assembly/game-of-life.ts:49:30 - (i32.add - (i32.add - (get_global $assembly/game-of-life/s) - ;;@ assembly/game-of-life.ts:49:34 - (i32.mul - (get_local $2) - ;;@ assembly/game-of-life.ts:49:38 - (get_global $assembly/game-of-life/w) - ) - ) - ;;@ assembly/game-of-life.ts:49:42 - (get_local $5) - ) - ;;@ assembly/game-of-life.ts:49:45 - (i32.const 1) - ) - ;;@ assembly/game-of-life.ts:49:49 - (br $break|3) - ) - ) - ) - ) - ) - ;;@ assembly/game-of-life.ts:25:27 - (set_local $5 - (i32.add - ;;@ assembly/game-of-life.ts:25:29 - (get_local $5) - (i32.const 1) - ) - ) - (br $continue|1) - ) - ) - ) - ) - ) - ;;@ assembly/game-of-life.ts:21:25 - (set_local $2 - (i32.add - ;;@ assembly/game-of-life.ts:21:27 - (get_local $2) - (i32.const 1) - ) - ) - (br $continue|0) - ) - ) - ) - ) - ) -) diff --git a/examples/game-of-life/index.html b/examples/game-of-life/index.html new file mode 100644 index 00000000..3645164c --- /dev/null +++ b/examples/game-of-life/index.html @@ -0,0 +1,90 @@ + + + +Conway's Game Of Life - AssemblyScript + + + +

+ Conway's Game Of Life in + AssemblyScript +

+ + + + diff --git a/examples/game-of-life/package.json b/examples/game-of-life/package.json index 608ffd35..bd97b507 100644 --- a/examples/game-of-life/package.json +++ b/examples/game-of-life/package.json @@ -3,11 +3,12 @@ "version": "1.0.0", "private": true, "scripts": { - "build": "npm run build:untouched && npm run build:optimized", - "build:untouched": "asc assembly/game-of-life.ts -b game-of-life.untouched.wasm -t game-of-life.untouched.wat --importMemory --validate --sourceMap --measure", - "build:optimized": "asc -O3 assembly/game-of-life.ts -b game-of-life.optimized.wasm -t game-of-life.optimized.wat --importMemory --validate --sourceMap --noDebug --measure" + "asbuild:untouched": "asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --importMemory --sourceMap --validate --measure", + "asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat -O3 --importMemory --sourceMap --validate --noDebug --measure", + "asbuild": "npm run asbuild:untouched && npm run asbuild:optimized", + "server": "http-server . -o -c-1" }, "devDependencies": { - "opn": "^5.3.0" + "http-server": "^0.11.1" } } diff --git a/examples/game-of-life/server.js b/examples/game-of-life/server.js deleted file mode 100644 index f6e6c8c1..00000000 --- a/examples/game-of-life/server.js +++ /dev/null @@ -1,32 +0,0 @@ -var http = require("http"); -var fs = require("fs"); -var open = require("opn"); - -const PORT = 9080; - -http.createServer((req, res) => { - var url = req.url; - console.log(req.method + " " + url); - if (/^\/([\w\-_]+(\.\w+)+)?$/i.test(url)) { - if (url === "/") url = "/game-of-life.html"; - fs.readFile(__dirname + url, function(err, data) { - if (err) { - res.writeHeader(404); - } else { - res.writeHeader(200, { - "Content-Type": - /\.wasm$/.test(url) ? "application/wasm" : - /\.(json|map)$/.test(url) ? "application/json" - : "text/html" - }); - res.write(data); - } - res.end(); - }); - } else { - res.writeHeader(404); - res.end(); - } -}).listen(PORT, () => { - open("http://localhost:9080/"); -}); diff --git a/examples/mandelbrot/README.md b/examples/mandelbrot/README.md new file mode 100644 index 00000000..2bc92f0a --- /dev/null +++ b/examples/mandelbrot/README.md @@ -0,0 +1,21 @@ +Mandelbrot Set +============== + +An [AssemblyScript](http://assemblyscript.org) example. Renders the Mandelbrot set to a canvas. Compiles to ~350 bytes of optimized WASM. + +Instructions +------------ + +First, install the development dependencies: + +``` +$> npm install +``` + +Now, to build [assembly/index.ts](./assembly/index.ts) to an untouched and an optimized `.wasm` including their respective `.wat` representations, run: + +``` +$> npm run asbuild +``` + +Afterwards, run `npm run server` to start a local server. Should also automatically launch a browser. diff --git a/examples/mandelbrot/assembly/index.ts b/examples/mandelbrot/assembly/index.ts new file mode 100644 index 00000000..969b2f52 --- /dev/null +++ b/examples/mandelbrot/assembly/index.ts @@ -0,0 +1,19 @@ +export function update(width: u32, height: u32, max: u32): void { + var translateX = width / 1.6; + var translateY = height / 2.0; + var scale = 4.0 / width; + for (let y: u32 = 0; y < height; ++y) { + let imaginary = (y - translateY) * scale; + for (let x: u32 = 0; x < width; ++x) { + let real = (x - translateX) * scale; + let iteration = 0; + for (let ix = 0.0, iy = 0.0; ix * ix + iy * iy <= 4.0; ++iteration) { + let t = ix * ix - iy * iy + real; + iy = 2.0 * ix * iy + imaginary; + ix = t; + if (++iteration >= max) break; + } + store(y * width + x, iteration * 255 / max); + } + } +} diff --git a/examples/mandelbrot/assembly/tsconfig.json b/examples/mandelbrot/assembly/tsconfig.json new file mode 100644 index 00000000..f45d47d2 --- /dev/null +++ b/examples/mandelbrot/assembly/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "../../../std/assembly.d.ts", + "include": [ + "./**/*.ts" + ] +} \ No newline at end of file diff --git a/examples/mandelbrot/build/.gitignore b/examples/mandelbrot/build/.gitignore new file mode 100644 index 00000000..22b2ed20 --- /dev/null +++ b/examples/mandelbrot/build/.gitignore @@ -0,0 +1,3 @@ +*.wasm +*.wasm.map +*.asm.js diff --git a/examples/mandelbrot/build/optimized.wasm b/examples/mandelbrot/build/optimized.wasm new file mode 100644 index 0000000000000000000000000000000000000000..c85a910812b82223f9104a62d63974b76c92eaa5 GIT binary patch literal 345 zcmYL_%}T>S5XWbBH=8scQ1k_6#B(3Oiz)OXD1zYKV1uMIP3Q-r2*JnDQ<}U)Ud@X- z3AWB<|NQ1Rv&%xV$q@k1#Rpwg6=;RvXcTa&?5>f6!`B7zftMRdn4#( zpC5gFUA8}Im3uefFZFOOr)an9&jJRz2KIuN{L51`2rr50?)0?C$v(?l6-StUPZnHdlP3Mzm`Orz8l)qkR BK)3(^ literal 0 HcmV?d00001 diff --git a/examples/mandelbrot/build/optimized.wat b/examples/mandelbrot/build/optimized.wat new file mode 100644 index 00000000..70a91dbf --- /dev/null +++ b/examples/mandelbrot/build/optimized.wat @@ -0,0 +1,261 @@ +(module + (type $iiiv (func (param i32 i32 i32))) + (memory $0 1) + (export "update" (func $assembly/index/update)) + (export "memory" (memory $0)) + (func $assembly/index/update (; 0 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 f64) + (local $4 f64) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 f64) + (local $9 f64) + (local $10 f64) + (local $11 f64) + (local $12 f64) + (local $13 f64) + ;;@ assembly/index.ts:2:2 + (set_local $9 + ;;@ assembly/index.ts:2:19 + (f64.div + (f64.convert_u/i32 + (get_local $0) + ) + ;;@ assembly/index.ts:2:27 + (f64.const 1.6) + ) + ) + ;;@ assembly/index.ts:3:2 + (set_local $10 + ;;@ assembly/index.ts:3:19 + (f64.div + (f64.convert_u/i32 + (get_local $1) + ) + ;;@ assembly/index.ts:3:28 + (f64.const 2) + ) + ) + ;;@ assembly/index.ts:4:2 + (set_local $8 + ;;@ assembly/index.ts:4:14 + (f64.div + (f64.const 4) + (f64.convert_u/i32 + ;;@ assembly/index.ts:4:20 + (get_local $0) + ) + ) + ) + (loop $continue|0 + (if + ;;@ assembly/index.ts:5:23 + (i32.lt_u + (get_local $5) + ;;@ assembly/index.ts:5:27 + (get_local $1) + ) + (block + ;;@ assembly/index.ts:6:4 + (set_local $11 + ;;@ assembly/index.ts:6:20 + (f64.mul + (f64.sub + (f64.convert_u/i32 + ;;@ assembly/index.ts:6:21 + (get_local $5) + ) + ;;@ assembly/index.ts:6:25 + (get_local $10) + ) + ;;@ assembly/index.ts:6:39 + (get_local $8) + ) + ) + ;;@ assembly/index.ts:7:9 + (set_local $6 + ;;@ assembly/index.ts:7:22 + (i32.const 0) + ) + (loop $continue|1 + (if + ;;@ assembly/index.ts:7:25 + (i32.lt_u + (get_local $6) + ;;@ assembly/index.ts:7:29 + (get_local $0) + ) + (block + ;;@ assembly/index.ts:8:6 + (set_local $12 + ;;@ assembly/index.ts:8:17 + (f64.mul + (f64.sub + (f64.convert_u/i32 + ;;@ assembly/index.ts:8:18 + (get_local $6) + ) + ;;@ assembly/index.ts:8:22 + (get_local $9) + ) + ;;@ assembly/index.ts:8:36 + (get_local $8) + ) + ) + ;;@ assembly/index.ts:9:6 + (set_local $7 + ;;@ assembly/index.ts:9:22 + (i32.const 0) + ) + ;;@ assembly/index.ts:10:6 + (block $break|2 + (set_local $3 + ;;@ assembly/index.ts:10:20 + (f64.const 0) + ) + (set_local $4 + ;;@ assembly/index.ts:10:30 + (f64.const 0) + ) + (loop $continue|2 + (if + ;;@ assembly/index.ts:10:35 + (f64.le + (f64.add + (f64.mul + (get_local $3) + ;;@ assembly/index.ts:10:40 + (get_local $3) + ) + ;;@ assembly/index.ts:10:45 + (f64.mul + (get_local $4) + ;;@ assembly/index.ts:10:50 + (get_local $4) + ) + ) + ;;@ assembly/index.ts:10:56 + (f64.const 4) + ) + (block + ;;@ assembly/index.ts:11:8 + (set_local $13 + ;;@ assembly/index.ts:11:16 + (f64.add + (f64.sub + (f64.mul + (get_local $3) + ;;@ assembly/index.ts:11:21 + (get_local $3) + ) + ;;@ assembly/index.ts:11:26 + (f64.mul + (get_local $4) + ;;@ assembly/index.ts:11:31 + (get_local $4) + ) + ) + ;;@ assembly/index.ts:11:36 + (get_local $12) + ) + ) + ;;@ assembly/index.ts:12:8 + (set_local $4 + ;;@ assembly/index.ts:12:13 + (f64.add + (f64.mul + (f64.mul + (f64.const 2) + ;;@ assembly/index.ts:12:19 + (get_local $3) + ) + ;;@ assembly/index.ts:12:24 + (get_local $4) + ) + ;;@ assembly/index.ts:12:29 + (get_local $11) + ) + ) + ;;@ assembly/index.ts:13:8 + (set_local $3 + ;;@ assembly/index.ts:13:13 + (get_local $13) + ) + ;;@ assembly/index.ts:14:32 + (br_if $break|2 + ;;@ assembly/index.ts:14:12 + (i32.ge_u + (tee_local $7 + (i32.add + ;;@ assembly/index.ts:14:14 + (get_local $7) + (i32.const 1) + ) + ) + ;;@ assembly/index.ts:14:27 + (get_local $2) + ) + ) + ;;@ assembly/index.ts:10:61 + (set_local $7 + (i32.add + ;;@ assembly/index.ts:10:63 + (get_local $7) + (i32.const 1) + ) + ) + (br $continue|2) + ) + ) + ) + ) + ;;@ assembly/index.ts:16:6 + (i32.store8 + ;;@ assembly/index.ts:16:16 + (i32.add + (i32.mul + (get_local $5) + ;;@ assembly/index.ts:16:20 + (get_local $0) + ) + ;;@ assembly/index.ts:16:28 + (get_local $6) + ) + ;;@ assembly/index.ts:16:31 + (i32.div_u + (i32.mul + (get_local $7) + ;;@ assembly/index.ts:16:43 + (i32.const 255) + ) + ;;@ assembly/index.ts:16:49 + (get_local $2) + ) + ) + ;;@ assembly/index.ts:7:36 + (set_local $6 + (i32.add + ;;@ assembly/index.ts:7:38 + (get_local $6) + (i32.const 1) + ) + ) + (br $continue|1) + ) + ) + ) + ;;@ assembly/index.ts:5:35 + (set_local $5 + (i32.add + ;;@ assembly/index.ts:5:37 + (get_local $5) + (i32.const 1) + ) + ) + (br $continue|0) + ) + ) + ) + ) +) diff --git a/examples/mandelbrot/build/untouched.wat b/examples/mandelbrot/build/untouched.wat new file mode 100644 index 00000000..7d7a11d4 --- /dev/null +++ b/examples/mandelbrot/build/untouched.wat @@ -0,0 +1,283 @@ +(module + (type $iiiv (func (param i32 i32 i32))) + (global $HEAP_BASE i32 (i32.const 4)) + (memory $0 1) + (export "update" (func $assembly/index/update)) + (export "memory" (memory $0)) + (func $assembly/index/update (; 0 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 f64) + (local $4 f64) + (local $5 f64) + (local $6 i32) + (local $7 f64) + (local $8 i32) + (local $9 f64) + (local $10 i32) + (local $11 f64) + (local $12 f64) + (local $13 f64) + ;;@ assembly/index.ts:2:2 + (set_local $3 + ;;@ assembly/index.ts:2:19 + (f64.div + (f64.convert_u/i32 + (get_local $0) + ) + ;;@ assembly/index.ts:2:27 + (f64.const 1.6) + ) + ) + ;;@ assembly/index.ts:3:2 + (set_local $4 + ;;@ assembly/index.ts:3:19 + (f64.div + (f64.convert_u/i32 + (get_local $1) + ) + ;;@ assembly/index.ts:3:28 + (f64.const 2) + ) + ) + ;;@ assembly/index.ts:4:2 + (set_local $5 + ;;@ assembly/index.ts:4:14 + (f64.div + (f64.const 4) + (f64.convert_u/i32 + ;;@ assembly/index.ts:4:20 + (get_local $0) + ) + ) + ) + ;;@ assembly/index.ts:5:2 + (block $break|0 + ;;@ assembly/index.ts:5:7 + (set_local $6 + ;;@ assembly/index.ts:5:20 + (i32.const 0) + ) + (loop $continue|0 + (if + ;;@ assembly/index.ts:5:23 + (i32.lt_u + (get_local $6) + ;;@ assembly/index.ts:5:27 + (get_local $1) + ) + (block + (block + ;;@ assembly/index.ts:6:4 + (set_local $7 + ;;@ assembly/index.ts:6:20 + (f64.mul + (f64.sub + (f64.convert_u/i32 + ;;@ assembly/index.ts:6:21 + (get_local $6) + ) + ;;@ assembly/index.ts:6:25 + (get_local $4) + ) + ;;@ assembly/index.ts:6:39 + (get_local $5) + ) + ) + ;;@ assembly/index.ts:7:4 + (block $break|1 + ;;@ assembly/index.ts:7:9 + (set_local $8 + ;;@ assembly/index.ts:7:22 + (i32.const 0) + ) + (loop $continue|1 + (if + ;;@ assembly/index.ts:7:25 + (i32.lt_u + (get_local $8) + ;;@ assembly/index.ts:7:29 + (get_local $0) + ) + (block + (block + ;;@ assembly/index.ts:8:6 + (set_local $9 + ;;@ assembly/index.ts:8:17 + (f64.mul + (f64.sub + (f64.convert_u/i32 + ;;@ assembly/index.ts:8:18 + (get_local $8) + ) + ;;@ assembly/index.ts:8:22 + (get_local $3) + ) + ;;@ assembly/index.ts:8:36 + (get_local $5) + ) + ) + ;;@ assembly/index.ts:9:6 + (set_local $10 + ;;@ assembly/index.ts:9:22 + (i32.const 0) + ) + ;;@ assembly/index.ts:10:6 + (block $break|2 + (block + (set_local $11 + ;;@ assembly/index.ts:10:20 + (f64.const 0) + ) + (set_local $12 + ;;@ assembly/index.ts:10:30 + (f64.const 0) + ) + ) + (loop $continue|2 + (if + ;;@ assembly/index.ts:10:35 + (f64.le + (f64.add + (f64.mul + (get_local $11) + ;;@ assembly/index.ts:10:40 + (get_local $11) + ) + ;;@ assembly/index.ts:10:45 + (f64.mul + (get_local $12) + ;;@ assembly/index.ts:10:50 + (get_local $12) + ) + ) + ;;@ assembly/index.ts:10:56 + (f64.const 4) + ) + (block + (block + ;;@ assembly/index.ts:11:8 + (set_local $13 + ;;@ assembly/index.ts:11:16 + (f64.add + (f64.sub + (f64.mul + (get_local $11) + ;;@ assembly/index.ts:11:21 + (get_local $11) + ) + ;;@ assembly/index.ts:11:26 + (f64.mul + (get_local $12) + ;;@ assembly/index.ts:11:31 + (get_local $12) + ) + ) + ;;@ assembly/index.ts:11:36 + (get_local $9) + ) + ) + ;;@ assembly/index.ts:12:8 + (set_local $12 + ;;@ assembly/index.ts:12:13 + (f64.add + (f64.mul + (f64.mul + (f64.const 2) + ;;@ assembly/index.ts:12:19 + (get_local $11) + ) + ;;@ assembly/index.ts:12:24 + (get_local $12) + ) + ;;@ assembly/index.ts:12:29 + (get_local $7) + ) + ) + ;;@ assembly/index.ts:13:8 + (set_local $11 + ;;@ assembly/index.ts:13:13 + (get_local $13) + ) + ;;@ assembly/index.ts:14:8 + (if + ;;@ assembly/index.ts:14:12 + (i32.ge_u + (tee_local $10 + (i32.add + ;;@ assembly/index.ts:14:14 + (get_local $10) + (i32.const 1) + ) + ) + ;;@ assembly/index.ts:14:27 + (get_local $2) + ) + ;;@ assembly/index.ts:14:32 + (br $break|2) + ) + ) + ;;@ assembly/index.ts:10:61 + (set_local $10 + (i32.add + ;;@ assembly/index.ts:10:63 + (get_local $10) + (i32.const 1) + ) + ) + (br $continue|2) + ) + ) + ) + ) + ;;@ assembly/index.ts:16:6 + (i32.store8 + ;;@ assembly/index.ts:16:16 + (i32.add + (i32.mul + (get_local $6) + ;;@ assembly/index.ts:16:20 + (get_local $0) + ) + ;;@ assembly/index.ts:16:28 + (get_local $8) + ) + ;;@ assembly/index.ts:16:31 + (i32.div_u + (i32.mul + (get_local $10) + ;;@ assembly/index.ts:16:43 + (i32.const 255) + ) + ;;@ assembly/index.ts:16:49 + (get_local $2) + ) + ) + ) + ;;@ assembly/index.ts:7:36 + (set_local $8 + (i32.add + ;;@ assembly/index.ts:7:38 + (get_local $8) + (i32.const 1) + ) + ) + (br $continue|1) + ) + ) + ) + ) + ) + ;;@ assembly/index.ts:5:35 + (set_local $6 + (i32.add + ;;@ assembly/index.ts:5:37 + (get_local $6) + (i32.const 1) + ) + ) + (br $continue|0) + ) + ) + ) + ) + ) +) diff --git a/examples/mandelbrot/index.html b/examples/mandelbrot/index.html new file mode 100644 index 00000000..ce02eef2 --- /dev/null +++ b/examples/mandelbrot/index.html @@ -0,0 +1,78 @@ + + + +Mandelbrot Set - AssemblyScript + + + +

+ Mandelbrot Set in + AssemblyScript +

+ + + + diff --git a/examples/mandelbrot/index.js b/examples/mandelbrot/index.js new file mode 100644 index 00000000..fbf18232 --- /dev/null +++ b/examples/mandelbrot/index.js @@ -0,0 +1,6 @@ +const fs = require("fs"); +const compiled = new WebAssembly.Module(fs.readFileSync(__dirname + "/build/optimized.wasm")); +const imports = {}; +Object.defineProperty(module, "exports", { + get: () => new WebAssembly.Instance(compiled, imports).exports +}); diff --git a/examples/mandelbrot/package.json b/examples/mandelbrot/package.json new file mode 100644 index 00000000..b345c2f4 --- /dev/null +++ b/examples/mandelbrot/package.json @@ -0,0 +1,14 @@ +{ + "name": "@assemblyscript/mandelbrot-example", + "version": "1.0.0", + "private": true, + "scripts": { + "asbuild:untouched": "asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --sourceMap --validate --measure", + "asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat -O3 --sourceMap --validate --noDebug --measure", + "asbuild": "npm run asbuild:untouched && npm run asbuild:optimized", + "server": "http-server . -o -c-1" + }, + "devDependencies": { + "http-server": "^0.11.1" + } +} diff --git a/tests/compiler/game-of-life.optimized.wat b/tests/compiler/game-of-life.optimized.wat index 63ccd061..009776be 100644 --- a/tests/compiler/game-of-life.optimized.wat +++ b/tests/compiler/game-of-life.optimized.wat @@ -1,28 +1,28 @@ (module (type $iiv (func (param i32 i32))) (type $v (func)) - (global $../../examples/game-of-life/assembly/game-of-life/w (mut i32) (i32.const 0)) - (global $../../examples/game-of-life/assembly/game-of-life/h (mut i32) (i32.const 0)) - (global $../../examples/game-of-life/assembly/game-of-life/s (mut i32) (i32.const 0)) + (global $../../examples/game-of-life/assembly/index/w (mut i32) (i32.const 0)) + (global $../../examples/game-of-life/assembly/index/h (mut i32) (i32.const 0)) + (global $../../examples/game-of-life/assembly/index/s (mut i32) (i32.const 0)) (memory $0 1) - (export "init" (func $../../examples/game-of-life/assembly/game-of-life/init)) - (export "step" (func $../../examples/game-of-life/assembly/game-of-life/step)) + (export "init" (func $../../examples/game-of-life/assembly/index/init)) + (export "step" (func $../../examples/game-of-life/assembly/index/step)) (export "memory" (memory $0)) - (func $../../examples/game-of-life/assembly/game-of-life/init (; 0 ;) (type $iiv) (param $0 i32) (param $1 i32) - (set_global $../../examples/game-of-life/assembly/game-of-life/w + (func $../../examples/game-of-life/assembly/index/init (; 0 ;) (type $iiv) (param $0 i32) (param $1 i32) + (set_global $../../examples/game-of-life/assembly/index/w (get_local $0) ) - (set_global $../../examples/game-of-life/assembly/game-of-life/h + (set_global $../../examples/game-of-life/assembly/index/h (get_local $1) ) - (set_global $../../examples/game-of-life/assembly/game-of-life/s + (set_global $../../examples/game-of-life/assembly/index/s (i32.mul (get_local $0) (get_local $1) ) ) ) - (func $../../examples/game-of-life/assembly/game-of-life/step (; 1 ;) (type $v) + (func $../../examples/game-of-life/assembly/index/step (; 1 ;) (type $v) (local $0 i32) (local $1 i32) (local $2 i32) @@ -33,13 +33,13 @@ (local $7 i32) (set_local $5 (i32.sub - (get_global $../../examples/game-of-life/assembly/game-of-life/h) + (get_global $../../examples/game-of-life/assembly/index/h) (i32.const 1) ) ) (set_local $6 (i32.sub - (get_global $../../examples/game-of-life/assembly/game-of-life/w) + (get_global $../../examples/game-of-life/assembly/index/w) (i32.const 1) ) ) @@ -47,7 +47,7 @@ (if (i32.lt_s (get_local $0) - (get_global $../../examples/game-of-life/assembly/game-of-life/h) + (get_global $../../examples/game-of-life/assembly/index/h) ) (block (set_local $3 @@ -80,7 +80,7 @@ (if (i32.lt_s (get_local $1) - (get_global $../../examples/game-of-life/assembly/game-of-life/w) + (get_global $../../examples/game-of-life/assembly/index/w) ) (block (set_local $2 @@ -95,7 +95,7 @@ (i32.add (i32.mul (get_local $3) - (get_global $../../examples/game-of-life/assembly/game-of-life/w) + (get_global $../../examples/game-of-life/assembly/index/w) ) (tee_local $2 (select @@ -113,7 +113,7 @@ (i32.add (i32.mul (get_local $3) - (get_global $../../examples/game-of-life/assembly/game-of-life/w) + (get_global $../../examples/game-of-life/assembly/index/w) ) (get_local $1) ) @@ -123,7 +123,7 @@ (i32.add (i32.mul (get_local $3) - (get_global $../../examples/game-of-life/assembly/game-of-life/w) + (get_global $../../examples/game-of-life/assembly/index/w) ) (tee_local $7 (select @@ -145,7 +145,7 @@ (i32.add (i32.mul (get_local $0) - (get_global $../../examples/game-of-life/assembly/game-of-life/w) + (get_global $../../examples/game-of-life/assembly/index/w) ) (get_local $2) ) @@ -155,7 +155,7 @@ (i32.add (i32.mul (get_local $0) - (get_global $../../examples/game-of-life/assembly/game-of-life/w) + (get_global $../../examples/game-of-life/assembly/index/w) ) (get_local $7) ) @@ -165,7 +165,7 @@ (i32.add (i32.mul (get_local $4) - (get_global $../../examples/game-of-life/assembly/game-of-life/w) + (get_global $../../examples/game-of-life/assembly/index/w) ) (get_local $2) ) @@ -175,7 +175,7 @@ (i32.add (i32.mul (get_local $4) - (get_global $../../examples/game-of-life/assembly/game-of-life/w) + (get_global $../../examples/game-of-life/assembly/index/w) ) (get_local $1) ) @@ -185,7 +185,7 @@ (i32.add (i32.mul (get_local $4) - (get_global $../../examples/game-of-life/assembly/game-of-life/w) + (get_global $../../examples/game-of-life/assembly/index/w) ) (get_local $7) ) @@ -197,7 +197,7 @@ (i32.add (i32.mul (get_local $0) - (get_global $../../examples/game-of-life/assembly/game-of-life/w) + (get_global $../../examples/game-of-life/assembly/index/w) ) (get_local $1) ) @@ -218,10 +218,10 @@ (i32.store8 (i32.add (i32.add - (get_global $../../examples/game-of-life/assembly/game-of-life/s) + (get_global $../../examples/game-of-life/assembly/index/s) (i32.mul (get_local $0) - (get_global $../../examples/game-of-life/assembly/game-of-life/w) + (get_global $../../examples/game-of-life/assembly/index/w) ) ) (get_local $1) @@ -237,10 +237,10 @@ (i32.store8 (i32.add (i32.add - (get_global $../../examples/game-of-life/assembly/game-of-life/s) + (get_global $../../examples/game-of-life/assembly/index/s) (i32.mul (get_local $0) - (get_global $../../examples/game-of-life/assembly/game-of-life/w) + (get_global $../../examples/game-of-life/assembly/index/w) ) ) (get_local $1) diff --git a/tests/compiler/game-of-life.ts b/tests/compiler/game-of-life.ts index 45fe9a3d..957a2761 100644 --- a/tests/compiler/game-of-life.ts +++ b/tests/compiler/game-of-life.ts @@ -1 +1 @@ -export { init, step } from "../../examples/game-of-life/assembly/game-of-life"; +export { init, step } from "../../examples/game-of-life/assembly/index"; diff --git a/tests/compiler/game-of-life.untouched.wat b/tests/compiler/game-of-life.untouched.wat index 748fcd11..a8e19ff0 100644 --- a/tests/compiler/game-of-life.untouched.wat +++ b/tests/compiler/game-of-life.untouched.wat @@ -1,29 +1,29 @@ (module (type $iiv (func (param i32 i32))) (type $v (func)) - (global $../../examples/game-of-life/assembly/game-of-life/w (mut i32) (i32.const 0)) - (global $../../examples/game-of-life/assembly/game-of-life/h (mut i32) (i32.const 0)) - (global $../../examples/game-of-life/assembly/game-of-life/s (mut i32) (i32.const 0)) + (global $../../examples/game-of-life/assembly/index/w (mut i32) (i32.const 0)) + (global $../../examples/game-of-life/assembly/index/h (mut i32) (i32.const 0)) + (global $../../examples/game-of-life/assembly/index/s (mut i32) (i32.const 0)) (global $HEAP_BASE i32 (i32.const 4)) (memory $0 1) - (export "init" (func $../../examples/game-of-life/assembly/game-of-life/init)) - (export "step" (func $../../examples/game-of-life/assembly/game-of-life/step)) + (export "init" (func $../../examples/game-of-life/assembly/index/init)) + (export "step" (func $../../examples/game-of-life/assembly/index/step)) (export "memory" (memory $0)) - (func $../../examples/game-of-life/assembly/game-of-life/init (; 0 ;) (type $iiv) (param $0 i32) (param $1 i32) - (set_global $../../examples/game-of-life/assembly/game-of-life/w + (func $../../examples/game-of-life/assembly/index/init (; 0 ;) (type $iiv) (param $0 i32) (param $1 i32) + (set_global $../../examples/game-of-life/assembly/index/w (get_local $0) ) - (set_global $../../examples/game-of-life/assembly/game-of-life/h + (set_global $../../examples/game-of-life/assembly/index/h (get_local $1) ) - (set_global $../../examples/game-of-life/assembly/game-of-life/s + (set_global $../../examples/game-of-life/assembly/index/s (i32.mul (get_local $0) (get_local $1) ) ) ) - (func $../../examples/game-of-life/assembly/game-of-life/step (; 1 ;) (type $v) + (func $../../examples/game-of-life/assembly/index/step (; 1 ;) (type $v) (local $0 i32) (local $1 i32) (local $2 i32) @@ -38,13 +38,13 @@ (block (set_local $0 (i32.sub - (get_global $../../examples/game-of-life/assembly/game-of-life/h) + (get_global $../../examples/game-of-life/assembly/index/h) (i32.const 1) ) ) (set_local $1 (i32.sub - (get_global $../../examples/game-of-life/assembly/game-of-life/w) + (get_global $../../examples/game-of-life/assembly/index/w) (i32.const 1) ) ) @@ -57,7 +57,7 @@ (if (i32.lt_s (get_local $2) - (get_global $../../examples/game-of-life/assembly/game-of-life/h) + (get_global $../../examples/game-of-life/assembly/index/h) ) (block (block @@ -97,7 +97,7 @@ (if (i32.lt_s (get_local $5) - (get_global $../../examples/game-of-life/assembly/game-of-life/w) + (get_global $../../examples/game-of-life/assembly/index/w) ) (block (block @@ -141,7 +141,7 @@ (i32.add (i32.mul (get_local $3) - (get_global $../../examples/game-of-life/assembly/game-of-life/w) + (get_global $../../examples/game-of-life/assembly/index/w) ) (get_local $6) ) @@ -150,7 +150,7 @@ (i32.add (i32.mul (get_local $3) - (get_global $../../examples/game-of-life/assembly/game-of-life/w) + (get_global $../../examples/game-of-life/assembly/index/w) ) (get_local $5) ) @@ -160,7 +160,7 @@ (i32.add (i32.mul (get_local $3) - (get_global $../../examples/game-of-life/assembly/game-of-life/w) + (get_global $../../examples/game-of-life/assembly/index/w) ) (get_local $7) ) @@ -170,7 +170,7 @@ (i32.add (i32.mul (get_local $2) - (get_global $../../examples/game-of-life/assembly/game-of-life/w) + (get_global $../../examples/game-of-life/assembly/index/w) ) (get_local $6) ) @@ -180,7 +180,7 @@ (i32.add (i32.mul (get_local $2) - (get_global $../../examples/game-of-life/assembly/game-of-life/w) + (get_global $../../examples/game-of-life/assembly/index/w) ) (get_local $7) ) @@ -190,7 +190,7 @@ (i32.add (i32.mul (get_local $4) - (get_global $../../examples/game-of-life/assembly/game-of-life/w) + (get_global $../../examples/game-of-life/assembly/index/w) ) (get_local $6) ) @@ -200,7 +200,7 @@ (i32.add (i32.mul (get_local $4) - (get_global $../../examples/game-of-life/assembly/game-of-life/w) + (get_global $../../examples/game-of-life/assembly/index/w) ) (get_local $5) ) @@ -210,7 +210,7 @@ (i32.add (i32.mul (get_local $4) - (get_global $../../examples/game-of-life/assembly/game-of-life/w) + (get_global $../../examples/game-of-life/assembly/index/w) ) (get_local $7) ) @@ -222,7 +222,7 @@ (i32.add (i32.mul (get_local $2) - (get_global $../../examples/game-of-life/assembly/game-of-life/w) + (get_global $../../examples/game-of-life/assembly/index/w) ) (get_local $5) ) @@ -255,10 +255,10 @@ (i32.store8 (i32.add (i32.add - (get_global $../../examples/game-of-life/assembly/game-of-life/s) + (get_global $../../examples/game-of-life/assembly/index/s) (i32.mul (get_local $2) - (get_global $../../examples/game-of-life/assembly/game-of-life/w) + (get_global $../../examples/game-of-life/assembly/index/w) ) ) (get_local $5) @@ -288,10 +288,10 @@ (i32.store8 (i32.add (i32.add - (get_global $../../examples/game-of-life/assembly/game-of-life/s) + (get_global $../../examples/game-of-life/assembly/index/s) (i32.mul (get_local $2) - (get_global $../../examples/game-of-life/assembly/game-of-life/w) + (get_global $../../examples/game-of-life/assembly/index/w) ) ) (get_local $5) diff --git a/tests/compiler/mandelbrot.optimized.wat b/tests/compiler/mandelbrot.optimized.wat new file mode 100644 index 00000000..de26b533 --- /dev/null +++ b/tests/compiler/mandelbrot.optimized.wat @@ -0,0 +1,196 @@ +(module + (type $iiiv (func (param i32 i32 i32))) + (memory $0 1) + (export "update" (func $../../examples/mandelbrot/assembly/index/update)) + (export "memory" (memory $0)) + (func $../../examples/mandelbrot/assembly/index/update (; 0 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 f64) + (local $4 f64) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 f64) + (local $9 f64) + (local $10 f64) + (local $11 f64) + (local $12 f64) + (local $13 f64) + (set_local $9 + (f64.div + (f64.convert_u/i32 + (get_local $0) + ) + (f64.const 1.6) + ) + ) + (set_local $10 + (f64.div + (f64.convert_u/i32 + (get_local $1) + ) + (f64.const 2) + ) + ) + (set_local $8 + (f64.div + (f64.const 4) + (f64.convert_u/i32 + (get_local $0) + ) + ) + ) + (loop $continue|0 + (if + (i32.lt_u + (get_local $5) + (get_local $1) + ) + (block + (set_local $11 + (f64.mul + (f64.sub + (f64.convert_u/i32 + (get_local $5) + ) + (get_local $10) + ) + (get_local $8) + ) + ) + (set_local $6 + (i32.const 0) + ) + (loop $continue|1 + (if + (i32.lt_u + (get_local $6) + (get_local $0) + ) + (block + (set_local $12 + (f64.mul + (f64.sub + (f64.convert_u/i32 + (get_local $6) + ) + (get_local $9) + ) + (get_local $8) + ) + ) + (set_local $7 + (i32.const 0) + ) + (block $break|2 + (set_local $3 + (f64.const 0) + ) + (set_local $4 + (f64.const 0) + ) + (loop $continue|2 + (if + (f64.le + (f64.add + (f64.mul + (get_local $3) + (get_local $3) + ) + (f64.mul + (get_local $4) + (get_local $4) + ) + ) + (f64.const 4) + ) + (block + (set_local $13 + (f64.add + (f64.sub + (f64.mul + (get_local $3) + (get_local $3) + ) + (f64.mul + (get_local $4) + (get_local $4) + ) + ) + (get_local $12) + ) + ) + (set_local $4 + (f64.add + (f64.mul + (f64.mul + (f64.const 2) + (get_local $3) + ) + (get_local $4) + ) + (get_local $11) + ) + ) + (set_local $3 + (get_local $13) + ) + (br_if $break|2 + (i32.ge_u + (tee_local $7 + (i32.add + (get_local $7) + (i32.const 1) + ) + ) + (get_local $2) + ) + ) + (set_local $7 + (i32.add + (get_local $7) + (i32.const 1) + ) + ) + (br $continue|2) + ) + ) + ) + ) + (i32.store8 + (i32.add + (i32.mul + (get_local $5) + (get_local $0) + ) + (get_local $6) + ) + (i32.div_u + (i32.mul + (get_local $7) + (i32.const 255) + ) + (get_local $2) + ) + ) + (set_local $6 + (i32.add + (get_local $6) + (i32.const 1) + ) + ) + (br $continue|1) + ) + ) + ) + (set_local $5 + (i32.add + (get_local $5) + (i32.const 1) + ) + ) + (br $continue|0) + ) + ) + ) + ) +) diff --git a/tests/compiler/mandelbrot.ts b/tests/compiler/mandelbrot.ts new file mode 100644 index 00000000..a6e0bc8c --- /dev/null +++ b/tests/compiler/mandelbrot.ts @@ -0,0 +1 @@ +export { update } from "../../examples/mandelbrot/assembly/index"; diff --git a/tests/compiler/mandelbrot.untouched.wat b/tests/compiler/mandelbrot.untouched.wat new file mode 100644 index 00000000..de0b2677 --- /dev/null +++ b/tests/compiler/mandelbrot.untouched.wat @@ -0,0 +1,213 @@ +(module + (type $iiiv (func (param i32 i32 i32))) + (global $HEAP_BASE i32 (i32.const 4)) + (memory $0 1) + (export "update" (func $../../examples/mandelbrot/assembly/index/update)) + (export "memory" (memory $0)) + (func $../../examples/mandelbrot/assembly/index/update (; 0 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 f64) + (local $4 f64) + (local $5 f64) + (local $6 i32) + (local $7 f64) + (local $8 i32) + (local $9 f64) + (local $10 i32) + (local $11 f64) + (local $12 f64) + (local $13 f64) + (set_local $3 + (f64.div + (f64.convert_u/i32 + (get_local $0) + ) + (f64.const 1.6) + ) + ) + (set_local $4 + (f64.div + (f64.convert_u/i32 + (get_local $1) + ) + (f64.const 2) + ) + ) + (set_local $5 + (f64.div + (f64.const 4) + (f64.convert_u/i32 + (get_local $0) + ) + ) + ) + (block $break|0 + (set_local $6 + (i32.const 0) + ) + (loop $continue|0 + (if + (i32.lt_u + (get_local $6) + (get_local $1) + ) + (block + (block + (set_local $7 + (f64.mul + (f64.sub + (f64.convert_u/i32 + (get_local $6) + ) + (get_local $4) + ) + (get_local $5) + ) + ) + (block $break|1 + (set_local $8 + (i32.const 0) + ) + (loop $continue|1 + (if + (i32.lt_u + (get_local $8) + (get_local $0) + ) + (block + (block + (set_local $9 + (f64.mul + (f64.sub + (f64.convert_u/i32 + (get_local $8) + ) + (get_local $3) + ) + (get_local $5) + ) + ) + (set_local $10 + (i32.const 0) + ) + (block $break|2 + (block + (set_local $11 + (f64.const 0) + ) + (set_local $12 + (f64.const 0) + ) + ) + (loop $continue|2 + (if + (f64.le + (f64.add + (f64.mul + (get_local $11) + (get_local $11) + ) + (f64.mul + (get_local $12) + (get_local $12) + ) + ) + (f64.const 4) + ) + (block + (block + (set_local $13 + (f64.add + (f64.sub + (f64.mul + (get_local $11) + (get_local $11) + ) + (f64.mul + (get_local $12) + (get_local $12) + ) + ) + (get_local $9) + ) + ) + (set_local $12 + (f64.add + (f64.mul + (f64.mul + (f64.const 2) + (get_local $11) + ) + (get_local $12) + ) + (get_local $7) + ) + ) + (set_local $11 + (get_local $13) + ) + (if + (i32.ge_u + (tee_local $10 + (i32.add + (get_local $10) + (i32.const 1) + ) + ) + (get_local $2) + ) + (br $break|2) + ) + ) + (set_local $10 + (i32.add + (get_local $10) + (i32.const 1) + ) + ) + (br $continue|2) + ) + ) + ) + ) + (i32.store8 + (i32.add + (i32.mul + (get_local $6) + (get_local $0) + ) + (get_local $8) + ) + (i32.div_u + (i32.mul + (get_local $10) + (i32.const 255) + ) + (get_local $2) + ) + ) + ) + (set_local $8 + (i32.add + (get_local $8) + (i32.const 1) + ) + ) + (br $continue|1) + ) + ) + ) + ) + ) + (set_local $6 + (i32.add + (get_local $6) + (i32.const 1) + ) + ) + (br $continue|0) + ) + ) + ) + ) + ) +)