Skip to content

Commit

Permalink
Allow internal abort to be disabled (#677)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Jun 19, 2019
1 parent c99becc commit f5b00c8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
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 @@ -861,7 +861,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 @@ -897,6 +897,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

0 comments on commit f5b00c8

Please sign in to comment.