Skip to content

Commit b1478ee

Browse files
authored
Clean up portable memory definitions (#973)
1 parent e3105e8 commit b1478ee

File tree

12 files changed

+1573
-1693
lines changed

12 files changed

+1573
-1693
lines changed

cli/asc.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ var assemblyscript, isDev = false;
4949
try { // `require("dist/asc.js")` in explicit browser tests
5050
assemblyscript = eval("require('./assemblyscript')");
5151
} catch (e) {
52-
// combine both errors that lead us here
53-
e.message = e_ts.stack + "\n---\n" + e.stack;
54-
throw e;
52+
throw Error(e_ts.stack + "\n---\n" + e.stack);
5553
}
5654
}
5755
}
@@ -302,10 +300,13 @@ exports.main = function main(argv, options, callback) {
302300
var sourceText = null; // text reported back to the compiler
303301
var sourcePath = null; // path reported back to the compiler
304302

305-
// Try file.ts, file/index.ts
303+
// Try file.ts, file/index.ts, file.d.ts
306304
if (!internalPath.startsWith(exports.libraryPrefix)) {
307305
if ((sourceText = readFile(sourcePath = internalPath + ".ts", baseDir)) == null) {
308-
sourceText = readFile(sourcePath = internalPath + "/index.ts", baseDir);
306+
if ((sourceText = readFile(sourcePath = internalPath + "/index.ts", baseDir)) == null) {
307+
// portable d.ts: uses the .js file next to it in JS or becomes an import in Wasm
308+
sourceText = readFile(sourcePath = internalPath + ".d.ts", baseDir);
309+
}
309310
}
310311

311312
// Search library in this order: stdlib, custom lib dirs, paths

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"url": "https://github.com/AssemblyScript/assemblyscript/issues"
2222
},
2323
"dependencies": {
24-
"binaryen": "89.0.0-nightly.20191120",
24+
"binaryen": "89.0.0-nightly.20191204",
2525
"long": "^4.0.0",
2626
"source-map-support": "^0.5.16",
2727
"ts-node": "^6.2.0",

src/compiler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ export class Compiler extends DiagnosticEmitter {
330330
max(options.memoryBase, 8)
331331
);
332332
this.module = Module.create();
333-
var featureFlags: BinaryenFeatureFlags = 0;
333+
var featureFlags: FeatureFlags = 0;
334334
if (this.options.hasFeature(Feature.SIGN_EXTENSION)) featureFlags |= FeatureFlags.SignExt;
335335
if (this.options.hasFeature(Feature.MUTABLE_GLOBALS)) featureFlags |= FeatureFlags.MutableGloabls;
336336
if (this.options.hasFeature(Feature.NONTRAPPING_F2I)) featureFlags |= FeatureFlags.NontrappingFPToInt;

src/glue/binaryen.d.ts

Lines changed: 764 additions & 751 deletions
Large diffs are not rendered by default.

src/glue/binaryen.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const binaryen = global.Binaryen || require("binaryen");
2+
3+
module.exports = binaryen;
4+
5+
const { Module } = require("../module");
6+
7+
Module.prototype.toText = function() {
8+
// NOTE: Conversion to StackIR can yield conversion artifacts like sequences
9+
// of unreachable statements not actually emitted by the compiler. Optimizing
10+
// StackIR removes these again, but may also suppress useless code emitted by
11+
// the compiler that's then no longer visible in tests. Both not ideal.
12+
return binaryen.wrapModule(this.ref).emitStackIR(/* optimize-stack-ir */ true);
13+
};
14+
15+
Module.prototype.toAsmjs = function() {
16+
return binaryen.wrapModule(this.ref).emitAsmjs();
17+
};

src/glue/js/binaryen.d.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/glue/js/binaryen.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/glue/js/index.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,7 @@
44
* @preferred
55
*//***/
66

7-
import "./binaryen"; // must be first so portable can pick up the memory implementation
87
import "../../../std/portable/index";
8+
import "../binaryen";
99
import "./float";
1010
import "./i64";
11-
12-
import { Module } from "../../module";
13-
14-
Module.prototype.toText = function(this: Module) {
15-
// NOTE: Conversion to StackIR can yield conversion artifacts like sequences
16-
// of unreachable statements not actually emitted by the compiler. Optimizing
17-
// StackIR removes these again, but may also suppress useless code emitted by
18-
// the compiler that's then no longer visible in tests. Both not ideal.
19-
return binaryen.wrapModule(this.ref).emitStackIR(/* optimize-stack-ir */ true);
20-
};
21-
22-
Module.prototype.toAsmjs = function(this: Module) {
23-
return binaryen.wrapModule(this.ref).emitAsmjs();
24-
};

0 commit comments

Comments
 (0)