Move fmod/fmodf to builtins and bind them to the '%' operator

This commit is contained in:
dcodeIO
2018-03-24 18:39:20 +01:00
parent 721d77012b
commit c80bf35747
21 changed files with 4378 additions and 4209 deletions

View File

@ -821,7 +821,7 @@ export class Compiler extends DiagnosticEmitter {
/** Compiles a readily resolved function instance. */
compileFunction(instance: Function): bool {
if (instance.is(CommonFlags.COMPILED)) return true;
assert(!instance.is(CommonFlags.AMBIENT | CommonFlags.BUILTIN) || instance.simpleName == "abort");
assert(!instance.is(CommonFlags.AMBIENT | CommonFlags.BUILTIN) || instance.internalName == "abort");
instance.set(CommonFlags.COMPILED);
// check that modifiers are matching but still compile as-is
@ -3227,14 +3227,42 @@ export class Compiler extends DiagnosticEmitter {
expr = module.createBinary(BinaryOp.RemU64, leftExpr, rightExpr);
break;
}
case TypeKind.F32:
case TypeKind.F32: {
let fmodPrototype = this.program.elementsLookup.get("fmodf");
if (!fmodPrototype) {
this.error(
DiagnosticCode.Cannot_find_name_0,
expression.range, "fmod"
);
expr = module.createUnreachable();
break;
}
assert(fmodPrototype.kind == ElementKind.FUNCTION_PROTOTYPE);
let fmodInstance = (<FunctionPrototype>fmodPrototype).resolve();
if (!(fmodInstance && this.compileFunction(fmodInstance))) {
expr = module.createUnreachable();
} else {
expr = this.makeCallDirect(fmodInstance, [ leftExpr, rightExpr ]);
}
break;
}
case TypeKind.F64: {
// TODO: internal fmod, possibly simply imported from JS
this.error(
DiagnosticCode.Operation_not_supported,
expression.range
);
expr = module.createUnreachable();
let fmodPrototype = this.program.elementsLookup.get("fmod");
if (!fmodPrototype) {
this.error(
DiagnosticCode.Cannot_find_name_0,
expression.range, "fmod"
);
expr = module.createUnreachable();
break;
}
assert(fmodPrototype.kind == ElementKind.FUNCTION_PROTOTYPE);
let fmodInstance = (<FunctionPrototype>fmodPrototype).resolve();
if (!(fmodInstance && this.compileFunction(fmodInstance))) {
expr = module.createUnreachable();
} else {
expr = this.makeCallDirect(fmodInstance, [ leftExpr, rightExpr ]);
}
break;
}
default: {

View File

@ -2514,7 +2514,7 @@ export class Function extends Element {
this.signature = signature;
this.memberOf = memberOf;
this.flags = prototype.flags;
if (!(prototype.is(CommonFlags.BUILTIN) || prototype.is(CommonFlags.DECLARE))) {
if (!(prototype.is(CommonFlags.AMBIENT | CommonFlags.BUILTIN) || prototype.is(CommonFlags.DECLARE))) {
let localIndex = 0;
if (memberOf && memberOf.kind == ElementKind.CLASS) {
assert(this.is(CommonFlags.INSTANCE));