toilscript 0.0.1 → 0.1.0

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 (120) 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 +0 -0
  6. package/dist/asc.generated.d.ts +10022 -0
  7. package/dist/asc.js +24457 -0
  8. package/dist/asc.js.map +7 -0
  9. package/dist/importmap.json +9 -0
  10. package/dist/toilscript.generated.d.ts +11237 -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 +2891 -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/tsconfig.json +6 -6
  78. package/std/assembly/typedarray.ts +1954 -1954
  79. package/std/assembly/uri.ts +17 -17
  80. package/std/assembly/util/bytes.ts +107 -107
  81. package/std/assembly/util/casemap.ts +497 -497
  82. package/std/assembly/util/error.ts +58 -58
  83. package/std/assembly/util/hash.ts +117 -117
  84. package/std/assembly/util/math.ts +1922 -1922
  85. package/std/assembly/util/memory.ts +290 -290
  86. package/std/assembly/util/number.ts +873 -873
  87. package/std/assembly/util/sort.ts +313 -313
  88. package/std/assembly/util/string.ts +1202 -1202
  89. package/std/assembly/util/uri.ts +275 -275
  90. package/std/assembly/vector.ts +4 -4
  91. package/std/assembly.json +16 -16
  92. package/std/portable/index.d.ts +461 -461
  93. package/std/portable/index.js +416 -416
  94. package/std/portable.json +11 -11
  95. package/std/types/assembly/index.d.ts +1 -1
  96. package/std/types/assembly/package.json +2 -2
  97. package/std/types/portable/index.d.ts +1 -1
  98. package/std/types/portable/package.json +2 -2
  99. package/tsconfig-base.json +13 -13
  100. package/util/README.md +23 -23
  101. package/util/browser/fs.js +1 -1
  102. package/util/browser/module.js +5 -5
  103. package/util/browser/path.js +520 -520
  104. package/util/browser/process.js +59 -59
  105. package/util/browser/url.js +23 -23
  106. package/util/cpu.d.ts +9 -9
  107. package/util/cpu.js +42 -42
  108. package/util/find.d.ts +6 -6
  109. package/util/find.js +20 -20
  110. package/util/node.d.ts +21 -21
  111. package/util/node.js +34 -34
  112. package/util/options.d.ts +70 -70
  113. package/util/options.js +262 -262
  114. package/util/terminal.d.ts +52 -52
  115. package/util/terminal.js +35 -35
  116. package/util/text.d.ts +26 -26
  117. package/util/text.js +114 -114
  118. package/util/tsconfig.json +9 -9
  119. package/util/web.d.ts +11 -11
  120. package/util/web.js +33 -33
