Skip to content

Commit 4924a53

Browse files
committed
feat: tests + runtime: update
now the runtime supports const and all the four basic operations, also the AST doesn't get recreated everytime (see Luna)
1 parent 434fe24 commit 4924a53

11 files changed

+2322
-24
lines changed

example/example.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
const startAeonRuntime = require("../runtime/start");
1+
const createAeonRuntime = require("../runtime/start");
22

33
// Compile the ./main.wat file with https://luna-demo.vercel.app
44
// Get the hex dump from either the middle div or the console
55

6-
// The below example
7-
// - exports aeonAddition
6+
// The below example
7+
// - exports addNumbers
88
// - takes two parameters (i32)
99
// - performs an addition (i32)
10-
const wasmBinary = new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 7, 1, 96, 2, 127, 127, 1, 127, 3, 2, 1, 0, 7, 18, 1, 14, 34, 97, 101, 111, 110, 65, 100, 100, 105, 116, 105, 111, 110, 34, 0, 0, 10, 9, 1, 7, 0, 32, 0, 32, 1, 106, 11]);
10+
const wasmBinary = new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 7, 1, 96, 2, 127, 127, 1, 127, 3, 2, 1, 0, 7, 16, 1, 12, 34, 97, 100, 100, 78, 117, 109, 98, 101, 114, 115, 34, 0, 0, 10, 9, 1, 7, 0, 32, 0, 32, 1, 106, 11]);
11+
12+
const runtime = createAeonRuntime(wasmBinary)
13+
const result = runtime("aeonAddition", 2, 3);
1114

12-
const result = startAeonRuntime(wasmBinary, "aeonAddition", 2, 3)
1315
console.log("Result", result) // prints 5

example/main.wat

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(module
2-
(func (export "aeonAddition") (param i32 i32) (result i32)
2+
(func (export "addNumbers") (param i32 i32) (result i32)
33
local.get 0
44
local.get 1
55
i32.add)

helpers/wasmSampleModules.js

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
const startAeonRuntime = require("./runtime/start");
1+
const createAeonRuntime = require("./runtime/start");
22

33
const wasmBinary = new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 8, 1, 96, 3, 127, 127, 127, 1, 127, 3, 2, 1, 0, 7, 16, 1, 12, 34, 97, 100, 100, 78, 117, 109, 98, 101, 114, 115, 34, 0, 0, 10, 9, 1, 7, 0, 32, 0, 32, 1, 32, 2, 106, 11]);
44

55
const n1 = 8;
66
const n2 = 20;
77
const n3 = 23;
88

9-
const result = startAeonRuntime(wasmBinary, "addNumbers", n1, n2, n3);
9+
const runtime = createAeonRuntime(wasmBinary);
10+
const result = runtime("addNumbers", n1, n2, n3);
1011
console.log(`${n1} + ${n2} + ${n3} =`, result)

package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1",
87
"start": "node index.js",
8+
"test": "jest",
99
"start:example": "node ./example/example.js"
1010
},
1111
"keywords": [],
1212
"author": "",
13-
"license": "ISC"
13+
"license": "ISC",
14+
"devDependencies": {
15+
"jest": "^29.3.1"
16+
}
1417
}

0 commit comments

Comments
 (0)