Commit b6a3f9f6 authored by Luke Wagner's avatar Luke Wagner
Browse files

Bug 927112 - OdinMonkey: loosen up type rules for + (r=sstangl)

--HG--
extra : rebase_source : 7c3cc07c2885202524f604cdd259e029f47282e9
parent 1e0bb61f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -253,8 +253,8 @@ assertEq(f(-1,false), 0);
assertEq(f(-5,false), 1);

assertAsmTypeFail('glob','imp','b', USE_ASM + HEAP_IMPORTS + "function f() { return (i32[0]+1)|0 } return f");
assertAsmTypeFail('glob','imp','b', USE_ASM + HEAP_IMPORTS + "function f() { return +(f64[0] + 1.0); } return f");
new Float64Array(BUF_64KB)[0] = 2.3;
assertEq(asmLink(asmCompile('glob','imp','b', USE_ASM + HEAP_IMPORTS + "function f() { return +(f64[0] + 2.0) } return f"), this, null, BUF_64KB)(), 2.3+2);
assertEq(asmLink(asmCompile('glob','imp','b', USE_ASM + HEAP_IMPORTS + "function f() { return +(f64[0] - 2.0) } return f"), this, null, BUF_64KB)(), 2.3-2);
assertEq(asmLink(asmCompile('glob','imp','b', USE_ASM + HEAP_IMPORTS + "function f() { return +(f64[0] * 2.0) } return f"), this, null, BUF_64KB)(), 2.3*2);
assertEq(asmLink(asmCompile('glob','imp','b', USE_ASM + HEAP_IMPORTS + "function f() { return +(f64[0] / 2.0) } return f"), this, null, BUF_64KB)(), 2.3/2);
+12 −21
Original line number Diff line number Diff line
@@ -4157,29 +4157,20 @@ CheckAddOrSub(FunctionCompiler &f, ParseNode *expr, MDefinition **def, Type *typ
    if (numAddOrSub > (1<<20))
        return f.fail(expr, "too many + or - without intervening coercion");

    if (expr->isKind(PNK_ADD)) {
    if (lhsType.isInt() && rhsType.isInt()) {
            *def = f.binary<MAdd>(lhsDef, rhsDef, MIRType_Int32);
            *type = Type::Intish;
        } else if (lhsType.isDouble() && rhsType.isDouble()) {
            *def = f.binary<MAdd>(lhsDef, rhsDef, MIRType_Double);
            *type = Type::Double;
        } else {
            return f.failf(expr, "operands to + must both be int or double, got %s and %s",
                           lhsType.toChars(), rhsType.toChars());
        }
    } else {
        if (lhsType.isInt() && rhsType.isInt()) {
            *def = f.binary<MSub>(lhsDef, rhsDef, MIRType_Int32);
        *def = expr->isKind(PNK_ADD)
               ? f.binary<MAdd>(lhsDef, rhsDef, MIRType_Int32)
               : f.binary<MSub>(lhsDef, rhsDef, MIRType_Int32);
        *type = Type::Intish;
    } else if (lhsType.isDoublish() && rhsType.isDoublish()) {
            *def = f.binary<MSub>(lhsDef, rhsDef, MIRType_Double);
        *def = expr->isKind(PNK_ADD)
               ? f.binary<MAdd>(lhsDef, rhsDef, MIRType_Double)
               : f.binary<MSub>(lhsDef, rhsDef, MIRType_Double);
        *type = Type::Double;
    } else {
            return f.failf(expr, "operands to - must both be int or doublish, got %s and %s",
        return f.failf(expr, "operands to +/- must both be int or doublish, got %s and %s",
                       lhsType.toChars(), rhsType.toChars());
    }
    }

    if (numAddOrSubOut)
        *numAddOrSubOut = numAddOrSub;