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:
Nathan Braswell
2015-06-05 00:34:24 -04:00
parent 6f9ceaa717
commit 7abab02fbf
15 changed files with 185 additions and 87 deletions

View File

@@ -1,3 +1,5 @@
import io:*
__if_comp__ __C__ simple_passthrough """
#include <stdlib.h>
"""
@@ -41,24 +43,36 @@ fun new<T>(): T* {
return new<T>(1);
}
/* We specilize on the trait Destructable to decide on whether or not the destructor should be called */
/* We specilize on the trait Object to decide on whether or not the destructor should be called */
fun delete<T>(toDelete: T*, itemCount: int): void {
delete<T>(toDelete);
}
/* Calling this with itemCount = 0 allows you to delete destructable objects without calling their destructors. */
fun delete<T(Destructable)>(toDelete: T*, itemCount: int): void {
for (var i: int = 0; i < itemCount; i++;)
fun delete<T(Object)>(toDelete: T*, itemCount: int): void {
// start at one because the actual delete will call the destructor of the first one as it
// finishes the pointer
for (var i: int = 1; i < itemCount; i++;)
toDelete[i].destruct();
delete<T>(toDelete);
}
/* We specilize on the trait Destructable to decide on whether or not the destructor should be called */
/* We specilize on the trait Object to decide on whether or not the destructor should be called */
fun delete<T>(toDelete: T*): void {
free<T>(toDelete);
}
fun delete<T(Destructable)>(toDelete: T*): void {
fun delete<T(Object)>(toDelete: T*): void {
toDelete->destruct();
free<T>(toDelete);
}
// a wrapper for copy constructing if it has the Object trait
fun maybe_copy_construct<T>(to:T*, from:T*):void {
*to = *from
}
fun maybe_copy_construct<T(Object)>(to:T*, from:T*):void {
to->copy_construct(from)
}