Files
kraken/tests/test_references.krak

68 lines
954 B
Plaintext

import io:*
obj test_cons(Object) {
fun construct(): *test_cons {
println("construct")
}
fun copy_construct(other: *test_cons) {
println("copy_construct")
}
fun destruct() {
println("destruct")
}
fun operator=(other: test_cons) {
println("=")
}
fun do() {
println("do")
}
}
fun call<T>(it: ref T) {
it.do()
}
fun byRef<T>(it: ref T) {
it = it + 1
}
fun byRef(it: * int) {
*it = *it + 1
}
fun byRef(it: ref int) {
it = it + 1
}
fun id(it: ref int): ref int {
return it
}
fun id<T>(it: ref T): ref T {
return it
}
// what about cosures closing over references?
fun main():int {
var a = 6
byRef(a)
println(a)
byRef(&a)
println(a)
id(a) = 14
println(a)
var b = 6.7
byRef(b)
println(b)
var t.construct() : test_cons
call(t)
id(t).do()
var do_copy = id(t)
do_copy.do()
return 0
}