Skip to content

Commit 4736227

Browse files
committed
Update binaryen to latest nightly; Source map support
1 parent a8da044 commit 4736227

File tree

120 files changed

+23849
-1959
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+23849
-1959
lines changed

bin/asc.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ try {
1717
assemblyscript = require("../src");
1818
}
1919

20+
const SOURCEMAP_ROOT = "assemblyscript:///";
21+
const LIBRARY_PREFIX = assemblyscript.LIBRARY_PREFIX;
22+
2023
const conf = require("./asc.json");
2124
const opts = {};
2225

@@ -126,7 +129,7 @@ libDirs.forEach(libDir => {
126129
var nextText = fs.readFileSync(path.join(libDir, file), { encoding: "utf8" });
127130
++readCount;
128131
var time = measure(() => {
129-
parser = assemblyscript.parseFile(nextText, ".std/" + file, parser, false);
132+
parser = assemblyscript.parseFile(nextText, LIBRARY_PREFIX + file, parser, false);
130133
});
131134
parseTime += time;
132135
notIoTime += time;
@@ -170,7 +173,7 @@ args._.forEach(filename => {
170173

171174
while ((nextFile = parser.nextFile()) != null) {
172175
var found = false;
173-
if (nextFile.startsWith(".std/")) {
176+
if (nextFile.startsWith(LIBRARY_PREFIX)) {
174177
for (var i = 0; i < libDirs.length; ++i) {
175178
readTime += measure(() => {
176179
try {
@@ -311,15 +314,17 @@ if (runPasses.length)
311314

312315
function processSourceMap(sourceMap, sourceMapURL) {
313316
var json = JSON.parse(sourceMap);
314-
return SourceMapConsumer.with(sourceMap, sourceMapURL, consumer => {
317+
json.sources = json.sources.map(name => SOURCEMAP_ROOT + name);
318+
var libPrefix = SOURCEMAP_ROOT + LIBRARY_PREFIX;
319+
return SourceMapConsumer.with(json, sourceMapURL, consumer => {
315320
var generator = SourceMapGenerator.fromSourceMap(consumer);
316321
json.sources.forEach(name => {
317322
var text, found = false;
318-
if (name.startsWith(".std/")) {
323+
if (name.startsWith(libPrefix)) {
319324
for (var i = 0, k = libDirs.length; i < k; ++i) {
320325
readTime += measure(() => {
321326
try {
322-
text = fs.readFileSync(path.join(libDirs[i], name.substring(4)), { encoding: "utf8" });
327+
text = fs.readFileSync(path.join(libDirs[i], name.substring(libPrefix.length)), { encoding: "utf8" });
323328
found = true;
324329
} catch (e) {}
325330
});
@@ -328,15 +333,16 @@ function processSourceMap(sourceMap, sourceMapURL) {
328333
} else {
329334
readTime += measure(() => {
330335
try {
331-
text = fs.readFileSync(name, { encoding: "utf8" });
336+
text = fs.readFileSync(name.substring(SOURCEMAP_ROOT.length), { encoding: "utf8" });
332337
found = true;
333338
} catch (e) {}
334339
});
335340
++readCount;
336341
}
337-
if (found)
342+
if (found) {
338343
generator.setSourceContent(name, text);
339-
else
344+
console.log(name + " ???");
345+
} else
340346
console.error("No source content found for file '" + name + "'.");
341347
});
342348
return generator.toString();
@@ -362,7 +368,7 @@ if (!args.noEmit) {
362368
: null;
363369
var binary;
364370
writeTime += measure(() => {
365-
binary = module.toBinary(sourceMapURL); // FIXME: 'not a valid URL' in FF
371+
binary = module.toBinary("http://127.0.0.1:8080/"+sourceMapURL); // FIXME: 'not a valid URL' in FF
366372
fs.writeFileSync(args.binaryFile, binary.output);
367373
});
368374
++writeCount;

examples/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
*.wast
22
*.wasm
3+
*.wasm.map
34
node_modules/
45
npm-debug.log
56
package-lock.json

examples/game-of-life/game-of-life.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
// Instantiate the module
77
var module = new WebAssembly.Module(binary);
8-
var instance = new WebAssembly.Instance(module, { /* no imports */ });
8+
var instance = new WebAssembly.Instance(module, { env: { abort: function() {} } });
99

1010
// Set up the canvas with a 2D rendering context
1111
var cnv = document.getElementById("canvas");

examples/game-of-life/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"private": true,
55
"scripts": {
66
"build": "npm run build:untouched && npm run build:optimized",
7-
"build:untouched": "asc assembly/game-of-life.ts -b game-of-life.untouched.wasm -t game-of-life.untouched.wast --validate",
8-
"build:optimized": "asc -O assembly/game-of-life.ts -b game-of-life.optimized.wasm -t game-of-life.optimized.wast --validate",
7+
"build:untouched": "asc assembly/game-of-life.ts -b game-of-life.untouched.wasm -t game-of-life.untouched.wast --validate --sourceMap --measure",
8+
"build:optimized": "asc -O assembly/game-of-life.ts -b game-of-life.optimized.wasm -t game-of-life.optimized.wast --validate --sourceMap --measure",
99
"browser": "game-of-life.html"
1010
}
1111
}

examples/i64-polyfill/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
},
1818
"scripts": {
1919
"build": "npm run build:untouched && npm run build:optimized",
20-
"build:untouched": "asc assembly/i64.ts -t i64.untouched.wast -b i64.untouched.wasm --noMemory --validate",
21-
"build:optimized": "asc -O assembly/i64.ts -b i64.optimized.wasm -t i64.optimized.wast --noMemory --validate",
20+
"build:untouched": "asc assembly/i64.ts -t i64.untouched.wast -b i64.untouched.wasm --noMemory --validate --sourceMap --measure",
21+
"build:optimized": "asc -O assembly/i64.ts -b i64.optimized.wasm -t i64.optimized.wast --noMemory --validate --sourceMap --measure",
2222
"test": "node tests"
2323
},
2424
"files": [

examples/pson/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"private": true,
55
"scripts": {
66
"build": "npm run build:untouched && npm run build:optimized",
7-
"build:untouched": "asc assembly/pson.ts -b pson.untouched.wasm -t pson.untouched.wast --validate",
8-
"build:optimized": "asc -O assembly/pson.ts -b pson.optimized.wasm -t pson.optimized.wast --validate",
7+
"build:untouched": "asc assembly/pson.ts -b pson.untouched.wasm -t pson.untouched.wast --validate --sourceMap --measure",
8+
"build:optimized": "asc -O assembly/pson.ts -b pson.optimized.wasm -t pson.optimized.wast --validate --sourceMap --measure",
99
"test": "node tests"
1010
},
1111
"devDependencies": {

examples/tlsf/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
![](https://s.gravatar.com/avatar/f105de3decfafc734b8eabe9a960b25d?size=48) TLSF
22
=================
33

4-
An implementation of the [Two Level Segregate Fit](http://www.gii.upv.es/tlsf/main/docs)
5-
memory allocator in AssemblyScript.
4+
An implementation of the [Two Level Segregate Fit](http://www.gii.upv.es/tlsf/main/docs) memory allocator in AssemblyScript.
65

76
Instructions
87
------------

examples/ugc/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"private": true,
55
"scripts": {
66
"build": "npm run build:untouched && npm run build:optimized",
7-
"build:untouched": "asc assembly/ugc.ts -t ugc.untouched.wast -b ugc.untouched.wasm --validate",
8-
"build:optimized": "asc -O3 assembly/ugc.ts -b ugc.optimized.wasm -t ugc.optimized.wast --validate --noDebug --noAssert",
7+
"build:untouched": "asc assembly/ugc.ts -t ugc.untouched.wast -b ugc.untouched.wasm --validate --sourceMap --measure",
8+
"build:optimized": "asc -O3 assembly/ugc.ts -b ugc.optimized.wasm -t ugc.optimized.wast --validate --noDebug --noAssert --sourceMap --measure",
99
"test": "node tests"
1010
}
1111
}

lib/utils/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![](https://s.gravatar.com/avatar/f105de3decfafc734b8eabe9a960b25d?size=64) utils
1+
![](https://s.gravatar.com/avatar/f105de3decfafc734b8eabe9a960b25d?size=48) utils
22
=================
33

44
Utilities for working with [AssemblyScript](http://assemblyscript.org) modules.

lib/webpack/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![](https://s.gravatar.com/avatar/f105de3decfafc734b8eabe9a960b25d?size=64) webpack
1+
![](https://s.gravatar.com/avatar/f105de3decfafc734b8eabe9a960b25d?size=48) webpack
22
=================
33

44
[webpack](https://webpack.js.org/) loader for [AssemblyScript](http://assemblyscript.org) modules.
@@ -7,9 +7,9 @@ Usage
77
-----
88

99
```js
10-
import Module from "@assemblyscript/webpack!module.wasm";
10+
import MyModule from "@assemblyscript/webpack!mymodule.wasm";
1111

12-
var myModule = Module({ imports: { ... }});
12+
var myModule = new MyModule({ imports: { /* if any */ } });
1313
```
1414

15-
TODO: Wire .ts files to the compiler API, accepting options, but also keep raw .wasm support.
15+
TODO: Pipe .ts files through `asc`, accepting the usual options, but also keep raw .wasm support.

lib/webpack/decode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
var s64 = new Array(123);
33
for (var i = 0; i < 64;) s64[i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i - 59 | 43] = i++;
44

5-
module.exports = function(string) {
5+
module.exports = function decode(string) {
66

77
// determine buffer length
88
var length = string.length;

lib/webpack/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ function loader(buffer) {
44
var data = base64.encode(buffer, 0, buffer.length);
55
var code = [
66
'var data = "' + data + '", wasm;',
7-
'module.exports = function(options) {',
8-
' if (!wasm) wasm = require("@assemblyscript/webpack/decode")(data);',
9-
' return new WebAssembly.Instance(new WebAssembly.Module(wasm), options && options.imports || {}).exports;',
7+
'module.exports = function AssemblyScriptModule(options) {',
8+
' if (!wasm)',
9+
' wasm = new WebAssembly.Module(require("@assemblyscript/webpack/decode")(data));',
10+
' return new WebAssembly.Instance(wasm, options && options.imports || {}).exports;',
1011
'};'
1112
];
1213
return code.join("\n") + "\n";

0 commit comments

Comments
 (0)