array code gen rewrite and work in progress on outer type info
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
fun box() : String {
|
||||
val a : Array<Int> = Array<Int> (5)
|
||||
var i = 0
|
||||
var sum = 0
|
||||
for(el in 0..4) {
|
||||
a[i] = i++
|
||||
}
|
||||
for (el in a) {
|
||||
sum = sum + el
|
||||
}
|
||||
if(sum != 10) return "a failed"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
fun box() : String {
|
||||
val b : Array<Int?> = Array<Int?> (5)
|
||||
var i = 0
|
||||
var sum = 0
|
||||
while(i < 5) {
|
||||
b[i] = i++
|
||||
}
|
||||
sum = 0
|
||||
for (el in b) {
|
||||
sum = sum + (el ?: 0)
|
||||
}
|
||||
System.out?.println(sum)
|
||||
if(sum != 10) return "b failed"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,22 +1,46 @@
|
||||
namespace test
|
||||
|
||||
class List<T>() {
|
||||
val a : Array<T> = Array<T>(1)
|
||||
class List<T>(len: Int) {
|
||||
val a : Array<T> = Array<T>(len)
|
||||
|
||||
fun reverse() {
|
||||
var i = 0
|
||||
var j = a.size-1
|
||||
while(i < j) {
|
||||
val x = a[i]
|
||||
a[i++] = a[j]
|
||||
a[j--] = x
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val a = List<String>()
|
||||
val d = List<Int>(1)
|
||||
d.a[0] = 10
|
||||
println(d.a[0])
|
||||
|
||||
val a = List<String>(1)
|
||||
a.a[0] = "1"
|
||||
println(a.a[0])
|
||||
|
||||
val b = List<Int?>()
|
||||
val b = List<Int?>(1)
|
||||
b.a[0] = 10
|
||||
println(b.a[0])
|
||||
|
||||
val c = List<Array<Int>>()
|
||||
val c = List<Array<Int>>(1)
|
||||
c.a[0] = Array<Int>(4)
|
||||
println(c.a[0].size)
|
||||
|
||||
val e = List<Int>(5)
|
||||
e.a[0] = 0
|
||||
e.a[1] = 1
|
||||
e.a[2] = 2
|
||||
e.a[3] = 3
|
||||
e.a[4] = 4
|
||||
e.reverse()
|
||||
for(el in e.a)
|
||||
println(el)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
@@ -8,18 +8,22 @@ trait javaUtilIterator<T> : java.util.Iterator<T> {
|
||||
}
|
||||
}
|
||||
|
||||
class MyIterator<T>(val array : ReadOnlyArray<T>) : javaUtilIterator<T> {
|
||||
private var index = 0
|
||||
|
||||
override fun hasNext() : Boolean = index < array.size
|
||||
|
||||
override fun next() : T = array.get(index++)
|
||||
}
|
||||
|
||||
trait ReadOnlyArray<out T> : ISized, java.lang.Iterable<T> {
|
||||
fun get(index : Int) : T
|
||||
|
||||
class MyIterator() : javaUtilIterator<T> {
|
||||
private var index = 0
|
||||
|
||||
override fun hasNext() : Boolean = index < size
|
||||
|
||||
override fun next() : T = get(index++)
|
||||
class Default {
|
||||
fun check(v: Any) = v is T
|
||||
}
|
||||
|
||||
override fun iterator() : java.util.Iterator<T> = MyIterator()
|
||||
override fun iterator() : java.util.Iterator<T> = MyIterator<T>(this)
|
||||
}
|
||||
|
||||
trait WriteOnlyArray<in T> : ISized {
|
||||
@@ -53,4 +57,4 @@ fun box() : String {
|
||||
System.out?.println(el)
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
class Box<T>() {
|
||||
open class Inner () {
|
||||
fun isT(s : Any) = if(s is T) "OK" else "fail"
|
||||
}
|
||||
|
||||
class Inner2() : Inner() {
|
||||
|
||||
}
|
||||
|
||||
fun inner() = Inner2()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return Box<String>.inner().isT("OK")
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import jet.arrays.JetGenericArray;
|
||||
import jet.arrays.JetIntArray;
|
||||
import jet.typeinfo.TypeInfo;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class ArrayGenTest extends CodegenTestCase {
|
||||
@@ -9,6 +13,7 @@ public class ArrayGenTest extends CodegenTestCase {
|
||||
|
||||
public void testKt326 () throws Exception {
|
||||
blackBoxFile("regressions/kt326.jet");
|
||||
System.out.println(generateToText());
|
||||
}
|
||||
|
||||
public void testCreateMultiInt () throws Exception {
|
||||
@@ -16,7 +21,8 @@ public class ArrayGenTest extends CodegenTestCase {
|
||||
Method foo = generateFunction();
|
||||
Object invoke = foo.invoke(null);
|
||||
System.out.println(invoke.getClass());
|
||||
assertTrue(invoke instanceof int[][]);
|
||||
assertTrue(invoke instanceof JetGenericArray);
|
||||
assertTrue(((JetGenericArray)invoke).getTypeInfo() == TypeInfo.INT_ARRAY_TYPE_INFO);
|
||||
}
|
||||
|
||||
public void testCreateMultiString () throws Exception {
|
||||
@@ -24,18 +30,16 @@ public class ArrayGenTest extends CodegenTestCase {
|
||||
Method foo = generateFunction();
|
||||
Object invoke = foo.invoke(null);
|
||||
System.out.println(invoke.getClass());
|
||||
assertTrue(invoke instanceof String[][]);
|
||||
assertTrue(invoke instanceof JetGenericArray);
|
||||
}
|
||||
|
||||
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 instanceof Integer[]);
|
||||
*/
|
||||
assertTrue(invoke instanceof JetIntArray);
|
||||
}
|
||||
|
||||
public void testIntGenerics () throws Exception {
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import jet.arrays.JetGenericArray;
|
||||
import jet.typeinfo.TypeInfo;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
@@ -89,7 +92,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[] { args }));
|
||||
assertEquals("IntelliJ IDEA", main.invoke(null, new Object[] { new JetGenericArray(args, TypeInfo.STRING_TYPE_INFO) }));
|
||||
}
|
||||
|
||||
public void testForInRange() throws Exception {
|
||||
@@ -145,6 +148,14 @@ public class ControlStructuresTest extends CodegenTestCase {
|
||||
blackBoxFile("controlStructures/forUserType.jet");
|
||||
}
|
||||
|
||||
public void testForIntArray() throws Exception {
|
||||
blackBoxFile("controlStructures/forIntArray.jet");
|
||||
}
|
||||
|
||||
public void testForNullableIntArray() throws Exception {
|
||||
blackBoxFile("controlStructures/forNullableIntArray.jet");
|
||||
}
|
||||
|
||||
public void testKt237() throws Exception {
|
||||
blackBoxFile("regressions/kt237.jet");
|
||||
}
|
||||
|
||||
@@ -2,6 +2,9 @@ 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;
|
||||
|
||||
import java.awt.*;
|
||||
@@ -19,7 +22,7 @@ public class NamespaceGenTest extends CodegenTestCase {
|
||||
System.out.println(text);
|
||||
|
||||
final Method main = generateFunction();
|
||||
Object[] args = new Object[] { new String[0] };
|
||||
Object[] args = new Object[] { new JetGenericArray(0, TypeInfo.STRING_TYPE_INFO) };
|
||||
main.invoke(null, args);
|
||||
}
|
||||
|
||||
@@ -343,14 +346,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 String[] { "main" } }));
|
||||
assertEquals("main", main.invoke(null, new Object[] { new JetGenericArray(new String[] { "main" }, TypeInfo.STRING_TYPE_INFO) }));
|
||||
}
|
||||
|
||||
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[] { array });
|
||||
main.invoke(null, new Object[] { new JetGenericArray(array, TypeInfo.STRING_TYPE_INFO) });
|
||||
assertEquals("jet", array[0]);
|
||||
}
|
||||
|
||||
@@ -359,22 +362,23 @@ public class NamespaceGenTest extends CodegenTestCase {
|
||||
System.out.println(generateToText());
|
||||
final Method main = generateFunction();
|
||||
int[] data = new int[] { 5 };
|
||||
main.invoke(null, new Object[] { data });
|
||||
main.invoke(null, new Object[] { new JetIntArray(data) });
|
||||
assertEquals(10, data[0]);
|
||||
}
|
||||
|
||||
public void testArrayNew() throws Exception {
|
||||
loadText("fun foo() = Array<Int>(4)");
|
||||
System.out.println(generateToText());
|
||||
final Method main = generateFunction();
|
||||
int[] result = (int[]) main.invoke(null);
|
||||
assertEquals(4, result.length);
|
||||
JetIntArray result = (JetIntArray) main.invoke(null);
|
||||
assertEquals(4, result.array.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 int[4] };
|
||||
Object[] args = new Object[] { new JetIntArray(new int[4]) };
|
||||
int result = (Integer) main.invoke(null, args);
|
||||
assertEquals(4, result);
|
||||
|
||||
@@ -495,6 +499,7 @@ public class NamespaceGenTest extends CodegenTestCase {
|
||||
final Method main = generateFunction();
|
||||
final String[] args = new String[] { "foo", "bar" };
|
||||
//noinspection ImplicitArrayToString
|
||||
assertEquals("s" + args.toString(), main.invoke(null, "s", args));
|
||||
JetGenericArray jetGenericArray = new JetGenericArray(args, TypeInfo.STRING_TYPE_INFO);
|
||||
assertEquals("s" + jetGenericArray.toString(), main.invoke(null, "s", jetGenericArray));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,11 +18,9 @@ public class TraitsTest extends CodegenTestCase {
|
||||
|
||||
public void testMultiple () throws Exception {
|
||||
blackBoxFile("traits/multiple.jet");
|
||||
System.out.println(generateToText());
|
||||
}
|
||||
|
||||
public void testStdlib () throws Exception {
|
||||
blackBoxFile("traits/stdlib.jet");
|
||||
System.out.println(generateToText());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,5 +135,9 @@ public class TypeInfoTest extends CodegenTestCase {
|
||||
System.out.println(generateToText());
|
||||
}
|
||||
|
||||
public void testInner() throws Exception {
|
||||
blackBoxFile("typeinfo/inner.jet");
|
||||
System.out.println(generateToText());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user