embedded-react 0.19.0 → 0.21.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 (148) hide show
  1. package/NOTICE +5 -0
  2. package/README.md +8 -3
  3. package/aot/app-file-loader.mjs +116 -0
  4. package/aot/compile.mjs +180 -90
  5. package/aot/compiler/animations.mjs +568 -317
  6. package/aot/compiler/boot.mjs +97 -35
  7. package/aot/compiler/branch-merge.mjs +4 -3
  8. package/aot/compiler/check.mjs +70 -18
  9. package/aot/compiler/collect.mjs +787 -288
  10. package/aot/compiler/contexts.mjs +391 -0
  11. package/aot/compiler/control-flow.mjs +439 -268
  12. package/aot/compiler/custom-hooks.mjs +686 -0
  13. package/aot/compiler/diagnostics.mjs +22 -25
  14. package/aot/compiler/elements/activity-indicator.mjs +25 -24
  15. package/aot/compiler/elements/button.mjs +182 -0
  16. package/aot/compiler/elements/dial.mjs +91 -77
  17. package/aot/compiler/elements/flat-list.mjs +24 -22
  18. package/aot/compiler/elements/image-background.mjs +76 -0
  19. package/aot/compiler/elements/image.mjs +52 -50
  20. package/aot/compiler/elements/modal.mjs +31 -30
  21. package/aot/compiler/elements/props.mjs +61 -26
  22. package/aot/compiler/elements/rewrite.mjs +118 -0
  23. package/aot/compiler/elements/section-list.mjs +370 -0
  24. package/aot/compiler/elements/switch.mjs +42 -34
  25. package/aot/compiler/elements/text-input.mjs +34 -32
  26. package/aot/compiler/expressions.mjs +1685 -392
  27. package/aot/compiler/handlers.mjs +2029 -547
  28. package/aot/compiler/helper-values.mjs +312 -0
  29. package/aot/compiler/ir/functions.mjs +11 -1
  30. package/aot/compiler/ir/nodes.mjs +43 -4
  31. package/aot/compiler/ir/reads.mjs +223 -22
  32. package/aot/compiler/ir/text.mjs +5 -1
  33. package/aot/compiler/ir/types.mjs +26 -14
  34. package/aot/compiler/ir/vectors.mjs +5 -1
  35. package/aot/compiler/kept-states.mjs +177 -0
  36. package/aot/compiler/keyboard.mjs +17 -7
  37. package/aot/compiler/list-items.mjs +226 -0
  38. package/aot/compiler/list-order.mjs +586 -0
  39. package/aot/compiler/list-split.mjs +259 -0
  40. package/aot/compiler/loops.mjs +582 -0
  41. package/aot/compiler/lower.mjs +246 -111
  42. package/aot/compiler/native-files.mjs +439 -0
  43. package/aot/compiler/native-header.mjs +335 -0
  44. package/aot/compiler/native-modules.mjs +1173 -0
  45. package/aot/compiler/nodes.mjs +195 -172
  46. package/aot/compiler/options.mjs +37 -31
  47. package/aot/compiler/out.mjs +32 -23
  48. package/aot/compiler/package/animations.mjs +779 -0
  49. package/aot/compiler/package/arena.mjs +252 -0
  50. package/aot/compiler/package/assemble.mjs +175 -0
  51. package/aot/compiler/package/bytecode.mjs +315 -0
  52. package/aot/compiler/package/checks.mjs +1026 -0
  53. package/aot/compiler/package/codegen.mjs +2168 -0
  54. package/aot/compiler/package/enums.mjs +148 -0
  55. package/aot/compiler/package/format.mjs +771 -0
  56. package/aot/compiler/package/layouts.mjs +136 -0
  57. package/aot/compiler/package/lower.mjs +2103 -0
  58. package/aot/compiler/package/props.mjs +118 -0
  59. package/aot/compiler/package/string-caps.mjs +515 -0
  60. package/aot/compiler/package/tables.mjs +127 -0
  61. package/aot/compiler/package/vectors.mjs +502 -0
  62. package/aot/compiler/package/writer.mjs +686 -0
  63. package/aot/compiler/pan-responder.mjs +69 -61
  64. package/aot/compiler/parse.mjs +23 -21
  65. package/aot/compiler/record-shapes.mjs +246 -0
  66. package/aot/compiler/records.mjs +654 -0
  67. package/aot/compiler/reducers.mjs +272 -0
  68. package/aot/compiler/static-eval.mjs +340 -30
  69. package/aot/compiler/style-text.mjs +178 -174
  70. package/aot/compiler/svg.mjs +480 -251
  71. package/aot/compiler/switch-cases.mjs +198 -0
  72. package/aot/compiler/tagged-records.mjs +450 -0
  73. package/aot/compiler/typing.mjs +307 -0
  74. package/aot/compiler/updaters.mjs +320 -0
  75. package/aot/compiler/window-dimensions.mjs +94 -0
  76. package/aot/compiler/worked-values.mjs +319 -0
  77. package/aot/demo-file.mjs +30 -0
  78. package/aot/screenshot-smoke.mjs +54 -40
  79. package/aot/style-map.mjs +152 -92
  80. package/assets/bake-font.mjs +123 -77
  81. package/assets/bake-image.mjs +39 -22
  82. package/assets/bake-svg.mjs +361 -262
  83. package/assets/build-builtin-font.mjs +11 -7
  84. package/assets/emit-c.mjs +77 -58
  85. package/assets/emit-container.mjs +123 -37
  86. package/assets/emit-pack.mjs +77 -67
  87. package/assets/font-config.mjs +9 -6
  88. package/assets/font-sizes.mjs +163 -123
  89. package/assets/glyph-coverage.mjs +74 -54
  90. package/assets/index.mjs +31 -9
  91. package/assets/rasterize.mjs +126 -99
  92. package/assets/svg-loader.mjs +8 -8
  93. package/build.mjs +23 -13
  94. package/cli.mjs +402 -172
  95. package/compile-bin.mjs +3 -3
  96. package/flash.mjs +537 -0
  97. package/hotreload/dev-device.mjs +90 -33
  98. package/hotreload/pack-app.mjs +55 -43
  99. package/hotreload/pack-split.mjs +62 -64
  100. package/hotreload/package-transfer.mjs +175 -0
  101. package/hotreload/protocol.mjs +50 -37
  102. package/hotreload/uploader.mjs +38 -27
  103. package/hotreload/watch-tree.mjs +19 -19
  104. package/pack-container.mjs +37 -21
  105. package/package.json +7 -8
  106. package/persist-transform.mjs +34 -28
  107. package/qjsc-wasm.mjs +25 -14
  108. package/sim/embedded-react.cjs +1 -1
  109. package/sim/embedded-react.js +1 -1
  110. package/sim/embedded-react.wasm +0 -0
  111. package/sim/index.html +94 -85
  112. package/sim-server.mjs +113 -94
  113. package/src/embedded-react/Animated.js +24 -24
  114. package/src/embedded-react/Dimensions.js +37 -0
  115. package/src/embedded-react/Easing.js +1 -1
  116. package/src/embedded-react/FlatList.js +3 -3
  117. package/src/embedded-react/LayoutAnimation.js +8 -5
  118. package/src/embedded-react/PanResponder.js +75 -71
  119. package/src/embedded-react/Pressable.js +2 -8
  120. package/src/embedded-react/SectionList.js +7 -9
  121. package/src/embedded-react/StyleSheet.js +4 -3
  122. package/src/embedded-react/TouchableOpacity.js +13 -8
  123. package/src/embedded-react/index.d.ts +88 -8
  124. package/src/embedded-react/index.js +2 -0
  125. package/src/embedded-react/layout-anim-config.js +10 -4
  126. package/src/embedded-react/list-child.js +5 -5
  127. package/src/embedded-react/named-colors.js +1 -1
  128. package/src/embedded-react/nativeModule.js +462 -0
  129. package/src/embedded-react/split-style.js +11 -11
  130. package/src/embedded-react/svg-ops.js +760 -593
  131. package/src/embedded-react/useHostValue.js +3 -3
  132. package/src/embedded-react/usePersistentState.js +6 -6
  133. package/src/embedded-react/warn-props.js +1 -1
  134. package/src/host-config.js +60 -53
  135. package/src/props.js +49 -41
  136. package/src/renderer.js +7 -4
  137. package/aot/compiler/assemble.mjs +0 -944
  138. package/aot/compiler/c/animations.mjs +0 -436
  139. package/aot/compiler/c/boot.mjs +0 -127
  140. package/aot/compiler/c/expressions.mjs +0 -270
  141. package/aot/compiler/c/functions.mjs +0 -268
  142. package/aot/compiler/c/keyboard.mjs +0 -96
  143. package/aot/compiler/c/nodes.mjs +0 -303
  144. package/aot/compiler/c/pan-responder.mjs +0 -136
  145. package/aot/compiler/c/statements.mjs +0 -319
  146. package/aot/compiler/c/text.mjs +0 -83
  147. package/aot/compiler/c/vectors.mjs +0 -381
  148. package/aot/compiler/c-syntax.mjs +0 -127
