@amxts/core 0.2.4 → 0.3.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 (71) hide show
  1. package/README.md +5 -5
  2. package/README.ru.md +5 -5
  3. package/as/amxts.d.ts +13 -3
  4. package/as/entities.ts +571 -501
  5. package/as/events.ts +3323 -557
  6. package/as/facade.ts +3079 -718
  7. package/as/fetch.ts +2 -2
  8. package/as/fs.ts +352 -59
  9. package/as/hlds.ts +121 -120
  10. package/as/hooks.ts +10585 -5177
  11. package/as/lib/check.ts +3 -2
  12. package/as/natives.ts +856 -1272
  13. package/as/promise.ts +37 -27
  14. package/as/vector.ts +94 -14
  15. package/includes/order.txt +17 -19
  16. package/node_modules/assemblyscript/std/assembly/index.d.ts +1 -1
  17. package/package.json +9 -6
  18. package/runtime/deps/assemblyscript/dist/asc.js +136 -42
  19. package/runtime/deps/assemblyscript/dist/assemblyscript.js +141 -141
  20. package/runtime/licenses/README.md +9 -7
  21. package/runtime/licenses/ReGameDLL-LICENSE +21 -0
  22. package/runtime/licenses/ReHLDS-LICENSE +21 -0
  23. package/runtime/licenses/zlib-LICENSE +22 -0
  24. package/runtime/natives.txt +618 -523
  25. package/runtime/patches/README.md +87 -1
  26. package/runtime/patches/assemblyscript-0.28.20-amxts.patch +4838 -416
  27. package/runtime/patches/wamr-2.4.5-amxts.patch +417 -5
  28. package/scripts/auto-imports.ts +1 -1
  29. package/scripts/build-identity.ts +102 -65
  30. package/scripts/build-wasm.ts +12 -12
  31. package/scripts/check.ts +4 -1
  32. package/scripts/client-messages.ts +73 -1
  33. package/scripts/compile-cache.ts +11 -8
  34. package/scripts/compile-pool.ts +6 -3
  35. package/scripts/compile-worker.ts +23 -23
  36. package/scripts/compile.ts +142 -19
  37. package/scripts/docs/as/amxts.ts +10 -4
  38. package/scripts/docs/as/facade.ts +1779 -275
  39. package/scripts/docs/as/fetch.ts +2 -2
  40. package/scripts/docs/as/fs.ts +190 -6
  41. package/scripts/docs/as/vector.ts +81 -0
  42. package/scripts/docs/entities.ts +12 -0
  43. package/scripts/docs/events.ts +49 -13
  44. package/scripts/docs/game.ts +6 -0
  45. package/scripts/docs/messages.ts +10 -1
  46. package/scripts/hlds-events.ts +11 -11
  47. package/scripts/includes.ts +3 -4
  48. package/scripts/leaf-natives.ts +84 -0
  49. package/scripts/player-fields.ts +1 -1
  50. package/scripts/plugin-natives.ts +1 -1
  51. package/scripts/prebuilt.ts +41 -10
  52. package/scripts/project.ts +2 -3
  53. package/scripts/reapi-events.ts +9 -9
  54. package/scripts/server-env.ts +145 -0
  55. package/scripts/shared-modules.ts +23 -7
  56. package/scripts/system.ts +1 -1
  57. package/scripts/tracked-fs.ts +11 -2
  58. package/scripts/typed-commands.ts +153 -15
  59. package/scripts/upgrade-calls.ts +225 -0
  60. package/scripts/upgrade-names.ts +1 -4
  61. package/scripts/upgrade.ts +26 -11
  62. package/src/cli-api.mjs +3 -2
  63. package/src/system.mjs +21 -11
  64. package/src/testing/compile.ts +31 -8
  65. package/src/testing/coroutines.ts +0 -10
  66. package/src/testing/memory.ts +89 -2
  67. package/src/testing/natives.ts +67 -30
  68. package/src/testing/server.ts +1094 -155
  69. package/src/testing/tables.ts +23 -6
  70. package/src/typecheck.mjs +110 -0
  71. package/runtime/licenses/Bun-LICENSE.md +0 -84
