array code gen rewrite and work in progress on outer type info

This commit is contained in:
Alex Tkachman
2011-09-29 12:55:35 +03:00
parent b40b7ada4d
commit ea9e1bee85
31 changed files with 1035 additions and 232 deletions
@@ -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"
}
+29 -5
View File
@@ -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"
}
+12 -8
View File
@@ -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"
}
}
+15
View File
@@ -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")
}