mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-29 22:51:46 +00:00
use gc interface directly, document
This commit is contained in:
@ -211,34 +211,12 @@ function objToRef(obj: ManagedObject): usize {
|
||||
return changetype<usize>(obj) + HEADER_SIZE;
|
||||
}
|
||||
|
||||
// @ts-ignore: decorator
|
||||
@global @unsafe
|
||||
export function __gc_register(ref: usize): void {
|
||||
if (TRACE) trace("gc.register", 1, ref);
|
||||
step(); // also makes sure it's initialized
|
||||
var obj = refToObj(ref);
|
||||
obj.color = white;
|
||||
fromSpace.push(obj);
|
||||
}
|
||||
// Garbage collector interface
|
||||
|
||||
// @ts-ignore: decorator
|
||||
@global @unsafe
|
||||
export function __gc_retain(ref: usize, parentRef: usize): void {
|
||||
if (TRACE) trace("gc.retain", 2, ref, parentRef);
|
||||
var parent = refToObj(parentRef);
|
||||
if (parent.color == i32(!white) && refToObj(ref).color == white) parent.makeGray();
|
||||
}
|
||||
|
||||
// @ts-ignore: decorator
|
||||
@global @unsafe
|
||||
export function __gc_release(ref: usize, parentRef: usize): void {
|
||||
if (TRACE) trace("gc.release", 2, ref, parentRef);
|
||||
}
|
||||
|
||||
// @ts-ignore: decorator
|
||||
@global @unsafe
|
||||
export function __gc_collect(): void {
|
||||
if (TRACE) trace("gc.collect");
|
||||
export function __ref_collect(): void {
|
||||
if (TRACE) trace("itcm.collect");
|
||||
// begin collecting if not yet collecting
|
||||
switch (state) {
|
||||
case State.INIT:
|
||||
@ -247,3 +225,27 @@ export function __gc_collect(): void {
|
||||
// finish the cycle
|
||||
while (state != State.IDLE) step();
|
||||
}
|
||||
|
||||
// @ts-ignore: decorator
|
||||
@global @unsafe
|
||||
export function __ref_register(ref: usize): void {
|
||||
if (TRACE) trace("itcm.register", 1, ref);
|
||||
step(); // also makes sure it's initialized
|
||||
var obj = refToObj(ref);
|
||||
obj.color = white;
|
||||
fromSpace.push(obj);
|
||||
}
|
||||
|
||||
// @ts-ignore: decorator
|
||||
@global @unsafe
|
||||
export function __ref_link(ref: usize, parentRef: usize): void {
|
||||
if (TRACE) trace("itcm.link", 2, ref, parentRef);
|
||||
var parent = refToObj(parentRef);
|
||||
if (parent.color == i32(!white) && refToObj(ref).color == white) parent.makeGray();
|
||||
}
|
||||
|
||||
// @ts-ignore: decorator
|
||||
@global @unsafe
|
||||
export function __ref_unlink(ref: usize, parentRef: usize): void {
|
||||
if (TRACE) trace("itcm.unlink", 2, ref, parentRef);
|
||||
}
|
||||
|
Reference in New Issue
Block a user