@elaraai/east 0.0.1-beta.3 → 0.0.1-beta.31

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 (191) hide show
  1. package/LICENSE.md +15 -666
  2. package/README.md +30 -8
  3. package/dist/src/analyze.d.ts +3 -0
  4. package/dist/src/analyze.d.ts.map +1 -1
  5. package/dist/src/analyze.js +76 -15
  6. package/dist/src/analyze.js.map +1 -1
  7. package/dist/src/ast.d.ts +37 -33
  8. package/dist/src/ast.d.ts.map +1 -1
  9. package/dist/src/ast_to_ir.d.ts +6 -0
  10. package/dist/src/ast_to_ir.d.ts.map +1 -1
  11. package/dist/src/ast_to_ir.js +135 -101
  12. package/dist/src/ast_to_ir.js.map +1 -1
  13. package/dist/src/builtins.d.ts +1 -1
  14. package/dist/src/builtins.d.ts.map +1 -1
  15. package/dist/src/builtins.js +32 -0
  16. package/dist/src/builtins.js.map +1 -1
  17. package/dist/src/comparison.d.ts.map +1 -1
  18. package/dist/src/comparison.js +12 -4
  19. package/dist/src/comparison.js.map +1 -1
  20. package/dist/src/compile.d.ts +26 -1
  21. package/dist/src/compile.d.ts.map +1 -1
  22. package/dist/src/compile.js +388 -257
  23. package/dist/src/compile.js.map +1 -1
  24. package/dist/src/datetime_format/types.d.ts +23 -23
  25. package/dist/src/eastir.d.ts +4 -0
  26. package/dist/src/eastir.d.ts.map +1 -1
  27. package/dist/src/eastir.js +27 -7
  28. package/dist/src/eastir.js.map +1 -1
  29. package/dist/src/error.d.ts +12 -1
  30. package/dist/src/error.d.ts.map +1 -1
  31. package/dist/src/error.js +31 -1
  32. package/dist/src/error.js.map +1 -1
  33. package/dist/src/expr/array.d.ts +109 -1
  34. package/dist/src/expr/array.d.ts.map +1 -1
  35. package/dist/src/expr/array.js +204 -44
  36. package/dist/src/expr/array.js.map +1 -1
  37. package/dist/src/expr/ast.d.ts +1 -1
  38. package/dist/src/expr/ast.d.ts.map +1 -1
  39. package/dist/src/expr/ast.js +16 -28
  40. package/dist/src/expr/ast.js.map +1 -1
  41. package/dist/src/expr/asyncfunction.js +1 -1
  42. package/dist/src/expr/asyncfunction.js.map +1 -1
  43. package/dist/src/expr/blob.d.ts +73 -1
  44. package/dist/src/expr/blob.d.ts.map +1 -1
  45. package/dist/src/expr/blob.js +97 -7
  46. package/dist/src/expr/blob.js.map +1 -1
  47. package/dist/src/expr/block.d.ts +232 -12
  48. package/dist/src/expr/block.d.ts.map +1 -1
  49. package/dist/src/expr/block.js +646 -140
  50. package/dist/src/expr/block.js.map +1 -1
  51. package/dist/src/expr/boolean.d.ts +44 -0
  52. package/dist/src/expr/boolean.d.ts.map +1 -1
  53. package/dist/src/expr/boolean.js +57 -5
  54. package/dist/src/expr/boolean.js.map +1 -1
  55. package/dist/src/expr/datetime.d.ts +135 -0
  56. package/dist/src/expr/datetime.d.ts.map +1 -1
  57. package/dist/src/expr/datetime.js +183 -33
  58. package/dist/src/expr/datetime.js.map +1 -1
  59. package/dist/src/expr/dict.d.ts +42 -0
  60. package/dist/src/expr/dict.d.ts.map +1 -1
  61. package/dist/src/expr/dict.js +105 -55
  62. package/dist/src/expr/dict.js.map +1 -1
  63. package/dist/src/expr/expr.d.ts +1 -1
  64. package/dist/src/expr/expr.d.ts.map +1 -1
  65. package/dist/src/expr/expr.js.map +1 -1
  66. package/dist/src/expr/float.d.ts +153 -0
  67. package/dist/src/expr/float.d.ts.map +1 -1
  68. package/dist/src/expr/float.js +190 -16
  69. package/dist/src/expr/float.js.map +1 -1
  70. package/dist/src/expr/function.d.ts +7 -2
  71. package/dist/src/expr/function.d.ts.map +1 -1
  72. package/dist/src/expr/function.js +1 -1
  73. package/dist/src/expr/function.js.map +1 -1
  74. package/dist/src/expr/index.d.ts +202 -2
  75. package/dist/src/expr/index.d.ts.map +1 -1
  76. package/dist/src/expr/index.js +207 -2
  77. package/dist/src/expr/index.js.map +1 -1
  78. package/dist/src/expr/integer.d.ts +180 -0
  79. package/dist/src/expr/integer.d.ts.map +1 -1
  80. package/dist/src/expr/integer.js +188 -17
  81. package/dist/src/expr/integer.js.map +1 -1
  82. package/dist/src/expr/libs/blob.js +2 -2
  83. package/dist/src/expr/libs/blob.js.map +1 -1
  84. package/dist/src/expr/libs/integer.d.ts +19 -0
  85. package/dist/src/expr/libs/integer.d.ts.map +1 -1
  86. package/dist/src/expr/libs/integer.js +47 -0
  87. package/dist/src/expr/libs/integer.js.map +1 -1
  88. package/dist/src/expr/libs/string.js +1 -1
  89. package/dist/src/expr/libs/string.js.map +1 -1
  90. package/dist/src/expr/recursive.d.ts +83 -0
  91. package/dist/src/expr/recursive.d.ts.map +1 -0
  92. package/dist/src/expr/recursive.js +99 -0
  93. package/dist/src/expr/recursive.js.map +1 -0
  94. package/dist/src/expr/ref.js +3 -3
  95. package/dist/src/expr/ref.js.map +1 -1
  96. package/dist/src/expr/set.d.ts +44 -2
  97. package/dist/src/expr/set.d.ts.map +1 -1
  98. package/dist/src/expr/set.js +97 -47
  99. package/dist/src/expr/set.js.map +1 -1
  100. package/dist/src/expr/string.d.ts +134 -0
  101. package/dist/src/expr/string.d.ts.map +1 -1
  102. package/dist/src/expr/string.js +172 -22
  103. package/dist/src/expr/string.js.map +1 -1
  104. package/dist/src/expr/struct.d.ts +1 -1
  105. package/dist/src/expr/struct.d.ts.map +1 -1
  106. package/dist/src/expr/struct.js +1 -1
  107. package/dist/src/expr/struct.js.map +1 -1
  108. package/dist/src/expr/types.d.ts +7 -6
  109. package/dist/src/expr/types.d.ts.map +1 -1
  110. package/dist/src/expr/variant.d.ts +123 -1
  111. package/dist/src/expr/variant.d.ts.map +1 -1
  112. package/dist/src/expr/variant.js +66 -2
  113. package/dist/src/expr/variant.js.map +1 -1
  114. package/dist/src/fuzz.d.ts +36 -2
  115. package/dist/src/fuzz.d.ts.map +1 -1
  116. package/dist/src/fuzz.js +344 -77
  117. package/dist/src/fuzz.js.map +1 -1
  118. package/dist/src/index.d.ts +1 -0
  119. package/dist/src/index.d.ts.map +1 -1
  120. package/dist/src/index.js +1 -0
  121. package/dist/src/index.js.map +1 -1
  122. package/dist/src/internal.d.ts +12 -0
  123. package/dist/src/internal.d.ts.map +1 -1
  124. package/dist/src/internal.js +13 -0
  125. package/dist/src/internal.js.map +1 -1
  126. package/dist/src/ir.d.ts +1551 -1505
  127. package/dist/src/ir.d.ts.map +1 -1
  128. package/dist/src/ir.js +49 -34
  129. package/dist/src/ir.js.map +1 -1
  130. package/dist/src/location.d.ts +30 -10
  131. package/dist/src/location.d.ts.map +1 -1
  132. package/dist/src/location.js +70 -28
  133. package/dist/src/location.js.map +1 -1
  134. package/dist/src/patch/apply.d.ts +15 -0
  135. package/dist/src/patch/apply.d.ts.map +1 -0
  136. package/dist/src/patch/apply.js +380 -0
  137. package/dist/src/patch/apply.js.map +1 -0
  138. package/dist/src/patch/compose.d.ts +15 -0
  139. package/dist/src/patch/compose.d.ts.map +1 -0
  140. package/dist/src/patch/compose.js +480 -0
  141. package/dist/src/patch/compose.js.map +1 -0
  142. package/dist/src/patch/diff.d.ts +15 -0
  143. package/dist/src/patch/diff.d.ts.map +1 -0
  144. package/dist/src/patch/diff.js +328 -0
  145. package/dist/src/patch/diff.js.map +1 -0
  146. package/dist/src/patch/fuzz.d.ts +73 -0
  147. package/dist/src/patch/fuzz.d.ts.map +1 -0
  148. package/dist/src/patch/fuzz.js +159 -0
  149. package/dist/src/patch/fuzz.js.map +1 -0
  150. package/dist/src/patch/index.d.ts +18 -0
  151. package/dist/src/patch/index.d.ts.map +1 -0
  152. package/dist/src/patch/index.js +20 -0
  153. package/dist/src/patch/index.js.map +1 -0
  154. package/dist/src/patch/invert.d.ts +15 -0
  155. package/dist/src/patch/invert.d.ts.map +1 -0
  156. package/dist/src/patch/invert.js +302 -0
  157. package/dist/src/patch/invert.js.map +1 -0
  158. package/dist/src/patch/type_of_patch.d.ts +17 -0
  159. package/dist/src/patch/type_of_patch.d.ts.map +1 -0
  160. package/dist/src/patch/type_of_patch.js +143 -0
  161. package/dist/src/patch/type_of_patch.js.map +1 -0
  162. package/dist/src/patch/types.d.ts +166 -0
  163. package/dist/src/patch/types.d.ts.map +1 -0
  164. package/dist/src/patch/types.js +69 -0
  165. package/dist/src/patch/types.js.map +1 -0
  166. package/dist/src/platform.d.ts +6 -0
  167. package/dist/src/platform.d.ts.map +1 -1
  168. package/dist/src/serialization/beast.d.ts.map +1 -1
  169. package/dist/src/serialization/beast.js +53 -18
  170. package/dist/src/serialization/beast.js.map +1 -1
  171. package/dist/src/serialization/beast2.d.ts +39 -3
  172. package/dist/src/serialization/beast2.d.ts.map +1 -1
  173. package/dist/src/serialization/beast2.js +241 -18
  174. package/dist/src/serialization/beast2.js.map +1 -1
  175. package/dist/src/serialization/csv.d.ts +139 -0
  176. package/dist/src/serialization/csv.d.ts.map +1 -0
  177. package/dist/src/serialization/csv.js +615 -0
  178. package/dist/src/serialization/csv.js.map +1 -0
  179. package/dist/src/serialization/index.d.ts +2 -1
  180. package/dist/src/serialization/index.d.ts.map +1 -1
  181. package/dist/src/serialization/index.js +2 -1
  182. package/dist/src/serialization/index.js.map +1 -1
  183. package/dist/src/type_of_type.d.ts +45 -34
  184. package/dist/src/type_of_type.d.ts.map +1 -1
  185. package/dist/src/type_of_type.js +62 -1
  186. package/dist/src/type_of_type.js.map +1 -1
  187. package/dist/src/types.d.ts +8 -8
  188. package/dist/src/types.d.ts.map +1 -1
  189. package/dist/src/types.js +4 -4
  190. package/dist/src/types.js.map +1 -1
  191. package/package.json +4 -5
@@ -5,19 +5,47 @@
5
5
  import {} from "./builtins.js";
6
6
  import { printLocationValue } from "./ir.js";
7
7
  import { compareFor, equalFor, greaterEqualFor, greaterFor, isFor, lessEqualFor, lessFor, notEqualFor } from "./comparison.js";
8
+ import { diffFor } from "./patch/diff.js";
9
+ import { applyFor } from "./patch/apply.js";
10
+ import { composeFor } from "./patch/compose.js";
11
+ import { invertFor } from "./patch/invert.js";
12
+ import { ConflictError } from "./patch/index.js";
8
13
  import { printFor, parseFor } from "./serialization/east.js";
9
14
  import { variant } from "./containers/variant.js";
10
- import { EastError } from "./error.js";
15
+ import { EastError, InternalError } from "./error.js";
11
16
  import { SortedSet } from "./containers/sortedset.js";
12
17
  import { SortedMap } from "./containers/sortedmap.js";
13
18
  import { BufferWriter } from "./serialization/binary-utils.js";
