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,123 @@
|
|
|
1
|
+
import { memcmp, memmove, memset } from "./util/memory";
|
|
2
|
+
import { E_NOTIMPLEMENTED } from "./util/error";
|
|
3
|
+
|
|
4
|
+
/** Memory manager interface. */
|
|
5
|
+
export namespace memory {
|
|
6
|
+
|
|
7
|
+
/** Gets the size of the memory in pages. */
|
|
8
|
+
// @ts-ignore: decorator
|
|
9
|
+
@builtin
|
|
10
|
+
export declare function size(): i32;
|
|
11
|
+
|
|
12
|
+
/** Grows the memory by the given size in pages and returns the previous size in pages. */
|
|
13
|
+
// @ts-ignore: decorator
|
|
14
|
+
@unsafe @builtin
|
|
15
|
+
export declare function grow(pages: i32): i32;
|
|
16
|
+
|
|
17
|
+
/** Fills a section in memory with the specified byte value. */
|
|
18
|
+
// @ts-ignore: decorator
|
|
19
|
+
@unsafe @builtin
|
|
20
|
+
export function fill(dst: usize, c: u8, n: usize): void {
|
|
21
|
+
memset(dst, c, n); // fallback if "bulk-memory" isn't enabled
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Copies a section of memory to another. Has move semantics. */
|
|
25
|
+
// @ts-ignore: decorator
|
|
26
|
+
@unsafe @builtin
|
|
27
|
+
export function copy(dst: usize, src: usize, n: usize): void {
|
|
28
|
+
memmove(dst, src, n); // fallback if "bulk-memory" isn't enabled
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export namespace atomic {
|
|
32
|
+
|
|
33
|
+
// @ts-ignore: decorator
|
|
34
|
+
@unsafe @builtin
|
|
35
|
+
export declare function wait32(ptr: usize, expected: i32, timeout: i64): AtomicWaitResult;
|
|
36
|
+
|
|
37
|
+
// @ts-ignore: decorator
|
|
38
|
+
@unsafe @builtin
|
|
39
|
+
export declare function wait64(ptr: usize, expected: i64, timeout: i64): AtomicWaitResult;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Initializes a memory segment. */
|
|
43
|
+
// @ts-ignore: decorator
|
|
44
|
+
@unsafe
|
|
45
|
+
export function init(segmentIndex: u32, srcOffset: usize, dstOffset: usize, n: usize): void {
|
|
46
|
+
throw new Error(E_NOTIMPLEMENTED);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Drops a memory segment. */
|
|
50
|
+
// @ts-ignore: decorator
|
|
51
|
+
@unsafe
|
|
52
|
+
export function drop(segmentIndex: u32): void {
|
|
53
|
+
throw new Error(E_NOTIMPLEMENTED);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Repeats a section of memory at a specific address. */
|
|
57
|
+
// @ts-ignore: decorator
|
|
58
|
+
@unsafe
|
|
59
|
+
export function repeat(dst: usize, src: usize, srcLength: usize, count: usize): void {
|
|
60
|
+
let index: usize = 0;
|
|
61
|
+
let total = srcLength * count;
|
|
62
|
+
while (index < total) {
|
|
63
|
+
memory.copy(dst + index, src, srcLength);
|
|
64
|
+
index += srcLength;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Compares a section of memory to another. */
|
|
69
|
+
// @ts-ignore: decorator
|
|
70
|
+
@inline
|
|
71
|
+
export function compare(vl: usize, vr: usize, n: usize): i32 {
|
|
72
|
+
return memcmp(vl, vr, n);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Gets a pointer to a static chunk of memory of the given size. */
|
|
76
|
+
// @ts-ignore: decorator
|
|
77
|
+
@builtin
|
|
78
|
+
export declare function data<T>(size: T, align?: i32): usize;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// @ts-ignore: decorator
|
|
82
|
+
@builtin
|
|
83
|
+
export declare const __data_end: usize;
|
|
84
|
+
|
|
85
|
+
// @ts-ignore: decorator
|
|
86
|
+
@builtin
|
|
87
|
+
export declare let __stack_pointer: usize;
|
|
88
|
+
|
|
89
|
+
// @ts-ignore: decorator
|
|
90
|
+
@builtin
|
|
91
|
+
export declare const __heap_base: usize;
|
|
92
|
+
|
|
93
|
+
/** Heap memory interface. */
|
|
94
|
+
export namespace heap {
|
|
95
|
+
|
|
96
|
+
/** Allocates a chunk of memory of at least the specified size. */
|
|
97
|
+
// @ts-ignore: decorator
|
|
98
|
+
@unsafe export function alloc(size: usize): usize {
|
|
99
|
+
return __alloc(size);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Reallocates a chunk of memory to have at least the specified size. */
|
|
103
|
+
// @ts-ignore: decorator
|
|
104
|
+
@unsafe export function realloc(ptr: usize, size: usize): usize {
|
|
105
|
+
return __realloc(ptr, size);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Frees a chunk of memory. Does hardly anything (most recent block only) with the stub runtime. */
|
|
109
|
+
// @ts-ignore: decorator
|
|
110
|
+
@unsafe export function free(ptr: usize): void {
|
|
111
|
+
__free(ptr);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Dangerously resets the entire heap. Specific to the stub runtime. */
|
|
115
|
+
// @ts-ignore: decorator
|
|
116
|
+
@unsafe export function reset(): void {
|
|
117
|
+
if (isDefined(__reset)) {
|
|
118
|
+
__reset();
|
|
119
|
+
} else {
|
|
120
|
+
throw new Error(E_NOTIMPLEMENTED);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import { itoa32, utoa32, itoa64, utoa64, dtoa } from "./util/number";
|
|
2
|
+
import { strtol, strtod } from "./util/string";
|
|
3
|
+
|
|
4
|
+
// @ts-ignore: decorator
|
|
5
|
+
@builtin @inline
|
|
6
|
+
export const NaN: f64 = 0 / 0; // context-aware
|
|
7
|
+
|
|
8
|
+
// @ts-ignore: decorator
|
|
9
|
+
@builtin @inline
|
|
10
|
+
export const Infinity: f64 = 1 / 0; // context-aware
|
|
11
|
+
|
|
12
|
+
// @ts-ignore: decorator
|
|
13
|
+
@builtin
|
|
14
|
+
export declare function isNaN<T extends number>(value: T): bool;
|
|
15
|
+
|
|
16
|
+
// @ts-ignore: decorator
|
|
17
|
+
@builtin
|
|
18
|
+
export declare function isFinite<T extends number>(value: T): bool;
|
|
19
|
+
|
|
20
|
+
@final @unmanaged
|
|
21
|
+
export abstract class I8 {
|
|
22
|
+
|
|
23
|
+
// @ts-ignore: decorator
|
|
24
|
+
@lazy
|
|
25
|
+
static readonly MIN_VALUE: i8 = i8.MIN_VALUE;
|
|
26
|
+
|
|
27
|
+
// @ts-ignore: decorator
|
|
28
|
+
@lazy
|
|
29
|
+
static readonly MAX_VALUE: i8 = i8.MAX_VALUE;
|
|
30
|
+
|
|
31
|
+
/** @deprecated */
|
|
32
|
+
static parseInt(value: string, radix: i32 = 0): i8 {
|
|
33
|
+
return <i8>strtol<i32>(value, radix);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
toString(this: i8, radix: i32 = 10): String {
|
|
37
|
+
return itoa32(this, radix);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@final @unmanaged
|
|
42
|
+
export abstract class I16 {
|
|
43
|
+
|
|
44
|
+
// @ts-ignore: decorator
|
|
45
|
+
@lazy
|
|
46
|
+
static readonly MIN_VALUE: i16 = i16.MIN_VALUE;
|
|
47
|
+
|
|
48
|
+
// @ts-ignore: decorator
|
|
49
|
+
@lazy
|
|
50
|
+
static readonly MAX_VALUE: i16 = i16.MAX_VALUE;
|
|
51
|
+
|
|
52
|
+
/** @deprecated */
|
|
53
|
+
static parseInt(value: string, radix: i32 = 0): i16 {
|
|
54
|
+
return <i16>strtol<i32>(value, radix);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
toString(this: i16, radix: i32 = 10): String {
|
|
58
|
+
return itoa32(this, radix);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@final @unmanaged
|
|
63
|
+
export abstract class I32 {
|
|
64
|
+
|
|
65
|
+
// @ts-ignore: decorator
|
|
66
|
+
@lazy
|
|
67
|
+
static readonly MIN_VALUE: i32 = i32.MIN_VALUE;
|
|
68
|
+
|
|
69
|
+
// @ts-ignore: decorator
|
|
70
|
+
@lazy
|
|
71
|
+
static readonly MAX_VALUE: i32 = i32.MAX_VALUE;
|
|
72
|
+
|
|
73
|
+
/** @deprecated */
|
|
74
|
+
static parseInt(value: string, radix: i32 = 0): i32 {
|
|
75
|
+
return <i32>strtol<i32>(value, radix);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
toString(this: i32, radix: i32 = 10): String {
|
|
79
|
+
return itoa32(this, radix);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
@final @unmanaged
|
|
84
|
+
export abstract class I64 {
|
|
85
|
+
|
|
86
|
+
// @ts-ignore: decorator
|
|
87
|
+
@lazy
|
|
88
|
+
static readonly MIN_VALUE: i64 = i64.MIN_VALUE;
|
|
89
|
+
|
|
90
|
+
// @ts-ignore: decorator
|
|
91
|
+
@lazy
|
|
92
|
+
static readonly MAX_VALUE: i64 = i64.MAX_VALUE;
|
|
93
|
+
|
|
94
|
+
/** @deprecated */
|
|
95
|
+
static parseInt(value: string, radix: i32 = 0): i64 {
|
|
96
|
+
return strtol<i64>(value, radix);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
toString(this: i64, radix: i32 = 10): String {
|
|
100
|
+
return itoa64(this, radix);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@final @unmanaged
|
|
105
|
+
export abstract class Isize {
|
|
106
|
+
|
|
107
|
+
// @ts-ignore: decorator
|
|
108
|
+
@lazy
|
|
109
|
+
static readonly MIN_VALUE: isize = isize.MIN_VALUE;
|
|
110
|
+
|
|
111
|
+
// @ts-ignore: decorator
|
|
112
|
+
@lazy
|
|
113
|
+
static readonly MAX_VALUE: isize = isize.MAX_VALUE;
|
|
114
|
+
|
|
115
|
+
/** @deprecated */
|
|
116
|
+
static parseInt(value: string, radix: i32 = 0): isize {
|
|
117
|
+
return <isize>strtol<i64>(value, radix);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
toString(this: isize, radix: i32 = 10): String {
|
|
121
|
+
if (sizeof<isize>() == 4) {
|
|
122
|
+
return itoa32(<i32>this, radix);
|
|
123
|
+
} else {
|
|
124
|
+
return itoa64(<i64>this, radix);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
@final @unmanaged
|
|
130
|
+
export abstract class U8 {
|
|
131
|
+
|
|
132
|
+
// @ts-ignore: decorator
|
|
133
|
+
@lazy
|
|
134
|
+
static readonly MIN_VALUE: u8 = u8.MIN_VALUE;
|
|
135
|
+
|
|
136
|
+
// @ts-ignore: decorator
|
|
137
|
+
@lazy
|
|
138
|
+
static readonly MAX_VALUE: u8 = u8.MAX_VALUE;
|
|
139
|
+
|
|
140
|
+
/** @deprecated */
|
|
141
|
+
static parseInt(value: string, radix: i32 = 0): u8 {
|
|
142
|
+
return <u8>strtol<i32>(value, radix);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
toString(this: u8, radix: i32 = 10): String {
|
|
146
|
+
return utoa32(this, radix);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
@final @unmanaged
|
|
151
|
+
export abstract class U16 {
|
|
152
|
+
|
|
153
|
+
// @ts-ignore: decorator
|
|
154
|
+
@lazy
|
|
155
|
+
static readonly MIN_VALUE: u16 = u16.MIN_VALUE;
|
|
156
|
+
|
|
157
|
+
// @ts-ignore: decorator
|
|
158
|
+
@lazy
|
|
159
|
+
static readonly MAX_VALUE: u16 = u16.MAX_VALUE;
|
|
160
|
+
|
|
161
|
+
/** @deprecated */
|
|
162
|
+
static parseInt(value: string, radix: i32 = 0): u16 {
|
|
163
|
+
return <u16>strtol<i32>(value, radix);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
toString(this: u16, radix: i32 = 10): String {
|
|
167
|
+
return utoa32(this, radix);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
@final @unmanaged
|
|
172
|
+
export abstract class U32 {
|
|
173
|
+
|
|
174
|
+
// @ts-ignore: decorator
|
|
175
|
+
@lazy
|
|
176
|
+
static readonly MIN_VALUE: u32 = u32.MIN_VALUE;
|
|
177
|
+
|
|
178
|
+
// @ts-ignore: decorator
|
|
179
|
+
@lazy
|
|
180
|
+
static readonly MAX_VALUE: u32 = u32.MAX_VALUE;
|
|
181
|
+
|
|
182
|
+
/** @deprecated */
|
|
183
|
+
static parseInt(value: string, radix: i32 = 0): u32 {
|
|
184
|
+
return <u32>strtol<i32>(value, radix);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
toString(this: u32, radix: i32 = 10): String {
|
|
188
|
+
return utoa32(this, radix);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
@final @unmanaged
|
|
193
|
+
export abstract class U64 {
|
|
194
|
+
|
|
195
|
+
// @ts-ignore: decorator
|
|
196
|
+
@lazy
|
|
197
|
+
static readonly MIN_VALUE: u64 = u64.MIN_VALUE;
|
|
198
|
+
|
|
199
|
+
// @ts-ignore: decorator
|
|
200
|
+
@lazy
|
|
201
|
+
static readonly MAX_VALUE: u64 = u64.MAX_VALUE;
|
|
202
|
+
|
|
203
|
+
/** @deprecated */
|
|
204
|
+
static parseInt(value: string, radix: i32 = 0): u64 {
|
|
205
|
+
return <u64>strtol<i64>(value, radix);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
toString(this: u64, radix: i32 = 10): String {
|
|
209
|
+
return utoa64(this, radix);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
@final @unmanaged
|
|
214
|
+
export abstract class Usize {
|
|
215
|
+
|
|
216
|
+
// @ts-ignore: decorator
|
|
217
|
+
@lazy
|
|
218
|
+
static readonly MIN_VALUE: usize = usize.MIN_VALUE;
|
|
219
|
+
|
|
220
|
+
// @ts-ignore: decorator
|
|
221
|
+
@lazy
|
|
222
|
+
static readonly MAX_VALUE: usize = usize.MAX_VALUE;
|
|
223
|
+
|
|
224
|
+
/** @deprecated */
|
|
225
|
+
static parseInt(value: string, radix: i32 = 0): usize {
|
|
226
|
+
return <usize>strtol<i64>(value, radix);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
toString(this: usize, radix: i32 = 10): String {
|
|
230
|
+
if (sizeof<usize>() == 4) {
|
|
231
|
+
return utoa32(<u32>this, radix);
|
|
232
|
+
} else {
|
|
233
|
+
return utoa64(<u64>this, radix);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
@final @unmanaged
|
|
239
|
+
export abstract class Bool {
|
|
240
|
+
|
|
241
|
+
// @ts-ignore: decorator
|
|
242
|
+
@lazy
|
|
243
|
+
static readonly MIN_VALUE: bool = bool.MIN_VALUE;
|
|
244
|
+
|
|
245
|
+
// @ts-ignore: decorator
|
|
246
|
+
@lazy
|
|
247
|
+
static readonly MAX_VALUE: bool = bool.MAX_VALUE;
|
|
248
|
+
|
|
249
|
+
toString(this: bool, radix: i32 = 0): String {
|
|
250
|
+
return this ? "true" : "false";
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export { Bool as Boolean };
|
|
255
|
+
|
|
256
|
+
@final @unmanaged
|
|
257
|
+
export abstract class F32 {
|
|
258
|
+
|
|
259
|
+
// @ts-ignore: decorator
|
|
260
|
+
@lazy
|
|
261
|
+
static readonly EPSILON: f32 = f32.EPSILON;
|
|
262
|
+
|
|
263
|
+
// @ts-ignore: decorator
|
|
264
|
+
@lazy
|
|
265
|
+
static readonly MIN_VALUE: f32 = f32.MIN_VALUE;
|
|
266
|
+
|
|
267
|
+
// @ts-ignore: decorator
|
|
268
|
+
@lazy
|
|
269
|
+
static readonly MAX_VALUE: f32 = f32.MAX_VALUE;
|
|
270
|
+
|
|
271
|
+
// @ts-ignore: decorator
|
|
272
|
+
@lazy
|
|
273
|
+
static readonly MIN_SAFE_INTEGER: f32 = f32.MIN_SAFE_INTEGER;
|
|
274
|
+
|
|
275
|
+
// @ts-ignore: decorator
|
|
276
|
+
@lazy
|
|
277
|
+
static readonly MAX_SAFE_INTEGER: f32 = f32.MAX_SAFE_INTEGER;
|
|
278
|
+
|
|
279
|
+
// @ts-ignore: decorator
|
|
280
|
+
@lazy
|
|
281
|
+
static readonly POSITIVE_INFINITY: f32 = f32.POSITIVE_INFINITY;
|
|
282
|
+
|
|
283
|
+
// @ts-ignore: decorator
|
|
284
|
+
@lazy
|
|
285
|
+
static readonly NEGATIVE_INFINITY: f32 = f32.NEGATIVE_INFINITY;
|
|
286
|
+
|
|
287
|
+
// @ts-ignore: decorator
|
|
288
|
+
@lazy
|
|
289
|
+
static readonly NaN: f32 = f32.NaN;
|
|
290
|
+
|
|
291
|
+
static isNaN(value: f32): bool {
|
|
292
|
+
return isNaN<f32>(value);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
static isFinite(value: f32): bool {
|
|
296
|
+
return isFinite<f32>(value);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
static isSafeInteger(value: f32): bool {
|
|
300
|
+
return abs<f32>(value) <= f32.MAX_SAFE_INTEGER && trunc<f32>(value) == value;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
static isInteger(value: f32): bool {
|
|
304
|
+
return isFinite<f32>(value) && trunc<f32>(value) == value;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/** @deprecated */
|
|
308
|
+
static parseInt(value: string, radix: i32 = 0): f32 {
|
|
309
|
+
return <f32>strtol<f64>(value, radix);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** @deprecated */
|
|
313
|
+
static parseFloat(value: string): f32 {
|
|
314
|
+
return <f32>strtod(value);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
toString(this: f32, radix: i32 = 0): String {
|
|
318
|
+
return dtoa(this);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
@final @unmanaged
|
|
323
|
+
export abstract class F64 {
|
|
324
|
+
|
|
325
|
+
// @ts-ignore: decorator
|
|
326
|
+
@lazy
|
|
327
|
+
static readonly EPSILON: f64 = f64.EPSILON;
|
|
328
|
+
|
|
329
|
+
// @ts-ignore: decorator
|
|
330
|
+
@lazy
|
|
331
|
+
static readonly MIN_VALUE: f64 = f64.MIN_VALUE;
|
|
332
|
+
|
|
333
|
+
// @ts-ignore: decorator
|
|
334
|
+
@lazy
|
|
335
|
+
static readonly MAX_VALUE: f64 = f64.MAX_VALUE;
|
|
336
|
+
|
|
337
|
+
// @ts-ignore: decorator
|
|
338
|
+
@lazy
|
|
339
|
+
static readonly MIN_SAFE_INTEGER: f64 = f64.MIN_SAFE_INTEGER;
|
|
340
|
+
|
|
341
|
+
// @ts-ignore: decorator
|
|
342
|
+
@lazy
|
|
343
|
+
static readonly MAX_SAFE_INTEGER: f64 = f64.MAX_SAFE_INTEGER;
|
|
344
|
+
|
|
345
|
+
// @ts-ignore: decorator
|
|
346
|
+
@lazy
|
|
347
|
+
static readonly POSITIVE_INFINITY: f64 = f64.POSITIVE_INFINITY;
|
|
348
|
+
|
|
349
|
+
// @ts-ignore: decorator
|
|
350
|
+
@lazy
|
|
351
|
+
static readonly NEGATIVE_INFINITY: f64 = f64.NEGATIVE_INFINITY;
|
|
352
|
+
|
|
353
|
+
// @ts-ignore: decorator
|
|
354
|
+
@lazy
|
|
355
|
+
static readonly NaN: f64 = f64.NaN;
|
|
356
|
+
|
|
357
|
+
static isNaN(value: f64): bool {
|
|
358
|
+
return isNaN<f64>(value);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
static isFinite(value: f64): bool {
|
|
362
|
+
return isFinite<f64>(value);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
static isSafeInteger(value: f64): bool {
|
|
366
|
+
return abs<f64>(value) <= f64.MAX_SAFE_INTEGER && trunc<f64>(value) == value;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
static isInteger(value: f64): bool {
|
|
370
|
+
return isFinite<f64>(value) && trunc<f64>(value) == value;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/** @deprecated */
|
|
374
|
+
static parseInt(value: string, radix: i32 = 0): f64 {
|
|
375
|
+
return strtol<f64>(value, radix);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/** @deprecated */
|
|
379
|
+
static parseFloat(value: string): f64 {
|
|
380
|
+
return strtod(value);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
toString(this: f64, radix: i32 = 0): String {
|
|
384
|
+
return dtoa(this);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
export { F64 as Number };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export abstract class Object {
|
|
2
|
+
static is<T>(x: T, y: T): bool {
|
|
3
|
+
if (isFloat<T>()) {
|
|
4
|
+
// Float pointing is special we shoulr presere following identities:
|
|
5
|
+
// 0.0 !=-0.0
|
|
6
|
+
// NaN == NaN
|
|
7
|
+
if (sizeof<T>() == 8) {
|
|
8
|
+
return (
|
|
9
|
+
bool(u32(x != x) & u32(y != y) |
|
|
10
|
+
u32(reinterpret<u64>(f64(x)) == reinterpret<u64>(f64(y))))
|
|
11
|
+
);
|
|
12
|
+
} else {
|
|
13
|
+
return (
|
|
14
|
+
bool(u32(x != x) & u32(y != y) |
|
|
15
|
+
u32(reinterpret<u32>(f32(x)) == reinterpret<u32>(f32(y))))
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
// For references, strings, integers and booleans
|
|
20
|
+
return x == y;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// TODO: Wrapper classes like `Function<T>` override the `this` type of
|
|
24
|
+
// `toString`, which is covariant and hence fails to overload. Wrapper classes
|
|
25
|
+
// might need a different mechanism to indicate such special `this` types.
|
|
26
|
+
// toString(): string {
|
|
27
|
+
// return "[object Object]";
|
|
28
|
+
// }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// TODO: The types `Object` and `object` differ in TypeScript, in that the
|
|
32
|
+
// latter indicates any non-primitive type, not including `string` for example.
|
|
33
|
+
// The `object` type hence remains reserved for now, also to potentially address
|
|
34
|
+
// the above `toString` TODO in alternative ways.
|
|
35
|
+
// @ts-ignore: nolib
|
|
36
|
+
// export type object = Object;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// Zero-overhead typed pointer. @unmanaged + changetype = no allocation, no GC.
|
|
2
|
+
// Promoted from tests/compiler/std/pointer.ts experiment.
|
|
3
|
+
|
|
4
|
+
@final @unmanaged
|
|
5
|
+
export class Pointer<T> {
|
|
6
|
+
|
|
7
|
+
@inline constructor(offset: usize = 0) {
|
|
8
|
+
return changetype<Pointer<T>>(offset);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
@inline get offset(): usize {
|
|
12
|
+
return changetype<usize>(this);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@inline get value(): T {
|
|
16
|
+
if (isReference<T>()) {
|
|
17
|
+
return changetype<T>(changetype<usize>(this));
|
|
18
|
+
} else {
|
|
19
|
+
return load<T>(changetype<usize>(this));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@inline set value(value: T) {
|
|
24
|
+
if (isReference<T>()) {
|
|
25
|
+
if (isManaged<T>()) ERROR("Unsafe unmanaged set of a managed object");
|
|
26
|
+
if (value == null) {
|
|
27
|
+
memory.fill(changetype<usize>(this), 0, offsetof<T>());
|
|
28
|
+
} else {
|
|
29
|
+
memory.copy(changetype<usize>(this), changetype<usize>(value), offsetof<T>());
|
|
30
|
+
}
|
|
31
|
+
} else {
|
|
32
|
+
store<T>(changetype<usize>(this), value);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@inline @operator("+") add(other: Pointer<T>): Pointer<T> {
|
|
37
|
+
return changetype<Pointer<T>>(changetype<usize>(this) + changetype<usize>(other));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@inline @operator("-") sub(other: Pointer<T>): Pointer<T> {
|
|
41
|
+
return changetype<Pointer<T>>(changetype<usize>(this) - changetype<usize>(other));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@inline @operator.prefix("++") inc(): Pointer<T> {
|
|
45
|
+
const size = isReference<T>() ? offsetof<T>() : sizeof<T>();
|
|
46
|
+
return changetype<Pointer<T>>(changetype<usize>(this) + size);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@inline @operator.prefix("--") dec(): Pointer<T> {
|
|
50
|
+
const size = isReference<T>() ? offsetof<T>() : sizeof<T>();
|
|
51
|
+
return changetype<Pointer<T>>(changetype<usize>(this) - size);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@inline @operator("[]") get(index: i32): T {
|
|
55
|
+
const size = isReference<T>() ? offsetof<T>() : sizeof<T>();
|
|
56
|
+
return load<T>(changetype<usize>(this) + (<usize>index * size));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@inline @operator("[]=") set(index: i32, value: T): void {
|
|
60
|
+
const size = isReference<T>() ? offsetof<T>() : sizeof<T>();
|
|
61
|
+
store<T>(changetype<usize>(this) + (<usize>index * size), value);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@inline isNull(): bool {
|
|
65
|
+
return changetype<usize>(this) == 0;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@inline equals(other: Pointer<T>): bool {
|
|
69
|
+
return changetype<usize>(this) == changetype<usize>(other);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@inline copyTo(dst: Pointer<T>, count: i32): void {
|
|
73
|
+
const size = isReference<T>() ? offsetof<T>() : sizeof<T>();
|
|
74
|
+
memory.copy(changetype<usize>(dst), changetype<usize>(this), <usize>count * size);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
@inline static null<T>(): Pointer<T> {
|
|
78
|
+
return changetype<Pointer<T>>(0);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export function bswap<T extends number>(value: T): T {
|
|
2
|
+
if (isInteger<T>()) {
|
|
3
|
+
if (sizeof<T>() == 1) {
|
|
4
|
+
return value;
|
|
5
|
+
}
|
|
6
|
+
if (sizeof<T>() == 2) {
|
|
7
|
+
return <T>(<u16>value << 8 | (<u16>value >> 8));
|
|
8
|
+
}
|
|
9
|
+
if (sizeof<T>() == 4) {
|
|
10
|
+
return <T>(
|
|
11
|
+
rotl(<u32>value & 0xFF00FF00, 8) |
|
|
12
|
+
rotr(<u32>value & 0x00FF00FF, 8)
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
if (sizeof<T>() == 8) {
|
|
16
|
+
let a = (<u64>value >> 8) & 0x00FF00FF00FF00FF;
|
|
17
|
+
let b = (<u64>value & 0x00FF00FF00FF00FF) << 8;
|
|
18
|
+
let v = a | b;
|
|
19
|
+
|
|
20
|
+
a = (v >>> 16) & 0x0000FFFF0000FFFF;
|
|
21
|
+
b = (v & 0x0000FFFF0000FFFF) << 16;
|
|
22
|
+
|
|
23
|
+
return <T>rotr(a | b, 32);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
ERROR("Unsupported generic type");
|
|
27
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Date as Date_binding,
|
|
3
|
+
performance as performance_binding
|
|
4
|
+
} from "bindings/dom";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
process as process_binding
|
|
8
|
+
} from "bindings/node";
|
|
9
|
+
|
|
10
|
+
export namespace process {
|
|
11
|
+
|
|
12
|
+
// @ts-ignore: decorator
|
|
13
|
+
@lazy export const arch = sizeof<usize>() == 4 ? "wasm32" : "wasm64";
|
|
14
|
+
|
|
15
|
+
// @ts-ignore: decorator
|
|
16
|
+
@lazy export const platform = "wasm";
|
|
17
|
+
|
|
18
|
+
// @ts-ignore: decorator
|
|
19
|
+
@lazy export const argv = lazyArgv();
|
|
20
|
+
|
|
21
|
+
// @ts-ignore: decorator
|
|
22
|
+
@lazy export const env = lazyEnv();
|
|
23
|
+
|
|
24
|
+
// @ts-ignore: decorator
|
|
25
|
+
@lazy export let exitCode = 0;
|
|
26
|
+
|
|
27
|
+
export function exit(code: i32 = exitCode): void {
|
|
28
|
+
process_binding.exit(code);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function time(): i64 {
|
|
32
|
+
return <i64>Date_binding.now();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function hrtime(): u64 {
|
|
36
|
+
let now = performance_binding.now();
|
|
37
|
+
let millis = <u64>now;
|
|
38
|
+
let fraction = now - <f64>millis;
|
|
39
|
+
return millis * 1000000 + <u64>(fraction * 1000000);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function lazyArgv(): string[] {
|
|
44
|
+
return process_binding.argv;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function lazyEnv(): Map<string,string> {
|
|
48
|
+
// TODO: What about Node?
|
|
49
|
+
return new Map();
|
|
50
|
+
}
|