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

--HG--
extra : rebase_source : 7c3cc07c2885202524f604cdd259e029f47282e9
This commit is contained in:
Luke Wagner 2013-10-16 18:02:13 -05:00
parent 1e0bb61fa1
commit b6a3f9f650
2 changed files with 13 additions and 22 deletions

View File

@ -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);

View File

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