I'm pretty sure I missed cases and introduced bugs with the new CGenerator triplit system, but I finally got all normal tests passing, and it's almost 5 in the morning, so I'm calling it a night. We have destructors and copy constructors now\! I need to work out copy assignment, but again, another day
This commit is contained in:
105
tests/test_destructor_copy_constructor.krak
Normal file
105
tests/test_destructor_copy_constructor.krak
Normal file
@@ -0,0 +1,105 @@
|
||||
import io:*
|
||||
|
||||
obj wDestructor {
|
||||
var data: char*
|
||||
var count: int
|
||||
fun construct(dat:char*):wDestructor* {
|
||||
data = dat
|
||||
count = 0
|
||||
return this
|
||||
}
|
||||
fun copy_construct(other: wDestructor*):void {
|
||||
data = other->data
|
||||
count = other->count + 1
|
||||
print("copy_construct ")
|
||||
print(data)
|
||||
print(" : ")
|
||||
print(count)
|
||||
println("!")
|
||||
}
|
||||
fun operator=(other: wDestructor*):void {
|
||||
data = other->data
|
||||
count = other->count + 1
|
||||
print("copy assign ")
|
||||
print(data)
|
||||
print(" : ")
|
||||
print(count)
|
||||
println("!")
|
||||
}
|
||||
fun destruct():void {
|
||||
print("destroyed ")
|
||||
print(data)
|
||||
print(" : ")
|
||||
print(count)
|
||||
println("!")
|
||||
}
|
||||
}
|
||||
|
||||
fun inFunction():void {
|
||||
{
|
||||
var func_out.construct("i"): wDestructor
|
||||
{
|
||||
var func_in_block_pre_ret.construct("j"): wDestructor
|
||||
return
|
||||
var func_in_block_post_ret.construct("k"): wDestructor
|
||||
}
|
||||
var func_out_post_ret.construct("l"): wDestructor
|
||||
}
|
||||
}
|
||||
|
||||
fun inOutFunc(thing: wDestructor):wDestructor {
|
||||
println("in inOutFunc")
|
||||
var toRet.construct("outFunc"): wDestructor
|
||||
return toRet
|
||||
}
|
||||
|
||||
fun main():int {
|
||||
var outside.construct("a"): wDestructor
|
||||
var outside2.construct("a2"): wDestructor
|
||||
{
|
||||
var simple_block.construct("b"): wDestructor
|
||||
}
|
||||
for (var i = 0; i < 5; i++;) {
|
||||
var in_for_block.construct("c"): wDestructor
|
||||
}
|
||||
for (var i = 0; i < 5; i++;)
|
||||
var in_for_no_block.construct("d"): wDestructor
|
||||
for (var i = 0; i < 5; i++;) {
|
||||
var it_for_pre_break.construct("e"): wDestructor
|
||||
break
|
||||
var it_for_post_break.construct("f"): wDestructor
|
||||
}
|
||||
for (var i = 0; i < 5; i++;) {
|
||||
var it_for_pre_continue.construct("g"): wDestructor
|
||||
continue
|
||||
var it_for_post_continue.construct("h"): wDestructor
|
||||
}
|
||||
/*for (var i.construct("in_for_dec"): wDestructor; i.data == "not_equal"; i.data;) println("should not print")*/
|
||||
|
||||
var idx = 0
|
||||
while (idx++ < 5) {
|
||||
var in_while_block.construct("in_while_block"): wDestructor
|
||||
}
|
||||
idx = 0
|
||||
while (idx++ < 5)
|
||||
var in_while_no_block.construct("in_while_no_block"): wDestructor
|
||||
idx = 0
|
||||
while (idx++ < 5) {
|
||||
var it_while_pre_break.construct("it_while_pre_break"): wDestructor
|
||||
break
|
||||
var it_while_post_break.construct("it_while_post_break"): wDestructor
|
||||
}
|
||||
idx = 0
|
||||
while (idx++ < 5) {
|
||||
var it_while_pre_continue.construct("it_while_pre_continue"): wDestructor
|
||||
continue
|
||||
var it_while_post_continue.construct("it_while_post_continue"): wDestructor
|
||||
}
|
||||
|
||||
inFunction()
|
||||
|
||||
var inFunc.construct("inFunc"):wDestructor
|
||||
var outFunc = inOutFunc(inFunc)
|
||||
println("time for the end")
|
||||
return 0
|
||||
}
|
||||
Reference in New Issue
Block a user