Skip to content

Commit 979a0b8

Browse files
committed
simplify
1 parent 878ee3f commit 979a0b8

File tree

1 file changed

+11
-42
lines changed

1 file changed

+11
-42
lines changed

std/assembly/internal/runtime.ts

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export function FREE(ref: usize): void {
8989
}
9090

9191
/** Registers a managed object with GC. */
92-
export function REGISTER<T>(ref: usize): void {
92+
export function REGISTER<T>(ref: usize, parentRef: usize): void {
9393
var header = UNREF(ref);
9494
header.classId = /* TODO: CLASSID<T>() */ 1;
9595
header.reserved2 = 0;
@@ -98,49 +98,18 @@ export function REGISTER<T>(ref: usize): void {
9898

9999
// === ArrayBuffer ================================================================================
100100

101-
/** Size of a buffer header, excl. common runtime header. */
102-
@inline export const BUFFER_HEADER_SIZE: usize = (offsetof<ArrayBuffer>() + AL_MASK) & ~AL_MASK;
103-
104-
/** Allocates a new ArrayBuffer and returns a pointer to it. */
105-
@inline export function ALLOC_BUFFER(byteLength: u32): ArrayBuffer {
106-
return changetype<ArrayBuffer>(ALLOC(BUFFER_HEADER_SIZE + byteLength));
107-
}
108-
109-
/** Reallocates an ArrayBuffer if necessary. Returns a pointer to it. */
110-
@inline export function REALLOC_BUFFER(ref: usize, byteLength: u32): ArrayBuffer {
111-
return changetype<ArrayBuffer>(REALLOC(ref, BUFFER_HEADER_SIZE + byteLength));
112-
}
113-
114-
/** Loads a value from a backing ArrayBuffer. */
115-
@inline export function LOAD_BUFFER<T,TOut = T>(buffer: ArrayBuffer, index: i32, byteOffset: i32 = 0): TOut {
116-
return <TOut>load<T>(
117-
changetype<usize>(buffer) + (<usize>index << alignof<T>()) + <usize>byteOffset,
118-
BUFFER_HEADER_SIZE
119-
);
120-
}
121-
122-
/** Stores a value to a backing ArrayBuffer. */
123-
@inline export function STORE_BUFFER<T,TIn = T>(buffer: ArrayBuffer, index: i32, value: TIn, byteOffset: i32 = 0): void {
124-
store<T>(
125-
changetype<usize>(buffer) + (<usize>index << alignof<T>()) + <usize>byteOffset,
126-
value,
127-
BUFFER_HEADER_SIZE
128-
);
101+
export abstract class ArrayBufferBase {
102+
get byteLength(): i32 {
103+
var header = changetype<HEADER>(changetype<usize>(this) - HEADER_SIZE);
104+
return header.payloadSize;
105+
}
129106
}
130107

131108
// === String =====================================================================================
132109

133-
/** Size of a string header, excl. common runtime header. */
134-
@inline export const STRING_HEADER_SIZE: usize = (offsetof<String>() + 1) & ~1; // 2 byte aligned
135-
136-
/** Allocates a new String and returns a pointer to it. */
137-
@inline export function ALLOC_STRING(length: u32): String {
138-
return changetype<String>(ALLOC(STRING_HEADER_SIZE + (length << 1)));
139-
}
140-
141-
/** Reallocates a String if necessary. Returns a pointer to it. */
142-
@inline export function REALLOC_STRING(ref: usize, length: u32): String {
143-
return changetype<String>(REALLOC(ref, STRING_HEADER_SIZE + (length << 1)));
110+
export abstract class StringBase {
111+
get length(): i32 {
112+
var header = changetype<HEADER>(changetype<usize>(this) - HEADER_SIZE);
113+
return header.payloadSize >>> 1;
114+
}
144115
}
145-
146-
// ...

0 commit comments

Comments
 (0)