toilscript 0.0.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.
- package/LICENSE +201 -0
- package/NOTICE +94 -0
- package/README.md +114 -0
- package/bin/asc.js +35 -0
- package/bin/asinit.js +468 -0
- package/dist/asc.d.ts +4 -0
- package/dist/toilscript.d.ts +4 -0
- package/dist/transform.cjs +1 -0
- package/dist/transform.d.ts +1 -0
- package/dist/transform.js +1 -0
- package/lib/binaryen.d.ts +2 -0
- package/lib/binaryen.js +2 -0
- package/package.json +114 -0
- package/std/README.md +6 -0
- package/std/assembly/array.ts +550 -0
- package/std/assembly/arraybuffer.ts +77 -0
- package/std/assembly/atomics.ts +127 -0
- package/std/assembly/bindings/asyncify.ts +16 -0
- package/std/assembly/bindings/dom.ts +291 -0
- package/std/assembly/bindings/node.ts +6 -0
- package/std/assembly/bitflags.ts +53 -0
- package/std/assembly/builtins.ts +2650 -0
- package/std/assembly/byteslice.ts +177 -0
- package/std/assembly/compat.ts +2 -0
- package/std/assembly/console.ts +42 -0
- package/std/assembly/crypto.ts +9 -0
- package/std/assembly/dataview.ts +181 -0
- package/std/assembly/date.ts +375 -0
- package/std/assembly/diagnostics.ts +11 -0
- package/std/assembly/encoding.ts +151 -0
- package/std/assembly/endian.ts +45 -0
- package/std/assembly/error.ts +44 -0
- package/std/assembly/fixedarray.ts +173 -0
- package/std/assembly/fixedmap.ts +326 -0
- package/std/assembly/fixedset.ts +275 -0
- package/std/assembly/function.ts +42 -0
- package/std/assembly/index.d.ts +2891 -0
- package/std/assembly/iterator.ts +35 -0
- package/std/assembly/map.ts +269 -0
- package/std/assembly/math.ts +3289 -0
- package/std/assembly/memory.ts +123 -0
- package/std/assembly/number.ts +388 -0
- package/std/assembly/object.ts +36 -0
- package/std/assembly/performance.ts +9 -0
- package/std/assembly/pointer.ts +80 -0
- package/std/assembly/polyfills.ts +27 -0
- package/std/assembly/process.ts +50 -0
- package/std/assembly/reference.ts +48 -0
- package/std/assembly/regexp.ts +12 -0
- package/std/assembly/rt/README.md +83 -0
- package/std/assembly/rt/common.ts +81 -0
- package/std/assembly/rt/index-incremental.ts +2 -0
- package/std/assembly/rt/index-memory.ts +1 -0
- package/std/assembly/rt/index-minimal.ts +2 -0
- package/std/assembly/rt/index-stub.ts +1 -0
- package/std/assembly/rt/index.d.ts +37 -0
- package/std/assembly/rt/itcms.ts +419 -0
- package/std/assembly/rt/memory-runtime.ts +94 -0
- package/std/assembly/rt/rtrace.ts +15 -0
- package/std/assembly/rt/stub.ts +133 -0
- package/std/assembly/rt/tcms.ts +254 -0
- package/std/assembly/rt/tlsf.ts +592 -0
- package/std/assembly/rt.ts +90 -0
- package/std/assembly/set.ts +225 -0
- package/std/assembly/shared/feature.ts +68 -0
- package/std/assembly/shared/runtime.ts +13 -0
- package/std/assembly/shared/target.ts +11 -0
- package/std/assembly/shared/tsconfig.json +11 -0
- package/std/assembly/shared/typeinfo.ts +72 -0
- package/std/assembly/staticarray.ts +423 -0
- package/std/assembly/string.ts +850 -0
- package/std/assembly/symbol.ts +114 -0
- package/std/assembly/table.ts +16 -0
- package/std/assembly/tsconfig.json +6 -0
- package/std/assembly/typedarray.ts +1954 -0
- package/std/assembly/uri.ts +17 -0
- package/std/assembly/util/bytes.ts +107 -0
- package/std/assembly/util/casemap.ts +497 -0
- package/std/assembly/util/error.ts +58 -0
- package/std/assembly/util/hash.ts +117 -0
- package/std/assembly/util/math.ts +1922 -0
- package/std/assembly/util/memory.ts +290 -0
- package/std/assembly/util/number.ts +873 -0
- package/std/assembly/util/sort.ts +313 -0
- package/std/assembly/util/string.ts +1202 -0
- package/std/assembly/util/uri.ts +275 -0
- package/std/assembly/vector.ts +4 -0
- package/std/assembly.json +16 -0
- package/std/portable/index.d.ts +461 -0
- package/std/portable/index.js +416 -0
- package/std/portable.json +11 -0
- package/std/types/assembly/index.d.ts +1 -0
- package/std/types/assembly/package.json +3 -0
- package/std/types/portable/index.d.ts +1 -0
- package/std/types/portable/package.json +3 -0
- package/tsconfig-base.json +13 -0
- package/util/README.md +23 -0
- package/util/browser/fs.js +1 -0
- package/util/browser/module.js +5 -0
- package/util/browser/path.js +520 -0
- package/util/browser/process.js +59 -0
- package/util/browser/url.js +23 -0
- package/util/cpu.d.ts +9 -0
- package/util/cpu.js +42 -0
- package/util/find.d.ts +6 -0
- package/util/find.js +20 -0
- package/util/node.d.ts +21 -0
- package/util/node.js +34 -0
- package/util/options.d.ts +70 -0
- package/util/options.js +262 -0
- package/util/terminal.d.ts +52 -0
- package/util/terminal.js +35 -0
- package/util/text.d.ts +26 -0
- package/util/text.js +114 -0
- package/util/tsconfig.json +9 -0
- package/util/web.d.ts +11 -0
- package/util/web.js +33 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Canonical aliases
|
|
2
|
+
export type funcref = ref_func | null;
|
|
3
|
+
export type externref = ref_extern | null;
|
|
4
|
+
export type anyref = ref_any | null;
|
|
5
|
+
export type eqref = ref_eq | null;
|
|
6
|
+
export type i31ref = ref_i31 | null;
|
|
7
|
+
export type structref = ref_struct | null;
|
|
8
|
+
export type arrayref = ref_array | null;
|
|
9
|
+
export type stringref = ref_string | null;
|
|
10
|
+
export type stringview_wtf8 = ref_stringview_wtf8 | null;
|
|
11
|
+
export type stringview_wtf16 = ref_stringview_wtf16 | null;
|
|
12
|
+
export type stringview_iter = ref_stringview_iter | null;
|
|
13
|
+
|
|
14
|
+
@unmanaged
|
|
15
|
+
abstract class Ref {
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@final @unmanaged
|
|
19
|
+
export abstract class RefFunc extends Ref {
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@final @unmanaged
|
|
23
|
+
export abstract class RefExtern extends Ref {
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@final @unmanaged
|
|
27
|
+
export abstract class RefAny extends Ref {
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@final @unmanaged
|
|
31
|
+
export abstract class RefEq extends Ref {
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@final @unmanaged
|
|
35
|
+
export abstract class RefI31 extends Ref {
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@final @unmanaged
|
|
39
|
+
export abstract class RefStruct extends Ref {
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@final @unmanaged
|
|
43
|
+
export abstract class RefArray extends Ref {
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@final @unmanaged
|
|
47
|
+
export abstract class RefString extends Ref {
|
|
48
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export class RegExp {
|
|
2
|
+
|
|
3
|
+
// @binding(CALL_NEW, [ STRING, STRING], OBJECT_HANDLE)
|
|
4
|
+
constructor(pattern: string, flags: string = "") { throw new Error("unreachable"); }
|
|
5
|
+
|
|
6
|
+
// @binding(CALL_THIS, [ STRING ], PASS_THRU)
|
|
7
|
+
test(search: string): bool { throw new Error("unreachable"); }
|
|
8
|
+
|
|
9
|
+
// @binding(CALL_THIS, [], STRING)
|
|
10
|
+
toString(): string { throw new Error("unreachable"); }
|
|
11
|
+
|
|
12
|
+
}
|
|
@@ -0,0 +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)
|
|
@@ -0,0 +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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./memory-runtime";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./stub";
|
|
@@ -0,0 +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;
|