More all-rounded implementation of the new objecty features, several bugfixes, and updates to the standard library to behave. Vector still needs a bit more work for some operations
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
8
|
||||
9
|
||||
10
|
||||
Does have Traits
|
||||
Does not have Traits
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import io:*
|
||||
|
||||
obj Traited(Traits) {}
|
||||
|
||||
fun funcID<T>(genFun: fun():T):T {
|
||||
return genFun()
|
||||
}
|
||||
|
||||
fun retInt():int {
|
||||
return 9
|
||||
}
|
||||
@@ -21,11 +22,22 @@ fun ptrFn<T>(ptr: T*):void {
|
||||
println(*ptr)
|
||||
}
|
||||
|
||||
fun traitAware<T>(it:T*):void {
|
||||
println("Does not have Traits")
|
||||
}
|
||||
|
||||
fun traitAware<T(Traits)>(it:T*):void {
|
||||
println("Does have Traits")
|
||||
}
|
||||
|
||||
fun main():int {
|
||||
var a = 8
|
||||
ptrFn(&a)
|
||||
println(funcID(retInt))
|
||||
doThePrint(printInt)
|
||||
var t:Traited
|
||||
traitAware(&t)
|
||||
traitAware(&a)
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
9131321
|
||||
15513
|
||||
3.7000007.7000007.70000015.700000
|
||||
Copied!
|
||||
Destroyed!
|
||||
Destroyed!
|
||||
Constructed: 0
|
||||
Copied: 0 to 1
|
||||
Copied: 1 to 2
|
||||
Destroyed: 1
|
||||
delete vector
|
||||
Destroyed: 2
|
||||
done
|
||||
Destroyed: 0
|
||||
|
||||
@@ -2,13 +2,34 @@ import io:*;
|
||||
import mem:*;
|
||||
import vector:*;
|
||||
|
||||
obj AbleToBeDestroyed (Destructable) {
|
||||
obj AbleToBeDestroyed (Object) {
|
||||
var data:int
|
||||
fun construct(dat:int):void {
|
||||
data = dat
|
||||
print("Constructed: ")
|
||||
println(data)
|
||||
}
|
||||
fun copy_construct(other:AbleToBeDestroyed*):void {
|
||||
println("Copied!");
|
||||
data = other->data+1
|
||||
print("Copied: ")
|
||||
print(other->data)
|
||||
print(" to ")
|
||||
println(data)
|
||||
}
|
||||
|
||||
fun operator=(other:AbleToBeDestroyed):void {
|
||||
print("Assigned: ")
|
||||
print(other.data)
|
||||
print(" to ")
|
||||
print(data)
|
||||
print(" is now ")
|
||||
data = other.data+1
|
||||
println(data)
|
||||
}
|
||||
|
||||
fun destruct(): void {
|
||||
println("Destroyed!");
|
||||
print("Destroyed: ")
|
||||
println(data)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -42,9 +63,11 @@ fun main(): int {
|
||||
println();
|
||||
|
||||
var desVec: vector<AbleToBeDestroyed>* = new<vector<AbleToBeDestroyed>>()->construct();
|
||||
var testDestruct: AbleToBeDestroyed;
|
||||
var testDestruct.construct(0): AbleToBeDestroyed;
|
||||
desVec->addEnd(testDestruct);
|
||||
delete<vector<AbleToBeDestroyed>>(desVec);
|
||||
println("delete vector")
|
||||
delete(desVec);
|
||||
println("done")
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user