@@ -29,7 +29,11 @@ function ensureCapacity(array: usize, newSize: usize, alignLog2: u32, canGrow: b
29
29
  // Make sure we don't reach BLOCK_MAXSIZE for new growed capacity.
30
30
  let newCapacity = max(newSize, MIN_SIZE) << alignLog2;
31
31
  if (canGrow) newCapacity = max(min(oldCapacity << 1, BLOCK_MAXSIZE), newCapacity);
32
- let newData = __renew(oldData, newCapacity);
32
+ // amxts: elements kept in the array's own object (the constructor's
33
+ // \`inline\`) move out to a buffer of their own; the object stays.
34
+ let newData = oldData == array
35
+ ? moveOut(changetype<ArrayBufferView>(array).dataStart, oldCapacity, newCapacity)
36
+ : __renew(oldData, newCapacity);
33
37
  // __new / __renew already init memory range as zeros in Incremental runtime.
34
38
  // So try to avoid this.
35
39
  if (ASC_RUNTIME != Runtime.Incremental) {
@@ -44,6 +48,13 @@ function ensureCapacity(array: usize, newSize: usize, alignLog2: u32, canGrow: b
44
48
  }
45
49
  }
46
50
 
51
+ // amxts: a new buffer of \`capacity\` bytes, starting with the \`size\` bytes at \`data\`.
52
+ function moveOut(data: usize, size: usize, capacity: usize): usize {
53
+ let buffer = __new(capacity, idof<ArrayBuffer>());
54
+ memory.copy(buffer, data, size);
55
+ return buffer;
56
+ }
57
+
47
58
  export class Array<T> {
48
59
  [key: number]: T;
49
60
 
@@ -73,17 +84,28 @@ export class Array<T> {
73
84
  return array;
74
85
  }
75
86
 
76
- constructor(length: i32 = 0) {
77
- if (<u32>length > <u32>BLOCK_MAXSIZE >>> alignof<T>()) throw new RangeError(E_INVALIDLENGTH);
78
- // reserve capacity for at least MIN_SIZE elements
79
- let bufferSize = max(<usize>length, MIN_SIZE) << alignof<T>();
80
- let buffer = changetype<ArrayBuffer>(__new(bufferSize, idof<ArrayBuffer>()));
81
- if (ASC_RUNTIME != Runtime.Incremental) {
82
- memory.fill(changetype<usize>(buffer), 0, bufferSize);
87
+ // amxts: \`inline\` makes an array of \`length\` with no buffer: the subclass
88
+ // that asks for it points the array at room in its own object (Vector), so
89
+ // it is one allocation, its own buffer until it grows past that room.
90
+ // Inlined: a constant \`inline\` leaves one of the two paths.
91
+ // @ts-ignore: decorator
92
+ @inline constructor(length: i32 = 0, inline: bool = false) {
93
+ if (inline) {
94
+ this.buffer = changetype<ArrayBuffer>(0);
95
+ this.dataStart = 0;
96
+ this.byteLength = 0;
97
+ } else {
98
+ if (<u32>length > <u32>BLOCK_MAXSIZE >>> alignof<T>()) throw new RangeError(E_INVALIDLENGTH);
99
+ // reserve capacity for at least MIN_SIZE elements
100
+ let bufferSize = max(<usize>length, MIN_SIZE) << alignof<T>();
101
+ let buffer = changetype<ArrayBuffer>(__new(bufferSize, idof<ArrayBuffer>()));
102
+ if (ASC_RUNTIME != Runtime.Incremental) {
103
+ memory.fill(changetype<usize>(buffer), 0, bufferSize);
104
+ }
105
+ this.buffer = buffer; // links
106
+ this.dataStart = changetype<usize>(buffer);
107
+ this.byteLength = <i32>bufferSize;
83
108
  }
84
- this.buffer = buffer; // links
85
- this.dataStart = changetype<usize>(buffer);
86
- this.byteLength = <i32>bufferSize;
87
109
  this.length_ = length;
88
110
  }
89
111
 
@@ -319,6 +341,17 @@ export class Array<T> {
319
341
  return out;
320
342
  }
321
343
 
344
+ // amxts: flatMap, as in JavaScript, for a function that returns an array:
345
+ // its elements, one array after another.
346
+ flatMap<U>(fn: (value: T, index: i32, array: Array<T>) => Array<U>): Array<U> {
347
+ let out = changetype<Array<U>>(__newArray(0, alignof<U>(), idof<Array<U>>()));
348
+ for (let i = 0, len = this.length_; i < min(len, this.length_); ++i) {
349
+ let part = fn(load<T>(this.dataStart + (<usize>i << alignof<T>())), i, this);
350
+ for (let j = 0, count = part.length_; j < count; ++j) out.push(load<U>(part.dataStart + (<usize>j << alignof<U>())));
351
+ }
352
+ return out;
353
+ }
354
+
322
355
  filter(fn: (value: T, index: i32, array: Array<T>) => bool): Array<T> {
323
356
  let result = changetype<Array<T>>(__newArray(0, alignof<T>(), idof<Array<T>>()));
324
357
  for (let i = 0, len = this.length_; i < min(len, this.length_); ++i) {
@@ -462,7 +495,7 @@ export class Array<T> {
462
495
  return this;
463
496
  }
464
497
 
465
- sort(comparator: (a: T, b: T) => i32 = COMPARATOR<T>()): Array<T> {
498
+ sort(comparator: (a: T, b: T) => f64 = COMPARATOR<T>()): Array<T> {
466
499
  SORT<T>(this.dataStart, this.length_, comparator);
467
500
  return this;
468
501
  }
@@ -4646,13 +4679,15 @@ export function __box<T>(value: T): usize {
4646
4679
  return changetype<usize>(new __Box<T>(value));
4647
4680
  }
4648
4681
 
4649
- /** amxts: what the box holds. */
4650
- export function __box_get<T>(box: usize): T {
4682
+ /** amxts: what the box holds - a load where it is read, not a call. */
4683
+ // @ts-ignore: decorator
4684
+ @inline export function __box_get<T>(box: usize): T {
4651
4685
  return changetype<__Box<T>>(box).value;
4652
4686
  }
4653
4687
 
4654
- /** amxts: \`value\` into the box, and back. */
4655
- export function __box_set<T>(box: usize, value: T): T {
4688
+ /** amxts: \`value\` into the box, and back - a store where it is written, not a call. */
4689
+ // @ts-ignore: decorator
4690
+ @inline export function __box_set<T>(box: usize, value: T): T {
4656
4691
  changetype<__Box<T>>(box).value = value;
4657
4692
  return value;
4658
4693
  }
@@ -11195,7 +11230,25 @@ function visitRoots(cookie: u32): void {
11195
11230
  function visitStack(cookie: u32): void {
11196
11231
  let ptr = __stack_pointer;
11197
11232
  while (ptr < __heap_base) {
11198
- __visit(load<usize>(ptr), cookie);
11233
+ let word = load<usize>(ptr);
11234
+ // amxts: a function's objects made in its frame, behind a mark and the
11235
+ // bytes they take (src/passes/stackobjects.ts): stepped over, or, behind
11236
+ // -2, each one whose slot has 1 at 8 visited as an object on the heap is
11237
+ if (word == <usize>-1 || word == <usize>-2) {
11238
+ let end = ptr + load<usize>(ptr, sizeof<usize>());
11239
+ if (word == <usize>-2) {
11240
+ // a slot: 12 bytes, the object's header, the object, to 16 bytes
11241
+ let slot = ptr;
11242
+ while (slot + 32 <= end) {
11243
+ let obj = slot + 32;
11244
+ if (load<u32>(slot, 8)) __visit_members(obj, cookie);
11245
+ slot = obj + ((<usize>load<u32>(obj - 4) + 15) & ~15);
11246
+ }
11247
+ }
11248
+ ptr = end;
11249
+ continue;
11250
+ }
11251
+ __visit(word, cookie);
11199
11252
  ptr += sizeof<usize>();
11200
11253
  }
11201
11254
  }
@@ -11287,7 +11340,9 @@ function free(obj: Object): void {
11287
11340
  @global @unsafe
11288
11341
  export function __new(size: usize, id: i32): usize {
11289
11342
  if (size >= OBJECT_MAXSIZE) throw new Error(E_ALLOCATION_TOO_LARGE);
11290
- if (total >= threshold) interrupt();
11343
+ // amxts: ASC_GC_STRESS steps the collector on every allocation, for the
11344
+ // tests of what the shadow stack keeps
11345
+ if (isDefined(ASC_GC_STRESS) || total >= threshold) interrupt();
11291
11346
  let obj = changetype<Object>(__alloc(OBJECT_OVERHEAD + size) - BLOCK_OVERHEAD);
11292
11347
  obj.rtId = id;
11293
11348
  obj.rtSize = <u32>size;
@@ -11401,7 +11456,7 @@ export function __collect(): void {
11401
11456
  // perform a full cycle
11402
11457
  step();
11403
11458
  while (state != STATE_IDLE) step();
11404
- threshold = <usize>(<u64>total * IDLEFACTOR / 100) + GRANULARITY;
11459
+ threshold = <usize>(<u64>total * IDLEFACTOR / 100) + IDLEGAP;
11405
11460
  if (TRACE) trace("GC (full) done at cur/max", 2, total, memory.size() << 16);
11406
11461
  if (RTRACE || PROFILE) oncollect(total);
11407
11462
  }
@@ -11418,6 +11473,14 @@ export function __collect(): void {
11418
11473
  // @ts-ignore: decorator
11419
11474
  @inline const IDLEFACTOR: usize = isDefined(ASC_GC_IDLEFACTOR) ? ASC_GC_IDLEFACTOR : 200;
11420
11475
 
11476
+ /**
11477
+ * amxts: how much more is allocated, at least, before the next cycle starts.
11478
+ * A cycle visits every root and every live object: with a small heap and
11479
+ * the gap GRANULARITY alone, it ran every few hundred allocations.
11480
+ */
11481
+ // @ts-ignore: decorator
11482
+ @inline const IDLEGAP: usize = isDefined(ASC_GC_IDLEGAP) ? ASC_GC_IDLEGAP : 1024 * 1024;
11483
+
11421
11484
  /** Threshold of memory used by objects to exceed before interrupting again. */
11422
11485
  // @ts-ignore: decorator
11423
11486
  @lazy let threshold: usize = ((<usize>memory.size() << 16) - __heap_base) >> 1;
@@ -11433,9 +11496,9 @@ function interrupt(): void {
11433
11496
  if (TRACE) trace("\u2514 GC (auto) done at cur/max", 2, total, memory.size() << 16);
11434
11497
  if (IDLEFACTOR % 100 == 0) {
11435
11498
  // optimization for the default GC parameters which idle factor is 200%
11436
- threshold = total * (IDLEFACTOR / 100) + GRANULARITY;
11499
+ threshold = total * (IDLEFACTOR / 100) + IDLEGAP;
11437
11500
  } else {
11438
- threshold = <usize>((<u64>total * IDLEFACTOR) / 100) + GRANULARITY;
11501
+ threshold = <usize>((<u64>total * IDLEFACTOR) / 100) + IDLEGAP;
11439
11502
  }
11440
11503
  if (PROFILE) onyield(total);
11441
11504
  return;
@@ -12405,6 +12468,19 @@ export function freeBlock(root: Root, block: Block): void {
12405
12468
  insertBlock(root, block);
12406
12469
  }
12407
12470
 
12471
+ // amxts: a small block freed goes on a list of its size, and the next
12472
+ // allocation of that size takes it back: no search, split or merge. It stays
12473
+ // a used block to TLSF, so no neighbour merges with it, and it is not given
12474
+ // back to TLSF for other sizes. Its first word links the list. The sizes are
12475
+ // TLSF's own (16 n + 12 on 32 bits), a list each, up to SMALL_MAX.
12476
+
12477
+ // @ts-ignore: decorator
12478
+ @inline const SMALL_MAX: usize = 124;
12479
+
12480
+ /** The lists' heads, by a block's size >> AL_BITS. */
12481
+ // @ts-ignore: decorator
12482
+ @lazy let SMALL = memory.data(<i32>(((SMALL_MAX >> AL_BITS) + 1) << alignof<usize>()));
12483
+
12408
12484
  /** Checks that a used block is valid to be freed or reallocated. */
12409
12485
  function checkUsedBlock(ptr: usize): Block {
12410
12486
  let block = changetype<Block>(ptr - BLOCK_OVERHEAD);
@@ -12418,6 +12494,14 @@ function checkUsedBlock(ptr: usize): Block {
12418
12494
  // @ts-ignore: decorator
12419
12495
  @global @unsafe
12420
12496
  export function __alloc(size: usize): usize {
12497
+ if (size <= SMALL_MAX) {
12498
+ let head = SMALL + (computeSize(size) >> AL_BITS << alignof<usize>());
12499
+ let block = load<usize>(head);
12500
+ if (block) {
12501
+ store<usize>(head, load<usize>(block, BLOCK_OVERHEAD));
12502
+ return block + BLOCK_OVERHEAD;
12503
+ }
12504
+ }
12421
12505
  if (!ROOT) initialize();
12422
12506
  return changetype<usize>(allocateBlock(ROOT, size)) + BLOCK_OVERHEAD;
12423
12507
  }
@@ -12436,8 +12520,16 @@ export function __realloc(ptr: usize, size: usize): usize {
12436
12520
  @global @unsafe
12437
12521
  export function __free(ptr: usize): void {
12438
12522
  if (ptr < __heap_base) return;
12523
+ let block = checkUsedBlock(ptr);
12524
+ let size = block.mmInfo & ~TAGS_MASK;
12525
+ if (size <= SMALL_MAX) {
12526
+ let head = SMALL + (size >> AL_BITS << alignof<usize>());
12527
+ store<usize>(ptr, load<usize>(head));
12528
+ store<usize>(head, changetype<usize>(block));
12529
+ return;
12530
+ }
12439
12531
  if (!ROOT) initialize();
12440
- freeBlock(ROOT, checkUsedBlock(ptr));
12532
+ freeBlock(ROOT, block);
12441
12533
  }
12442
12534
  `,set:`/// <reference path="./rt/index.d.ts" />
12443
12535
 
@@ -13206,7 +13298,7 @@ export class StaticArray<T> {
13206
13298
  return false;
13207
13299
  }
13208
13300
 
13209
- sort(comparator: (a: T, b: T) => i32 = COMPARATOR<T>()): StaticArray<T> {
13301
+ sort(comparator: (a: T, b: T) => f64 = COMPARATOR<T>()): StaticArray<T> {
13210
13302
  SORT<T>(changetype<usize>(this), this.length, comparator);
13211
13303
  return this;
13212
13304
  }
@@ -14356,7 +14448,7 @@ export class Int8Array extends ArrayBufferView {
14356
14448
  return this;
14357
14449
  }
14358
14450
 
14359
- sort(comparator: (a: i8, b: i8) => i32 = COMPARATOR<i8>()): Int8Array {
14451
+ sort(comparator: (a: i8, b: i8) => f64 = COMPARATOR<i8>()): Int8Array {
14360
14452
  SORT<i8>(this.dataStart, this.length, comparator);
14361
14453
  return this;
14362
14454
  }
@@ -14498,7 +14590,7 @@ export class Uint8Array extends ArrayBufferView {
14498
14590
  return this;
14499
14591
  }
14500
14592
 
14501
- sort(comparator: (a: u8, b: u8) => i32 = COMPARATOR<u8>()): Uint8Array {
14593
+ sort(comparator: (a: u8, b: u8) => f64 = COMPARATOR<u8>()): Uint8Array {
14502
14594
  SORT<u8>(this.dataStart, this.length, comparator);
14503
14595
  return this;
14504
14596
  }
@@ -14641,7 +14733,7 @@ export class Uint8ClampedArray extends ArrayBufferView {
14641
14733
  return this;
14642
14734
  }
14643
14735
 
14644
- sort(comparator: (a: u8, b: u8) => i32 = COMPARATOR<u8>()): Uint8ClampedArray {
14736
+ sort(comparator: (a: u8, b: u8) => f64 = COMPARATOR<u8>()): Uint8ClampedArray {
14645
14737
  SORT<u8>(this.dataStart, this.length, comparator);
14646
14738
  return this;
14647
14739
  }
@@ -14783,7 +14875,7 @@ export class Int16Array extends ArrayBufferView {
14783
14875
  return this;
14784
14876
  }
14785
14877
 
14786
- sort(comparator: (a: i16, b: i16) => i32 = COMPARATOR<i16>()): Int16Array {
14878
+ sort(comparator: (a: i16, b: i16) => f64 = COMPARATOR<i16>()): Int16Array {
14787
14879
  SORT<i16>(this.dataStart, this.length, comparator);
14788
14880
  return this;
14789
14881
  }
@@ -14925,7 +15017,7 @@ export class Uint16Array extends ArrayBufferView {
14925
15017
  return this;
14926
15018
  }
14927
15019
 
14928
- sort(comparator: (a: u16, b: u16) => i32 = COMPARATOR<u16>()): Uint16Array {
15020
+ sort(comparator: (a: u16, b: u16) => f64 = COMPARATOR<u16>()): Uint16Array {
14929
15021
  SORT<u16>(this.dataStart, this.length, comparator);
14930
15022
  return this;
14931
15023
  }
@@ -15067,7 +15159,7 @@ export class Int32Array extends ArrayBufferView {
15067
15159
  return this;
15068
15160
  }
15069
15161
 
15070
- sort(comparator: (a: i32, b: i32) => i32 = COMPARATOR<i32>()): Int32Array {
15162
+ sort(comparator: (a: i32, b: i32) => f64 = COMPARATOR<i32>()): Int32Array {
15071
15163
  SORT<i32>(this.dataStart, this.length, comparator);
15072
15164
  return this;
15073
15165
  }
@@ -15209,7 +15301,7 @@ export class Uint32Array extends ArrayBufferView {
15209
15301
  return this;
15210
15302
  }
15211
15303
 
15212
- sort(comparator: (a: u32, b: u32) => i32 = COMPARATOR<u32>()): Uint32Array {
15304
+ sort(comparator: (a: u32, b: u32) => f64 = COMPARATOR<u32>()): Uint32Array {
15213
15305
  SORT<u32>(this.dataStart, this.length, comparator);
15214
15306
  return this;
15215
15307
  }
@@ -15351,7 +15443,7 @@ export class Int64Array extends ArrayBufferView {
15351
15443
  return this;
15352
15444
  }
15353
15445
 
15354
- sort(comparator: (a: i64, b: i64) => i32 = COMPARATOR<i64>()): Int64Array {
15446
+ sort(comparator: (a: i64, b: i64) => f64 = COMPARATOR<i64>()): Int64Array {
15355
15447
  SORT<i64>(this.dataStart, this.length, comparator);
15356
15448
  return this;
15357
15449
  }
@@ -15493,7 +15585,7 @@ export class Uint64Array extends ArrayBufferView {
15493
15585
  return this;
15494
15586
  }
15495
15587
 
15496
- sort(comparator: (a: u64, b: u64) => i32 = COMPARATOR<u64>()): Uint64Array {
15588
+ sort(comparator: (a: u64, b: u64) => f64 = COMPARATOR<u64>()): Uint64Array {
15497
15589
  SORT<u64>(this.dataStart, this.length, comparator);
15498
15590
  return this;
15499
15591
  }
@@ -15635,7 +15727,7 @@ export class Float32Array extends ArrayBufferView {
15635
15727
  return this;
15636
15728
  }
15637
15729
 
15638
- sort(comparator: (a: f32, b: f32) => i32 = COMPARATOR<f32>()): Float32Array {
15730
+ sort(comparator: (a: f32, b: f32) => f64 = COMPARATOR<f32>()): Float32Array {
15639
15731
  SORT<f32>(this.dataStart, this.length, comparator);
15640
15732
  return this;
15641
15733
  }
@@ -15777,7 +15869,7 @@ export class Float64Array extends ArrayBufferView {
15777
15869
  return this;
15778
15870
  }
15779
15871
 
15780
- sort(comparator: (a: f64, b: f64) => i32 = COMPARATOR<f64>()): Float64Array {
15872
+ sort(comparator: (a: f64, b: f64) => f64 = COMPARATOR<f64>()): Float64Array {
15781
15873
  SORT<f64>(this.dataStart, this.length, comparator);
15782
15874
  return this;
15783
15875
  }
@@ -20132,7 +20224,9 @@ function wholeWithoutFraction(buffer: usize, length: i32): i32 {
20132
20224
  }
20133
20225
  `,"util/sort":`import { compareImpl } from "./string";
20134
20226
 
20135
- type Comparator<T> = (a: T, b: T) => i32;
20227
+ // amxts: a comparator returns a number, and its sign orders two elements, as
20228
+ // in JavaScript: \`(a, b) => a - b\` sorts fractions too. NaN is 0, equal.
20229
+ type Comparator<T> = (a: T, b: T) => f64;
20136
20230
 
20137
20231
  // @ts-ignore: decorator
20138
20232
  @lazy @inline const EMPTY = u32.MAX_VALUE;
@@ -20338,7 +20432,7 @@ function insertionSort<T>(
20338
20432
  let a = load<T>(ptr + (<usize>i << alignof<T>()), 0);
20339
20433
  let b = load<T>(ptr + (<usize>i << alignof<T>()), 1 << alignof<T>());
20340
20434
  let min = b, max = a;
20341
- if (comparator(a, b) <= 0) {
20435
+ if (!(comparator(a, b) > 0)) {
20342
20436
  min = a, max = b;
20343
20437
  }
20344
20438
  let j = i - 1;
@@ -20384,10 +20478,10 @@ function extendRunRight<T>(
20384
20478
  ) > 0) {
20385
20479
  while (
20386
20480
  j < right &&
20387
- (comparator(
20481
+ comparator(
20388
20482
  load<T>(ptr + (<usize>j << alignof<T>()), 1 << alignof<T>()),
20389
20483
  load<T>(ptr + (<usize>j << alignof<T>()))
20390
- ) >>> 31) // < 0
20484
+ ) < 0
20391
20485
  ) ++j;
20392
20486
  // reverse
20393
20487
  let k = j;
@@ -20399,10 +20493,10 @@ function extendRunRight<T>(
20399
20493
  } else {
20400
20494
  while (
20401
20495
  j < right &&
20402
- comparator(
20496
+ !(comparator(
20403
20497
  load<T>(ptr + (<usize>j << alignof<T>()), 1 << alignof<T>()),
20404
20498
  load<T>(ptr + (<usize>j << alignof<T>()))
20405
- ) >= 0
20499
+ ) < 0)
20406
20500
  ) ++j;
20407
20501
  }
20408
20502
  return j;
@@ -24010,7 +24104,7 @@ declare class Array<T> {
24010
24104
  unshift(element: T): i32;
24011
24105
  slice(from?: i32, to?: i32): Array<T>;
24012
24106
  splice(start: i32, deleteCount?: i32, ...items: T[]): Array<T>;
24013
- sort(comparator?: (a: T, b: T) => i32): this;
24107
+ sort(comparator?: (a: T, b: T) => f64): this;
24014
24108
  join(separator?: string): string;
24015
24109
  reverse(): this;
24016
24110
  /** Flattens an array of arrays. If any null entries exist in the array, they are ignored, unlike JavaScript's version of Array#flat(). */
@@ -24047,7 +24141,7 @@ declare class StaticArray<T> {
24047
24141
  concat<U extends ArrayLike<T>>(other: U): U;
24048
24142
  slice(from?: i32, to?: i32): Array<T>;
24049
24143
  slice<U extends ArrayLike<T>>(from?: i32, to?: i32): U;
24050
- sort(comparator?: (a: T, b: T) => i32): this;
24144
+ sort(comparator?: (a: T, b: T) => f64): this;
24051
24145
  join(separator?: string): string;
24052
24146
  reverse(): this;
24053
24147
  toString(): string;