change for 9 array classes
This commit is contained in:
@@ -301,6 +301,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
private abstract class ForLoopGenerator {
|
||||
protected JetForExpression expression;
|
||||
protected Type loopRangeType;
|
||||
protected JetType expressionType;
|
||||
protected VariableDescriptor parameterDescriptor;
|
||||
|
||||
public ForLoopGenerator(JetForExpression expression, Type loopRangeType) {
|
||||
@@ -308,6 +309,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
this.loopRangeType = loopRangeType;
|
||||
final JetParameter loopParameter = expression.getLoopParameter();
|
||||
this.parameterDescriptor = bindingContext.get(BindingContext.VALUE_PARAMETER, loopParameter);
|
||||
expressionType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression.getLoopRange());
|
||||
}
|
||||
|
||||
public void invoke() {
|
||||
@@ -364,7 +366,6 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
protected void generatePrologue() {
|
||||
myLengthVar = myMap.enterTemp();
|
||||
gen(expression.getLoopRange(), loopRangeType);
|
||||
derefArray(bindingContext.get(BindingContext.EXPRESSION_TYPE, expression.getLoopRange()));
|
||||
v.arraylength();
|
||||
v.store(myLengthVar, Type.INT_TYPE);
|
||||
myIndexVar = myMap.enterTemp();
|
||||
@@ -373,15 +374,16 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
}
|
||||
|
||||
protected void generateCondition(Type asmParamType, Label end) {
|
||||
Type arrayElParamType = state.getStandardLibrary().getArray().equals(expressionType.getConstructor().getDeclarationDescriptor()) ? JetTypeMapper.boxType(asmParamType): asmParamType;
|
||||
|
||||
v.load(myIndexVar, Type.INT_TYPE);
|
||||
v.load(myLengthVar, Type.INT_TYPE);
|
||||
v.ificmpge(end);
|
||||
|
||||
gen(expression.getLoopRange(), loopRangeType); // array
|
||||
derefArray(bindingContext.get(BindingContext.EXPRESSION_TYPE, expression.getLoopRange()));
|
||||
v.load(myIndexVar, Type.INT_TYPE);
|
||||
v.aload(asmParamType);
|
||||
StackValue.onStack(asmParamType).put(asmParamType, v);
|
||||
v.aload(arrayElParamType);
|
||||
StackValue.onStack(arrayElParamType).put(asmParamType, v);
|
||||
v.store(lookupLocal(parameterDescriptor), asmParamType);
|
||||
}
|
||||
|
||||
@@ -1626,10 +1628,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
//noinspection ConstantConditions
|
||||
JetType expressionType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression);
|
||||
type = typeMapper.mapType(expressionType, OwnerKind.IMPLEMENTATION);
|
||||
if (state.getStandardLibrary().getArray().equals(expressionType.getConstructor().getDeclarationDescriptor())) {
|
||||
if (type.getSort() == Type.ARRAY) {
|
||||
generateNewArray(expression, expressionType);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
ClassDescriptor classDecl = (ClassDescriptor) constructorDescriptor.getContainingDeclaration();
|
||||
|
||||
receiver.put(receiver.type, v);
|
||||
@@ -1692,43 +1693,20 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
}
|
||||
gen(args.get(0).getArgumentExpression(), Type.INT_TYPE);
|
||||
|
||||
JetType elementType = typeMapper.getGenericsElementType(arrayType);
|
||||
if(elementType != null) {
|
||||
generateTypeInfo(elementType);
|
||||
v.invokestatic("jet/arrays/JetArray", "newArray", "(ILjet/typeinfo/TypeInfo;)Ljet/arrays/JetArray;");
|
||||
}
|
||||
else {
|
||||
elementType = arrayType.getArguments().get(0).getType();
|
||||
JetStandardLibrary standardLibrary = state.getStandardLibrary();
|
||||
if (elementType.equals(standardLibrary.getIntType())) {
|
||||
v.invokestatic("jet/arrays/JetArray", "newIntArray", "(I)Ljet/arrays/JetIntArray;");
|
||||
}
|
||||
else if (elementType.equals(standardLibrary.getLongType())) {
|
||||
v.invokestatic("jet/arrays/JetArray", "newLongArray", "(I)Ljet/arrays/JetLongArray;");
|
||||
}
|
||||
else if (elementType.equals(standardLibrary.getShortType())) {
|
||||
v.invokestatic("jet/arrays/JetArray", "newShortArray", "(I)Ljet/arrays/JetShortArray;");
|
||||
}
|
||||
else if (elementType.equals(standardLibrary.getByteType())) {
|
||||
v.invokestatic("jet/arrays/JetArray", "newByteArray", "(I)Ljet/arrays/JetByteArray;");
|
||||
}
|
||||
else if (elementType.equals(standardLibrary.getCharType())) {
|
||||
v.invokestatic("jet/arrays/JetArray", "newCharArray", "(I)Ljet/arrays/JetCharArray;");
|
||||
}
|
||||
else if (elementType.equals(standardLibrary.getFloatType())) {
|
||||
v.invokestatic("jet/arrays/JetArray", "newFloatArray", "(I)Ljet/arrays/JetFloatArray;");
|
||||
}
|
||||
else if (elementType.equals(standardLibrary.getDoubleType())) {
|
||||
v.invokestatic("jet/arrays/JetArray", "newDoubleArray", "(I)Ljet/arrays/JetDoubleArray;");
|
||||
}
|
||||
else if (elementType.equals(standardLibrary.getBooleanType())) {
|
||||
v.invokestatic("jet/arrays/JetArray", "newBoolArray", "(I)Ljet/arrays/JetBoolArray;");
|
||||
if(state.getStandardLibrary().getArray().equals(arrayType.getConstructor().getDeclarationDescriptor())) {
|
||||
JetType elementType = typeMapper.getGenericsElementType(arrayType);
|
||||
if(elementType != null) {
|
||||
generateTypeInfo(elementType);
|
||||
v.invokestatic("jet/typeinfo/TypeInfo", "newArray", "(ILjet/typeinfo/TypeInfo;)[Ljava/lang/Object;");
|
||||
}
|
||||
else {
|
||||
generateTypeInfo(elementType);
|
||||
v.invokestatic("jet/arrays/JetArray", "newGenericArray", "(ILjet/typeinfo/TypeInfo;)Ljet/arrays/JetGenericArray;");
|
||||
v.newarray(JetTypeMapper.boxType(typeMapper.mapType(arrayType.getArguments().get(0).getType())));
|
||||
}
|
||||
}
|
||||
else {
|
||||
Type type = typeMapper.mapType(arrayType, OwnerKind.IMPLEMENTATION);
|
||||
v.newarray(type.getElementType());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1737,11 +1715,17 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
JetType type = bindingContext.get(BindingContext.EXPRESSION_TYPE, array);
|
||||
final Type arrayType = type == null ? Type.VOID_TYPE : typeMapper.mapType(type);
|
||||
gen(array, arrayType);
|
||||
derefArray(type);
|
||||
generateArrayIndex(expression);
|
||||
if (state.getStandardLibrary().getArray().equals(type.getConstructor().getDeclarationDescriptor())) {
|
||||
JetType elementType = type.getArguments().get(0).getType();
|
||||
return StackValue.arrayElement(typeMapper.mapType(elementType), typeMapper.isGenericsArray(type));
|
||||
if (arrayType.getSort() == Type.ARRAY) {
|
||||
if(state.getStandardLibrary().getArray().equals(type.getConstructor().getDeclarationDescriptor())) {
|
||||
JetType elementType = type.getArguments().get(0).getType();
|
||||
Type notBoxed = typeMapper.mapType(elementType);
|
||||
Type boxed = JetTypeMapper.boxType(notBoxed);
|
||||
return StackValue.arrayElement(notBoxed, true);
|
||||
}
|
||||
else {
|
||||
return StackValue.arrayElement(arrayType.getElementType(), false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
final PsiElement declaration = BindingContextUtils.resolveToDeclarationPsiElement(bindingContext, expression);
|
||||
@@ -1764,7 +1748,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
}
|
||||
}
|
||||
|
||||
public void derefArray(JetType type) {
|
||||
public void _derefArray(JetType type) {
|
||||
if (state.getStandardLibrary().getArray().equals(type.getConstructor().getDeclarationDescriptor())) {
|
||||
JetType elementType = type.getArguments().get(0).getType();
|
||||
JetStandardLibrary standardLibrary = state.getStandardLibrary();
|
||||
|
||||
@@ -40,15 +40,15 @@ public class JetTypeMapper {
|
||||
public static final Type JL_NUMBER_TYPE = Type.getObjectType("java/lang/Number");
|
||||
public static final Type JL_STRING_BUILDER = Type.getObjectType("java/lang/StringBuilder");
|
||||
|
||||
public static final Type ARRAY_INT_TYPE = Type.getObjectType("jet/arrays/JetIntArray");
|
||||
public static final Type ARRAY_LONG_TYPE = Type.getObjectType("jet/arrays/JetLongArray");
|
||||
public static final Type ARRAY_SHORT_TYPE = Type.getObjectType("jet/arrays/JetShortArray");
|
||||
public static final Type ARRAY_BYTE_TYPE = Type.getObjectType("jet/arrays/JetByteArray");
|
||||
public static final Type ARRAY_CHAR_TYPE = Type.getObjectType("jet/arrays/JetCharArray");
|
||||
public static final Type ARRAY_FLOAT_TYPE = Type.getObjectType("jet/arrays/JetFloatArray");
|
||||
public static final Type ARRAY_DOUBLE_TYPE = Type.getObjectType("jet/arrays/JetDoubleArray");
|
||||
public static final Type ARRAY_BOOL_TYPE = Type.getObjectType("jet/arrays/JetBoolArray");
|
||||
public static final Type ARRAY_GENERIC_TYPE = Type.getObjectType("jet/arrays/JetGenericArray");
|
||||
public static final Type ARRAY_INT_TYPE = Type.getType(int[].class);
|
||||
public static final Type ARRAY_LONG_TYPE = Type.getType(long[].class);
|
||||
public static final Type ARRAY_SHORT_TYPE = Type.getType(short[].class);
|
||||
public static final Type ARRAY_BYTE_TYPE = Type.getType(byte[].class);
|
||||
public static final Type ARRAY_CHAR_TYPE = Type.getType(char[].class);
|
||||
public static final Type ARRAY_FLOAT_TYPE = Type.getType(float[].class);
|
||||
public static final Type ARRAY_DOUBLE_TYPE = Type.getType(double[].class);
|
||||
public static final Type ARRAY_BOOL_TYPE = Type.getType(boolean[].class);
|
||||
public static final Type ARRAY_GENERIC_TYPE = Type.getType(Object[].class);
|
||||
|
||||
private final JetStandardLibrary standardLibrary;
|
||||
private final BindingContext bindingContext;
|
||||
@@ -56,7 +56,6 @@ public class JetTypeMapper {
|
||||
private final Map<String, Integer> anonymousSubclassesCount = new HashMap<String, Integer>();
|
||||
|
||||
private final HashMap<JetType,String> knowTypes = new HashMap<JetType, String>();
|
||||
private final HashMap<JetType,String> knowArrayTypes = new HashMap<JetType, String>();
|
||||
|
||||
public JetTypeMapper(JetStandardLibrary standardLibrary, BindingContext bindingContext) {
|
||||
this.standardLibrary = standardLibrary;
|
||||
@@ -383,41 +382,41 @@ public class JetTypeMapper {
|
||||
return Type.getType(String.class);
|
||||
}
|
||||
|
||||
if(jetType.equals(standardLibrary.getByteArrayType())){
|
||||
return ARRAY_BYTE_TYPE;
|
||||
}
|
||||
if(jetType.equals(standardLibrary.getShortArrayType())){
|
||||
return ARRAY_SHORT_TYPE;
|
||||
}
|
||||
if(jetType.equals(standardLibrary.getIntArrayType())){
|
||||
return ARRAY_INT_TYPE;
|
||||
}
|
||||
if(jetType.equals(standardLibrary.getLongArrayType())){
|
||||
return ARRAY_LONG_TYPE;
|
||||
}
|
||||
if(jetType.equals(standardLibrary.getFloatArrayType())){
|
||||
return ARRAY_FLOAT_TYPE;
|
||||
}
|
||||
if(jetType.equals(standardLibrary.getDoubleArrayType())){
|
||||
return ARRAY_DOUBLE_TYPE;
|
||||
}
|
||||
if(jetType.equals(standardLibrary.getCharArrayType())){
|
||||
return ARRAY_CHAR_TYPE;
|
||||
}
|
||||
if(jetType.equals(standardLibrary.getBooleanArrayType())){
|
||||
return ARRAY_BOOL_TYPE;
|
||||
}
|
||||
|
||||
DeclarationDescriptor descriptor = jetType.getConstructor().getDeclarationDescriptor();
|
||||
if (standardLibrary.getArray().equals(descriptor)) {
|
||||
if (jetType.getArguments().size() != 1) {
|
||||
throw new UnsupportedOperationException("arrays must have one type argument");
|
||||
}
|
||||
JetType memberType = jetType.getArguments().get(0).getType();
|
||||
|
||||
if (memberType.equals(standardLibrary.getIntType())) {
|
||||
return ARRAY_INT_TYPE;
|
||||
}
|
||||
if (memberType.equals(standardLibrary.getLongType())) {
|
||||
return ARRAY_LONG_TYPE;
|
||||
}
|
||||
if (memberType.equals(standardLibrary.getShortType())) {
|
||||
return ARRAY_SHORT_TYPE;
|
||||
}
|
||||
if (memberType.equals(standardLibrary.getByteType())) {
|
||||
return ARRAY_BYTE_TYPE;
|
||||
}
|
||||
if (memberType.equals(standardLibrary.getCharType())) {
|
||||
return ARRAY_CHAR_TYPE;
|
||||
}
|
||||
if (memberType.equals(standardLibrary.getFloatType())) {
|
||||
return ARRAY_FLOAT_TYPE;
|
||||
}
|
||||
if (memberType.equals(standardLibrary.getDoubleType())) {
|
||||
return ARRAY_DOUBLE_TYPE;
|
||||
}
|
||||
if (memberType.equals(standardLibrary.getBooleanType())) {
|
||||
return ARRAY_BOOL_TYPE;
|
||||
}
|
||||
if(!isGenericsArray(jetType))
|
||||
return ARRAY_GENERIC_TYPE;
|
||||
return Type.getType("[" + boxType(mapType(memberType, kind)).getDescriptor());
|
||||
else
|
||||
return TYPE_OBJECT;
|
||||
return ARRAY_GENERIC_TYPE;
|
||||
}
|
||||
if (JetStandardClasses.getAny().equals(descriptor)) {
|
||||
return Type.getType(Object.class);
|
||||
@@ -704,20 +703,17 @@ public class JetTypeMapper {
|
||||
knowTypes.put(standardLibrary.getTuple0Type(),"TUPLE0_TYPE_INFO");
|
||||
knowTypes.put(standardLibrary.getNullableTuple0Type(),"NULLABLE_TUPLE0_TYPE_INFO");
|
||||
|
||||
knowArrayTypes.put(standardLibrary.getIntType(), "INT_ARRAY_TYPE_INFO");
|
||||
knowArrayTypes.put(standardLibrary.getLongType(), "LONG_ARRAY_TYPE_INFO");
|
||||
knowArrayTypes.put(standardLibrary.getShortType(),"SHORT_ARRAY_TYPE_INFO");
|
||||
knowArrayTypes.put(standardLibrary.getByteType(),"BYTE_ARRAY_TYPE_INFO");
|
||||
knowArrayTypes.put(standardLibrary.getCharType(),"CHAR_ARRAY_TYPE_INFO");
|
||||
knowArrayTypes.put(standardLibrary.getFloatType(),"FLOAT_ARRAY_TYPE_INFO");
|
||||
knowArrayTypes.put(standardLibrary.getDoubleType(),"DOUBLE_ARRAY_TYPE_INFO");
|
||||
knowArrayTypes.put(standardLibrary.getBooleanType(),"BOOLEAN_ARRAY_TYPE_INFO");
|
||||
knowTypes.put(standardLibrary.getIntArrayType(), "INT_ARRAY_TYPE_INFO");
|
||||
knowTypes.put(standardLibrary.getLongArrayType(), "LONG_ARRAY_TYPE_INFO");
|
||||
knowTypes.put(standardLibrary.getShortArrayType(),"SHORT_ARRAY_TYPE_INFO");
|
||||
knowTypes.put(standardLibrary.getByteArrayType(),"BYTE_ARRAY_TYPE_INFO");
|
||||
knowTypes.put(standardLibrary.getCharArrayType(),"CHAR_ARRAY_TYPE_INFO");
|
||||
knowTypes.put(standardLibrary.getFloatArrayType(),"FLOAT_ARRAY_TYPE_INFO");
|
||||
knowTypes.put(standardLibrary.getDoubleArrayType(),"DOUBLE_ARRAY_TYPE_INFO");
|
||||
knowTypes.put(standardLibrary.getBooleanArrayType(),"BOOLEAN_ARRAY_TYPE_INFO");
|
||||
}
|
||||
|
||||
public String isKnownTypeInfo(JetType jetType) {
|
||||
if(standardLibrary.getArray().equals(jetType.getConstructor().getDeclarationDescriptor()))
|
||||
return knowArrayTypes.get(jetType.getArguments().get(0).getType());
|
||||
|
||||
return knowTypes.get(jetType);
|
||||
}
|
||||
|
||||
|
||||
@@ -75,8 +75,8 @@ public abstract class StackValue {
|
||||
return new Invert(stackValue);
|
||||
}
|
||||
|
||||
public static StackValue arrayElement(Type type, boolean genericsArray) {
|
||||
return new ArrayElement(type, genericsArray);
|
||||
public static StackValue arrayElement(Type type, boolean unbox) {
|
||||
return new ArrayElement(type, unbox);
|
||||
}
|
||||
|
||||
public static StackValue collectionElement(Type type, CallableMethod getter, CallableMethod setter) {
|
||||
@@ -424,32 +424,23 @@ public abstract class StackValue {
|
||||
}
|
||||
|
||||
private static class ArrayElement extends StackValue {
|
||||
private boolean genericsArray;
|
||||
private Type boxed;
|
||||
|
||||
public ArrayElement(Type type, boolean genericsArray) {
|
||||
public ArrayElement(Type type, boolean unbox) {
|
||||
super(type);
|
||||
this.genericsArray = genericsArray;
|
||||
this.boxed = unbox ? JetTypeMapper.boxType(type) : type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(Type type, InstructionAdapter v) {
|
||||
if(genericsArray) {
|
||||
v.invokevirtual("jet/arrays/JetArray", "get", "(I)Ljava/lang/Object;");
|
||||
}
|
||||
else {
|
||||
v.aload(this.type); // assumes array and index are on the stack
|
||||
}
|
||||
coerce(type, v);
|
||||
v.aload(boxed); // assumes array and index are on the stack
|
||||
onStack(boxed).coerce(type, v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(InstructionAdapter v) {
|
||||
if(genericsArray) {
|
||||
v.invokevirtual("jet/arrays/JetArray", "set", "(ILjava/lang/Object;)V");
|
||||
}
|
||||
else {
|
||||
v.astore(type); // assumes array and index are on the stack
|
||||
}
|
||||
onStack(type).coerce(boxed, v);
|
||||
v.astore(boxed);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,32 +18,7 @@ public class ArraySize implements IntrinsicMethod {
|
||||
@Override
|
||||
public StackValue generate(ExpressionCodegen codegen, InstructionAdapter v, Type expectedType, PsiElement element, List<JetExpression> arguments, StackValue receiver) {
|
||||
receiver.put(JetTypeMapper.TYPE_OBJECT, v);
|
||||
if(receiver.type.equals(JetTypeMapper.TYPE_OBJECT)) {
|
||||
v.visitTypeInsn(Opcodes.CHECKCAST, "jet/arrays/JetArray");
|
||||
v.invokevirtual("jet/arrays/JetArray", "getSize", "()I");
|
||||
}
|
||||
else {
|
||||
if(receiver.type.equals(JetTypeMapper.ARRAY_BYTE_TYPE))
|
||||
v.getfield(receiver.type.getInternalName(), "array", "[B");
|
||||
else if(receiver.type.equals(JetTypeMapper.ARRAY_SHORT_TYPE))
|
||||
v.getfield(receiver.type.getInternalName(), "array", "[S");
|
||||
else if(receiver.type.equals(JetTypeMapper.ARRAY_INT_TYPE))
|
||||
v.getfield(receiver.type.getInternalName(), "array", "[I");
|
||||
else if(receiver.type.equals(JetTypeMapper.ARRAY_LONG_TYPE))
|
||||
v.getfield(receiver.type.getInternalName(), "array", "[J");
|
||||
else if(receiver.type.equals(JetTypeMapper.ARRAY_FLOAT_TYPE))
|
||||
v.getfield(receiver.type.getInternalName(), "array", "[F");
|
||||
else if(receiver.type.equals(JetTypeMapper.ARRAY_DOUBLE_TYPE))
|
||||
v.getfield(receiver.type.getInternalName(), "array", "[D");
|
||||
else if(receiver.type.equals(JetTypeMapper.ARRAY_CHAR_TYPE))
|
||||
v.getfield(receiver.type.getInternalName(), "array", "[C");
|
||||
else if(receiver.type.equals(JetTypeMapper.ARRAY_BOOL_TYPE))
|
||||
v.getfield(receiver.type.getInternalName(), "array", "[Z");
|
||||
else
|
||||
v.getfield("jet/arrays/JetGenericArray", "array", "[Ljava/lang/Object;");
|
||||
|
||||
v.arraylength();
|
||||
}
|
||||
v.arraylength();
|
||||
|
||||
return StackValue.onStack(Type.INT_TYPE);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ public class IntrinsicMethods {
|
||||
private static final IntrinsicMethod DEC = new Increment(-1);
|
||||
|
||||
private static final List<String> PRIMITIVE_NUMBER_TYPES = ImmutableList.of("Boolean", "Byte", "Char", "Short", "Int", "Float", "Long", "Double");
|
||||
public static final ArraySize ARRAY_SIZE = new ArraySize();
|
||||
|
||||
private final Project myProject;
|
||||
private final JetStandardLibrary myStdLib;
|
||||
@@ -41,7 +42,6 @@ public class IntrinsicMethods {
|
||||
for (String method : primitiveCastMethods) {
|
||||
declareIntrinsicProperty("Number", method, NUMBER_CAST);
|
||||
}
|
||||
declareIntrinsicProperty("Array", "size", new ArraySize());
|
||||
|
||||
for (String type : PRIMITIVE_NUMBER_TYPES) {
|
||||
declareIntrinsicFunction(type, "minus", 0, UNARY_MINUS);
|
||||
@@ -73,6 +73,20 @@ public class IntrinsicMethods {
|
||||
|
||||
declareIntrinsicStringMethods();
|
||||
declareIntrinsicProperty("String", "length", new StringLength());
|
||||
|
||||
declareArrayMethods();
|
||||
}
|
||||
|
||||
private void declareArrayMethods() {
|
||||
declareIntrinsicProperty("Array", "size", ARRAY_SIZE);
|
||||
declareIntrinsicProperty("ByteArray", "size", ARRAY_SIZE);
|
||||
declareIntrinsicProperty("ShortArray", "size", ARRAY_SIZE);
|
||||
declareIntrinsicProperty("IntArray", "size", ARRAY_SIZE);
|
||||
declareIntrinsicProperty("LongArray", "size", ARRAY_SIZE);
|
||||
declareIntrinsicProperty("FloatArray", "size", ARRAY_SIZE);
|
||||
declareIntrinsicProperty("DoubleArray", "size", ARRAY_SIZE);
|
||||
declareIntrinsicProperty("CharArray", "size", ARRAY_SIZE);
|
||||
declareIntrinsicProperty("BooleanArray", "size", ARRAY_SIZE);
|
||||
}
|
||||
|
||||
private void declareIntrinsicStringMethods() {
|
||||
|
||||
+16
-1
@@ -114,7 +114,14 @@ public class JavaTypeTransformer {
|
||||
|
||||
@Override
|
||||
public JetType visitArrayType(PsiArrayType arrayType) {
|
||||
JetType type = transformToType(arrayType.getComponentType());
|
||||
PsiType componentType = arrayType.getComponentType();
|
||||
if(componentType instanceof PsiPrimitiveType) {
|
||||
JetType jetType = getPrimitiveTypesMap().get("[" + componentType.getCanonicalText());
|
||||
if(jetType != null)
|
||||
return TypeUtils.makeNullable(jetType);
|
||||
}
|
||||
|
||||
JetType type = transformToType(componentType);
|
||||
return TypeUtils.makeNullable(standardLibrary.getArrayType(type));
|
||||
}
|
||||
|
||||
@@ -136,6 +143,14 @@ public class JavaTypeTransformer {
|
||||
primitiveTypesMap.put("float", standardLibrary.getFloatType());
|
||||
primitiveTypesMap.put("double", standardLibrary.getDoubleType());
|
||||
primitiveTypesMap.put("boolean", standardLibrary.getBooleanType());
|
||||
primitiveTypesMap.put("[byte", standardLibrary.getByteArrayType());
|
||||
primitiveTypesMap.put("[short", standardLibrary.getShortArrayType());
|
||||
primitiveTypesMap.put("[char", standardLibrary.getCharArrayType());
|
||||
primitiveTypesMap.put("[int", standardLibrary.getIntArrayType());
|
||||
primitiveTypesMap.put("[long", standardLibrary.getLongArrayType());
|
||||
primitiveTypesMap.put("[float", standardLibrary.getFloatArrayType());
|
||||
primitiveTypesMap.put("[double", standardLibrary.getDoubleArrayType());
|
||||
primitiveTypesMap.put("[boolean", standardLibrary.getBooleanArrayType());
|
||||
primitiveTypesMap.put("void", JetStandardClasses.getUnitType());
|
||||
primitiveTypesMap.put("java.lang.Byte", TypeUtils.makeNullable(standardLibrary.getByteType()));
|
||||
primitiveTypesMap.put("java.lang.Short", TypeUtils.makeNullable(standardLibrary.getShortType()));
|
||||
|
||||
@@ -56,6 +56,62 @@ class Array<T>(val size : Int) {
|
||||
fun iterator() : Iterator<T>
|
||||
}
|
||||
|
||||
class ByteArray(val size : Int) {
|
||||
fun get(index : Int) : Byte
|
||||
fun set(index : Int, value : Byte) : Unit
|
||||
|
||||
fun iterator() : Iterator<Byte>
|
||||
}
|
||||
|
||||
class ShortArray(val size : Int) {
|
||||
fun get(index : Int) : Short
|
||||
fun set(index : Int, value : Short) : Unit
|
||||
|
||||
fun iterator() : Iterator<Short>
|
||||
}
|
||||
|
||||
class IntArray(val size : Int) {
|
||||
fun get(index : Int) : Int
|
||||
fun set(index : Int, value : Int) : Unit
|
||||
|
||||
fun iterator() : Iterator<Int>
|
||||
}
|
||||
|
||||
class LongArray(val size : Int) {
|
||||
fun get(index : Int) : Long
|
||||
fun set(index : Int, value : Long) : Unit
|
||||
|
||||
fun iterator() : Iterator<Long>
|
||||
}
|
||||
|
||||
class FloatArray(val size : Int) {
|
||||
fun get(index : Int) : Float
|
||||
fun set(index : Int, value : Float) : Unit
|
||||
|
||||
fun iterator() : Iterator<Float>
|
||||
}
|
||||
|
||||
class DoubleArray(val size : Int) {
|
||||
fun get(index : Int) : Double
|
||||
fun set(index : Int, value : Double) : Unit
|
||||
|
||||
fun iterator() : Iterator<Double>
|
||||
}
|
||||
|
||||
class CharArray(val size : Int) {
|
||||
fun get(index : Int) : Char
|
||||
fun set(index : Int, value : Char) : Unit
|
||||
|
||||
fun iterator() : Iterator<Char>
|
||||
}
|
||||
|
||||
class BooleanArray(val size : Int) {
|
||||
fun get(index : Int) : Boolean
|
||||
fun set(index : Int, value : Boolean) : Unit
|
||||
|
||||
fun iterator() : Iterator<Boolean>
|
||||
}
|
||||
|
||||
trait Comparable<in T> {
|
||||
fun compareTo(other : T) : Int
|
||||
}
|
||||
|
||||
@@ -82,6 +82,24 @@ public class JetStandardLibrary {
|
||||
private final JetType nullableBooleanType;
|
||||
private final JetType nullableTuple0Type;
|
||||
|
||||
private final ClassDescriptor byteArrayClass;
|
||||
private final ClassDescriptor charArrayClass;
|
||||
private final ClassDescriptor shortArrayClass;
|
||||
private final ClassDescriptor intArrayClass;
|
||||
private final ClassDescriptor longArrayClass;
|
||||
private final ClassDescriptor floatArrayClass;
|
||||
private final ClassDescriptor doubleArrayClass;
|
||||
private final ClassDescriptor booleanArrayClass;
|
||||
|
||||
private final JetType byteArrayType;
|
||||
private final JetType charArrayType;
|
||||
private final JetType shortArrayType;
|
||||
private final JetType intArrayType;
|
||||
private final JetType longArrayType;
|
||||
private final JetType floatArrayType;
|
||||
private final JetType doubleArrayType;
|
||||
private final JetType booleanArrayType;
|
||||
|
||||
public JetType getTuple0Type() {
|
||||
return tuple0Type;
|
||||
}
|
||||
@@ -136,6 +154,24 @@ public class JetStandardLibrary {
|
||||
this.stringType = new JetTypeImpl(getString());
|
||||
this.tuple0Type = new JetTypeImpl(JetStandardClasses.getTuple(0));
|
||||
|
||||
this.byteArrayClass = (ClassDescriptor) libraryScope.getClassifier("ByteArray");
|
||||
this.charArrayClass = (ClassDescriptor) libraryScope.getClassifier("CharArray");
|
||||
this.shortArrayClass = (ClassDescriptor) libraryScope.getClassifier("ShortArray");
|
||||
this.intArrayClass = (ClassDescriptor) libraryScope.getClassifier("IntArray");
|
||||
this.longArrayClass = (ClassDescriptor) libraryScope.getClassifier("LongArray");
|
||||
this.floatArrayClass = (ClassDescriptor) libraryScope.getClassifier("FloatArray");
|
||||
this.doubleArrayClass = (ClassDescriptor) libraryScope.getClassifier("DoubleArray");
|
||||
this.booleanArrayClass = (ClassDescriptor) libraryScope.getClassifier("BooleanArray");
|
||||
|
||||
this.byteArrayType = new JetTypeImpl(byteArrayClass);
|
||||
this.charArrayType = new JetTypeImpl(charArrayClass);
|
||||
this.shortArrayType = new JetTypeImpl(shortArrayClass);
|
||||
this.intArrayType = new JetTypeImpl(intArrayClass);
|
||||
this.longArrayType = new JetTypeImpl(longArrayClass);
|
||||
this.floatArrayType = new JetTypeImpl(floatArrayClass);
|
||||
this.doubleArrayType = new JetTypeImpl(doubleArrayClass);
|
||||
this.booleanArrayType = new JetTypeImpl(booleanArrayClass);
|
||||
|
||||
this.nullableByteType = TypeUtils.makeNullable(byteType);
|
||||
this.nullableCharType = TypeUtils.makeNullable(charType);
|
||||
this.nullableShortType = TypeUtils.makeNullable(shortType);
|
||||
@@ -343,4 +379,68 @@ public class JetStandardLibrary {
|
||||
public JetType getNullableTuple0Type() {
|
||||
return nullableTuple0Type;
|
||||
}
|
||||
|
||||
public JetType getBooleanArrayType() {
|
||||
return booleanArrayType;
|
||||
}
|
||||
|
||||
public JetType getByteArrayType() {
|
||||
return byteArrayType;
|
||||
}
|
||||
|
||||
public JetType getCharArrayType() {
|
||||
return charArrayType;
|
||||
}
|
||||
|
||||
public JetType getShortArrayType() {
|
||||
return shortArrayType;
|
||||
}
|
||||
|
||||
public JetType getIntArrayType() {
|
||||
return intArrayType;
|
||||
}
|
||||
|
||||
public JetType getLongArrayType() {
|
||||
return longArrayType;
|
||||
}
|
||||
|
||||
public JetType getFloatArrayType() {
|
||||
return floatArrayType;
|
||||
}
|
||||
|
||||
public JetType getDoubleArrayType() {
|
||||
return doubleArrayType;
|
||||
}
|
||||
|
||||
public ClassDescriptor getByteArrayClass() {
|
||||
return byteArrayClass;
|
||||
}
|
||||
|
||||
public ClassDescriptor getCharArrayClass() {
|
||||
return charArrayClass;
|
||||
}
|
||||
|
||||
public ClassDescriptor getShortArrayClass() {
|
||||
return shortArrayClass;
|
||||
}
|
||||
|
||||
public ClassDescriptor getIntArrayClass() {
|
||||
return intArrayClass;
|
||||
}
|
||||
|
||||
public ClassDescriptor getLongArrayClass() {
|
||||
return longArrayClass;
|
||||
}
|
||||
|
||||
public ClassDescriptor getFloatArrayClass() {
|
||||
return floatArrayClass;
|
||||
}
|
||||
|
||||
public ClassDescriptor getDoubleArrayClass() {
|
||||
return doubleArrayClass;
|
||||
}
|
||||
|
||||
public ClassDescriptor getBooleanArrayClass() {
|
||||
return booleanArrayClass;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fun box() : String {
|
||||
val a : Array<Int> = Array<Int> (5)
|
||||
val a = Array<Int> (5)
|
||||
var i = 0
|
||||
var sum = 0
|
||||
for(el in 0..4) {
|
||||
|
||||
@@ -42,7 +42,7 @@ class B : `java::java.lang.Object`Object {
|
||||
fun <T> t(t : T) : T {
|
||||
`c`c(java.lang.Integer(1))
|
||||
System.out.`java::java.io.PrintStream.print(Object)`print(t)
|
||||
System.out.`java::java.io.PrintStream.print(char[])`print(null : Array<Char>?)
|
||||
System.out.`java::java.io.PrintStream.print(char[])`print(null : CharArray?)
|
||||
System.out.`java::java.io.PrintStream.print(Object)`print(null : Object?)
|
||||
System.out.`java::java.io.PrintStream.print(Int)`print(1)
|
||||
System.out.`java::java.io.PrintStream.print(Double)`print(1.0)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import jet.arrays.JetGenericArray;
|
||||
import jet.arrays.JetIntArray;
|
||||
import jet.typeinfo.TypeInfo;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ArrayGenTest extends CodegenTestCase {
|
||||
public void testKt238 () throws Exception {
|
||||
@@ -21,8 +21,7 @@ public class ArrayGenTest extends CodegenTestCase {
|
||||
Method foo = generateFunction();
|
||||
Object invoke = foo.invoke(null);
|
||||
System.out.println(invoke.getClass());
|
||||
assertTrue(invoke instanceof JetGenericArray);
|
||||
assertTrue(((JetGenericArray)invoke).getTypeInfo() == TypeInfo.INT_ARRAY_TYPE_INFO);
|
||||
assertTrue(invoke instanceof Integer[][]);
|
||||
}
|
||||
|
||||
public void testCreateMultiString () throws Exception {
|
||||
@@ -30,7 +29,7 @@ public class ArrayGenTest extends CodegenTestCase {
|
||||
Method foo = generateFunction();
|
||||
Object invoke = foo.invoke(null);
|
||||
System.out.println(invoke.getClass());
|
||||
assertTrue(invoke instanceof JetGenericArray);
|
||||
assertTrue(invoke instanceof Object[]);
|
||||
}
|
||||
|
||||
public void testCreateMultiGenerics () throws Exception {
|
||||
@@ -39,7 +38,7 @@ public class ArrayGenTest extends CodegenTestCase {
|
||||
Method foo = generateFunction();
|
||||
Object invoke = foo.invoke(null);
|
||||
System.out.println(invoke.getClass());
|
||||
assertTrue(invoke instanceof JetIntArray);
|
||||
assertTrue(invoke instanceof Integer[]);
|
||||
}
|
||||
|
||||
public void testIntGenerics () throws Exception {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import jet.arrays.JetGenericArray;
|
||||
import jet.typeinfo.TypeInfo;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@@ -92,7 +91,7 @@ public class ControlStructuresTest extends CodegenTestCase {
|
||||
System.out.println(generateToText());
|
||||
final Method main = generateFunction();
|
||||
String[] args = new String[] { "IntelliJ", " ", "IDEA" };
|
||||
assertEquals("IntelliJ IDEA", main.invoke(null, new Object[] { new JetGenericArray(args, TypeInfo.STRING_TYPE_INFO) }));
|
||||
assertEquals("IntelliJ IDEA", main.invoke(null, new Object[] { args }));
|
||||
}
|
||||
|
||||
public void testForInRange() throws Exception {
|
||||
|
||||
@@ -2,8 +2,6 @@ package org.jetbrains.jet.codegen;
|
||||
|
||||
import jet.IntRange;
|
||||
import jet.Tuple2;
|
||||
import jet.arrays.JetGenericArray;
|
||||
import jet.arrays.JetIntArray;
|
||||
import jet.typeinfo.TypeInfo;
|
||||
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||
|
||||
@@ -22,7 +20,7 @@ public class NamespaceGenTest extends CodegenTestCase {
|
||||
System.out.println(text);
|
||||
|
||||
final Method main = generateFunction();
|
||||
Object[] args = new Object[] { new JetGenericArray(0, TypeInfo.STRING_TYPE_INFO) };
|
||||
Object[] args = new Object[] { new String[0] };
|
||||
main.invoke(null, args);
|
||||
}
|
||||
|
||||
@@ -261,7 +259,7 @@ public class NamespaceGenTest extends CodegenTestCase {
|
||||
loadText("fun foo(s1: String, s2: String, s3: String) = s1 + s2 + s3");
|
||||
final String text = generateToText();
|
||||
final int firstStringBuilderCreation = text.indexOf("NEW java/lang/StringBuilder");
|
||||
assertEquals(-1, text.indexOf("NEW java/lang/StringBuilder", firstStringBuilderCreation+1));
|
||||
assertEquals(-1, text.indexOf("NEW java/lang/StringBuilder", firstStringBuilderCreation + 1));
|
||||
final Method main = generateFunction();
|
||||
assertEquals("jet Lang", main.invoke(null, "jet", " ", "Lang"));
|
||||
}
|
||||
@@ -346,14 +344,14 @@ public class NamespaceGenTest extends CodegenTestCase {
|
||||
public void testArrayRead() throws Exception {
|
||||
loadText("fun foo(c: Array<String>) = c[0]");
|
||||
final Method main = generateFunction();
|
||||
assertEquals("main", main.invoke(null, new Object[] { new JetGenericArray(new String[] { "main" }, TypeInfo.STRING_TYPE_INFO) }));
|
||||
assertEquals("main", main.invoke(null, new Object[]{new String[]{"main"}}));
|
||||
}
|
||||
|
||||
public void testArrayWrite() throws Exception {
|
||||
loadText("fun foo(c: Array<String>) { c[0] = \"jet\"; }");
|
||||
final Method main = generateFunction();
|
||||
String[] array = new String[] { null };
|
||||
main.invoke(null, new Object[] { new JetGenericArray(array, TypeInfo.STRING_TYPE_INFO) });
|
||||
main.invoke(null, new Object[] { array });
|
||||
assertEquals("jet", array[0]);
|
||||
}
|
||||
|
||||
@@ -361,27 +359,61 @@ public class NamespaceGenTest extends CodegenTestCase {
|
||||
loadText("fun foo(c: Array<Int>) { c[0] *= 2 }");
|
||||
System.out.println(generateToText());
|
||||
final Method main = generateFunction();
|
||||
int[] data = new int[] { 5 };
|
||||
main.invoke(null, new Object[] { new JetIntArray(data) });
|
||||
assertEquals(10, data[0]);
|
||||
Integer[] data = new Integer[] { 5 };
|
||||
main.invoke(null, new Object[] { data });
|
||||
assertEquals(10, data[0].intValue());
|
||||
}
|
||||
|
||||
public void testArrayAugAssignLong() throws Exception {
|
||||
loadText("fun foo(c: LongArray) { c[0] *= 2 }");
|
||||
System.out.println(generateToText());
|
||||
final Method main = generateFunction();
|
||||
long[] data = new long[] { 5 };
|
||||
main.invoke(null, new Object[] { data });
|
||||
assertEquals(10L, data[0]);
|
||||
}
|
||||
|
||||
public void testArrayNew() throws Exception {
|
||||
loadText("fun foo() = Array<Int>(4)");
|
||||
System.out.println(generateToText());
|
||||
final Method main = generateFunction();
|
||||
JetIntArray result = (JetIntArray) main.invoke(null);
|
||||
assertEquals(4, result.array.length);
|
||||
Integer[] result = (Integer[]) main.invoke(null);
|
||||
assertEquals(4, result.length);
|
||||
}
|
||||
|
||||
public void testFloatArrayNew() throws Exception {
|
||||
loadText("fun foo() = FloatArray(4)");
|
||||
System.out.println(generateToText());
|
||||
final Method main = generateFunction();
|
||||
float[] result = (float[]) main.invoke(null);
|
||||
assertEquals(4, result.length);
|
||||
}
|
||||
|
||||
public void testFloatArrayArrayNew() throws Exception {
|
||||
loadText("fun foo() = Array<FloatArray>(4)");
|
||||
System.out.println(generateToText());
|
||||
final Method main = generateFunction();
|
||||
float[][] result = (float[][]) main.invoke(null);
|
||||
assertEquals(4, result.length);
|
||||
}
|
||||
|
||||
public void testArraySize() throws Exception {
|
||||
loadText("fun foo(a: Array<Int>) = a.size");
|
||||
System.out.println(generateToText());
|
||||
final Method main = generateFunction();
|
||||
Object[] args = new Object[] { new JetIntArray(new int[4]) };
|
||||
Object[] args = new Object[] { new Integer[4] };
|
||||
int result = (Integer) main.invoke(null, args);
|
||||
System.out.println(result);
|
||||
assertEquals(4, result);
|
||||
}
|
||||
|
||||
public void testIntArraySize() throws Exception {
|
||||
loadText("fun foo(a: IntArray) = a.size");
|
||||
System.out.println(generateToText());
|
||||
final Method main = generateFunction();
|
||||
Object[] args = new Object[] { new int[4] };
|
||||
int result = (Integer) main.invoke(null, args);
|
||||
assertEquals(4, result);
|
||||
|
||||
}
|
||||
|
||||
public void testIntRange() throws Exception {
|
||||
@@ -499,7 +531,6 @@ public class NamespaceGenTest extends CodegenTestCase {
|
||||
final Method main = generateFunction();
|
||||
final String[] args = new String[] { "foo", "bar" };
|
||||
//noinspection ImplicitArrayToString
|
||||
JetGenericArray jetGenericArray = new JetGenericArray(args, TypeInfo.STRING_TYPE_INFO);
|
||||
assertEquals("s" + jetGenericArray.toString(), main.invoke(null, "s", jetGenericArray));
|
||||
assertEquals("s" + args.toString(), main.invoke(null, "s", args));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
package jet.arrays;
|
||||
|
||||
import jet.JetObject;
|
||||
import jet.typeinfo.TypeInfo;
|
||||
|
||||
public abstract class JetArray<T> implements JetObject {
|
||||
public abstract T get(int index);
|
||||
public abstract void set(int index, T value);
|
||||
public abstract int getSize();
|
||||
|
||||
public static JetArray newArray(int length, TypeInfo elementTypeInfo) {
|
||||
if(elementTypeInfo.equals(TypeInfo.BYTE_TYPE_INFO))
|
||||
return new JetByteArray(length);
|
||||
if(elementTypeInfo.equals(TypeInfo.SHORT_TYPE_INFO))
|
||||
return new JetShortArray(length);
|
||||
if(elementTypeInfo.equals(TypeInfo.INT_TYPE_INFO))
|
||||
return new JetIntArray(length);
|
||||
if(elementTypeInfo.equals(TypeInfo.LONG_TYPE_INFO))
|
||||
return new JetShortArray(length);
|
||||
if(elementTypeInfo.equals(TypeInfo.CHAR_TYPE_INFO))
|
||||
return new JetCharArray(length);
|
||||
if(elementTypeInfo.equals(TypeInfo.BOOL_TYPE_INFO))
|
||||
return new JetBoolArray(length);
|
||||
if(elementTypeInfo.equals(TypeInfo.FLOAT_TYPE_INFO))
|
||||
return new JetFloatArray(length);
|
||||
if(elementTypeInfo.equals(TypeInfo.DOUBLE_TYPE_INFO))
|
||||
return new JetDoubleArray(length);
|
||||
|
||||
return new JetGenericArray(length, elementTypeInfo);
|
||||
}
|
||||
|
||||
public static JetByteArray newByteArray(int length) {
|
||||
return new JetByteArray(length);
|
||||
}
|
||||
|
||||
public static JetShortArray newShortArray(int length) {
|
||||
return new JetShortArray(length);
|
||||
}
|
||||
|
||||
public static JetIntArray newIntArray(int length) {
|
||||
return new JetIntArray(length);
|
||||
}
|
||||
|
||||
public static JetLongArray newLongArray(int length) {
|
||||
return new JetLongArray(length);
|
||||
}
|
||||
|
||||
public static JetCharArray newCharArray(int length) {
|
||||
return new JetCharArray(length);
|
||||
}
|
||||
|
||||
public static JetBoolArray newBoolArray(int length) {
|
||||
return new JetBoolArray(length);
|
||||
}
|
||||
|
||||
public static JetFloatArray newFloatArray(int length) {
|
||||
return new JetFloatArray(length);
|
||||
}
|
||||
|
||||
public static JetDoubleArray newDoubleArray(int length) {
|
||||
return new JetDoubleArray(length);
|
||||
}
|
||||
|
||||
public static JetGenericArray newGenericArray(int length, TypeInfo typeInfo) {
|
||||
return new JetGenericArray(length, typeInfo);
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package jet.arrays;
|
||||
|
||||
import jet.typeinfo.TypeInfo;
|
||||
|
||||
public final class JetBoolArray extends JetArray<Boolean> {
|
||||
public final boolean[] array;
|
||||
|
||||
public JetBoolArray(boolean[] array) {
|
||||
this.array = array;
|
||||
}
|
||||
|
||||
public JetBoolArray(int length) {
|
||||
this.array = new boolean[length];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean get(int index) {
|
||||
return array[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int index, Boolean value) {
|
||||
array[index] = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return array.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeInfo<?> getTypeInfo() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package jet.arrays;
|
||||
|
||||
import jet.typeinfo.TypeInfo;
|
||||
|
||||
public final class JetByteArray extends JetArray<Byte> {
|
||||
public final byte[] array;
|
||||
|
||||
public JetByteArray(byte[] array) {
|
||||
this.array = array;
|
||||
}
|
||||
|
||||
public JetByteArray(int length) {
|
||||
this.array = new byte[length];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte get(int index) {
|
||||
return array[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int index, Byte value) {
|
||||
array[index] = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return array.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeInfo<?> getTypeInfo() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package jet.arrays;
|
||||
|
||||
import jet.typeinfo.TypeInfo;
|
||||
|
||||
public final class JetCharArray extends JetArray<Character> {
|
||||
public final char[] array;
|
||||
|
||||
public JetCharArray(char[] array) {
|
||||
this.array = array;
|
||||
}
|
||||
|
||||
public JetCharArray(int length) {
|
||||
this.array = new char[length];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Character get(int index) {
|
||||
return array[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int index, Character value) {
|
||||
array[index] = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return array.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeInfo<?> getTypeInfo() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package jet.arrays;
|
||||
|
||||
import jet.typeinfo.TypeInfo;
|
||||
|
||||
public final class JetDoubleArray extends JetArray<Double> {
|
||||
public final double[] array;
|
||||
|
||||
public JetDoubleArray(double[] array) {
|
||||
this.array = array;
|
||||
}
|
||||
|
||||
public JetDoubleArray(int length) {
|
||||
this.array = new double[length];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double get(int index) {
|
||||
return array[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int index, Double value) {
|
||||
array[index] = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return array.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeInfo<?> getTypeInfo() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package jet.arrays;
|
||||
|
||||
import jet.typeinfo.TypeInfo;
|
||||
|
||||
public final class JetFloatArray extends JetArray<Float> {
|
||||
public final float[] array;
|
||||
|
||||
public JetFloatArray(float[] array) {
|
||||
this.array = array;
|
||||
}
|
||||
|
||||
public JetFloatArray(int length) {
|
||||
this.array = new float[length];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float get(int index) {
|
||||
return array[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int index, Float value) {
|
||||
array[index] = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return array.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeInfo<?> getTypeInfo() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package jet.arrays;
|
||||
|
||||
import jet.typeinfo.TypeInfo;
|
||||
|
||||
public final class JetGenericArray<T> extends JetArray<T> {
|
||||
public final T[] array;
|
||||
private final TypeInfo<T> typeInfo;
|
||||
|
||||
public JetGenericArray(T[] array, TypeInfo<T> typeInfo) {
|
||||
this.array = array;
|
||||
this.typeInfo = typeInfo;
|
||||
}
|
||||
|
||||
public JetGenericArray(int length, TypeInfo<T> typeInfo) {
|
||||
this.array = (T[]) TypeInfo.newArray(length, typeInfo);
|
||||
this.typeInfo = typeInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(int index) {
|
||||
return array[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int index, T value) {
|
||||
array[index] = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return array.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeInfo<?> getTypeInfo() {
|
||||
return typeInfo;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package jet.arrays;
|
||||
|
||||
import jet.typeinfo.TypeInfo;
|
||||
|
||||
public final class JetIntArray extends JetArray<Integer> {
|
||||
public final int[] array;
|
||||
|
||||
public JetIntArray(int[] array) {
|
||||
this.array = array;
|
||||
}
|
||||
|
||||
public JetIntArray(int length) {
|
||||
this.array = new int[length];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer get(int index) {
|
||||
return array[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int index, Integer value) {
|
||||
array[index] = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return array.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeInfo<?> getTypeInfo() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package jet.arrays;
|
||||
|
||||
import jet.typeinfo.TypeInfo;
|
||||
|
||||
public final class JetLongArray extends JetArray<Long> {
|
||||
public final long[] array;
|
||||
|
||||
public JetLongArray(long[] array) {
|
||||
this.array = array;
|
||||
}
|
||||
|
||||
public JetLongArray(int length) {
|
||||
this.array = new long[length];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long get(int index) {
|
||||
return array[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int index, Long value) {
|
||||
array[index] = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return array.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeInfo<?> getTypeInfo() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package jet.arrays;
|
||||
|
||||
import jet.typeinfo.TypeInfo;
|
||||
|
||||
public final class JetShortArray extends JetArray<Short> {
|
||||
public final short[] array;
|
||||
|
||||
public JetShortArray(short[] array) {
|
||||
this.array = array;
|
||||
}
|
||||
|
||||
public JetShortArray(int length) {
|
||||
this.array = new short[length];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Short get(int index) {
|
||||
return array[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int index, Short value) {
|
||||
array[index] = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return array.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeInfo<?> getTypeInfo() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package jet.typeinfo;
|
||||
|
||||
import jet.JetObject;
|
||||
import jet.Tuple0;
|
||||
import jet.arrays.*;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Field;
|
||||
@@ -51,31 +50,7 @@ public abstract class TypeInfo<T> implements JetObject {
|
||||
public static final TypeInfo<Tuple0> NULLABLE_TUPLE0_TYPE_INFO = getTypeInfo(Tuple0.class, true);
|
||||
|
||||
public static Object [] newArray(int length, TypeInfo typeInfo) {
|
||||
Signature signature = ((TypeInfoImpl) typeInfo).signature;
|
||||
if(signature.klazz.isArray() && signature.klazz.getComponentType().isPrimitive()) {
|
||||
Class componentType = signature.klazz.getComponentType();
|
||||
if(componentType == byte.class)
|
||||
return (Object[]) Array.newInstance(JetByteArray.class, length);
|
||||
if(componentType == short.class)
|
||||
return (Object[]) Array.newInstance(JetShortArray.class, length);
|
||||
if(componentType == int.class)
|
||||
return (Object[]) Array.newInstance(JetIntArray.class, length);
|
||||
if(componentType == long.class)
|
||||
return (Object[]) Array.newInstance(JetLongArray.class, length);
|
||||
if(componentType == char.class)
|
||||
return (Object[]) Array.newInstance(JetCharArray.class, length);
|
||||
if(componentType == boolean.class)
|
||||
return (Object[]) Array.newInstance(JetBoolArray.class, length);
|
||||
if(componentType == float.class)
|
||||
return (Object[]) Array.newInstance(JetFloatArray.class, length);
|
||||
if(componentType == double.class)
|
||||
return (Object[]) Array.newInstance(JetDoubleArray.class, length);
|
||||
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
else {
|
||||
return (Object[]) Array.newInstance(signature.klazz, length);
|
||||
}
|
||||
return (Object[]) Array.newInstance(((TypeInfoImpl)typeInfo).signature.klazz, length);
|
||||
}
|
||||
|
||||
public static <T> TypeInfoProjection invariantProjection(final TypeInfo<T> typeInfo) {
|
||||
@@ -495,6 +470,12 @@ public abstract class TypeInfo<T> implements JetObject {
|
||||
}
|
||||
|
||||
private static Signature internalParse(Class klass) {
|
||||
if(klass.isArray() && !klass.getComponentType().isPrimitive()) {
|
||||
Signature signature = new ArraySignature(klass);
|
||||
map.put(klass, signature);
|
||||
return signature;
|
||||
}
|
||||
|
||||
JetSignature annotation = (JetSignature) klass.getAnnotation(JetSignature.class);
|
||||
if(annotation != null) {
|
||||
String value = annotation.value();
|
||||
@@ -710,5 +691,26 @@ public abstract class TypeInfo<T> implements JetObject {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static class ArraySignature extends Signature {
|
||||
public ArraySignature(Class klass) {
|
||||
super(null, klass);
|
||||
variables = new LinkedList<TypeInfoProjection>();
|
||||
varNames = new HashMap<String, Integer>();
|
||||
varNames.put("T", 0);
|
||||
final TypeInfoVar typeInfoVar = new TypeInfoVar(this, 0);
|
||||
variables.add(new TypeInfoProjection(){
|
||||
@Override
|
||||
public TypeInfoVariance getVariance() {
|
||||
return TypeInfoVariance.INVARIANT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeInfo getType() {
|
||||
return typeInfoVar;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user