big codegen rewrite
This commit is contained in:
@@ -28,30 +28,36 @@ public class ArrayGenTest extends CodegenTestCase {
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||
}
|
||||
|
||||
public void testKt238 () throws Exception {
|
||||
public void testKt238() throws Exception {
|
||||
blackBoxFile("regressions/kt238.jet");
|
||||
}
|
||||
|
||||
public void testKt326 () throws Exception {
|
||||
// blackBoxFile("regressions/kt326.jet");
|
||||
// System.out.println(generateToText());
|
||||
public void testKt326() throws Exception {
|
||||
// blackBoxFile("regressions/kt326.jet");
|
||||
// System.out.println(generateToText());
|
||||
}
|
||||
|
||||
public void testKt779 () throws Exception {
|
||||
public void testKt779() throws Exception {
|
||||
blackBoxFile("regressions/kt779.jet");
|
||||
// System.out.println(generateToText());
|
||||
// System.out.println(generateToText());
|
||||
}
|
||||
|
||||
public void testCreateMultiInt () throws Exception {
|
||||
public void testCreateMultiInt() throws Exception {
|
||||
loadText("fun foo() = Array<Array<Int>> (5, { Array<Int>(it, {239}) })");
|
||||
Method foo = generateFunction();
|
||||
Integer[][] invoke = (Integer[][]) foo.invoke(null);
|
||||
assertEquals(invoke[2].length, 2);
|
||||
assertEquals(invoke[4].length, 4);
|
||||
assertEquals(invoke[4][2].intValue(), 239);
|
||||
try {
|
||||
Integer[][] invoke = (Integer[][]) foo.invoke(null);
|
||||
assertEquals(invoke[2].length, 2);
|
||||
assertEquals(invoke[4].length, 4);
|
||||
assertEquals(invoke[4][2].intValue(), 239);
|
||||
}
|
||||
catch (Throwable e) {
|
||||
System.out.println(generateToText());
|
||||
throw ((e instanceof RuntimeException)) ? (RuntimeException) e : new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void testCreateMultiIntNullable () throws Exception {
|
||||
public void testCreateMultiIntNullable() throws Exception {
|
||||
loadText("fun foo() = Array<Array<Int?>> (5, { arrayOfNulls<Int>(it) })");
|
||||
Method foo = generateFunction();
|
||||
Integer[][] invoke = (Integer[][]) foo.invoke(null);
|
||||
@@ -59,7 +65,7 @@ public class ArrayGenTest extends CodegenTestCase {
|
||||
assertEquals(invoke[4].length, 4);
|
||||
}
|
||||
|
||||
public void testCreateMultiString () throws Exception {
|
||||
public void testCreateMultiString() throws Exception {
|
||||
loadText("fun foo() = Array<Array<String>> (5, { Array<String>(0,{\"\"}) })");
|
||||
Method foo = generateFunction();
|
||||
Object invoke = foo.invoke(null);
|
||||
@@ -67,16 +73,16 @@ public class ArrayGenTest extends CodegenTestCase {
|
||||
assertTrue(invoke instanceof Object[]);
|
||||
}
|
||||
|
||||
public void testCreateMultiGenerics () throws Exception {
|
||||
// loadText("class L<T>() { val a = Array<T?>(5) } fun foo() = L<Int>.a");
|
||||
// System.out.println(generateToText());
|
||||
// Method foo = generateFunction();
|
||||
// Object invoke = foo.invoke(null);
|
||||
// System.out.println(invoke.getClass());
|
||||
// assertTrue(invoke.getClass() == Object[].class);
|
||||
public void testCreateMultiGenerics() throws Exception {
|
||||
// loadText("class L<T>() { val a = Array<T?>(5) } fun foo() = L<Int>.a");
|
||||
// System.out.println(generateToText());
|
||||
// Method foo = generateFunction();
|
||||
// Object invoke = foo.invoke(null);
|
||||
// System.out.println(invoke.getClass());
|
||||
// assertTrue(invoke.getClass() == Object[].class);
|
||||
}
|
||||
|
||||
public void testIntGenerics () throws Exception {
|
||||
public void testIntGenerics() throws Exception {
|
||||
loadText("class L<T>(var a : T) {} fun foo() = L<Int>(5).a");
|
||||
//System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
@@ -85,221 +91,222 @@ public class ArrayGenTest extends CodegenTestCase {
|
||||
assertTrue(invoke instanceof Integer);
|
||||
}
|
||||
|
||||
public void testIterator () throws Exception {
|
||||
public void testIterator() throws Exception {
|
||||
loadText("fun box() { val x = Array<Int>(5, { it } ).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }");
|
||||
// System.out.println(generateToText());
|
||||
// System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testPrimitiveIterator () throws Exception {
|
||||
public void testPrimitiveIterator() throws Exception {
|
||||
loadText("fun box() { val x = ByteArray(5).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.nextByte()) } }");
|
||||
// System.out.println(generateToText());
|
||||
// System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testPrimitiveIteratorByte () throws Exception {
|
||||
public void testPrimitiveIteratorByte() throws Exception {
|
||||
loadText("fun box() { for(x in ByteArray(5)) { java.lang.System.out?.println(x) } }");
|
||||
// System.out.println(generateToText());
|
||||
// System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testPrimitiveIteratorShort () throws Exception {
|
||||
public void testPrimitiveIteratorShort() throws Exception {
|
||||
loadText("fun box() { for(x in ShortArray(5)) { java.lang.System.out?.println(x) } }");
|
||||
// System.out.println(generateToText());
|
||||
// System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testPrimitiveIteratorInt () throws Exception {
|
||||
public void testPrimitiveIteratorInt() throws Exception {
|
||||
loadText("fun box() { for(x in IntArray(5)) { java.lang.System.out?.println(x) } }");
|
||||
// System.out.println(generateToText());
|
||||
// System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testPrimitiveIteratorLong () throws Exception {
|
||||
public void testPrimitiveIteratorLong() throws Exception {
|
||||
loadText("fun box() { for(x in LongArray(5)) { java.lang.System.out?.println(x) } }");
|
||||
// System.out.println(generateToText());
|
||||
// System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testPrimitiveIteratorFloat () throws Exception {
|
||||
public void testPrimitiveIteratorFloat() throws Exception {
|
||||
loadText("fun box() { for(x in FloatArray(5)) { java.lang.System.out?.println(x) } }");
|
||||
// System.out.println(generateToText());
|
||||
// System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testPrimitiveIteratorDouble () throws Exception {
|
||||
public void testPrimitiveIteratorDouble() throws Exception {
|
||||
loadText("fun box() { for(x in DoubleArray(5)) { java.lang.System.out?.println(x) } }");
|
||||
// System.out.println(generateToText());
|
||||
// System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testPrimitiveIteratorChar () throws Exception {
|
||||
public void testPrimitiveIteratorChar() throws Exception {
|
||||
loadText("fun box() { for(x in CharArray(5)) { java.lang.System.out?.println(x) } }");
|
||||
// System.out.println(generateToText());
|
||||
// System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testPrimitiveIteratorBoolean () throws Exception {
|
||||
public void testPrimitiveIteratorBoolean() throws Exception {
|
||||
loadText("fun box() { for(x in BooleanArray(5)) { java.lang.System.out?.println(x) } }");
|
||||
// System.out.println(generateToText());
|
||||
// System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testLongIterator () throws Exception {
|
||||
public void testLongIterator() throws Exception {
|
||||
loadText("fun box() { val x = LongArray(5).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.nextLong()) } }");
|
||||
// System.out.println(generateToText());
|
||||
// System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testCharIterator () throws Exception {
|
||||
public void testCharIterator() throws Exception {
|
||||
loadText("fun box() { val x = CharArray(5).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }");
|
||||
// System.out.println(generateToText());
|
||||
// System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testByteIterator () throws Exception {
|
||||
public void testByteIterator() throws Exception {
|
||||
loadText("fun box() { val x = ByteArray(5).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }");
|
||||
// System.out.println(generateToText());
|
||||
// System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testShortIterator () throws Exception {
|
||||
public void testShortIterator() throws Exception {
|
||||
loadText("fun box() { val x = ShortArray(5).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }");
|
||||
// System.out.println(generateToText());
|
||||
// System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testIntIterator () throws Exception {
|
||||
public void testIntIterator() throws Exception {
|
||||
loadText("fun box() { val x = IntArray(5).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }");
|
||||
// System.out.println(generateToText());
|
||||
// System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testLongIterator2 () throws Exception {
|
||||
public void testLongIterator2() throws Exception {
|
||||
loadText("fun box() { val x = LongArray(5).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }");
|
||||
// System.out.println(generateToText());
|
||||
// System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testFloatIterator () throws Exception {
|
||||
public void testFloatIterator() throws Exception {
|
||||
loadText("fun box() { val x = FloatArray(5).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }");
|
||||
// System.out.println(generateToText());
|
||||
// System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testDoubleIterator () throws Exception {
|
||||
public void testDoubleIterator() throws Exception {
|
||||
loadText("fun box() { val x = ShortArray(5).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }");
|
||||
// System.out.println(generateToText());
|
||||
// System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testBooleanIterator () throws Exception {
|
||||
public void testBooleanIterator() throws Exception {
|
||||
loadText("fun box() { val x = BooleanArray(5).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }");
|
||||
// System.out.println(generateToText());
|
||||
// System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testArrayIndices () throws Exception {
|
||||
loadText("fun box() { val x = Array<Int>(5, {it}).indices.iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }");
|
||||
// System.out.println(generateToText());
|
||||
public void testArrayIndices() throws Exception {
|
||||
loadText(
|
||||
"fun box() { val x = Array<Int>(5, {it}).indices.iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }");
|
||||
// System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testCharIndices () throws Exception {
|
||||
public void testCharIndices() throws Exception {
|
||||
loadText("fun box() { val x = CharArray(5).indices.iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }");
|
||||
// System.out.println(generateToText());
|
||||
// System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testCollectionPlusAssign () throws Exception {
|
||||
public void testCollectionPlusAssign() throws Exception {
|
||||
blackBoxFile("regressions/kt33.jet");
|
||||
}
|
||||
|
||||
public void testArrayPlusAssign () throws Exception {
|
||||
public void testArrayPlusAssign() throws Exception {
|
||||
loadText("fun box() : Int { val s = IntArray(1); s [0] = 5; s[0] += 7; return s[0] }");
|
||||
// System.out.println(generateToText());
|
||||
// System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
assertTrue((Integer)foo.invoke(null) == 12);
|
||||
assertTrue((Integer) foo.invoke(null) == 12);
|
||||
}
|
||||
|
||||
public void testCollectionAssignGetMultiIndex () throws Exception {
|
||||
loadText("import java.util.ArrayList\n" +
|
||||
"fun box() : String { val s = ArrayList<String>(1); s.add(\"\"); s [1, -1] = \"5\"; s[2, -2] += \"7\"; return s[2,-2] }\n" +
|
||||
"fun ArrayList<String>.get(index1: Int, index2 : Int) = this[index1+index2]!!\n" +
|
||||
"fun ArrayList<String>.set(index1: Int, index2 : Int, elem: String) { this[index1+index2] = elem }\n");
|
||||
// System.out.println(generateToText());
|
||||
Method foo = generateFunction("box");
|
||||
assertTrue(foo.invoke(null).equals("57"));
|
||||
}
|
||||
|
||||
public void testArrayGetAssignMultiIndex () throws Exception {
|
||||
loadText(
|
||||
"fun box() : String? { val s = Array<String>(1,{ \"\" }); s [1, -1] = \"5\"; s[2, -2] += \"7\"; return s[-3,3] }\n" +
|
||||
"fun Array<String>.get(index1: Int, index2 : Int) = this[index1+index2]\n" +
|
||||
"fun Array<String>.set(index1: Int, index2 : Int, elem: String) { this[index1+index2] = elem\n }");
|
||||
// System.out.println(generateToText());
|
||||
public void testCollectionAssignGetMultiIndex() throws Exception {
|
||||
loadText("import java.util.ArrayList\n" +
|
||||
"fun box() : String { val s = ArrayList<String>(1); s.add(\"\"); s [1, -1] = \"5\"; s[2, -2] += \"7\"; return s[2,-2] }\n" +
|
||||
"fun ArrayList<String>.get(index1: Int, index2 : Int) = this[index1+index2]!!\n" +
|
||||
"fun ArrayList<String>.set(index1: Int, index2 : Int, elem: String) { this[index1+index2] = elem }\n");
|
||||
// System.out.println(generateToText());
|
||||
Method foo = generateFunction("box");
|
||||
assertTrue(foo.invoke(null).equals("57"));
|
||||
}
|
||||
|
||||
public void testCollectionGetMultiIndex () throws Exception {
|
||||
loadText("import java.util.ArrayList\n" +
|
||||
"fun box() : String { val s = ArrayList<String>(1); s.add(\"\"); s [1, -1] = \"5\"; return s[2, -2] }\n" +
|
||||
"fun ArrayList<String>.get(index1: Int, index2 : Int) = this[index1+index2]!!\n" +
|
||||
"fun ArrayList<String>.set(index1: Int, index2 : Int, elem: String) { this[index1+index2] = elem }\n");
|
||||
// System.out.println(generateToText());
|
||||
Method foo = generateFunction("box");
|
||||
assertTrue(foo.invoke(null).equals("5"));
|
||||
}
|
||||
|
||||
public void testArrayGetMultiIndex () throws Exception {
|
||||
public void testArrayGetAssignMultiIndex() throws Exception {
|
||||
loadText(
|
||||
"fun box() : String? { val s = Array<String>(1,{ \"\" }); s [1, -1] = \"5\"; return s[-2, 2] }\n" +
|
||||
"fun Array<String>.get(index1: Int, index2 : Int) = this[index1+index2]\n" +
|
||||
"fun Array<String>.set(index1: Int, index2 : Int, elem: String) { this[index1+index2] = elem\n }");
|
||||
// System.out.println(generateToText());
|
||||
"fun box() : String? { val s = Array<String>(1,{ \"\" }); s [1, -1] = \"5\"; s[2, -2] += \"7\"; return s[-3,3] }\n" +
|
||||
"fun Array<String>.get(index1: Int, index2 : Int) = this[index1+index2]\n" +
|
||||
"fun Array<String>.set(index1: Int, index2 : Int, elem: String) { this[index1+index2] = elem\n }");
|
||||
// System.out.println(generateToText());
|
||||
Method foo = generateFunction("box");
|
||||
assertTrue(foo.invoke(null).equals("57"));
|
||||
}
|
||||
|
||||
public void testCollectionGetMultiIndex() throws Exception {
|
||||
loadText("import java.util.ArrayList\n" +
|
||||
"fun box() : String { val s = ArrayList<String>(1); s.add(\"\"); s [1, -1] = \"5\"; return s[2, -2] }\n" +
|
||||
"fun ArrayList<String>.get(index1: Int, index2 : Int) = this[index1+index2]!!\n" +
|
||||
"fun ArrayList<String>.set(index1: Int, index2 : Int, elem: String) { this[index1+index2] = elem }\n");
|
||||
// System.out.println(generateToText());
|
||||
Method foo = generateFunction("box");
|
||||
assertTrue(foo.invoke(null).equals("5"));
|
||||
}
|
||||
|
||||
public void testMap () throws Exception {
|
||||
public void testArrayGetMultiIndex() throws Exception {
|
||||
loadText(
|
||||
"fun box() : Int? { val s = java.util.HashMap<String,Int?>(); s[\"239\"] = 239; return s[\"239\"] }\n" +
|
||||
"fun java.util.HashMap<String,Int?>.set(index: String, elem: Int?) { this.put(index, elem) }");
|
||||
// System.out.println(generateToText());
|
||||
"fun box() : String? { val s = Array<String>(1,{ \"\" }); s [1, -1] = \"5\"; return s[-2, 2] }\n" +
|
||||
"fun Array<String>.get(index1: Int, index2 : Int) = this[index1+index2]\n" +
|
||||
"fun Array<String>.set(index1: Int, index2 : Int, elem: String) { this[index1+index2] = elem\n }");
|
||||
// System.out.println(generateToText());
|
||||
Method foo = generateFunction("box");
|
||||
assertTrue((Integer)foo.invoke(null) == 239);
|
||||
assertTrue(foo.invoke(null).equals("5"));
|
||||
}
|
||||
|
||||
public void testLongDouble () throws Exception {
|
||||
public void testMap() throws Exception {
|
||||
loadText(
|
||||
"fun box() : Int { var l = IntArray(1); l[0.toLong()] = 4; l[0.toLong()] += 6; return l[0.toLong()];}\n" +
|
||||
"fun IntArray.set(index: Long, elem: Int) { this[index.toInt()] = elem }\n" +
|
||||
"fun IntArray.get(index: Long) = this[index.toInt()]");
|
||||
// System.out.println(generateToText());
|
||||
"fun box() : Int? { val s = java.util.HashMap<String,Int?>(); s[\"239\"] = 239; return s[\"239\"] }\n" +
|
||||
"fun java.util.HashMap<String,Int?>.set(index: String, elem: Int?) { this.put(index, elem) }");
|
||||
// System.out.println(generateToText());
|
||||
Method foo = generateFunction("box");
|
||||
assertTrue((Integer)foo.invoke(null) == 10);
|
||||
assertTrue((Integer) foo.invoke(null) == 239);
|
||||
}
|
||||
|
||||
public void testLongDouble() throws Exception {
|
||||
loadText(
|
||||
"fun box() : Int { var l = IntArray(1); l[0.toLong()] = 4; l[0.toLong()] += 6; return l[0.toLong()];}\n" +
|
||||
"fun IntArray.set(index: Long, elem: Int) { this[index.toInt()] = elem }\n" +
|
||||
"fun IntArray.get(index: Long) = this[index.toInt()]");
|
||||
// System.out.println(generateToText());
|
||||
Method foo = generateFunction("box");
|
||||
assertTrue((Integer) foo.invoke(null) == 10);
|
||||
}
|
||||
|
||||
public void testKt503() {
|
||||
@@ -308,7 +315,7 @@ public class ArrayGenTest extends CodegenTestCase {
|
||||
|
||||
public void testKt602() {
|
||||
blackBoxFile("regressions/kt602.jet");
|
||||
// System.out.println(generateToText());
|
||||
// System.out.println(generateToText());
|
||||
}
|
||||
|
||||
public void testKt950() {
|
||||
@@ -317,12 +324,12 @@ public class ArrayGenTest extends CodegenTestCase {
|
||||
|
||||
public void testKt594() throws Exception {
|
||||
loadFile("regressions/kt594.jet");
|
||||
// System.out.println(generateToText());
|
||||
// System.out.println(generateToText());
|
||||
blackBox();
|
||||
}
|
||||
|
||||
public void testNonNullArray() throws Exception {
|
||||
blackBoxFile("classes/nonnullarray.jet");
|
||||
// System.out.println(generateToText());
|
||||
// System.out.println(generateToText());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user