embedded-react 0.18.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/NOTICE +1 -1
  2. package/README.md +8 -4
  3. package/aot/compile.mjs +178 -58
  4. package/aot/compiler/animations.mjs +290 -281
  5. package/aot/compiler/boot.mjs +70 -33
  6. package/aot/compiler/branch-merge.mjs +4 -3
  7. package/aot/compiler/check.mjs +9 -9
  8. package/aot/compiler/collect.mjs +324 -205
  9. package/aot/compiler/control-flow.mjs +209 -197
  10. package/aot/compiler/diagnostics.mjs +22 -25
  11. package/aot/compiler/elements/activity-indicator.mjs +25 -24
  12. package/aot/compiler/elements/dial.mjs +91 -77
  13. package/aot/compiler/elements/flat-list.mjs +24 -22
  14. package/aot/compiler/elements/image.mjs +51 -50
  15. package/aot/compiler/elements/modal.mjs +31 -30
  16. package/aot/compiler/elements/props.mjs +23 -23
  17. package/aot/compiler/elements/switch.mjs +42 -34
  18. package/aot/compiler/elements/text-input.mjs +34 -32
  19. package/aot/compiler/expressions.mjs +372 -333
  20. package/aot/compiler/handlers.mjs +473 -387
  21. package/aot/compiler/ir/functions.mjs +11 -1
  22. package/aot/compiler/ir/nodes.mjs +4 -4
  23. package/aot/compiler/ir/reads.mjs +19 -19
  24. package/aot/compiler/ir/types.mjs +14 -14
  25. package/aot/compiler/ir/vectors.mjs +5 -1
  26. package/aot/compiler/keyboard.mjs +17 -7
  27. package/aot/compiler/lower.mjs +77 -80
  28. package/aot/compiler/nodes.mjs +169 -152
  29. package/aot/compiler/options.mjs +35 -30
  30. package/aot/compiler/out.mjs +18 -22
  31. package/aot/compiler/package/animations.mjs +669 -0
  32. package/aot/compiler/package/arena.mjs +252 -0
  33. package/aot/compiler/package/assemble.mjs +177 -0
  34. package/aot/compiler/package/bytecode.mjs +286 -0
  35. package/aot/compiler/package/checks.mjs +1022 -0
  36. package/aot/compiler/package/codegen.mjs +1329 -0
  37. package/aot/compiler/package/enums.mjs +138 -0
  38. package/aot/compiler/package/format.mjs +760 -0
  39. package/aot/compiler/package/layouts.mjs +136 -0
  40. package/aot/compiler/package/lower.mjs +1606 -0
  41. package/aot/compiler/package/props.mjs +118 -0
  42. package/aot/compiler/package/tables.mjs +103 -0
  43. package/aot/compiler/package/vectors.mjs +502 -0
  44. package/aot/compiler/package/writer.mjs +664 -0
  45. package/aot/compiler/pan-responder.mjs +69 -61
  46. package/aot/compiler/parse.mjs +21 -21
  47. package/aot/compiler/static-eval.mjs +25 -23
  48. package/aot/compiler/style-text.mjs +161 -172
  49. package/aot/compiler/svg.mjs +477 -251
  50. package/aot/screenshot-smoke.mjs +55 -41
  51. package/aot/style-map.mjs +102 -90
  52. package/assets/bake-font.mjs +123 -77
  53. package/assets/bake-image.mjs +39 -22
  54. package/assets/bake-svg.mjs +361 -262
  55. package/assets/build-builtin-font.mjs +14 -10
  56. package/assets/emit-c.mjs +83 -62
  57. package/assets/emit-container.mjs +124 -38
  58. package/assets/emit-pack.mjs +77 -67
  59. package/assets/font-config.mjs +9 -6
  60. package/assets/font-sizes.mjs +163 -123
  61. package/assets/glyph-coverage.mjs +74 -54
  62. package/assets/index.mjs +31 -9
  63. package/assets/rasterize.mjs +126 -99
  64. package/assets/svg-loader.mjs +8 -8
  65. package/build.mjs +16 -14
  66. package/cli.mjs +359 -172
  67. package/compile-bin.mjs +5 -5
  68. package/flash.mjs +537 -0
  69. package/hotreload/dev-device.mjs +90 -33
  70. package/hotreload/pack-app.mjs +55 -43
  71. package/hotreload/pack-split.mjs +46 -37
  72. package/hotreload/package-transfer.mjs +175 -0
  73. package/hotreload/protocol.mjs +51 -38
  74. package/hotreload/uploader.mjs +38 -27
  75. package/hotreload/watch-tree.mjs +19 -19
  76. package/pack-container.mjs +31 -23
  77. package/package.json +11 -12
  78. package/persist-transform.mjs +34 -28
  79. package/qjsc-wasm.mjs +25 -14
  80. package/sim/embedded-react.cjs +1 -1
  81. package/sim/embedded-react.js +1 -1
  82. package/sim/embedded-react.wasm +0 -0
  83. package/sim/index.html +94 -85
  84. package/sim-server.mjs +101 -82
  85. package/src/embedded-react/Animated.js +24 -24
  86. package/src/embedded-react/Easing.js +1 -1
  87. package/src/embedded-react/FlatList.js +4 -4
  88. package/src/embedded-react/LayoutAnimation.js +8 -5
  89. package/src/embedded-react/PanResponder.js +75 -71
  90. package/src/embedded-react/Pressable.js +2 -8
  91. package/src/embedded-react/SectionList.js +6 -6
  92. package/src/embedded-react/StyleSheet.js +4 -3
  93. package/src/embedded-react/TouchableOpacity.js +13 -8
  94. package/src/embedded-react/index.d.ts +5 -5
  95. package/src/embedded-react/layout-anim-config.js +10 -4
  96. package/src/embedded-react/list-child.js +5 -5
  97. package/src/embedded-react/named-colors.js +1 -1
  98. package/src/embedded-react/split-style.js +11 -11
  99. package/src/embedded-react/svg-ops.js +760 -593
  100. package/src/embedded-react/useHostValue.js +3 -3
  101. package/src/embedded-react/usePersistentState.js +6 -6
  102. package/src/embedded-react/warn-props.js +1 -1
  103. package/src/host-config.js +60 -53
  104. package/src/props.js +49 -41
  105. package/src/renderer.js +7 -4
  106. package/aot/compiler/assemble.mjs +0 -944
  107. package/aot/compiler/c/animations.mjs +0 -436
  108. package/aot/compiler/c/boot.mjs +0 -127
  109. package/aot/compiler/c/expressions.mjs +0 -270
  110. package/aot/compiler/c/functions.mjs +0 -268
  111. package/aot/compiler/c/keyboard.mjs +0 -96
  112. package/aot/compiler/c/nodes.mjs +0 -303
  113. package/aot/compiler/c/pan-responder.mjs +0 -136
  114. package/aot/compiler/c/statements.mjs +0 -319
  115. package/aot/compiler/c/text.mjs +0 -83
  116. package/aot/compiler/c/vectors.mjs +0 -381
  117. package/aot/compiler/c-syntax.mjs +0 -127
@@ -22,24 +22,13 @@ import { aotError, locateError, withLoc } from './diagnostics.mjs';
22
22
  import { bootSlotOf, containsBoot, foldBoot, isBoot, wholeBootValue, } from './boot.mjs';
23
23
  import { evalStatic, foldScope, hasBinding } from './static-eval.mjs';
24
24
  import { lowerGestureField } from './pan-responder.mjs';
25
- import { toCExpr } from './c/expressions.mjs';
26
- import { printText } from './c/text.mjs';
27
- import { BOOL, FLOAT, INT, INT64_NUMBER, INT64_MATH, STRING, TIME, isBoolean, isConvertible64, isIntSlot, isTime, int64Join, int64Of, stateType, refType, slotOf, typeOfCExpr, typeOfSlot, } from './ir/types.mjs';
25
+ import { BOOL, FLOAT, INT, INT64_NUMBER, INT64_MATH, STRING, TIME, isBoolean, isConvertible64, isIntSlot, isTime, int64Join, int64Of, stateType, refType, slotOf, typeOfSlot, typeOfSlotValue, } from './ir/types.mjs';
28
26
  /*----------------------------------------------------------------------------------------------------------------------
29
27
  - Constants
30
28
  ---------------------------------------------------------------------------------------------------------------------*/
31
29
  /** The binary operators lowered as arithmetic, and those lowered as comparisons. */
32
- const ARITH = new Set(['+', '-', '*', '/', '%']);
30
+ const ARITHMETIC = new Set(['+', '-', '*', '/', '%']);
33
31
  const COMPARE = new Set(['<', '>', '<=', '>=', '==', '!=', '===', '!==']);
34
- /**
35
- * The C helper each whole-number operator lowers to. It saturates at the limit of its type, where C's own
36
- * signed overflow is undefined behavior; the 64-bit variant appends `64`.
37
- */
38
- export const CHECKED_OP = {
39
- '+': 'app_add',
40
- '-': 'app_sub',
41
- '*': 'app_mul',
42
- };
43
32
  /** The saturating helper each whole-number operator lowers to in the IR. */
