@elaraai/east 1.0.80 → 1.0.82

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 (150) hide show
  1. package/dist/src/builtins.d.ts +1 -1
  2. package/dist/src/builtins.d.ts.map +1 -1
  3. package/dist/src/builtins.js +19 -0
  4. package/dist/src/builtins.js.map +1 -1
  5. package/dist/src/codegen/spellings.d.ts.map +1 -1
  6. package/dist/src/codegen/spellings.js +3 -0
  7. package/dist/src/codegen/spellings.js.map +1 -1
  8. package/dist/src/comparison.d.ts +54 -0
  9. package/dist/src/comparison.d.ts.map +1 -1
  10. package/dist/src/comparison.equivalent.spec.d.ts +6 -0
  11. package/dist/src/comparison.equivalent.spec.d.ts.map +1 -0
  12. package/dist/src/comparison.equivalent.spec.js +130 -0
  13. package/dist/src/comparison.equivalent.spec.js.map +1 -0
  14. package/dist/src/comparison.js +93 -20
  15. package/dist/src/comparison.js.map +1 -1
  16. package/dist/src/compile/builtins/array.d.ts +2 -1
  17. package/dist/src/compile/builtins/array.d.ts.map +1 -1
  18. package/dist/src/compile/builtins/array.js +35 -0
  19. package/dist/src/compile/builtins/array.js.map +1 -1
  20. package/dist/src/compile/builtins/dict.d.ts +1 -0
  21. package/dist/src/compile/builtins/dict.d.ts.map +1 -1
  22. package/dist/src/compile/builtins/dict.js +25 -0
  23. package/dist/src/compile/builtins/dict.js.map +1 -1
  24. package/dist/src/compile/builtins/set.d.ts +1 -0
  25. package/dist/src/compile/builtins/set.d.ts.map +1 -1
  26. package/dist/src/compile/builtins/set.js +25 -0
  27. package/dist/src/compile/builtins/set.js.map +1 -1
  28. package/dist/src/compile/builtins/tree.d.ts +32 -0
  29. package/dist/src/compile/builtins/tree.d.ts.map +1 -0
  30. package/dist/src/compile/builtins/tree.js +108 -0
  31. package/dist/src/compile/builtins/tree.js.map +1 -0
  32. package/dist/src/compile/functions.d.ts.map +1 -1
  33. package/dist/src/compile/functions.js +4 -4
  34. package/dist/src/compile/functions.js.map +1 -1
  35. package/dist/src/compile/runtime.d.ts +12 -15
  36. package/dist/src/compile/runtime.d.ts.map +1 -1
  37. package/dist/src/compile/runtime.js +19 -16
  38. package/dist/src/compile/runtime.js.map +1 -1
  39. package/dist/src/compile.signature.spec.d.ts +6 -0
  40. package/dist/src/compile.signature.spec.d.ts.map +1 -0
  41. package/dist/src/compile.signature.spec.js +53 -0
  42. package/dist/src/compile.signature.spec.js.map +1 -0
  43. package/dist/src/expr/array.d.ts +158 -81
  44. package/dist/src/expr/array.d.ts.map +1 -1
  45. package/dist/src/expr/array.js +68 -51
  46. package/dist/src/expr/array.js.map +1 -1
  47. package/dist/src/expr/ast.d.ts.map +1 -1
  48. package/dist/src/expr/ast.js +13 -0
  49. package/dist/src/expr/ast.js.map +1 -1
  50. package/dist/src/expr/blob.d.ts +8 -8
  51. package/dist/src/expr/blob.js +8 -8
  52. package/dist/src/expr/block.d.ts +18 -5
  53. package/dist/src/expr/block.d.ts.map +1 -1
  54. package/dist/src/expr/block.js +19 -0
  55. package/dist/src/expr/block.js.map +1 -1
  56. package/dist/src/expr/boolean.d.ts +10 -10
  57. package/dist/src/expr/boolean.js +10 -10
  58. package/dist/src/expr/datetime.d.ts +28 -28
  59. package/dist/src/expr/datetime.js +28 -28
  60. package/dist/src/expr/dict.d.ts +101 -51
  61. package/dist/src/expr/dict.d.ts.map +1 -1
  62. package/dist/src/expr/dict.js +97 -36
  63. package/dist/src/expr/dict.js.map +1 -1
  64. package/dist/src/expr/float.d.ts +23 -23
  65. package/dist/src/expr/float.js +23 -23
  66. package/dist/src/expr/integer.d.ts +17 -17
  67. package/dist/src/expr/integer.js +11 -11
  68. package/dist/src/expr/libs/array.d.ts +6 -6
  69. package/dist/src/expr/libs/array.js +6 -6
  70. package/dist/src/expr/libs/blob.d.ts +2 -2
  71. package/dist/src/expr/libs/blob.js +2 -2
  72. package/dist/src/expr/libs/datetime.d.ts +25 -25
  73. package/dist/src/expr/libs/datetime.js +25 -25
  74. package/dist/src/expr/libs/dict.d.ts +2 -2
  75. package/dist/src/expr/libs/dict.js +2 -2
  76. package/dist/src/expr/libs/float.d.ts +15 -15
  77. package/dist/src/expr/libs/float.js +15 -15
  78. package/dist/src/expr/libs/integer.d.ts +12 -12
  79. package/dist/src/expr/libs/integer.js +12 -12
  80. package/dist/src/expr/libs/set.d.ts +2 -2
  81. package/dist/src/expr/libs/set.js +2 -2
  82. package/dist/src/expr/libs/string.d.ts +4 -4
  83. package/dist/src/expr/libs/string.js +4 -4
  84. package/dist/src/expr/recursive.d.ts +22 -5
  85. package/dist/src/expr/recursive.d.ts.map +1 -1
  86. package/dist/src/expr/recursive.js +22 -5
  87. package/dist/src/expr/recursive.js.map +1 -1
  88. package/dist/src/expr/ref.d.ts +5 -5
  89. package/dist/src/expr/ref.js +5 -5
  90. package/dist/src/expr/set.d.ts +96 -51
  91. package/dist/src/expr/set.d.ts.map +1 -1
  92. package/dist/src/expr/set.js +85 -29
  93. package/dist/src/expr/set.js.map +1 -1
  94. package/dist/src/expr/string.d.ts +28 -28
  95. package/dist/src/expr/string.js +28 -28
  96. package/dist/src/expr/struct.d.ts.map +1 -1
  97. package/dist/src/expr/struct.js +2 -2
  98. package/dist/src/expr/variant.d.ts +12 -12
  99. package/dist/src/expr/variant.js +7 -7
  100. package/dist/src/function_symbols.d.ts +28 -0
  101. package/dist/src/function_symbols.d.ts.map +1 -0
  102. package/dist/src/function_symbols.js +28 -0
  103. package/dist/src/function_symbols.js.map +1 -0
  104. package/dist/src/location.d.ts +32 -0
  105. package/dist/src/location.d.ts.map +1 -1
  106. package/dist/src/location.js +38 -0
  107. package/dist/src/location.js.map +1 -1
  108. package/dist/src/location.spec.js +89 -1
  109. package/dist/src/location.spec.js.map +1 -1
  110. package/dist/src/runner_protocol.d.ts +46 -5
  111. package/dist/src/runner_protocol.d.ts.map +1 -1
  112. package/dist/src/runner_protocol.js +24 -5
  113. package/dist/src/runner_protocol.js.map +1 -1
  114. package/dist/src/serialization/beast2/index.d.ts +1 -0
  115. package/dist/src/serialization/beast2/index.d.ts.map +1 -1
  116. package/dist/src/serialization/beast2/index.js +1 -0
  117. package/dist/src/serialization/beast2/index.js.map +1 -1
  118. package/dist/src/serialization/beast2/v5/canonical.d.ts +101 -0
  119. package/dist/src/serialization/beast2/v5/canonical.d.ts.map +1 -0
  120. package/dist/src/serialization/beast2/v5/canonical.js +436 -0
  121. package/dist/src/serialization/beast2/v5/canonical.js.map +1 -0
  122. package/dist/src/serialization/beast2/v5/canonical.spec.d.ts +6 -0
  123. package/dist/src/serialization/beast2/v5/canonical.spec.d.ts.map +1 -0
  124. package/dist/src/serialization/beast2/v5/canonical.spec.js +124 -0
  125. package/dist/src/serialization/beast2/v5/canonical.spec.js.map +1 -0
  126. package/dist/src/serialization/beast2/v5/elements.d.ts +3 -1
  127. package/dist/src/serialization/beast2/v5/elements.d.ts.map +1 -1
  128. package/dist/src/serialization/beast2/v5/elements.js +7 -2
  129. package/dist/src/serialization/beast2/v5/elements.js.map +1 -1
  130. package/dist/src/serialization/beast2/v5/elements.spec.js +1 -1
  131. package/dist/src/serialization/beast2/v5/elements.spec.js.map +1 -1
  132. package/dist/src/serialization/beast2/v5/intake.d.ts +98 -0
  133. package/dist/src/serialization/beast2/v5/intake.d.ts.map +1 -0
  134. package/dist/src/serialization/beast2/v5/intake.js +462 -0
  135. package/dist/src/serialization/beast2/v5/intake.js.map +1 -0
  136. package/dist/src/serialization/beast2/v5/intake.spec.d.ts +6 -0
  137. package/dist/src/serialization/beast2/v5/intake.spec.d.ts.map +1 -0
  138. package/dist/src/serialization/beast2/v5/intake.spec.js +202 -0
  139. package/dist/src/serialization/beast2/v5/intake.spec.js.map +1 -0
  140. package/dist/src/serialization/beast2/v5/runs.d.ts +6 -4
  141. package/dist/src/serialization/beast2/v5/runs.d.ts.map +1 -1
  142. package/dist/src/serialization/beast2/v5/runs.js +31 -5
  143. package/dist/src/serialization/beast2/v5/runs.js.map +1 -1
  144. package/dist/src/serialization/beast2/v5/runs.spec.js +23 -3
  145. package/dist/src/serialization/beast2/v5/runs.spec.js.map +1 -1
  146. package/dist/src/serialization/index.d.ts +1 -1
  147. package/dist/src/serialization/index.d.ts.map +1 -1
  148. package/dist/src/serialization/index.js +1 -1
  149. package/dist/src/serialization/index.js.map +1 -1
  150. package/package.json +1 -1
