diff --git a/README.md b/README.md index 556d22ee..f31c86c8 100644 --- a/README.md +++ b/README.md @@ -80,3 +80,5 @@ Options: --noTreeShaking Disables tree-shaking. --noDebug Disables assertions. ``` + +Unless a bundle has been built to `dist/`, `asc` runs the TypeScript sources directly via [ts-node](https://www.npmjs.com/package/ts-node). Useful for development. diff --git a/package-lock.json b/package-lock.json index 965b728d..4b2b8320 100644 --- a/package-lock.json +++ b/package-lock.json @@ -216,9 +216,9 @@ "dev": true }, "binaryen": { - "version": "39.0.0-nightly.20171205", - "resolved": "https://registry.npmjs.org/binaryen/-/binaryen-39.0.0-nightly.20171205.tgz", - "integrity": "sha512-OYyWKbtGCSjfX1mTmwMfTANC+trKmEIOOfAMbqjJzU+qmEFCt942kIn+6+3sNeuehLLuPeXrEOq1JxKnKVdizg==" + "version": "40.0.0-nightly.20171209", + "resolved": "https://registry.npmjs.org/binaryen/-/binaryen-40.0.0-nightly.20171209.tgz", + "integrity": "sha512-ELe79ZuH6dPLo+j3tbTvGl9BagzUTtIuYlY3LWz1kj5JzgpqeZmUweay1vK6MZo7J/1IA7Sgda4J7vxUhNu03Q==" }, "bn.js": { "version": "4.11.8", diff --git a/package.json b/package.json index cae59267..a069f827 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ }, "dependencies": { "@types/node": "^8.0.54", - "binaryen": "39.0.0-nightly.20171205", + "binaryen": "40.0.0-nightly.20171209", "minimist": "^1.2.0", "source-map-support": "^0.5.0" }, diff --git a/portable-assembly.d.ts b/portable-assembly.d.ts index 5f1f102d..e4fe5a76 100644 --- a/portable-assembly.d.ts +++ b/portable-assembly.d.ts @@ -23,7 +23,7 @@ declare type bool = boolean; // Portable built-ins -/** Performs the sign-agnostic count leading zero bits operation on a 32-bit or 64-bit integer. All zero bits are considered leading if the value is zero. */ +/** Performs the sign-agnostic count leading zero bits operation on a 32-bit integer. All zero bits are considered leading if the value is zero. */ declare function clz(value: T): T; /** Computes the absolute value of an integer or float. */ declare function abs(value: T): T; diff --git a/src/compiler.ts b/src/compiler.ts index 9fff4bc8..47990362 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -1707,7 +1707,7 @@ export class Compiler extends DiagnosticEmitter { case LiteralKind.FLOAT: { const floatValue: f64 = (expression).value; if (contextualType == Type.f32) - return this.module.createF32(Math.fround(floatValue)); + return this.module.createF32(floatValue); this.currentType = Type.f64; return this.module.createF64(floatValue); } diff --git a/src/types.ts b/src/types.ts index b28aa58e..e70eaa96 100644 --- a/src/types.ts +++ b/src/types.ts @@ -37,7 +37,7 @@ export class Type { constructor(kind: TypeKind, size: i32) { this.kind = kind; this.size = size; - this.byteSize = Math.ceil(size / 8); + this.byteSize = ceil(size / 8); this.classType = null; } diff --git a/tests/compiler/game-of-life.html b/tests/compiler/game-of-life.html index 12ff57b0..198b62ee 100644 --- a/tests/compiler/game-of-life.html +++ b/tests/compiler/game-of-life.html @@ -5,13 +5,11 @@ fetch("game-of-life.optimized.wast").then(response => response.text()).then(text => { // Convert it to binary format - var buffer = Binaryen.parseText(text).emitBinary(); + var binary = Binaryen.parseText(text).emitBinary(); // Instantiate the module - return WebAssembly.instantiate(buffer, {}); - -}).then(result => { - var module = result.instance; + var module = new WebAssembly.Module(binary); + var instance = new WebAssembly.Instance(module, { /* no imports */ }); // Set up the canvas with a 2D rendering context var cnv = document.getElementById("canvas"); @@ -22,28 +20,28 @@ fetch("game-of-life.optimized.wast").then(response => response.text()).then(text S = s + s; // total memory required to store input and output // Grow the (exported) memory if it's size isn't sufficient - var memory = module.exports.memory; + var memory = instance.exports.memory; if (memory.buffer.byteLength < S) memory.grow(Math.ceil((S - memory.buffer.byteLength) / 65536)); + // Initialize with width and height + instance.exports.init(w, h); + // Fill input at [0, s-1] with random cells var mem = new Uint8Array(memory.buffer); for (var y = 0; y < h; ++y) for (var x = 0; x < w; ++x) mem[y * w + x] = Math.random() > 0.1 ? 0 : 1; - // Initialize with width and height - module.exports.init(w, h); - // Update about 30 times a second - function update() { + (function update() { setTimeout(update, 33); - module.exports.step(); + instance.exports.step(); mem.set(mem.subarray(s, S), 0); // copy output -> input - } + })(); // Keep rendering the output at [s, 2*s-1] - function render() { + (function render() { requestAnimationFrame(render); ctx.clearRect(0, 0, w, h); ctx.fillStyle = "#333"; @@ -51,10 +49,7 @@ fetch("game-of-life.optimized.wast").then(response => response.text()).then(text for (var x = 0; x < w; ++x) if (mem[s + y * w + x]) ctx.fillRect(x, y, 1, 1); - } - - update(); - render(); + })(); }).catch(err => { throw err;