Skip to content

Update examples for 0.10.0 #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ jobs:
- uses: dcodeIO/setup-node-nvm@master
with:
node-version: current
- run: |
- name: Test
run: |
cd game-of-life
npm install
npm run asbuild
Expand All @@ -26,7 +27,8 @@ jobs:
- uses: dcodeIO/setup-node-nvm@master
with:
node-version: current
- run: |
- name: Test
run: |
cd i64
npm install
npm run asbuild
Expand All @@ -38,7 +40,8 @@ jobs:
- uses: dcodeIO/setup-node-nvm@master
with:
node-version: current
- run: |
- name: Test
run: |
cd interference
npm install
npm run asbuild
Expand All @@ -49,7 +52,8 @@ jobs:
- uses: dcodeIO/setup-node-nvm@master
with:
node-version: current
- run: |
- name: Test
run: |
cd libm
npm install
npm run asbuild
Expand All @@ -61,7 +65,8 @@ jobs:
- uses: dcodeIO/setup-node-nvm@master
with:
node-version: current
- run: |
- name: Test
run: |
cd loader
npm install
npm run asbuild
Expand All @@ -73,7 +78,8 @@ jobs:
- uses: dcodeIO/setup-node-nvm@master
with:
node-version: current
- run: |
- name: Test
run: |
cd mandelbrot
npm install
npm run asbuild
Expand All @@ -84,7 +90,8 @@ jobs:
- uses: dcodeIO/setup-node-nvm@master
with:
node-version: current
- run: |
- name: Test
run: |
cd n-body
npm install
npm run asbuild
Expand All @@ -96,7 +103,8 @@ jobs:
- uses: dcodeIO/setup-node-nvm@master
with:
node-version: current
- run: |
- name: Test
run: |
cd transform
npm install
npm test
Binary file modified interference/build/optimized.wasm
Binary file not shown.
Binary file modified loader/build/optimized.wasm
Binary file not shown.
9 changes: 5 additions & 4 deletions loader/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require("fs");
const loader = require("@assemblyscript/loader");
const myModule = module.exports = loader.instantiateSync(fs.readFileSync(__dirname + "/build/optimized.wasm"),
const wasmModule = loader.instantiateSync(fs.readFileSync(__dirname + "/build/optimized.wasm"),

// These are the JavaScript imports to our WebAssembly module, translating
// from WebAssembly strings, received as a pointer into the module's memory,
Expand All @@ -9,14 +9,15 @@ const myModule = module.exports = loader.instantiateSync(fs.readFileSync(__dirna
// Example 3: Calling JavaScript imports with WebAssembly strings.
myConsole: {
log(messagePtr) { // Called as `console.log` in assembly/index.ts
console.log(myModule.__getString(messagePtr));
console.log(wasmModule.exports.__getString(messagePtr));
},
time(labelPtr) { // Called as `console.time` in assembly/index.ts
console.time(myModule.__getString(labelPtr));
console.time(wasmModule.exports.__getString(labelPtr));
},
timeEnd(labelPtr) { // Called as `console.timeEnd` in assembly/index.ts
console.timeEnd(myModule.__getString(labelPtr));
console.timeEnd(wasmModule.exports.__getString(labelPtr));
}
}
}
);
module.exports = wasmModule.exports;
Binary file modified n-body/build/as_nbody.wasm
Binary file not shown.
8 changes: 4 additions & 4 deletions n-body/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"license": "Apache-2.0",
"private": true,
"scripts": {
"asbuild:optimized": "asc assembly/index.ts -b build/as_nbody.wasm -t build/as_nbody.wat -O3 --runtime none --noAssert --importMemory",
"asbuild:asmjs": "asc assembly/index.ts -a build/as_nbody.asm.js -O3 --runtime none --noAssert && node scripts/postprocess-asmjs",
"asbuild": "npm run asbuild:optimized && npm run asbuild:asmjs",
"asbuild:wasm": "asc assembly/index.ts -b build/as_nbody.wasm -t build/as_nbody.wat -O3 --runtime none --noAssert --importMemory",
"asbuild:js": "asc assembly/index.ts -j build/as_nbody.js -O3 --runtime none --noAssert && node scripts/postprocess-js",
"asbuild": "npm run asbuild:wasm && npm run asbuild:js",
"tsbuild": "tsc -p assembly -t ES2017 -m commonjs --outDir build",
"rsbuild": "cd rust && RUSTFLAGS='-C link-arg=-s' cargo +nightly build --release",
"build": "npm run asbuild && npm run tsbuild && npm run rsbuild",
"start": "http-server . -o -c-1",
"test": "node --wasm-no-bounds-checks --wasm-no-stack-checks --expose-gc tests"
"test": "node --no-wasm-bounds-checks --no-wasm-stack-checks --expose-gc tests"
},
"devDependencies": {
"assemblyscript": "latest",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require("fs");
const path = require("path");

const filename = path.join(__dirname, "..", "build" , "as_nbody.asm.js");
const filename = path.join(__dirname, "..", "build" , "as_nbody.js");
var source = fs.readFileSync(filename, { encoding: "utf8" });
source = source.replace(/^export var ([^ ]+) =/mg, ($0, $1) => "exports." + $1 + " = ");
fs.writeFileSync(filename, source);
31 changes: 19 additions & 12 deletions n-body/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ const fs = require("fs");

// Load WASM version
const nbodyAS = require("../assembly/index.js");
const nbodyRS = require("../rust/index.js");
var nbodyRS;
try {
nbodyRS = require("../rust/index.js");
} catch (e) {}

// Load ASMJS version
var src = fs.readFileSync(__dirname + "/../build/as_nbody.asm.js", "utf8")
// Load JS version
var src = fs.readFileSync(__dirname + "/../build/as_nbody.js", "utf8")
.replace(/const retasmFunc[^$]*$/g, "");

const nbodyAsmJS = eval(src + ";asmFunc")({
const nbodyAS_JS = eval(src + ";asmFunc")({
Int8Array,
Int16Array,
Int32Array,
Expand Down Expand Up @@ -70,26 +73,30 @@ console.log("\nCOLD SERIES:\n");
prologue("AssemblyScript WASM", steps);
epilogue(test(nbodyAS, steps));

prologue("AssemblyScript ASMJS", steps);
epilogue(test(nbodyAsmJS, steps));
prologue("AssemblyScript JS", steps);
epilogue(test(nbodyAS_JS, steps));

prologue("JS", steps);
epilogue(test(nbodyJS, steps));

prologue("Rust WASM", steps);
epilogue(test(nbodyRS, steps));
if (nbodyRS) {
prologue("Rust WASM", steps);
epilogue(test(nbodyRS, steps));
}

console.log("\nWARMED UP SERIES:\n");
sleep(1000);

prologue("AssemblyScript WASM", steps);
epilogue(test(nbodyAS, steps));

prologue("AssemblyScript ASMJS", steps);
epilogue(test(nbodyAsmJS, steps));
prologue("AssemblyScript JS", steps);
epilogue(test(nbodyAS_JS, steps));

prologue("JS", steps);
epilogue(test(nbodyJS, steps));

prologue("Rust WASM", steps);
epilogue(test(nbodyRS, steps));
if (nbodyRS) {
prologue("Rust WASM", steps);
epilogue(test(nbodyRS, steps));
}
2 changes: 1 addition & 1 deletion transform/mytransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const binaryen = require("binaryen");
class MyTransform extends Transform {
afterParse(parser) {
this.log("[mytransform.js] afterParse called, baseDir = " + this.baseDir);
var sources = parser.program.sources;
var sources = this.program.sources;
sources.forEach(source => this.log(" " + source.internalPath + " [" + SourceKind[source.sourceKind] + "]"));
}
afterInitialize(program) {
Expand Down
2 changes: 1 addition & 1 deletion transform/mytransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as binaryen from "binaryen";
class MyTransform extends Transform {
afterParse(parser: Parser): void {
this.log("[mytransform.ts] afterParse called, baseDir = " + this.baseDir);
var sources = parser.program.sources;
var sources = this.program.sources;
sources.forEach(source => this.log(" " + source.internalPath + " [" + SourceKind[source.sourceKind] + "]"));
}
afterInitialize(program: Program) {
Expand Down