Skip to content

Commit

Permalink
updating adder example
Browse files Browse the repository at this point in the history
  • Loading branch information
dfirebaugh committed Jan 31, 2024
1 parent 4990e83 commit 93a82c5
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 67 deletions.
4 changes: 2 additions & 2 deletions examples/adder/adder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const fs = require('node:fs');
const wasmBuffer = fs.readFileSync('./adder.wasm');
WebAssembly.instantiate(wasmBuffer).then(wasmModule => {
const { add_two, add_four } = wasmModule.instance.exports;
const sum = add_four(5, 6, 2, 4);
const sum2 = add_two(5, 6);
const sum = add_four(1,1,1+2-2,1);
const sum2 = add_two(2, 20);
console.log(sum);
console.log(sum2);
});
Expand Down
4 changes: 2 additions & 2 deletions examples/adder/adder.pn
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ pub i32 add_two(i32 x, i32 y) {
}

pub i32 add_four(i32 a, i32 b, i32 c, i32 d) {
if 1 != 1 {
return a - b - c - d
if !is_eq(a, 2) {
return (a - b - c - d)
}
return a + b + c + d
}
49 changes: 0 additions & 49 deletions examples/adder/main.go

This file was deleted.

15 changes: 1 addition & 14 deletions examples/adder/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,8 @@

build adder wasm

(ran from the root of this project)

```bash
punch build -o ./examples/adder/adder ./examples/adder/adder.pn
```

This should output a `adder.wat` and an `adder.wasm` file.

`./examples/adder/main.go` is a go program that can load up the `adder.wasm` file and run the functions it contains.

```bash
go run ./examples/adder/main.go
```

```bash
cd ./examples/adders/
punch build -o ./adder ./adder.pn
node adder.js
```

0 comments on commit 93a82c5

Please sign in to comment.