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

Allow internal abort to be disabled #677

Merged
merged 4 commits into from Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions cli/asc.js
Expand Up @@ -459,10 +459,10 @@ exports.main = function main(argv, options, callback) {
let part = aliases[i];
let p = part.indexOf("=");
if (p < 0) return callback(Error("Global alias '" + part + "' is invalid."));
let name = part.substring(0, p).trim();
let alias = part.substring(p + 1).trim();
if (!name.length) return callback(Error("Global alias '" + part + "' is invalid."));
assemblyscript.setGlobalAlias(compilerOptions, name, alias);
let alias = part.substring(0, p).trim();
let name = part.substring(p + 1).trim();
if (!alias.length) return callback(Error("Global alias '" + part + "' is invalid."));
assemblyscript.setGlobalAlias(compilerOptions, alias, name);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/compiler.ts
Expand Up @@ -197,7 +197,7 @@ export class Options {
explicitStart: bool = false;
/** Static memory start offset. */
memoryBase: i32 = 0;
/** Global aliases. */
/** Global aliases, mapping alias names as the key to internal names to be aliased as the value. */
globalAliases: Map<string,string> | null = null;
/** Additional features to activate. */
features: Feature = Feature.NONE;
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Expand Up @@ -93,10 +93,10 @@ export function setMemoryBase(options: Options, memoryBase: u32): void {
}

/** Sets a 'globalAliases' value. */
export function setGlobalAlias(options: Options, name: string, alias: string): void {
export function setGlobalAlias(options: Options, alias: string, name: string): void {
var globalAliases = options.globalAliases;
if (!globalAliases) options.globalAliases = globalAliases = new Map();
globalAliases.set(name, alias);
globalAliases.set(alias, name);
}

/** Sets the `explicitStart` option. */
Expand Down
13 changes: 10 additions & 3 deletions src/program.ts
Expand Up @@ -375,8 +375,8 @@ export class Program extends DiagnosticEmitter {
f64ArrayPrototype: ClassPrototype;
/** String instance reference. */
stringInstance: Class;
/** Abort function reference, if present. */
abortInstance: Function;
/** Abort function reference, if not explicitly disabled. */
abortInstance: Function | null;

// runtime references

Expand Down Expand Up @@ -849,7 +849,7 @@ export class Program extends DiagnosticEmitter {
this.fixedArrayPrototype = <ClassPrototype>this.require(CommonSymbols.FixedArray, ElementKind.CLASS_PROTOTYPE);
this.setPrototype = <ClassPrototype>this.require(CommonSymbols.Set, ElementKind.CLASS_PROTOTYPE);
this.mapPrototype = <ClassPrototype>this.require(CommonSymbols.Map, ElementKind.CLASS_PROTOTYPE);
this.abortInstance = this.requireFunction(CommonSymbols.abort);
this.abortInstance = this.lookupFunction(CommonSymbols.abort); // can be disabled
this.allocInstance = this.requireFunction(CommonSymbols.alloc);
this.reallocInstance = this.requireFunction(CommonSymbols.realloc);
this.freeInstance = this.requireFunction(CommonSymbols.free);
Expand Down Expand Up @@ -885,6 +885,13 @@ export class Program extends DiagnosticEmitter {
return resolved;
}

/** Obtains a non-generic global function and returns it. Returns `null` if it does not exist. */
private lookupFunction(name: string): Function | null {
var prototype = this.lookupGlobal(name);
if (!prototype || prototype.kind != ElementKind.FUNCTION_PROTOTYPE) return null;
return this.resolver.resolveFunction(<FunctionPrototype>prototype, null);
}

/** Requires that a non-generic global function is present and returns it. */
private requireFunction(name: string): Function {
var prototype = this.require(name, ElementKind.FUNCTION_PROTOTYPE);
Expand Down