@@ -50,7 +50,7 @@ export class ArrayExpr extends Expr {
50
50
  * const getSize = East.function([ArrayType(IntegerType)], IntegerType, ($, arr) => {
51
51
  * $.return(arr.size());
52
52
  * });
53
- * const compiled = East.compile(getSize.toIR(), []);
53
+ * const compiled = East.compile(getSize, []);
54
54
  * compiled([1n, 2n, 3n]); // 3n
55
55
  * compiled([]); // 0n
56
56
  * ```
@@ -75,7 +75,7 @@ export class ArrayExpr extends Expr {
75
75
  * const getLength = East.function([ArrayType(IntegerType)], IntegerType, ($, arr) => {
76
76
  * $.return(arr.length());
77
77
  * });
78
- * const compiled = East.compile(getLength.toIR(), []);
78
+ * const compiled = East.compile(getLength, []);
79
79
  * compiled([1n, 2n, 3n]); // 3n
80
80
  * compiled([]); // 0n
81
81
  * ```
@@ -101,7 +101,7 @@ export class ArrayExpr extends Expr {
101
101
  * const hasElement = East.function([ArrayType(IntegerType), IntegerType], BooleanType, ($, arr, index) => {
102
102
  * $.return(arr.has(index));
103
103
  * });
104
- * const compiled = East.compile(hasElement.toIR(), []);
104
+ * const compiled = East.compile(hasElement, []);
105
105
  * compiled([10n, 20n, 30n], 1n); // true
106
106
  * compiled([10n, 20n, 30n], 5n); // false
107
107
  * compiled([10n, 20n, 30n], -1n); // false
@@ -132,7 +132,7 @@ export class ArrayExpr extends Expr {
132
132
  * const getElement = East.function([ArrayType(IntegerType), IntegerType], IntegerType, ($, arr, index) => {
133
133
  * $.return(arr.get(index));
134
134
  * });
135
- * const compiled = East.compile(getElement.toIR(), []);
135
+ * const compiled = East.compile(getElement, []);
136
136
  * compiled([10n, 20n, 30n], 1n); // 20n
137
137
  * // compiled([10n, 20n, 30n], 5n) would throw error
138
138
  *
@@ -140,7 +140,7 @@ export class ArrayExpr extends Expr {
140
140
  * const getOrDefault = East.function([ArrayType(IntegerType), IntegerType], IntegerType, ($, arr, index) => {
141
141
  * $.return(arr.get(index, ($, i) => -1n));
142
142
  * });
143
- * compiled = East.compile(getOrDefault.toIR(), []);
143
+ * compiled = East.compile(getOrDefault, []);
144
144
  * compiled([10n, 20n, 30n], 5n); // -1n (out of bounds)
145
145
  * ```
146
146
  */
@@ -182,7 +182,7 @@ export class ArrayExpr extends Expr {
182
182
  * const getElement = East.function([ArrayType(IntegerType), IntegerType], IntegerType, ($, arr, index) => {
183
183
  * $.return(arr.get(index));
184
184
  * });
185
- * const compiled = East.compile(getElement.toIR(), []);
185
+ * const compiled = East.compile(getElement, []);
186
186
  * compiled([10n, 20n, 30n], 1n); // 20n
187
187
  * // compiled([10n, 20n, 30n], 5n) would throw error
188
188
  *
@@ -190,7 +190,7 @@ export class ArrayExpr extends Expr {
190
190
  * const getOrDefault = East.function([ArrayType(IntegerType), IntegerType], IntegerType, ($, arr, index) => {
191
191
  * $.return(arr.get(index, ($, i) => -1n));
192
192
  * });
193
- * compiled = East.compile(getOrDefault.toIR(), []);
193
+ * compiled = East.compile(getOrDefault, []);
194
194
  * compiled([10n, 20n, 30n], 5n); // -1n (out of bounds)
195
195
  * ```
196
196
  */
@@ -229,7 +229,7 @@ export class ArrayExpr extends Expr {
229
229
  * const tryGetElement = East.function([ArrayType(IntegerType), IntegerType], OptionType(IntegerType), ($, arr, index) => {
230
230
  * $.return(arr.tryGet(index));
231
231
  * });
232
- * const compiled = East.compile(tryGetElement.toIR(), []);
232
+ * const compiled = East.compile(tryGetElement, []);
233
233
  * compiled([10n, 20n, 30n], 1n); // {_tag: "some", some: 20n}
234
234
  * compiled([10n, 20n, 30n], 5n); // {_tag: "none", none: null}
235
235
  * ```
@@ -260,7 +260,7 @@ export class ArrayExpr extends Expr {
260
260
  * $(arr.update(index, value)); // Mutate the array
261
261
  * $.return(arr);
262
262
  * });
263
- * const compiled = East.compile(updateElement.toIR(), []);
263
+ * const compiled = East.compile(updateElement, []);
264
264
  * compiled([10n, 20n, 30n], 1n, 99n); // [10n, 99n, 30n]
265
265
  * ```
266
266
  */
@@ -308,7 +308,7 @@ export class ArrayExpr extends Expr {
308
308
  * $(arr.pushLast(value)); // Mutate the array
309
309
  * $.return(arr);
310
310
  * });
311
- * const compiled = East.compile(appendValue.toIR(), []);
311
+ * const compiled = East.compile(appendValue, []);
312
312
  * compiled([1n, 2n, 3n], 4n); // [1n, 2n, 3n, 4n]
313
313
  * ```
314
314
  */
@@ -335,7 +335,7 @@ export class ArrayExpr extends Expr {
335
335
  * const removeLastValue = East.function([ArrayType(IntegerType)], IntegerType, ($, arr) => {
336
336
  * $.return(arr.popLast());
337
337
  * });
338
- * const compiled = East.compile(removeLastValue.toIR(), []);
338
+ * const compiled = East.compile(removeLastValue, []);
339
339
  * compiled([1n, 2n, 3n]); // 3n (arr is now [1n, 2n])
340
340
  * ```
341
341
  */
@@ -361,7 +361,7 @@ export class ArrayExpr extends Expr {
361
361
  * $(arr.pushFirst(value)); // Mutate the array
362
362
  * $.return(arr);
363
363
  * });
364
- * const compiled = East.compile(prependValue.toIR(), []);
364
+ * const compiled = East.compile(prependValue, []);
365
365
  * compiled([1n, 2n, 3n], 0n); // [0n, 1n, 2n, 3n]
366
366
  * ```
367
367
  */
@@ -388,7 +388,7 @@ export class ArrayExpr extends Expr {
388
388
  * const removeFirstValue = East.function([ArrayType(IntegerType)], IntegerType, ($, arr) => {
389
389
  * $.return(arr.popFirst());
390
390
  * });
391
- * const compiled = East.compile(removeFirstValue.toIR(), []);
391
+ * const compiled = East.compile(removeFirstValue, []);
392
392
  * compiled([1n, 2n, 3n]); // 1n (arr is now [2n, 3n])
393
393
  * ```
394
394
  */
@@ -414,7 +414,7 @@ export class ArrayExpr extends Expr {
414
414
  * $(arr1.append(arr2)); // Mutate arr1
415
415
  * $.return(arr1);
416
416
  * });
417
- * const compiled = East.compile(appendArray.toIR(), []);
417
+ * const compiled = East.compile(appendArray, []);
418
418
  * compiled([1n, 2n], [3n, 4n]); // [1n, 2n, 3n, 4n]
419
419
  * ```
420
420
  */
@@ -441,7 +441,7 @@ export class ArrayExpr extends Expr {
441
441
  * $(arr1.prepend(arr2)); // Mutate arr1
442
442
  * $.return(arr1);
443
443
  * });
444
- * const compiled = East.compile(prependArray.toIR(), []);
444
+ * const compiled = East.compile(prependArray, []);
445
445
  * compiled([3n, 4n], [1n, 2n]); // [1n, 2n, 3n, 4n]
446
446
  * ```
447
447
  */
@@ -472,7 +472,7 @@ export class ArrayExpr extends Expr {
472
472
  * arr1.mergeAll(arr2, ($, current, other, index) => current.add(other));
473
473
  * $.return(null);
474
474
  * });
475
- * const compiled = East.compile(mergeArrays.toIR(), []);
475
+ * const compiled = East.compile(mergeArrays, []);
476
476
  * const arr1 = [10n, 20n, 30n];
477
477
  * const arr2 = [1n, 2n, 3n];
478
478
  * compiled(arr1, arr2); // null (arr1 is now [11n, 22n, 33n])
@@ -485,7 +485,7 @@ export class ArrayExpr extends Expr {
485
485
  * arr1.mergeAll(arr2, ($, current, other, index) => current.concat(" + ").concat(other));
486
486
  * $.return(arr1);
487
487
  * });
