-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
49 lines (38 loc) · 828 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const fs = require("fs");
const loader = require("@assemblyscript/loader");
function importCallback(a, b) {
return a + b;
}
const imports = {
test: {
importCallback,
},
};
const wasmModule = loader.instantiateSync(
fs.readFileSync(__dirname + "/build/optimized.wasm"),
imports
);
function squareArrayWrap(array) {
const {
__newArray,
__getInt32Array,
Int32Array_ID,
squareArray,
} = wasmModule.exports;
const arr = __newArray(Int32Array_ID, array);
const result = __getInt32Array(squareArray(arr));
return result;
}
function calcSinLookupWrap() {
const {
__getFloat64Array,
calcSinLookup,
} = wasmModule.exports;
return __getFloat64Array(calcSinLookup());
}
module.exports = {
...wasmModule.exports,
squareArrayWrap,
calcSinLookupWrap,
importCallback,
};