14
- import { decodeBeast2For, decodeBeastFor, encodeBeast2For, encodeBeastFor, fromJSONFor, toJSONFor } from "./serialization/index.js";
19
+ import { decodeBeast2For, decodeBeastFor, encodeBeast2For, encodeBeastFor, fromJSONFor, toJSONFor, decodeCsvFor, encodeCsvFor } from "./serialization/index.js";
15
20
  import { formatDateTime } from "./datetime_format/print.js";
16
21
  import { parseDateTimeFormatted } from "./datetime_format/parse.js";
17
22
  import { EastTypeValueType, isTypeValueEqual, expandTypeValue } from "./type_of_type.js";
18
23
  import { ref } from "./containers/ref.js";
19
24
  export { isTypeValueEqual };
20
25
  export const printTypeValue = printFor(EastTypeValueType);
26
+ /**
27
+ * Symbol used to attach source IR to compiled functions.
28
+ * This enables serialization of free functions (functions with no captures).
29
+ */
30
+ export const EAST_IR_SYMBOL = Symbol.for("east.ir");
31
+ /**
32
+ * Symbol used to attach capture values to compiled functions.
33
+ * This enables serialization of closures (functions with captures).
34
+ */
35
+ export const EAST_CAPTURES_SYMBOL = Symbol.for("east.captures");
36
+ /** Determines if a variable requires boxing (mutable + captured) */
37
+ export function requiresBoxing(variable) {
38
+ return variable.mutable && variable.captured;
39
+ }
40
+ /** Get a context value, throwing InternalError if missing */
41
+ function getContextValue(ctx, name) {
42
+ const value = ctx[name];
43
+ if (value === undefined) {
44
+ throw new InternalError(`Variable '${name}' not found in runtime context`);
45
+ }
46
+ return value;
47
+ }
48
+ // =============================================================================
21
49
  /** @internal Track iteration locks to prevent concurrent modification */
22
50
  const iterationLocks = new WeakMap();
23
51
  /** @internal Lock a collection for iteration (prevents size/keyset modifications) */