488
- * const compiled = East.compile(mergeStrings.toIR(), []);
488
+ * const compiled = East.compile(mergeStrings, []);
489
489
  * compiled(["a", "b"], ["x", "y"]); // ["a + x", "b + y"]
490
490
  * ```
491
491
  */
@@ -516,7 +516,7 @@ export class ArrayExpr extends Expr {
516
516
  * arr.clear();
517
517
  * $.return(arr);
518
518
  * });
519
- * const compiled = East.compile(clearArray.toIR(), []);
519
+ * const compiled = East.compile(clearArray, []);
520
520
  * compiled([1n, 2n, 3n]); // []
521
521
  * ```
522
522
  */
@@ -545,7 +545,7 @@ export class ArrayExpr extends Expr {
545
545
  * arr.sortInPlace();
546
546
  * $.return(arr);
547
547
  * });
548
- * const compiled = East.compile(sortNumbers.toIR(), []);
548
+ * const compiled = East.compile(sortNumbers, []);
549
549
  * compiled([3n, 1n, 4n, 1n, 5n]); // [1n, 1n, 3n, 4n, 5n]
550
550
  * ```
551
551
  *
@@ -557,7 +557,7 @@ export class ArrayExpr extends Expr {
557
557
  * people.sortInPlace(($, p) => p.age);
558
558
  * $.return(people);
559
559
  * });
560
- * const compiled = East.compile(sortByAge.toIR(), []);
560
+ * const compiled = East.compile(sortByAge, []);
561
561
  * compiled([{ name: "Alice", age: 30n }, { name: "Bob", age: 25n }]);
562
562
  * // [{ name: "Bob", age: 25n }, { name: "Alice", age: 30n }]
563
563
  * ```
