toilscript 0.0.1 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/LICENSE +201 -201
  2. package/NOTICE +94 -94
  3. package/README.md +101 -114
  4. package/bin/asc.js +0 -0
  5. package/bin/asinit.js +6 -6
  6. package/dist/asc.generated.d.ts +10027 -0
  7. package/dist/asc.js +24474 -0
  8. package/dist/asc.js.map +7 -0
  9. package/dist/importmap.json +9 -0
  10. package/dist/toilscript.generated.d.ts +11242 -0
  11. package/dist/toilscript.js +337 -0
  12. package/dist/toilscript.js.map +7 -0
  13. package/dist/web.js +22 -0
  14. package/lib/binaryen.d.ts +2 -2
  15. package/lib/binaryen.js +2 -2
  16. package/package.json +115 -114
  17. package/std/README.md +6 -6
  18. package/std/assembly/array.ts +550 -550
  19. package/std/assembly/arraybuffer.ts +77 -77
  20. package/std/assembly/atomics.ts +127 -127
  21. package/std/assembly/bindings/asyncify.ts +16 -16
  22. package/std/assembly/bindings/dom.ts +291 -291
  23. package/std/assembly/bindings/node.ts +6 -6
  24. package/std/assembly/bitflags.ts +53 -53
  25. package/std/assembly/builtins.ts +2650 -2650
  26. package/std/assembly/byteslice.ts +177 -177
  27. package/std/assembly/compat.ts +2 -2
  28. package/std/assembly/console.ts +42 -42
  29. package/std/assembly/crypto.ts +9 -9
  30. package/std/assembly/dataview.ts +181 -181
  31. package/std/assembly/date.ts +375 -375
  32. package/std/assembly/diagnostics.ts +11 -11
  33. package/std/assembly/encoding.ts +151 -151
  34. package/std/assembly/endian.ts +45 -45
  35. package/std/assembly/error.ts +44 -44
  36. package/std/assembly/fixedarray.ts +173 -173
  37. package/std/assembly/fixedmap.ts +326 -326
  38. package/std/assembly/fixedset.ts +275 -275
  39. package/std/assembly/function.ts +42 -42
  40. package/std/assembly/index.d.ts +2892 -2891
  41. package/std/assembly/iterator.ts +35 -35
  42. package/std/assembly/map.ts +269 -269
  43. package/std/assembly/math.ts +3289 -3289
  44. package/std/assembly/memory.ts +123 -123
  45. package/std/assembly/number.ts +388 -388
  46. package/std/assembly/object.ts +36 -36
  47. package/std/assembly/performance.ts +9 -9
  48. package/std/assembly/pointer.ts +80 -80
  49. package/std/assembly/polyfills.ts +27 -27
  50. package/std/assembly/process.ts +50 -50
  51. package/std/assembly/reference.ts +48 -48
  52. package/std/assembly/regexp.ts +12 -12
  53. package/std/assembly/rt/README.md +83 -83
  54. package/std/assembly/rt/common.ts +81 -81
  55. package/std/assembly/rt/index-incremental.ts +2 -2
  56. package/std/assembly/rt/index-memory.ts +1 -1
  57. package/std/assembly/rt/index-minimal.ts +2 -2
  58. package/std/assembly/rt/index-stub.ts +1 -1
  59. package/std/assembly/rt/index.d.ts +37 -37
  60. package/std/assembly/rt/itcms.ts +419 -419
  61. package/std/assembly/rt/memory-runtime.ts +94 -94
  62. package/std/assembly/rt/rtrace.ts +15 -15
  63. package/std/assembly/rt/stub.ts +133 -133
  64. package/std/assembly/rt/tcms.ts +254 -254
  65. package/std/assembly/rt/tlsf.ts +592 -592
  66. package/std/assembly/rt.ts +90 -90
  67. package/std/assembly/set.ts +225 -225
  68. package/std/assembly/shared/feature.ts +68 -68
  69. package/std/assembly/shared/runtime.ts +13 -13
  70. package/std/assembly/shared/target.ts +11 -11
  71. package/std/assembly/shared/tsconfig.json +11 -11
  72. package/std/assembly/shared/typeinfo.ts +72 -72
  73. package/std/assembly/staticarray.ts +423 -423
  74. package/std/assembly/string.ts +850 -850
  75. package/std/assembly/symbol.ts +114 -114
  76. package/std/assembly/table.ts +16 -16
  77. package/std/assembly/toilscript.ts +16 -0
  78. package/std/assembly/tsconfig.json +6 -6
  79. package/std/assembly/typedarray.ts +1954 -1954
  80. package/std/assembly/uri.ts +17 -17
  81. package/std/assembly/util/bytes.ts +107 -107
  82. package/std/assembly/util/casemap.ts +497 -497
  83. package/std/assembly/util/error.ts +58 -58
  84. package/std/assembly/util/hash.ts +117 -117
  85. package/std/assembly/util/math.ts +1922 -1922
  86. package/std/assembly/util/memory.ts +290 -290
  87. package/std/assembly/util/number.ts +873 -873
  88. package/std/assembly/util/sort.ts +313 -313
  89. package/std/assembly/util/string.ts +1202 -1202
  90. package/std/assembly/util/uri.ts +275 -275
  91. package/std/assembly/vector.ts +4 -4
  92. package/std/assembly.json +16 -16
  93. package/std/portable/index.d.ts +461 -461
  94. package/std/portable/index.js +416 -416
  95. package/std/portable.json +11 -11
  96. package/std/types/assembly/index.d.ts +1 -1
  97. package/std/types/assembly/package.json +2 -2
  98. package/std/types/portable/index.d.ts +1 -1
  99. package/std/types/portable/package.json +2 -2
  100. package/tsconfig-base.json +13 -13
  101. package/util/README.md +23 -23
  102. package/util/browser/fs.js +1 -1
  103. package/util/browser/module.js +5 -5
  104. package/util/browser/path.js +520 -520
  105. package/util/browser/process.js +59 -59
  106. package/util/browser/url.js +23 -23
  107. package/util/cpu.d.ts +9 -9
  108. package/util/cpu.js +42 -42
  109. package/util/find.d.ts +6 -6
  110. package/util/find.js +20 -20
  111. package/util/node.d.ts +21 -21
  112. package/util/node.js +34 -34
  113. package/util/options.d.ts +70 -70
  114. package/util/options.js +262 -262
  115. package/util/terminal.d.ts +52 -52
  116. package/util/terminal.js +35 -35
  117. package/util/text.d.ts +26 -26
  118. package/util/text.js +114 -114
  119. package/util/tsconfig.json +9 -9
  120. package/util/web.d.ts +11 -11
  121. package/util/web.js +33 -33
