BREAKING CHANGE: Unify Math & Mathf. Make every method in Math polymorphic by MaxGraey · Pull Request #2335 · AssemblyScript/assemblyscript · GitHub
Skip to content
Open
12 changes: 6 additions & 6 deletions src/common.ts
60 changes: 12 additions & 48 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5327,23 +5327,14 @@ export class Compiler extends DiagnosticEmitter {
}
let instance = this.f32PowInstance;
if (!instance) {
let namespace = this.program.lookup(CommonNames.Mathf);
if (!namespace) {
this.error(
DiagnosticCode.Cannot_find_name_0,
reportNode.range, "Mathf"
);
return module.unreachable();
}
let namespaceMembers = namespace.members;
if (!namespaceMembers || !namespaceMembers.has(CommonNames.pow)) {
let prototype = this.program.lookup(CommonNames.fpow32);
if (!prototype) {
this.error(
DiagnosticCode.Cannot_find_name_0,
reportNode.range, "Mathf.pow"
reportNode.range, "pow32"
);
return module.unreachable();
}
let prototype = assert(namespaceMembers.get(CommonNames.pow));
assert(prototype.kind == ElementKind.FUNCTION_PROTOTYPE);
this.f32PowInstance = instance = this.resolver.resolveFunction(<FunctionPrototype>prototype, null);
}
Expand All @@ -5369,23 +5360,14 @@ export class Compiler extends DiagnosticEmitter {
}
let instance = this.f64PowInstance;
if (!instance) {
let namespace = this.program.lookup(CommonNames.Math);
if (!namespace) {
this.error(
DiagnosticCode.Cannot_find_name_0,
reportNode.range, "Math"
);
return module.unreachable();
}
let namespaceMembers = namespace.members;
if (!namespaceMembers || !namespaceMembers.has(CommonNames.pow)) {
let prototype = this.program.lookup(CommonNames.fpow64);
if (!prototype) {
this.error(
DiagnosticCode.Cannot_find_name_0,
reportNode.range, "Math.pow"
reportNode.range, "pow64"
);
return module.unreachable();
}
let prototype = assert(namespaceMembers.get(CommonNames.pow));
assert(prototype.kind == ElementKind.FUNCTION_PROTOTYPE);
this.f64PowInstance = instance = this.resolver.resolveFunction(<FunctionPrototype>prototype, null);
}
Expand Down Expand Up @@ -5507,23 +5489,14 @@ export class Compiler extends DiagnosticEmitter {
case TypeKind.F32: {
let instance = this.f32ModInstance;
if (!instance) {
let namespace = this.program.lookup(CommonNames.Mathf);
if (!namespace) {
this.error(
DiagnosticCode.Cannot_find_name_0,
reportNode.range, "Mathf"
);
return module.unreachable();
}
let namespaceMembers = namespace.members;
if (!namespaceMembers || !namespaceMembers.has(CommonNames.mod)) {
let prototype = this.program.lookup(CommonNames.fmod32);
if (!prototype) {
this.error(
DiagnosticCode.Cannot_find_name_0,
reportNode.range, "Mathf.mod"
reportNode.range, "mod32"
);
return module.unreachable();
}
let prototype = assert(namespaceMembers.get(CommonNames.mod));
assert(prototype.kind == ElementKind.FUNCTION_PROTOTYPE);
this.f32ModInstance = instance = this.resolver.resolveFunction(<FunctionPrototype>prototype, null);
}
Expand All @@ -5535,23 +5508,14 @@ export class Compiler extends DiagnosticEmitter {
case TypeKind.F64: {
let instance = this.f64ModInstance;
if (!instance) {
let namespace = this.program.lookup(CommonNames.Math);
if (!namespace) {
this.error(
DiagnosticCode.Cannot_find_name_0,
reportNode.range, "Math"
);
return module.unreachable();
}
let namespaceMembers = namespace.members;
if (!namespaceMembers || !namespaceMembers.has(CommonNames.mod)) {
let prototype = this.program.lookup(CommonNames.fmod64);
if (!prototype) {
this.error(
DiagnosticCode.Cannot_find_name_0,
reportNode.range, "Math.mod"
reportNode.range, "mod64"
);
return module.unreachable();
}
let prototype = assert(namespaceMembers.get(CommonNames.mod));
assert(prototype.kind == ElementKind.FUNCTION_PROTOTYPE);
this.f64ModInstance = instance = this.resolver.resolveFunction(<FunctionPrototype>prototype, null);
}
Expand Down
3 changes: 0 additions & 3 deletions src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1401,9 +1401,6 @@ export class Program extends DiagnosticEmitter {
if (!globalAliases.has(CommonNames.Math)) {
globalAliases.set(CommonNames.Math, CommonNames.NativeMath);
}
if (!globalAliases.has(CommonNames.Mathf)) {
globalAliases.set(CommonNames.Mathf, CommonNames.NativeMathf);
}
// TODO: for (let [alias, name] of globalAliases) {
for (let _keys = Map_keys(globalAliases), i = 0, k = _keys.length; i < k; ++i) {
let alias = unchecked(_keys[i]);
Expand Down
142 changes: 70 additions & 72 deletions std/assembly/index.d.ts
Loading