Skip to content

Commit 2df318a

Browse files
committed
Implicitly alias stdlib exports as program globals, see AssemblyScript#8
1 parent 3980e53 commit 2df318a

27 files changed

Lines changed: 417 additions & 179 deletions

package-lock.json

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
"@types/glob": "^5.0.34",
2222
"@types/long": "^3.0.32",
2323
"@types/minimist": "^1.2.0",
24-
"@types/node": "^8.5.2",
24+
"@types/node": "^8.5.8",
2525
"chalk": "^2.3.0",
2626
"diff": "^3.4.0",
2727
"long": "^3.2.0",
2828
"source-map-support": "^0.5.0",
2929
"ts-loader": "^3.2.0",
3030
"ts-node": "^4.1.0",
31-
"tslint": "^5.8.0",
31+
"tslint": "^5.9.1",
3232
"typescript": "^2.6.2",
3333
"webpack": "^3.10.0"
3434
},

src/ast.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,12 +1176,20 @@ export enum ModifierKind {
11761176
/** Base class of all statement nodes. */
11771177
export abstract class Statement extends Node { }
11781178

1179+
export enum SourceKind {
1180+
DEFAULT,
1181+
ENTRY,
1182+
STDLIB
1183+
}
1184+
11791185
/** A top-level source node. */
11801186
export class Source extends Node {
11811187

11821188
kind = NodeKind.SOURCE;
11831189
parent = null;
11841190

1191+
/** Source kind. */
1192+
sourceKind: SourceKind;
11851193
/** Path as provided to the parser. */
11861194
path: string;
11871195
/** Normalized path. */
@@ -1194,21 +1202,24 @@ export class Source extends Node {
11941202
text: string;
11951203
/** Tokenizer reference. */
11961204
tokenizer: Tokenizer | null = null;
1197-
/** Whether an entry file or not. */
1198-
isEntry: bool;
11991205

12001206
/** Constructs a new source node. */
1201-
constructor(path: string, text: string, isEntry: bool = false) {
1207+
constructor(path: string, text: string, kind: SourceKind = SourceKind.DEFAULT) {
12021208
super();
1209+
this.sourceKind = kind;
12031210
this.path = path;
12041211
this.normalizedPath = normalizePath(path, true);
12051212
this.internalPath = mangleInternalPath(this.normalizedPath);
12061213
this.statements = new Array();
12071214
this.range = new Range(this, 0, text.length);
12081215
this.text = text;
1209-
this.isEntry = isEntry;
12101216
}
12111217

1218+
/** Tests if this source is an entry file. */
1219+
get isEntry(): bool { return this.sourceKind == SourceKind.ENTRY; }
1220+
/** Tests if this source is a stdlib file. */
1221+
get isStdlib(): bool { return this.sourceKind == SourceKind.STDLIB; }
1222+
12121223
serialize(sb: string[]): void {
12131224
for (var i: i32 = 0, k: i32 = this.statements.length; i < k; ++i) {
12141225
this.statements[i].serialize(sb);
@@ -1236,6 +1247,8 @@ export abstract class DeclarationStatement extends Statement {
12361247

12371248
/** Gets the mangled internal name of this declaration. */
12381249
get internalName(): string { return this._cachedInternalName === null ? this._cachedInternalName = mangleInternalName(this) : this._cachedInternalName; }
1250+
/** Tests if this is a top-level declaration. */
1251+
get isTopLevel(): bool { return this.parent != null && this.parent.kind == NodeKind.SOURCE; }
12391252
}
12401253

12411254
/** Base class of all variable-like declaration statements with a type and initializer. */

0 commit comments

Comments
 (0)