2019-03-13 22:35:47 +01:00
|
|
|
/** Garbage collector interface. */
|
|
|
|
export namespace gc {
|
|
|
|
|
2019-03-14 04:33:58 +01:00
|
|
|
/** Whether the garbage collector interface is implemented. */
|
2019-03-14 06:09:49 +01:00
|
|
|
// @ts-ignore: decorator
|
|
|
|
@lazy
|
2019-03-15 09:26:31 +01:00
|
|
|
export const IMPLEMENTED: bool = isDefined(
|
2019-03-14 06:09:49 +01:00
|
|
|
// @ts-ignore: stub
|
|
|
|
__gc_register
|
|
|
|
);
|
2019-03-14 04:33:58 +01:00
|
|
|
|
2019-03-13 22:35:47 +01:00
|
|
|
/** Registers a managed object to be tracked by the garbage collector. */
|
2019-03-14 06:09:49 +01:00
|
|
|
// @ts-ignore: decorator
|
2019-03-14 12:46:36 +01:00
|
|
|
@unsafe @inline
|
2019-03-15 09:26:31 +01:00
|
|
|
export function register(ref: usize): void {
|
2019-03-14 06:09:49 +01:00
|
|
|
// @ts-ignore: stub
|
2019-03-14 04:33:58 +01:00
|
|
|
if (isDefined(__gc_register)) __gc_register(ref);
|
2019-03-15 13:13:48 +01:00
|
|
|
else WARNING("missing implementation: gc.register");
|
2019-03-13 22:35:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Links a registered object with the registered object now referencing it. */
|
2019-03-14 06:09:49 +01:00
|
|
|
// @ts-ignore: decorator
|
2019-03-14 12:46:36 +01:00
|
|
|
@unsafe @inline
|
2019-03-15 09:26:31 +01:00
|
|
|
export function link(ref: usize, parentRef: usize): void {
|
2019-03-14 06:09:49 +01:00
|
|
|
// @ts-ignore: stub
|
2019-03-14 04:33:58 +01:00
|
|
|
if (isDefined(__gc_link)) __gc_link(ref, parentRef);
|
2019-03-15 13:13:48 +01:00
|
|
|
else WARNING("missing implementation: gc.link");
|
2019-03-13 22:35:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Marks an object as being reachable. */
|
2019-03-14 06:09:49 +01:00
|
|
|
// @ts-ignore: decorator
|
|
|
|
@unsafe
|
|
|
|
export function mark(ref: usize): void {
|
|
|
|
// @ts-ignore: stub
|
2019-03-14 04:33:58 +01:00
|
|
|
if (isDefined(__gc_mark)) __gc_mark(ref);
|
2019-03-15 13:13:48 +01:00
|
|
|
else WARNING("missing implementation: gc.mark");
|
2019-03-13 22:35:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Performs a full garbage collection cycle. */
|
2019-03-14 04:33:58 +01:00
|
|
|
export function collect(): void {
|
2019-03-14 06:09:49 +01:00
|
|
|
// @ts-ignore: stub
|
2019-03-14 04:33:58 +01:00
|
|
|
if (isDefined(__gc_collect)) __gc_collect();
|
|
|
|
else WARNING("missing implementation: gc.collect");
|
2019-03-13 22:35:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: move marking into userspace using builtins like iterateFields?
|