-
Notifications
You must be signed in to change notification settings - Fork 0
/
layout.js
45 lines (33 loc) · 1.21 KB
/
layout.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
"use strict";
const path = require("path");
const fs = require("fs");
const asc = require("assemblyscript/cli/asc");
const loader = require("assemblyscript/lib/loader");
const wamem = require("./build/Release/wamem");
// https://www.assemblyscript.org/memory.html#internals
main();
async function main() {
await asc.ready;
wamem.setupTrap();
console.time("compileString");
const script = fs.readFileSync(path.join(__dirname, "layout.as"), "utf-8");
console.timeEnd("compileString");
const reservation = 512 * 1024 * 1024;
const { binary } = asc.compileString(script, {
optimize: 2,
exportRuntime: true,
importMemory: true,
memoryBase: reservation, // at COMPILE time
});
const memory = wamem.createMemory(reservation);
const bufferSize = memory.buffer.byteLength;
console.log("bufferSize", bufferSize);
console.time("instantiate");
const module = await loader.instantiate(binary, { env: { memory } });
console.timeEnd("instantiate");
const { staticString, newArray, __heap_base } = module.exports;
console.log(Object.keys(module.exports));
console.log("staticString", staticString.value);
console.log("newArray", newArray());
console.log("__heap_base", __heap_base);
}