@@ -0,0 +1,94 @@
1
+ /*
2
+ * Copyright 2026 Cory Lamming
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * @file compiler/window-dimensions.mts
18
+ * @brief Turns `useWindowDimensions()` and `Dimensions.get('window')` into reads of the panel's size.
19
+ */
20
+ import { traverse } from '@babel/core';
21
+ import { PANEL_KEY } from './boot.mjs';
22
+ import { aotError } from './diagnostics.mjs';
23
+ /*----------------------------------------------------------------------------------------------------------------------
24
+ - Constants
25
+ ---------------------------------------------------------------------------------------------------------------------*/
26
+ /** The package the two are imported from. */
27
+ const PACKAGE = 'embedded-react';
28
+ /** The sizes `Dimensions.get` names, which are the same on a panel. */
29
+ const SIZES = new Set(['window', 'screen']);
30
+ /*----------------------------------------------------------------------------------------------------------------------
31
+ - Implementation
32
+ ---------------------------------------------------------------------------------------------------------------------*/
33
+ /**
34
+ * The package export a name stands for where it is read, or null when it is anything else: a local, a prop or a
35
+ * state of that name hides the import.
36
+ *
37
+ * @param path Where the name is read.
38
+ * @param node The name.
39
+ *
40
+ * @returns The export's name, or null.
41
+ */
42
+ function packageExportOf(path, node) {
43
+ if (node.type !== 'Identifier')
44
+ return null;
45
+ const binding = path.scope.getBinding(node.name);
46
+ const specifier = binding?.path.node;
47
+ const declaration = binding?.path.parent;
48
+ if (specifier?.type !== 'ImportSpecifier' ||
49
+ declaration?.type !== 'ImportDeclaration' ||
50
+ declaration.source.value !== PACKAGE) {
51
+ return null;
52
+ }
53
+ const { imported } = specifier;
54
+ return imported.type === 'Identifier' ? imported.name : imported.value;
55
+ }
56
+ /**
57
+ * Rewrites each `useWindowDimensions()` and `Dimensions.get('window' | 'screen')` to a read of the panel's size,
58
+ * which folds as `screen` does. Only the package's own exports are rewritten, by whatever name they are imported.
59
+ *
60
+ * @param ast The parsed module, rewritten in place.
61
+ *
62
+ * @throws An AotError for any other use of `Dimensions`.
63
+ */
64
+ export function rewriteWindowDimensions(ast) {
65
+ const panel = (node) => ({ type: 'Identifier', name: PANEL_KEY, loc: node.loc });
66
+ traverse.cache.clear();
67
+ traverse(ast, {
68
+ CallExpression(path) {
69
+ const { callee, arguments: callArguments } = path.node;
70
+ if (packageExportOf(path, callee) === 'useWindowDimensions') {
71
+ path.replaceWith(panel(path.node));
72
+ }
73
+ else if (callee.type === 'MemberExpression' &&
74
+ packageExportOf(path, callee.object) === 'Dimensions') {
75
+ const [size] = callArguments;
76
+ const isGet = !callee.computed &&
77
+ callee.property.type === 'Identifier' &&
78
+ callee.property.name === 'get';
79
+ if (!isGet ||
80
+ callArguments.length !== 1 ||
81
+ size.type !== 'StringLiteral' ||
82
+ !SIZES.has(size.value)) {
83
+ const error = aotError("AOT: Dimensions has only get('window') and get('screen')", 'the panel size is fixed while the app runs, so there is nothing else to read or listen to.');
84
+ if (path.node.loc) {
85
+ error.aotLoc = path.node.loc.start;
86
+ }
87
+ throw error;
88
+ }
89
+ path.replaceWith(panel(path.node));
90
+ }
91
+ },
92
+ });
93
+ traverse.cache.clear();
94
+ }
@@ -0,0 +1,319 @@
1
+ /*
2
+ * Copyright 2026 Cory Lamming
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /*
17
+ * Values worked out with a loop: a block-bodied `useMemo`, or a helper used as a value, whose body has `let` locals
18
+ * or loops. Such a body can't be one expression, so it runs as statements, each `return` setting a local and leaving
19
+ * the body. In a handler, effect or timer it runs just before the statement that reads it. In render it has a state
20
+ * of its own, which the update works out again, before anything that reads it, when what it reads changes.
21
+ */
22
+ /*----------------------------------------------------------------------------------------------------------------------
23
+ - Imports
24
+ ---------------------------------------------------------------------------------------------------------------------*/
25
+ import { holdLater, setLater, shapeOf, shapeOfType, typedLater, } from './typing.mjs';
26
+ import { aotError } from './diagnostics.mjs';
27
+ import { assumeType, assumedTypeOf, buildsText, lowerSource, lowerText, typeSource, } from './expressions.mjs';
28
+ import { lowerStmts } from './handlers.mjs';
29
+ import { helperEnvironment } from './helper-values.mjs';
30
+ import { BOOL, FLOAT, INT, INT64_NUMBER, STRING, TIME } from './ir/types.mjs';
31
+ import { Out } from './out.mjs';
32
+ import { checkValueBody } from './updaters.mjs';
33
+ /*----------------------------------------------------------------------------------------------------------------------
34
+ - Variables
35
+ ---------------------------------------------------------------------------------------------------------------------*/
36
+ /** Numbers each value and each list worked out in render as it is made, so the update works out each in turn. */
37
+ let rebuilds = 0;
38
+ /** Numbers the locals a value is left in. */
39
+ let results = 0;
40
+ /*----------------------------------------------------------------------------------------------------------------------
41
+ - Implementation
42
+ ---------------------------------------------------------------------------------------------------------------------*/
43
+ /**
44
+ * The next number in the order the update works out what render makes: a value worked out with a loop, or a list
45
+ * filtered, sorted or split.
46
+ *
47
+ * @returns The number.
48
+ */
49
+ export const nextRebuild = () => rebuilds++;
50
+ /**
51
+ * Whether statements need to run as statements: they declare a `let` or loop, not counting a function inside them.
52
+ *
53
+ * @param statements The statements.
54
+ *
55
+ * @returns Whether they do.
56
+ */
57
+ function loopsIn(statements) {
58
+ return statements.some(statement => {
59
+ switch (statement?.type) {
60
+ case 'VariableDeclaration':
61
+ return statement.kind !== 'const';
62
+ case 'ForStatement':
63
+ case 'ForOfStatement':
64
+ case 'ForInStatement':
65
+ case 'WhileStatement':
66
+ case 'DoWhileStatement':
67
+ return true;
68
+ case 'BlockStatement':
69
+ return loopsIn(statement.body);
70
+ case 'IfStatement':
71
+ return loopsIn([statement.consequent, statement.alternate]);
72
+ case 'SwitchStatement':
73
+ return statement.cases.some(({ consequent }) => loopsIn(consequent));
74
+ case 'LabeledStatement':
75
+ return loopsIn([statement.body]);
76
+ default:
77
+ return false;
78
+ }
79
+ });
80
+ }
81
+ /**
82
+ * Whether a helper's body loops or declares a `let`, so it runs as statements rather than as one expression.
83
+ *
84
+ * @param helper The helper.
85
+ *
86
+ * @returns Whether it does.
87
+ */
88
+ export const runsAsStatements = (helper) => helper.body.type === 'BlockStatement' && loopsIn(helper.body.body);
89
+ /**
90
+ * What a value-giving body is, for errors: `the useMemo for "total"` or `helper "sum"`.
91
+ *
92
+ * @param name The helper's name.
93
+ *
94
+ * @returns The phrase, and the memo's name for a memo.
95
+ */
96
+ function describe(name) {
97
+ const memo = /^useMemo\((.*)\)$/.exec(name)?.[1] ?? null;
98
+ return {
99
+ what: memo === null ? `helper "${name}"` : `the useMemo for "${memo}"`,
100
+ memo,
101
+ };
102
+ }
103
+ /**
104
+ * The type a local holding every value a body returns has: a string, a boolean, or a number. A number is a float
105
+ * when any is, and 64 bits when any is, a time unless every 64-bit one is a plain number.
106
+ *
107
+ * @param types The returned values' types.
108
+ * @param what What returns them, for errors.
109
+ *
110
+ * @returns The type.
111
+ */
112
+ function joinedType(types, what) {
113
+ const kinds = new Set(types.map(type => type.kind));
114
+ joinedShape(types.map(shapeOfType), what);
115
+ if (kinds.has('string'))
116
+ return STRING;
117
+ if (kinds.has('bool'))
118
+ return BOOL;
119
+ if (kinds.has('int64')) {
120
+ if (kinds.has('float')) {
121
+ throw aotError(`AOT: ${what} loops, so it can't return a 64-bit whole number on one path and a fraction on another`, 'return whole numbers on every path, e.g. Math.round(x), or fractions on every path.');
122
+ }
123
+ return types.every(type => type.kind !== 'int64' || type.source === 'number')
124
+ ? INT64_NUMBER
125
+ : TIME;
126
+ }
127
+ return kinds.has('float') ? FLOAT : INT;
128
+ }
129
+ /**
130
+ * Whether a local holding every value a body returns holds a string, a boolean or a number: each must be one of
131
+ * those, and all the same.
132
+ *
133
+ * @param shapes The returned values' shapes.
134
+ * @param what What returns them, for errors.
135
+ *
136
+ * @returns The shape.
137
+ */
138
+ function joinedShape(shapes, what) {
139
+ const sorts = new Set(shapes);
140
+ if (sorts.has('struct') || sorts.has('node')) {
141
+ throw aotError(`AOT: ${what} loops, so it must return a number, a boolean or a string`, 'return the value itself, e.g. a field of an item rather than the item.');
142
+ }
143
+ if (sorts.size > 1) {
144
+ throw aotError(`AOT: ${what} loops, so each \`return\` must give the same kind of value`, `it returns a ${[...sorts].join(' on one path and a ')} on another. Return one kind on every path.`);
145
+ }
146
+ return shapes[0] ?? 'number';
147
+ }
148
+ /**
149
+ * How a local or a state holding a type is kept.
150
+ *
151
+ * @param type The type.
152
+ *
153
+ * @returns Its slot kind, and whether it is a boolean or a 64-bit plain number.
154
+ */
155
+ const heldAs = (type) => type.kind === 'string'
156
+ ? { slotKind: 'string' }
157
+ : type.kind === 'float'
158
+ ? { slotKind: 'float' }
159
+ : type.kind === 'int64'
160
+ ? {
161
+ slotKind: 'i64',
162
+ ...(type.source === 'number' ? { isLiteral: true } : {}),
163
+ }
164
+ : { slotKind: 'int', ...(type.kind === 'bool' ? { isBoolean: true } : {}) };
165
+ /**
166
+ * A value of a type that a local starts at before a `return` sets it.
167
+ *
168
+ * @param type The type.
169
+ *
170
+ * @returns The value.
171
+ */
172
+ const zeroOf = (type) => type.kind === 'string'
173
+ ? { kind: 'string', value: '', type }
174
+ : type.kind === 'bool'
175
+ ? { kind: 'boolean', value: false, type }
176
+ : { kind: 'number', value: 0, type };
177
+ /**
178
+ * Lowers a looping body to statements, each `return` leaving its value in a local of its own and the body.
179
+ *
180
+ * @param call The call.
181
+ * @param name The helper's name.
182
+ * @param helper The helper.
183
+ * @param environment The caller's environment.
184
+ * @param state The component's state table.
185
+ * @param output Everything emitted so far.
186
+ *
187
+ * @returns The statements and the local.
188
+ */
189
+ function lowerValueStatements(call, name, helper, environment, state, output) {
190
+ const { what, memo } = describe(name);
191
+ checkValueBody(helper.body, what, memo !== null);
192
+ const resultName = `value@${name}#${results++}`;
193
+ const returned = [];
194
+ const context = {
195
+ stateChanged: false,
196
+ output,
197
+ helperList: helper.body.body,
198
+ returnsValue: (argument, bodyEnvironment) => {
199
+ if (buildsText(argument, bodyEnvironment)) {
200
+ const text = lowerText(argument, bodyEnvironment);
201
+ const value = { kind: 'string', value: '', type: STRING };
202
+ returned.push({ value, text });
203
+ return [{ kind: 'assignLocal', name: resultName, value, text }];
204
+ }
205
+ const { source, expression: value } = lowerSource(argument, bodyEnvironment);
206
+ returned.push({ value, source });
207
+ return [{ kind: 'assignLocal', name: resultName, value }];
208
+ },
209
+ };
210
+ const body = lowerStmts(helper.body.body, helperEnvironment(name, helper, call.arguments, environment), state, context);
211
+ // Whether it is a string, a boolean or a number is known now; a number's width once each value is typed.
212
+ const shape = joinedShape(returned.map(({ value, text }) => (text ? 'string' : shapeOf(value))), what);
213
+ const type = () => joinedType(returned.map(({ value, text }) => (text ? STRING : value.type)), what);
214
+ const result = holdLater({ name: resultName }, shape, () => heldAs(type()));
215
+ assumeType(result, () => joinedType(returned.map(({ source }) => source ? typeSource(source, false).type : STRING), what));
216
+ return {
217
+ statements: [
218
+ {
219
+ kind: 'declareLocal',
220
+ name: resultName,
221
+ initializer: typedLater(shape, () => zeroOf(type())),
222
+ isHoisted: false,
223
+ },
224
+ ...(context.usedReturn ? [{ kind: 'block', body }] : body),
225
+ ],
226
+ result,
227
+ shape,
228
+ type,
229
+ };
230
+ }
231
+ /**
232
+ * A call to a helper that loops, used as a value. In a handler, effect or timer, the body runs before the statement
233
+ * that reads it, into a local. In render it is a state of its own, which the update works out again before anything
234
+ * that reads it.
235
+ *
236
+ * @param call The call.
237
+ * @param name The helper's name.
238
+ * @param helper The helper.
239
+ * @param environment The caller's environment.
240
+ *
241
+ * @returns The value.
242
+ */
243
+ export function workedValueOf(call, name, helper, environment) {
244
+ const location = call.loc?.start;
245
+ const { what, memo } = describe(name);
246
+ // In a handler, effect or timer: worked out just before the statement.
247
+ const sink = environment.before;
248
+ if (sink) {
249
+ const { statements, result } = lowerValueStatements(call, name, helper, environment, sink.state, sink.output);
250
+ sink.statements.push(...statements);
251
+ return { kind: 'local', local: result, location };
252
+ }
253
+ if (environment.outsideRender) {
254
+ throw aotError(`AOT: ${what} loops, so it can't be used as a value here`, 'call it from a statement of a handler, an effect or a timer, or from render.');
255
+ }
256
+ if (environment.inListRow) {
257
+ throw aotError(`AOT: ${what} loops, so it can't be used inside a list row`, 'a value worked out with a loop is worked out once, outside the rows. Work it out for the whole list in a ' +
258
+ 'useMemo, or keep it in each item.');
259
+ }
260
+ const values = environment.workedValues;
261
+ if (!values) {
262
+ throw new Error('AOT internal: no table for values worked out with a loop');
263
+ }
264
+ // In render: a state of its own, one per call and component instance. A call inside a helper being inlined may be
265
+ // given other arguments each time, so it gets one each time.
266
+ const prefix = environment.callbackPrefix ?? '';
267
+ const shared = !environment.inlining?.size;
268
+ const known = shared ? values.get(call)?.get(prefix) : undefined;
269
+ if (known)
270
+ return { kind: 'state', state: known, location };
271
+ const { statements, result, shape, type } = lowerValueStatements(call, name, helper, { ...environment, workedInRender: true }, { byName: new Map(environment.state), bySetter: new Map() }, new Out(new Map(), null));
272
+ const count = [...values.values()].reduce((sum, map) => sum + map.size, 0);
273
+ const label = memo ?? name;
274
+ const worked = {
275
+ kind: 'scalar',
276
+ name: label,
277
+ slotName: `${prefix}w${count}_${label}`,
278
+ setter: undefined,
279
+ slotKind: shape === 'string' ? 'string' : 'int',
280
+ isBoolean: shape === 'bool',
281
+ initial: shape === 'string' ? '' : 0,
282
+ host: false,
283
+ initialAt: location,
284
+ };
285
+ if (shape === 'number') {
286
+ setLater(worked, ['slotKind', 'widened'], () => {
287
+ const held = type();
288
+ const widened = held.kind !== 'int64'
289
+ ? undefined
290
+ : held.source === 'number'
291
+ ? 'number'
292
+ : 'time';
293
+ return { slotKind: heldAs(held).slotKind, widened };
294
+ });
295
+ assumeType(worked, () => assumedTypeOf(result));
296
+ }
297
+ const read = typedLater(shape, () => ({
298
+ kind: 'local',
299
+ local: result,
300
+ type: type(),
301
+ }));
302
+ worked.worked = {
303
+ rebuild: [
304
+ ...statements,
305
+ shape === 'string'
306
+ ? {
307
+ kind: 'setStateText',
308
+ state: worked,
309
+ text: { parts: [{ kind: 'value', value: read }] },
310
+ }
311
+ : { kind: 'setState', state: worked, value: read },
312
+ ],
313
+ order: nextRebuild(),
314
+ };
315
+ if (!values.has(call))
316
+ values.set(call, new Map());
317
+ values.get(call).set(shared ? prefix : `${prefix}#${count}`, worked);
318
+ return { kind: 'state', state: worked, location };
319
+ }
@@ -0,0 +1,30 @@
1
+ /*
2
+ * Copyright 2026 Cory Lamming
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { existsSync } from 'node:fs';
17
+ import { resolve } from 'node:path';
18
+ /**
19
+ * A demo's file, in TypeScript or JavaScript: `demoFile(directory, 'App')` is App.tsx when there is one, else
20
+ * App.jsx.
21
+ *
22
+ * @param directory The demo's folder.
23
+ * @param name The file's name, without its extension.
24
+ *
25
+ * @returns The path, which is the .jsx one when neither is there.
26
+ */
27
+ export function demoFile(directory, name) {
28
+ const typed = resolve(directory, `${name}.tsx`);
29
+ return existsSync(typed) ? typed : resolve(directory, `${name}.jsx`);
30
+ }
@@ -17,11 +17,11 @@
17
17
  /*
18
18
  * `npm run aot:smoke` — automated compile-and-screenshot smoke test for the Flow B (AOT) demos.
19
19
  *
20
- * For each demo it: (1) compiles App.jsx → dist/app.gen.{c,h} (`node aot/compile.mts`), (2) rebuilds the
21
- * linux-aot SDL host (which links the generated C), (3) runs it headless via ER_AOT_SHOT to render ONE
22
- * frame to a BMP, and (4) checks the image actually has content (distinct colors above a floor) — i.e., it
23
- * compiled, linked, and rendered something rather than crashing or drawing a blank screen. Exits non-zero
24
- * if any demo fails, so it can gate CI.
20
+ * It builds the linux-aot SDL host (which loads a package), then for each demo: (1) compiles App.jsx →
21
+ * dist/app.erpkg (`node aot/compile.mts`), (2) runs the host headless via ER_AOT_SHOT to render ONE frame to
22
+ * a BMP, and (3) checks the image actually has content (distinct colors above a floor) — i.e., it compiled,
23
+ * loaded, and rendered something rather than crashing or drawing a blank screen. Exits non-zero if any demo
24
+ * fails, so it can gate CI.
25
25
  *
26
26
  * Prereq: the linux-aot CMake build must be configurable (SDL2 found). It reuses examples/linux-aot/build;
27
27
  * if that isn't configured yet, set CMAKE_TOOLCHAIN_FILE (e.g. a vcpkg toolchain) and it will configure it.
@@ -32,22 +32,29 @@ import {existsSync, mkdirSync, readFileSync, rmSync} from 'node:fs';
32
32
  import {resolve, dirname} from 'node:path';
33
33
  import {fileURLToPath} from 'node:url';
34
34
 
35
+ // Where a BMP's header keeps what the check reads, and the 'BM' it starts with.
36
+ const BMP_MAGIC = [0x42, 0x4d];
37
+ const BMP_PIXEL_OFFSET_AT = 10;
38
+ const BMP_WIDTH_AT = 18;
39
+ const BMP_HEIGHT_AT = 22;
40
+ const BMP_BITS_PER_PIXEL_AT = 28;
41
+
35
42
  const here = dirname(fileURLToPath(import.meta.url)); // packages/embedded-react/aot
36
- const jsDir = resolve(here, '..'); // packages/embedded-react
37
- const repoRoot = resolve(here, '../../..');
38
- const exampleDir = resolve(repoRoot, 'examples/linux-aot');
39
- const buildDir = resolve(exampleDir, 'build');
40
- const exe = resolve(
41
- buildDir,
43
+ const packageDirectory = resolve(here, '..'); // packages/embedded-react
44
+ const repositoryRoot = resolve(here, '../../..');
45
+ const exampleDirectory = resolve(repositoryRoot, 'examples/linux-aot');
46
+ const buildDirectory = resolve(exampleDirectory, 'build');
47
+ const executable = resolve(
48
+ buildDirectory,
42
49
  process.platform === 'win32'
43
50
  ? 'embedded-react-desktop-aot.exe'
44
51
  : 'embedded-react-desktop-aot',
45
52
  );
46
- const tmpDir = resolve(jsDir, 'dist', '.smoke');
53
+ const temporaryDirectory = resolve(packageDirectory, 'dist', '.smoke');
47
54
 
48
55
  /**
49
- * The demos to smoke-test. `screen` sets ER_AOT_SCREEN_W/H so the responsive thermostat folds to its `solo`
50
- * (AOT-compilable) branch; `minColors` is the floor of distinct sampled colors that counts as "rendered".
56
+ * The demos to smoke-test. `screen` sets ER_AOT_SCREEN_W/H, the panel the package is for and the window's size;
57
+ * `minColors` is the floor of distinct sampled colors that counts as "rendered".
51
58
  */
