This commit is contained in:
dcode
2019-03-14 05:11:03 +01:00
parent 6163a73ab5
commit a5e14a0eaa
24 changed files with 739 additions and 102 deletions

View File

@ -2,6 +2,7 @@
export namespace gc {
/** Whether the garbage collector interface is implemented. */
// @ts-ignore: decorator, undefined
@lazy export const implemented: bool = isDefined(__gc_register);
/** Gets the computed unique class id of a class type. */
@ -12,24 +13,28 @@ export namespace gc {
/** Registers a managed object to be tracked by the garbage collector. */
@unsafe export function register(ref: usize): void {
// @ts-ignore: undefined
if (isDefined(__gc_register)) __gc_register(ref);
else ERROR("missing implementation: gc.register");
}
/** Links a registered object with the registered object now referencing it. */
@unsafe export function link(ref: usize, parentRef: usize): void {
// @ts-ignore: undefined
if (isDefined(__gc_link)) __gc_link(ref, parentRef);
else ERROR("missing implementation: gc.link");
}
/** Marks an object as being reachable. */
@unsafe export function mark(ref: usize): void {
// @ts-ignore: undefined
if (isDefined(__gc_mark)) __gc_mark(ref);
else ERROR("missing implementation: gc.mark");
}
/** Performs a full garbage collection cycle. */
export function collect(): void {
// @ts-ignore: undefined
if (isDefined(__gc_collect)) __gc_collect();
else WARNING("missing implementation: gc.collect");
}