Skip to content

Commit 074c23f

Browse files
committed
Merge remote-tracking branch 'origin/master' into release
2 parents 45347e6 + f93a262 commit 074c23f

File tree

10 files changed

+192
-38
lines changed

10 files changed

+192
-38
lines changed

.github/ISSUE_TEMPLATE.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<!--
2+
Thanks for submitting an issue to AssemblyScript! Please take a moment to
3+
read the contributing guidelines linked below to get off to a good start 🙂
4+
-->

.github/PULL_REQUEST_TEMPLATE.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!--
2+
Thanks for submitting a pull request to AssemblyScript! Please take a moment to
3+
review the contributing guidelines linked below, and confirm with an [x] 🙂
4+
-->
5+
6+
7+
8+
9+
10+
- [ ] I've read the contributing guidelines

CONTRIBUTING.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,20 @@ Submitting Pull Requests
3535

3636
Instructions are similar to those for bug reports. Please provide the following information:
3737

38+
* If this is not a trivial fix, consider **creating an issue to discuss first** and **later link to it from the PR**.
3839
* Use a **clear and descriptive title** for the pull request.
39-
* Provide a **description of the suggested changes** in as many details as necessary.
40+
* Provide a **description of the changes** in as many details as necessary.
4041
* **Document your new code** where necessary.
4142
* Please **refrain from refactoring (unrelated code)** as it makes your pull request easier to review.
4243
* **Create tests for your new code** where necessary. For creating or updating tests, please see the [Test Instructions](./tests).
4344

44-
Before submitting your pull request, please make sure that the following conditions are met:
45+
Before submitting your pull request, also make sure that the following conditions are met:
4546

4647
* Your new code **adheres to the code style** through running `npm run check`.
4748
* Your new code **passes all existing and new tests** through running `npm run test`.
4849
* Your PR **excludes distribution files** in `dist/**`.
4950
* You appended yourself to the **list of contributors** in the [NOTICE](./NOTICE) file.
51+
52+
Please note that if a pull request is rather complicated, i.e. touches lots of internals, or became stale, it is not uncommon that a core contributor performs the final integration to get it done in good conscience while naming you as a co-author.
53+
54+
Thank you!

NOTICE

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ under the licensing terms detailed in LICENSE:
2121
* Vladimir Tikhonov <[email protected]>
2222
* Duncan Uszkay <[email protected]>
2323
24+
* Julien Letellier <[email protected]>
2425

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

cli/asc.js