@@ -1,416 +1,416 @@
1
- /** @module std/portable *//***/
2
-
3
- let globalScope = typeof window !== "undefined" && window || typeof global !== "undefined" && global || self;
4
- if (typeof globalScope.ASC_TARGET === "undefined") {
5
-
6
- globalScope.ASC_TARGET = 0; // Target.JS
7
- globalScope.ASC_RUNTIME = 0; // Runtime.Stub
8
- globalScope.ASC_NO_ASSERT = false;
9
- globalScope.ASC_MEMORY_BASE = 0;
10
- globalScope.ASC_OPTIMIZE_LEVEL = 3;
11
- globalScope.ASC_SHRINK_LEVEL = 0;
12
- globalScope.ASC_FEATURE_MUTABLE_GLOBAL = false;
13
- globalScope.ASC_FEATURE_SIGN_EXTENSION = false;
14
- globalScope.ASC_FEATURE_BULK_MEMORY = false;
15
- globalScope.ASC_FEATURE_SIMD = false;
16
- globalScope.ASC_FEATURE_THREADS = false;
17
-
18
- let F64 = new Float64Array(1);
19
- let U64 = new Uint32Array(F64.buffer);
20
-
21
- Object.defineProperties(
22
- globalScope["i8"] = function i8(value) { return value << 24 >> 24; },
23
- {
24
- "MIN_VALUE": { value: -128 },
25
- "MAX_VALUE": { value: 127 },
26
-
27
- parse(str, radix) { return parseInt(str, radix) << 24 >> 24; }
28
- }
29
- );
30
-
31
- Object.defineProperties(
32
- globalScope["i16"] = function i16(value) { return value << 16 >> 16; },
33
- {
34
- "MIN_VALUE": { value: -32768 },
35
- "MAX_VALUE": { value: 32767 },
36
-
37
- parse(str, radix) { return parseInt(str, radix) << 16 >> 16; }
38
- }
39
- );
40
-
41
- Object.defineProperties(
42
- globalScope["i32"] = globalScope["isize"] = function i32(value) { return value | 0; },
43
- {
44
- "MIN_VALUE": { value: -2147483648 },
45
- "MAX_VALUE": { value: 2147483647 },
46
-
47
- parse(str, radix) { return parseInt(str, radix) | 0; }
48
- }
49
- );
50
-
51
- Object.defineProperties(
52
- globalScope["u8"] = function u8(value) { return value & 0xff; },
53
- {
54
- "MIN_VALUE": { value: 0 },
55
- "MAX_VALUE": { value: 255 },
56
-
57
- parse(str, radix) { return parseInt(str, radix) & 0xff; }
58
- }
59
- );
60
-
61
- Object.defineProperties(
62
- globalScope["u16"] = function u16(value) { return value & 0xffff; },
63
- {
64
- "MIN_VALUE": { value: 0 },
65
- "MAX_VALUE": { value: 65535 },
66
-
67
- parse(str, radix) { return parseInt(str, radix) & 0xffff; }
68
- }
69
- );
70
-
71
- Object.defineProperties(
72
- globalScope["u32"] = globalScope["usize"] = function u32(value) { return value >>> 0; },
73
- {
74
- "MIN_VALUE": { value: 0 },
75
- "MAX_VALUE": { value: 4294967295 },
76
-
77
- parse(str, radix) { return parseInt(str, radix) >>> 0; }
78
- }
79
- );
80
-
81
- Object.defineProperties(
82
- globalScope["bool"] = function bool(value) { return !!value; },
83
- {
84
- "MIN_VALUE": { value: false },
85
- "MAX_VALUE": { value: true },
86
-
87
- parse(str) { return str.trim() === "true"; }
88
- }
89
- );
90
-
91
- Object.defineProperties(
92
- globalScope["f32"] = function f32(value) { return Math.fround(value); },
93
- {
94
- "EPSILON": { value: 1.1920928955078125e-07 },
95
- "MIN_VALUE": { value: 1.401298464324817e-45 },
96
- "MAX_VALUE": { value: 3.4028234663852886e+38 },
97
- "MIN_NORMAL_VALUE": { value: 1.1754943508222875e-38 },
98
- "MIN_SAFE_INTEGER": { value: -16777215 },
99
- "MAX_SAFE_INTEGER": { value: 16777215 },
100
- "POSITIVE_INFINITY": { value: Infinity },
101
- "NEGATIVE_INFINITY": { value: -Infinity },
102
- "NaN": { value: NaN },
103
-
104
- parse(str) { return Math.fround(parseFloat(str)); }
105
- }
106
- );
107
-
108
- Object.defineProperties(
109
- globalScope["f64"] = function f64(value) { return +value; },
110
- {
111
- "EPSILON": { value: 2.2204460492503131e-016 },
112
- "MIN_VALUE": { value: 5e-324 },
113
- "MAX_VALUE": { value: 1.7976931348623157e+308 },
114
- "MIN_NORMAL_VALUE": { value: 2.2250738585072014e-308 },
115
- "MIN_SAFE_INTEGER": { value: -9007199254740991 },
116
- "MAX_SAFE_INTEGER": { value: 9007199254740991 },
117
- "POSITIVE_INFINITY": { value: Infinity },
118
- "NEGATIVE_INFINITY": { value: -Infinity },
119
- "NaN": { value: NaN },
120
-
121
- parse(str) { return parseFloat(str); }
122
- }
123
- );
124
-
125
- globalScope["clz"] = Math.clz32;
126
-
127
- globalScope["ctz"] = function ctz(value) {
128
- return 32 - Math.clz32(~value & (value - 1));
129
- };
130
-
131
- globalScope["popcnt"] = function popcnt(value) {
132
- value -= value >>> 1 & 0x55555555;
133
- value = (value & 0x33333333) + (value >>> 2 & 0x33333333);
134
- return (((value + (value >>> 4)) & 0x0F0F0F0F) * 0x01010101) >>> 24;
135
- };
136
-
137
- globalScope["rotl"] = function rotl(value, shift) {
138
- shift &= 31;
139
- return (value << shift) | (value >>> (32 - shift));
140
- };
141
-
142
- globalScope["rotr"] = function rotr(value, shift) {
143
- shift &= 31;
144
- return (value >>> shift) | (value << (32 - shift));
145
- };
146
-
147
- globalScope["abs"] = Math.abs;
148
-
149
- globalScope["max"] = Math.max;
150
-
151
- globalScope["min"] = Math.min;
152
-
153
- globalScope["ceil"] = Math.ceil;
154
-
155
- globalScope["floor"] = Math.floor;
156
-
157
- globalScope["nearest"] = function nearest(value) {
158
- const INV_EPS64 = 4503599627370496.0;
159
- const y = Math.abs(value);
160
- return y < INV_EPS64
161
- ? (y + INV_EPS64 - INV_EPS64) * Math.sign(value)
162
- : value;
163
- };
164
-
165
- globalScope["select"] = function select(ifTrue, ifFalse, condition) {
166
- return condition ? ifTrue : ifFalse;
167
- };
168
-
169
- globalScope["sqrt"] = Math.sqrt;
170
-
171
- globalScope["trunc"] = Math.trunc;
172
-
173
- globalScope["copysign"] = function copysign(x, y) {
174
- return y
175
- ? Math.abs(x) * Math.sign(y)
176
- : (F64[0] = y, U64[1] >>> 31 ? -1 : 1); // +0, -0, -NaN, +NaN
177
- };
178
-
179
- globalScope["bswap"] = function bswap(value) {
180
- let a = value >> 8 & 0x00FF00FF;
181
- let b = (value & 0x00FF00FF) << 8;
182
- value = a | b;
183
- a = value >> 16 & 0x0000FFFF;
184
- b = (value & 0x0000FFFF) << 16;
185
- return a | b;
186
- };
187
-
188
- function UnreachableError() {
189
- if (Error.captureStackTrace) {
190
- Error.captureStackTrace(this, UnreachableError);
191
- } else {
192
- this.stack = this.name + ": " + this.message + "\n" + new Error().stack;
193
- }
194
- }
195
- UnreachableError.prototype = Object.create(Error.prototype);
196
- UnreachableError.prototype.name = "UnreachableError";
197
- UnreachableError.prototype.message = "unreachable";
198
-
199
- globalScope["unreachable"] = function unreachable() {
200
- throw new UnreachableError();
201
- };
202
-
203
- function AssertionError(message) {
204
- this.message = message || "assertion failed";
205
- if (Error.captureStackTrace) {
206
- Error.captureStackTrace(this, AssertionError);
207
- } else {
208
- this.stack = this.name + ": " + this.message + "\n" + new Error().stack;
209
- }
210
- }
211
- AssertionError.prototype = Object.create(Error.prototype);
212
- AssertionError.prototype.name = "AssertionError";
213
-
214
- globalScope["assert"] = function assert(isTrueish, message) {
215
- if (isTrueish) return isTrueish;
216
- throw new AssertionError(message);
217
- };
218
-
219
- globalScope["changetype"] = function changetype(value) {
220
- return value;
221
- };
222
-
223
- String["fromCharCodes"] = function fromCharCodes(arr) {
224
- const CHUNKSIZE = 1 << 13;
225
- const len = arr.length;
226
- if (len <= CHUNKSIZE) {
227
- return String.fromCharCode.apply(String, arr);
228
- }
229
- let index = 0;
230
- let parts = '';
231
- while (index < len) {
232
- parts += String.fromCharCode.apply(
233
- String,
234
- arr.slice(index, Math.min(index + CHUNKSIZE, len))
235
- );
236
- index += CHUNKSIZE;
237
- }
238
- return parts;
239
- };
240
-
241
- String["fromCodePoints"] = function fromCodePoints(arr) {
242
- const CHUNKSIZE = 1 << 13;
243
- const len = arr.length;
244
- if (len <= CHUNKSIZE) {
245
- return String.fromCodePoint.apply(String, arr);
246
- }
247
- let index = 0;
248
- let parts = '';
249
- while (index < len) {
250
- parts += String.fromCodePoint.apply(
251
- String,
252
- arr.slice(index, Math.min(index + CHUNKSIZE, len))
253
- );
254
- index += CHUNKSIZE;
255
- }
256
- return parts;
257
- };
258
-
259
- if (!String.prototype.at) {
260
- Object.defineProperty(String.prototype, "at", {
261
- value: function at(index) {
262
- return this.charAt(index >= 0 ? index : index + this.length);
263
- },
264
- configurable: true
265
- });
266
- }
267
-
268
- if (!String.prototype.replaceAll) {
269
- Object.defineProperty(String.prototype, "replaceAll", {
270
- value: function replaceAll(search, replacement) {
271
- let res = this.split(search).join(replacement);
272
- if (!search.length) res = replacement + res + replacement;
273
- return res;
274
- },
275
- configurable: true
276
- });
277
- }
278
-
279
- function defaultComparator(a, b) {
280
- if (a == b) {
281
- if (a != 0) return 0;
282
- a = 1 / a;
283
- b = 1 / b;
284
- } else {
285
- let nanA = a != a, nanB = b != b;
286
- if (nanA | nanB) return nanA - nanB;
287
- if (a == null) a = String(a);
288
- if (b == null) b = String(b);
289
- }
290
- return a > b ? 1 : -1;
291
- }
292
-
293
- const arraySort = Array.prototype.sort;
294
- Array.prototype.sort = function sort(comparator) {
295
- return arraySort.call(this, comparator || defaultComparator);
296
- };
297
-
298
- [ Array,
299
- Uint8ClampedArray,
300
- Uint8Array, Int8Array,
301
- Uint16Array, Int16Array,
302
- Uint32Array, Int32Array,
303
- Float32Array, Float64Array
304
- ].forEach(Ctr => {
305
- if (!Ctr.prototype.at) {
306
- Object.defineProperty(Ctr.prototype, "at", {
307
- value: function at(index) {
308
- return this[index >= 0 ? index : index + this.length];
309
- },
310
- configurable: true
311
- });
312
- }
313
-
314
- if (!Ctr.prototype.findLastIndex) {
315
- Object.defineProperty(Ctr.prototype, "findLastIndex", {
316
- value: function findLastIndex(fn) {
317
- for (let i = this.length - 1; i >= 0; --i) {
318
- if (fn(this[i], i, this)) return i;
319
- }
320
- return -1;
321
- },
322
- configurable: true
323
- });
324
- }
325
-
326
- if (Ctr != Array) {
327
- Object.defineProperty(Ctr, "wrap", {
328
- value: function wrap(buffer, byteOffset, length) {
329
- return new Ctr(buffer, byteOffset, length);
330
- },
331
- configurable: true
332
- });
333
- }
334
- });
335
-
336
- globalScope["isInteger"] = Number.isInteger;
337
-
338
- globalScope["isFloat"] = function isFloat(arg) {
339
- return typeof arg === "number";
340
- };
341
-
342
- globalScope["isNullable"] = function isNullable(arg) {
343
- return true;
344
- };
345
-
346
- globalScope["isReference"] = function isReference(arg) {
347
- return typeof arg === "object" || typeof arg === "string";
348
- };
349
-
350
- globalScope["isFunction"] = function isFunction(arg) {
351
- return typeof arg === "function";
352
- };
353
-
354
- globalScope["isString"] = function isString(arg) {
355
- return typeof arg === "string" || arg instanceof String;
356
- };
357
-
358
- globalScope["isArray"] = Array.isArray;
359
- globalScope["isArrayLike"] = function isArrayLike(expr) {
360
- return expr
361
- && typeof expr === 'object'
362
- && typeof expr.length === 'number'
363
- && expr.length >= 0
364
- && Math.trunc(expr.length) === expr.length;
365
- };
366
-
367
- globalScope["isDefined"] = function isDefined(expr) {
368
- return typeof expr !== "undefined";
369
- };
370
-
371
- globalScope["isConstant"] = function isConstant(expr) {
372
- return false;
373
- };
374
-
375
- globalScope["unchecked"] = function unchecked(expr) {
376
- return expr;
377
- };
378
-
379
- globalScope["fmod"] = function fmod(x, y) {
380
- return x % y;
381
- };
382
-
383
- globalScope["fmodf"] = function fmodf(x, y) {
384
- return Math.fround(x % y);
385
- };
386
-
387
- globalScope["JSMath"] = Math;
388
-
389
- Object.defineProperties(globalScope["JSMath"], {
390
- sincos_sin: { value: 0.0, writable: true },
391
- sincos_cos: { value: 0.0, writable: true },
392
- signbit: {
393
- value: function signbit(x) {
394
- F64[0] = x; return Boolean(U64[1] >>> 31);
395
- }
396
- },
397
- sincos: {
398
- value: function sincos(x) {
399
- this.sincos_sin = Math.sin(x);
400
- this.sincos_cos = Math.cos(x);
401
- }
402
- },
403
- exp2: {
404
- value: function exp2(x) {
405
- return Math.pow(2, x);
406
- }
407
- }
408
- });
409
-
410
- globalScope["unmanaged"] = function() { /* nop */ };
411
-
412
- globalScope["trace"] = function(message, n) {
413
- if (n) message += Array.prototype.slice.call(arguments, 2, 2 + n);
414
- console.error("trace: " + message);
415
- };
416
- }
1
+ /** @module std/portable *//***/
2
+
3
+ let globalScope = typeof window !== "undefined" && window || typeof global !== "undefined" && global || self;
4
+ if (typeof globalScope.ASC_TARGET === "undefined") {
5
+
6
+ globalScope.ASC_TARGET = 0; // Target.JS
7
+ globalScope.ASC_RUNTIME = 0; // Runtime.Stub
8
+ globalScope.ASC_NO_ASSERT = false;
9
+ globalScope.ASC_MEMORY_BASE = 0;
10
+ globalScope.ASC_OPTIMIZE_LEVEL = 3;
11
+ globalScope.ASC_SHRINK_LEVEL = 0;
12
+ globalScope.ASC_FEATURE_MUTABLE_GLOBAL = false;
13
+ globalScope.ASC_FEATURE_SIGN_EXTENSION = false;
14
+ globalScope.ASC_FEATURE_BULK_MEMORY = false;
15
+ globalScope.ASC_FEATURE_SIMD = false;
16
+ globalScope.ASC_FEATURE_THREADS = false;
17
+
18
+ let F64 = new Float64Array(1);
19
+ let U64 = new Uint32Array(F64.buffer);
20
+
21
+ Object.defineProperties(
22
+ globalScope["i8"] = function i8(value) { return value << 24 >> 24; },
23
+ {
24
+ "MIN_VALUE": { value: -128 },
25
+ "MAX_VALUE": { value: 127 },
26
+
27
+ parse(str, radix) { return parseInt(str, radix) << 24 >> 24; }
28
+ }
29
+ );
30
+
31
+ Object.defineProperties(
32
+ globalScope["i16"] = function i16(value) { return value << 16 >> 16; },
33
+ {
34
+ "MIN_VALUE": { value: -32768 },
35
+ "MAX_VALUE": { value: 32767 },
36
+
37
+ parse(str, radix) { return parseInt(str, radix) << 16 >> 16; }
38
+ }
39
+ );
40
+
41
+ Object.defineProperties(
42
+ globalScope["i32"] = globalScope["isize"] = function i32(value) { return value | 0; },
43
+ {
44
+ "MIN_VALUE": { value: -2147483648 },
45
+ "MAX_VALUE": { value: 2147483647 },
46
+
47
+ parse(str, radix) { return parseInt(str, radix) | 0; }
48
+ }
49
+ );
50
+
51
+ Object.defineProperties(
52
+ globalScope["u8"] = function u8(value) { return value & 0xff; },
53
+ {
54
+ "MIN_VALUE": { value: 0 },
55
+ "MAX_VALUE": { value: 255 },
56
+
57
+ parse(str, radix) { return parseInt(str, radix) & 0xff; }
58
+ }
59
+ );
60
+
61
+ Object.defineProperties(
62
+ globalScope["u16"] = function u16(value) { return value & 0xffff; },
63
+ {
64
+ "MIN_VALUE": { value: 0 },
65
+ "MAX_VALUE": { value: 65535 },
66
+
67
+ parse(str, radix) { return parseInt(str, radix) & 0xffff; }
68
+ }
69
+ );
70
+
71
+ Object.defineProperties(
72
+ globalScope["u32"] = globalScope["usize"] = function u32(value) { return value >>> 0; },
73
+ {
74
+ "MIN_VALUE": { value: 0 },
75
+ "MAX_VALUE": { value: 4294967295 },
76
+
77
+ parse(str, radix) { return parseInt(str, radix) >>> 0; }
78
+ }
79
+ );
80
+
81
+ Object.defineProperties(
82
+ globalScope["bool"] = function bool(value) { return !!value; },
83
+ {
84
+ "MIN_VALUE": { value: false },
85
+ "MAX_VALUE": { value: true },
86
+
87
+ parse(str) { return str.trim() === "true"; }
88
+ }
89
+ );
90
+
91
+ Object.defineProperties(
92
+ globalScope["f32"] = function f32(value) { return Math.fround(value); },
93
+ {
94
+ "EPSILON": { value: 1.1920928955078125e-07 },
95
+ "MIN_VALUE": { value: 1.401298464324817e-45 },
96
+ "MAX_VALUE": { value: 3.4028234663852886e+38 },
97
+ "MIN_NORMAL_VALUE": { value: 1.1754943508222875e-38 },
98
+ "MIN_SAFE_INTEGER": { value: -16777215 },
99
+ "MAX_SAFE_INTEGER": { value: 16777215 },
100
+ "POSITIVE_INFINITY": { value: Infinity },
101
+ "NEGATIVE_INFINITY": { value: -Infinity },
102
+ "NaN": { value: NaN },
103
+
104
+ parse(str) { return Math.fround(parseFloat(str)); }
105
+ }
106
+ );
107
+
108
+ Object.defineProperties(
109
+ globalScope["f64"] = function f64(value) { return +value; },
110
+ {
111
+ "EPSILON": { value: 2.2204460492503131e-016 },
112
+ "MIN_VALUE": { value: 5e-324 },
113
+ "MAX_VALUE": { value: 1.7976931348623157e+308 },
114
+ "MIN_NORMAL_VALUE": { value: 2.2250738585072014e-308 },
115
+ "MIN_SAFE_INTEGER": { value: -9007199254740991 },
116
+ "MAX_SAFE_INTEGER": { value: 9007199254740991 },
117
+ "POSITIVE_INFINITY": { value: Infinity },
118
+ "NEGATIVE_INFINITY": { value: -Infinity },
119
+ "NaN": { value: NaN },
120
+
121
+ parse(str) { return parseFloat(str); }
122
+ }
123
+ );
124
+
125
+ globalScope["clz"] = Math.clz32;
126
+
127
+ globalScope["ctz"] = function ctz(value) {
128
+ return 32 - Math.clz32(~value & (value - 1));
129
+ };
130
+
131
+ globalScope["popcnt"] = function popcnt(value) {
132
+ value -= value >>> 1 & 0x55555555;
133
+ value = (value & 0x33333333) + (value >>> 2 & 0x33333333);
134
+ return (((value + (value >>> 4)) & 0x0F0F0F0F) * 0x01010101) >>> 24;
135
+ };
136
+
137
+ globalScope["rotl"] = function rotl(value, shift) {
138
+ shift &= 31;
139
+ return (value << shift) | (value >>> (32 - shift));
140
+ };
141
+
142
+ globalScope["rotr"] = function rotr(value, shift) {
143
+ shift &= 31;
144
+ return (value >>> shift) | (value << (32 - shift));
145
+ };
146
+
147
+ globalScope["abs"] = Math.abs;
148
+
149
+ globalScope["max"] = Math.max;
150
+
151
+ globalScope["min"] = Math.min;
152
+
153
+ globalScope["ceil"] = Math.ceil;
154
+
155
+ globalScope["floor"] = Math.floor;
156
+
157
+ globalScope["nearest"] = function nearest(value) {
158
+ const INV_EPS64 = 4503599627370496.0;
159
+ const y = Math.abs(value);
160
+ return y < INV_EPS64
161
+ ? (y + INV_EPS64 - INV_EPS64) * Math.sign(value)
162
+ : value;
163
+ };
164
+
165
+ globalScope["select"] = function select(ifTrue, ifFalse, condition) {
166
+ return condition ? ifTrue : ifFalse;
167
+ };
168
+
169
+ globalScope["sqrt"] = Math.sqrt;
170
+
171
+ globalScope["trunc"] = Math.trunc;
172
+
173
+ globalScope["copysign"] = function copysign(x, y) {
174
+ return y
175
+ ? Math.abs(x) * Math.sign(y)
176
+ : (F64[0] = y, U64[1] >>> 31 ? -1 : 1); // +0, -0, -NaN, +NaN
177
+ };
178
+
179
+ globalScope["bswap"] = function bswap(value) {
180
+ let a = value >> 8 & 0x00FF00FF;
181
+ let b = (value & 0x00FF00FF) << 8;
182
+ value = a | b;
183
+ a = value >> 16 & 0x0000FFFF;
184
+ b = (value & 0x0000FFFF) << 16;
185
+ return a | b;
186
+ };
187
+
188
+ function UnreachableError() {
189
+ if (Error.captureStackTrace) {
190
+ Error.captureStackTrace(this, UnreachableError);
191
+ } else {
192
+ this.stack = this.name + ": " + this.message + "\n" + new Error().stack;
193
+ }
194
+ }
195
+ UnreachableError.prototype = Object.create(Error.prototype);
196
+ UnreachableError.prototype.name = "UnreachableError";
197
+ UnreachableError.prototype.message = "unreachable";
198
+
199
+ globalScope["unreachable"] = function unreachable() {
200
+ throw new UnreachableError();
201
+ };
202
+
203
+ function AssertionError(message) {
204
+ this.message = message || "assertion failed";
205
+ if (Error.captureStackTrace) {
206
+ Error.captureStackTrace(this, AssertionError);
207
+ } else {
208
+ this.stack = this.name + ": " + this.message + "\n" + new Error().stack;
209
+ }
210
+ }
211
+ AssertionError.prototype = Object.create(Error.prototype);
212
+ AssertionError.prototype.name = "AssertionError";
213
+
214
+ globalScope["assert"] = function assert(isTrueish, message) {
215
+ if (isTrueish) return isTrueish;
216
+ throw new AssertionError(message);
217
+ };
218
+
219
+ globalScope["changetype"] = function changetype(value) {
220
+ return value;
221
+ };
222
+
223
+ String["fromCharCodes"] = function fromCharCodes(arr) {
224
+ const CHUNKSIZE = 1 << 13;
225
+ const len = arr.length;
226
+ if (len <= CHUNKSIZE) {
227
+ return String.fromCharCode.apply(String, arr);
228
+ }
229
+ let index = 0;
230
+ let parts = '';
231
+ while (index < len) {
232
+ parts += String.fromCharCode.apply(
233
+ String,
234
+ arr.slice(index, Math.min(index + CHUNKSIZE, len))
235
+ );
236
+ index += CHUNKSIZE;
237
+ }
238
+ return parts;
239
+ };
240
+
241
+ String["fromCodePoints"] = function fromCodePoints(arr) {
242
+ const CHUNKSIZE = 1 << 13;
243
+ const len = arr.length;
244
+ if (len <= CHUNKSIZE) {
245
+ return String.fromCodePoint.apply(String, arr);
246
+ }
247
+ let index = 0;
248
+ let parts = '';
249
+ while (index < len) {
250
+ parts += String.fromCodePoint.apply(
251
+ String,
252
+ arr.slice(index, Math.min(index + CHUNKSIZE, len))
253
+ );
254
+ index += CHUNKSIZE;
255
+ }
256
+ return parts;
257
+ };
258
+
259
+ if (!String.prototype.at) {
260
+ Object.defineProperty(String.prototype, "at", {
261
+ value: function at(index) {
262
+ return this.charAt(index >= 0 ? index : index + this.length);
263
+ },
264
+ configurable: true
265
+ });
266
+ }
267
+
268
+ if (!String.prototype.replaceAll) {
269
+ Object.defineProperty(String.prototype, "replaceAll", {
270
+ value: function replaceAll(search, replacement) {
271
+ let res = this.split(search).join(replacement);
272
+ if (!search.length) res = replacement + res + replacement;
273
+ return res;
274
+ },
275
+ configurable: true
276
+ });
277
+ }
278
+
279
+ function defaultComparator(a, b) {
280
+ if (a == b) {
281
+ if (a != 0) return 0;
282
+ a = 1 / a;
283
+ b = 1 / b;
284
+ } else {
285
+ let nanA = a != a, nanB = b != b;
286
+ if (nanA | nanB) return nanA - nanB;
287
+ if (a == null) a = String(a);
288
+ if (b == null) b = String(b);
289
+ }
290
+ return a > b ? 1 : -1;
291
+ }
292
+
293
+ const arraySort = Array.prototype.sort;
294
+ Array.prototype.sort = function sort(comparator) {
295
+ return arraySort.call(this, comparator || defaultComparator);
296
+ };
297
+
298
+ [ Array,
299
+ Uint8ClampedArray,
300
+ Uint8Array, Int8Array,
301
+ Uint16Array, Int16Array,
302
+ Uint32Array, Int32Array,
303
+ Float32Array, Float64Array
304
+ ].forEach(Ctr => {
305
+ if (!Ctr.prototype.at) {
306
+ Object.defineProperty(Ctr.prototype, "at", {
307
+ value: function at(index) {
308
+ return this[index >= 0 ? index : index + this.length];
309
+ },
310
+ configurable: true
311
+ });
312
+ }
313
+
314
+ if (!Ctr.prototype.findLastIndex) {
315
+ Object.defineProperty(Ctr.prototype, "findLastIndex", {
316
+ value: function findLastIndex(fn) {
317
+ for (let i = this.length - 1; i >= 0; --i) {
318
+ if (fn(this[i], i, this)) return i;
319
+ }
320
+ return -1;
321
+ },
322
+ configurable: true
323
+ });
324
+ }
325
+
326
+ if (Ctr != Array) {
327
+ Object.defineProperty(Ctr, "wrap", {
328
+ value: function wrap(buffer, byteOffset, length) {
329
+ return new Ctr(buffer, byteOffset, length);
330
+ },
331
+ configurable: true
332
+ });
333
+ }
334
+ });
335
+
336
+ globalScope["isInteger"] = Number.isInteger;
337
+
338
+ globalScope["isFloat"] = function isFloat(arg) {
339
+ return typeof arg === "number";
340
+ };
341
+
342
+ globalScope["isNullable"] = function isNullable(arg) {
343
+ return true;
344
+ };
345
+
346
+ globalScope["isReference"] = function isReference(arg) {
347
+ return typeof arg === "object" || typeof arg === "string";
348
+ };
349
+
350
+ globalScope["isFunction"] = function isFunction(arg) {
351
+ return typeof arg === "function";
352
+ };
353
+
354
+ globalScope["isString"] = function isString(arg) {
355
+ return typeof arg === "string" || arg instanceof String;
356
+ };
357
+
358
+ globalScope["isArray"] = Array.isArray;
359
+ globalScope["isArrayLike"] = function isArrayLike(expr) {
360
+ return expr
361
+ && typeof expr === 'object'
362
+ && typeof expr.length === 'number'
363
+ && expr.length >= 0
364
+ && Math.trunc(expr.length) === expr.length;
365
+ };
366
+
367
+ globalScope["isDefined"] = function isDefined(expr) {
368
+ return typeof expr !== "undefined";
369
+ };
370
+
371
+ globalScope["isConstant"] = function isConstant(expr) {
372
+ return false;
373
+ };
374
+
375
+ globalScope["unchecked"] = function unchecked(expr) {
376
+ return expr;
377
+ };
378
+
379
+ globalScope["fmod"] = function fmod(x, y) {
380
+ return x % y;
381
+ };
382
+
383
+ globalScope["fmodf"] = function fmodf(x, y) {
384
+ return Math.fround(x % y);
385
+ };
386
+
387
+ globalScope["JSMath"] = Math;
388
+
389
+ Object.defineProperties(globalScope["JSMath"], {
390
+ sincos_sin: { value: 0.0, writable: true },
391
+ sincos_cos: { value: 0.0, writable: true },
392
+ signbit: {
393
+ value: function signbit(x) {
394
+ F64[0] = x; return Boolean(U64[1] >>> 31);
395
+ }
396
+ },
397
+ sincos: {
398
+ value: function sincos(x) {
399
+ this.sincos_sin = Math.sin(x);
400
+ this.sincos_cos = Math.cos(x);
401
+ }
402
+ },
403
+ exp2: {
404
+ value: function exp2(x) {
405
+ return Math.pow(2, x);
406
+ }
407
+ }
408
+ });
409
+
410
+ globalScope["unmanaged"] = function() { /* nop */ };
411
+
412
+ globalScope["trace"] = function(message, n) {
413
+ if (n) message += Array.prototype.slice.call(arguments, 2, 2 + n);
414
+ console.error("trace: " + message);
415
+ };
416
+ }