44
33
  const CHECKED_HELPER = {
45
34
  '+': 'add',
@@ -54,7 +43,7 @@ const WHOLE_BOOT_TYPES = new Set([
54
43
  'ConditionalExpression',
55
44
  'CallExpression',
56
45
  ]);
57
- /** The range of a C int. */
46
+ /** The range of an int. */
58
47
  const INT_MIN = -(2 ** 31);
59
48
  export const INT_MAX = 2 ** 31 - 1;
60
49
  /** The Math functions that keep a whole number whole. */
@@ -68,7 +57,7 @@ const WHOLE_MATH = new Set([
68
57
  'max',
69
58
  ]);
70
59
  /** The helper that rounds `a / b` for two whole numbers the way each Math function does. */
71
- const INT_ROUND_DIV = new Map([
60
+ const INT_ROUND_DIVISION = new Map([
72
61
  ['floor', 'floordiv'],
73
62
  ['ceil', 'ceildiv'],
74
63
  ['round', 'rounddiv'],
@@ -90,12 +79,11 @@ const FLOAT_MATH_BINARY = new Set(['min', 'max', 'atan2', 'pow']);
90
79
  let assumedWide = null;
91
80
  /** The fields of an onLayout rect. */
92
81
  const LAYOUT_FIELDS = new Set(['x', 'y', 'width', 'height']);
82
+ /** The largest 32-bit int. */
83
+ const INT32_MAX = 0x7fffffff;
93
84
  /*----------------------------------------------------------------------------------------------------------------------
94
85
  - Implementation
95
86
  ---------------------------------------------------------------------------------------------------------------------*/
96
- // The modules that still build C from a lowered expression or text import asCond and formatArgs from here.
97
- export { asCond } from './c/expressions.mjs';
98
- export { formatArgs } from './c/text.mjs';
99
87
  /**
100
88
  * A 64-bit timestamp met a float, which would round it.
101
89
  *
@@ -146,13 +134,13 @@ export function findShadowedClockCalls(ast) {
146
134
  * `node` as an integer compile-time constant, or null.
147
135
  *
148
136
  * @param node The expression.
149
- * @param env The expression environment.
137
+ * @param environment The expression environment.
150
138
  *
151
139
  * @returns The integer, or null when the expression is not one.
152
140
  */
153
- export function staticInt(node, env) {
141
+ export function staticInt(node, environment) {
154
142
  try {
155
- const value = evalStatic(node, foldScope(env, env.consts ?? {}), 'strict');
143
+ const value = evalStatic(node, foldScope(environment, environment.constants ?? {}), 'strict');
156
144
  return Number.isInteger(value) ? value : null;
157
145
  }
158
146
  catch {
@@ -181,38 +169,42 @@ function numConst(value) {
181
169
  * check pass, at the expression: a float holds no NaN or Infinity, a folded `0 / 0` say.
182
170
  *
183
171
  * @param value The number.
184
- * @param loc Where it is.
172
+ * @param location Where it is.
185
173
  *
186
174
  * @returns Its source.
187
175
  */
188
- function numberSource(value, loc) {
176
+ function numberSource(value, location) {
189
177
  if (numConst(value).type.kind === 'float') {
190
178
  checkNumber(value);
191
179
  }
192
- return { kind: 'number', value, loc };
180
+ return { kind: 'number', value, location };
193
181
  }
194
182
  /**
195
183
  * A read of a value worked out at boot. One boot cannot work out is taken at the build's panel instead, which
196
184
  * the panel at boot must then give too.
197
185
  *
198
186
  * @param value The value.
199
- * @param loc Where it is read.
187
+ * @param location Where it is read.
200
188
  *
201
189
  * @returns Its source.
202
190
  */
203
- function bootSource(value, loc) {
191
+ function bootSource(value, location) {
204
192
  const slot = bootSlotOf(value);
205
193
  if (slot) {
206
- return { kind: 'fixed', expr: { kind: 'boot', slot, type: slot.type }, loc };
194
+ return {
195
+ kind: 'fixed',
196
+ expression: { kind: 'boot', slot, type: slot.type },
197
+ location,
198
+ };
207
199
  }
208
200
  const buildValue = foldBoot(value);
209
201
  if (typeof buildValue === 'number')
210
- return numberSource(buildValue, loc);
202
+ return numberSource(buildValue, location);
211
203
  if (typeof buildValue === 'string') {
212
- return { kind: 'string', value: buildValue, loc };
204
+ return { kind: 'string', value: buildValue, location };
213
205
  }
214
206
  if (typeof buildValue === 'boolean') {
215
- return { kind: 'boolean', value: buildValue, loc };
207
+ return { kind: 'boolean', value: buildValue, location };
216
208
  }
217
209
  throw new Error('AOT: a value derived from the panel size cannot be used in a dynamic expression');
218
210
  }
@@ -248,13 +240,13 @@ function readsBootName(node, scope) {
248
240
  * in double precision. Null for one that also reads state, or that boot cannot work out.
249
241
  *
250
242
  * @param node The expression.
251
- * @param env The expression environment.
252
- * @param loc Where it is.
243
+ * @param environment The expression environment.
244
+ * @param location Where it is.
253
245
  *
254
246
  * @returns Its source, or null.
255
247
  */
256
- function wholeBootSource(node, env, loc) {
257
- const scope = foldScope(env, env.consts ?? {});
248
+ function wholeBootSource(node, environment, location) {
249
+ const scope = foldScope(environment, environment.constants ?? {});
258
250
  if (!readsBootName(node, scope))
259
251
  return null;
260
252
  let value;
@@ -269,7 +261,11 @@ function wholeBootSource(node, env, loc) {
269
261
  const whole = wholeBootValue(node, scope, value);
270
262
  const slot = whole && bootSlotOf(whole);
271
263
  return slot
272
- ? { kind: 'fixed', expr: { kind: 'boot', slot, type: slot.type }, loc }
264
+ ? {
265
+ kind: 'fixed',
266
+ expression: { kind: 'boot', slot, type: slot.type },
267
+ location,
268
+ }
273
269
  : null;
274
270
  }
275
271
  /**
@@ -306,7 +302,7 @@ const boolConst = (value) => ({
306
302
  const localRead = (local) => ({
307
303
  kind: 'local',
308
304
  local,
309
- type: typeOfCExpr(local),
305
+ type: typeOfSlotValue(local),
310
306
  });
311
307
  /**
312
308
  * Whole-number math JS would not cut to 32 bits: `+ - *`, negation, `%`, and the Math functions that keep a
@@ -333,18 +329,18 @@ const keepsMath64Node = (node) => (node.type === 'BinaryExpression' &&
333
329
  * @returns Whether it is whole-number math JS would not cut to 32 bits.
334
330
  */
335
331
  const keepsMath64 = (source) => (source.kind === 'binary' &&
336
- (Boolean(CHECKED_HELPER[source.op]) || source.op === '%')) ||
337
- (source.kind === 'unary' && source.op === '-') ||
332
+ (Boolean(CHECKED_HELPER[source.operator]) || source.operator === '%')) ||
333
+ (source.kind === 'unary' && source.operator === '-') ||
338
334
  (source.kind === 'math' && source.wholeMath);
339
335
  /**
340
336
  * A 64-bit value computed at runtime from a timestamp, as opposed to a 64-bit constant or whole-number math
341
337
  * widened to 64 bits beside one.
342
338
  *
343
- * @param expr The lowered expression.
339
+ * @param expression The lowered expression.
344
340
  *
345
341
  * @returns Whether it is a timestamp.
346
342
  */
347
- export const isTime64 = (expr) => isTime(expr.type);
343
+ export const isTime64 = (expression) => isTime(expression.type);
348
344
  /**
349
345
  * Besides a float, a 64-bit number that is not a time converts, as in JS; only a timestamp refuses.
350
346
  *
@@ -360,16 +356,16 @@ const litPeers = (...operands) => operands.some(operand => operand.type.kind ===
360
356
  /**
361
357
  * The error for a divisor that is not a constant where a time's has to be one.
362
358
  *
363
- * @param loc Where the divisor is.
359
+ * @param location Where the divisor is.
364
360
  *
365
361
  * @returns The error, for the caller to throw.
366
362
  */
367
- function nonConstantDivisorError(loc) {
363
+ function nonConstantDivisorError(location) {
368
364
  const error = aotError('AOT: a 64-bit time value can only be divided by a constant', 'the divisor must be known at compile time — e.g. `ms % 1000`, `Math.floor(ms / ' +
369
365
  '60000)`. For a divisor from state, reduce the timestamp first: `(ms % 86400000) / ' +
370
366
  'period`.');
371
- if (loc) {
372
- error.aotLoc = loc;
367
+ if (location) {
368
+ error.aotLoc = location;
373
369
  }
374
370
  return error;
375
371
  }
@@ -379,12 +375,12 @@ function nonConstantDivisorError(loc) {
379
375
  * converts it: a remainder of 0, or a quotient saturated by the dividend's sign.
380
376
  *
381
377
  * @param node The divisor.
382
- * @param env The expression environment.
378
+ * @param environment The expression environment.
383
379
  *
384
380
  * @returns The divisor's value.
385
381
  */
386
- export function constDivisor(node, env) {
387
- const divisor = staticInt(node, env);
382
+ export function constDivisor(node, environment) {
383
+ const divisor = staticInt(node, environment);
388
384
  if (divisor !== null)
389
385
  return divisor;
390
386
  throw nonConstantDivisorError(node.loc?.start);
@@ -399,7 +395,7 @@ export function constDivisor(node, env) {
399
395
  function sourceDivisor(divisor) {
400
396
  if (divisor.constant !== null)
401
397
  return divisor.constant;
402
- throw nonConstantDivisorError(divisor.loc);
398
+ throw nonConstantDivisorError(divisor.location);
403
399
  }
404
400
  /**
405
401
  * `+ - * %` with a 64-bit value on either side, kept whole. `+ - *` saturate at the int64 limits. With a
@@ -418,14 +414,14 @@ function typeArith64(source, left, right) {
418
414
  if (left.type.kind === 'float' || right.type.kind === 'float') {
419
415
  throw mix64Error();
420
416
  }
421
- if (source.op === '/') {
417
+ if (source.operator === '/') {
422
418
  throw aotError('AOT: `/` on a 64-bit time value is not supported', 'JS division gives a fraction, which a 64-bit integer cannot hold. Use Math.floor(a / ' +
423
419
  'b) for whole units — e.g. Math.floor(ms / 1000) for seconds.');
424
420
  }
425
421
  // With no timestamp on either side, this is whole-number math widened to 64 bits.
426
422
  const isWide = !isTime64(left) && !isTime64(right);
427
423
  // `%`: zero/±1 divisors give 0, a timestamp needs a constant divisor, and the result narrows to int if it fits.
428
- if (source.op === '%') {
424
+ if (source.operator === '%') {
429
425
  const staticDivisor = source.divisor.constant;
430
426
  // JS gives NaN for a zero divisor, which is 0 here, as the int `%` has it.
431
427
  if (staticDivisor === 0)
@@ -435,20 +431,20 @@ function typeArith64(source, left, right) {
435
431
  kind: 'helper',
436
432
  helper: 'mod',
437
433
  bits: 64,
438
- args: [left, right],
434
+ callArguments: [left, right],
439
435
  type: INT64_MATH,
440
436
  };
441
437
  }
442
438
  const divisor = sourceDivisor(source.divisor);
443
- // ±1 leaves no remainder, and INT64_MIN % -1 overflows in C.
439
+ // ±1 leaves no remainder, and INT64_MIN % -1 overflows.
444
440
  if (divisor === 1 || divisor === -1)
445
441
  return numConst(0);
446
- if (Math.abs(divisor) <= 0x7fffffff || isIntSlot(left.type)) {
442
+ if (Math.abs(divisor) <= INT32_MAX || isIntSlot(left.type)) {
447
443
  return { kind: 'narrowRemainder', left, right, type: INT };
448
444
  }
449
445
  return {
450
446
  kind: 'arithmetic',
451
- op: '%',
447
+ operator: '%',
452
448
  left,
453
449
  right,
454
450
  type: isWide ? INT64_MATH : TIME,
@@ -457,9 +453,9 @@ function typeArith64(source, left, right) {
457
453
  // `+ - *`: the saturating 64-bit helper.
458
454
  return {
459
455
  kind: 'helper',
460
- helper: CHECKED_HELPER[source.op],
456
+ helper: CHECKED_HELPER[source.operator],
461
457
  bits: 64,
462
- args: [left, right],
458
+ callArguments: [left, right],
463
459
  type: isWide ? INT64_MATH : TIME,
464
460
  };
465
461
  }
@@ -468,13 +464,13 @@ function typeArith64(source, left, right) {
468
464
  * division by a constant (see constDivisor); a zero one saturates by the dividend's sign, as JS's ±Infinity
469
465
  * converts. Null when neither side is a timestamp, which leaves it to the whole-number or float path.
470
466
  *
471
- * @param fn The Math function's name.
467
+ * @param mathFunction The Math function's name.
472
468
  * @param division Its one argument, the division.
473
469
  * @param math64 Whole-number math is worked out in 64 bits here.
474
470
  *
475
471
  * @returns The typed call, or null when it is not this case.
476
472
  */
477
- function typeTimeRoundDiv(fn, division, math64) {
473
+ function typeTimeRoundDiv(mathFunction, division, math64) {
478
474
  const dividend = typeSource(division.left, math64);
479
475
  const divisor = typeSource(division.right, math64);
480
476
  if (!isTime64(dividend) && !isTime64(divisor))
@@ -484,39 +480,39 @@ function typeTimeRoundDiv(fn, division, math64) {
484
480
  }
485
481
  if (dividend.type.kind === 'string' || divisor.type.kind === 'string')
486
482
  return null;
487
- // Dividing by -1 is a negation, which saturates; C's `/` would overflow on INT64_MIN / -1.
483
+ // Dividing by -1 is a negation, which saturates; a plain `/` would overflow on INT64_MIN / -1.
488
484
  if (sourceDivisor(division.divisor) === -1) {
489
485
  return {
490
486
  kind: 'helper',
491
487
  helper: 'neg',
492
488
  bits: 64,
493
- args: [dividend],
489
+ callArguments: [dividend],
494
490
  type: TIME,
495
491
  };
496
492
  }
497
493
  return {
498
494
  kind: 'helper',
499
- helper: INT_ROUND_DIV.get(fn),
495
+ helper: INT_ROUND_DIVISION.get(mathFunction),
500
496
  bits: 64,
501
- args: [dividend, divisor],
497
+ callArguments: [dividend, divisor],
502
498
  type: TIME,
503
499
  };
504
500
  }
505
501
  /**
506
502
  * Math.floor / ceil / round / trunc over `a / b` with two whole numbers, as exact integer division: the float
507
503
  * path rounds an operand past 2^24, so Math.floor(16777217 / 1) would come out 16777216. A zero divisor keeps
508
- * JS's answer as app_f2i converts it (±Infinity saturates by the dividend's sign, 0 / 0 is 0), and
504
+ * JS's answer as an int (±Infinity saturates by the dividend's sign, 0 / 0 is 0), and
509
505
  * INT_MIN / -1 saturates too. Beside a 64-bit value, or with a 64-bit operand that is not a timestamp (a
510
506
  * constant past the int range, or math already widened), it divides in 64 bits, since JS would not cut the
511
507
  * operands to 32. Null for anything else, which leaves it to the float path.
512
508
  *
513
- * @param fn The Math function's name.
509
+ * @param mathFunction The Math function's name.
514
510
  * @param division Its one argument, the division.
515
511
  * @param math64 Whole-number math is worked out in 64 bits here.
516
512
  *
517
513
  * @returns The typed call, or null when it is not this case.
518
514
  */
519
- function typeIntRoundDiv(fn, division, math64) {
515
+ function typeIntRoundDiv(mathFunction, division, math64) {
520
516
  // Divide in 64 bits beside a 64-bit value, when both operands are whole numbers and neither is a timestamp.
521
517
  const dividend = typeSource(division.left, math64);
522
518
  const divisor = typeSource(division.right, math64);
@@ -529,9 +525,9 @@ function typeIntRoundDiv(fn, division, math64) {
529
525
  return null;
530
526
  return {
531
527
  kind: 'helper',
532
- helper: INT_ROUND_DIV.get(fn),
528
+ helper: INT_ROUND_DIVISION.get(mathFunction),
533
529
  bits: 64,
534
- args: [dividend, divisor],
530
+ callArguments: [dividend, divisor],
535
531
  type: INT64_MATH,
536
532
  };
537
533
  }
@@ -540,56 +536,61 @@ function typeIntRoundDiv(fn, division, math64) {
540
536
  return null;
541
537
  return {
542
538
  kind: 'helper',
543
- helper: INT_ROUND_DIV.get(fn),
539
+ helper: INT_ROUND_DIVISION.get(mathFunction),
544
540
  bits: 32,
545
- args: [dividend, divisor],
541
+ callArguments: [dividend, divisor],
546
542
  type: INT,
547
543
  };
548
544
  }
549
545
  /**
550
546
  * Math.* over a 64-bit timestamp: only what stays exact in whole numbers.
551
547
  *
552
- * @param fn The Math function's name.
553
- * @param argExprs Its typed arguments, at least one of them 64-bit.
548
+ * @param mathFunction The Math function's name.
549
+ * @param argumentExpressions Its typed arguments, at least one of them 64-bit.
554
550
  *
555
551
  * @returns The typed call.
556
552
  */
557
- function typeMath64(fn, argExprs) {
558
- if (argExprs.some(argExpr => argExpr.type.kind === 'float')) {
553
+ function typeMath64(mathFunction, argumentExpressions) {
554
+ if (argumentExpressions.some(argumentExpression => argumentExpression.type.kind === 'float')) {
559
555
  throw mix64Error();
560
556
  }
561
- if (argExprs.every(argExpr => isIntSlot(argExpr.type) || argExpr.type.kind === 'int64')) {
557
+ if (argumentExpressions.every(argumentExpression => isIntSlot(argumentExpression.type) ||
558
+ argumentExpression.type.kind === 'int64')) {
562
559
  // Whole-number math with no timestamp in it stays whole-number math.
563
- const isWide = !argExprs.some(isTime64);
560
+ const isWide = !argumentExpressions.some(isTime64);
564
561
  // A timestamp is already whole, so rounding leaves it as it is.
565
- if ((fn === 'floor' || fn === 'round' || fn === 'ceil' || fn === 'trunc') &&
566
- argExprs.length === 1) {
562
+ if ((mathFunction === 'floor' ||
563
+ mathFunction === 'round' ||
564
+ mathFunction === 'ceil' ||
565
+ mathFunction === 'trunc') &&
566
+ argumentExpressions.length === 1) {
567
567
  return {
568
568
  kind: 'wholeRound',
569
- operand: argExprs[0],
569
+ operand: argumentExpressions[0],
570
570
  type: isWide ? INT64_MATH : TIME,
571
571
  };
572
572
  }
573
- if (fn === 'abs' && argExprs.length === 1) {
573
+ if (mathFunction === 'abs' && argumentExpressions.length === 1) {
574
574
  return {
575
575
  kind: 'helper',
576
576
  helper: 'abs',
577
577
  bits: 64,
578
- args: [argExprs[0]],
578
+ callArguments: [argumentExpressions[0]],
579
579
  type: isWide ? INT64_MATH : TIME,
580
580
  };
581
581
  }
582
- if ((fn === 'min' || fn === 'max') && argExprs.length === 2) {
582
+ if ((mathFunction === 'min' || mathFunction === 'max') &&
583
+ argumentExpressions.length === 2) {
583
584
  return {
584
585
  kind: 'helper',
585
- helper: fn,
586
+ helper: mathFunction,
586
587
  bits: 64,
587
- args: [argExprs[0], argExprs[1]],
588
+ callArguments: [argumentExpressions[0], argumentExpressions[1]],
588
589
  type: isWide ? INT64_MATH : TIME,
589
590
  };
590
591
  }
591
592
  }
592
- throw aotError(`AOT: Math.${fn}(...) on a 64-bit time value is not supported`, 'Math.floor / round / ceil / trunc / abs / min / max keep a timestamp exact; for ' +
593
+ throw aotError(`AOT: Math.${mathFunction}(...) on a 64-bit time value is not supported`, 'Math.floor / round / ceil / trunc / abs / min / max keep a timestamp exact; for ' +
593
594
  'anything else, reduce it to a small number first, e.g. `ms % 1000`.');
594
595
  }
595
596
  /**
@@ -602,12 +603,12 @@ function typeMath64(fn, argExprs) {
602
603
  */
603
604
  function typeUnary(source, math64) {
604
605
  const operand = typeSource(source.operand, math64);
605
- if ((source.op === '-' || source.op === '+') &&
606
+ if ((source.operator === '-' || source.operator === '+') &&
606
607
  operand.type.kind === 'string') {
607
- throw aotError(`AOT: unary "${source.op}" on a string is not supported`, 'JS would coerce the string to a number; C has no such coercion. Keep the operand numeric.');
608
+ throw aotError(`AOT: unary "${source.operator}" on a string is not supported`, "JS would coerce the string to a number; the AOT doesn't. Keep the operand numeric.");
608
609
  }
609
610
  // Negating the minimum overflows, so a whole number saturates the way `+ - *` do.
610
- if (source.op === '-' &&
611
+ if (source.operator === '-' &&
611
612
  (isIntSlot(operand.type) || operand.type.kind === 'int64')) {
612
613
  const is64Bit = operand.type.kind === 'int64' || math64;
613
614
  return is64Bit
@@ -615,23 +616,27 @@ function typeUnary(source, math64) {
615
616
  kind: 'helper',
616
617
  helper: 'neg',
617
618
  bits: 64,
618
- args: [operand],
619
+ callArguments: [operand],
619
620
  type: operand.type.kind === 'int64' ? operand.type : INT64_MATH,
620
621
  }
621
622
  : {
622
623
  kind: 'helper',
623
624
  helper: 'neg',
624
625
  bits: 32,
625
- args: [operand],
626
+ callArguments: [operand],
626
627
  type: INT,
627
628
  };
628
629
  }
629
630
  // Only `!` yields a boolean; unary +/- coerce to a number, so `+flag` drops its boolean-ness.
630
631
  return {
631
632
  kind: 'unary',
632
- op: source.op,
633
+ operator: source.operator,
633
634
  operand,
634
- type: source.op === '!' ? BOOL : isBoolean(operand.type) ? INT : operand.type,
635
+ type: source.operator === '!'
636
+ ? BOOL
637
+ : isBoolean(operand.type)
638
+ ? INT
639
+ : operand.type,
635
640
  };
636
641
  }
637
642
  /**
@@ -657,48 +662,47 @@ function typeBinary(source, math64) {
657
662
  }
658
663
  [left, right] = litPeers(left, right);
659
664
  // Arithmetic: refuse strings, hand 64-bit math to typeArith64, and saturate whole-number `+ - *`.
660
- if (ARITH.has(source.op)) {
665
+ if (ARITHMETIC.has(source.operator)) {
661
666
  if (left.type.kind === 'string' || right.type.kind === 'string') {
662
- // String `+` has no single C value; only a char-buffer destination can lower it, via emitFormat().
663
- if (source.op === '+') {
664
- throw aotError('AOT: string concatenation is not supported in this position', 'a `+` chain over strings lowers to a printf format, which only works where the value ' +
665
- 'lands in a text buffer: a <Text> body, a string useState setter, or a <TextInput ' +
666
- 'value>.');
667
+ // String `+` has no single value; only a destination that holds text can lower it, via lowerText().
668
+ if (source.operator === '+') {
669
+ throw aotError('AOT: string concatenation is not supported in this position', 'a `+` chain over strings only works where the value lands in text: a <Text> body, a string ' +
670
+ 'useState setter, or a <TextInput value>.');
667
671
  }
668
- // JS would coerce the string to a number; C would do pointer arithmetic or refuse to compile.
669
- throw aotError(`AOT: "${source.op}" on a string is not supported`, 'keep both operands numeric — a string cannot be coerced to a number here.');
672
+ // JS would coerce the string to a number; the AOT doesn't.
673
+ throw aotError(`AOT: "${source.operator}" on a string is not supported`, 'keep both operands numeric — a string cannot be coerced to a number here.');
670
674
  }
671
- // `/` takes a 64-bit constant as an ordinary C number; only a runtime 64-bit value is refused it.
675
+ // `/` takes a 64-bit constant as an ordinary number; only a runtime 64-bit value is refused it.
672
676
  if (isTime64(left) ||
673
677
  isTime64(right) ||
674
678
  ((left.type.kind === 'int64' || right.type.kind === 'int64') &&
675
- (CHECKED_HELPER[source.op] || source.op === '%'))) {
679
+ (CHECKED_HELPER[source.operator] || source.operator === '%'))) {
676
680
  return typeArith64(source, left, right);
677
681
  }
678
- if (source.op === '/') {
682
+ if (source.operator === '/') {
679
683
  return { kind: 'floatDivide', left, right, type: FLOAT };
680
684
  }
681
685
  const isFloat = left.type.kind === 'float' || right.type.kind === 'float';
682
- const checkedHelper = !isFloat && CHECKED_HELPER[source.op];
686
+ const checkedHelper = !isFloat && CHECKED_HELPER[source.operator];
683
687
  if (checkedHelper) {
684
688
  return math64
685
689
  ? {
686
690
  kind: 'helper',
687
691
  helper: checkedHelper,
688
692
  bits: 64,
689
- args: [left, right],
693
+ callArguments: [left, right],
690
694
  type: INT64_MATH,
691
695
  }
692
696
  : {
693
697
  kind: 'helper',
694
698
  helper: checkedHelper,
695
699
  bits: 32,
696
- args: [left, right],
700
+ callArguments: [left, right],
697
701
  type: INT,
698
702
  };
699
703
  }
700
- // A 0 divisor (NaN in JS) or -1 (INT_MIN % -1 overflows C) gives 0; other constants need no check.
701
- if (!isFloat && source.op === '%') {
704
+ // A 0 divisor (NaN in JS) or -1 (INT_MIN % -1 overflows) gives 0; other constants need no check.
705
+ if (!isFloat && source.operator === '%') {
702
706
  const staticDivisor = source.divisor.constant;
703
707
  if (staticDivisor === 0 || staticDivisor === -1) {
704
708
  return numConst(0);
@@ -708,48 +712,52 @@ function typeBinary(source, math64) {
708
712
  kind: 'helper',
709
713
  helper: 'mod',
710
714
  bits: 32,
711
- args: [left, right],
715
+ callArguments: [left, right],
712
716
  type: INT,
713
717
  };
714
718
  }
715
719
  }
716
- // C has no float `%`; fmodf matches JS's `%` exactly, zero and infinite divisors included.
717
- if (isFloat && source.op === '%') {
720
+ // fmod matches JS's `%` exactly, zero and infinite divisors included.
721
+ if (isFloat && source.operator === '%') {
718
722
  return {
719
723
  kind: 'floatMath',
720
- fn: 'mod',
721
- args: [left, right],
724
+ mathFunction: 'mod',
725
+ callArguments: [left, right],
722
726
  type: FLOAT,
723
727
  };
724
728
  }
725
729
  return {
726
730
  kind: 'arithmetic',
727
- op: source.op,
731
+ operator: source.operator,
728
732
  left,
729
733
  right,
730
734
  type: isFloat ? FLOAT : INT,
731
735
  };
732
736
  }
733
- // Comparisons: strings through strcmp, everything else as a plain C comparison yielding a boolean.
734
- if (COMPARE.has(source.op)) {
735
- const cOperator = source.op === '===' ? '==' : source.op === '!==' ? '!=' : source.op;
737
+ // Comparisons: strings by their text, everything else as a plain comparison yielding a boolean.
738
+ if (COMPARE.has(source.operator)) {
739
+ const comparison = source.operator === '==='
740
+ ? '=='
741
+ : source.operator === '!=='
742
+ ? '!='
743
+ : source.operator;
736
744
  if (left.type.kind === 'string' || right.type.kind === 'string') {
737
745
  if (slotOf(left.type) !== slotOf(right.type)) {
738
746
  // A strict comparison never coerces, so a string against a number is decided statically.
739
- if (source.op === '===' || source.op === '!==') {
740
- return boolConst(source.op === '!==');
747
+ if (source.operator === '===' || source.operator === '!==') {
748
+ return boolConst(source.operator === '!==');
741
749
  }
742
- throw aotError('AOT: a string cannot be compared with a number', `\`${source.op}\` coerces the string to a number in JS, which C cannot reproduce. ` +
750
+ throw aotError('AOT: a string cannot be compared with a number', `\`${source.operator}\` coerces the string to a number in JS, which the AOT doesn't reproduce. ` +
743
751
  `Compare like with like, or use === / !== (which never coerce).`);
744
752
  }
745
753
  // Equality is exact, but strcmp's UTF-8 order can differ from JS's UTF-16 order, so refuse ordering.
746
- if (cOperator !== '==' && cOperator !== '!=') {
747
- throw aotError(`AOT: ordering strings with "${source.op}" is not supported`, 'JS orders strings by UTF-16 code unit but the device holds UTF-8, so the order can ' +
754
+ if (comparison !== '==' && comparison !== '!=') {
755
+ throw aotError(`AOT: ordering strings with "${source.operator}" is not supported`, 'JS orders strings by UTF-16 code unit but the device holds UTF-8, so the order can ' +
748
756
  'differ. Use === / !==, or compare numbers.');
749
757
  }
750
758
  return {
751
759
  kind: 'stringEquals',
752
- op: cOperator,
760
+ operator: comparison,
753
761
  left,
754
762
  right,
755
763
  type: BOOL,
@@ -760,25 +768,25 @@ function typeBinary(source, math64) {
760
768
  (left.type.kind === 'float' || right.type.kind === 'float')) {
761
769
  throw mix64Error();
762
770
  }
763
- // `true === 1` is false in JS but true in C's int slot; fold it when the other side is surely a number.
771
+ // `true === 1` is false in JS but true in an int slot; fold it when the other side is surely a number.
764
772
  const isSurelyNumber = (isWrittenAsNumber, operand) => !isBoolean(operand.type) &&
765
773
  (operand.type.kind === 'float' ||
766
774
  operand.type.kind === 'int64' ||
767
775
  isWrittenAsNumber);
768
- if ((source.op === '===' || source.op === '!==') &&
776
+ if ((source.operator === '===' || source.operator === '!==') &&
769
777
  ((isBoolean(left.type) && isSurelyNumber(source.rightIsNumber, right)) ||
770
778
  (isBoolean(right.type) && isSurelyNumber(source.leftIsNumber, left)))) {
771
- return boolConst(source.op === '!==');
779
+ return boolConst(source.operator === '!==');
772
780
  }
773
781
  return {
774
782
  kind: 'compare',
775
- op: cOperator,
783
+ operator: comparison,
776
784
  left,
777
785
  right,
778
786
  type: BOOL,
779
787
  };
780
788
  }
781
- throw new Error(`AOT: unsupported binary operator "${source.op}"`);
789
+ throw new Error(`AOT: unsupported binary operator "${source.operator}"`);
782
790
  }
783
791
  /**
784
792
  * Types `&&` / `||`. JS returns an operand, so with a 64-bit side the value is kept instead of collapsing it
@@ -796,30 +804,30 @@ function typeLogical(source, math64) {
796
804
  throw mix64Error();
797
805
  }
798
806
  if (left.type.kind === 'string' || right.type.kind === 'string') {
799
- throw aotError(`AOT: "${source.op}" cannot mix a 64-bit time value with a string`, 'keep both sides numbers, or write the branch out: {ms ? ms : 0}.');
807
+ throw aotError(`AOT: "${source.operator}" cannot mix a 64-bit time value with a string`, 'keep both sides numbers, or write the branch out: {ms ? ms : 0}.');
800
808
  }
801
809
  if (isBoolean(left.type) || isBoolean(right.type)) {
802
- throw bool64Error(`"${source.op}"`);
810
+ throw bool64Error(`"${source.operator}"`);
803
811
  }
804
812
  return {
805
813
  kind: 'pick',
806
- op: source.op,
814
+ operator: source.operator,
807
815
  left,
808
816
  right,
809
817
  type: int64Join(left.type, right.type),
810
818
  };
811
819
  }
812
- // Otherwise the C result is the truth of the expression, a boolean only when both operands are.
820
+ // Otherwise the result is the truth of the expression, a boolean only when both operands are.
813
821
  return {
814
822
  kind: 'logical',
815
- op: source.op,
823
+ operator: source.operator,
816
824
  left,
817
825
  right,
818
826
  type: isBoolean(left.type) && isBoolean(right.type) ? BOOL : INT,
819
827
  };
820
828
  }
821
829
  /**
822
- * Types `test ? consequent : alternate`. Both branches share one C slot: float or 64-bit if either is, and a
830
+ * Types `test ? consequent : alternate`. Both branches share one slot: float or 64-bit if either is, and a
823
831
  * 64-bit branch beside a float or a boolean one is refused.
824
832
  *
825
833
  * @param source The expression.
@@ -830,7 +838,7 @@ function typeLogical(source, math64) {
830
838
  function typeConditional(source, math64) {
831
839
  const test = typeSource(source.test, math64);
832
840
  const [consequent, alternate] = litPeers(typeSource(source.consequent, math64), typeSource(source.alternate, math64));
833
- // A string branch beside a numeric one is ill-typed C with no single printf spec, so refuse it here.
841
+ // A string branch beside a numeric one has no single type, so refuse it here.
834
842
  if ((consequent.type.kind === 'string') !==
835
843
  (alternate.type.kind === 'string')) {
836
844
  throw aotError('AOT: a ternary cannot mix a string branch with a numeric one', "both branches must be the same kind — quote the number to keep it text, e.g. {ok ? '1' : 'none'}.");
@@ -870,71 +878,81 @@ function typeConditional(source, math64) {
870
878
  * @returns The typed call.
871
879
  */
872
880
  function typeMath(source, math64) {
873
- const { fn } = source;
881
+ const { mathFunction } = source;
882
+ // Math.min and Math.max take any number of values, the IR's two: the rest go pairwise, left to right.
883
+ if ((mathFunction === 'min' || mathFunction === 'max') &&
884
+ source.callArguments.length > 2) {
885
+ const [first, second, ...rest] = source.callArguments;
886
+ return typeMath(rest.reduce((pairs, argument) => ({ ...source, callArguments: [pairs, argument] }), { ...source, callArguments: [first, second] }), math64);
887
+ }
874
888
  if (source.exactDivision) {
875
- const division = source.args[0];
876
- const timeDiv = typeTimeRoundDiv(fn, division, math64);
877
- if (timeDiv)
878
- return timeDiv;
879
- const intDiv = typeIntRoundDiv(fn, division, math64);
880
- if (intDiv)
881
- return intDiv;
889
+ const division = source.callArguments[0];
890
+ const timeDivision = typeTimeRoundDiv(mathFunction, division, math64);
891
+ if (timeDivision)
892
+ return timeDivision;
893
+ const intDivision = typeIntRoundDiv(mathFunction, division, math64);
894
+ if (intDivision)
895
+ return intDivision;
882
896
  }
883
- let argExprs = litPeers(...source.args.map(arg => typeSource(arg, math64)));
884
- if (argExprs.some(argExpr => argExpr.type.kind === 'int64')) {
897
+ let argumentExpressions = litPeers(...source.callArguments.map(argument => typeSource(argument, math64)));
898
+ if (argumentExpressions.some(argumentExpression => argumentExpression.type.kind === 'int64')) {
885
899
  // Whole-number Math keeps a 64-bit value exact, and a time takes nothing else; the rest works on floats.
886
- if (WHOLE_MATH.has(fn) || argExprs.some(isTime64)) {
887
- return typeMath64(fn, argExprs);
900
+ if (WHOLE_MATH.has(mathFunction) || argumentExpressions.some(isTime64)) {
901
+ return typeMath64(mathFunction, argumentExpressions);
888
902
  }
889
- argExprs = argExprs.map((argExpr) => argExpr.type.kind === 'int64'
890
- ? { kind: 'toFloat', operand: argExpr, type: FLOAT }
891
- : argExpr);
903
+ argumentExpressions = argumentExpressions.map((argumentExpression) => argumentExpression.type.kind === 'int64'
904
+ ? { kind: 'toFloat', operand: argumentExpression, type: FLOAT }
905
+ : argumentExpression);
892
906
  }
893
907
  // Keep int abs/min/max whole (a float rounds past 2^24); with math64, abs widens to keep |INT_MIN|.
894
- if (argExprs.length && argExprs.every(argExpr => isIntSlot(argExpr.type))) {
895
- if (fn === 'abs' && argExprs.length === 1) {
908
+ if (argumentExpressions.length &&
909
+ argumentExpressions.every(argumentExpression => isIntSlot(argumentExpression.type))) {
910
+ if (mathFunction === 'abs' && argumentExpressions.length === 1) {
896
911
  return math64
897
912
  ? {
898
913
  kind: 'helper',
899
914
  helper: 'abs',
900
915
  bits: 64,
901
- args: [argExprs[0]],
916
+ callArguments: [argumentExpressions[0]],
902
917
  type: INT64_MATH,
903
918
  }
904
919
  : {
905
920
  kind: 'helper',
906
921
  helper: 'abs',
907
922
  bits: 32,
908
- args: [argExprs[0]],
923
+ callArguments: [argumentExpressions[0]],
909
924
  type: INT,
910
925
  };
911
926
  }
912
- if ((fn === 'min' || fn === 'max') && argExprs.length === 2) {
927
+ if ((mathFunction === 'min' || mathFunction === 'max') &&
928
+ argumentExpressions.length === 2) {
913
929
  return {
914
930
  kind: 'helper',
915
- helper: fn,
931
+ helper: mathFunction,
916
932
  bits: 32,
917
- args: [argExprs[0], argExprs[1]],
933
+ callArguments: [argumentExpressions[0], argumentExpressions[1]],
918
934
  type: INT,
919
935
  };
920
936
  }
921
937
  }
922
- // Math.trunc stays an int: an int as is, a float via app_f2i (toward zero, NaN as 0, saturating).
923
- if (fn === 'trunc' && argExprs.length === 1) {
924
- return isIntSlot(argExprs[0].type)
925
- ? { kind: 'wholeRound', operand: argExprs[0], type: INT }
926
- : { kind: 'trunc', operand: argExprs[0], type: INT };
938
+ // Math.trunc stays an int: an int as is, a float truncated (toward zero, NaN as 0, saturating).
939
+ if (mathFunction === 'trunc' && argumentExpressions.length === 1) {
940
+ return isIntSlot(argumentExpressions[0].type)
941
+ ? { kind: 'wholeRound', operand: argumentExpressions[0], type: INT }
942
+ : { kind: 'trunc', operand: argumentExpressions[0], type: INT };
927
943
  }
928
- if (FLOAT_MATH_UNARY.has(fn) && argExprs.length === 1) {
944
+ if (FLOAT_MATH_UNARY.has(mathFunction) && argumentExpressions.length === 1) {
929
945
  // An int is already whole, so rounding leaves it as it is; a float round trip would lose digits.
930
- const roundsToWhole = fn === 'round' || fn === 'floor' || fn === 'ceil';
931
- if (roundsToWhole && isIntSlot(argExprs[0].type)) {
932
- return { kind: 'wholeRound', operand: argExprs[0], type: INT };
946
+ const roundsToWhole = mathFunction === 'round' ||
947
+ mathFunction === 'floor' ||
948
+ mathFunction === 'ceil';
949
+ if (roundsToWhole && isIntSlot(argumentExpressions[0].type)) {
950
+ return { kind: 'wholeRound', operand: argumentExpressions[0], type: INT };
933
951
  }
934
952
  const floatCall = {
935
953
  kind: 'floatMath',
936
- fn: fn,
937
- args: [argExprs[0]],
954
+ mathFunction: mathFunction,
955
+ callArguments: [argumentExpressions[0]],
938
956
  type: FLOAT,
939
957
  };
940
958
  // round/floor/ceil yield a whole number, kept as an int so %d / int assignments are correct.
@@ -942,15 +960,15 @@ function typeMath(source, math64) {
942
960
  ? { kind: 'toInt', operand: floatCall, type: INT }
943
961
  : floatCall;
944
962
  }
945
- if (FLOAT_MATH_BINARY.has(fn) && argExprs.length === 2) {
963
+ if (FLOAT_MATH_BINARY.has(mathFunction) && argumentExpressions.length === 2) {
946
964
  return {
947
965
  kind: 'floatMath',
948
- fn: fn,
949
- args: [argExprs[0], argExprs[1]],
966
+ mathFunction: mathFunction,
967
+ callArguments: [argumentExpressions[0], argumentExpressions[1]],
950
968
  type: FLOAT,
951
969
  };
952
970
  }
953
- throw new Error(`AOT: unsupported Math.${fn}(...) (arity ${argExprs.length})`);
971
+ throw new Error(`AOT: unsupported Math.${mathFunction}(...) (arity ${argumentExpressions.length})`);
954
972
  }
955
973
  /**
956
974
  * The typing pass over one source expression: gives it its type and decides how it is computed. Pure, so a
@@ -975,8 +993,9 @@ export function typeSource(source, math64) {
975
993
  return boolConst(source.value);
976
994
  case 'state': {
977
995
  const { state } = source;
978
- const assumed = (state.cType === 'int' || state.cType === 'i64') && !state.isBool
979
- ? assumedWide?.get(state.cField)
996
+ const assumed = (state.slotKind === 'int' || state.slotKind === 'i64') &&
997
+ !state.isBoolean
998
+ ? assumedWide?.get(state.slotName)
980
999
  : undefined;
981
1000
  return {
982
1001
  kind: 'state',
@@ -991,8 +1010,9 @@ export function typeSource(source, math64) {
991
1010
  : localRead(source.local);
992
1011
  case 'ref': {
993
1012
  const { ref } = source;
994
- const assumed = ref.kind === 'value' && (ref.cType === 'int' || ref.cType === 'i64')
995
- ? assumedWide?.get(ref.cVar)
1013
+ const assumed = ref.kind === 'value' &&
1014
+ (ref.slotKind === 'int' || ref.slotKind === 'i64')
1015
+ ? assumedWide?.get(ref.slotName)
996
1016
  : undefined;
997
1017
  return {
998
1018
  kind: 'ref',
@@ -1001,7 +1021,7 @@ export function typeSource(source, math64) {
1001
1021
  };
1002
1022
  }
1003
1023
  case 'fixed':
1004
- return source.expr;
1024
+ return source.expression;
1005
1025
  case 'unary':
1006
1026
  return typeUnary(source, wide);
1007
1027
  case 'binary':
@@ -1015,7 +1035,7 @@ export function typeSource(source, math64) {
1015
1035
  }
1016
1036
  }
1017
1037
  catch (error) {
1018
- locateError(error, source.loc);
1038
+ locateError(error, source.location);
1019
1039
  throw error;
1020
1040
  }
1021
1041
  }
@@ -1062,46 +1082,51 @@ export function inferWideSlots(stores, wide) {
1062
1082
  /**
1063
1083
  * Whether two sets of slot widths are the same.
1064
1084
  *
1065
- * @param a One set.
1066
- * @param b The other.
1085
+ * @param left One set.
1086
+ * @param right The other.
1067
1087
  *
1068
1088
  * @returns True when every slot holds the same in both.
1069
1089
  */
1070
- export const sameSlotWidths = (a, b) => a.size === b.size && [...a].every(([slot, holds]) => b.get(slot) === holds);
1090
+ export const sameSlotWidths = (left, right) => left.size === right.size &&
1091
+ [...left].every(([slot, holds]) => right.get(slot) === holds);
1071
1092
  /**
1072
1093
  * Whether an operand is written as a number, so a boolean on the other side of `===` never equals it: a
1073
1094
  * numeric literal, a negated one, or a non-boolean state read by name.
1074
1095
  *
1075
1096
  * @param node The operand.
1076
- * @param env The expression environment.
1097
+ * @param environment The expression environment.
1077
1098
  *
1078
1099
  * @returns True when it is surely a number.
1079
1100
  */
1080
- const isWrittenAsNumber = (node, env) => node.type === 'NumericLiteral' ||
1101
+ const isWrittenAsNumber = (node, environment) => node.type === 'NumericLiteral' ||
1081
1102
  (node.type === 'UnaryExpression' &&
1082
1103
  node.argument.type === 'NumericLiteral') ||
1083
1104
  (node.type === 'Identifier' &&
1084
- !env.locals.has(node.name) &&
1085
- env.state.get(node.name)?.isBool === false);
1105
+ !environment.locals.has(node.name) &&
1106
+ environment.state.get(node.name)?.isBoolean ===
1107
+ false);
1086
1108
  /**
1087
1109
  * A binary expression's source, from its operands' sources.
1088
1110
  *
1089
1111
  * @param node The expression.
1090
1112
  * @param left Its left operand's source.
1091
1113
  * @param right Its right operand's source.
1092
- * @param env The expression environment.
1114
+ * @param environment The expression environment.
1093
1115
  *
1094
1116
  * @returns The source.
1095
1117
  */
1096
- const binarySource = (node, left, right, env) => ({
1118
+ const binarySource = (node, left, right, environment) => ({
1097
1119
  kind: 'binary',
1098
- op: node.operator,
1120
+ operator: node.operator,
1099
1121
  left,
1100
1122
  right,
1101
- divisor: { constant: staticInt(node.right, env), loc: node.right.loc?.start },
1102
- leftIsNumber: isWrittenAsNumber(node.left, env),
1103
- rightIsNumber: isWrittenAsNumber(node.right, env),
1104
- loc: node.loc?.start,
1123
+ divisor: {
1124
+ constant: staticInt(node.right, environment),
1125
+ location: node.right.loc?.start,
1126
+ },
1127
+ leftIsNumber: isWrittenAsNumber(node.left, environment),
1128
+ rightIsNumber: isWrittenAsNumber(node.right, environment),
1129
+ location: node.loc?.start,
1105
1130
  });
1106
1131
  /**
1107
1132
  * Whether `node` is the handler's event, or its `nativeEvent` as React Native code reads it.
@@ -1127,80 +1152,89 @@ function isEventRoot(node, event) {
1127
1152
  * in turn, so an error in it is reported before anything after it.
1128
1153
  *
1129
1154
  * @param node The expression.
1130
- * @param env The expression environment.
1155
+ * @param environment The expression environment.
1131
1156
  *
1132
1157
  * @returns The source.
1133
1158
  */
1134
- function sourceOf(node, env) {
1135
- const loc = node.loc?.start;
1159
+ function sourceOf(node, environment) {
1160
+ const location = node.loc?.start;
1136
1161
  // An expression that depends only on the panel is read from a slot worked out at boot, in doubles as JS.
1137
1162
  const whole = WHOLE_BOOT_TYPES.has(node.type)
1138
- ? wholeBootSource(node, env, loc)
1163
+ ? wholeBootSource(node, environment, location)
1139
1164
  : null;
1140
1165
  if (whole)
1141
1166
  return whole;
1142
- const operand = (operandNode) => lowerSource(operandNode, env).source;
1167
+ const operand = (operandNode) => lowerSource(operandNode, environment).source;
1143
1168
  switch (node.type) {
1144
1169
  case 'NumericLiteral':
1145
- return numberSource(node.value, loc);
1170
+ return numberSource(node.value, location);
1146
1171
  case 'StringLiteral':
1147
- return { kind: 'string', value: node.value, loc };
1172
+ return { kind: 'string', value: node.value, location };
1148
1173
  case 'BooleanLiteral':
1149
- return { kind: 'boolean', value: node.value, loc };
1174
+ return { kind: 'boolean', value: node.value, location };
1150
1175
  case 'Identifier': {
1151
1176
  // A name resolves to a local first, then to state, then to a compile-time constant.
1152
- if (env.locals.has(node.name)) {
1153
- return { kind: 'local', local: env.locals.get(node.name), loc };
1177
+ if (environment.locals.has(node.name)) {
1178
+ return {
1179
+ kind: 'local',
1180
+ local: environment.locals.get(node.name),
1181
+ location,
1182
+ };
1154
1183
  }
1155
- if (env.state.has(node.name)) {
1156
- const stateRecord = env.state.get(node.name);
1184
+ if (environment.state.has(node.name)) {
1185
+ const stateRecord = environment.state.get(node.name);
1157
1186
  if (stateRecord.kind === 'list') {
1158
1187
  throw new Error(`AOT: a list state ("${node.name}") can only be used via .length or .map`);
1159
1188
  }
1160
- return { kind: 'state', state: stateRecord, loc };
1189
+ return { kind: 'state', state: stateRecord, location };
1161
1190
  }
1162
- if (hasBinding(env.consts, node.name)) {
1163
- const constValue = env.consts[node.name];
1164
- if (isBoot(constValue))
1165
- return bootSource(constValue, loc);
1166
- if (typeof constValue === 'number')
1167
- return numberSource(constValue, loc);
1168
- if (typeof constValue === 'string') {
1169
- return { kind: 'string', value: constValue, loc };
1191
+ if (hasBinding(environment.constants, node.name)) {
1192
+ const constantValue = environment.constants[node.name];
1193
+ if (isBoot(constantValue))
1194
+ return bootSource(constantValue, location);
1195
+ if (typeof constantValue === 'number')
1196
+ return numberSource(constantValue, location);
1197
+ if (typeof constantValue === 'string') {
1198
+ return { kind: 'string', value: constantValue, location };
1170
1199
  }
1171
- if (typeof constValue === 'boolean') {
1172
- return { kind: 'boolean', value: constValue, loc };
1200
+ if (typeof constantValue === 'boolean') {
1201
+ return { kind: 'boolean', value: constantValue, location };
1173
1202
  }
1174
1203
  }
1175
1204
  throw new Error(`AOT: cannot resolve identifier "${node.name}" in a dynamic expression`);
1176
1205
  }
1177
1206
  case 'UnaryExpression': {
1178
1207
  // A constant is negated here, so `-A` is its value, and -2147483648 is not an int overflow.
1179
- const staticOperand = node.operator === '-' ? staticInt(node.argument, env) : null;
1208
+ const staticOperand = node.operator === '-' ? staticInt(node.argument, environment) : null;
1180
1209
  if (staticOperand !== null)
1181
- return numberSource(-staticOperand, loc);
1210
+ return numberSource(-staticOperand, location);
1182
1211
  const operandSource = operand(node.argument);
1183
1212
  if (node.operator === '-' ||
1184
1213
  node.operator === '+' ||
1185
1214
  node.operator === '!') {
1186
- return { kind: 'unary', op: node.operator, operand: operandSource, loc };
1215
+ return {
1216
+ kind: 'unary',
1217
+ operator: node.operator,
1218
+ operand: operandSource,
1219
+ location,
1220
+ };
1187
1221
  }
1188
1222
  throw new Error(`AOT: unsupported unary operator "${node.operator}"`);
1189
1223
  }
1190
1224
  case 'BinaryExpression': {
1191
1225
  // Fold `+ - *` over two whole-number constants as JS would, so a product past int range stays exact.
1192
- const leftConst = CHECKED_HELPER[node.operator]
1193
- ? staticInt(node.left, env)
1226
+ const leftConstant = CHECKED_HELPER[node.operator]
1227
+ ? staticInt(node.left, environment)
1194
1228
  : null;
1195
- const rightConst = leftConst === null ? null : staticInt(node.right, env);
1196
- if (rightConst !== null) {
1229
+ const rightConstant = leftConstant === null ? null : staticInt(node.right, environment);
1230
+ if (rightConstant !== null) {
1197
1231
  return numberSource(node.operator === '+'
1198
- ? leftConst + rightConst
1232
+ ? leftConstant + rightConstant
1199
1233
  : node.operator === '-'
1200
- ? leftConst - rightConst
1201
- : leftConst * rightConst, loc);
1234
+ ? leftConstant - rightConstant
1235
+ : leftConstant * rightConstant, location);
1202
1236
  }
1203
- return binarySource(node, operand(node.left), operand(node.right), env);
1237
+ return binarySource(node, operand(node.left), operand(node.right), environment);
1204
1238
  }
1205
1239
  case 'LogicalExpression': {
1206
1240
  // Only `&&` and `||` are supported (not `??`).
@@ -1210,10 +1244,10 @@ function sourceOf(node, env) {
1210
1244
  }
1211
1245
  return {
1212
1246
  kind: 'logical',
1213
- op: operator,
1247
+ operator: operator,
1214
1248
  left: operand(node.left),
1215
1249
  right: operand(node.right),
1216
- loc,
1250
+ location,
1217
1251
  };
1218
1252
  }
1219
1253
  case 'ConditionalExpression':
@@ -1222,23 +1256,23 @@ function sourceOf(node, env) {
1222
1256
  test: operand(node.test),
1223
1257
  consequent: operand(node.consequent),
1224
1258
  alternate: operand(node.alternate),
1225
- loc,
1259
+ location,
1226
1260
  };
1227
1261
  case 'MemberExpression': {
1228
1262
  // Static fold: member access that resolves to a compile-time constant (e.g., a .map item's `.key`).
1229
1263
  try {
1230
- const constValue = evalStatic(node, foldScope(env, env.consts ?? {}), 'boot');
1231
- if (isBoot(constValue))
1232
- return bootSource(constValue, loc);
1264
+ const constantValue = evalStatic(node, foldScope(environment, environment.constants ?? {}), 'boot');
1265
+ if (isBoot(constantValue))
1266
+ return bootSource(constantValue, location);
1233
1267
  // A number with no float form falls through too, so its check runs now, not in the check pass.
1234
- if (typeof constValue === 'number') {
1235
- return attemptLowering(() => numberSource(constValue, loc));
1268
+ if (typeof constantValue === 'number') {
1269
+ return attemptLowering(() => numberSource(constantValue, location));
1236
1270
  }
1237
- if (typeof constValue === 'string') {
1238
- return { kind: 'string', value: constValue, loc };
1271
+ if (typeof constantValue === 'string') {
1272
+ return { kind: 'string', value: constantValue, location };
1239
1273
  }
1240
- if (typeof constValue === 'boolean') {
1241
- return { kind: 'boolean', value: constValue, loc };
1274
+ if (typeof constantValue === 'boolean') {
1275
+ return { kind: 'boolean', value: constantValue, location };
1242
1276
  }
1243
1277
  }
1244
1278
  catch {
@@ -1247,22 +1281,26 @@ function sourceOf(node, env) {
1247
1281
  // Otherwise the object must be one of the runtime forms below; `prop` is null for a computed member.
1248
1282
  const object = node.object;
1249
1283
  const prop = node.computed ? null : node.property.name;
1250
- const fixed = (expr) => ({ kind: 'fixed', expr, loc });
1284
+ const fixed = (expression) => ({
1285
+ kind: 'fixed',
1286
+ expression,
1287
+ location,
1288
+ });
1251
1289
  // `<list>.length` → the runtime count.
1252
1290
  if (object.type === 'Identifier' &&
1253
- env.state.get(object.name)?.kind === 'list' &&
1291
+ environment.state.get(object.name)?.kind === 'list' &&
1254
1292
  prop === 'length') {
1255
1293
  return fixed({
1256
1294
  kind: 'listLength',
1257
- list: env.state.get(object.name),
1295
+ list: environment.state.get(object.name),
1258
1296
  type: INT,
1259
1297
  });
1260
1298
  }
1261
1299
  // `<item>.field` where item is a struct local (a list row's bound element).
1262
1300
  if (object.type === 'Identifier' &&
1263
- env.locals.get(object.name)?.struct &&
1301
+ environment.locals.get(object.name)?.struct &&
1264
1302
  prop) {
1265
- const item = env.locals.get(object.name);
1303
+ const item = environment.locals.get(object.name);
1266
1304
  const field = item.struct.fields.find(structField => structField.key === prop);
1267
1305
  if (!field) {
1268
1306
  throw new Error(`AOT: unknown field "${prop}" on a list item`);
@@ -1274,37 +1312,39 @@ function sourceOf(node, env) {
1274
1312
  type: typeOfSlot(field.kind),
1275
1313
  });
1276
1314
  }
1277
- // `<ref>.current` — a value ref's mutable C slot.
1315
+ // `<ref>.current` — a value ref's mutable slot.
1278
1316
  if (object.type === 'Identifier' &&
1279
- env.refs?.has(object.name) &&
1317
+ environment.refs?.has(object.name) &&
1280
1318
  prop === 'current') {
1281
- const ref = env.refs.get(object.name);
1319
+ const ref = environment.refs.get(object.name);
1282
1320
  ref.used = true;
1283
- return { kind: 'ref', ref, loc };
1321
+ return { kind: 'ref', ref, location };
1284
1322
  }
1285
1323
  // `<event>.x / .y / .dx / .dy` — touch fields of the handler's EREventData.
1286
1324
  if (object.type === 'Identifier' &&
1287
- env.event === object.name &&
1325
+ environment.event === object.name &&
1288
1326
  (prop === 'x' || prop === 'y' || prop === 'dx' || prop === 'dy')) {
1289
1327
  return fixed({ kind: 'event', field: prop, type: INT });
1290
1328
  }
1291
1329
  // `<event>.vx / .vy` — finger velocity (px/ms) at the last move; the engine measures it, a handler cannot.
1292
1330
  if (object.type === 'Identifier' &&
1293
- env.event === object.name &&
1331
+ environment.event === object.name &&
1294
1332
  (prop === 'vx' || prop === 'vy')) {
1295
1333
  return fixed({ kind: 'event', field: prop, type: FLOAT });
1296
1334
  }
1297
1335
  // `<gestureState>.…` — the second argument of a PanResponder callback (see emitPanResponder).
1298
- if (object.type === 'Identifier' && env.gesture === object.name && prop) {
1299
- return fixed(lowerGestureField(prop, env.pan));
1336
+ if (object.type === 'Identifier' &&
1337
+ environment.gesture === object.name &&
1338
+ prop) {
1339
+ return fixed(lowerGestureField(prop, environment.pan));
1300
1340
  }
1301
1341
  // `<event>.layout.x / .y / .width / .height` — the onLayout rect, also read as
1302
1342
  // `<event>.nativeEvent.layout.…` as in React Native.
1303
1343
  if (object.type === 'MemberExpression' &&
1304
1344
  !object.computed &&
1305
1345
  object.property.name === 'layout' &&
1306
- isEventRoot(object.object, env.event)) {
1307
- if (!env.layout) {
1346
+ isEventRoot(object.object, environment.event)) {
1347
+ if (!environment.layout) {
1308
1348
  throw aotError('AOT: only an onLayout event carries a layout rect', 'read e.layout (or e.nativeEvent.layout) inside an onLayout handler.');
1309
1349
  }
1310
1350
  if (!LAYOUT_FIELDS.has(prop)) {
@@ -1330,12 +1370,12 @@ function sourceOf(node, env) {
1330
1370
  callee.object.type === 'Identifier' &&
1331
1371
  (callee.object.name === 'Date' ||
1332
1372
  callee.object.name === 'performance') &&
1333
- !env.shadowedClock?.has(node)) {
1373
+ !environment.shadowedClock?.has(node)) {
1334
1374
  if (callee.property.name === 'now') {
1335
1375
  return {
1336
1376
  kind: 'fixed',
1337
- expr: { kind: 'clock', clock: callee.object.name, type: TIME },
1338
- loc,
1377
+ expression: { kind: 'clock', clock: callee.object.name, type: TIME },
1378
+ location,
1339
1379
  };
1340
1380
  }
1341
1381
  if (callee.object.name === 'Date') {
@@ -1344,29 +1384,29 @@ function sourceOf(node, env) {
1344
1384
  }
1345
1385
  if (callee.type === 'Identifier' &&
1346
1386
  callee.name === 'Date' &&
1347
- !env.shadowedClock?.has(node)) {
1387
+ !environment.shadowedClock?.has(node)) {
1348
1388
  throw dateObjectError();
1349
1389
  }
1350
1390
  // Math.*: a division under floor / ceil / round / trunc stays apart, for the typing pass to divide exactly.
1351
1391
  if (callee.type === 'MemberExpression' &&
1352
1392
  callee.object.name === 'Math') {
1353
- const fn = callee.property.name;
1393
+ const mathFunction = callee.property.name;
1354
1394
  const division = node.arguments[0];
1355
- const exactDivision = INT_ROUND_DIV.has(fn) &&
1395
+ const exactDivision = INT_ROUND_DIVISION.has(mathFunction) &&
1356
1396
  node.arguments.length === 1 &&
1357
1397
  division.type === 'BinaryExpression' &&
1358
1398
  division.operator === '/';
1359
1399
  return {
1360
1400
  kind: 'math',
1361
- fn,
1362
- args: exactDivision
1401
+ mathFunction,
1402
+ callArguments: exactDivision
1363
1403
  ? [
1364
- binarySource(division, operand(division.left), operand(division.right), env),
1404
+ binarySource(division, operand(division.left), operand(division.right), environment),
1365
1405
  ]
1366
1406
  : node.arguments.map(operand),
1367
1407
  exactDivision,
1368
1408
  wholeMath: keepsMath64Node(node),
1369
- loc,
1409
+ location,
1370
1410
  };
1371
1411
  }
1372
1412
  throw new Error('AOT: unsupported call expression in a dynamic expression');
@@ -1375,7 +1415,7 @@ function sourceOf(node, env) {
1375
1415
  // `new Date(…)` gets the Date-specific error; any other constructor gets the generic one below.
1376
1416
  if (node.callee.type === 'Identifier' &&
1377
1417
  node.callee.name === 'Date' &&
1378
- !env.shadowedClock?.has(node)) {
1418
+ !environment.shadowedClock?.has(node)) {
1379
1419
  throw dateObjectError();
1380
1420
  }
1381
1421
  break;
@@ -1386,62 +1426,81 @@ function sourceOf(node, env) {
1386
1426
  * Lowers one JS expression to its source and types it, with the expression's location attached to any AOT
1387
1427
  * error either step throws.
1388
1428
  */
1389
- export const lowerSource = withLoc((node, env) => {
1429
+ export const lowerSource = withLoc((node, environment) => {
1390
1430
  // Below a node that is not whole-number math, its operands are typed as usual (see keepsMath64Node).
1391
- if (env.math64 && !keepsMath64Node(node)) {
1392
- env = { ...env, math64: false };
1431
+ if (environment.math64 && !keepsMath64Node(node)) {
1432
+ environment = { ...environment, math64: false };
1393
1433
  }
1394
- const source = sourceOf(node, env);
1395
- return { source, expr: typeSource(source, env.math64 ?? false) };
1434
+ const source = sourceOf(node, environment);
1435
+ return {
1436
+ source,
1437
+ expression: typeSource(source, environment.math64 ?? false),
1438
+ };
1396
1439
  });
1397
1440
  /**
1398
1441
  * Lowers one JS expression to the IR: its source, typed by the typing pass.
1399
1442
  *
1400
1443
  * @param node The expression.
1401
- * @param env The expression environment.
1444
+ * @param environment The expression environment.
1402
1445
  *
1403
1446
  * @returns The typed expression.
1404
1447
  */
1405
- export const lowerExprWide = (node, env) => lowerSource(node, env).expr;
1448
+ export const lowerExprWide = (node, environment) => lowerSource(node, environment).expression;
1406
1449
  /**
1407
- * emitExpr for the destinations that can hold a 64-bit timestamp: state, refs, locals, text, conditions.
1450
+ * What a slot holding an expression's value records about it. A bare local is the Local itself, so a list row keeps
1451
+ * its struct (extractProps copies it into a prop).
1408
1452
  *
1409
- * @param node The expression.
1410
- * @param env The expression environment.
1453
+ * @param expression The expression.
1411
1454
  *
1412
- * @returns The expression as C.
1455
+ * @returns The slot value.
1413
1456
  */
1414
- export const emitExprWide = (node, env) => toCExpr(lowerExprWide(node, env));
1457
+ export function slotValueOf(expression) {
1458
+ if (expression.kind === 'local') {
1459
+ return expression.local;
1460
+ }
1461
+ const value = { slotKind: slotOf(expression.type) };
1462
+ if (expression.type.kind === 'bool') {
1463
+ value.isBoolean = true;
1464
+ }
1465
+ else if (expression.type.kind === 'int64' &&
1466
+ expression.type.source !== 'time') {
1467
+ value[expression.type.source === 'number' ? 'isLiteral' : 'wide'] = true;
1468
+ }
1469
+ return value;
1470
+ }
1415
1471
  /**
1416
- * emitExprWide, for a local that holds the value: with the source it was lowered from, which the typing pass
1472
+ * lowerExprWide, for a local that holds the value: with the source it was lowered from, which the typing pass
1417
1473
  * reads when it infers slot widths.
1418
1474
  *
1419
1475
  * @param node The expression.
1420
- * @param env The expression environment.
1476
+ * @param environment The expression environment.
1421
1477
  *
1422
- * @returns The expression as C, and its source.
1478
+ * @returns The slot value, its source, and the typed expression.
1423
1479
  */
1424
- export function emitSourcedWide(node, env) {
1425
- const lowered = lowerSource(node, env);
1426
- return { ...toCExpr(lowered.expr), source: lowered.source };
1480
+ export function lowerSourcedWide(node, environment) {
1481
+ const lowered = lowerSource(node, environment);
1482
+ return {
1483
+ ...slotValueOf(lowered.expression),
1484
+ source: lowered.source,
1485
+ expression: lowered.expression,
1486
+ };
1427
1487
  }
1428
1488
  /**
1429
- * Lowers an expression for a destination that holds an int, a float, or a string. C would narrow a 64-bit
1430
- * value (a Date.now() / performance.now() timestamp, or a whole number past the int range) into one of those
1431
- * without a warning, so it is refused here; the destinations that hold 64 bits call lowerExprWide.
1489
+ * Lowers an expression for a destination that holds an int, a float, or a string. A 64-bit value (a Date.now() /
1490
+ * performance.now() timestamp, or a whole number past the int range) would be cut narrowing into one of those, so it
1491
+ * is refused here; the destinations that hold 64 bits call lowerExprWide.
1432
1492
  *
1433
- * The result carries its type, so the caller can pick the right printf spec or assignment. A destination
1434
- * that holds text lowers through lowerText instead.
1493
+ * The result carries its type. A destination that holds text lowers through lowerText instead.
1435
1494
  *
1436
1495
  * @param node The expression.
1437
- * @param env The expression environment.
1496
+ * @param environment The expression environment.
1438
1497
  *
1439
1498
  * @returns The lowered expression; never 64-bit.
1440
1499
  */
1441
- export function lowerExpr(node, env) {
1442
- const expr = lowerExprWide(node, env);
1443
- if (expr.type.kind !== 'int64')
1444
- return expr;
1500
+ export function lowerExpr(node, environment) {
1501
+ const expression = lowerExprWide(node, environment);
1502
+ if (expression.type.kind !== 'int64')
1503
+ return expression;
1445
1504
  const error = aotError('AOT: a 64-bit value (Date.now() / performance.now(), or a whole number past ±2^31) cannot be used here', 'keep it in state, a ref or a local, compare it, or show it in text. Anywhere else, ' +
1446
1505
  'reduce it to a small number first — e.g. `ms % 1000`, or `Math.floor(ms / 1000) % ' +
1447
1506
  '60`.');
@@ -1450,17 +1509,6 @@ export function lowerExpr(node, env) {
1450
1509
  }
1451
1510
  throw error;
1452
1511
  }
1453
- /**
1454
- * lowerExpr, as C: what the emitters that do not build the IR yet use.
1455
- *
1456
- * @param node The expression.
1457
- * @param env The expression environment.
1458
- *
1459
- * @returns The expression as C; never 64-bit.
1460
- */
1461
- export function emitExpr(node, env) {
1462
- return toCExpr(lowerExpr(node, env));
1463
- }
1464
1512
  /**
1465
1513
  * An aotError pinned to the expression that cannot be lowered to text (lowerTextParts is not withLoc-wrapped).
1466
1514
  *
@@ -1495,13 +1543,13 @@ export const jsxChildText = (value) => value === undefined || value === null ||
1495
1543
  * appends. Each part is literal text, a runtime value, or a boolean printed as a word.
1496
1544
  *
1497
1545
  * @param node The expression.
1498
- * @param env The expression environment.
1546
+ * @param environment The expression environment.
1499
1547
  * @param scope The constants a fold may read (already filtered by foldScope).
1500
1548
  * @param isOperand The expression is an operand of `+`, where null / undefined / booleans print as words.
1501
1549
  *
1502
1550
  * @returns The parts, and whether JS would treat the expression as a string.
1503
1551
  */
1504
- function lowerTextParts(node, env, scope, isOperand = false) {
1552
+ function lowerTextParts(node, environment, scope, isOperand = false) {
1505
1553
  // `undefined` is "" as a child but "undefined" in a `+`; handled here, not in the fold every prop reader shares.
1506
1554
  if (node.type === 'Identifier' && node.name === 'undefined') {
1507
1555
  return {
@@ -1511,13 +1559,13 @@ function lowerTextParts(node, env, scope, isOperand = false) {
1511
1559
  }
1512
1560
  // A compile-time constant becomes literal text; a value worked out at boot is a runtime value.
1513
1561
  try {
1514
- const constValue = evalStatic(node, scope, 'strict');
1562
+ const constantValue = evalStatic(node, scope, 'strict');
1515
1563
  return {
1516
- isString: typeof constValue === 'string',
1564
+ isString: typeof constantValue === 'string',
1517
1565
  parts: [
1518
1566
  {
1519
1567
  kind: 'literal',
1520
- text: isOperand ? String(constValue) : jsxChildText(constValue),
1568
+ text: isOperand ? String(constantValue) : jsxChildText(constantValue),
1521
1569
  },
1522
1570
  ],
1523
1571
  };
@@ -1527,16 +1575,16 @@ function lowerTextParts(node, env, scope, isOperand = false) {
1527
1575
  }
1528
1576
  // A `+` with a string on either side is a concatenation: its parts are both sides' parts in order.
1529
1577
  if (node.type === 'BinaryExpression' && node.operator === '+') {
1530
- const leftParts = lowerTextParts(node.left, env, scope, true);
1531
- const rightParts = lowerTextParts(node.right, env, scope, true);
1578
+ const leftParts = lowerTextParts(node.left, environment, scope, true);
1579
+ const rightParts = lowerTextParts(node.right, environment, scope, true);
1532
1580
  if (leftParts.isString || rightParts.isString) {
1533
1581
  return { isString: true, parts: [...leftParts.parts, ...rightParts.parts] };
1534
1582
  }
1535
1583
  }
1536
1584
  // A branch or operand that concatenates needs its own format; refuse before lowerExpr's misleading error.
1537
- const concatenates = (subExpr) => subExpr.type === 'BinaryExpression' &&
1538
- subExpr.operator === '+' &&
1539
- lowerTextParts(subExpr, env, scope, true).isString;
1585
+ const concatenates = (subExpression) => subExpression.type === 'BinaryExpression' &&
1586
+ subExpression.operator === '+' &&
1587
+ lowerTextParts(subExpression, environment, scope, true).isString;
1540
1588
  if (node.type === 'ConditionalExpression' &&
1541
1589
  (concatenates(node.test) ||
1542
1590
  concatenates(node.consequent) ||
@@ -1551,17 +1599,17 @@ function lowerTextParts(node, env, scope, isOperand = false) {
1551
1599
  'string first in a string useState.');
1552
1600
  }
1553
1601
  // Anything else is one runtime value.
1554
- const value = lowerExprWide(node, env);
1555
- // C collapses `&&`/`||` to 0/1 and a ternary to one slot, so text matches JS only when operands agree in kind.
1602
+ const value = lowerExprWide(node, environment);
1603
+ // `&&`/`||` collapse to 0/1 and a ternary to one slot, so text matches JS only when operands agree in kind.
1556
1604
  if (node.type === 'LogicalExpression' && !isBoolean(value.type)) {
1557
1605
  throw textShapeError(node, `AOT: "${node.operator}" in text evaluates to one of its operands, not to true/false`, `\`a ${node.operator} b\` is a or b unless both sides are already booleans — the ` +
1558
- `generated C only has 0/1. Write the branch out instead: {cond ? 'yes' : ''}.`);
1606
+ `package only has 0/1. Write the branch out instead: {cond ? 'yes' : ''}.`);
1559
1607
  }
1560
1608
  if (node.type === 'ConditionalExpression' &&
1561
- isBoolean(lowerExprWide(node.consequent, env).type) !==
1562
- isBoolean(lowerExprWide(node.alternate, env).type)) {
1609
+ isBoolean(lowerExprWide(node.consequent, environment).type) !==
1610
+ isBoolean(lowerExprWide(node.alternate, environment).type)) {
1563
1611
  throw textShapeError(node, 'AOT: a ternary in text mixes a boolean branch with a non-boolean one', 'JS renders those differently (`cond ? true : 5` is "true" or "5") but they share one ' +
1564
- 'C slot here. Make both branches the same kind.');
1612
+ 'slot here. Make both branches the same kind.');
1565
1613
  }
1566
1614
  // A boolean prints nothing as a child, "true"/"false" as an operand; isString stays false so `on + n` adds.
1567
1615
  if (isBoolean(value.type)) {
@@ -1579,23 +1627,14 @@ function lowerTextParts(node, env, scope, isOperand = false) {
1579
1627
  * <TextInput value>). A string-building `+` chain becomes its parts in order; anything else is one value.
1580
1628
  *
1581
1629
  * @param node The expression.
1582
- * @param env The expression environment.
1630
+ * @param environment The expression environment.
1583
1631
  * @param scope The constants a fold may read; by default the env's.
1584
1632
  *
1585
1633
  * @returns The text.
1586
1634
  */
1587
- export function lowerText(node, env, scope = env.consts ?? {}) {
1588
- return { parts: lowerTextParts(node, env, foldScope(env, scope)).parts };
1589
- }
1590
- /**
1591
- * lowerText, printed as one printf format and its arguments (one spec per runtime value, literals folded in).
1592
- *
1593
- * @param node The expression.
1594
- * @param env The expression environment.
1595
- * @param scope The constants a fold may read; by default the env's.
1596
- *
1597
- * @returns The format, with literal `%` already escaped as `%%`, and its arguments.
1598
- */
1599
- export function emitFormat(node, env, scope = env.consts ?? {}) {
1600
- return printText(lowerText(node, env, scope));
1635
+ export function lowerText(node, environment, scope = environment.constants ?? {}) {
1636
+ return {
1637
+ parts: lowerTextParts(node, environment, foldScope(environment, scope))
1638
+ .parts,
1639
+ };
1601
1640
  }