+19-12
Original file line numberDiff line numberDiff line change
@@ -207,20 +207,20 @@ exports.main = function main(argv, options, callback) {
207207
// Check for unknown arguments
208208
if (opts.unknown.length) {
209209
opts.unknown.forEach(arg => {
210-
stderr.write(colorsUtil.stderr.yellow("WARN: ") + "Unknown option '" + arg + "'" + EOL);
210+
stderr.write(colorsUtil.stderr.yellow("WARNING ") + "Unknown option '" + arg + "'" + EOL);
211211
});
212212
}
213213

214214
// Check for trailing arguments
215215
if (opts.trailing.length) {
216-
stderr.write(colorsUtil.stderr.yellow("WARN: ") + "Unsupported trailing arguments: " + opts.trailing.join(" ") + EOL);
216+
stderr.write(colorsUtil.stderr.yellow("WARNING ") + "Unsupported trailing arguments: " + opts.trailing.join(" ") + EOL);
217217
}
218218

219219
// Use default callback if none is provided
220220
if (!callback) callback = function defaultCallback(err) {
221221
var code = 0;
222222
if (err) {
223-
stderr.write(colorsUtil.stderr.red("ERROR: ") + err.stack.replace(/^ERROR: /i, "") + EOL);
223+
stderr.write(colorsUtil.stderr.red("FAILURE ") + err.stack.replace(/^ERROR: /i, "") + EOL);
224224
code = 1;
225225
}
226226
return code;
@@ -534,15 +534,20 @@ exports.main = function main(argv, options, callback) {
534534
var internalPath;
535535
while ((internalPath = assemblyscript.nextFile(program)) != null) {
536536
let file = getFile(internalPath, assemblyscript.getDependee(program, internalPath));
537-
if (!file) return callback(Error("Import '" + internalPath + "' not found."));
538-
stats.parseCount++;
539-
stats.parseTime += measure(() => {
540-
assemblyscript.parse(program, file.sourceText, file.sourcePath, false);
541-
});
537+
if (file) {
538+
stats.parseCount++;
539+
stats.parseTime += measure(() => {
540+
assemblyscript.parse(program, file.sourceText, file.sourcePath, false);
541+
});
542+
} else {
543+
assemblyscript.parse(program, null, internalPath + extension.ext, false);
544+
}
542545
}
543546
var numErrors = checkDiagnostics(program, stderr);
544547
if (numErrors) {
545-
return callback(Error(numErrors + " parse error(s)"));
548+
const err = Error(numErrors + " parse error(s)");
549+
err.stack = err.message; // omit stack
550+
return callback(err);
546551
}
547552
}
548553

@@ -577,8 +582,8 @@ exports.main = function main(argv, options, callback) {
577582
let sourceText = readFile(sourcePath + extension.ext, baseDir);
578583
if (sourceText == null) {
579584
sourceText = readFile(sourcePath + "/index" + extension.ext, baseDir);
580-
if (sourceText == null) return callback(Error("Entry file '" + sourcePath + extension.ext + "' not found."));
581-
sourcePath += "/index" + extension.ext;
585+
if (sourceText != null) sourcePath += "/index" + extension.ext;
586+
else sourcePath += extension.ext;
582587
} else {
583588
sourcePath += extension.ext;
584589
}
@@ -634,7 +639,9 @@ exports.main = function main(argv, options, callback) {
634639
var numErrors = checkDiagnostics(program, stderr);
635640
if (numErrors) {
636641
if (module) module.dispose();
637-
return callback(Error(numErrors + " compile error(s)"));
642+
const err = Error(numErrors + " compile error(s)");
643+
err.stack = err.message; // omit stack
644+
return callback(err);
638645
}
639646

640647
// Call afterCompile transform hook

src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ export function isError(message: DiagnosticMessage): bool {
214214
export function parse(
215215
/** Program reference. */
216216
program: Program,
217-
/** Source text of the file. */
218-
text: string,
217+
/** Source text of the file, or `null` to indicate not found. */
218+
text: string | null,
219219
/** Normalized path of the file. */
220220
path: string,
221221
/** Whether this is an entry file. */

src/parser.ts

+44-15
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ import {
8989
mangleInternalPath
9090
} from "./ast";
9191

92+
/** Represents a dependee. */
93+
class Dependee {
94+
constructor(
95+
public source: Source,
96+
public reportNode: Node
97+
) {}
98+
}
99+
92100
/** Parser interface. */
93101
export class Parser extends DiagnosticEmitter {
94102

@@ -102,8 +110,8 @@ export class Parser extends DiagnosticEmitter {
102110
onComment: CommentHandler | null = null;
103111
/** Current file being parsed. */
104112
currentSource: Source | null = null;
105-
/** Dependency map **/
106-
dependees: Map<string, Source> = new Map();
113+
/** Map of dependees being depended upon by a source, by path. */
114+
dependees: Map<string, Dependee> = new Map();
107115
/** An array of parsed sources. */
108116
sources: Source[];
109117

@@ -118,21 +126,37 @@ export class Parser extends DiagnosticEmitter {
118126

119127
/** Parses a file and adds its definitions to the program. */
120128
parseFile(
121-
/** Source text of the file. */
122-
text: string,
129+
/** Source text of the file, or `null` to indicate not found. */
130+
text: string | null,
123131
/** Normalized path of the file. */
124132
path: string,
125133
/** Whether this is an entry file. */
126134
isEntry: bool
127135
): void {
128136
// the frontend gives us paths with file extensions
129137
var normalizedPath = normalizePath(path);
130-
var internalPath = mangleInternalPath(normalizedPath);
138+
var internalPath = mangleInternalPath(path);
139+
131140
// check if already processed
132141
if (this.donelog.has(internalPath)) return;
133142
this.donelog.add(internalPath); // do not parse again
134143
this.seenlog.add(internalPath); // do not request again
135144

145+
// check if this is an error
146+
if (text === null) {
147+
let dependees = this.dependees;
148+
let dependee: Dependee | null = null;
149+
if (dependees.has(internalPath)) dependee = assert(dependees.get(internalPath));
150+
this.error(
151+
DiagnosticCode.File_0_not_found,
152+
dependee
153+
? dependee.reportNode.range
154+
: null,
155+
path
156+
);
157+
return;
158+
}
159+
136160
// create the source element
137161
var source = new Source(
138162
isEntry
@@ -402,10 +426,13 @@ export class Parser extends DiagnosticEmitter {
402426
return backlog.length ? assert(backlog.shift()) : null;
403427
}
404428

405-
/** Obtains the dependee of the given imported file. */
429+
/** Obtains the path of the dependee of the given imported file. */
406430
getDependee(dependent: string): string | null {
407-
var source = this.dependees.get(dependent);
408-
if (source) return source.internalPath;
431+
var dependees = this.dependees;
432+
if (dependees.has(dependent)) {
433+
let dependee = assert(dependees.get(dependent));
434+
return dependee.source.internalPath;
435+
}
409436
return null;
410437
}
411438

@@ -2447,11 +2474,13 @@ export class Parser extends DiagnosticEmitter {
24472474
}
24482475
}
24492476
let ret = Node.createExportStatement(members, path, isDeclare, tn.range(startPos, tn.pos));
2450-
let internalPath = ret.internalPath;
2451-
if (internalPath !== null && !this.seenlog.has(internalPath)) {
2452-
this.dependees.set(internalPath, currentSource);
2453-
this.backlog.push(internalPath);
2454-
this.seenlog.add(internalPath);
2477+
if (path !== null) {
2478+
let internalPath = assert(ret.internalPath);
2479+
if (!this.seenlog.has(internalPath)) {
2480+
this.dependees.set(internalPath, new Dependee(currentSource, path));
2481+
this.backlog.push(internalPath);
2482+
this.seenlog.add(internalPath);
2483+
}
24552484
}
24562485
tn.skip(Token.SEMICOLON);
24572486
return ret;
@@ -2466,7 +2495,7 @@ export class Parser extends DiagnosticEmitter {
24662495
if (!exportPaths) source.exportPaths = [ internalPath ];
24672496
else if (!exportPaths.includes(internalPath)) exportPaths.push(internalPath);
24682497
if (!this.seenlog.has(internalPath)) {
2469-
this.dependees.set(internalPath, currentSource);
2498+
this.dependees.set(internalPath, new Dependee(currentSource, path));
24702499
this.backlog.push(internalPath);
24712500
}
24722501
tn.skip(Token.SEMICOLON);
@@ -2638,7 +2667,7 @@ export class Parser extends DiagnosticEmitter {
26382667
}
26392668
let internalPath = ret.internalPath;
26402669
if (!this.seenlog.has(internalPath)) {
2641-
this.dependees.set(internalPath, assert(this.currentSource));
2670+
this.dependees.set(internalPath, new Dependee(assert(this.currentSource), path));
26422671
this.backlog.push(internalPath);
26432672
}
26442673
tn.skip(Token.SEMICOLON);

std/portable/index.d.ts

+45
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,48 @@ declare function unmanaged(constructor: Function): void;
303303

304304
/** Environmental tracing function. */
305305
declare function trace(msg: string, n?: i32, a0?: f64, a1?: f64, a2?: f64, a3?: f64, a4?: f64): void;
306+
307+
declare interface Int8ArrayConstructor {
308+
/** Equivalent to calling `new Int8Array` with multiple arguments. */
309+
wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): Int8Array;
310+
}
311+
312+
declare interface Uint8ArrayConstructor {
313+
/** Equivalent to calling `new Uint8Array` with multiple arguments. */
314+
wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): Uint8Array;
315+
}
316+
317+
declare interface Uint8ClampedArrayConstructor {
318+
/** Equivalent to calling `new Uint8ClampedArray` with multiple arguments. */
319+
wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): Uint8ClampedArray;
320+
}
321+
322+
declare interface Int16ArrayConstructor {
323+
/** Equivalent to calling `new Int16Array` with multiple arguments. */
324+
wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): Int16Array;
325+
}
326+
327+
declare interface Uint16ArrayConstructor {
328+
/** Equivalent to calling `new Uint16Array` with multiple arguments. */
329+
wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): Uint16Array;
330+
}
331+
332+
declare interface Int32ArrayConstructor {
333+
/** Equivalent to calling `new Int32Array` with multiple arguments. */
334+
wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): Int32Array;
335+
}
336+
337+
declare interface Uint32ArrayConstructor {
338+
/** Equivalent to calling `new Uint32Array` with multiple arguments. */
339+
wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): Uint32Array;
340+
}
341+
342+
declare interface Float32ArrayConstructor {
343+
/** Equivalent to calling `new Float32Array` with multiple arguments. */
344+
wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): Float32Array;
345+
}
346+
347+
declare interface Float64ArrayConstructor {
348+
/** Equivalent to calling `new Float64Array` with multiple arguments. */
349+
wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): Float64Array;
350+
}

std/portable/index.js

+54
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,57 @@ globalScope["trace"] = function(message, n) {
313313
if (n) message += Array.prototype.slice.call(arguments, 2, 2 + n);
314314
console.error("trace: " + message);
315315
};
316+
317+
Object.defineProperty(Int8Array, "wrap", {
318+
value: function wrap(buffer, byteOffset, length) {
319+
return new Int8Array(buffer, byteOffset, length);
320+
}
321+
});
322+
323+
Object.defineProperty(Uint8Array, "wrap", {
324+
value: function wrap(buffer, byteOffset, length) {
325+
return new Uint8Array(buffer, byteOffset, length);
326+
}
327+
});
328+
329+
Object.defineProperty(Uint8ClampedArray, "wrap", {
330+
value: function wrap(buffer, byteOffset, length) {
331+
return new Uint8ClampedArray(buffer, byteOffset, length);
332+
}
333+
});
334+
335+
Object.defineProperty(Int16Array, "wrap", {
336+
value: function wrap(buffer, byteOffset, length) {
337+
return new Int16Array(buffer, byteOffset, length);
338+
}
339+
});
340+
341+
Object.defineProperty(Uint16Array, "wrap", {
342+
value: function wrap(buffer, byteOffset, length) {
343+
return new Uint16Array(buffer, byteOffset, length);
344+
}
345+
});
346+
347+
Object.defineProperty(Int32Array, "wrap", {
348+
value: function wrap(buffer, byteOffset, length) {
349+
return new Int32Array(buffer, byteOffset, length);
350+
}
351+
});
352+
353+
Object.defineProperty(Uint32Array, "wrap", {
354+
value: function wrap(buffer, byteOffset, length) {
355+
return new Uint32Array(buffer, byteOffset, length);
356+
}
357+
});
358+
359+
Object.defineProperty(Float32Array, "wrap", {
360+
value: function wrap(buffer, byteOffset, length) {
361+
return new Float32Array(buffer, byteOffset, length);
362+
}
363+
});
364+
365+
Object.defineProperty(Float64Array, "wrap", {
366+
value: function wrap(buffer, byteOffset, length) {
367+
return new Float64Array(buffer, byteOffset, length);
368+
}
369+
});

tests/packages/packages/g/test.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
#!/usr/bin/env node
2-
let asc = require("../../../../cli/asc");
2+
const asc = require("../../../../cli/asc");
33

4-
let argv = [
4+
const stderr = asc.createMemoryStream();
5+
asc.main([
56
"assembly/index.ts",
67
"--noEmit",
78
"--runtime", "stub",
89
"--traceResolution"
9-
];
10-
11-
asc.main(argv, error => {
12-
if (/Import .*lib\/a.* not found/g.test(error.message)) {
10+
], { stderr }, err => {
11+
if (stderr.toString().includes("File '~lib/a.ts' not found.")) {
1312
process.exit(0);
1413
}
15-
console.error("Failed!\n" + error);
14+
console.error("Failed!\n" + err);
1615
process.exit(1);
1716
});

0 commit comments

Comments
 (0)