diff --git a/std/assembly/internal/runtime.ts b/std/assembly/internal/runtime.ts index efe87985..4f154847 100644 --- a/std/assembly/internal/runtime.ts +++ b/std/assembly/internal/runtime.ts @@ -89,7 +89,7 @@ export function FREE(ref: usize): void { } /** Registers a managed object with GC. */ -export function REGISTER(ref: usize): void { +export function REGISTER(ref: usize, parentRef: usize): void { var header = UNREF(ref); header.classId = /* TODO: CLASSID() */ 1; header.reserved2 = 0; @@ -98,49 +98,18 @@ export function REGISTER(ref: usize): void { // === ArrayBuffer ================================================================================ -/** Size of a buffer header, excl. common runtime header. */ -@inline export const BUFFER_HEADER_SIZE: usize = (offsetof() + AL_MASK) & ~AL_MASK; - -/** Allocates a new ArrayBuffer and returns a pointer to it. */ -@inline export function ALLOC_BUFFER(byteLength: u32): ArrayBuffer { - return changetype(ALLOC(BUFFER_HEADER_SIZE + byteLength)); -} - -/** Reallocates an ArrayBuffer if necessary. Returns a pointer to it. */ -@inline export function REALLOC_BUFFER(ref: usize, byteLength: u32): ArrayBuffer { - return changetype(REALLOC(ref, BUFFER_HEADER_SIZE + byteLength)); -} - -/** Loads a value from a backing ArrayBuffer. */ -@inline export function LOAD_BUFFER(buffer: ArrayBuffer, index: i32, byteOffset: i32 = 0): TOut { - return load( - changetype(buffer) + (index << alignof()) + byteOffset, - BUFFER_HEADER_SIZE - ); -} - -/** Stores a value to a backing ArrayBuffer. */ -@inline export function STORE_BUFFER(buffer: ArrayBuffer, index: i32, value: TIn, byteOffset: i32 = 0): void { - store( - changetype(buffer) + (index << alignof()) + byteOffset, - value, - BUFFER_HEADER_SIZE - ); +export abstract class ArrayBufferBase { + get byteLength(): i32 { + var header = changetype
(changetype(this) - HEADER_SIZE); + return header.payloadSize; + } } // === String ===================================================================================== -/** Size of a string header, excl. common runtime header. */ -@inline export const STRING_HEADER_SIZE: usize = (offsetof() + 1) & ~1; // 2 byte aligned - -/** Allocates a new String and returns a pointer to it. */ -@inline export function ALLOC_STRING(length: u32): String { - return changetype(ALLOC(STRING_HEADER_SIZE + (length << 1))); +export abstract class StringBase { + get length(): i32 { + var header = changetype
(changetype(this) - HEADER_SIZE); + return header.payloadSize >>> 1; + } } - -/** Reallocates a String if necessary. Returns a pointer to it. */ -@inline export function REALLOC_STRING(ref: usize, length: u32): String { - return changetype(REALLOC(ref, STRING_HEADER_SIZE + (length << 1))); -} - -// ...