@@ -63,7 +91,7 @@ class BreakException {
63
91
  *
64
92
  * @internal
65
93
  */
66
- export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx = true, compilingNodes = new Set()) {
94
+ export function compile_internal(ir, ctx, platform, asyncPlatformFns, platformDef, fresh_ctx = true, compilingNodes = new Set()) {
67
95
  // The IR is checked prior to compilation, so we can assume it's valid here.
68
96
  // The compiler needs to take care that Promises are properly awaited, so most IR nodes need both sync and async implementations.
69
97
  // We assume unnecessary `async` functions degrade performance but unnecessary `await`s are not too bad, so while we could be more "specific" in our awaits we do not bother
@@ -73,7 +101,7 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
73
101
  return (_ctx) => v;
74
102
  }
75
103
  else if (ir.type === "Error") {
76
- const message_compiled = compile_internal(ir.value.message, ctx, platform, asyncPlatformFns, false, compilingNodes);
104
+ const message_compiled = compile_internal(ir.value.message, ctx, platform, asyncPlatformFns, platformDef, false, compilingNodes);
77
105
  const location = ir.value.location;
78
106
  if (ir.value.isAsync) {
79
107
  return async (ctx) => { throw new EastError(await message_compiled(ctx), { location: location }); };
@@ -83,15 +111,15 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
83
111
  }
84
112
  }
85
113
  else if (ir.type === "TryCatch") {
86
- const try_body = compile_internal(ir.value.try_body, Object.create(ctx), platform, asyncPlatformFns, true, compilingNodes);
114
+ const try_body = compile_internal(ir.value.try_body, Object.create(ctx), platform, asyncPlatformFns, platformDef, true, compilingNodes);
87
115
  const new_ctx = Object.create(ctx);
88
116
  const message_name = ir.value.message.value.name;
89
117
  const stack_name = ir.value.stack.value.name;
90
118
  new_ctx[message_name] = ir.value.message.value.type;
91
119
  new_ctx[stack_name] = ir.value.stack.value.type;
92
- const catch_body = compile_internal(ir.value.catch_body, new_ctx, platform, asyncPlatformFns, true, compilingNodes);
120
+ const catch_body = compile_internal(ir.value.catch_body, new_ctx, platform, asyncPlatformFns, platformDef, true, compilingNodes);
93
121
  // Don't include finally unless necessary (Value nodes are effect free)
94
- const finally_body = ir.value.finally_body.type === "Value" ? undefined : compile_internal(ir.value.finally_body, Object.create(ctx), platform, asyncPlatformFns, true, compilingNodes);
122
+ const finally_body = ir.value.finally_body.type === "Value" ? undefined : compile_internal(ir.value.finally_body, Object.create(ctx), platform, asyncPlatformFns, platformDef, true, compilingNodes);
95
123
  if (ir.value.isAsync) {
96
124
  if (finally_body === undefined) {
97
125
  return async (ctx) => {
@@ -101,8 +129,8 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
101
129
  catch (e) {
102
130
  if (e instanceof EastError) {
103
131
  const new_ctx = Object.create(ctx);
104
- new_ctx[message_name] = e.message;
105
- new_ctx[stack_name] = e.location;
132
+ new_ctx[message_name] = variant("value", e.message);
133
+ new_ctx[stack_name] = variant("value", e.location);
106
134
  return await catch_body(new_ctx);
107
135
  }
108
136
  else {
@@ -119,8 +147,8 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
119
147
  catch (e) {
120
148
  if (e instanceof EastError) {
121
149
  const new_ctx = Object.create(ctx);
122
- new_ctx[message_name] = e.message;
123
- new_ctx[stack_name] = e.location;
150
+ new_ctx[message_name] = variant("value", e.message);
151
+ new_ctx[stack_name] = variant("value", e.location);
124
152
  return await catch_body(new_ctx);
125
153
  }
126
154
  else {
@@ -142,8 +170,8 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
142
170
  catch (e) {
143
171
  if (e instanceof EastError) {
144
172
  const new_ctx = Object.create(ctx);
145
- new_ctx[message_name] = e.message;
146
- new_ctx[stack_name] = e.location;
173
+ new_ctx[message_name] = variant("value", e.message);
174
+ new_ctx[stack_name] = variant("value", e.location);
147
175
  return catch_body(new_ctx);
148
176
  }
149
177
  else {
@@ -160,8 +188,8 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
160
188
  catch (e) {
161
189
  if (e instanceof EastError) {
162
190
  const new_ctx = Object.create(ctx);
163
- new_ctx[message_name] = e.message;
164
- new_ctx[stack_name] = e.location;
191
+ new_ctx[message_name] = variant("value", e.message);
192
+ new_ctx[stack_name] = variant("value", e.location);
165
193
  return catch_body(new_ctx);
166
194
  }
167
195
  else {
@@ -177,73 +205,58 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
177
205
  }
178
206
  else if (ir.type === "Variable") {
179
207
  const name = ir.value.name;
180
- if (ir.value.mutable && ir.value.captured) {
181
- return (ctx) => ctx[name].x;
182
- }
183
- else {
184
- return (ctx) => ctx[name];
185
- }
208
+ // All context values are variants - read via .value
209
+ return (ctx) => getContextValue(ctx, name).value;
186
210
  }
187
211
  else if (ir.type === "Let") {
188
- const compiled_statement = compile_internal(ir.value.value, ctx, platform, asyncPlatformFns, false, compilingNodes);
212
+ const compiled_statement = compile_internal(ir.value.value, ctx, platform, asyncPlatformFns, platformDef, false, compilingNodes);
189
213
  const name = ir.value.variable.value.name;
190
214
  ctx[name] = ir.value.variable.value.type;
191
- if (ir.value.variable.value.mutable && ir.value.variable.value.captured) {
192
- if (ir.value.isAsync) {
193
- return async (ctx) => {
194
- ctx[name] = { x: await compiled_statement(ctx) };
195
- return null;
196
- };
197
- }
198
- else {
199
- return (ctx) => {
200
- ctx[name] = { x: compiled_statement(ctx) };
201
- return null;
202
- };
203
- }
215
+ const boxed = requiresBoxing(ir.value.variable.value);
216
+ if (ir.value.isAsync) {
217
+ return async (ctx) => {
218
+ ctx[name] = boxed
219
+ ? variant("boxed", await compiled_statement(ctx))
220
+ : variant("value", await compiled_statement(ctx));
221
+ return null;
222
+ };
204
223
  }
205
224
  else {
206
- if (ir.value.isAsync) {
207
- return async (ctx) => {
208
- ctx[name] = await compiled_statement(ctx);
209
- return null;
210
- };
211
- }
212
- else {
213
- return (ctx) => {
214
- ctx[name] = compiled_statement(ctx);
215
- return null;
216
- };
217
- }
225
+ return (ctx) => {
226
+ ctx[name] = boxed
227
+ ? variant("boxed", compiled_statement(ctx))
228
+ : variant("value", compiled_statement(ctx));
229
+ return null;
230
+ };
218
231
  }
219
232
  }
220
233
  else if (ir.type === "Assign") {
221
234
  const name = ir.value.variable.value.name;
222
- const compiled_statement = compile_internal(ir.value.value, ctx, platform, asyncPlatformFns, false, compilingNodes);
223
- if (ir.value.variable.value.mutable && ir.value.variable.value.captured) {
235
+ const compiled_statement = compile_internal(ir.value.value, ctx, platform, asyncPlatformFns, platformDef, false, compilingNodes);
236
+ if (requiresBoxing(ir.value.variable.value)) {
237
+ // Boxed variables: mutate in place via .value
224
238
  if (ir.value.isAsync) {
225
239
  return async (ctx) => {
226
- const value = await compiled_statement(ctx);
227
- ctx[name].x = value;
240
+ getContextValue(ctx, name).value = await compiled_statement(ctx);
228
241
  return null;
229
242
  };
230
243
  }
231
244
  else {
232
245
  return (ctx) => {
233
- const value = compiled_statement(ctx);
234
- ctx[name].x = value;
246
+ getContextValue(ctx, name).value = compiled_statement(ctx);
235
247
  return null;
236
248
  };
237
249
  }
238
250
  }
239
251
  else {
252
+ // Non-boxed variables: replace the variant
240
253
  if (ir.value.isAsync) {
241
254
  return async (ctx) => {
242
255
  const value = await compiled_statement(ctx);
243
256
  // We need to check in which prototype the variable lives
244
257
  while (!Object.hasOwn(ctx, name))
245
258
  ctx = Object.getPrototypeOf(ctx);
246
- ctx[name] = value;
259
+ ctx[name] = variant("value", value);
247
260
  return null;
248
261
  };
249
262
  }
@@ -253,7 +266,7 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
253
266
  // We need to check in which prototype the variable lives
254
267
  while (!Object.hasOwn(ctx, name))
255
268
  ctx = Object.getPrototypeOf(ctx);
256
- ctx[name] = value;
269
+ ctx[name] = variant("value", value);
257
270
  return null;
258
271
  };
259
272
  }
@@ -262,69 +275,105 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
262
275
  else if (ir.type === "As") {
263
276
  // in dynamically typed runtimes like Javascript, this is a no-op
264
277
  // (for statically typed runtimes this assists in unifying types in branches)
265
- return compile_internal(ir.value.value, ctx, platform, asyncPlatformFns, fresh_ctx, compilingNodes);
278
+ return compile_internal(ir.value.value, ctx, platform, asyncPlatformFns, platformDef, fresh_ctx, compilingNodes);
266
279
  }
267
280
  else if (ir.type === "UnwrapRecursive") {
268
281
  // in dynamically typed runtimes like Javascript, this is a no-op
269
282
  // (for statically typed runtimes this assists in e.g. typing a reference or pointer)
270
- return compile_internal(ir.value.value, ctx, platform, asyncPlatformFns, fresh_ctx, compilingNodes);
283
+ return compile_internal(ir.value.value, ctx, platform, asyncPlatformFns, platformDef, fresh_ctx, compilingNodes);
271
284
  }
272
285
  else if (ir.type === "WrapRecursive") {
273
286
  // in dynamically typed runtimes like Javascript, this is a no-op
274
287
  // (for statically typed runtimes this assists in e.g. typing a heap allocation)
275
- return compile_internal(ir.value.value, ctx, platform, asyncPlatformFns, false, compilingNodes);
288
+ return compile_internal(ir.value.value, ctx, platform, asyncPlatformFns, platformDef, false, compilingNodes);
276
289
  }
277
290
  else if (ir.type === "Function") {
278
- const ctx2 = {};
291
+ // Compile-time type context for body compilation
292
+ const typeCtx = {};
279
293
  for (const variable of ir.value.captures) {
280
- ctx2[variable.value.name] = variable.value.type;
294
+ typeCtx[variable.value.name] = variable.value.type;
281
295
  }
282
296
  for (const parameter of ir.value.parameters) {
283
- const parameter_name = parameter.value.name;
284
- ctx2[parameter_name] = parameter.value.type;
297
+ typeCtx[parameter.value.name] = parameter.value.type;
285
298
  }
286
- const compiled_body = compile_internal(ir.value.body, ctx2, platform, asyncPlatformFns, true, compilingNodes);
299
+ const compiled_body = compile_internal(ir.value.body, typeCtx, platform, asyncPlatformFns, platformDef, true, compilingNodes);
287
300
  const capture_names = ir.value.captures.map(v => v.value.name);
288
301
  const parameter_names = ir.value.parameters.map(v => v.value.name);
302
+ // Store original IR for potential serialization
303
+ const originalIR = ir;
289
304
  return (ctx) => {
290
- const ctx2 = {};
305
+ // Runtime context for captured values
306
+ const captureCtx = {};
291
307
  for (const name of capture_names) {
292
- ctx2[name] = ctx[name];
308
+ captureCtx[name] = getContextValue(ctx, name);
293
309
  }
294
- return (...args) => {
295
- const ctx3 = { ...ctx2 };
296
- parameter_names.forEach((name, i) => ctx3[name] = args[i]);
297
- return compiled_body(ctx3);
310
+ const fn = (...args) => {
311
+ const fnCtx = { ...captureCtx };
312
+ parameter_names.forEach((name, i) => fnCtx[name] = variant("value", args[i]));
313
+ return compiled_body(fnCtx);
298
314
  };
315
+ // Attach IR to function for serialization support
316
+ Object.defineProperty(fn, EAST_IR_SYMBOL, {
317
+ value: originalIR,
318
+ writable: false,
319
+ enumerable: false,
320
+ configurable: false
321
+ });
322
+ // Attach capture values for serialization support
323
+ Object.defineProperty(fn, EAST_CAPTURES_SYMBOL, {
324
+ value: captureCtx,
325
+ writable: false,
326
+ enumerable: false,
327
+ configurable: false
328
+ });
329
+ return fn;
299
330
  };
300
331
  }
301
332
  else if (ir.type === "AsyncFunction") {
302
- const ctx2 = {};
333
+ // Compile-time type context for body compilation
334
+ const typeCtx = {};
303
335
  for (const variable of ir.value.captures) {
304
- ctx2[variable.value.name] = variable.value.type;
336
+ typeCtx[variable.value.name] = variable.value.type;
305
337
  }
306
338
  for (const parameter of ir.value.parameters) {
307
- const parameter_name = parameter.value.name;
308
- ctx2[parameter_name] = parameter.value.type;
339
+ typeCtx[parameter.value.name] = parameter.value.type;
309
340
  }
310
- const compiled_body = compile_internal(ir.value.body, ctx2, platform, asyncPlatformFns, true, compilingNodes);
341
+ const compiled_body = compile_internal(ir.value.body, typeCtx, platform, asyncPlatformFns, platformDef, true, compilingNodes);
311
342
  const capture_names = ir.value.captures.map(v => v.value.name);
312
343
  const parameter_names = ir.value.parameters.map(v => v.value.name);
344
+ // Store original IR for potential serialization
345
+ const originalIR = ir;
313
346
  return (ctx) => {
314
- const ctx2 = {};
347
+ // Runtime context for captured values
348
+ const captureCtx = {};
315
349
  for (const name of capture_names) {
316
- ctx2[name] = ctx[name];
350
+ captureCtx[name] = getContextValue(ctx, name);
317
351
  }
318
- return (...args) => {
319
- const ctx3 = { ...ctx2 };
320
- parameter_names.forEach((name, i) => ctx3[name] = args[i]);
321
- return compiled_body(ctx3); // Promise can pass through in tail position
352
+ const fn = (...args) => {
353
+ const fnCtx = { ...captureCtx };
354
+ parameter_names.forEach((name, i) => fnCtx[name] = variant("value", args[i]));
355
+ return compiled_body(fnCtx); // Promise can pass through in tail position
322
356
  };
357
+ // Attach IR to function for serialization support
358
+ Object.defineProperty(fn, EAST_IR_SYMBOL, {
359
+ value: originalIR,
360
+ writable: false,
361
+ enumerable: false,
362
+ configurable: false
363
+ });
364
+ // Attach capture values for serialization support
365
+ Object.defineProperty(fn, EAST_CAPTURES_SYMBOL, {
366
+ value: captureCtx,
367
+ writable: false,
368
+ enumerable: false,
369
+ configurable: false
370
+ });
371
+ return fn;
323
372
  };
324
373
  }
325
374
  else if (ir.type === "Call") {
326
- const compiled_f = compile_internal(ir.value.function, ctx, platform, asyncPlatformFns, false, compilingNodes);
327
- const compiled_args = ir.value.arguments.map(argument => compile_internal(argument, ctx, platform, asyncPlatformFns, false, compilingNodes));
375
+ const compiled_f = compile_internal(ir.value.function, ctx, platform, asyncPlatformFns, platformDef, false, compilingNodes);
376
+ const compiled_args = ir.value.arguments.map(argument => compile_internal(argument, ctx, platform, asyncPlatformFns, platformDef, false, compilingNodes));
328
377
  const location = ir.value.location;
329
378
  if (ir.value.isAsync) {
330
379
  // need to await the arguments
@@ -341,7 +390,7 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
341
390
  return e.value;
342
391
  }
343
392
  else if (e instanceof EastError) {
344
- e.location.push(location); // The fact that we need to push the call location not the definition location means we need to handle this here
393
+ e.location.push(...location); // The fact that we need to push the call location not the definition location means we need to handle this here
345
394
  throw (e);
346
395
  }
347
396
  else if (e instanceof ContinueException) {
@@ -366,7 +415,7 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
366
415
  return e.value;
367
416
  }
368
417
  else if (e instanceof EastError) {
369
- e.location.push(location); // The fact that we need to push the call location not the definition location means we need to handle this here
418
+ e.location.push(...location); // The fact that we need to push the call location not the definition location means we need to handle this here
370
419
  throw (e);
371
420
  }
372
421
  else if (e instanceof ContinueException) {
@@ -383,8 +432,8 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
383
432
  }
384
433
  }
385
434
  else if (ir.type === "CallAsync") {
386
- const compiled_f = compile_internal(ir.value.function, ctx, platform, asyncPlatformFns, false, compilingNodes);
387
- const compiled_args = ir.value.arguments.map(argument => compile_internal(argument, ctx, platform, asyncPlatformFns, false, compilingNodes));
435
+ const compiled_f = compile_internal(ir.value.function, ctx, platform, asyncPlatformFns, platformDef, false, compilingNodes);
436
+ const compiled_args = ir.value.arguments.map(argument => compile_internal(argument, ctx, platform, asyncPlatformFns, platformDef, false, compilingNodes));
388
437
  const location = ir.value.location;
389
438
  return async (ctx) => {
390
439
  try {
@@ -399,7 +448,7 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
399
448
  return e.value;
400
449
  }
401
450
  else if (e instanceof EastError) {
402
- e.location.push(location); // The fact that we need to push the call location not the definition location means we need to handle this here
451
+ e.location.push(...location); // The fact that we need to push the call location not the definition location means we need to handle this here
403
452
  throw (e);
404
453
  }
405
454
  else if (e instanceof ContinueException) {
@@ -422,11 +471,11 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
422
471
  asyncPredicate = true;
423
472
  }
424
473
  ifs.push({
425
- predicate: compile_internal(predicate, ctx, platform, asyncPlatformFns, false, compilingNodes),
426
- body: compile_internal(body, Object.create(ctx), platform, asyncPlatformFns, true, compilingNodes),
474
+ predicate: compile_internal(predicate, ctx, platform, asyncPlatformFns, platformDef, false, compilingNodes),
475
+ body: compile_internal(body, Object.create(ctx), platform, asyncPlatformFns, platformDef, true, compilingNodes),
427
476
  });
428
477
  }
429
- const else_body = compile_internal(ir.value.else_body, Object.create(ctx), platform, asyncPlatformFns, true, compilingNodes);
478
+ const else_body = compile_internal(ir.value.else_body, Object.create(ctx), platform, asyncPlatformFns, platformDef, true, compilingNodes);
430
479
  if (ir.value.isAsync) {
431
480
  if (asyncPredicate) {
432
481
  return async (ctx) => {
@@ -461,7 +510,7 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
461
510
  }
462
511
  }
463
512
  else if (ir.type === "Match") {
464
- const compiled_variant = compile_internal(ir.value.variant, ctx, platform, asyncPlatformFns, false, compilingNodes);
513
+ const compiled_variant = compile_internal(ir.value.variant, ctx, platform, asyncPlatformFns, platformDef, false, compilingNodes);
465
514
  const compiled_cases = {};
466
515
  const data_names = {};
467
516
  for (const { case: k, variable, body } of ir.value.cases) {
@@ -469,14 +518,14 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
469
518
  const data_name = variable.value.name;
470
519
  data_names[k] = data_name;
471
520
  ctx2[data_name] = variable.value.type;
472
- compiled_cases[k] = compile_internal(body, ctx2, platform, asyncPlatformFns, true, compilingNodes);
521
+ compiled_cases[k] = compile_internal(body, ctx2, platform, asyncPlatformFns, platformDef, true, compilingNodes);
473
522
  }
474
523
  if (ir.value.isAsync) {
475
524
  if (ir.value.variant.value.isAsync) {
476
525
  return async (ctx) => {
477
526
  const v = await compiled_variant(ctx);
478
527
  const ctx2 = Object.create(ctx);
479
- ctx2[data_names[v.type]] = v.value;
528
+ ctx2[data_names[v.type]] = variant("value", v.value);
480
529
  return await compiled_cases[v.type](ctx2);
481
530
  };
482
531
  }
@@ -484,7 +533,7 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
484
533
  return async (ctx) => {
485
534
  const v = compiled_variant(ctx);
486
535
  const ctx2 = Object.create(ctx);
487
- ctx2[data_names[v.type]] = v.value;
536
+ ctx2[data_names[v.type]] = variant("value", v.value);
488
537
  return await compiled_cases[v.type](ctx2);
489
538
  };
490
539
  }
@@ -493,15 +542,15 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
493
542
  return (ctx) => {
494
543
  const v = compiled_variant(ctx);
495
544
  const ctx2 = Object.create(ctx);
496
- ctx2[data_names[v.type]] = v.value;
545
+ ctx2[data_names[v.type]] = variant("value", v.value);
497
546
  return compiled_cases[v.type](ctx2);
498
547
  };
499
548
  }
500
549
  }
501
550
  else if (ir.type === "While") {
502
- const compiled_predicate = compile_internal(ir.value.predicate, ctx, platform, asyncPlatformFns, false, compilingNodes);
551
+ const compiled_predicate = compile_internal(ir.value.predicate, ctx, platform, asyncPlatformFns, platformDef, false, compilingNodes);
503
552
  const ctx2 = Object.create(ctx);
504
- const compiled_body = compile_internal(ir.value.body, ctx2, platform, asyncPlatformFns, true, compilingNodes);
553
+ const compiled_body = compile_internal(ir.value.body, ctx2, platform, asyncPlatformFns, platformDef, true, compilingNodes);
505
554
  const label = ir.value.label.name;
506
555
  if (ir.value.isAsync) {
507
556
  return async (ctx) => {
@@ -550,13 +599,13 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
550
599
  }
551
600
  else if (ir.type === "ForArray") {
552
601
  const value_type = expandTypeValue(ir.value.array.value.type).value;
553
- const compiled_array = compile_internal(ir.value.array, ctx, platform, asyncPlatformFns, false, compilingNodes);
602
+ const compiled_array = compile_internal(ir.value.array, ctx, platform, asyncPlatformFns, platformDef, false, compilingNodes);
554
603
  const ctx2 = Object.create(ctx);
555
604
  const key_name = ir.value.key.value.name;
556
605
  const value_name = ir.value.value.value.name;
557
606
  ctx2[key_name] = variant("Integer", null);
558
607
  ctx2[value_name] = value_type;
559
- const compiled_body = compile_internal(ir.value.body, ctx2, platform, asyncPlatformFns, true, compilingNodes);
608
+ const compiled_body = compile_internal(ir.value.body, ctx2, platform, asyncPlatformFns, platformDef, true, compilingNodes);
560
609
  const label = ir.value.label.name;
561
610
  if (ir.value.isAsync) {
562
611
  return async (ctx) => {
@@ -565,8 +614,8 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
565
614
  try {
566
615
  for (const [key, value] of array.entries()) {
567
616
  const ctx2 = Object.create(ctx);
568
- ctx2[key_name] = BigInt(key);
569
- ctx2[value_name] = value;
617
+ ctx2[key_name] = variant("value", BigInt(key));
618
+ ctx2[value_name] = variant("value", value);
570
619
  try {
571
620
  await compiled_body(ctx2);
572
621
  }
@@ -596,8 +645,8 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
596
645
  try {
597
646
  for (const [key, value] of array.entries()) {
598
647
  const ctx2 = Object.create(ctx);
599
- ctx2[key_name] = BigInt(key);
600
- ctx2[value_name] = value;
648
+ ctx2[key_name] = variant("value", BigInt(key));
649
+ ctx2[value_name] = variant("value", value);
601
650
  try {
602
651
  compiled_body(ctx2);
603
652
  }
@@ -623,11 +672,11 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
623
672
  }
624
673
  else if (ir.type === "ForSet") {
625
674
  const key_type = expandTypeValue(ir.value.set.value.type).value;
626
- const compiled_set = compile_internal(ir.value.set, ctx, platform, asyncPlatformFns, false, compilingNodes);
675
+ const compiled_set = compile_internal(ir.value.set, ctx, platform, asyncPlatformFns, platformDef, false, compilingNodes);
627
676
  const ctx2 = Object.create(ctx);
628
677
  const key_name = ir.value.key.value.name;
629
678
  ctx2[key_name] = key_type;
630
- const compiled_body = compile_internal(ir.value.body, ctx2, platform, asyncPlatformFns, true, compilingNodes);
679
+ const compiled_body = compile_internal(ir.value.body, ctx2, platform, asyncPlatformFns, platformDef, true, compilingNodes);
631
680
  const label = ir.value.label.name;
632
681
  if (ir.value.isAsync) {
633
682
  return async (ctx) => {
@@ -636,7 +685,7 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
636
685
  try {
637
686
  for (const key of set) {
638
687
  const ctx2 = Object.create(ctx);
639
- ctx2[key_name] = key;
688
+ ctx2[key_name] = variant("value", key);
640
689
  try {
641
690
  await compiled_body(ctx2);
642
691
  }
@@ -666,7 +715,7 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
666
715
  try {
667
716
  for (const key of set) {
668
717
  const ctx2 = Object.create(ctx);
669
- ctx2[key_name] = key;
718
+ ctx2[key_name] = variant("value", key);
670
719
  try {
671
720
  compiled_body(ctx2);
672
721
  }
@@ -693,13 +742,13 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
693
742
  else if (ir.type === "ForDict") {
694
743
  const key_type = expandTypeValue(ir.value.dict.value.type).value.key;
695
744
  const value_type = expandTypeValue(ir.value.dict.value.type).value.value;
696
- const compiled_dict = compile_internal(ir.value.dict, ctx, platform, asyncPlatformFns, false, compilingNodes);
745
+ const compiled_dict = compile_internal(ir.value.dict, ctx, platform, asyncPlatformFns, platformDef, false, compilingNodes);
697
746
  const ctx2 = Object.create(ctx);
698
747
  const key_name = ir.value.key.value.name;
699
748
  const value_name = ir.value.value.value.name;
700
749
  ctx2[key_name] = key_type;
701
750
  ctx2[value_name] = value_type;
702
- const compiled_body = compile_internal(ir.value.body, ctx2, platform, asyncPlatformFns, true, compilingNodes);
751
+ const compiled_body = compile_internal(ir.value.body, ctx2, platform, asyncPlatformFns, platformDef, true, compilingNodes);
703
752
  const label = ir.value.label.name;
704
753
  if (ir.value.isAsync) {
705
754
  return async (ctx) => {
@@ -708,8 +757,8 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
708
757
  try {
709
758
  for (const [key, value] of dict) {
710
759
  const ctx2 = Object.create(ctx);
711
- ctx2[key_name] = key;
712
- ctx2[value_name] = value;
760
+ ctx2[key_name] = variant("value", key);
761
+ ctx2[value_name] = variant("value", value);
713
762
  try {
714
763
  await compiled_body(ctx2);
715
764
  }
@@ -739,8 +788,8 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
739
788
  try {
740
789
  for (const [key, value] of dict) {
741
790
  const ctx2 = Object.create(ctx);
742
- ctx2[key_name] = key;
743
- ctx2[value_name] = value;
791
+ ctx2[key_name] = variant("value", key);
792
+ ctx2[value_name] = variant("value", value);
744
793
  try {
745
794
  compiled_body(ctx2);
746
795
  }
@@ -770,7 +819,7 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
770
819
  if (fresh_ctx) {
771
820
  const compiled_statements = [];
772
821
  for (const statement of ir.value.statements) {
773
- const compiled_statement = compile_internal(statement, ctx, platform, asyncPlatformFns, true, compilingNodes);
822
+ const compiled_statement = compile_internal(statement, ctx, platform, asyncPlatformFns, platformDef, true, compilingNodes);
774
823
  compiled_statements.push(compiled_statement);
775
824
  }
776
825
  if (ir.value.isAsync) {
@@ -796,7 +845,7 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
796
845
  const ctx2 = Object.create(ctx);
797
846
  const compiled_statements = [];
798
847
  for (const statement of ir.value.statements) {
799
- const compiled_statement = compile_internal(statement, ctx2, platform, asyncPlatformFns, true, compilingNodes);
848
+ const compiled_statement = compile_internal(statement, ctx2, platform, asyncPlatformFns, platformDef, true, compilingNodes);
800
849
  compiled_statements.push(compiled_statement);
801
850
  }
802
851
  if (ir.value.isAsync) {
@@ -822,7 +871,7 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
822
871
  }
823
872
  }
824
873
  else if (ir.type === "GetField") {
825
- const struct = compile_internal(ir.value.struct, ctx, platform, asyncPlatformFns, false, compilingNodes);
874
+ const struct = compile_internal(ir.value.struct, ctx, platform, asyncPlatformFns, platformDef, false, compilingNodes);
826
875
  const field = ir.value.field;
827
876
  if (ir.value.isAsync) {
828
877
  return async (ctx) => (await struct(ctx))[field];
@@ -833,7 +882,7 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
833
882
  }
834
883
  else if (ir.type === "Struct") {
835
884
  const fields = ir.value.fields.map(f => {
836
- return compile_internal(f.value, ctx, platform, asyncPlatformFns, false, compilingNodes);
885
+ return compile_internal(f.value, ctx, platform, asyncPlatformFns, platformDef, false, compilingNodes);
837
886
  });
838
887
  const keys = ir.value.fields.map(f => f.name);
839
888
  if (ir.value.isAsync) {
@@ -851,7 +900,7 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
851
900
  }
852
901
  else if (ir.type === "Variant") {
853
902
  const k = ir.value.case;
854
- const v = compile_internal(ir.value.value, ctx, platform, asyncPlatformFns, false, compilingNodes);
903
+ const v = compile_internal(ir.value.value, ctx, platform, asyncPlatformFns, platformDef, false, compilingNodes);
855
904
  if (ir.value.isAsync) {
856
905
  return async (ctx) => variant(k, await v(ctx));
857
906
  }
@@ -860,7 +909,7 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
860
909
  }
861
910
  }
862
911
  else if (ir.type === "NewRef") {
863
- const value = compile_internal(ir.value.value, ctx, platform, asyncPlatformFns, false, compilingNodes);
912
+ const value = compile_internal(ir.value.value, ctx, platform, asyncPlatformFns, platformDef, false, compilingNodes);
864
913
  if (ir.value.isAsync) {
865
914
  return async (ctx) => ref(await value(ctx));
866
915
  }
@@ -870,7 +919,7 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
870
919
  }
871
920
  else if (ir.type === "NewArray") {
872
921
  const values = ir.value.values.map(a => {
873
- return compile_internal(a, ctx, platform, asyncPlatformFns, false, compilingNodes);
922
+ return compile_internal(a, ctx, platform, asyncPlatformFns, platformDef, false, compilingNodes);
874
923
  });
875
924
  if (ir.value.isAsync) {
876
925
  return async (ctx) => {
@@ -887,7 +936,7 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
887
936
  }
888
937
  else if (ir.type === "NewSet") {
889
938
  const values = ir.value.values.map(a => {
890
- return compile_internal(a, ctx, platform, asyncPlatformFns, false, compilingNodes);
939
+ return compile_internal(a, ctx, platform, asyncPlatformFns, platformDef, false, compilingNodes);
891
940
  });
892
941
  const keyComparer = compareFor(ir.value.type.value);
893
942
  if (ir.value.isAsync) {
@@ -905,7 +954,7 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
905
954
  }
906
955
  else if (ir.type === "NewDict") {
907
956
  const values = ir.value.values.map(({ key, value }) => {
908
- return [compile_internal(key, ctx, platform, asyncPlatformFns, false, compilingNodes), compile_internal(value, ctx, platform, asyncPlatformFns, false, compilingNodes)];
957
+ return [compile_internal(key, ctx, platform, asyncPlatformFns, platformDef, false, compilingNodes), compile_internal(value, ctx, platform, asyncPlatformFns, platformDef, false, compilingNodes)];
909
958
  });
910
959
  const keyComparer = compareFor(ir.value.type.value.key);
911
960
  if (ir.value.isAsync) {
@@ -922,7 +971,7 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
922
971
  }
923
972
  }
924
973
  else if (ir.type === "Return") {
925
- const compiled_value = compile_internal(ir.value.value, ctx, platform, asyncPlatformFns, false, compilingNodes);
974
+ const compiled_value = compile_internal(ir.value.value, ctx, platform, asyncPlatformFns, platformDef, false, compilingNodes);
926
975
  if (ir.value.isAsync) {
927
976
  return async (ctx) => {
928
977
  throw new ReturnException(await compiled_value(ctx));
@@ -952,7 +1001,7 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
952
1001
  if (a.value.isAsync) {
953
1002
  argsAsync = true;
954
1003
  }
955
- return compile_internal(a, ctx, platform, asyncPlatformFns, false, compilingNodes);
1004
+ return compile_internal(a, ctx, platform, asyncPlatformFns, platformDef, false, compilingNodes);
956
1005
  });
957
1006
  // Special optimization for regex builtins with literal pattern/flags
958
1007
  if ((ir.value.builtin === "RegexContains" || ir.value.builtin === "RegexIndexOf" || ir.value.builtin === "RegexReplace") &&
@@ -1127,7 +1176,7 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
1127
1176
  }
1128
1177
  }
1129
1178
  }
1130
- const evaluator = builtin_evaluators[ir.value.builtin](ir.value.location, ...ir.value.type_parameters);
1179
+ const evaluator = builtin_evaluators[ir.value.builtin](ir.value.location, platformDef, ...ir.value.type_parameters);
1131
1180
  if (argsAsync) {
1132
1181
  return async (ctx) => {
1133
1182
  const args_resolved = [];
@@ -1147,11 +1196,41 @@ export function compile_internal(ir, ctx, platform, asyncPlatformFns, fresh_ctx
1147
1196
  if (a.value.isAsync) {
1148
1197
  argsAsync = true;
1149
1198
  }
1150
- return compile_internal(a, ctx, platform, asyncPlatformFns, false, compilingNodes);
1199
+ return compile_internal(a, ctx, platform, asyncPlatformFns, platformDef, false, compilingNodes);
1151
1200
  });
1152
- const evaluator = platform[ir.value.name];
1153
- if (evaluator === undefined) {
1154
- throw new Error(`Evaluator for platform function ${JSON.stringify(ir.value.name)} not found at ${printLocationValue(ir.value.location)}`);
1201
+ // Look up platform function definition to check if generic
1202
+ const platformFn = platformDef.find(p => p.name === ir.value.name);
1203
+ const typeParams = ir.value.type_parameters ?? [];
1204
+ // Get evaluator - for generic functions, call factory with type params
1205
+ let evaluator;
1206
+ if (typeParams.length > 0 && platformFn?.type_parameters && platformFn.type_parameters.length > 0) {
1207
+ // Generic platform function - fn is a factory that takes type params
1208
+ if (!platformFn.fn) {
1209
+ // Missing generic platform function - create stub that throws at runtime
1210
+ const name = ir.value.name;
1211
+ const location = ir.value.location;
1212
+ evaluator = () => {
1213
+ throw new EastError(`Platform function '${name}' is not available`, { location });
1214
+ };
1215
+ }
1216
+ else {
1217
+ evaluator = platformFn.fn(...typeParams);
1218
+ }
1219
+ }
1220
+ else {
1221
+ // Non-generic - use platform map for backwards compatibility
1222
+ const platformEvaluator = platform[ir.value.name];
1223
+ if (platformEvaluator === undefined) {
1224
+ // Missing platform function - create stub that throws at runtime
1225
+ const name = ir.value.name;
1226
+ const location = ir.value.location;
1227
+ evaluator = () => {
1228
+ throw new EastError(`Platform function '${name}' is not available`, { location });
1229
+ };
1230
+ }
1231
+ else {
1232
+ evaluator = platformEvaluator;
1233
+ }
1155
1234
  }
1156
1235
  if (argsAsync) {
1157
1236
  return async (ctx) => {
@@ -1180,7 +1259,7 @@ function call_function(location, compiled_f, ...args) {
1180
1259
  return e.value;
1181
1260
  }
1182
1261
  else if (e instanceof EastError) {
1183
- e.location.push(location); // The fact that we need to push the call location not the definition location means we need to handle this here
1262
+ e.location.push(...location); // The fact that we need to push the call location not the definition location means we need to handle this here
1184
1263
  throw (e);
1185
1264
  }
1186
1265
  else if (e instanceof ContinueException) {
@@ -1196,13 +1275,43 @@ function call_function(location, compiled_f, ...args) {
1196
1275
  }
1197
1276
  /** @internal */
1198
1277
  const builtin_evaluators = {
1199
- Is: (_location, T) => isFor(T),
1200
- Equal: (_location, T) => equalFor(T),
1201
- NotEqual: (_location, T) => notEqualFor(T),
1202
- Less: (_location, T) => lessFor(T),
1203
- LessEqual: (_location, T) => lessEqualFor(T),
1204
- Greater: (_location, T) => greaterFor(T),
1205
- GreaterEqual: (_location, T) => greaterEqualFor(T),
1278
+ Is: (_location, _platformDef, T) => isFor(T),
1279
+ Equal: (_location, _platformDef, T) => equalFor(T),
1280
+ NotEqual: (_location, _platformDef, T) => notEqualFor(T),
1281
+ Less: (_location, _platformDef, T) => lessFor(T),
1282
+ LessEqual: (_location, _platformDef, T) => lessEqualFor(T),
1283
+ Greater: (_location, _platformDef, T) => greaterFor(T),
1284
+ GreaterEqual: (_location, _platformDef, T) => greaterEqualFor(T),
1285
+ Diff: (_location, _platformDef, T) => diffFor(T),
1286
+ ApplyPatch: (location, _platformDef, T) => {
1287
+ const apply = applyFor(T);
1288
+ return (base, patch) => {
1289
+ try {
1290
+ return apply(base, patch);
1291
+ }
1292
+ catch (e) {
1293
+ if (e instanceof ConflictError) {
1294
+ throw new EastError(e.message, { location });
1295
+ }
1296
+ throw e;
1297
+ }
1298
+ };
1299
+ },
1300
+ ComposePatch: (location, _platformDef, T) => {
1301
+ const compose = composeFor(T);
1302
+ return (first, second) => {
1303
+ try {
1304
+ return compose(first, second);
1305
+ }
1306
+ catch (e) {
1307
+ if (e instanceof ConflictError) {
1308
+ throw new EastError(e.message, { location });
1309
+ }
1310
+ throw e;
1311
+ }
1312
+ };
1313
+ },
1314
+ InvertPatch: (_location, _platformDef, T) => invertFor(T),
1206
1315
  BooleanNot: (_location) => (x) => !x,
1207
1316
  BooleanOr: (_location) => (x, y) => x || y,
1208
1317
  BooleanAnd: (_location) => (x, y) => x && y,
@@ -1257,10 +1366,10 @@ const builtin_evaluators = {
1257
1366
  FloatSin: (_location) => (value) => Math.sin(value),
1258
1367
  FloatCos: (_location) => (value) => Math.cos(value),
1259
1368
  FloatTan: (_location) => (value) => Math.tan(value),
1260
- Print: (_location, T) => {
1369
+ Print: (_location, _platformDef, T) => {
1261
1370
  return printFor(T);
1262
1371
  },
1263
- Parse: (location, T) => {
1372
+ Parse: (location, _platformDef, T) => {
1264
1373
  const p = parseFor(T);
1265
1374
  return (x) => {
1266
1375
  const result = p(x);
@@ -1460,7 +1569,7 @@ const builtin_evaluators = {
1460
1569
  return buffer.toUint8Array();
1461
1570
  };
1462
1571
  },
1463
- StringParseJSON: (location, type) => {
1572
+ StringParseJSON: (location, _platformDef, type) => {
1464
1573
  const fromJSON = fromJSONFor(type);
1465
1574
  return (x) => {
1466
1575
  let parsed;
@@ -1478,7 +1587,7 @@ const builtin_evaluators = {
1478
1587
  }
1479
1588
  };
1480
1589
  },
1481
- StringPrintJSON: (_location, type) => {
1590
+ StringPrintJSON: (_location, _platformDef, type) => {
1482
1591
  const toJSON = toJSONFor(type);
1483
1592
  return (x) => JSON.stringify(toJSON(x));
1484
1593
  },
@@ -1555,13 +1664,13 @@ const builtin_evaluators = {
1555
1664
  }
1556
1665
  };
1557
1666
  },
1558
- BlobEncodeBeast: (_location, type) => {
1667
+ BlobEncodeBeast: (_location, _platformDef, type) => {
1559
1668
  const encodeBeast = encodeBeastFor(type);
1560
1669
  return (value) => {
1561
1670
  return encodeBeast(value);
1562
1671
  };
1563
1672
  },
1564
- BlobDecodeBeast: (location, type) => {
1673
+ BlobDecodeBeast: (location, _platformDef, type) => {
1565
1674
  const decodeBeast = decodeBeastFor(type);
1566
1675
  return (data) => {
1567
1676
  try {
@@ -1572,14 +1681,14 @@ const builtin_evaluators = {
1572
1681
  }
1573
1682
  };
1574
1683
  },
1575
- BlobEncodeBeast2: (_location, type) => {
1684
+ BlobEncodeBeast2: (_location, _platformDef, type) => {
1576
1685
  const encodeBeast2 = encodeBeast2For(type);
1577
1686
  return (value) => {
1578
1687
  return encodeBeast2(value);
1579
1688
  };
1580
1689
  },
1581
- BlobDecodeBeast2: (location, type) => {
1582
- const decodeBeast2 = decodeBeast2For(type);
1690
+ BlobDecodeBeast2: (location, platformDef, type) => {
1691
+ const decodeBeast2 = decodeBeast2For(type, { platform: platformDef });
1583
1692
  return (data) => {
1584
1693
  try {
1585
1694
  return decodeBeast2(data);
@@ -1589,17 +1698,39 @@ const builtin_evaluators = {
1589
1698
  }
1590
1699
  };
1591
1700
  },
1592
- RefGet: (_location, _T) => (ref) => {
1701
+ BlobDecodeCsv: (location, _platformDef, structType, _configType) => {
1702
+ return (data, config) => {
1703
+ try {
1704
+ const decoder = decodeCsvFor(structType, config);
1705
+ return decoder(data);
1706
+ }
1707
+ catch (e) {
1708
+ throw new EastError(`Failed to decode CSV data: ${e.message}`, { location });
1709
+ }
1710
+ };
1711
+ },
1712
+ ArrayEncodeCsv: (location, _platformDef, structType, _configType) => {
1713
+ return (data, config) => {
1714
+ try {
1715
+ const encoder = encodeCsvFor(structType, config);
1716
+ return encoder(data);
1717
+ }
1718
+ catch (e) {
1719
+ throw new EastError(`Failed to encode CSV data: ${e.message}`, { location });
1720
+ }
1721
+ };
1722
+ },
1723
+ RefGet: (_location, _platformDef, _T) => (ref) => {
1593
1724
  return ref.value;
1594
1725
  },
1595
- RefUpdate: (location, _T) => (ref, value) => {
1726
+ RefUpdate: (location, _platformDef, _T) => (ref, value) => {
1596
1727
  if (Object.isFrozen(ref)) {
1597
1728
  throw new EastError("Cannot modify frozen Ref", { location });
1598
1729
  }
1599
1730
  ref.value = value;
1600
1731
  return null;
1601
1732
  },
1602
- RefMerge: (location, _T) => (ref, value, merger) => {
1733
+ RefMerge: (location, _platformDef, _T) => (ref, value, merger) => {
1603
1734
  if (Object.isFrozen(ref)) {
1604
1735
  throw new EastError("Cannot modify frozen Ref", { location });
1605
1736
  }
@@ -1607,7 +1738,7 @@ const builtin_evaluators = {
1607
1738
  ref.value = new_value;
1608
1739
  return null;
1609
1740
  },
1610
- ArrayGenerate: (location, _T) => (size, f) => {
1741
+ ArrayGenerate: (location, _platformDef, _T) => (size, f) => {
1611
1742
  const result = [];
1612
1743
  for (let i = 0n; i < size; i += 1n) {
1613
1744
  const v = call_function(location, f, i);
@@ -1648,12 +1779,12 @@ const builtin_evaluators = {
1648
1779
  }
1649
1780
  return result;
1650
1781
  },
1651
- ArraySize: (_location, _T) => (array) => BigInt(array.length),
1652
- ArrayHas: (_location, _T) => (array, key) => {
1782
+ ArraySize: (_location, _platformDef, _T) => (array) => BigInt(array.length),
1783
+ ArrayHas: (_location, _platformDef, _T) => (array, key) => {
1653
1784
  const i = Number(key);
1654
1785
  return i >= 0 && i < array.length;
1655
1786
  },
1656
- ArrayGet: (location, _T) => (array, key) => {
1787
+ ArrayGet: (location, _platformDef, _T) => (array, key) => {
1657
1788
  const i = Number(key);
1658
1789
  if (i < 0 || i >= array.length) {
1659
1790
  throw new EastError(`Array index ${key} out of bounds`, { location });
@@ -1662,7 +1793,7 @@ const builtin_evaluators = {
1662
1793
  return array[i];
1663
1794
  }
1664
1795
  },
1665
- ArrayGetOrDefault: (location, _T) => (array, key, defaultFn) => {
1796
+ ArrayGetOrDefault: (location, _platformDef, _T) => (array, key, defaultFn) => {
1666
1797
  const i = Number(key);
1667
1798
  if (i < 0 || i >= array.length) {
1668
1799
  return call_function(location, defaultFn, key);
@@ -1671,7 +1802,7 @@ const builtin_evaluators = {
1671
1802
  return array[i];
1672
1803
  }
1673
1804
  },
1674
- ArrayTryGet: (_location, _T) => (array, key) => {
1805
+ ArrayTryGet: (_location, _platformDef, _T) => (array, key) => {
1675
1806
  const i = Number(key);
1676
1807
  if (i < 0 || i >= array.length) {
1677
1808
  return variant("none", null);
@@ -1680,7 +1811,7 @@ const builtin_evaluators = {
1680
1811
  return variant("some", array[i]);
1681
1812
  }
1682
1813
  },
1683
- ArrayUpdate: (location, _T) => (array, key, value) => {
1814
+ ArrayUpdate: (location, _platformDef, _T) => (array, key, value) => {
1684
1815
  if (Object.isFrozen(array)) {
1685
1816
  throw new EastError("Cannot modify frozen Array", { location });
1686
1817
  }
@@ -1693,7 +1824,7 @@ const builtin_evaluators = {
1693
1824
  return null;
1694
1825
  }
1695
1826
  },
1696
- ArrayMerge: (location, _T) => (array, key, value, merger) => {
1827
+ ArrayMerge: (location, _platformDef, _T) => (array, key, value, merger) => {
1697
1828
  if (Object.isFrozen(array)) {
1698
1829
  throw new EastError("Cannot modify frozen Array", { location });
1699
1830
  }
@@ -1707,7 +1838,7 @@ const builtin_evaluators = {
1707
1838
  return null;
1708
1839
  }
1709
1840
  },
1710
- ArrayPushLast: (location, _T) => (array, value) => {
1841
+ ArrayPushLast: (location, _platformDef, _T) => (array, value) => {
1711
1842
  if (Object.isFrozen(array)) {
1712
1843
  throw new EastError("Cannot modify frozen Array", { location });
1713
1844
  }
@@ -1717,7 +1848,7 @@ const builtin_evaluators = {
1717
1848
  array.push(value);
1718
1849
  return null;
1719
1850
  },
1720
- ArrayPopLast: (location, _T) => (array) => {
1851
+ ArrayPopLast: (location, _platformDef, _T) => (array) => {
1721
1852
  if (Object.isFrozen(array)) {
1722
1853
  throw new EastError("Cannot modify frozen Array", { location });
1723
1854
  }
@@ -1731,7 +1862,7 @@ const builtin_evaluators = {
1731
1862
  return array.pop();
1732
1863
  }
1733
1864
  },
1734
- ArrayPushFirst: (location, _T) => (array, value) => {
1865
+ ArrayPushFirst: (location, _platformDef, _T) => (array, value) => {
1735
1866
  if (Object.isFrozen(array)) {
1736
1867
  throw new EastError("Cannot modify frozen Array", { location });
1737
1868
  }
@@ -1741,7 +1872,7 @@ const builtin_evaluators = {
1741
1872
  array.unshift(value);
1742
1873
  return null;
1743
1874
  },
1744
- ArrayPopFirst: (location, _T) => (array) => {
1875
+ ArrayPopFirst: (location, _platformDef, _T) => (array) => {
1745
1876
  if (Object.isFrozen(array)) {
1746
1877
  throw new EastError("Cannot modify frozen Array", { location });
1747
1878
  }
@@ -1755,7 +1886,7 @@ const builtin_evaluators = {
1755
1886
  return array.shift();
1756
1887
  }
1757
1888
  },
1758
- ArrayAppend: (location, _T) => (array, other) => {
1889
+ ArrayAppend: (location, _platformDef, _T) => (array, other) => {
1759
1890
  if (Object.isFrozen(array)) {
1760
1891
  throw new EastError("Cannot modify frozen Array", { location });
1761
1892
  }
@@ -1765,7 +1896,7 @@ const builtin_evaluators = {
1765
1896
  array.push(...other);
1766
1897
  return null;
1767
1898
  },
1768
- ArrayPrepend: (location, _T) => (array, other) => {
1899
+ ArrayPrepend: (location, _platformDef, _T) => (array, other) => {
1769
1900
  if (Object.isFrozen(array)) {
1770
1901
  throw new EastError("Cannot modify frozen Array", { location });
1771
1902
  }
@@ -1775,7 +1906,7 @@ const builtin_evaluators = {
1775
1906
  array.unshift(...other);
1776
1907
  return null;
1777
1908
  },
1778
- ArrayMergeAll: (location, _T, _T2) => (array, other, merger) => {
1909
+ ArrayMergeAll: (location, _platformDef, _T, _T2) => (array, other, merger) => {
1779
1910
  if (Object.isFrozen(array)) {
1780
1911
  throw new EastError("Cannot modify frozen Array", { location });
1781
1912
  }
@@ -1799,7 +1930,7 @@ const builtin_evaluators = {
1799
1930
  }
1800
1931
  return null;
1801
1932
  },
1802
- ArrayClear: (location, _T) => (array) => {
1933
+ ArrayClear: (location, _platformDef, _T) => (array) => {
1803
1934
  if (Object.isFrozen(array)) {
1804
1935
  throw new EastError("Cannot modify frozen Array", { location });
1805
1936
  }
@@ -1809,7 +1940,7 @@ const builtin_evaluators = {
1809
1940
  array.length = 0;
1810
1941
  return null;
1811
1942
  },
1812
- ArraySortInPlace: (location, T, T2) => (array, by) => {
1943
+ ArraySortInPlace: (location, _platformDef, T, T2) => (array, by) => {
1813
1944
  if (Object.isFrozen(array)) {
1814
1945
  throw new EastError("Cannot modify frozen Array", { location });
1815
1946
  }
@@ -1830,7 +1961,7 @@ const builtin_evaluators = {
1830
1961
  }
1831
1962
  return null;
1832
1963
  },
1833
- ArrayReverseInPlace: (location, _T) => (array) => {
1964
+ ArrayReverseInPlace: (location, _platformDef, _T) => (array) => {
1834
1965
  if (Object.isFrozen(array)) {
1835
1966
  throw new EastError("Cannot modify frozen Array", { location });
1836
1967
  }
@@ -1840,7 +1971,7 @@ const builtin_evaluators = {
1840
1971
  array.reverse();
1841
1972
  return null;
1842
1973
  },
1843
- ArraySort: (location, T, T2) => (array, by) => {
1974
+ ArraySort: (location, _platformDef, T, T2) => (array, by) => {
1844
1975
  const cmp = compareFor(T2);
1845
1976
  const newArray = [...array];
1846
1977
  newArray.sort((a, b) => {
@@ -1850,12 +1981,12 @@ const builtin_evaluators = {
1850
1981
  });
1851
1982
  return newArray;
1852
1983
  },
1853
- ArrayReverse: (_location, _T) => (array) => {
1984
+ ArrayReverse: (_location, _platformDef, _T) => (array) => {
1854
1985
  const newArray = [...array];
1855
1986
  newArray.reverse();
1856
1987
  return newArray;
1857
1988
  },
1858
- ArrayIsSorted: (location, T, T2) => {
1989
+ ArrayIsSorted: (location, _platformDef, T, T2) => {
1859
1990
  const cmp = compareFor(T2);
1860
1991
  return (array, by) => {
1861
1992
  if (array.length < 2)
@@ -1877,7 +2008,7 @@ const builtin_evaluators = {
1877
2008
  return true;
1878
2009
  };
1879
2010
  },
1880
- ArrayFindSortedFirst: (location, T, T2) => {
2011
+ ArrayFindSortedFirst: (location, _platformDef, T, T2) => {
1881
2012
  const cmp = compareFor(T2);
1882
2013
  return (array, key, by) => {
1883
2014
  let low = 0;
@@ -1901,7 +2032,7 @@ const builtin_evaluators = {
1901
2032
  return BigInt(low);
1902
2033
  };
1903
2034
  },
1904
- ArrayFindSortedLast: (location, T, T2) => {
2035
+ ArrayFindSortedLast: (location, _platformDef, T, T2) => {
1905
2036
  const cmp = compareFor(T2);
1906
2037
  return (array, key, by) => {
1907
2038
  let low = 0;
@@ -1925,7 +2056,7 @@ const builtin_evaluators = {
1925
2056
  return BigInt(low);
1926
2057
  };
1927
2058
  },
1928
- ArrayFindSortedRange: (location, T, T2) => {
2059
+ ArrayFindSortedRange: (location, _platformDef, T, T2) => {
1929
2060
  const cmp = compareFor(T2);
1930
2061
  return (array, key, by) => {
1931
2062
  let lo = -1;
@@ -1983,7 +2114,7 @@ const builtin_evaluators = {
1983
2114
  return { start: BigInt(lo + 1), end: BigInt(lo + 1) };
1984
2115
  };
1985
2116
  },
1986
- ArrayFindFirst: (location, T, T2) => {
2117
+ ArrayFindFirst: (location, _platformDef, T, T2) => {
1987
2118
  const cmp = compareFor(T2);
1988
2119
  return (array, value, by) => {
1989
2120
  lockForIteration(array);
@@ -2001,15 +2132,15 @@ const builtin_evaluators = {
2001
2132
  }
2002
2133
  };
2003
2134
  },
2004
- ArrayConcat: (_location, _T) => (a1, a2) => {
2135
+ ArrayConcat: (_location, _platformDef, _T) => (a1, a2) => {
2005
2136
  return [...a1, ...a2];
2006
2137
  },
2007
- ArraySlice: (_location, _T) => (array, start, end) => {
2138
+ ArraySlice: (_location, _platformDef, _T) => (array, start, end) => {
2008
2139
  const startNum = Number(start);
2009
2140
  const endNum = Number(end);
2010
2141
  return array.slice(startNum, endNum);
2011
2142
  },
2012
- ArrayGetKeys: (location, _T) => (array, keys, onMissing) => {
2143
+ ArrayGetKeys: (location, _platformDef, _T) => (array, keys, onMissing) => {
2013
2144
  return keys.map(k => {
2014
2145
  const i = Number(k);
2015
2146
  if (i < 0 || i >= array.length) {
@@ -2020,7 +2151,7 @@ const builtin_evaluators = {
2020
2151
  }
2021
2152
  });
2022
2153
  },
2023
- ArrayForEach: (location, _T, _T2) => (array, f) => {
2154
+ ArrayForEach: (location, _platformDef, _T, _T2) => (array, f) => {
2024
2155
  lockForIteration(array);
2025
2156
  try {
2026
2157
  array.forEach((x, i) => {
@@ -2032,10 +2163,10 @@ const builtin_evaluators = {
2032
2163
  unlockForIteration(array);
2033
2164
  }
2034
2165
  },
2035
- ArrayCopy: (_location, _T) => (array) => {
2166
+ ArrayCopy: (_location, _platformDef, _T) => (array) => {
2036
2167
  return [...array];
2037
2168
  },
2038
- ArrayMap: (location, _T, _T2) => (array, f) => {
2169
+ ArrayMap: (location, _platformDef, _T, _T2) => (array, f) => {
2039
2170
  lockForIteration(array);
2040
2171
  try {
2041
2172
  return array.map((x, i) => {
@@ -2046,7 +2177,7 @@ const builtin_evaluators = {
2046
2177
  unlockForIteration(array);
2047
2178
  }
2048
2179
  },
2049
- ArrayFilter: (location, _T, _T2) => (array, f) => {
2180
+ ArrayFilter: (location, _platformDef, _T, _T2) => (array, f) => {
2050
2181
  lockForIteration(array);
2051
2182
  try {
2052
2183
  return array.filter((x, i) => {
@@ -2057,7 +2188,7 @@ const builtin_evaluators = {
2057
2188
  unlockForIteration(array);
2058
2189
  }
2059
2190
  },
2060
- ArrayFilterMap: (location, _T, _T2) => (array, f) => {
2191
+ ArrayFilterMap: (location, _platformDef, _T, _T2) => (array, f) => {
2061
2192
  lockForIteration(array);
2062
2193
  try {
2063
2194
  const result = [];
@@ -2073,7 +2204,7 @@ const builtin_evaluators = {
2073
2204
  unlockForIteration(array);
2074
2205
  }
2075
2206
  },
2076
- ArrayFirstMap: (location, _T, _T2) => (array, f) => {
2207
+ ArrayFirstMap: (location, _platformDef, _T, _T2) => (array, f) => {
2077
2208
  lockForIteration(array);
2078
2209
  try {
2079
2210
  for (let i = 0; i < array.length; i++) {
@@ -2088,7 +2219,7 @@ const builtin_evaluators = {
2088
2219
  unlockForIteration(array);
2089
2220
  }
2090
2221
  },
2091
- ArrayFold: (location, _T, _T2) => (array, init, f) => {
2222
+ ArrayFold: (location, _platformDef, _T, _T2) => (array, init, f) => {
2092
2223
  lockForIteration(array);
2093
2224
  try {
2094
2225
  return array.reduce((acc, x, i) => {
@@ -2099,7 +2230,7 @@ const builtin_evaluators = {
2099
2230
  unlockForIteration(array);
2100
2231
  }
2101
2232
  },
2102
- ArrayMapReduce: (location, _T, _T2) => (array, mapFn, reduceFn) => {
2233
+ ArrayMapReduce: (location, _platformDef, _T, _T2) => (array, mapFn, reduceFn) => {
2103
2234
  if (array.length === 0) {
2104
2235
  throw new EastError("Cannot reduce empty array with no initial value", { location });
2105
2236
  }
@@ -2116,8 +2247,8 @@ const builtin_evaluators = {
2116
2247
  unlockForIteration(array);
2117
2248
  }
2118
2249
  },
2119
- ArrayStringJoin: (_location) => (x, y) => x.join(y),
2120
- ArrayToSet: (location, _T, T2) => {
2250
+ ArrayStringJoin: (_location, _platformDef) => (x, y) => x.join(y),
2251
+ ArrayToSet: (location, _platformDef, _T, T2) => {
2121
2252
  const compare = compareFor(T2);
2122
2253
  return (array, f) => {
2123
2254
  lockForIteration(array);
@@ -2134,7 +2265,7 @@ const builtin_evaluators = {
2134
2265
  }
2135
2266
  };
2136
2267
  },
2137
- ArrayToDict: (location, _T, K2, _T2) => {
2268
+ ArrayToDict: (location, _platformDef, _T, K2, _T2) => {
2138
2269
  const compare = compareFor(K2);
2139
2270
  return (array, keyFn, valueFn, onConflict) => {
2140
2271
  const result = new SortedMap([], compare);
@@ -2160,12 +2291,12 @@ const builtin_evaluators = {
2160
2291
  }
2161
2292
  };
2162
2293
  },
2163
- ArrayFlattenToArray: (location, _T) => (array, fn) => {
2294
+ ArrayFlattenToArray: (location, _platformDef, _T) => (array, fn) => {
2164
2295
  return array.flatMap(v => {
2165
2296
  return call_function(location, fn, v);
2166
2297
  });
2167
2298
  },
2168
- ArrayFlattenToSet: (location, _T, K2) => {
2299
+ ArrayFlattenToSet: (location, _platformDef, _T, K2) => {
2169
2300
  const compare = compareFor(K2);
2170
2301
  return (array, fn) => {
2171
2302
  const result = new SortedSet([], compare);
@@ -2184,7 +2315,7 @@ const builtin_evaluators = {
2184
2315
  }
2185
2316
  };
2186
2317
  },
2187
- ArrayFlattenToDict: (location, _T, K2, _T2) => {
2318
+ ArrayFlattenToDict: (location, _platformDef, _T, K2, _T2) => {
2188
2319
  const compare = compareFor(K2);
2189
2320
  return (array, fn, onConflict) => {
2190
2321
  const result = new SortedMap([], compare);
@@ -2210,7 +2341,7 @@ const builtin_evaluators = {
2210
2341
  }
2211
2342
  };
2212
2343
  },
2213
- ArrayGroupFold: (location, _T, K2, _V2) => {
2344
+ ArrayGroupFold: (location, _platformDef, _T, K2, _V2) => {
2214
2345
  const compare = compareFor(K2);
2215
2346
  return (array, keyFn, init, folder) => {
2216
2347
  const result = new SortedMap([], compare);
@@ -2233,7 +2364,7 @@ const builtin_evaluators = {
2233
2364
  }
2234
2365
  };
2235
2366
  },
2236
- SetGenerate: (location, K) => {
2367
+ SetGenerate: (location, _platformDef, K) => {
2237
2368
  const keyComparer = compareFor(K);
2238
2369
  return (size, keyFn, onConflict) => {
2239
2370
  const result = new SortedSet([], keyComparer);
@@ -2249,9 +2380,9 @@ const builtin_evaluators = {
2249
2380
  return result;
2250
2381
  };
2251
2382
  },
2252
- SetSize: (_location, _K) => (s) => BigInt(s.size),
2253
- SetHas: (_location, _K) => (s, key) => s.has(key),
2254
- SetInsert: (location, K) => {
2383
+ SetSize: (_location, _platformDef, _K) => (s) => BigInt(s.size),
2384
+ SetHas: (_location, _platformDef, _K) => (s, key) => s.has(key),
2385
+ SetInsert: (location, _platformDef, K) => {
2255
2386
  const print = printFor(K);
2256
2387
  return (s, key) => {
2257
2388
  if (Object.isFrozen(s)) {
@@ -2268,7 +2399,7 @@ const builtin_evaluators = {
2268
2399
  return null;
2269
2400
  };
2270
2401
  },
2271
- SetTryInsert: (location, _K) => (s, key) => {
2402
+ SetTryInsert: (location, _platformDef, _K) => (s, key) => {
2272
2403
  if (Object.isFrozen(s)) {
2273
2404
  throw new EastError("Cannot modify frozen Set", { location });
2274
2405
  }
@@ -2279,7 +2410,7 @@ const builtin_evaluators = {
2279
2410
  s.add(key);
2280
2411
  return s.size > size_before;
2281
2412
  },
2282
- SetDelete: (location, K) => {
2413
+ SetDelete: (location, _platformDef, K) => {
2283
2414
  const print = printFor(K);
2284
2415
  return (s, key) => {
2285
2416
  if (Object.isFrozen(s)) {
@@ -2294,7 +2425,7 @@ const builtin_evaluators = {
2294
2425
  return null;
2295
2426
  };
2296
2427
  },
2297
- SetTryDelete: (location, _K) => (s, key) => {
2428
+ SetTryDelete: (location, _platformDef, _K) => (s, key) => {
2298
2429
  if (Object.isFrozen(s)) {
2299
2430
  throw new EastError("Cannot modify frozen Set", { location });
2300
2431
  }
@@ -2303,7 +2434,7 @@ const builtin_evaluators = {
2303
2434
  }
2304
2435
  return s.delete(key);
2305
2436
  },
2306
- SetClear: (location, _K) => (s) => {
2437
+ SetClear: (location, _platformDef, _K) => (s) => {
2307
2438
  if (Object.isFrozen(s)) {
2308
2439
  throw new EastError("Cannot modify frozen Set", { location });
2309
2440
  }
@@ -2313,7 +2444,7 @@ const builtin_evaluators = {
2313
2444
  s.clear();
2314
2445
  return null;
2315
2446
  },
2316
- SetUnionInPlace: (location, _K) => (s1, s2) => {
2447
+ SetUnionInPlace: (location, _platformDef, _K) => (s1, s2) => {
2317
2448
  if (Object.isFrozen(s1)) {
2318
2449
  throw new EastError("Cannot modify frozen Set", { location });
2319
2450
  }
@@ -2323,19 +2454,19 @@ const builtin_evaluators = {
2323
2454
  s2.forEach(v => s1.add(v));
2324
2455
  return null;
2325
2456
  },
2326
- SetUnion: (_location, _K) => (s1, s2) => s1.union(s2),
2327
- SetIntersect: (_location, _K) => (s1, s2) => s1.intersection(s2),
2328
- SetDiff: (_location, _K) => (s1, s2) => s1.difference(s2),
2329
- SetSymDiff: (_location, _K) => (s1, s2) => s1.symmetricDifference(s2),
2330
- SetIsSubset: (_location, _K) => (s1, s2) => s1.isSubsetOf(s2),
2331
- SetIsDisjoint: (_location, _K) => (s1, s2) => s1.isDisjointFrom(s2),
2332
- SetCopy: (_location, K) => {
2457
+ SetUnion: (_location, _platformDef, _K) => (s1, s2) => s1.union(s2),
2458
+ SetIntersect: (_location, _platformDef, _K) => (s1, s2) => s1.intersection(s2),
2459
+ SetDiff: (_location, _platformDef, _K) => (s1, s2) => s1.difference(s2),
2460
+ SetSymDiff: (_location, _platformDef, _K) => (s1, s2) => s1.symmetricDifference(s2),
2461
+ SetIsSubset: (_location, _platformDef, _K) => (s1, s2) => s1.isSubsetOf(s2),
2462
+ SetIsDisjoint: (_location, _platformDef, _K) => (s1, s2) => s1.isDisjointFrom(s2),
2463
+ SetCopy: (_location, _platformDef, K) => {
2333
2464
  const compare = compareFor(K);
2334
2465
  return (s) => {
2335
2466
  return new SortedSet([...s], compare);
2336
2467
  };
2337
2468
  },
2338
- SetForEach: (location, _K, _T2) => (s, f) => {
2469
+ SetForEach: (location, _platformDef, _K, _T2) => (s, f) => {
2339
2470
  lockForIteration(s);
2340
2471
  try {
2341
2472
  s.forEach(x => {
@@ -2347,7 +2478,7 @@ const builtin_evaluators = {
2347
2478
  unlockForIteration(s);
2348
2479
  }
2349
2480
  },
2350
- SetFilter: (location, K) => {
2481
+ SetFilter: (location, _platformDef, K) => {
2351
2482
  const compare = compareFor(K);
2352
2483
  return (s, f) => {
2353
2484
  const result = new SortedSet([], compare);
@@ -2366,7 +2497,7 @@ const builtin_evaluators = {
2366
2497
  }
2367
2498
  };
2368
2499
  },
2369
- SetFilterMap: (location, K, _V2) => {
2500
+ SetFilterMap: (location, _platformDef, K, _V2) => {
2370
2501
  const compare = compareFor(K);
2371
2502
  return (s, f) => {
2372
2503
  const result = new SortedMap([], compare);
@@ -2385,7 +2516,7 @@ const builtin_evaluators = {
2385
2516
  }
2386
2517
  };
2387
2518
  },
2388
- SetFirstMap: (location, _K, _T2) => (s, f) => {
2519
+ SetFirstMap: (location, _platformDef, _K, _T2) => (s, f) => {
2389
2520
  lockForIteration(s);
2390
2521
  try {
2391
2522
  for (const k of s) {
@@ -2400,7 +2531,7 @@ const builtin_evaluators = {
2400
2531
  unlockForIteration(s);
2401
2532
  }
2402
2533
  },
2403
- SetMapReduce: (location, _K, _T2) => (s, mapFn, reduceFn) => {
2534
+ SetMapReduce: (location, _platformDef, _K, _T2) => (s, mapFn, reduceFn) => {
2404
2535
  if (s.size === 0) {
2405
2536
  throw new EastError("Cannot reduce empty set with no initial value", { location });
2406
2537
  }
@@ -2419,7 +2550,7 @@ const builtin_evaluators = {
2419
2550
  unlockForIteration(s);
2420
2551
  }
2421
2552
  },
2422
- SetMap: (location, K, _T2) => {
2553
+ SetMap: (location, _platformDef, K, _T2) => {
2423
2554
  const compare = compareFor(K);
2424
2555
  return (s, f) => {
2425
2556
  const result = new SortedMap([], compare);
@@ -2436,7 +2567,7 @@ const builtin_evaluators = {
2436
2567
  }
2437
2568
  };
2438
2569
  },
2439
- SetReduce: (location, _K, _T2) => (s, f, init) => {
2570
+ SetReduce: (location, _platformDef, _K, _T2) => (s, f, init) => {
2440
2571
  let acc = init;
2441
2572
  lockForIteration(s);
2442
2573
  try {
@@ -2449,7 +2580,7 @@ const builtin_evaluators = {
2449
2580
  unlockForIteration(s);
2450
2581
  }
2451
2582
  },
2452
- SetToArray: (location, _K, _T2) => (s, valueFn) => {
2583
+ SetToArray: (location, _platformDef, _K, _T2) => (s, valueFn) => {
2453
2584
  const ret = [];
2454
2585
  lockForIteration(s);
2455
2586
  try {
@@ -2463,7 +2594,7 @@ const builtin_evaluators = {
2463
2594
  unlockForIteration(s);
2464
2595
  }
2465
2596
  },
2466
- SetToSet: (location, K, K2) => {
2597
+ SetToSet: (location, _platformDef, K, K2) => {
2467
2598
  const compare = compareFor(K2);
2468
2599
  return (s, f) => {
2469
2600
  const result = new SortedSet([], compare);
@@ -2481,7 +2612,7 @@ const builtin_evaluators = {
2481
2612
  }
2482
2613
  };
2483
2614
  },
2484
- SetToDict: (location, K, K2, _V2) => {
2615
+ SetToDict: (location, _platformDef, K, K2, _V2) => {
2485
2616
  const compare = compareFor(K2);
2486
2617
  return (s, keyFn, valueFn, onConflict) => {
2487
2618
  const result = new SortedMap([], compare);
@@ -2506,7 +2637,7 @@ const builtin_evaluators = {
2506
2637
  }
2507
2638
  };
2508
2639
  },
2509
- SetFlattenToArray: (location, _K, _T2) => (s, fn) => {
2640
+ SetFlattenToArray: (location, _platformDef, _K, _T2) => (s, fn) => {
2510
2641
  const ret = [];
2511
2642
  lockForIteration(s);
2512
2643
  try {
@@ -2520,7 +2651,7 @@ const builtin_evaluators = {
2520
2651
  unlockForIteration(s);
2521
2652
  }
2522
2653
  },
2523
- SetFlattenToSet: (location, _K, K2) => {
2654
+ SetFlattenToSet: (location, _platformDef, _K, K2) => {
2524
2655
  const compare = compareFor(K2);
2525
2656
  return (s, fn) => {
2526
2657
  const result = new SortedSet([], compare);
@@ -2539,7 +2670,7 @@ const builtin_evaluators = {
2539
2670
  }
2540
2671
  };
2541
2672
  },
2542
- SetFlattenToDict: (location, _K, K2, _V2) => {
2673
+ SetFlattenToDict: (location, _platformDef, _K, K2, _V2) => {
2543
2674
  const compare = compareFor(K2);
2544
2675
  return (s, fn, onConflict) => {
2545
2676
  const result = new SortedMap([], compare);
@@ -2565,7 +2696,7 @@ const builtin_evaluators = {
2565
2696
  }
2566
2697
  };
2567
2698
  },
2568
- SetGroupFold: (location, _K, K2, _T2) => {
2699
+ SetGroupFold: (location, _platformDef, _K, K2, _T2) => {
2569
2700
  const compare = compareFor(K2);
2570
2701
  return (s, keyFn, init, folder) => {
2571
2702
  const result = new SortedMap([], compare);
@@ -2587,7 +2718,7 @@ const builtin_evaluators = {
2587
2718
  }
2588
2719
  };
2589
2720
  },
2590
- DictGenerate: (location, K, _V) => {
2721
+ DictGenerate: (location, _platformDef, K, _V) => {
2591
2722
  const keyComparer = compareFor(K);
2592
2723
  return (size, keyFn, valueFn, onConflict) => {
2593
2724
  const result = new SortedMap([], keyComparer);
@@ -2606,9 +2737,9 @@ const builtin_evaluators = {
2606
2737
  return result;
2607
2738
  };
2608
2739
  },
2609
- DictSize: (_location, _K, _V) => (d) => BigInt(d.size),
2610
- DictHas: (_location, _K, _V) => (d, key) => d.has(key),
2611
- DictGet: (location, K, _V) => {
2740
+ DictSize: (_location, _platformDef, _K, _V) => (d) => BigInt(d.size),
2741
+ DictHas: (_location, _platformDef, _K, _V) => (d, key) => d.has(key),
2742
+ DictGet: (location, _platformDef, K, _V) => {
2612
2743
  const print = printFor(K);
2613
2744
  return (d, key) => {
2614
2745
  const result = d.get(key);
@@ -2620,7 +2751,7 @@ const builtin_evaluators = {
2620
2751
  }
2621
2752
  };
2622
2753
  },
2623
- DictGetOrDefault: (location, _K, _V) => (d, key, onMissingFn) => {
2754
+ DictGetOrDefault: (location, _platformDef, _K, _V) => (d, key, onMissingFn) => {
2624
2755
  const result = d.get(key);
2625
2756
  if (result === undefined) {
2626
2757
  return call_function(location, onMissingFn, key);
@@ -2629,7 +2760,7 @@ const builtin_evaluators = {
2629
2760
  return result;
2630
2761
  }
2631
2762
  },
2632
- DictTryGet: (_location, _K, _V) => (d, key) => {
2763
+ DictTryGet: (_location, _platformDef, _K, _V) => (d, key) => {
2633
2764
  const result = d.get(key);
2634
2765
  if (result === undefined) {
2635
2766
  return variant("none", null);
@@ -2638,7 +2769,7 @@ const builtin_evaluators = {
2638
2769
  return variant("some", result);
2639
2770
  }
2640
2771
  },
2641
- DictInsert: (location, K, _V) => {
2772
+ DictInsert: (location, _platformDef, K, _V) => {
2642
2773
  const print = printFor(K);
2643
2774
  return (d, key, value) => {
2644
2775
  if (Object.isFrozen(d)) {
@@ -2657,7 +2788,7 @@ const builtin_evaluators = {
2657
2788
  return null;
2658
2789
  };
2659
2790
  },
2660
- DictGetOrInsert: (location, _K, _V) => (d, key, onMissing) => {
2791
+ DictGetOrInsert: (location, _platformDef, _K, _V) => (d, key, onMissing) => {
2661
2792
  if (Object.isFrozen(d)) {
2662
2793
  throw new EastError("Cannot modify frozen Dict", { location });
2663
2794
  }
@@ -2674,7 +2805,7 @@ const builtin_evaluators = {
2674
2805
  return existing;
2675
2806
  }
2676
2807
  },
2677
- DictInsertOrUpdate: (location, _K, _V) => (d, key, value, onConflictFn) => {
2808
+ DictInsertOrUpdate: (location, _platformDef, _K, _V) => (d, key, value, onConflictFn) => {
2678
2809
  if (Object.isFrozen(d)) {
2679
2810
  throw new EastError("Cannot modify frozen Dict", { location });
2680
2811
  }
@@ -2691,7 +2822,7 @@ const builtin_evaluators = {
2691
2822
  }
2692
2823
  return null;
2693
2824
  },
2694
- DictUpdate: (location, K, _V) => {
2825
+ DictUpdate: (location, _platformDef, K, _V) => {
2695
2826
  const print = printFor(K);
2696
2827
  return (d, key, value) => {
2697
2828
  if (Object.isFrozen(d)) {
@@ -2706,7 +2837,7 @@ const builtin_evaluators = {
2706
2837
  }
2707
2838
  };
2708
2839
  },
2709
- DictSwap: (location, K, _V) => {
2840
+ DictSwap: (location, _platformDef, K, _V) => {
2710
2841
  const print = printFor(K);
2711
2842
  return (d, key, value) => {
2712
2843
  if (Object.isFrozen(d)) {
@@ -2720,7 +2851,7 @@ const builtin_evaluators = {
2720
2851
  return existing;
2721
2852
  };
2722
2853
  },
2723
- DictMerge: (location, _K, _V) => (d, key, value, mergeFn, initialFn) => {
2854
+ DictMerge: (location, _platformDef, _K, _V) => (d, key, value, mergeFn, initialFn) => {
2724
2855
  if (Object.isFrozen(d)) {
2725
2856
  throw new EastError("Cannot modify frozen Dict", { location });
2726
2857
  }
@@ -2735,7 +2866,7 @@ const builtin_evaluators = {
2735
2866
  d.set(key, new_value);
2736
2867
  return null;
2737
2868
  },
2738
- DictDelete: (location, K, _V) => {
2869
+ DictDelete: (location, _platformDef, K, _V) => {
2739
2870
  const print = printFor(K);
2740
2871
  return (d, key) => {
2741
2872
  if (Object.isFrozen(d)) {
@@ -2751,7 +2882,7 @@ const builtin_evaluators = {
2751
2882
  return null;
2752
2883
  };
2753
2884
  },
2754
- DictTryDelete: (location, _K, _V) => (d, key) => {
2885
+ DictTryDelete: (location, _platformDef, _K, _V) => (d, key) => {
2755
2886
  if (Object.isFrozen(d)) {
2756
2887
  throw new EastError("Cannot modify frozen Dict", { location });
2757
2888
  }
@@ -2760,7 +2891,7 @@ const builtin_evaluators = {
2760
2891
  }
2761
2892
  return d.delete(key);
2762
2893
  },
2763
- DictPop: (location, K, _V) => {
2894
+ DictPop: (location, _platformDef, K, _V) => {
2764
2895
  const print = printFor(K);
2765
2896
  return (d, key) => {
2766
2897
  if (Object.isFrozen(d)) {
@@ -2779,7 +2910,7 @@ const builtin_evaluators = {
2779
2910
  }
2780
2911
  };
2781
2912
  },
2782
- DictClear: (location, _K, _V) => (d) => {
2913
+ DictClear: (location, _platformDef, _K, _V) => (d) => {
2783
2914
  if (Object.isFrozen(d)) {
2784
2915
  throw new EastError("Cannot modify frozen Dict", { location });
2785
2916
  }
@@ -2789,7 +2920,7 @@ const builtin_evaluators = {
2789
2920
  d.clear();
2790
2921
  return null;
2791
2922
  },
2792
- DictUnionInPlace: (location, _K, _V) => (d1, d2, onConflict) => {
2923
+ DictUnionInPlace: (location, _platformDef, _K, _V) => (d1, d2, onConflict) => {
2793
2924
  if (Object.isFrozen(d1)) {
2794
2925
  throw new EastError("Cannot modify frozen Dict", { location });
2795
2926
  }
@@ -2808,7 +2939,7 @@ const builtin_evaluators = {
2808
2939
  });
2809
2940
  return null;
2810
2941
  },
2811
- DictMergeAll: (location, _K, _V) => (d1, d2, mergeFn, initialFn) => {
2942
+ DictMergeAll: (location, _platformDef, _K, _V) => (d1, d2, mergeFn, initialFn) => {
2812
2943
  if (Object.isFrozen(d1)) {
2813
2944
  throw new EastError("Cannot modify frozen Dict", { location });
2814
2945
  }
@@ -2825,13 +2956,13 @@ const builtin_evaluators = {
2825
2956
  });
2826
2957
  return null;
2827
2958
  },
2828
- DictKeys: (_location, K, _V) => {
2959
+ DictKeys: (_location, _platformDef, K, _V) => {
2829
2960
  const compare = compareFor(K);
2830
2961
  return (d) => {
2831
2962
  return new SortedSet([...d.keys()], compare);
2832
2963
  };
2833
2964
  },
2834
- DictGetKeys: (location, K, _V) => {
2965
+ DictGetKeys: (location, _platformDef, K, _V) => {
2835
2966
  const compare = compareFor(K);
2836
2967
  return (d, keys, onMissing) => {
2837
2968
  const result = new SortedMap([], compare);
@@ -2848,7 +2979,7 @@ const builtin_evaluators = {
2848
2979
  return result;
2849
2980
  };
2850
2981
  },
2851
- DictForEach: (location, _K, _V, _T2) => (d, f) => {
2982
+ DictForEach: (location, _platformDef, _K, _V, _T2) => (d, f) => {
2852
2983
  lockForIteration(d);
2853
2984
  try {
2854
2985
  d.forEach((v, k) => {
@@ -2860,13 +2991,13 @@ const builtin_evaluators = {
2860
2991
  unlockForIteration(d);
2861
2992
  }
2862
2993
  },
2863
- DictCopy: (_location, K, _V) => {
2994
+ DictCopy: (_location, _platformDef, K, _V) => {
2864
2995
  const compare = compareFor(K);
2865
2996
  return (d) => {
2866
2997
  return new SortedMap([...d], compare);
2867
2998
  };
2868
2999
  },
2869
- DictMap: (location, K, _V, _V2) => {
3000
+ DictMap: (location, _platformDef, K, _V, _V2) => {
2870
3001
  const compare = compareFor(K);
2871
3002
  return (d, f) => {
2872
3003
  const result = new SortedMap([], compare);
@@ -2883,7 +3014,7 @@ const builtin_evaluators = {
2883
3014
  }
2884
3015
  };
2885
3016
  },
2886
- DictFilter: (location, K, _V) => {
3017
+ DictFilter: (location, _platformDef, K, _V) => {
2887
3018
  const compare = compareFor(K);
2888
3019
  return (d, f) => {
2889
3020
  const result = new SortedMap([], compare);
@@ -2902,7 +3033,7 @@ const builtin_evaluators = {
2902
3033
  }
2903
3034
  };
2904
3035
  },
2905
- DictFilterMap: (location, K, _V, _V2) => {
3036
+ DictFilterMap: (location, _platformDef, K, _V, _V2) => {
2906
3037
  const compare = compareFor(K);
2907
3038
  return (d, f) => {
2908
3039
  const result = new SortedMap([], compare);
@@ -2921,7 +3052,7 @@ const builtin_evaluators = {
2921
3052
  }
2922
3053
  };
2923
3054
  },
2924
- DictFirstMap: (location, _K, _V, _T2) => (d, f) => {
3055
+ DictFirstMap: (location, _platformDef, _K, _V, _T2) => (d, f) => {
2925
3056
  lockForIteration(d);
2926
3057
  try {
2927
3058
  for (const [k, v] of d) {
@@ -2936,7 +3067,7 @@ const builtin_evaluators = {
2936
3067
  unlockForIteration(d);
2937
3068
  }
2938
3069
  },
2939
- DictMapReduce: (location, _K, _V, _T2) => (d, mapFn, reduceFn) => {
3070
+ DictMapReduce: (location, _platformDef, _K, _V, _T2) => (d, mapFn, reduceFn) => {
2940
3071
  if (d.size === 0) {
2941
3072
  throw new EastError("Cannot reduce empty dictionary with no initial value", { location });
2942
3073
  }
@@ -2955,7 +3086,7 @@ const builtin_evaluators = {
2955
3086
  unlockForIteration(d);
2956
3087
  }
2957
3088
  },
2958
- DictReduce: (location, _K, _V, _T2) => (d, f, init) => {
3089
+ DictReduce: (location, _platformDef, _K, _V, _T2) => (d, f, init) => {
2959
3090
  let acc = init;
2960
3091
  lockForIteration(d);
2961
3092
  try {
@@ -2968,7 +3099,7 @@ const builtin_evaluators = {
2968
3099
  unlockForIteration(d);
2969
3100
  }
2970
3101
  },
2971
- DictToArray: (location, _K, _V, _T2) => (d, valueFn) => {
3102
+ DictToArray: (location, _platformDef, _K, _V, _T2) => (d, valueFn) => {
2972
3103
  const ret = [];
2973
3104
  lockForIteration(d);
2974
3105
  try {
@@ -2982,7 +3113,7 @@ const builtin_evaluators = {
2982
3113
  unlockForIteration(d);
2983
3114
  }
2984
3115
  },
2985
- DictToSet: (location, _K, _V, K2) => {
3116
+ DictToSet: (location, _platformDef, _K, _V, K2) => {
2986
3117
  const compare = compareFor(K2);
2987
3118
  return (d, fn) => {
2988
3119
  const result = new SortedSet([], compare);
@@ -2999,7 +3130,7 @@ const builtin_evaluators = {
2999
3130
  }
3000
3131
  };
3001
3132
  },
3002
- DictToDict: (location, K, _V, K2, _V2) => {
3133
+ DictToDict: (location, _platformDef, K, _V, K2, _V2) => {
3003
3134
  const compare = compareFor(K2);
3004
3135
  return (d, keyFn, valueFn, onConflict) => {
3005
3136
  const result = new SortedMap([], compare);
@@ -3024,7 +3155,7 @@ const builtin_evaluators = {
3024
3155
  }
3025
3156
  };
3026
3157
  },
3027
- DictFlattenToArray: (location, _K, _V, _T2) => (d, fn) => {
3158
+ DictFlattenToArray: (location, _platformDef, _K, _V, _T2) => (d, fn) => {
3028
3159
  const ret = [];
3029
3160
  lockForIteration(d);
3030
3161
  try {
@@ -3040,7 +3171,7 @@ const builtin_evaluators = {
3040
3171
  unlockForIteration(d);
3041
3172
  }
3042
3173
  },
3043
- DictFlattenToSet: (location, _K, _V, K2) => {
3174
+ DictFlattenToSet: (location, _platformDef, _K, _V, K2) => {
3044
3175
  const compare = compareFor(K2);
3045
3176
  return (d, fn) => {
3046
3177
  const result = new SortedSet([], compare);
@@ -3059,7 +3190,7 @@ const builtin_evaluators = {
3059
3190
  }
3060
3191
  };
3061
3192
  },
3062
- DictFlattenToDict: (location, _K, _V, K2, _V2) => {
3193
+ DictFlattenToDict: (location, _platformDef, _K, _V, K2, _V2) => {
3063
3194
  const compare = compareFor(K2);
3064
3195
  return (d, fn, onConflict) => {
3065
3196
  const result = new SortedMap([], compare);
@@ -3085,7 +3216,7 @@ const builtin_evaluators = {
3085
3216
  }
3086
3217
  };
3087
3218
  },
3088
- DictGroupFold: (location, _K, _V, K2, _T2) => {
3219
+ DictGroupFold: (location, _platformDef, _K, _V, K2, _T2) => {
3089
3220
  const compare = compareFor(K2);
3090
3221
  return (d, keyFn, init, folder) => {
3091
3222
  const result = new SortedMap([], compare);