Fix bugs in JavaScript backend

This commit is contained in:
Alexey Andreev 2016-08-08 13:07:29 +03:00
parent 055312055b
commit 081efd2d60
2 changed files with 33 additions and 10 deletions

View File

@ -1514,10 +1514,18 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
visitBinary(expr, "%", expr.getType() == OperationType.INT);
break;
case EQUALS:
visitBinary(expr, "===", false);
if (expr.getType() == OperationType.INT) {
visitBinary(expr, "==", false);
} else {
visitBinary(expr, "===", false);
}
break;
case NOT_EQUALS:
visitBinary(expr, "!==", false);
if (expr.getType() == OperationType.INT) {
visitBinary(expr, "!=", false);
} else {
visitBinary(expr, "!==", false);
}
break;
case GREATER:
visitBinary(expr, ">", false);
@ -1591,7 +1599,7 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
}
case NEGATE:
if (expr.getType() == OperationType.LONG) {
writer.append("Long_not(");
writer.append("Long_neg(");
precedence = Precedence.min();
expr.getOperand().acceptVisitor(this);
writer.append(')');
@ -2231,7 +2239,11 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
String clsName = ((ValueType.Object) expr.getType()).getClassName();
ClassHolder cls = classSource.get(clsName);
if (cls != null && !cls.getModifiers().contains(ElementModifier.INTERFACE)) {
precedence = Precedence.COMPARISON.next();
boolean needsParentheses = Precedence.COMPARISON.ordinal() < precedence.ordinal();
if (needsParentheses) {
writer.append('(');
}
precedence = Precedence.CONDITIONAL.next();
expr.getExpr().acceptVisitor(this);
writer.append(" instanceof ").appendClass(clsName);
if (expr.getLocation() != null) {

View File

@ -645,8 +645,10 @@ function Long_gt(a, b) {
if (a.hi > b.hi) {
return true;
}
if ((a.lo >>> 1) > (b.lo >>> 1)) {
return true;
var x = a.lo >>> 1;
var y = b.lo >>> 1;
if (x != y) {
return x > y;
}
return (a.lo & 1) > (b.lo & 1);
}
@ -657,8 +659,10 @@ function Long_ge(a, b) {
if (a.hi > b.hi) {
return true;
}
if ((a.lo >>> 1) >= (b.lo >>> 1)) {
return true;
var x = a.lo >>> 1;
var y = b.lo >>> 1;
if (x != y) {
return x >= y;
}
return (a.lo & 1) >= (b.lo & 1);
}
@ -669,8 +673,10 @@ function Long_lt(a, b) {
if (a.hi < b.hi) {
return true;
}
if ((a.lo >>> 1) < (b.lo >>> 1)) {
return true;
var x = a.lo >>> 1;
var y = b.lo >>> 1;
if (x != y) {
return x < y;
}
return (a.lo & 1) < (b.lo & 1);
}
@ -684,6 +690,11 @@ function Long_le(a, b) {
if ((a.lo >>> 1) <= (b.lo >>> 1)) {
return true;
}
var x = a.lo >>> 1;
var y = b.lo >>> 1;
if (x != y) {
return x <= y;
}
return (a.lo & 1) <= (b.lo & 1);
}