use hard-coded TypeInfo instances for primitive types
This commit is contained in:
@@ -61,6 +61,18 @@ public class ExpressionCodegen extends JetVisitor {
|
|||||||
private final Stack<Label> myBreakTargets = new Stack<Label>();
|
private final Stack<Label> myBreakTargets = new Stack<Label>();
|
||||||
private final Stack<StackValue> myStack = new Stack<StackValue>();
|
private final Stack<StackValue> myStack = new Stack<StackValue>();
|
||||||
|
|
||||||
|
private static final String[] PRIMITIVE_TYPE_INFO_FIELDS = {
|
||||||
|
null,
|
||||||
|
"BOOL_TYPE_INFO",
|
||||||
|
"CHAR_TYPE_INFO",
|
||||||
|
"BYTE_TYPE_INFO",
|
||||||
|
"SHORT_TYPE_INFO",
|
||||||
|
"INT_TYPE_INFO",
|
||||||
|
"FLOAT_TYPE_INFO",
|
||||||
|
"LONG_TYPE_INFO",
|
||||||
|
"DOUBLE_TYPE_INFO"
|
||||||
|
};
|
||||||
|
|
||||||
private final InstructionAdapter v;
|
private final InstructionAdapter v;
|
||||||
private final FrameMap myMap;
|
private final FrameMap myMap;
|
||||||
private final JetTypeMapper typeMapper;
|
private final JetTypeMapper typeMapper;
|
||||||
@@ -1703,9 +1715,15 @@ public class ExpressionCodegen extends JetVisitor {
|
|||||||
throw new UnsupportedOperationException("don't know what this type parameter resolves to");
|
throw new UnsupportedOperationException("don't know what this type parameter resolves to");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Type jvmType = typeMapper.mapType(jetType, OwnerKind.INTERFACE);
|
||||||
|
if (jvmType.getSort() <= Type.DOUBLE) {
|
||||||
|
v.getstatic("jet/typeinfo/TypeInfo", PRIMITIVE_TYPE_INFO_FIELDS[jvmType.getSort()], "Ljet/typeinfo/TypeInfo;");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
v.anew(JetTypeMapper.TYPE_TYPEINFO);
|
v.anew(JetTypeMapper.TYPE_TYPEINFO);
|
||||||
v.dup();
|
v.dup();
|
||||||
v.aconst(typeMapper.jvmType((ClassDescriptor) declarationDescriptor, OwnerKind.INTERFACE));
|
v.aconst(jvmType);
|
||||||
List<TypeProjection> arguments = jetType.getArguments();
|
List<TypeProjection> arguments = jetType.getArguments();
|
||||||
if (arguments.size() > 0) {
|
if (arguments.size() > 0) {
|
||||||
v.iconst(arguments.size());
|
v.iconst(arguments.size());
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
class Box<T>(t: T) {
|
||||||
|
var value = t
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isIntBox(box: Box<out Any?>): Boolean {
|
||||||
|
return box is Box<Int>;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val box = Box<Int>(1)
|
||||||
|
return if (isIntBox(box)) "OK" else "fail"
|
||||||
|
}
|
||||||
@@ -75,6 +75,9 @@ public abstract class CodegenTestCase extends LightCodeInsightFixtureTestCase {
|
|||||||
System.out.println(generateToText());
|
System.out.println(generateToText());
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
if (!"OK".equals(actual)) {
|
||||||
|
System.out.println(generateToText());
|
||||||
|
}
|
||||||
assertEquals("OK", actual);
|
assertEquals("OK", actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,6 +84,10 @@ public class TypeInfoTest extends CodegenTestCase {
|
|||||||
generateFunction(); // assert no exception
|
generateFunction(); // assert no exception
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testPrimitiveTypeInfo() throws Exception {
|
||||||
|
blackBoxFile("typeInfo/primitiveTypeInfo.jet");
|
||||||
|
}
|
||||||
|
|
||||||
private Runnable newRunnable() {
|
private Runnable newRunnable() {
|
||||||
return new Runnable() {
|
return new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -79,4 +79,13 @@ public class TypeInfo<T> implements JetObject {
|
|||||||
result = 31 * result + (typeParameters != null ? Arrays.hashCode(typeParameters) : 0);
|
result = 31 * result + (typeParameters != null ? Arrays.hashCode(typeParameters) : 0);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final TypeInfo<Byte> BYTE_TYPE_INFO = new TypeInfo<Byte>(Byte.class);
|
||||||
|
public static final TypeInfo<Short> SHORT_TYPE_INFO = new TypeInfo<Short>(Short.class);
|
||||||
|
public static final TypeInfo<Integer> INT_TYPE_INFO = new TypeInfo<Integer>(Integer.class);
|
||||||
|
public static final TypeInfo<Long> LONG_TYPE_INFO = new TypeInfo<Long>(Long.class);
|
||||||
|
public static final TypeInfo<Character> CHAR_TYPE_INFO = new TypeInfo<Character>(Character.class);
|
||||||
|
public static final TypeInfo<Boolean> BOOL_TYPE_INFO = new TypeInfo<Boolean>(Boolean.class);
|
||||||
|
public static final TypeInfo<Float> FLOAT_TYPE_INFO = new TypeInfo<Float>(Float.class);
|
||||||
|
public static final TypeInfo<Double> DOUBLE_TYPE_INFO = new TypeInfo<Double>(Double.class);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user