@@ -601,7 +601,7 @@ export class ArrayExpr extends Expr {
601
601
  * const sortNumbers = East.function([ArrayType(IntegerType)], ArrayType(IntegerType), ($, arr) => {
602
602
  * $.return(arr.sort());
603
603
  * });
604
- * const compiled = East.compile(sortNumbers.toIR(), []);
604
+ * const compiled = East.compile(sortNumbers, []);
605
605
  * compiled([3n, 1n, 4n, 1n, 5n]); // [1n, 1n, 3n, 4n, 5n]
606
606
  * ```
607
607
  *
@@ -612,7 +612,7 @@ export class ArrayExpr extends Expr {
612
612
  * const sortByAgeDesc = East.function([ArrayType(PersonType)], ArrayType(PersonType), ($, people) => {
613
613
  * $.return(people.sort(($, p) => p.age.negate()));
614
614
  * });
615
- * const compiled = East.compile(sortByAgeDesc.toIR(), []);
615
+ * const compiled = East.compile(sortByAgeDesc, []);
616
616
  * compiled([{ name: "Alice", age: 30n }, { name: "Bob", age: 25n }]);
617
617
  * // [{ name: "Alice", age: 30n }, { name: "Bob", age: 25n }]
618
618
  * ```
@@ -652,7 +652,7 @@ export class ArrayExpr extends Expr {
652
652
  * arr.reverseInPlace();
653
653
  * $.return(arr);
654
654
  * });
