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:
Nathan Braswell
2015-05-30 04:43:01 -04:00
parent b71bb84070
commit bbcebf7c17
13 changed files with 482 additions and 66 deletions

View File

@@ -0,0 +1,47 @@
destroyed b : 0!
destroyed c : 0!
destroyed c : 0!
destroyed c : 0!
destroyed c : 0!
destroyed c : 0!
destroyed d : 0!
destroyed d : 0!
destroyed d : 0!
destroyed d : 0!
destroyed d : 0!
destroyed e : 0!
destroyed g : 0!
destroyed g : 0!
destroyed g : 0!
destroyed g : 0!
destroyed g : 0!
destroyed in_while_block : 0!
destroyed in_while_block : 0!
destroyed in_while_block : 0!
destroyed in_while_block : 0!
destroyed in_while_block : 0!
destroyed in_while_no_block : 0!
destroyed in_while_no_block : 0!
destroyed in_while_no_block : 0!
destroyed in_while_no_block : 0!
destroyed in_while_no_block : 0!
destroyed it_while_pre_break : 0!
destroyed it_while_pre_continue : 0!
destroyed it_while_pre_continue : 0!
destroyed it_while_pre_continue : 0!
destroyed it_while_pre_continue : 0!
destroyed it_while_pre_continue : 0!
destroyed j : 0!
destroyed i : 0!
copy_construct inFunc : 1!
in inOutFunc
copy_construct outFunc : 1!
destroyed outFunc : 0!
destroyed inFunc : 1!
copy_construct outFunc : 2!
destroyed outFunc : 1!
time for the end
destroyed outFunc : 2!
destroyed inFunc : 0!
destroyed a2 : 0!
destroyed a : 0!

View 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
}

View File

@@ -1,6 +1,9 @@
4
1337
26614
9131321
15513
3.7000007.7000007.70000015.700000
Copied!
Destroyed!
Destroyed!

View File

@@ -3,6 +3,10 @@ import mem:*;
import vector:*;
obj AbleToBeDestroyed (Destructable) {
fun copy_construct(other:AbleToBeDestroyed*):void {
println("Copied!");
}
fun destruct(): void {
println("Destroyed!");
}
@@ -24,6 +28,8 @@ fun main(): int {
for (var i: int = 0; i < intVec.size; i++;)
print(intVec.at(i));
println();
intVec.do(fun(it:int):void print(it+7);)
println();
var subd = intVec.map(fun(it:int):int { return it-1; })
for (var i: int = 0; i < subd.size; i++;)