mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-04-30 09:22:27 +00:00
simplify
This commit is contained in:
parent
878ee3f13b
commit
979a0b8f23
@ -89,7 +89,7 @@ export function FREE(ref: usize): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Registers a managed object with GC. */
|
/** Registers a managed object with GC. */
|
||||||
export function REGISTER<T>(ref: usize): void {
|
export function REGISTER<T>(ref: usize, parentRef: usize): void {
|
||||||
var header = UNREF(ref);
|
var header = UNREF(ref);
|
||||||
header.classId = /* TODO: CLASSID<T>() */ 1;
|
header.classId = /* TODO: CLASSID<T>() */ 1;
|
||||||
header.reserved2 = 0;
|
header.reserved2 = 0;
|
||||||
@ -98,49 +98,18 @@ export function REGISTER<T>(ref: usize): void {
|
|||||||
|
|
||||||
// === ArrayBuffer ================================================================================
|
// === ArrayBuffer ================================================================================
|
||||||
|
|
||||||
/** Size of a buffer header, excl. common runtime header. */
|
export abstract class ArrayBufferBase {
|
||||||
@inline export const BUFFER_HEADER_SIZE: usize = (offsetof<ArrayBuffer>() + AL_MASK) & ~AL_MASK;
|
get byteLength(): i32 {
|
||||||
|
var header = changetype<HEADER>(changetype<usize>(this) - HEADER_SIZE);
|
||||||
/** Allocates a new ArrayBuffer and returns a pointer to it. */
|
return header.payloadSize;
|
||||||
@inline export function ALLOC_BUFFER(byteLength: u32): ArrayBuffer {
|
}
|
||||||
return changetype<ArrayBuffer>(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<ArrayBuffer>(REALLOC(ref, BUFFER_HEADER_SIZE + byteLength));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Loads a value from a backing ArrayBuffer. */
|
|
||||||
@inline export function LOAD_BUFFER<T,TOut = T>(buffer: ArrayBuffer, index: i32, byteOffset: i32 = 0): TOut {
|
|
||||||
return <TOut>load<T>(
|
|
||||||
changetype<usize>(buffer) + (<usize>index << alignof<T>()) + <usize>byteOffset,
|
|
||||||
BUFFER_HEADER_SIZE
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Stores a value to a backing ArrayBuffer. */
|
|
||||||
@inline export function STORE_BUFFER<T,TIn = T>(buffer: ArrayBuffer, index: i32, value: TIn, byteOffset: i32 = 0): void {
|
|
||||||
store<T>(
|
|
||||||
changetype<usize>(buffer) + (<usize>index << alignof<T>()) + <usize>byteOffset,
|
|
||||||
value,
|
|
||||||
BUFFER_HEADER_SIZE
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// === String =====================================================================================
|
// === String =====================================================================================
|
||||||
|
|
||||||
/** Size of a string header, excl. common runtime header. */
|
export abstract class StringBase {
|
||||||
@inline export const STRING_HEADER_SIZE: usize = (offsetof<String>() + 1) & ~1; // 2 byte aligned
|
get length(): i32 {
|
||||||
|
var header = changetype<HEADER>(changetype<usize>(this) - HEADER_SIZE);
|
||||||
/** Allocates a new String and returns a pointer to it. */
|
return header.payloadSize >>> 1;
|
||||||
@inline export function ALLOC_STRING(length: u32): String {
|
}
|
||||||
return changetype<String>(ALLOC(STRING_HEADER_SIZE + (length << 1)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Reallocates a String if necessary. Returns a pointer to it. */
|
|
||||||
@inline export function REALLOC_STRING(ref: usize, length: u32): String {
|
|
||||||
return changetype<String>(REALLOC(ref, STRING_HEADER_SIZE + (length << 1)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ...
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user