655
- * const compiled = East.compile(reverseArray.toIR(), []);
655
+ * const compiled = East.compile(reverseArray, []);
656
656
  * compiled([1n, 2n, 3n, 4n, 5n]); // [5n, 4n, 3n, 2n, 1n]
657
657
  * ```
658
658
  *
@@ -681,7 +681,7 @@ export class ArrayExpr extends Expr {
681
681
  * const reverseArray = East.function([ArrayType(StringType)], ArrayType(StringType), ($, arr) => {
682
682
  * $.return(arr.reverse());
683
683
  * });
684
- * const compiled = East.compile(reverseArray.toIR(), []);
684
+ * const compiled = East.compile(reverseArray, []);
685
685
  * compiled(["a", "b", "c"]); // ["c", "b", "a"]
686
686
  * ```
687
687
  *
@@ -708,7 +708,7 @@ export class ArrayExpr extends Expr {
708
708
  * const checkSorted = East.function([ArrayType(IntegerType)], BooleanType, ($, arr) => {
709
709
  * $.return(arr.isSorted());
710
710
  * });
711
- * const compiled = East.compile(checkSorted.toIR(), []);
711
+ * const compiled = East.compile(checkSorted, []);
712
712
  * compiled([1n, 2n, 3n, 4n]); // true
713
713
  * compiled([1n, 3n, 2n, 4n]); // false
714
714
  * ```
@@ -720,7 +720,7 @@ export class ArrayExpr extends Expr {
720
720
  * const checkSortedByAge = East.function([ArrayType(PersonType)], BooleanType, ($, people) => {
721
721
  * $.return(people.isSorted(($, p) => p.age));
722
722
  * });
723
- * const compiled = East.compile(checkSortedByAge.toIR(), []);
723
+ * const compiled = East.compile(checkSortedByAge, []);
724
724
  * compiled([{ name: "Bob", age: 25n }, { name: "Alice", age: 30n }]); // true
725
725
  * ```
726
726
  */
@@ -762,7 +762,7 @@ export class ArrayExpr extends Expr {
762
762
  * const findFirst = East.function([ArrayType(IntegerType), IntegerType], IntegerType, ($, arr, value) => {
763
763
  * $.return(arr.findSortedFirst(value));
764
764
  * });
765
- * const compiled = East.compile(findFirst.toIR(), []);
765
+ * const compiled = East.compile(findFirst, []);
766
766
  * compiled([1n, 3n, 5n, 7n, 9n], 5n); // 2n (index of 5)
767
767
  * compiled([1n, 3n, 5n, 7n, 9n], 4n); // 2n (index where 4 would be inserted)
768
768
  * compiled([1n, 3n, 5n, 7n, 9n], 10n); // 5n (out of bounds)
@@ -775,7 +775,7 @@ export class ArrayExpr extends Expr {
775
775
  * const findByAge = East.function([ArrayType(PersonType), IntegerType], IntegerType, ($, people, age) => {
776
776
  * $.return(people.findSortedFirst(age, ($, p) => p.age));
777
777
  * });
778
- * const compiled = East.compile(findByAge.toIR(), []);
778
+ * const compiled = East.compile(findByAge, []);
779
779
  * // Assumes people array is sorted by age
780
780
  * compiled([{ name: "Bob", age: 25n }, { name: "Alice", age: 30n }], 28n); // 1n
781
781
  * ```
@@ -819,7 +819,7 @@ export class ArrayExpr extends Expr {
819
819
  * const findLast = East.function([ArrayType(IntegerType), IntegerType], IntegerType, ($, arr, value) => {
820
820
  * $.return(arr.findSortedLast(value));
821
821
  * });
822
- * const compiled = East.compile(findLast.toIR(), []);
822
+ * const compiled = East.compile(findLast, []);
823
823
  * compiled([1n, 3n, 5n, 7n, 9n], 5n); // 2n (index of 5)
824
824
  * compiled([1n, 3n, 5n, 7n, 9n], 6n); // 2n (index of last element <= 6)
825
825
  * compiled([1n, 3n, 5n, 7n, 9n], 0n); // -1n (all elements are greater)
@@ -864,7 +864,7 @@ export class ArrayExpr extends Expr {
864
864
  * const findRange = East.function([ArrayType(IntegerType), IntegerType], StructType({ start: IntegerType, end: IntegerType }), ($, arr, value) => {
865
865
  * $.return(arr.findSortedRange(value));
866
866
  * });
867
- * const compiled = East.compile(findRange.toIR(), []);
867
+ * const compiled = East.compile(findRange, []);
868
868
  * compiled([1n, 3n, 5n, 5n, 5n, 7n, 9n], 5n); // { start: 2n, end: 5n }
869
869
  * compiled([1n, 3n, 5n, 7n, 9n], 4n); // { start: 2n, end: 2n } (not found)
870
870
  * ```
@@ -907,7 +907,7 @@ export class ArrayExpr extends Expr {
907
907
  * const sliceArray = East.function([ArrayType(IntegerType), IntegerType, IntegerType], ArrayType(IntegerType), ($, arr, start, end) => {
908
908
  * $.return(arr.slice(start, end));
909
909
  * });
910
- * const compiled = East.compile(sliceArray.toIR(), []);
910
+ * const compiled = East.compile(sliceArray, []);
911
911
  * compiled([10n, 20n, 30n, 40n, 50n], 1n, 4n); // [20n, 30n, 40n]
912
912
  * compiled([10n, 20n, 30n, 40n, 50n], 0n, 2n); // [10n, 20n]
913
913
  * ```
@@ -938,7 +938,7 @@ export class ArrayExpr extends Expr {
938
938
  * const concatArrays = East.function([ArrayType(IntegerType), ArrayType(IntegerType)], ArrayType(IntegerType), ($, arr1, arr2) => {
939
939
  * $.return(arr1.concat(arr2));
940
940
  * });
941
- * const compiled = East.compile(concatArrays.toIR(), []);
941
+ * const compiled = East.compile(concatArrays, []);
942
942
  * compiled([1n, 2n, 3n], [4n, 5n]); // [1n, 2n, 3n, 4n, 5n]
943
943
  * ```
944
944
  */
@@ -967,7 +967,7 @@ export class ArrayExpr extends Expr {
967
967
  * const getMultiple = East.function([ArrayType(StringType), ArrayType(IntegerType)], ArrayType(StringType), ($, arr, indices) => {
968
968
  * $.return(arr.getKeys(indices));
969
969
  * });
970
- * const compiled = East.compile(getMultiple.toIR(), []);
970
+ * const compiled = East.compile(getMultiple, []);
971
971
  * compiled(["a", "b", "c", "d"], [0n, 2n, 3n]); // ["a", "c", "d"]
972
972
  * ```
973
973
  *
@@ -977,7 +977,7 @@ export class ArrayExpr extends Expr {
977
977
  * const getWithDefault = East.function([ArrayType(IntegerType), ArrayType(IntegerType)], ArrayType(IntegerType), ($, arr, indices) => {
978
978
  * $.return(arr.getKeys(indices, ($, key) => -1n));
979
979
  * });
980
- * const compiled = East.compile(getWithDefault.toIR(), []);
980
+ * const compiled = East.compile(getWithDefault, []);
981
981
  * compiled([10n, 20n, 30n], [1n, 5n, 2n]); // [20n, -1n, 30n]
982
982
  * ```
983
983
  */
@@ -1017,7 +1017,7 @@ export class ArrayExpr extends Expr {
1017
1017
  * });
1018
1018
  * $.return(null);
1019
1019
  * });
1020
- * const compiled = East.compile(forEachExample.toIR(), [log.implement(console.log)]);
1020
+ * const compiled = East.compile(forEachExample, [log.implement(console.log)]);
1021
1021
  * compiled([10n, 20n, 30n]);
1022
1022
  * // Logs: "Index 0: 10", "Index 1: 20", "Index 2: 30"
1023
1023
  * ```
@@ -1052,7 +1052,7 @@ export class ArrayExpr extends Expr {
1052
1052
  * copy.pushLast(99n);
1053
1053
  * $.return(copy);
1054
1054
  * });
1055
- * const compiled = East.compile(copyArray.toIR(), []);
1055
+ * const compiled = East.compile(copyArray, []);
1056
1056
  * const original = [1n, 2n, 3n];
1057
1057
  * compiled(original); // [1n, 2n, 3n, 99n]
1058
1058
  * // original is unchanged: [1n, 2n, 3n]
@@ -1116,7 +1116,7 @@ export class ArrayExpr extends Expr {
1116
1116
  * const filterEven = East.function([ArrayType(IntegerType)], ArrayType(IntegerType), ($, arr) => {
1117
1117
  * $.return(arr.filter(($, x, i) => x.modulo(2n).equal(0n)));
1118
1118
  * });
1119
- * const compiled = East.compile(filterEven.toIR(), []);
1119
+ * const compiled = East.compile(filterEven, []);
1120
1120
  * compiled([1n, 2n, 3n, 4n, 5n, 6n]); // [2n, 4n, 6n]
1121
1121
  * ```
1122
1122
  *
@@ -1126,7 +1126,7 @@ export class ArrayExpr extends Expr {
1126
1126
  * const filterFirstThree = East.function([ArrayType(StringType)], ArrayType(StringType), ($, arr) => {
1127
1127
  * $.return(arr.filter(($, elem, index) => index.lessThan(3n)));
1128
1128
  * });
1129
- * const compiled = East.compile(filterFirstThree.toIR(), []);
1129
+ * const compiled = East.compile(filterFirstThree, []);
1130
1130
  * compiled(["a", "b", "c", "d", "e"]); // ["a", "b", "c"]
1131
1131
  * ```
1132
1132
  *
@@ -1137,7 +1137,7 @@ export class ArrayExpr extends Expr {
1137
1137
  * const filterAdults = East.function([ArrayType(PersonType)], ArrayType(PersonType), ($, people) => {
1138
1138
  * $.return(people.filter(($, p, i) => p.age.greaterOrEqual(18n)));
1139
1139
  * });
1140
- * const compiled = East.compile(filterAdults.toIR(), []);
1140
+ * const compiled = East.compile(filterAdults, []);
1141
1141
  * compiled([{ name: "Alice", age: 30n }, { name: "Bob", age: 15n }]); // [{ name: "Alice", age: 30n }]
1142
1142
  * ```
1143
1143
  */
@@ -1263,7 +1263,7 @@ export class ArrayExpr extends Expr {
1263
1263
  * const sumArray = East.function([ArrayType(IntegerType)], IntegerType, ($, arr) => {
1264
1264
  * $.return(arr.reduce(($, acc, val, index) => acc.add(val), 0n));
1265
1265
  * });
1266
- * const compiled = East.compile(sumArray.toIR(), []);
1266
+ * const compiled = East.compile(sumArray, []);
1267
1267
  * compiled([1n, 2n, 3n, 4n]); // 10n
1268
1268
  * compiled([]); // 0n (initial value)
1269
1269
  * ```
@@ -1276,7 +1276,7 @@ export class ArrayExpr extends Expr {
1276
1276
  * $.if(index.equal(0n), () => val, () => acc.concat(", ").concat(val))
1277
1277
  * , ""));
1278
1278
  * });
1279
- * const compiled = East.compile(joinArray.toIR(), []);
1279
+ * const compiled = East.compile(joinArray, []);
1280
1280
  * compiled(["a", "b", "c"]); // "a, b, c"
1281
1281
  * ```
1282
1282
  *
@@ -1319,7 +1319,7 @@ export class ArrayExpr extends Expr {
1319
1319
  * const runningTotal = East.function([ArrayType(IntegerType)], ArrayType(IntegerType), ($, arr) => {
1320
1320
  * $.return(arr.scan(($, acc, x, i) => acc.add(x), 0n));
1321
1321
  * });
1322
- * const compiled = East.compile(runningTotal.toIR(), []);
1322
+ * const compiled = East.compile(runningTotal, []);
1323
1323
  * compiled([1n, 2n, 3n, 4n]); // [1n, 3n, 6n, 10n]
1324
1324
  * compiled([]); // []
1325
1325
  * ```
@@ -1330,7 +1330,7 @@ export class ArrayExpr extends Expr {
1330
1330
  * const forwardFill = East.function([ArrayType(StringType)], ArrayType(StringType), ($, cells) => {
1331
1331
  * $.return(cells.scan(($, acc, cell, i) => cell.equal("").ifElse(() => acc, () => cell), ""));
1332
1332
  * });
1333
- * const compiled = East.compile(forwardFill.toIR(), []);
1333
+ * const compiled = East.compile(forwardFill, []);
1334
1334
  * compiled(["a", "", "", "b", ""]); // ["a", "a", "a", "b", "b"]
1335
1335
  * ```
1336
1336
  *
@@ -1377,7 +1377,7 @@ export class ArrayExpr extends Expr {
1377
1377
  * const allPositive = East.function([ArrayType(IntegerType)], BooleanType, ($, arr) => {
1378
1378
  * $.return(arr.every(($, x, i) => x.greater(0n)));
1379
1379
  * });
1380
- * const compiled = East.compile(allPositive.toIR(), []);
1380
+ * const compiled = East.compile(allPositive, []);
1381
1381
  * compiled([1n, 2n, 3n]); // true
1382
1382
  * compiled([1n, -2n, 3n]); // false
1383
1383
  * compiled([]); // true (empty array)
@@ -1390,7 +1390,7 @@ export class ArrayExpr extends Expr {
1390
1390
  * const allAdults = East.function([ArrayType(PersonType)], BooleanType, ($, people) => {
1391
1391
  * $.return(people.every(($, p, i) => p.age.greaterOrEqual(18n)));
1392
1392
  * });
1393
- * const compiled = East.compile(allAdults.toIR(), []);
1393
+ * const compiled = East.compile(allAdults, []);
1394
1394
  * compiled([{ name: "Alice", age: 30n }, { name: "Bob", age: 25n }]); // true
1395
1395
  * ```
1396
1396
  *
@@ -1427,7 +1427,7 @@ export class ArrayExpr extends Expr {
1427
1427
  * const hasNegative = East.function([ArrayType(IntegerType)], BooleanType, ($, arr) => {
1428
1428
  * $.return(arr.some(($, x, i) => x.less(0n)));
1429
1429
  * });
1430
- * const compiled = East.compile(hasNegative.toIR(), []);
1430
+ * const compiled = East.compile(hasNegative, []);
1431
1431
  * compiled([1n, 2n, 3n]); // false
1432
1432
  * compiled([1n, -2n, 3n]); // true
1433
1433
  * compiled([]); // false (empty array)
@@ -1440,7 +1440,7 @@ export class ArrayExpr extends Expr {
1440
1440
  * const hasMinor = East.function([ArrayType(PersonType)], BooleanType, ($, people) => {
1441
1441
  * $.return(people.some(($, p, i) => p.age.less(18n)));
1442
1442
  * });
1443
- * const compiled = East.compile(hasMinor.toIR(), []);
1443
+ * const compiled = East.compile(hasMinor, []);
1444
1444
  * compiled([{ name: "Alice", age: 30n }, { name: "Bob", age: 15n }]); // true
1445
1445
  * ```
1446
1446
  *
@@ -1632,7 +1632,7 @@ export class ArrayExpr extends Expr {
1632
1632
  * const joinStrings = East.function([ArrayType(StringType), StringType], StringType, ($, arr, delimiter) => {
1633
1633
  * $.return(arr.stringJoin(delimiter));
1634
1634
  * });
1635
- * const compiled = East.compile(joinStrings.toIR(), []);
1635
+ * const compiled = East.compile(joinStrings, []);
1636
1636
  * compiled(["a", "b", "c"], ", "); // "a, b, c"
1637
1637
  * compiled(["hello", "world"], " "); // "hello world"
1638
1638
  * compiled([], ", "); // ""
@@ -1745,6 +1745,23 @@ export class ArrayExpr extends Expr {
1745
1745
  arguments: [this[AstSymbol], fnAst, onConflictAst],
1746
1746
  });
1747
1747
  }
1748
+ toTree(node, keyFn, parentFn, buildFn) {
1749
+ const keyFnAst = valueOrExprToAstTyped(keyFn, FunctionType([this.value_type, IntegerType], undefined));
1750
+ const keyType = keyFnAst.type.output;
1751
+ if (!isDataType(keyType)) {
1752
+ throw new Error(`Can only key a tree by data types, got ${printType(keyType)}`);
1753
+ }
1754
+ const parentFnAst = valueOrExprToAstTyped(parentFn, FunctionType([this.value_type, IntegerType], OptionType(keyType)));
1755
+ const buildFnAst = valueOrExprToAstTyped(buildFn, FunctionType([this.value_type, IntegerType, ArrayType(node)], node));
1756
+ return this[FactorySymbol]({
1757
+ ast_type: "Builtin",
1758
+ type: ArrayType(node),
1759
+ loc_id: get_location_id(),
1760
+ builtin: "ArrayToTree",
1761
+ type_parameters: [this.value_type, keyType, node],
1762
+ arguments: [this[AstSymbol], keyFnAst, parentFnAst, buildFnAst],
1763
+ });
1764
+ }
1748
1765
  groupReduce(keyFn, initFn, reduceFn) {
1749
1766
  // Note - initFn has to be before reduceFn, otherwise the TypeScript type inference doesn't work properly
1750
1767
  const keyFnAst = valueOrExprToAstTyped(keyFn, FunctionType([this.value_type, IntegerType], undefined));
@@ -1947,7 +1964,7 @@ export class ArrayExpr extends Expr {
1947
1964
  * const toCsv = East.function([ArrayType(PersonType)], BlobType, ($, people) => {
1948
1965
  * $.return(people.encodeCsv({ delimiter: ',' }));
1949
1966
  * });
1950
- * const compiled = East.compile(toCsv.toIR(), []);
1967
+ * const compiled = East.compile(toCsv, []);
1951
1968
  * const blob = compiled([{ name: "Alice", age: 30n }, { name: "Bob", age: 25n }]);
1952
1969
  * new TextDecoder().decode(blob); // "name,age\r\nAlice,30\r\nBob,25"
1953
1970
  * ```
@@ -1976,7 +1993,7 @@ export class ArrayExpr extends Expr {
1976
1993
  * const isEqual = East.function([ArrayType(IntegerType), ArrayType(IntegerType)], BooleanType, ($, a, b) => {
1977
1994
  * $.return(a.equals(b));
1978
1995
  * });
1979
- * const compiled = East.compile(isEqual.toIR(), []);
1996
+ * const compiled = East.compile(isEqual, []);
1980
1997
  * compiled([1n, 2n, 3n], [1n, 2n, 3n]); // true
1981
1998
  * compiled([1n, 2n], [1n, 2n, 3n]); // false
1982
1999
  * ```
@@ -1995,7 +2012,7 @@ export class ArrayExpr extends Expr {
1995
2012
  * const isNotEqual = East.function([ArrayType(IntegerType), ArrayType(IntegerType)], BooleanType, ($, a, b) => {
1996
2013
  * $.return(a.notEquals(b));
1997
2014
  * });
1998
- * const compiled = East.compile(isNotEqual.toIR(), []);
2015
+ * const compiled = East.compile(isNotEqual, []);
1999
2016
  * compiled([1n, 2n], [1n, 2n, 3n]); // true
2000
2017
  * compiled([1n, 2n, 3n], [1n, 2n, 3n]); // false
2001
2018
  * ```