Skip to content

Commit 47e4b8e

Browse files
committed
more
1 parent bfc7e42 commit 47e4b8e

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

std/assembly/rt.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ export function __typeinfo(id: u32): TypeinfoFlags {
2525

2626
// @ts-ignore: decorator
2727
@unsafe
28-
export function __instanceof(ref: usize, superId: u32): bool { // keyword
29-
var id = changetype<OBJECT>(ref - TOTAL_OVERHEAD).rtId;
28+
export function __instanceof(ptr: usize, classId: u32): bool { // keyword
29+
var id = changetype<OBJECT>(ptr - TOTAL_OVERHEAD).rtId;
3030
var ptr = __rtti_base;
3131
if (id <= load<u32>(ptr)) {
32-
do if (id == superId) return true;
32+
do if (id == classId) return true;
3333
while (id = changetype<Typeinfo>(ptr + sizeof<u32>() + id * offsetof<Typeinfo>()).base);
3434
}
3535
return false;

std/assembly/rt/README.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,54 @@ The runtime provides the functionality necessary to dynamically allocate and dea
66
Interface
77
---------
88

9-
### Memory manager
10-
11-
* **__alloc**(size: `usize`): `usize`<br />
12-
Dynamically allocates a chunk of memory of at least the specified size and returns its address.
13-
Alignment is guaranteed to be 16 bytes to fit up to v128 values naturally.
14-
15-
* **__realloc**(ref: `usize`, size: `usize`): `usize`<br />
16-
Dynamically changes the size of a chunk of memory, possibly moving it to a new address.
17-
18-
* **__free**(ref: `usize`): `void`<br />
19-
Frees a dynamically allocated chunk of memory by its address.
20-
219
### Garbage collector / `--exportRuntime`
2210

2311
* **__new**(size: `usize`, id: `u32` = 0): `usize`<br />
2412
Dynamically allocates a GC object of at least the specified size and returns its address.
2513
Alignment is guaranteed to be 16 bytes to fit up to v128 values naturally.
2614
GC-allocated objects cannot be used with `__realloc` and `__free`.
2715

16+
* **__pin**(ptr: `usize`): `usize`<br />
17+
Pins the object pointed to by `ptr` externally so it and its directly reachable members and indirectly reachable objects do not become garbage collected.
18+
19+
* **__unpin**(ptr: `usize`): `void`<br />
20+
Unpins the object pointed to by `ptr` externally so it can become garbage collected.
21+
2822
* **__collect**(): `void`<br />
29-
Performs a full garbage collection cycle.
23+
Performs a full garbage collection.
3024

3125
### Internals
3226

27+
* **__alloc**(size: `usize`): `usize`<br />
28+
Dynamically allocates a chunk of memory of at least the specified size and returns its address.
29+
Alignment is guaranteed to be 16 bytes to fit up to v128 values naturally.
30+
31+
* **__realloc**(ptr: `usize`, size: `usize`): `usize`<br />
32+
Dynamically changes the size of a chunk of memory, possibly moving it to a new address.
33+
34+
* **__free**(ptr: `usize`): `void`<br />
35+
Frees a dynamically allocated chunk of memory by its address.
36+
3337
* **__renew**(ptr: `usize`, size: `usize`): `usize`<br />
3438
Like `__realloc`, but for `__new`ed GC objects.
3539

3640
* **__link**(parentPtr: `usize`, childPtr: `usize`, expectMultiple: `bool`): `void`<br />
3741
Introduces a link from a parent object to a child object, i.e. upon `parent.field = child`.
3842

39-
* **__visit**(ref: `usize`, cookie: `u32`): `void`<br />
43+
* **__visit**(ptr: `usize`, cookie: `u32`): `void`<br />
4044
Concrete visitor implementation called during traversal. Cookie can be used to indicate one of multiple operations.
4145

42-
### Built-ins
43-
44-
* **__typeinfo**(id: `u32`): `RTTIFlags`<br />
45-
Obtains the runtime type information for objects with the specified runtime id. Runtime type information is a set of flags indicating whether a type is managed, an array or similar, and what the relevant alignments when creating an instance externally are etc.
46-
47-
* **__instanceof**
48-
4946
* **__visit_globals**(cookie: `u32`): `void`<br />
5047
Calls `__visit` on each global that is of a managed type.
5148

52-
* **__visit_members**(ref: `usize`, cookie: `u32`): `void`<br />
53-
Calls `__visit` on each member of the object pointed to by `ref`.
49+
* **__visit_members**(ptr: `usize`, cookie: `u32`): `void`<br />
50+
Calls `__visit` on each member of the object pointed to by `ptr`.
5451

55-
### Related
52+
* **__typeinfo**(id: `u32`): `RTTIFlags`<br />
53+
Obtains the runtime type information for objects with the specified runtime id. Runtime type information is a set of flags indicating whether a type is managed, an array or similar, and what the relevant alignments when creating an instance externally are etc.
5654

57-
* **idof**<`T`>(): `u32`<br />
58-
Obtains the unique internal class id of a managed type.
55+
* **__instanceof**(ptr: `usize`, classId: `u32`): `bool`<br />
56+
Tests if the object pointed to by `ptr` is an instance of the specified class id.
5957

6058
ITCMS / `--runtime incremental`
6159
-----
@@ -84,3 +82,5 @@ STUB / `--runtime stub`
8482
----
8583

8684
The stub is a maximally minimal runtime substitute, consisting of a simple and fast bump allocator with no means of freeing up memory again, except when freeing the respective most recently allocated object on top of the bump. Useful where memory is not a concern, and/or where it is sufficient to destroy the whole module including any potential garbage after execution.
85+
86+
See also: [Garbage collection](https://www.assemblyscript.org/garbage-collection.html)

0 commit comments

Comments
 (0)