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

@ -120,7 +120,7 @@ export class Array<T> extends ArrayBufferView {
@operator("{}=") private __unchecked_set(index: i32, value: T): void {
if (isManaged<T>()) {
let offset = this.dataStart + (<usize>index << alignof<T>());
store<usize>(offset, __retainRelease(changetype<usize>(value), load<usize>(offset)));
store<usize>(offset, __retainRelease(load<usize>(offset), changetype<usize>(value)));
} else {
store<T>(this.dataStart + (<usize>index << alignof<T>()), value);
}
@ -182,7 +182,7 @@ export class Array<T> extends ArrayBufferView {
ensureSize(changetype<usize>(this), newLength, alignof<T>());
if (isManaged<T>()) {
let offset = this.dataStart + (<usize>length << alignof<T>());
store<usize>(offset, __retainRelease(changetype<usize>(value), load<usize>(offset)));
store<usize>(offset, __retainRelease(load<usize>(offset), changetype<usize>(value)));
} else {
store<T>(this.dataStart + (<usize>length << alignof<T>()), value);
}

View File

@ -106,7 +106,7 @@ export class Map<K,V> {
var entry = this.find(key, hashCode); // unmanaged!
if (entry) {
entry.value = isManaged<V>()
? changetype<V>(__retainRelease(changetype<usize>(value), changetype<usize>(entry.value)))
? changetype<V>(__retainRelease(changetype<usize>(entry.value), changetype<usize>(value)))
: value;
} else {
// check if rehashing is necessary

View File

@ -68,7 +68,11 @@ export function __allocArray(length: i32, alignLog2: usize, id: u32, data: usize
// // @ts-ignore: decorator
// @builtin @unsafe
// export declare function __retainRelease(ref: usize, oldRef: usize): usize;
// export declare function __retainRelease(oldRef: usize, newRef: usize): usize;
// // @ts-ignore: decorator
// @builtin @unsafe
// export declare function __skippedRelease(oldRef: usize, newRef: usize): usize;
// // @ts-ignore: decorator
// @builtin @unsafe

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

View File

@ -961,11 +961,11 @@ function SUBARRAY<TArray extends ArrayBufferView, T>(
else begin = min(begin, length);
if (end < 0) end = max(length + end, begin);
else end = max(min(end, length), begin);
var out = __alloc(offsetof<TArray>(), idof<TArray>());
changetype<ArrayBufferView>(out).data = array.data; // retains
changetype<ArrayBufferView>(out).dataStart = array.dataStart + (<usize>begin << alignof<T>());
changetype<ArrayBufferView>(out).dataLength = (end - begin) << alignof<T>();
return changetype<TArray>(out); // retains
var out = changetype<TArray>(__alloc(offsetof<TArray>(), idof<TArray>())); // retains
out.data = array.data; // retains
out.dataStart = array.dataStart + (<usize>begin << alignof<T>());
out.dataLength = (end - begin) << alignof<T>();
return out;
}
// @ts-ignore: decorator