give it a shot

This commit is contained in:
dcode
2019-03-21 18:30:36 +01:00
parent d9463c5484
commit e57fa14ff9
5 changed files with 740 additions and 204 deletions

View File

@ -34,6 +34,22 @@ export class Array<T> extends ArrayBufferView {
constructor(length: i32 = 0) {
super(length, alignof<T>());
if (isReference<T>()) {
if (!isNullable<T>()) {
let cur = this.dataStart;
let end = cur + (<usize>length << alignof<T>());
while (cur < end) {
// TODO: probably a common reason for complaints of T not having a default ctor. what if
// the array ctor would also take default arguments, like `new Array<Ref>(10, ...args)`?
store<T>(cur,
isString<T>()
? "" // no need to instantiate
: RETAIN<T,this>(instantiate<T>(), this)
);
cur += sizeof<T>();
}
}
}
this.length_ = length;
}

View File

@ -19,7 +19,7 @@ import { HEAP_BASE, memory } from "./memory";
// Changes the size of a previously allocated, but not yet registered, runtime object, for
// example when a pre-allocated buffer turned out to be too small or too large. This works by
// aligning dynamic allocations to actual block size internally so in the best case REALLOCATE
// only updates payload size while in the worst case moves the object to larger a block.
// only updates payload size while in the worst case moves the object to a larger block.
//
// DISCARD(ref)
// ------------