boxing for constants
This commit is contained in:
@@ -187,35 +187,6 @@ public class ExpressionCodegen extends JetVisitor {
|
|||||||
@Override
|
@Override
|
||||||
public void visitConstantExpression(JetConstantExpression expression) {
|
public void visitConstantExpression(JetConstantExpression expression) {
|
||||||
myStack.push(StackValue.constant(expression.getValue()));
|
myStack.push(StackValue.constant(expression.getValue()));
|
||||||
/*
|
|
||||||
Object value = element.getValue();
|
|
||||||
v.aconst(value);
|
|
||||||
|
|
||||||
if (value instanceof Integer) {
|
|
||||||
v.invokestatic("java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;");
|
|
||||||
}
|
|
||||||
else if (value instanceof Boolean) {
|
|
||||||
v.invokestatic("java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;");
|
|
||||||
}
|
|
||||||
else if (value instanceof Character) {
|
|
||||||
v.invokestatic("java/lang/Character", "valueOf", "(C)Ljava/lang/Character;");
|
|
||||||
}
|
|
||||||
else if (value instanceof Short) {
|
|
||||||
v.invokestatic("java/lang/Short", "valueOf", "(S)Ljava/lang/Short;");
|
|
||||||
}
|
|
||||||
else if (value instanceof Long) {
|
|
||||||
v.invokestatic("java/lang/Long", "valueOf", "(J)Ljava/lang/Long;");
|
|
||||||
}
|
|
||||||
else if (value instanceof Byte) {
|
|
||||||
v.invokestatic("java/lang/Byte", "valueOf", "(B)Ljava/lang/Byte;");
|
|
||||||
}
|
|
||||||
else if (value instanceof Float) {
|
|
||||||
v.invokestatic("java/lang/Float", "valueOf", "(F)Ljava/lang/Float;");
|
|
||||||
}
|
|
||||||
else if (value instanceof Double) {
|
|
||||||
v.invokestatic("java/lang/Double", "valueOf", "(D)Ljava/lang/Double;");
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ public class JetTypeMapper {
|
|||||||
if (jetType.equals(standardLibrary.getIntType())) {
|
if (jetType.equals(standardLibrary.getIntType())) {
|
||||||
return Type.INT_TYPE;
|
return Type.INT_TYPE;
|
||||||
}
|
}
|
||||||
|
if (jetType.equals(TypeUtils.makeNullable(standardLibrary.getIntType()))) {
|
||||||
|
return Type.getObjectType("java/lang/Integer");
|
||||||
|
}
|
||||||
if (jetType.equals(standardLibrary.getLongType())) {
|
if (jetType.equals(standardLibrary.getLongType())) {
|
||||||
return Type.LONG_TYPE;
|
return Type.LONG_TYPE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,6 +97,32 @@ public abstract class StackValue {
|
|||||||
@Override
|
@Override
|
||||||
public void put(Type type, InstructionAdapter v) {
|
public void put(Type type, InstructionAdapter v) {
|
||||||
v.aconst(value);
|
v.aconst(value);
|
||||||
|
if (type.getSort() == Type.OBJECT) {
|
||||||
|
if (value instanceof Integer) {
|
||||||
|
v.invokestatic("java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;");
|
||||||
|
}
|
||||||
|
else if (value instanceof Boolean) {
|
||||||
|
v.invokestatic("java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;");
|
||||||
|
}
|
||||||
|
else if (value instanceof Character) {
|
||||||
|
v.invokestatic("java/lang/Character", "valueOf", "(C)Ljava/lang/Character;");
|
||||||
|
}
|
||||||
|
else if (value instanceof Short) {
|
||||||
|
v.invokestatic("java/lang/Short", "valueOf", "(S)Ljava/lang/Short;");
|
||||||
|
}
|
||||||
|
else if (value instanceof Long) {
|
||||||
|
v.invokestatic("java/lang/Long", "valueOf", "(J)Ljava/lang/Long;");
|
||||||
|
}
|
||||||
|
else if (value instanceof Byte) {
|
||||||
|
v.invokestatic("java/lang/Byte", "valueOf", "(B)Ljava/lang/Byte;");
|
||||||
|
}
|
||||||
|
else if (value instanceof Float) {
|
||||||
|
v.invokestatic("java/lang/Float", "valueOf", "(F)Ljava/lang/Float;");
|
||||||
|
}
|
||||||
|
else if (value instanceof Double) {
|
||||||
|
v.invokestatic("java/lang/Double", "valueOf", "(D)Ljava/lang/Double;");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -221,12 +221,18 @@ public class NamespaceGenTest extends LightCodeInsightFixtureTestCase {
|
|||||||
assertEquals(239, main.invoke(null, new Object[]{null}));
|
assertEquals(239, main.invoke(null, new Object[]{null}));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBoxingInCall() throws Exception {
|
public void testIntBoxed() throws Exception {
|
||||||
loadText("fun foo(s: String): Int? = Integer.getInteger(s, 239)");
|
loadText("fun foo(s: String): Int? = Integer.getInteger(s, 239)");
|
||||||
final Method main = generateFunction();
|
final Method main = generateFunction();
|
||||||
assertEquals(239, main.invoke(null, "no.such.system.property"));
|
assertEquals(239, main.invoke(null, "no.such.system.property"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBoxConstant() throws Exception {
|
||||||
|
loadText("fun foo(): Int? = 239");
|
||||||
|
final Method main = generateFunction();
|
||||||
|
assertEquals(239, main.invoke(null));
|
||||||
|
}
|
||||||
|
|
||||||
public void testLong() throws Exception {
|
public void testLong() throws Exception {
|
||||||
loadText("fun foo(a: Long, b: Long): Long = a + b");
|
loadText("fun foo(a: Long, b: Long): Long = a + b");
|
||||||
System.out.println(generateToText());
|
System.out.println(generateToText());
|
||||||
|
|||||||
Reference in New Issue
Block a user