Skip to content

Commit 497366d

Browse files
author
Willem Wyndham
committed
Merge branch 'master' into lib/threading
2 parents afd7bb4 + 2fe228f commit 497366d

File tree

134 files changed

+47731
-10075
lines changed

Some content is hidden

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

134 files changed

+47731
-10075
lines changed

NOTICE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ under the licensing terms detailed in LICENSE:
1010
* Alan Pierce <[email protected]>
1111
1212
* Linus Unnebäck <[email protected]>
13+
* Joshua Tenner <[email protected]>
14+
* Nidin Vinayakan <[email protected]>
1315

1416
Portions of this software are derived from third-party works licensed under
1517
the following terms:

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ $> npm link
5757
Examples
5858
--------
5959

60-
* **[Conway's Game of Life](./examples/game-of-life)** [ [demo](https://rawgit.com/AssemblyScript/assemblyscript/master/examples/game-of-life/index.html) | [fiddle](https://webassembly.studio/?f=gvuw4enb3qk) ]<br />
60+
* **[Conway's Game of Life](./examples/game-of-life)** [ [demo](https://assemblyscript.github.io/assemblyscript/examples/game-of-life) | [fiddle](https://webassembly.studio/?f=gvuw4enb3qk) ]<br />
6161
Continuously updates the cellular automaton and visualizes its state on a canvas.
6262

63-
* **[Mandelbrot Set](./examples/mandelbrot)** [ [demo](https://rawgit.com/AssemblyScript/assemblyscript/master/examples/mandelbrot/index.html) | [fiddle](https://webassembly.studio/?f=m6hbiw9wyq) ]<br />
63+
* **[Mandelbrot Set](./examples/mandelbrot)** [ [demo](https://assemblyscript.github.io/assemblyscript/examples/mandelbrot) | [fiddle](https://webassembly.studio/?f=m6hbiw9wyq) ]<br />
6464
Renders the Mandelbrot set to a canvas.
6565

6666
* **[i64 polyfill](./examples/i64-polyfill)**<br />
@@ -72,7 +72,7 @@ Examples
7272
* **[WASM parser](./lib/parse)**<br />
7373
A WebAssembly binary parser in WebAssembly.
7474

75-
* **[N-body system](./examples/n-body)** [ [demo](https://rawgit.com/AssemblyScript/assemblyscript/master/examples/n-body/index.html) ]<br />
75+
* **[N-body system](./examples/n-body)** [ [demo](https://assemblyscript.github.io/assemblyscript/examples/n-body) ]<br />
7676
An implementation of the N-body system from the [Computer Language Benchmarks Game](https://benchmarksgame-team.pages.debian.net/benchmarksgame/).
7777

7878
Building

bin/asinit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const path = require("path");
44
const colors = require("../cli/util/colors");
55
const version = require("../package.json").version;
66

7-
if (process.argv.length < 3) printHelp();
7+
if (process.argv.length != 3 || process.argv[2] == "--help" || process.argv[2] == "-h") printHelp();
88

99
function printHelp() {
1010
console.log([

cli/asc.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ interface CompilerOptions {
5555
/** Standard error stream to use. */
5656
stderr?: OutputStream;
5757
/** Reads a file from disk (or memory). */
58-
readFile?: (name: string) => string | null;
58+
readFile?: (filename: string, baseDir: string) => string | null;
5959
/** Writes a file to disk (or memory). */
60-
writeFile?: (name: string, contents: Uint8Array) => void;
60+
writeFile?: (filename: string, contents: Uint8Array, baseDir: string) => void;
6161
/** Lists all files within a directory. */
62-
listFiles?: (dir: string) => string[] | null;
62+
listFiles?: (dirname: string, baseDir: string) => string[] | null;
6363
}
6464

6565
/** Convenience function that parses and compiles source strings directly. */

cli/asc.js

Lines changed: 58 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ exports.compileString = (sources, options) => {
9696
if (typeof sources === "string") sources = { "input.ts": sources };
9797
const output = Object.create({
9898
stdout: createMemoryStream(),
99-
stderr: createMemoryStream(),
100-
binary: null,
101-
text: null
99+
stderr: createMemoryStream()
102100
});
103101
var argv = [
104102
"--binaryFile", "binary",
@@ -270,7 +268,7 @@ exports.main = function main(argv, options, callback) {
270268
}
271269
for (let j = 0, l = libFiles.length; j < l; ++j) {
272270
let libPath = libFiles[j];
273-
let libText = readFile(path.join(libDir, libPath));
271+
let libText = readFile(libPath, libDir);
274272
if (libText === null) return callback(Error("Library file '" + libPath + "' not found."));
275273
stats.parseCount++;
276274
stats.parseTime += measure(() => {
@@ -285,33 +283,10 @@ exports.main = function main(argv, options, callback) {
285283
}
286284
}
287285

288-
// Include entry files
289-
for (let i = 0, k = argv.length; i < k; ++i) {
290-
const filename = argv[i];
291-
292-
let sourcePath = String(filename).replace(/\\/g, "/").replace(/(\.ts|\/)$/, "");
293-
294-
// Try entryPath.ts, then entryPath/index.ts
295-
let sourceText = readFile(path.join(baseDir, sourcePath) + ".ts");
296-
if (sourceText === null) {
297-
sourceText = readFile(path.join(baseDir, sourcePath, "index.ts"));
298-
if (sourceText === null) {
299-
return callback(Error("Entry file '" + sourcePath + ".ts' not found."));
300-
} else {
301-
sourcePath += "/index.ts";
302-
}
303-
} else {
304-
sourcePath += ".ts";
305-
}
306-
307-
stats.parseCount++;
308-
stats.parseTime += measure(() => {
309-
parser = assemblyscript.parseFile(sourceText, sourcePath, true, parser);
310-
});
311-
312-
// Process backlog
286+
// Parses the backlog of imported files after including entry files
287+
function parseBacklog() {
288+
var sourcePath, sourceText;
313289
while ((sourcePath = parser.nextFile()) != null) {
314-
let found = false;
315290

316291
// Load library file if explicitly requested
317292
if (sourcePath.startsWith(exports.libraryPrefix)) {
@@ -325,13 +300,12 @@ exports.main = function main(argv, options, callback) {
325300
sourcePath = exports.libraryPrefix + indexName + ".ts";
326301
} else {
327302
for (let i = 0, k = customLibDirs.length; i < k; ++i) {
328-
const dir = customLibDirs[i];
329-
sourceText = readFile(path.join(dir, plainName + ".ts"));
303+
sourceText = readFile(plainName + ".ts", customLibDirs[i]);
330304
if (sourceText !== null) {
331305
sourcePath = exports.libraryPrefix + plainName + ".ts";
332306
break;
333307
} else {
334-
sourceText = readFile(path.join(dir, indexName + ".ts"));
308+
sourceText = readFile(indexName + ".ts", customLibDirs[i]);
335309
if (sourceText !== null) {
336310
sourcePath = exports.libraryPrefix + indexName + ".ts";
337311
break;
@@ -344,11 +318,11 @@ exports.main = function main(argv, options, callback) {
344318
} else {
345319
const plainName = sourcePath;
346320
const indexName = sourcePath + "/index";
347-
sourceText = readFile(path.join(baseDir, plainName + ".ts"));
321+
sourceText = readFile(plainName + ".ts", baseDir);
348322
if (sourceText !== null) {
349323
sourcePath = plainName + ".ts";
350324
} else {
351-
sourceText = readFile(path.join(baseDir, indexName + ".ts"));
325+
sourceText = readFile(indexName + ".ts", baseDir);
352326
if (sourceText !== null) {
353327
sourcePath = indexName + ".ts";
354328
} else if (!plainName.startsWith(".")) {
@@ -361,12 +335,12 @@ exports.main = function main(argv, options, callback) {
361335
} else {
362336
for (let i = 0, k = customLibDirs.length; i < k; ++i) {
363337
const dir = customLibDirs[i];
364-
sourceText = readFile(path.join(dir, plainName + ".ts"));
338+
sourceText = readFile(plainName + ".ts", customLibDirs[i]);
365339
if (sourceText !== null) {
366340
sourcePath = exports.libraryPrefix + plainName + ".ts";
367341
break;
368342
} else {
369-
sourceText = readFile(path.join(dir, indexName + ".ts"));
343+
sourceText = readFile(indexName + ".ts", customLibDirs[i]);
370344
if (sourceText !== null) {
371345
sourcePath = exports.libraryPrefix + indexName + ".ts";
372346
break;
@@ -390,7 +364,38 @@ exports.main = function main(argv, options, callback) {
390364
}
391365
}
392366

367+
// Include entry files
368+
for (let i = 0, k = argv.length; i < k; ++i) {
369+
const filename = argv[i];
370+
371+
let sourcePath = String(filename).replace(/\\/g, "/").replace(/(\.ts|\/)$/, "");
372+
373+
// Try entryPath.ts, then entryPath/index.ts
374+
let sourceText = readFile(sourcePath + ".ts", baseDir);
375+
if (sourceText === null) {
376+
sourceText = readFile(sourcePath + "/index.ts", baseDir);
377+
if (sourceText === null) {
378+
return callback(Error("Entry file '" + sourcePath + ".ts' not found."));
379+
} else {
380+
sourcePath += "/index.ts";
381+
}
382+
} else {
383+
sourcePath += ".ts";
384+
}
385+
386+
stats.parseCount++;
387+
stats.parseTime += measure(() => {
388+
parser = assemblyscript.parseFile(sourceText, sourcePath, true, parser);
389+
});
390+
let code = parseBacklog();
391+
if (code) return code;
392+
}
393+
393394
applyTransform("afterParse", parser);
395+
{
396+
let code = parseBacklog();
397+
if (code) return code;
398+
}
394399

395400
// Finish parsing
396401
const program = assemblyscript.finishParsing(parser);
@@ -568,7 +573,7 @@ exports.main = function main(argv, options, callback) {
568573
});
569574

570575
if (args.binaryFile.length) {
571-
writeFile(path.join(baseDir, args.binaryFile), wasm.output);
576+
writeFile(args.binaryFile, wasm.output, baseDir);
572577
} else {
573578
writeStdout(wasm.output);
574579
hasStdout = true;
@@ -588,15 +593,12 @@ exports.main = function main(argv, options, callback) {
588593
text = exports.libraryFiles[stdName];
589594
} else {
590595
for (let i = 0, k = customLibDirs.length; i < k; ++i) {
591-
text = readFile(path.join(
592-
customLibDirs[i],
593-
name.substring(exports.libraryPrefix.length))
594-
);
596+
text = readFile(name.substring(exports.libraryPrefix.length), customLibDirs[i]);
595597
if (text !== null) break;
596598
}
597599
}
598600
} else {
599-
text = readFile(path.join(baseDir, name));
601+
text = readFile(name, baseDir);
600602
}
601603
if (text === null) {
602604
return callback(Error("Source file '" + name + "' not found."));
@@ -605,10 +607,9 @@ exports.main = function main(argv, options, callback) {
605607
sourceMap.sourceContents[index] = text;
606608
});
607609
writeFile(path.join(
608-
baseDir,
609610
path.dirname(args.binaryFile),
610611
path.basename(sourceMapURL)
611-
), JSON.stringify(sourceMap));
612+
).replace(/^\.\//, ""), JSON.stringify(sourceMap), baseDir);
612613
} else {
613614
stderr.write("Skipped source map (stdout already occupied)" + EOL);
614615
}
@@ -623,7 +624,7 @@ exports.main = function main(argv, options, callback) {
623624
stats.emitTime += measure(() => {
624625
asm = module.toAsmjs();
625626
});
626-
writeFile(path.join(baseDir, args.asmjsFile), asm);
627+
writeFile(args.asmjsFile, asm, baseDir);
627628
} else if (!hasStdout) {
628629
stats.emitCount++;
629630
stats.emitTime += measure(() => {
@@ -643,7 +644,7 @@ exports.main = function main(argv, options, callback) {
643644
stats.emitTime += measure(() => {
644645
idl = assemblyscript.buildIDL(program);
645646
});
646-
writeFile(path.join(baseDir, args.idlFile), idl);
647+
writeFile(args.idlFile, idl, baseDir);
647648
} else if (!hasStdout) {
648649
stats.emitCount++;
649650
stats.emitTime += measure(() => {
@@ -663,7 +664,7 @@ exports.main = function main(argv, options, callback) {
663664
stats.emitTime += measure(() => {
664665
tsd = assemblyscript.buildTSD(program);
665666
});
666-
writeFile(path.join(baseDir, args.tsdFile), tsd);
667+
writeFile(args.tsdFile, tsd, baseDir);
667668
} else if (!hasStdout) {
668669
stats.emitCount++;
669670
stats.emitTime += measure(() => {
@@ -683,7 +684,7 @@ exports.main = function main(argv, options, callback) {
683684
stats.emitTime += measure(() => {
684685
wat = module.toText();
685686
});
686-
writeFile(path.join(baseDir, args.textFile), wat);
687+
writeFile(args.textFile, wat, baseDir);
687688
} else if (!hasStdout) {
688689
stats.emitCount++;
689690
stats.emitTime += measure(() => {
@@ -700,28 +701,28 @@ exports.main = function main(argv, options, callback) {
700701
}
701702
return callback(null);
702703

703-
function readFileNode(filename) {
704+
function readFileNode(filename, baseDir) {
704705
try {
705706
let text;
706707
stats.readCount++;
707708
stats.readTime += measure(() => {
708-
text = fs.readFileSync(filename, { encoding: "utf8" });
709+
text = fs.readFileSync(path.join(baseDir, filename), { encoding: "utf8" });
709710
});
710711
return text;
711712
} catch (e) {
712713
return null;
713714
}
714715
}
715716

716-
function writeFileNode(filename, contents) {
717+
function writeFileNode(filename, contents, baseDir) {
717718
try {
718719
stats.writeCount++;
719720
stats.writeTime += measure(() => {
720-
mkdirp(path.dirname(filename));
721+
mkdirp(path.join(baseDir, path.dirname(filename)));
721722
if (typeof contents === "string") {
722-
fs.writeFileSync(filename, contents, { encoding: "utf8" } );
723+
fs.writeFileSync(path.join(baseDir, filename), contents, { encoding: "utf8" } );
723724
} else {
724-
fs.writeFileSync(filename, contents);
725+
fs.writeFileSync(path.join(baseDir, filename), contents);
725726
}
726727
});
727728
return true;
@@ -730,11 +731,11 @@ exports.main = function main(argv, options, callback) {
730731
}
731732
}
732733

733-
function listFilesNode(dirname) {
734+
function listFilesNode(dirname, baseDir) {
734735
var files;
735736
try {
736737
stats.readTime += measure(() => {
737-
files = fs.readdirSync(dirname).filter(file => /^(?!.*\.d\.ts$).*\.ts$/.test(file));
738+
files = fs.readdirSync(path.join(baseDir, dirname)).filter(file => /^(?!.*\.d\.ts$).*\.ts$/.test(file));
738739
});
739740
return files;
740741
} catch (e) {

dist/asc.js

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

dist/asc.js.map

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

dist/assemblyscript.js

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

dist/assemblyscript.js.map

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
-27 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)