@@ -1,83 +1,83 @@
1
- The AssemblyScript Runtime
2
- ==========================
3
-
4
- The runtime provides the functionality necessary to dynamically allocate and deallocate memory of objects, arrays and buffers, as well as collect garbage that is no longer used. The current implementation is either a Two-Color Mark & Sweep (TCMS) garbage collector that must be called manually when the execution stack is unwound or an Incremental Tri-Color Mark & Sweep (ITCMS) garbage collector that is fully automated with a shadow stack, implemented on top of a Two-Level Segregate Fit (TLSF) memory manager. It's not designed to be the fastest of its kind, but intentionally focuses on simplicity and ease of integration until we can replace it with the real deal, i.e. Wasm GC.
5
-
6
- Interface
7
- ---------
8
-
9
- ### Garbage collector / `--exportRuntime`
10
-
11
- * **__new**(size: `usize`, id: `u32` = 0): `usize`<br />
12
- Dynamically allocates a GC object 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
- GC-allocated objects cannot be used with `__realloc` and `__free`.
15
-
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
-
22
- * **__collect**(): `void`<br />
23
- Performs a full garbage collection.
24
-
25
- ### Internals
26
-
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
-
37
- * **__renew**(ptr: `usize`, size: `usize`): `usize`<br />
38
- Like `__realloc`, but for `__new`ed GC objects.
39
-
40
- * **__link**(parentPtr: `usize`, childPtr: `usize`, expectMultiple: `bool`): `void`<br />
41
- Introduces a link from a parent object to a child object, i.e. upon `parent.field = child`.
42
-
43
- * **__visit**(ptr: `usize`, cookie: `u32`): `void`<br />
44
- Concrete visitor implementation called during traversal. Cookie can be used to indicate one of multiple operations.
45
-
46
- * **__visit_globals**(cookie: `u32`): `void`<br />
47
- Calls `__visit` on each global that is of a managed type.
48
-
49
- * **__visit_members**(ptr: `usize`, cookie: `u32`): `void`<br />
50
- Calls `__visit` on each member of the object pointed to by `ptr`.
51
-
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.
54
-
55
- ITCMS / `--runtime incremental`
56
- -----
57
-
58
- The Incremental Tri-Color Mark & Sweep garbage collector maintains a separate shadow stack of managed values in the background to achieve full automation. Maintaining another stack introduces some overhead compared to the simpler Two-Color Mark & Sweep garbage collector, but makes it independent of whether the execution stack is unwound or not when it is invoked, so the garbage collector can run interleaved with the program.
59
-
60
- There are several constants one can experiment with to tweak ITCMS's automation:
61
-
62
- * `--use ASC_GC_GRANULARITY=1024`<br />
63
- How often to interrupt. The default of 1024 means "interrupt each 1024 bytes allocated".
64
- * `--use ASC_GC_STEPFACTOR=200`<br />
65
- How long to interrupt. The default of 200% means "run at double the speed of allocations".
66
- * `--use ASC_GC_IDLEFACTOR=200`<br />
67
- How long to idle. The default of 200% means "wait for memory to double before kicking in again".
68
- * `--use ASC_GC_MARKCOST=1`<br />
69
- How costly it is to mark one object. Budget per interrupt is `GRANULARITY * STEPFACTOR / 100`.
70
- * `--use ASC_GC_SWEEPCOST=10`<br />
71
- How costly it is to sweep one object. Budget per interrupt is `GRANULARITY * STEPFACTOR / 100`.
72
-
73
- TCMS / `--runtime minimal`
74
- ----
75
-
76
- If automation and low pause times aren't strictly necessary, using the Two-Color Mark & Sweep garbage collector instead by invoking collection manually at appropriate times when the execution stack is unwound may be more performant as it simpler and has less overhead. The execution stack is typically unwound when invoking the collector externally, at a place that is not indirectly called from Wasm.
77
-
78
- STUB / `--runtime stub`
79
- ----
80
-
81
- 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.
82
-
83
- See also: [Garbage collection](https://www.assemblyscript.org/garbage-collection.html)
1
+ The AssemblyScript Runtime
2
+ ==========================
3
+
4
+ The runtime provides the functionality necessary to dynamically allocate and deallocate memory of objects, arrays and buffers, as well as collect garbage that is no longer used. The current implementation is either a Two-Color Mark & Sweep (TCMS) garbage collector that must be called manually when the execution stack is unwound or an Incremental Tri-Color Mark & Sweep (ITCMS) garbage collector that is fully automated with a shadow stack, implemented on top of a Two-Level Segregate Fit (TLSF) memory manager. It's not designed to be the fastest of its kind, but intentionally focuses on simplicity and ease of integration until we can replace it with the real deal, i.e. Wasm GC.
5
+
6
+ Interface
7
+ ---------
8
+
9
+ ### Garbage collector / `--exportRuntime`
10
+
11
+ * **__new**(size: `usize`, id: `u32` = 0): `usize`<br />
12
+ Dynamically allocates a GC object 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
+ GC-allocated objects cannot be used with `__realloc` and `__free`.
15
+
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
+
22
+ * **__collect**(): `void`<br />
23
+ Performs a full garbage collection.
24
+
25
+ ### Internals
26
+
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
+
37
+ * **__renew**(ptr: `usize`, size: `usize`): `usize`<br />
38
+ Like `__realloc`, but for `__new`ed GC objects.
39
+
40
+ * **__link**(parentPtr: `usize`, childPtr: `usize`, expectMultiple: `bool`): `void`<br />
41
+ Introduces a link from a parent object to a child object, i.e. upon `parent.field = child`.
42
+
43
+ * **__visit**(ptr: `usize`, cookie: `u32`): `void`<br />
44
+ Concrete visitor implementation called during traversal. Cookie can be used to indicate one of multiple operations.
45
+
46
+ * **__visit_globals**(cookie: `u32`): `void`<br />
47
+ Calls `__visit` on each global that is of a managed type.
48
+
49
+ * **__visit_members**(ptr: `usize`, cookie: `u32`): `void`<br />
50
+ Calls `__visit` on each member of the object pointed to by `ptr`.
51
+
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.
54
+
55
+ ITCMS / `--runtime incremental`
56
+ -----
57
+
58
+ The Incremental Tri-Color Mark & Sweep garbage collector maintains a separate shadow stack of managed values in the background to achieve full automation. Maintaining another stack introduces some overhead compared to the simpler Two-Color Mark & Sweep garbage collector, but makes it independent of whether the execution stack is unwound or not when it is invoked, so the garbage collector can run interleaved with the program.
59
+
60
+ There are several constants one can experiment with to tweak ITCMS's automation:
61
+
62
+ * `--use ASC_GC_GRANULARITY=1024`<br />
63
+ How often to interrupt. The default of 1024 means "interrupt each 1024 bytes allocated".
64
+ * `--use ASC_GC_STEPFACTOR=200`<br />
65
+ How long to interrupt. The default of 200% means "run at double the speed of allocations".
66
+ * `--use ASC_GC_IDLEFACTOR=200`<br />
67
+ How long to idle. The default of 200% means "wait for memory to double before kicking in again".
68
+ * `--use ASC_GC_MARKCOST=1`<br />
69
+ How costly it is to mark one object. Budget per interrupt is `GRANULARITY * STEPFACTOR / 100`.
70
+ * `--use ASC_GC_SWEEPCOST=10`<br />
71
+ How costly it is to sweep one object. Budget per interrupt is `GRANULARITY * STEPFACTOR / 100`.
72
+
73
+ TCMS / `--runtime minimal`
74
+ ----
75
+
76
+ If automation and low pause times aren't strictly necessary, using the Two-Color Mark & Sweep garbage collector instead by invoking collection manually at appropriate times when the execution stack is unwound may be more performant as it simpler and has less overhead. The execution stack is typically unwound when invoking the collector externally, at a place that is not indirectly called from Wasm.
77
+
78
+ STUB / `--runtime stub`
79
+ ----
80
+
81
+ 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.
82
+
83
+ See also: [Garbage collection](https://www.assemblyscript.org/garbage-collection.html)
@@ -1,81 +1,81 @@
1
- // Alignment guarantees
2
-
3
- // @ts-ignore: decorator
4
- @inline export const AL_BITS: u32 = 4; // 16 bytes to fit up to v128
5
- // @ts-ignore: decorator
6
- @inline export const AL_SIZE: usize = 1 << <usize>AL_BITS;
7
- // @ts-ignore: decorator
8
- @inline export const AL_MASK: usize = AL_SIZE - 1;
9
-
10
- // Extra debugging
11
-
12
- // @ts-ignore: decorator
13
- @inline export const DEBUG = true;
14
- // @ts-ignore: decorator
15
- @inline export const TRACE = false;
16
- // @ts-ignore: decorator
17
- @inline export const RTRACE = isDefined(ASC_RTRACE);
18
- // @ts-ignore: decorator
19
- @inline export const PROFILE = isDefined(ASC_PROFILE);
20
-
21
- // Memory manager
22
-
23
- // ╒════════════ Memory manager block layout (32-bit) ═════════════╕
24
- // 3 2 1
25
- // 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 bits
26
- // ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┤
27
- // │ MM info │ -4
28
- // ╞>ptr═══════════════════════════════════════════════════════════╡
29
- // │ ... │
30
- @unmanaged export class BLOCK {
31
- /** Memory manager info. */
32
- mmInfo: usize;
33
- }
34
-
35
- /** Overhead of a memory manager block. */
36
- // @ts-ignore: decorator
37
- @inline export const BLOCK_OVERHEAD: usize = offsetof<BLOCK>();
38
-
39
- /** Maximum size of a memory manager block's payload. */
40
- // @ts-ignore: decorator
41
- @inline export const BLOCK_MAXSIZE: usize = (1 << 30) - BLOCK_OVERHEAD;
42
-
43
- // Garbage collector
44
-
45
- // ╒══════════ Garbage collector object layout (32-bit) ═══════════╕
46
- // 3 2 1
47
- // 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 bits
48
- // ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┤
49
- // │ Memory manager block │ -20
50
- // ╞═══════════════════════════════════════════════════════════════╡
51
- // │ GC info │ -16
52
- // ├───────────────────────────────────────────────────────────────┤
53
- // │ GC info │ -12
54
- // ├───────────────────────────────────────────────────────────────┤
55
- // │ RT id │ -8
56
- // ├───────────────────────────────────────────────────────────────┤
57
- // │ RT size │ -4
58
- // ╞>ptr═══════════════════════════════════════════════════════════╡
59
- // │ ... │
60
- @unmanaged export class OBJECT extends BLOCK {
61
- /** Garbage collector info. */
62
- gcInfo: u32;
63
- /** Garbage collector info. */
64
- gcInfo2: u32;
65
- /** Runtime class id. */
66
- rtId: u32;
67
- /** Runtime object size. */
68
- rtSize: u32;
69
- }
70
-
71
- /** Overhead of a garbage collector object. Excludes memory manager block overhead. */
72
- // @ts-ignore: decorator
73
- @inline export const OBJECT_OVERHEAD: usize = (offsetof<OBJECT>() - BLOCK_OVERHEAD + AL_MASK) & ~AL_MASK;
74
-
75
- /** Maximum size of a garbage collector object's payload. */
76
- // @ts-ignore: decorator
77
- @inline export const OBJECT_MAXSIZE: usize = BLOCK_MAXSIZE - OBJECT_OVERHEAD;
78
-
79
- /** Total of memory manager and garbage collector overhead. */
80
- // @ts-ignore: decorator
81
- @inline export const TOTAL_OVERHEAD: usize = BLOCK_OVERHEAD + OBJECT_OVERHEAD;
1
+ // Alignment guarantees
2
+
3
+ // @ts-ignore: decorator
4
+ @inline export const AL_BITS: u32 = 4; // 16 bytes to fit up to v128
5
+ // @ts-ignore: decorator
6
+ @inline export const AL_SIZE: usize = 1 << <usize>AL_BITS;
7
+ // @ts-ignore: decorator
8
+ @inline export const AL_MASK: usize = AL_SIZE - 1;
9
+
10
+ // Extra debugging
11
+
12
+ // @ts-ignore: decorator
13
+ @inline export const DEBUG = true;
14
+ // @ts-ignore: decorator
15
+ @inline export const TRACE = false;
16
+ // @ts-ignore: decorator
17
+ @inline export const RTRACE = isDefined(ASC_RTRACE);
18
+ // @ts-ignore: decorator
19
+ @inline export const PROFILE = isDefined(ASC_PROFILE);
20
+
21
+ // Memory manager
22
+
23
+ // ╒════════════ Memory manager block layout (32-bit) ═════════════╕
24
+ // 3 2 1
25
+ // 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 bits
26
+ // ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┤
27
+ // │ MM info │ -4
28
+ // ╞>ptr═══════════════════════════════════════════════════════════╡
29
+ // │ ... │
30
+ @unmanaged export class BLOCK {
31
+ /** Memory manager info. */
32
+ mmInfo: usize;
33
+ }
34
+
35
+ /** Overhead of a memory manager block. */
36
+ // @ts-ignore: decorator
37
+ @inline export const BLOCK_OVERHEAD: usize = offsetof<BLOCK>();
38
+
39
+ /** Maximum size of a memory manager block's payload. */
40
+ // @ts-ignore: decorator
41
+ @inline export const BLOCK_MAXSIZE: usize = (1 << 30) - BLOCK_OVERHEAD;
42
+
43
+ // Garbage collector
44
+
45
+ // ╒══════════ Garbage collector object layout (32-bit) ═══════════╕
46
+ // 3 2 1
47
+ // 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 bits
48
+ // ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┤
49
+ // │ Memory manager block │ -20
50
+ // ╞═══════════════════════════════════════════════════════════════╡
51
+ // │ GC info │ -16
52
+ // ├───────────────────────────────────────────────────────────────┤
53
+ // │ GC info │ -12
54
+ // ├───────────────────────────────────────────────────────────────┤
55
+ // │ RT id │ -8
56
+ // ├───────────────────────────────────────────────────────────────┤
57
+ // │ RT size │ -4
58
+ // ╞>ptr═══════════════════════════════════════════════════════════╡
59
+ // │ ... │
60
+ @unmanaged export class OBJECT extends BLOCK {
61
+ /** Garbage collector info. */
62
+ gcInfo: u32;
63
+ /** Garbage collector info. */
64
+ gcInfo2: u32;
65
+ /** Runtime class id. */
66
+ rtId: u32;
67
+ /** Runtime object size. */
68
+ rtSize: u32;
69
+ }
70
+
71
+ /** Overhead of a garbage collector object. Excludes memory manager block overhead. */
72
+ // @ts-ignore: decorator
73
+ @inline export const OBJECT_OVERHEAD: usize = (offsetof<OBJECT>() - BLOCK_OVERHEAD + AL_MASK) & ~AL_MASK;
74
+
75
+ /** Maximum size of a garbage collector object's payload. */
76
+ // @ts-ignore: decorator
77
+ @inline export const OBJECT_MAXSIZE: usize = BLOCK_MAXSIZE - OBJECT_OVERHEAD;
78
+
79
+ /** Total of memory manager and garbage collector overhead. */
80
+ // @ts-ignore: decorator
81
+ @inline export const TOTAL_OVERHEAD: usize = BLOCK_OVERHEAD + OBJECT_OVERHEAD;
@@ -1,2 +1,2 @@
1
- import "./tlsf";
2
- import "./itcms";
1
+ import "./tlsf";
2
+ import "./itcms";
@@ -1 +1 @@
1
- import "./memory-runtime";
1
+ import "./memory-runtime";
@@ -1,2 +1,2 @@
1
- import "./tlsf";
2
- import "./tcms";
1
+ import "./tlsf";
2
+ import "./tcms";
@@ -1 +1 @@
1
- import "./stub";
1
+ import "./stub";
@@ -1,37 +1,37 @@
1
- // Memory manager
2
- declare function __alloc(size: usize): usize;
3
- declare function __realloc(ptr: usize, size: usize): usize;
4
- declare function __free(ptr: usize): void;
5
- declare function __reset(): void;
6
-
7
- // Garbage collector
8
- declare function __new(size: usize, id: u32): usize;
9
- declare function __renew(ptr: usize, size: usize): usize;
10
- declare function __link(parentPtr: usize, childPtr: usize, expectMultiple: bool): void;
11
- declare function __collect(): void;
12
-
13
- // Runtime type info
14
- declare function __typeinfo(id: u32): u32;
15
-
16
- // Visitors
17
- declare function __visit(ptr: usize, cookie: i32): void;
18
- declare function __visit_globals(cookie: u32): void;
19
- declare function __visit_members(ptr: usize, cookie: u32): void;
20
-
21
- // Allocation helpers
22
- declare function __newBuffer(size: usize, id: u32, data?: usize): usize;
23
- declare function __newArray(length: i32, alignLog2: usize, id: u32, data?: usize): usize;
24
-
25
- // Finalization
26
- declare function __finalize(ptr: usize): void;
27
-
28
- // Debugging
29
- declare const ASC_RTRACE: bool;
30
- declare const ASC_PROFILE: bool;
31
-
32
- // Incremental GC constants
33
- declare const ASC_GC_GRANULARITY: i32;
34
- declare const ASC_GC_SWEEPFACTOR: i32;
35
- declare const ASC_GC_IDLEFACTOR: i32;
36
- declare const ASC_GC_MARKCOST: i32;
37
- declare const ASC_GC_SWEEPCOST: i32;
1
+ // Memory manager
2
+ declare function __alloc(size: usize): usize;
3
+ declare function __realloc(ptr: usize, size: usize): usize;
4
+ declare function __free(ptr: usize): void;
5
+ declare function __reset(): void;
6
+
7
+ // Garbage collector
8
+ declare function __new(size: usize, id: u32): usize;
9
+ declare function __renew(ptr: usize, size: usize): usize;
10
+ declare function __link(parentPtr: usize, childPtr: usize, expectMultiple: bool): void;
11
+ declare function __collect(): void;
12
+
13
+ // Runtime type info
14
+ declare function __typeinfo(id: u32): u32;
15
+
16
+ // Visitors
17
+ declare function __visit(ptr: usize, cookie: i32): void;
18
+ declare function __visit_globals(cookie: u32): void;
19
+ declare function __visit_members(ptr: usize, cookie: u32): void;
20
+
21
+ // Allocation helpers
22
+ declare function __newBuffer(size: usize, id: u32, data?: usize): usize;
23
+ declare function __newArray(length: i32, alignLog2: usize, id: u32, data?: usize): usize;
24
+
25
+ // Finalization
26
+ declare function __finalize(ptr: usize): void;
27
+
28
+ // Debugging
29
+ declare const ASC_RTRACE: bool;
30
+ declare const ASC_PROFILE: bool;
31
+
32
+ // Incremental GC constants
33
+ declare const ASC_GC_GRANULARITY: i32;
34
+ declare const ASC_GC_SWEEPFACTOR: i32;
35
+ declare const ASC_GC_IDLEFACTOR: i32;
36
+ declare const ASC_GC_MARKCOST: i32;
37
+ declare const ASC_GC_SWEEPCOST: i32;