Skip to content

Consider NaN falseish #933

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

Merged
merged 4 commits into from
Nov 5, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
326 changes: 253 additions & 73 deletions src/builtins.ts

Large diffs are not rendered by default.

195 changes: 101 additions & 94 deletions src/compiler.ts

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions src/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,6 @@ export class Flow {
temps.push(local);
}

/** Gets and immediately frees a temporary local of the specified type. */
getAndFreeTempLocal(type: Type, except: Set<i32> | null = null): Local {
var local = this.getTempLocal(type, except);
this.freeTempLocal(local);
return local;
}

/** Gets the scoped local of the specified name. */
getScopedLocal(name: string): Local | null {
var scopedLocals = this.scopedLocals;
Expand Down
76 changes: 38 additions & 38 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1755,44 +1755,44 @@ export class Relooper {
}
}

// export function hasSideEffects(expr: ExpressionRef): bool {
// // TODO: there's more
// switch (_BinaryenExpressionGetId(expr)) {
// case ExpressionId.LocalGet:
// case ExpressionId.GlobalGet:
// case ExpressionId.Const:
// case ExpressionId.Nop: {
// return false;
// }
// case ExpressionId.Block: {
// for (let i = 0, k = _BinaryenBlockGetNumChildren(expr); i < k; ++i) {
// if (hasSideEffects(_BinaryenBlockGetChild(expr, i))) return true;
// }
// return false;
// }
// case ExpressionId.If: {
// return hasSideEffects(_BinaryenIfGetCondition(expr))
// || hasSideEffects(_BinaryenIfGetIfTrue(expr))
// || hasSideEffects(_BinaryenIfGetIfFalse(expr));
// }
// case ExpressionId.Unary: {
// return hasSideEffects(_BinaryenUnaryGetValue(expr));
// }
// case ExpressionId.Binary: {
// return hasSideEffects(_BinaryenBinaryGetLeft(expr))
// || hasSideEffects(_BinaryenBinaryGetRight(expr));
// }
// case ExpressionId.Drop: {
// return hasSideEffects(_BinaryenDropGetValue(expr));
// }
// case ExpressionId.Select: {
// return hasSideEffects(_BinaryenSelectGetIfTrue(expr))
// || hasSideEffects(_BinaryenSelectGetIfFalse(expr))
// || hasSideEffects(_BinaryenSelectGetCondition(expr));
// }
// }
// return true;
// }
export function hasSideEffects(expr: ExpressionRef): bool {
// TODO: there's more
switch (_BinaryenExpressionGetId(expr)) {
case ExpressionId.LocalGet:
case ExpressionId.GlobalGet:
case ExpressionId.Const:
case ExpressionId.Nop: {
return false;
}
case ExpressionId.Block: {
for (let i = 0, k = _BinaryenBlockGetNumChildren(expr); i < k; ++i) {
if (hasSideEffects(_BinaryenBlockGetChild(expr, i))) return true;
}
return false;
}
case ExpressionId.If: {
return hasSideEffects(_BinaryenIfGetCondition(expr))
|| hasSideEffects(_BinaryenIfGetIfTrue(expr))
|| hasSideEffects(_BinaryenIfGetIfFalse(expr));
}
case ExpressionId.Unary: {
return hasSideEffects(_BinaryenUnaryGetValue(expr));
}
case ExpressionId.Binary: {
return hasSideEffects(_BinaryenBinaryGetLeft(expr))
|| hasSideEffects(_BinaryenBinaryGetRight(expr));
}
case ExpressionId.Drop: {
return hasSideEffects(_BinaryenDropGetValue(expr));
}
case ExpressionId.Select: {
return hasSideEffects(_BinaryenSelectGetIfTrue(expr))
|| hasSideEffects(_BinaryenSelectGetIfFalse(expr))
|| hasSideEffects(_BinaryenSelectGetCondition(expr));
}
}
return true;
}

// helpers
// can't do stack allocation here: STACKTOP is a global in WASM but a hidden variable in asm.js
Expand Down
6 changes: 3 additions & 3 deletions src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -999,10 +999,10 @@ export class Program extends DiagnosticEmitter {
return this.resolver.resolveFunction(<FunctionPrototype>prototype, null);
}

/** Requires that a non-generic global function is present and returns it. */
private requireFunction(name: string): Function {
/** Requires that a global function is present and returns it. */
private requireFunction(name: string, typeArguments: Type[] | null = null): Function {
var prototype = this.require(name, ElementKind.FUNCTION_PROTOTYPE);
var resolved = this.resolver.resolveFunction(<FunctionPrototype>prototype, null);
var resolved = this.resolver.resolveFunction(<FunctionPrototype>prototype, typeArguments);
if (!resolved) throw new Error("invalid " + name);
return resolved;
}
Expand Down
18 changes: 6 additions & 12 deletions std/assembly/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,13 @@ export const NaN: f64 = 0 / 0;
@builtin @inline
export const Infinity: f64 = 1 / 0;

export function isNaN<T extends number>(value: T): bool {
if (!isFloat<T>()) {
if (!isInteger<T>()) ERROR("numeric type expected");
}
return value != value;
}
// @ts-ignore: decorator
@builtin
export declare function isNaN<T extends number>(value: T): bool;

export function isFinite<T extends number>(value: T): bool {
if (!isFloat<T>()) {
if (!isInteger<T>()) ERROR("numeric type expected");
}
return value - value == 0;
}
// @ts-ignore: decorator
@builtin
export declare function isFinite<T extends number>(value: T): bool;

@sealed @unmanaged
export abstract class I8 {
Expand Down
Loading