提交 807b669b 编写于 作者: D Dmitry Jemerov

Double

上级 5b5e8119
......@@ -506,12 +506,13 @@ public class ExpressionCodegen extends JetVisitor {
private static boolean isNumberPrimitive(String className) {
return className.equals("Int") || className.equals("Long") || className.equals("Short") ||
className.equals("Byte") || className.equals("Char") || className.equals("Float");
className.equals("Byte") || className.equals("Char") || className.equals("Float") ||
className.equals("Double");
}
private static boolean isNumberPrimitive(Type type) {
return type == Type.INT_TYPE || type == Type.SHORT_TYPE || type == Type.BYTE_TYPE || type == Type.CHAR_TYPE ||
type == Type.FLOAT_TYPE;
type == Type.FLOAT_TYPE || type == Type.DOUBLE_TYPE;
}
private static int opcodeForMethod(final String name) {
......@@ -526,7 +527,8 @@ public class ExpressionCodegen extends JetVisitor {
private void generateBinaryOp(JetBinaryExpression expression, FunctionDescriptor op, int opcode) {
JetType returnType = op.getUnsubstitutedReturnType();
final Type asmType = typeMapper.mapType(returnType);
if (asmType == Type.INT_TYPE || asmType == Type.LONG_TYPE || asmType == Type.FLOAT_TYPE) {
if (asmType == Type.INT_TYPE || asmType == Type.LONG_TYPE ||
asmType == Type.FLOAT_TYPE || asmType == Type.DOUBLE_TYPE) {
gen(expression.getLeft(), asmType);
gen(expression.getRight(), asmType);
v.visitInsn(asmType.getOpcode(opcode));
......
......@@ -35,6 +35,9 @@ public class JetTypeMapper {
if (jetType.equals(standardLibrary.getFloatType())) {
return Type.FLOAT_TYPE;
}
if (jetType.equals(standardLibrary.getDoubleType())) {
return Type.DOUBLE_TYPE;
}
if (jetType.equals(standardLibrary.getBooleanType())) {
return Type.BOOLEAN_TYPE;
}
......
......@@ -158,7 +158,7 @@ public abstract class StackValue {
else {
throw new UnsupportedOperationException("don't know how to generate this condjump");
}
if (type == Type.FLOAT_TYPE) {
if (type == Type.FLOAT_TYPE || type == Type.DOUBLE_TYPE) {
if (opToken == JetTokens.GT || opToken == JetTokens.GTEQ) {
v.cmpg(type);
}
......
......@@ -287,6 +287,14 @@ public class NamespaceGenTest extends LightCodeInsightFixtureTestCase {
binOpTest("fun foo(a: Float, b: Float): Boolean = a == b", 1.0f, 1.0f, true);
}
public void testDouble() throws Exception {
binOpTest("fun foo(a: Double, b: Double): Double = a + b", 1.0, 2.0, 3.0);
}
public void testDoubleCmp() throws Exception {
binOpTest("fun foo(a: Double, b: Double): Boolean = a == b", 1.0, 2.0, false);
}
private void binOpTest(final String text, final Object arg1, final Object arg2, final Object expected) throws Exception {
loadText(text);
System.out.println(generateToText());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册