This commit is contained in:
dcode
2019-05-23 03:08:25 +02:00
parent d94b4fca50
commit 51fdf9db4f
182 changed files with 81381 additions and 95410 deletions

View File

@ -27,8 +27,11 @@ Interface
### Internals
* **__retainRelease**(newRef: `usize`, oldRef: `usize`): `usize`<br />
Retains a reference to an object type while releasing the reference it replaces. Returns the retained reference.
* **__retainRelease**(oldRef: `usize`, newRef: `usize`): `usize`<br />
Retains a reference to a new object type while releasing the reference it replaces. Returns the retained reference. This is a workaround.
* **__skippedRelease**(oldRef: `usize`, newRef: `usize`): `usize`<br />
Ignores a reference to a new object type while releasing the reference it replaces. Returns the ignored reference. This is a workaround.
* **__visit**(ref: `usize`, cookie: `u32`): `void`<br />
Concrete visitor implementation called during traversal. Cookie can be used to indicate one of multiple operations.

View File

@ -3,7 +3,8 @@ declare function __realloc(ref: usize, size: usize): usize;
declare function __free(ref: usize): void;
declare function __retain(ref: usize): void;
declare function __release(ref: usize): void;
declare function __retainRelease(ref: usize, oldRef: usize): usize;
declare function __retainRelease(oldRef: usize, newRef: usize): usize;
declare function __skippedRelease(oldRef: usize, newRef: usize): usize;
declare function __collect(): void;
declare function __typeinfo(id: u32): u32;
declare function __instanceof(ref: usize, superId: u32): bool;

View File

@ -61,7 +61,7 @@ import { TypeinfoFlags } from "shared/typeinfo";
@inline const VISIT_COLLECTWHITE = 5;
// @ts-ignore: decorator
@global @unsafe @builtin
@global @unsafe
function __visit(ref: usize, cookie: i32): void {
if (ref < HEAP_BASE) return;
var s = changetype<Block>(ref - BLOCK_OVERHEAD);
@ -243,27 +243,34 @@ function collectWhite(s: Block): void {
}
// @ts-ignore: decorator
@global @unsafe @builtin
@global @unsafe
export function __retain(ref: usize): usize {
if (ref > HEAP_BASE) increment(changetype<Block>(ref - BLOCK_OVERHEAD));
return ref;
}
// @ts-ignore: decorator
@global @unsafe @builtin
@global @unsafe
export function __release(ref: usize): void {
if (ref > HEAP_BASE) decrement(changetype<Block>(ref - BLOCK_OVERHEAD));
}
// @ts-ignore: decorator
@global @unsafe @builtin
export function __retainRelease(ref: usize, oldRef: usize): usize {
if (ref != oldRef) {
@global @unsafe
export function __retainRelease(oldRef: usize, newRef: usize): usize {
if (newRef != oldRef) {
let heapBase = HEAP_BASE;
if (ref > heapBase) increment(changetype<Block>(ref - BLOCK_OVERHEAD));
if (newRef > heapBase) increment(changetype<Block>(newRef - BLOCK_OVERHEAD));
if (oldRef > heapBase) decrement(changetype<Block>(oldRef - BLOCK_OVERHEAD));
}
return ref;
return newRef;
}
// @ts-ignore: decorator
@global @unsafe
export function __skippedRelease(oldRef: usize, newRef: usize): usize {
if (oldRef > HEAP_BASE) decrement(changetype<Block>(oldRef - BLOCK_OVERHEAD));
return newRef;
}
// @ts-ignore: decorator

View File

@ -9,7 +9,7 @@ var startOffset: usize = (HEAP_BASE + AL_MASK) & ~AL_MASK;
var offset: usize = startOffset;
// @ts-ignore: decorator
@unsafe @global @builtin
@unsafe @global
export function __alloc(size: usize, id: u32): usize {
if (size > BLOCK_MAXSIZE) unreachable();
var ptr = offset + BLOCK_OVERHEAD;
@ -30,7 +30,7 @@ export function __alloc(size: usize, id: u32): usize {
}
// @ts-ignore: decorator
@unsafe @global @builtin
@unsafe @global
export function __realloc(ref: usize, size: usize): usize {
var block = changetype<BLOCK>(ref - BLOCK_OVERHEAD);
var oldSize = <usize>block.rtSize;
@ -45,7 +45,7 @@ export function __realloc(ref: usize, size: usize): usize {
}
// @ts-ignore: decorator
@unsafe @global @builtin
@unsafe @global
export function __free(ref: usize): void {
}
@ -56,28 +56,34 @@ export function __free(ref: usize): void {
// }
// @ts-ignore: decorator
@global @unsafe @builtin
@global @unsafe
export function __retain(ref: usize): usize {
return ref;
}
// @ts-ignore: decorator
@global @unsafe @builtin
@global @unsafe
export function __release(ref: usize): void {
}
// @ts-ignore: decorator
@global @unsafe @builtin
@global @unsafe
export function __visit(ref: usize, cookie: u32): void {
}
// @ts-ignore: decorator
@global @unsafe @builtin
export function __retainRelease(ref: usize, oldRef: usize): usize {
return ref;
@global @unsafe
export function __retainRelease(oldRef: usize, newRef: usize): usize {
return newRef;
}
// @ts-ignore: decorator
@global @unsafe @builtin
@global @unsafe
export function __skippedRelease(oldRef: usize, newRef: usize): usize {
return newRef;
}
// @ts-ignore: decorator
@global @unsafe
export function __collect(): void {
}

View File

@ -337,7 +337,7 @@ function searchBlock(root: Root, size: usize): Block | null {
// search second level
var slMap = GETSL(root, fl) & (~0 << sl);
var head: Block | null;
var head: Block | null = null;
if (!slMap) {
// search next larger first level
let flMap = root.flMap & (~0 << (fl + 1));
@ -534,7 +534,7 @@ export function freeBlock(root: Root, block: Block): void {
}
// @ts-ignore: decorator
@global @unsafe @builtin
@global @unsafe
export function __alloc(size: usize, id: u32): usize {
var root = ROOT;
if (!root) {
@ -547,7 +547,7 @@ export function __alloc(size: usize, id: u32): usize {
}
// @ts-ignore: decorator
@global @unsafe @builtin
@global @unsafe
export function __realloc(ref: usize, size: usize): usize {
if (DEBUG) assert(ROOT); // must be initialized
assert(ref != 0 && !(ref & AL_MASK)); // must exist and be aligned
@ -555,7 +555,7 @@ export function __realloc(ref: usize, size: usize): usize {
}
// @ts-ignore: decorator
@global @unsafe @builtin
@global @unsafe
export function __free(ref: usize): void {
if (DEBUG) assert(ROOT); // must be initialized
assert(ref != 0 && !(ref & AL_MASK)); // must exist and be aligned