52
59
  const DEMOS = [
53
60
  {name: 'watch-face', screen: {w: 240, h: 280}, minColors: 40},
@@ -64,14 +71,14 @@ const DEMOS = [
64
71
  * @returns The number of distinct colors sampled.
65
72
  */
66
73
  function bmpDistinctColors(path, step = 4) {
67
- const bmp = readFileSync(path);
68
- if (bmp[0] !== 0x42 || bmp[1] !== 0x4d) {
74
+ const bitmap = readFileSync(path);
75
+ if (bitmap[0] !== BMP_MAGIC[0] || bitmap[1] !== BMP_MAGIC[1]) {
69
76
  throw new Error(`not a BMP: ${path}`);
70
77
  }
71
- const pixelOffset = bmp.readUInt32LE(10);
72
- const width = bmp.readInt32LE(18);
73
- const height = Math.abs(bmp.readInt32LE(22));
74
- const bitsPerPixel = bmp.readUInt16LE(28);
78
+ const pixelOffset = bitmap.readUInt32LE(BMP_PIXEL_OFFSET_AT);
79
+ const width = bitmap.readInt32LE(BMP_WIDTH_AT);
80
+ const height = Math.abs(bitmap.readInt32LE(BMP_HEIGHT_AT));
81
+ const bitsPerPixel = bitmap.readUInt16LE(BMP_BITS_PER_PIXEL_AT);
75
82
  if (bitsPerPixel !== 24 && bitsPerPixel !== 32) {
76
83
  throw new Error(`unexpected BMP bpp ${bitsPerPixel}`);
77
84
  }
@@ -81,54 +88,60 @@ function bmpDistinctColors(path, step = 4) {
81
88
  for (let y = 0; y < height; y += step) {
82
89
  for (let x = 0; x < width; x += step) {
83
90
  const index = pixelOffset + y * rowSize + x * bytesPerPixel;
84
- colors.add((bmp[index] << 16) | (bmp[index + 1] << 8) | bmp[index + 2]); // BGR triplet
91
+ colors.add(
92
+ (bitmap[index] << 16) | (bitmap[index + 1] << 8) | bitmap[index + 2],
93
+ ); // BGR triplet
85
94
  }
86
95
  }
87
96
  return colors.size;
88
97
  }
89
98
 
90
- function run(command, args, options = {}) {
91
- execFileSync(command, args, {stdio: 'pipe', ...options});
99
+ function run(command, commandArguments, options = {}) {
100
+ execFileSync(command, commandArguments, {stdio: 'pipe', ...options});
92
101
  }
93
102
 
94
103
  /** Configures the linux-aot CMake build on the first run. */
95
104
  function ensureConfigured() {
96
- if (existsSync(resolve(buildDir, 'CMakeCache.txt'))) return;
105
+ if (existsSync(resolve(buildDirectory, 'CMakeCache.txt'))) return;
97
106
  console.log('• configuring linux-aot build (first run)…');
98
- const args = ['-S', exampleDir, '-B', buildDir];
107
+ const cmakeArguments = ['-S', exampleDirectory, '-B', buildDirectory];
99
108
  if (process.env.CMAKE_TOOLCHAIN_FILE) {
100
- args.push(`-DCMAKE_TOOLCHAIN_FILE=${process.env.CMAKE_TOOLCHAIN_FILE}`);
109
+ cmakeArguments.push(
110
+ `-DCMAKE_TOOLCHAIN_FILE=${process.env.CMAKE_TOOLCHAIN_FILE}`,
111
+ );
101
112
  }
102
113
  if (process.platform === 'win32') {
103
- args.push('-G', 'MinGW Makefiles');
114
+ cmakeArguments.push('-G', 'MinGW Makefiles');
104
115
  }
105
- run('cmake', args);
116
+ run('cmake', cmakeArguments);
106
117
  }
107
118
 
108
119
  /**
109
- * Compiles one demo, relinks the host, renders one frame and checks the frame has content. A step that cannot
110
- * run (the compiler, the build or the host) throws.
120
+ * Compiles one demo, renders one frame and checks the frame has content. A step that cannot run (the compiler or
121
+ * the host) throws.
111
122
  *
112
123
  * @param demo The demo, from DEMOS.
113
124
  *
114
125
  * @returns Why the demo failed, or null when it rendered.
115
126
  */
116
127
  function smokeTest(demo) {
117
- const shot = resolve(tmpDir, `${demo.name}.bmp`);
128
+ const shot = resolve(temporaryDirectory, `${demo.name}.bmp`);
118
129
  rmSync(shot, {force: true});
119
130
 
120
- // Compile with the demo's screen size, relink the host, then render one frame to the BMP.
121
- const compileEnv = {...process.env};
131
+ // Compile at the demo's screen size, then render one frame to the BMP in a window of that size.
132
+ const screenEnvironment = {...process.env};
122
133
  if (demo.screen) {
123
- compileEnv.ER_AOT_SCREEN_W = String(demo.screen.w);
124
- compileEnv.ER_AOT_SCREEN_H = String(demo.screen.h);
134
+ screenEnvironment.ER_AOT_SCREEN_W = String(demo.screen.w);
135
+ screenEnvironment.ER_AOT_SCREEN_H = String(demo.screen.h);
125
136
  }
126
137
  run('node', [resolve(here, 'compile.mts'), demo.name], {
127
- cwd: jsDir,
128
- env: compileEnv,
138
+ cwd: packageDirectory,
139
+ env: screenEnvironment,
140
+ });
141
+ run(executable, [resolve(packageDirectory, 'dist/app.erpkg')], {
142
+ cwd: buildDirectory,
143
+ env: {...screenEnvironment, ER_NO_HIDPI: '1', ER_AOT_SHOT: shot},
129
144
  });
130
- run('cmake', ['--build', buildDir]);
131
- run(exe, [], {cwd: buildDir, env: {...process.env, ER_AOT_SHOT: shot}});
132
145
 
133
146
  // The frame must exist and show more than a blank screen.
134
147
  if (!existsSync(shot)) {
@@ -143,8 +156,9 @@ function smokeTest(demo) {
143
156
  }
144
157
 
145
158
  let failures = 0;
146
- mkdirSync(tmpDir, {recursive: true});
159
+ mkdirSync(temporaryDirectory, {recursive: true});
147
160
  ensureConfigured();
161
+ run('cmake', ['--build', buildDirectory]);
148
162
 
149
163
  for (const demo of DEMOS) {
150
164
  let failure;