Skip to content

Commit 465f995

Browse files
authored
Implement virtual overloading / interfaces (#1208)
1 parent d673417 commit 465f995

File tree

76 files changed

+6216
-2476
lines changed

Some content is hidden

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

76 files changed

+6216
-2476
lines changed

cli/asc.js

+34-41
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,10 @@ exports.main = function main(argv, options, callback) {
375375
let transform = transforms[i];
376376
if (typeof transform[name] === "function") {
377377
try {
378-
transform[name](...args);
378+
stats.transformCount++;
379+
stats.transfromTime += measure(() => {
380+
transform[name](...args);
381+
});
379382
} catch (e) {
380383
return e;
381384
}
@@ -605,29 +608,11 @@ exports.main = function main(argv, options, callback) {
605608
return callback(null);
606609
}
607610

608-
// Set up optimization levels
609-
var optimizeLevel = 0;
610-
var shrinkLevel = 0;
611-
if (args.optimize) {
612-
optimizeLevel = exports.defaultOptimizeLevel;
613-
shrinkLevel = exports.defaultShrinkLevel;
614-
}
615-
if (typeof args.optimizeLevel === "number") {
616-
optimizeLevel = args.optimizeLevel;
617-
}
618-
if (typeof args.shrinkLevel === "number") {
619-
shrinkLevel = args.shrinkLevel;
620-
}
621-
optimizeLevel = Math.min(Math.max(optimizeLevel, 0), 3);
622-
shrinkLevel = Math.min(Math.max(shrinkLevel, 0), 2);
623-
624-
try {
625-
stats.compileTime += measure(() => {
626-
assemblyscript.initializeProgram(program, compilerOptions);
627-
});
628-
} catch(e) {
629-
return callback(e);
630-
}
611+
// Pre-emptively initialize the program
612+
stats.initializeCount++;
613+
stats.initializeTime += measure(() => {
614+
assemblyscript.initializeProgram(program);
615+
});
631616

632617
// Call afterInitialize transform hook
633618
{
@@ -637,13 +622,9 @@ exports.main = function main(argv, options, callback) {
637622

638623
var module;
639624
stats.compileCount++;
640-
try {
641-
stats.compileTime += measure(() => {
642-
module = assemblyscript.compile(program);
643-
});
644-
} catch (e) {
645-
return callback(e);
646-
}
625+
stats.compileTime += measure(() => {
626+
module = assemblyscript.compile(program);
627+
});
647628
var numErrors = checkDiagnostics(program, stderr);
648629
if (numErrors) {
649630
if (module) module.dispose();
@@ -907,6 +888,7 @@ exports.main = function main(argv, options, callback) {
907888
function listFilesNode(dirname, baseDir) {
908889
var files;
909890
try {
891+
stats.readCount++;
910892
stats.readTime += measure(() => {
911893
files = fs.readdirSync(path.join(baseDir, dirname)).filter(file => extension.re_except_d.test(file))
912894
});
@@ -958,14 +940,18 @@ function createStats() {
958940
writeCount: 0,
959941
parseTime: 0,
960942
parseCount: 0,
943+
initializeTime: 0,
944+
initializeCount: 0,
961945
compileTime: 0,
962946
compileCount: 0,
963947
emitTime: 0,
964948
emitCount: 0,
965949
validateTime: 0,
966950
validateCount: 0,
967951
optimizeTime: 0,
968-
optimizeCount: 0
952+
optimizeCount: 0,
953+
transformTime: 0,
954+
transformCount: 0
969955
};
970956
}
971957

@@ -983,26 +969,33 @@ function measure(fn) {
983969

984970
exports.measure = measure;
985971

972+
function pad(str, len) {
973+
while (str.length < len) str = " " + str;
974+
return str;
975+
}
976+
986977
/** Formats a high resolution time to a human readable string. */
987978
function formatTime(time) {
988-
return time ? (time / 1e6).toFixed(3) + " ms" : "N/A";
979+
return time ? (time / 1e6).toFixed(3) + " ms" : "n/a";
989980
}
990981

991982
exports.formatTime = formatTime;
992983

993984
/** Formats and prints out the contents of a set of stats. */
994985
function printStats(stats, output) {
995986
function format(time, count) {
996-
return formatTime(time);
987+
return pad(formatTime(time), 12) + " n=" + count;
997988
}
998989
(output || process.stdout).write([
999-
"I/O Read : " + format(stats.readTime, stats.readCount),
1000-
"I/O Write : " + format(stats.writeTime, stats.writeCount),
1001-
"Parse : " + format(stats.parseTime, stats.parseCount),
1002-
"Compile : " + format(stats.compileTime, stats.compileCount),
1003-
"Emit : " + format(stats.emitTime, stats.emitCount),
1004-
"Validate : " + format(stats.validateTime, stats.validateCount),
1005-
"Optimize : " + format(stats.optimizeTime, stats.optimizeCount)
990+
"I/O Read : " + format(stats.readTime, stats.readCount),
991+
"I/O Write : " + format(stats.writeTime, stats.writeCount),
992+
"Parse : " + format(stats.parseTime, stats.parseCount),
993+
"Initialize : " + format(stats.initializeTime, stats.initializeCount),
994+
"Compile : " + format(stats.compileTime, stats.compileCount),
995+
"Emit : " + format(stats.emitTime, stats.emitCount),
996+
"Validate : " + format(stats.validateTime, stats.validateCount),
997+
"Optimize : " + format(stats.optimizeTime, stats.optimizeCount),
998+
"Transform : " + format(stats.transformTime, stats.transformCount)
1006999
].join(EOL) + EOL);
10071000
}
10081001

lib/loader/index.d.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@ export interface ResultObject {
55
instance: WebAssembly.Instance;
66
}
77

8-
type ImportValue = Function | WebAssembly.Global | WebAssembly.Memory | WebAssembly.Table | number;
9-
108
/** WebAssembly imports with two levels of nesting. */
119
export type Imports = {
10+
[key: string]: object,
1211
env?: {
1312
memory?: WebAssembly.Memory;
1413
table?: WebAssembly.Table;
1514
seed?(): number;
1615
abort?(msg: number, file: number, line: number, column: number): void;
1716
trace?(msg: number, numArgs?: number, ...args: number[]): void;
18-
} & Record<string, ImportValue>;
19-
} & Record<string, Record<string, ImportValue>>;
17+
};
18+
};
2019

2120
/** Utility mixed in by the loader. */
2221
export interface ASUtil {

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@
6666
"prepublishOnly": "node scripts/prepublish",
6767
"postpublish": "node scripts/postpublish",
6868
"asbuild": "npm run asbuild:untouched && npm run asbuild:optimized",
69-
"asbuild:untouched": "node bin/asc src/glue/wasm/index.ts src/index.ts -t out/assemblyscript.untouched.wat -b out/assemblyscript.untouched.wasm -d out/assemblyscript.d.ts --validate --debug --measure",
70-
"asbuild:optimized": "node bin/asc src/glue/wasm/index.ts src/index.ts -t out/assemblyscript.optimized.wat -b out/assemblyscript.optimized.wasm -O3 --validate --measure",
69+
"asbuild:untouched": "node bin/asc src/glue/wasm/index.ts src/index.ts -t out/assemblyscript.untouched.wat -b out/assemblyscript.untouched.wasm -d out/assemblyscript.d.ts --validate --debug --measure --runtime stub",
70+
"asbuild:optimized": "node bin/asc src/glue/wasm/index.ts src/index.ts -t out/assemblyscript.optimized.wat -b out/assemblyscript.optimized.wasm -O3 --validate --measure --runtime stub",
7171
"astest": "ts-node tests/bootstrap"
7272
},
7373
"releaseFiles": [

src/ast.ts

+10
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,16 @@ export abstract class Node {
11661166
}
11671167
return false;
11681168
}
1169+
1170+
/** Checks if this is a call calling a method on super. */
1171+
get isCallOnSuper(): bool {
1172+
if (this.kind != NodeKind.CALL) return false;
1173+
var expression = changetype<CallExpression>(this).expression;
1174+
if (expression.kind != NodeKind.PROPERTYACCESS) return false;
1175+
var target = (<PropertyAccessExpression>expression).expression;
1176+
if (target.kind == NodeKind.SUPER) return true;
1177+
return false;
1178+
}
11691179
}
11701180

11711181
// types

src/common.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ export enum CommonFlags {
6666
INLINED = 1 << 23,
6767
/** Is scoped. */
6868
SCOPED = 1 << 24,
69-
/** Is a trampoline. */
70-
TRAMPOLINE = 1 << 25,
69+
/** Is a stub. */
70+
STUB = 1 << 25,
7171
/** Is a virtual method. */
7272
VIRTUAL = 1 << 26,
7373
/** Is (part of) a closure. */
@@ -99,6 +99,8 @@ export const LIBRARY_SUBST = "~lib";
9999
export const LIBRARY_PREFIX = LIBRARY_SUBST + PATH_DELIMITER;
100100
/** Path index suffix. */
101101
export const INDEX_SUFFIX = PATH_DELIMITER + "index";
102+
/** Stub function delimiter. */
103+
export const STUB_DELIMITER = "@";
102104

103105
/** Common names. */
104106
export namespace CommonNames {

0 commit comments

Comments
 (0)