__if_comp__ __C__ simple_passthrough """ #include """ /* we have a template versions so we don't have to cast (because we don't have that yet) */ fun malloc(size: int): T* { var memPtr: T*; __if_comp__ __C__ { simple_passthrough( size = size, memPtr = memPtr : memPtr = memPtr :) """ memPtr = malloc(size); """ } return memPtr; } fun free(memPtr: T*): void { __if_comp__ __C__ { simple_passthrough(memPtr = memPtr ::) """ free(memPtr); """ } } fun sizeof(): int { var testObj: T; var result: int; __if_comp__ __C__ { simple_passthrough(testObj = testObj : result = result:) """ int result = sizeof(testObj); """ } return result; } fun new(count: int): T* { return malloc( sizeof() * count ); } fun new(): T* { return new(1); } /* We specilize on the trait Destructable to decide on whether or not the destructor should be called */ fun delete(toDelete: T*, itemCount: int): void { delete(toDelete); } /* Calling this with itemCount = 0 allows you to delete destructable objects without calling their destructors. */ fun delete(toDelete: T*, itemCount: int): void { for (var i: int = 0; i < itemCount; i++;) toDelete[i].destruct(); delete(toDelete); } /* We specilize on the trait Destructable to decide on whether or not the destructor should be called */ fun delete(toDelete: T*): void { free(toDelete); } fun delete(toDelete: T*): void { toDelete->destruct(); free(toDelete); }