Skip to content

Commit 0c537c3

Browse files
committed
test a few things
1 parent 4f1a971 commit 0c537c3

File tree

6 files changed

+6803
-26
lines changed

6 files changed

+6803
-26
lines changed

std/assembly/internal/runtime.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class HEADER {
2525
/** Magic value used to validate common runtime headers. */
2626
@inline export const HEADER_MAGIC: u32 = 0xA55E4B17;
2727

28-
/** Aligns an allocation to actual block size. */
28+
/** Aligns an allocation to actual block size. Primarily targets TLSF. */
2929
export function ALIGN(payloadSize: usize): usize {
3030
// round up to power of 2, e.g. with HEADER_SIZE=8:
3131
// 0 -> 2^3 = 8
@@ -36,14 +36,6 @@ export function ALIGN(payloadSize: usize): usize {
3636
return <usize>1 << <usize>(<u32>32 - clz<u32>(payloadSize + HEADER_SIZE - 1));
3737
}
3838

39-
/** Gets to the common runtime header of the specified reference. */
40-
export function UNREF(ref: usize): HEADER {
41-
assert(ref >= HEAP_BASE + HEADER_SIZE); // must be a heap object
42-
var header = changetype<HEADER>(ref - HEADER_SIZE);
43-
assert(header.classId == HEADER_MAGIC); // must be unregistered
44-
return header;
45-
}
46-
4739
/** Allocates a new object and returns a pointer to its payload. */
4840
export function ALLOC(payloadSize: u32): usize {
4941
var header = changetype<HEADER>(memory.allocate(ALIGN(payloadSize)));
@@ -60,7 +52,7 @@ export function ALLOC(payloadSize: u32): usize {
6052

6153
/** Reallocates an object if necessary. Returns a pointer to its (moved) payload. */
6254
export function REALLOC(ref: usize, newPayloadSize: u32): usize {
63-
var header = UNREF(ref);
55+
var header = changetype<HEADER>(ref - HEADER_SIZE);
6456
var payloadSize = header.payloadSize;
6557
if (payloadSize < newPayloadSize) {
6658
let newAlignedSize = ALIGN(newPayloadSize);
@@ -93,13 +85,17 @@ export function REALLOC(ref: usize, newPayloadSize: u32): usize {
9385

9486
/** Frees an object. Must not have been registered with GC yet. */
9587
export function FREE(ref: usize): void {
96-
var header = UNREF(ref);
88+
assert(ref >= HEAP_BASE + HEADER_SIZE); // must be a heap object
89+
var header = changetype<HEADER>(ref - HEADER_SIZE);
90+
assert(header.classId == HEADER_MAGIC); // must be unregistered
9791
memory.free(changetype<usize>(header));
9892
}
9993

10094
/** Registers a managed object with GC. Cannot be changed anymore afterwards. */
10195
export function REGISTER<T>(ref: usize, parentRef: usize): void {
102-
var header = UNREF(ref);
96+
assert(ref >= HEAP_BASE + HEADER_SIZE); // must be a heap object
97+
var header = changetype<HEADER>(ref - HEADER_SIZE);
98+
assert(header.classId == HEADER_MAGIC); // must be unregistered
10399
header.classId = __rt_classid<T>();
104100
if (GC) __REGISTER_IMPL(ref, parentRef); // tslint:disable-line
105101
}

tests/compiler/std/gc-integration.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,3 @@ var b_ref: B = changetype<B>(32); // global root, non-nullable
1717
var i: i32 = 0;
1818
__rt_iterateroots((ref: usize): void => { assert(<u32>ref == ++i << 3); });
1919
assert(i == 4);
20-
21-
assert(__rt_classid<A>() != __rt_classid<B>());

tests/compiler/std/gc-integration.untouched.wat

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,6 @@
5858
call $~lib/env/abort
5959
unreachable
6060
end
61-
i32.const 43
62-
i32.const 44
63-
i32.ne
64-
i32.eqz
65-
if
66-
i32.const 0
67-
i32.const 8
68-
i32.const 21
69-
i32.const 0
70-
call $~lib/env/abort
71-
unreachable
72-
end
7361
)
7462
(func $start (; 3 ;) (type $FUNCSIG$v)
7563
call $start:std/gc-integration

0 commit comments

Comments
 (0)