Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement virtual overloading / interfaces #1208

Merged
merged 29 commits into from
Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 34 additions & 41 deletions cli/asc.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,10 @@ exports.main = function main(argv, options, callback) {
let transform = transforms[i];
if (typeof transform[name] === "function") {
try {
transform[name](...args);
stats.transformCount++;
stats.transfromTime += measure(() => {
transform[name](...args);
});
} catch (e) {
return e;
}
Expand Down Expand Up @@ -605,29 +608,11 @@ exports.main = function main(argv, options, callback) {
return callback(null);
}

// Set up optimization levels
var optimizeLevel = 0;
var shrinkLevel = 0;
if (args.optimize) {
optimizeLevel = exports.defaultOptimizeLevel;
shrinkLevel = exports.defaultShrinkLevel;
}
if (typeof args.optimizeLevel === "number") {
optimizeLevel = args.optimizeLevel;
}
if (typeof args.shrinkLevel === "number") {
shrinkLevel = args.shrinkLevel;
}
optimizeLevel = Math.min(Math.max(optimizeLevel, 0), 3);
shrinkLevel = Math.min(Math.max(shrinkLevel, 0), 2);

try {
stats.compileTime += measure(() => {
assemblyscript.initializeProgram(program, compilerOptions);
});
} catch(e) {
return callback(e);
}
// Pre-emptively initialize the program
stats.initializeCount++;
stats.initializeTime += measure(() => {
assemblyscript.initializeProgram(program);
});

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

var module;
stats.compileCount++;
try {
stats.compileTime += measure(() => {
module = assemblyscript.compile(program);
});
} catch (e) {
return callback(e);
}
stats.compileTime += measure(() => {
module = assemblyscript.compile(program);
});
var numErrors = checkDiagnostics(program, stderr);
if (numErrors) {
if (module) module.dispose();
Expand Down Expand Up @@ -907,6 +888,7 @@ exports.main = function main(argv, options, callback) {
function listFilesNode(dirname, baseDir) {
var files;
try {
stats.readCount++;
stats.readTime += measure(() => {
files = fs.readdirSync(path.join(baseDir, dirname)).filter(file => extension.re_except_d.test(file))
});
Expand Down Expand Up @@ -958,14 +940,18 @@ function createStats() {
writeCount: 0,
parseTime: 0,
parseCount: 0,
initializeTime: 0,
initializeCount: 0,
compileTime: 0,
compileCount: 0,
emitTime: 0,
emitCount: 0,
validateTime: 0,
validateCount: 0,
optimizeTime: 0,
optimizeCount: 0
optimizeCount: 0,
transformTime: 0,
transformCount: 0
};
}

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

exports.measure = measure;

function pad(str, len) {
while (str.length < len) str = " " + str;
return str;
}

/** Formats a high resolution time to a human readable string. */
function formatTime(time) {
return time ? (time / 1e6).toFixed(3) + " ms" : "N/A";
return time ? (time / 1e6).toFixed(3) + " ms" : "n/a";
}

exports.formatTime = formatTime;

/** Formats and prints out the contents of a set of stats. */
function printStats(stats, output) {
function format(time, count) {
return formatTime(time);
return pad(formatTime(time), 12) + " n=" + count;
}
(output || process.stdout).write([
"I/O Read : " + format(stats.readTime, stats.readCount),
"I/O Write : " + format(stats.writeTime, stats.writeCount),
"Parse : " + format(stats.parseTime, stats.parseCount),
"Compile : " + format(stats.compileTime, stats.compileCount),
"Emit : " + format(stats.emitTime, stats.emitCount),
"Validate : " + format(stats.validateTime, stats.validateCount),
"Optimize : " + format(stats.optimizeTime, stats.optimizeCount)
"I/O Read : " + format(stats.readTime, stats.readCount),
"I/O Write : " + format(stats.writeTime, stats.writeCount),
"Parse : " + format(stats.parseTime, stats.parseCount),
"Initialize : " + format(stats.initializeTime, stats.initializeCount),
"Compile : " + format(stats.compileTime, stats.compileCount),
"Emit : " + format(stats.emitTime, stats.emitCount),
"Validate : " + format(stats.validateTime, stats.validateCount),
"Optimize : " + format(stats.optimizeTime, stats.optimizeCount),
"Transform : " + format(stats.transformTime, stats.transformCount)
].join(EOL) + EOL);
}

Expand Down
7 changes: 3 additions & 4 deletions lib/loader/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ export interface ResultObject {
instance: WebAssembly.Instance;
}

type ImportValue = Function | WebAssembly.Global | WebAssembly.Memory | WebAssembly.Table | number;

/** WebAssembly imports with two levels of nesting. */
export type Imports = {
[key: string]: object,
env?: {
memory?: WebAssembly.Memory;
table?: WebAssembly.Table;
seed?(): number;
abort?(msg: number, file: number, line: number, column: number): void;
trace?(msg: number, numArgs?: number, ...args: number[]): void;
} & Record<string, ImportValue>;
} & Record<string, Record<string, ImportValue>>;
};
};

/** Utility mixed in by the loader. */
export interface ASUtil {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
"prepublishOnly": "node scripts/prepublish",
"postpublish": "node scripts/postpublish",
"asbuild": "npm run asbuild:untouched && npm run asbuild:optimized",
"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",
"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",
"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",
"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",
"astest": "ts-node tests/bootstrap"
},
"releaseFiles": [
Expand Down
10 changes: 10 additions & 0 deletions src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,16 @@ export abstract class Node {
}
return false;
}

/** Checks if this is a call calling a method on super. */
get isCallOnSuper(): bool {
if (this.kind != NodeKind.CALL) return false;
var expression = changetype<CallExpression>(this).expression;
if (expression.kind != NodeKind.PROPERTYACCESS) return false;
var target = (<PropertyAccessExpression>expression).expression;
if (target.kind == NodeKind.SUPER) return true;
return false;
}
}

// types
Expand Down
6 changes: 4 additions & 2 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ export enum CommonFlags {
INLINED = 1 << 23,
/** Is scoped. */
SCOPED = 1 << 24,
/** Is a trampoline. */
TRAMPOLINE = 1 << 25,
/** Is a stub. */
STUB = 1 << 25,
/** Is a virtual method. */
VIRTUAL = 1 << 26,
/** Is (part of) a closure. */
Expand Down Expand Up @@ -99,6 +99,8 @@ export const LIBRARY_SUBST = "~lib";
export const LIBRARY_PREFIX = LIBRARY_SUBST + PATH_DELIMITER;
/** Path index suffix. */
export const INDEX_SUFFIX = PATH_DELIMITER + "index";
/** Stub function delimiter. */
export const STUB_DELIMITER = "@";

/** Common names. */
export namespace CommonNames {
Expand Down
Loading