Inline test data structure changed

This commit is contained in:
Mikhael Bogdanov
2014-06-04 15:47:20 +04:00
committed by Michael Bogdanov
parent b37c0d3fff
commit 02c6bdeaa3
115 changed files with 765 additions and 519 deletions
@@ -0,0 +1,11 @@
fun test1(): Int {
val inlineX = Inline()
return inlineX.foo({(z: Int) -> "" + z}, 25, {String.() -> this.length})
}
fun box(): String {
if (test1() != 2) return "test1: ${test1()}"
return "OK"
}
@@ -0,0 +1,7 @@
class Inline() {
inline fun foo(closure1 : (l: Int) -> String, param: Int, closure2: String.() -> Int) : Int {
return closure1(param).closure2()
}
}
@@ -0,0 +1,23 @@
import test.*
import java.util.*
fun sample(): Input {
return Input("Hello", "World");
}
test fun testForEachLine() {
val list = ArrayList<String>()
val reader = sample()
reader.forEachLine{
list.add(it)
}
}
fun box(): String {
testForEachLine()
return "OK"
}
@@ -0,0 +1,20 @@
package test
public class Input(val s1: String, val s2: String) {
public fun iterator() : Iterator<String> {
return arrayListOf(s1, s2).iterator()
}
}
public inline fun <T, R> T.use(block: (T)-> R) : R {
return block(this)
}
public inline fun Input.forEachLine(block: (String) -> Unit): Unit {
useLines { lines -> lines.forEach(block) }
}
public inline fun Input.useLines(block2: (Iterator<String>) -> Unit): Unit {
this.use{ block2(it.iterator()) }
}
@@ -0,0 +1,23 @@
import test.*
import java.util.*
fun sample(): Input {
return Input("Hello", "World");
}
test fun testForEachLine() {
val list = ArrayList<String>()
val reader = sample()
reader.forEachLine{
list.add("111")
}
}
fun box(): String {
testForEachLine()
return "OK"
}
@@ -0,0 +1,19 @@
package test
public class Input(val s1: String, val s2: String) {
public fun iterator() : Iterator<String> {
return arrayListOf(s1, s2).iterator()
}
}
public inline fun <T, R> T.use(block: ()-> R) : R {
return block()
}
public inline fun <T, R> T.use2(block: ()-> R) : R {
return block()
}
public inline fun Input.forEachLine(block: () -> Unit): Unit {
use { use2 (block) }
}
@@ -0,0 +1,22 @@
import test.*
fun Data.test1(d: Data) : Long {
val input2 = Input(this)
val input = Input(this)
return input.use<Input, Long>{
val output = Output(d)
output.use<Output,Long>{
input.copyTo(output, 10)
}
}
}
fun box(): String {
val result = Data().test1(Data())
if (result != 100.toLong()) return "test1: ${result}"
return "OK"
}
@@ -0,0 +1,38 @@
package test
public class Data()
public class Input(val d: Data) : Closeable {
public fun data() : Int = 100
}
public class Output(val d: Data) : Closeable {
public fun doOutput(data: Int): Int = data
}
public open trait Closeable {
open public fun close() {}
}
public inline fun <T: Closeable, R> T.use(block: (T)-> R) : R {
var closed = false
try {
return block(this)
} catch (e: Exception) {
closed = true
try {
this.close()
} catch (closeException: Exception) {
}
throw e
} finally {
if (!closed) {
this.close()
}
}
}
public fun Input.copyTo(output: Output, size: Int): Long {
return output.doOutput(this.data()).toLong()
}
@@ -0,0 +1,43 @@
import test.*
fun Data.test1(d: Data) : Long {
val input = Input(this)
var result = 10.toLong()
with(input) {
result = use<Long>{
val output = Output(d)
use<Long>{
data()
copyTo(output, 10)
}
}
}
return result
}
fun Data.test2(d: Data) : Long {
val input = Input(this)
var result = 10.toLong()
with2(input) {
result = use<Long>{
val output = Output(d)
useNoInline<Long>{
data()
copyTo(output, 10)
}
}
}
return result
}
fun box(): String {
val result = Data().test1(Data())
if (result != 100.toLong()) return "test1: ${result}"
val result2 = Data().test2(Data())
if (result2 != 100.toLong()) return "test2: ${result2}"
return "OK"
}
@@ -0,0 +1,30 @@
package test
public class Data()
public class Input(val d: Data) : Closeable {
public fun data() : Int = 100
}
public class Output(val d: Data) : Closeable {
public fun doOutput(data: Int): Int = data
}
public open trait Closeable {
open public fun close() {}
}
public inline fun <R> use(block: ()-> R) : R {
return block()
}
public fun <R> useNoInline(block: ()-> R) : R {
return block()
}
public fun Input.copyTo(output: Output, size: Int): Long {
return output.doOutput(this.data()).toLong()
}
public inline fun with2<T>(receiver : T, body : T.() -> Unit) : Unit = {receiver.body()}()