This commit is contained in:
Alex Tkachman
2011-10-28 08:05:30 +02:00
parent 05db935efb
commit d52ba949a0
2 changed files with 15 additions and 5 deletions
@@ -1867,20 +1867,22 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
throw new CompilationException("primitive array constructor requires one argument"); throw new CompilationException("primitive array constructor requires one argument");
} }
} }
gen(args.get(0).getArgumentExpression(), Type.INT_TYPE);
if(isArray) { if(isArray) {
JetType elementType = typeMapper.getGenericsElementType(arrayType); JetType elementType = typeMapper.getGenericsElementType(arrayType);
if(elementType != null) { if(elementType != null) {
generateTypeInfo(elementType); generateTypeInfo(elementType);
v.invokestatic("jet/typeinfo/TypeInfo", "newArray", "(ILjet/typeinfo/TypeInfo;)[Ljava/lang/Object;"); gen(args.get(0).getArgumentExpression(), Type.INT_TYPE);
v.invokevirtual("jet/typeinfo/TypeInfo", "newArray", "(I)[Ljava/lang/Object;");
} }
else { else {
gen(args.get(0).getArgumentExpression(), Type.INT_TYPE);
v.newarray(JetTypeMapper.boxType(typeMapper.mapType(arrayType.getArguments().get(0).getType()))); v.newarray(JetTypeMapper.boxType(typeMapper.mapType(arrayType.getArguments().get(0).getType())));
} }
} }
else { else {
Type type = typeMapper.mapType(arrayType, OwnerKind.IMPLEMENTATION); Type type = typeMapper.mapType(arrayType, OwnerKind.IMPLEMENTATION);
gen(args.get(0).getArgumentExpression(), Type.INT_TYPE);
v.newarray(type.getElementType()); v.newarray(type.getElementType());
} }
+11 -3
View File
@@ -49,9 +49,7 @@ public abstract class TypeInfo<T> implements JetObject {
public static final TypeInfo<String> NULLABLE_STRING_TYPE_INFO = getTypeInfo(String.class, true); public static final TypeInfo<String> NULLABLE_STRING_TYPE_INFO = getTypeInfo(String.class, true);
public static final TypeInfo<Tuple0> NULLABLE_TUPLE0_TYPE_INFO = getTypeInfo(Tuple0.class, true); public static final TypeInfo<Tuple0> NULLABLE_TUPLE0_TYPE_INFO = getTypeInfo(Tuple0.class, true);
public static Object [] newArray(int length, TypeInfo typeInfo) { public abstract Object [] newArray(int length);
return (Object[]) Array.newInstance(((TypeInfoImpl)typeInfo).signature.klazz, length);
}
public static <T> TypeInfoProjection invariantProjection(final TypeInfo<T> typeInfo) { public static <T> TypeInfoProjection invariantProjection(final TypeInfo<T> typeInfo) {
return (TypeInfoProjection) typeInfo; return (TypeInfoProjection) typeInfo;
@@ -126,6 +124,11 @@ public abstract class TypeInfo<T> implements JetObject {
this.varIndex = varIndex; this.varIndex = varIndex;
} }
@Override
public Object[] newArray(int length) {
throw new UnsupportedOperationException();
}
@Override @Override
public Object getClassObject() { public Object getClassObject() {
throw new UnsupportedOperationException("Abstract TypeInfo"); throw new UnsupportedOperationException("Abstract TypeInfo");
@@ -209,6 +212,11 @@ public abstract class TypeInfo<T> implements JetObject {
return projections[index]; return projections[index];
} }
@Override
public Object[] newArray(int length) {
return (Object[]) Array.newInstance(signature.klazz, length);
}
public final Object getClassObject() { public final Object getClassObject() {
try { try {
final Class implClass = signature.klazz.getClassLoader().loadClass(signature.klazz.getCanonicalName()); final Class implClass = signature.klazz.getClassLoader().loadClass(signature.klazz.getCanonicalName());