embedded-react 0.16.0 → 0.18.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.
- package/aot/compiler/animations.mjs +102 -34
- package/aot/compiler/assemble.mjs +169 -31
- package/aot/compiler/boot.mjs +441 -0
- package/aot/compiler/branch-merge.mjs +315 -0
- package/aot/compiler/c/animations.mjs +90 -16
- package/aot/compiler/c/boot.mjs +127 -0
- package/aot/compiler/c/expressions.mjs +63 -8
- package/aot/compiler/c/nodes.mjs +34 -13
- package/aot/compiler/c/statements.mjs +92 -15
- package/aot/compiler/check.mjs +32 -3
- package/aot/compiler/collect.mjs +95 -9
- package/aot/compiler/control-flow.mjs +43 -18
- package/aot/compiler/diagnostics.mjs +33 -0
- package/aot/compiler/elements/dial.mjs +8 -7
- package/aot/compiler/elements/props.mjs +19 -9
- package/aot/compiler/elements/text-input.mjs +7 -2
- package/aot/compiler/expressions.mjs +132 -10
- package/aot/compiler/handlers.mjs +62 -24
- package/aot/compiler/ir/boot.mjs +16 -0
- package/aot/compiler/ir/nodes.mjs +28 -4
- package/aot/compiler/ir/reads.mjs +351 -0
- package/aot/compiler/keyboard.mjs +35 -21
- package/aot/compiler/lower.mjs +40 -11
- package/aot/compiler/nodes.mjs +22 -9
- package/aot/compiler/options.mjs +63 -12
- package/aot/compiler/static-eval.mjs +314 -56
- package/aot/compiler/style-text.mjs +201 -19
- package/aot/compiler/svg.mjs +7 -3
- package/aot/style-map.mjs +9 -11
- package/assets/bake-svg.mjs +3 -2
- package/package.json +1 -1
- package/sim/embedded-react.wasm +0 -0
- package/src/embedded-react/Animated.js +41 -0
- package/src/embedded-react/Button.js +3 -4
- package/src/embedded-react/Pressable.js +59 -0
- package/src/embedded-react/TouchableOpacity.js +6 -9
- package/src/embedded-react/index.d.ts +118 -30
- package/src/embedded-react/index.js +1 -1
- package/src/embedded-react/named-colors.js +37 -0
- package/src/embedded-react/svg-ops.js +13 -16
- package/src/host-config.js +50 -8
|
@@ -0,0 +1,351 @@
|
|
|
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
|
+
- Implementation
|
|
18
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
19
|
+
/**
|
|
20
|
+
* Records what a local reads: a list row's item reads its list, and any other local reads what it was set from.
|
|
21
|
+
* A local with neither is untracked.
|
|
22
|
+
*
|
|
23
|
+
* @param local The local.
|
|
24
|
+
* @param found What the walk has found.
|
|
25
|
+
*/
|
|
26
|
+
function readLocal(local, found) {
|
|
27
|
+
if (local.list) {
|
|
28
|
+
found.states.add(local.list);
|
|
29
|
+
}
|
|
30
|
+
else if (local.source) {
|
|
31
|
+
readSource(local.source, found);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
found.untracked = true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Records what an expression, before typing, reads.
|
|
39
|
+
*
|
|
40
|
+
* @param source The expression.
|
|
41
|
+
* @param found What the walk has found.
|
|
42
|
+
*/
|
|
43
|
+
function readSource(source, found) {
|
|
44
|
+
switch (source.kind) {
|
|
45
|
+
case 'number':
|
|
46
|
+
case 'string':
|
|
47
|
+
case 'boolean':
|
|
48
|
+
return;
|
|
49
|
+
case 'state':
|
|
50
|
+
found.states.add(source.state);
|
|
51
|
+
return;
|
|
52
|
+
case 'local':
|
|
53
|
+
readLocal(source.local, found);
|
|
54
|
+
return;
|
|
55
|
+
case 'ref':
|
|
56
|
+
found.untracked = true;
|
|
57
|
+
return;
|
|
58
|
+
case 'fixed':
|
|
59
|
+
readExpr(source.expr, found);
|
|
60
|
+
return;
|
|
61
|
+
case 'unary':
|
|
62
|
+
readSource(source.operand, found);
|
|
63
|
+
return;
|
|
64
|
+
case 'binary':
|
|
65
|
+
case 'logical':
|
|
66
|
+
readSource(source.left, found);
|
|
67
|
+
readSource(source.right, found);
|
|
68
|
+
return;
|
|
69
|
+
case 'conditional':
|
|
70
|
+
readSource(source.test, found);
|
|
71
|
+
readSource(source.consequent, found);
|
|
72
|
+
readSource(source.alternate, found);
|
|
73
|
+
return;
|
|
74
|
+
case 'math':
|
|
75
|
+
source.args.forEach(arg => readSource(arg, found));
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Records what an expression reads.
|
|
81
|
+
*
|
|
82
|
+
* @param expr The expression.
|
|
83
|
+
* @param found What the walk has found.
|
|
84
|
+
*/
|
|
85
|
+
function readExpr(expr, found) {
|
|
86
|
+
switch (expr.kind) {
|
|
87
|
+
case 'number':
|
|
88
|
+
case 'string':
|
|
89
|
+
case 'boolean':
|
|
90
|
+
case 'pi':
|
|
91
|
+
return;
|
|
92
|
+
case 'state':
|
|
93
|
+
found.states.add(expr.state);
|
|
94
|
+
return;
|
|
95
|
+
case 'boot':
|
|
96
|
+
found.boot = true;
|
|
97
|
+
return;
|
|
98
|
+
case 'local':
|
|
99
|
+
readLocal(expr.local, found);
|
|
100
|
+
return;
|
|
101
|
+
case 'listLength':
|
|
102
|
+
found.states.add(expr.list);
|
|
103
|
+
return;
|
|
104
|
+
case 'itemField':
|
|
105
|
+
readLocal(expr.item, found);
|
|
106
|
+
return;
|
|
107
|
+
case 'ref':
|
|
108
|
+
case 'clock':
|
|
109
|
+
case 'event':
|
|
110
|
+
case 'layout':
|
|
111
|
+
case 'gesture':
|
|
112
|
+
found.untracked = true;
|
|
113
|
+
return;
|
|
114
|
+
case 'toFloat':
|
|
115
|
+
case 'unary':
|
|
116
|
+
case 'wholeRound':
|
|
117
|
+
case 'trunc':
|
|
118
|
+
case 'toInt':
|
|
119
|
+
readExpr(expr.operand, found);
|
|
120
|
+
return;
|
|
121
|
+
case 'helper':
|
|
122
|
+
case 'floatMath':
|
|
123
|
+
expr.args.forEach(arg => readExpr(arg, found));
|
|
124
|
+
return;
|
|
125
|
+
case 'arithmetic':
|
|
126
|
+
case 'floatDivide':
|
|
127
|
+
case 'narrowRemainder':
|
|
128
|
+
case 'compare':
|
|
129
|
+
case 'stringEquals':
|
|
130
|
+
case 'logical':
|
|
131
|
+
case 'pick':
|
|
132
|
+
readExpr(expr.left, found);
|
|
133
|
+
readExpr(expr.right, found);
|
|
134
|
+
return;
|
|
135
|
+
case 'conditional':
|
|
136
|
+
readExpr(expr.test, found);
|
|
137
|
+
readExpr(expr.consequent, found);
|
|
138
|
+
readExpr(expr.alternate, found);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Records what a conditional's show condition reads, the conditions it sits within included.
|
|
144
|
+
*
|
|
145
|
+
* @param show The condition.
|
|
146
|
+
* @param found What the walk has found.
|
|
147
|
+
*/
|
|
148
|
+
function readShow(show, found) {
|
|
149
|
+
if (show.kind === 'rowInUse') {
|
|
150
|
+
found.states.add(show.list);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
readExpr(show.test, found);
|
|
154
|
+
if (show.within) {
|
|
155
|
+
readShow(show.within, found);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Records what a state-driven prop value reads.
|
|
160
|
+
*
|
|
161
|
+
* @param value The value.
|
|
162
|
+
* @param found What the walk has found.
|
|
163
|
+
*/
|
|
164
|
+
function readPropValue(value, found) {
|
|
165
|
+
switch (value.kind) {
|
|
166
|
+
case 'constant':
|
|
167
|
+
return;
|
|
168
|
+
case 'select':
|
|
169
|
+
readExpr(value.test, found);
|
|
170
|
+
readPropValue(value.whenTrue, found);
|
|
171
|
+
readPropValue(value.whenFalse, found);
|
|
172
|
+
return;
|
|
173
|
+
case 'opacity':
|
|
174
|
+
case 'dimension':
|
|
175
|
+
case 'visible':
|
|
176
|
+
case 'float':
|
|
177
|
+
readExpr(value.value, found);
|
|
178
|
+
return;
|
|
179
|
+
case 'shown':
|
|
180
|
+
readShow(value.show, found);
|
|
181
|
+
return;
|
|
182
|
+
case 'whileShown':
|
|
183
|
+
readShow(value.show, found);
|
|
184
|
+
readPropValue(value.value, found);
|
|
185
|
+
return;
|
|
186
|
+
case 'flag':
|
|
187
|
+
readExpr(value.test, found);
|
|
188
|
+
return;
|
|
189
|
+
case 'byte':
|
|
190
|
+
readPropValue(value.value, found);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Records what a text reads.
|
|
196
|
+
*
|
|
197
|
+
* @param text The text.
|
|
198
|
+
* @param found What the walk has found.
|
|
199
|
+
*/
|
|
200
|
+
function readText(text, found) {
|
|
201
|
+
for (const part of text.parts) {
|
|
202
|
+
if (part.kind !== 'literal') {
|
|
203
|
+
readExpr(part.value, found);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Records what one slot of a drawing's op-tape reads.
|
|
209
|
+
*
|
|
210
|
+
* @param value The slot.
|
|
211
|
+
* @param found What the walk has found.
|
|
212
|
+
*/
|
|
213
|
+
function readTapeValue(value, found) {
|
|
214
|
+
switch (value.kind) {
|
|
215
|
+
case 'op':
|
|
216
|
+
case 'number':
|
|
217
|
+
case 'local':
|
|
218
|
+
case 'fullTurn':
|
|
219
|
+
return;
|
|
220
|
+
case 'float':
|
|
221
|
+
readExpr(value.value, found);
|
|
222
|
+
return;
|
|
223
|
+
case 'chain':
|
|
224
|
+
readTapeValue(value.first, found);
|
|
225
|
+
value.rest.forEach(step => readTapeValue(step.value, found));
|
|
226
|
+
return;
|
|
227
|
+
case 'radians':
|
|
228
|
+
readTapeValue(value.degrees, found);
|
|
229
|
+
return;
|
|
230
|
+
case 'clampRadius':
|
|
231
|
+
readTapeValue(value.radius, found);
|
|
232
|
+
readTapeValue(value.side, found);
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Records what a paint color reads.
|
|
238
|
+
*
|
|
239
|
+
* @param color The color.
|
|
240
|
+
* @param found What the walk has found.
|
|
241
|
+
*/
|
|
242
|
+
function readPaintColor(color, found) {
|
|
243
|
+
if (color.kind === 'state') {
|
|
244
|
+
readPropValue(color.value, found);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* What a walk found, as reads.
|
|
249
|
+
*
|
|
250
|
+
* @param found What the walk found.
|
|
251
|
+
*
|
|
252
|
+
* @returns The state read, or null when something untracked is read too.
|
|
253
|
+
*/
|
|
254
|
+
const readsOf = (found) => found.untracked ? null : found.states;
|
|
255
|
+
/**
|
|
256
|
+
* The state a node's props, text and image read. app_update() sets them all again together, so this is
|
|
257
|
+
* everything any of them reads.
|
|
258
|
+
*
|
|
259
|
+
* @param node The node.
|
|
260
|
+
*
|
|
261
|
+
* @returns Its reads.
|
|
262
|
+
*/
|
|
263
|
+
export const nodeReads = (node) => readsOf(nodeFound(node));
|
|
264
|
+
/**
|
|
265
|
+
* Whether a node's runtime props read only values worked out at boot, so er_app_build() sets them once.
|
|
266
|
+
*
|
|
267
|
+
* @param node The node.
|
|
268
|
+
*
|
|
269
|
+
* @returns True when they do.
|
|
270
|
+
*/
|
|
271
|
+
export const isBootOnlyNode = (node) => isBootOnly(nodeFound(node));
|
|
272
|
+
/**
|
|
273
|
+
* Whether a drawing reads only values worked out at boot, so er_app_build() builds it once.
|
|
274
|
+
*
|
|
275
|
+
* @param vector The drawing.
|
|
276
|
+
*
|
|
277
|
+
* @returns True when it does.
|
|
278
|
+
*/
|
|
279
|
+
export const isBootOnlyVector = (vector) => isBootOnly(vectorFound(vector));
|
|
280
|
+
/**
|
|
281
|
+
* Whether a walk found boot values and nothing that changes.
|
|
282
|
+
*
|
|
283
|
+
* @param found What the walk found.
|
|
284
|
+
*
|
|
285
|
+
* @returns True when it did.
|
|
286
|
+
*/
|
|
287
|
+
const isBootOnly = (found) => !!found.boot && !found.untracked && found.states.size === 0;
|
|
288
|
+
/**
|
|
289
|
+
* Walks everything a node's props, text and image read.
|
|
290
|
+
*
|
|
291
|
+
* @param node The node.
|
|
292
|
+
*
|
|
293
|
+
* @returns What the walk found.
|
|
294
|
+
*/
|
|
295
|
+
function nodeFound(node) {
|
|
296
|
+
const found = { states: new Set(), untracked: false };
|
|
297
|
+
node.stateProps.forEach(prop => readPropValue(prop.value, found));
|
|
298
|
+
if (node.text) {
|
|
299
|
+
readText(node.text, found);
|
|
300
|
+
}
|
|
301
|
+
if (node.image?.kind === 'value') {
|
|
302
|
+
readExpr(node.image.value, found);
|
|
303
|
+
}
|
|
304
|
+
return found;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* The state a drawing reads: its locals and tape, and its paints and gradients.
|
|
308
|
+
*
|
|
309
|
+
* @param vector The drawing.
|
|
310
|
+
*
|
|
311
|
+
* @returns Its reads.
|
|
312
|
+
*/
|
|
313
|
+
export const vectorReads = (vector) => readsOf(vectorFound(vector));
|
|
314
|
+
/**
|
|
315
|
+
* Walks everything a drawing reads.
|
|
316
|
+
*
|
|
317
|
+
* @param vector The drawing.
|
|
318
|
+
*
|
|
319
|
+
* @returns What the walk found.
|
|
320
|
+
*/
|
|
321
|
+
function vectorFound(vector) {
|
|
322
|
+
const found = { states: new Set(), untracked: false };
|
|
323
|
+
vector.locals.forEach(local => readTapeValue(local.value, found));
|
|
324
|
+
vector.tape.forEach(value => readTapeValue(value, found));
|
|
325
|
+
for (const paint of vector.paints) {
|
|
326
|
+
readPaintColor(paint.fill, found);
|
|
327
|
+
readPaintColor(paint.stroke, found);
|
|
328
|
+
readTapeValue(paint.strokeWidth, found);
|
|
329
|
+
for (const gradient of [paint.fillGradient, paint.strokeGradient]) {
|
|
330
|
+
if (gradient.when) {
|
|
331
|
+
readExpr(gradient.when.test, found);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
for (const gradient of vector.gradients) {
|
|
336
|
+
for (const stop of gradient.stops) {
|
|
337
|
+
readPaintColor(stop.color, found);
|
|
338
|
+
readTapeValue(stop.offset, found);
|
|
339
|
+
}
|
|
340
|
+
for (const value of [
|
|
341
|
+
gradient.ax,
|
|
342
|
+
gradient.ay,
|
|
343
|
+
gradient.bx,
|
|
344
|
+
gradient.by,
|
|
345
|
+
gradient.r,
|
|
346
|
+
]) {
|
|
347
|
+
readTapeValue(value, found);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return found;
|
|
351
|
+
}
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
- Imports
|
|
18
18
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
19
19
|
import { parseColor } from '../../src/embedded-react/svg-ops.js';
|
|
20
|
-
import { aotError } from './diagnostics.mjs';
|
|
20
|
+
import { aotError, withLoc } from './diagnostics.mjs';
|
|
21
21
|
import { evalStatic } from './static-eval.mjs';
|
|
22
22
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
23
23
|
- Implementation
|
|
@@ -89,28 +89,13 @@ function lowerKey(key, layerIndex) {
|
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
91
|
/**
|
|
92
|
-
* Lowers a
|
|
93
|
-
* optionally a full layout) from the app with no engine edit. The config must be statically foldable; omit
|
|
94
|
-
* `layers` to keep the built-in QWERTY.
|
|
92
|
+
* Lowers the argument of a `setKeyboardConfig(...)` call, its AOT errors located at it.
|
|
95
93
|
*
|
|
96
|
-
* @param
|
|
94
|
+
* @param configArg The call's config argument.
|
|
97
95
|
*
|
|
98
|
-
* @returns The config
|
|
96
|
+
* @returns The config.
|
|
99
97
|
*/
|
|
100
|
-
|
|
101
|
-
// Find the first top-level setKeyboardConfig(...) call; without one, the built-in keyboard stays as is.
|
|
102
|
-
let configArg = null;
|
|
103
|
-
for (const statement of program.body) {
|
|
104
|
-
if (statement.type === 'ExpressionStatement' &&
|
|
105
|
-
statement.expression.type === 'CallExpression' &&
|
|
106
|
-
statement.expression.callee.type === 'Identifier' &&
|
|
107
|
-
statement.expression.callee.name === 'setKeyboardConfig') {
|
|
108
|
-
configArg = statement.expression.arguments[0];
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
if (!configArg)
|
|
113
|
-
return null;
|
|
98
|
+
const lowerConfig = withLoc((configArg) => {
|
|
114
99
|
// Fold the config object at compile time.
|
|
115
100
|
let config;
|
|
116
101
|
try {
|
|
@@ -122,13 +107,19 @@ export function lowerKeyboardConfig(program) {
|
|
|
122
107
|
if (config == null || typeof config !== 'object') {
|
|
123
108
|
throw aotError('AOT: setKeyboardConfig(...) needs a config object');
|
|
124
109
|
}
|
|
125
|
-
// Lower the layout when the app gives one, layer by layer and row by row.
|
|
110
|
+
// Lower the layout when the app gives one, layer by layer and row by row; C has no empty table.
|
|
126
111
|
let layers = null;
|
|
127
112
|
if (Array.isArray(config.layers)) {
|
|
113
|
+
if (!config.layers.length) {
|
|
114
|
+
throw aotError('AOT: setKeyboardConfig `layers` needs at least one layer', 'omit `layers` to keep the built-in QWERTY.');
|
|
115
|
+
}
|
|
128
116
|
layers = config.layers.map((layer, layerIndex) => {
|
|
129
117
|
if (!Array.isArray(layer)) {
|
|
130
118
|
throw aotError('AOT: setKeyboardConfig `layers[i]` must be an array of rows');
|
|
131
119
|
}
|
|
120
|
+
if (!layer.length) {
|
|
121
|
+
throw aotError(`AOT: setKeyboardConfig \`layers[${layerIndex}]\` needs at least one row`);
|
|
122
|
+
}
|
|
132
123
|
return layer.map(row => {
|
|
133
124
|
if (!Array.isArray(row) || !row.length) {
|
|
134
125
|
throw aotError('AOT: each keyboard row must be a non-empty array of keys');
|
|
@@ -149,4 +140,27 @@ export function lowerKeyboardConfig(program) {
|
|
|
149
140
|
keyActiveColor: kbdColor(config.keyActiveColor),
|
|
150
141
|
labelColor: kbdColor(config.labelColor),
|
|
151
142
|
};
|
|
143
|
+
});
|
|
144
|
+
/**
|
|
145
|
+
* Lowers a module-level `setKeyboardConfig({...})`, which customizes the on-screen keyboard (colors/sizes, and
|
|
146
|
+
* optionally a full layout) from the app with no engine edit. The config must be statically foldable; omit
|
|
147
|
+
* `layers` to keep the built-in QWERTY.
|
|
148
|
+
*
|
|
149
|
+
* @param program The parsed module.
|
|
150
|
+
*
|
|
151
|
+
* @returns The config, or null when the module has none.
|
|
152
|
+
*/
|
|
153
|
+
export function lowerKeyboardConfig(program) {
|
|
154
|
+
// Find the first top-level setKeyboardConfig(...) call; without one, the built-in keyboard stays as is.
|
|
155
|
+
let configArg = null;
|
|
156
|
+
for (const statement of program.body) {
|
|
157
|
+
if (statement.type === 'ExpressionStatement' &&
|
|
158
|
+
statement.expression.type === 'CallExpression' &&
|
|
159
|
+
statement.expression.callee.type === 'Identifier' &&
|
|
160
|
+
statement.expression.callee.name === 'setKeyboardConfig') {
|
|
161
|
+
configArg = statement.expression.arguments[0];
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return configArg ? lowerConfig(configArg) : null;
|
|
152
166
|
}
|
package/aot/compiler/lower.mjs
CHANGED
|
@@ -18,9 +18,10 @@
|
|
|
18
18
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
19
19
|
import { checkNumber, lowerWithChecks, runChecks } from './check.mjs';
|
|
20
20
|
import { aotError } from './diagnostics.mjs';
|
|
21
|
-
import { evalStatic, withUndefined } from './static-eval.mjs';
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
21
|
+
import { evalStatic, setBinding, withUndefined } from './static-eval.mjs';
|
|
22
|
+
import { abandonBoot, beginBoot, endBoot, setBootLowering } from './boot.mjs';
|
|
23
|
+
import { findShadowedClockCalls, emitSourcedWide, lowerExpr, } from './expressions.mjs';
|
|
24
|
+
import { findComponent, declaredNames, moduleScope, collectState, findReturnJSX, collectComponents, collectHelpers, collectImageImports, collectSvgImports, collectCallbacks, collectMemos, collectEffects, bindConst, } from './collect.mjs';
|
|
24
25
|
import { collectAnims, collectRefs } from './animations.mjs';
|
|
25
26
|
import { lowerEffect } from './handlers.mjs';
|
|
26
27
|
import { collectPanResponders } from './pan-responder.mjs';
|
|
@@ -28,7 +29,8 @@ import { emitNode } from './nodes.mjs';
|
|
|
28
29
|
import { lowerKeyboardConfig } from './keyboard.mjs';
|
|
29
30
|
import { normalizeUndefined, parseApp } from './parse.mjs';
|
|
30
31
|
import { Out } from './out.mjs';
|
|
31
|
-
import { isStateDriven, nodesOf,
|
|
32
|
+
import { isStateDriven, nodesOf, updatedVectorOf } from './ir/nodes.mjs';
|
|
33
|
+
import { nodeReads, vectorReads } from './ir/reads.mjs';
|
|
32
34
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
33
35
|
- Implementation
|
|
34
36
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
@@ -100,6 +102,22 @@ function settleFunctions(out, hasUpdate) {
|
|
|
100
102
|
}
|
|
101
103
|
}
|
|
102
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Flags each state a node or drawing reads, so a write to it marks it changed and app_update() sets them again.
|
|
107
|
+
* A node that also reads something untracked is set on every update, so its reads need no flag.
|
|
108
|
+
*
|
|
109
|
+
* @param nodes The app's nodes.
|
|
110
|
+
*/
|
|
111
|
+
function watchState(nodes) {
|
|
112
|
+
for (const node of nodes) {
|
|
113
|
+
const vector = updatedVectorOf(node);
|
|
114
|
+
for (const reads of [nodeReads(node), vector && vectorReads(vector)]) {
|
|
115
|
+
reads?.forEach(record => {
|
|
116
|
+
record.isWatched = true;
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
103
121
|
/**
|
|
104
122
|
* Refuses state C cannot hold: a number in a list item that has no C form, and a host value that would take
|
|
105
123
|
* the name of the setter every app exports for the wall clock. A field an item leaves out starts at 0.
|
|
@@ -138,10 +156,16 @@ function checkStateRecords(stateRecords) {
|
|
|
138
156
|
* @returns The lowered app.
|
|
139
157
|
*/
|
|
140
158
|
export function lowerApp(src, opts, wide, stores) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
159
|
+
beginBoot();
|
|
160
|
+
try {
|
|
161
|
+
const { result, checks } = lowerWithChecks(() => lowerProgram(src, opts, wide, stores));
|
|
162
|
+
const app = { ...result, boot: endBoot(), checks };
|
|
163
|
+
runChecks(app.checks);
|
|
164
|
+
return app;
|
|
165
|
+
}
|
|
166
|
+
finally {
|
|
167
|
+
abandonBoot();
|
|
168
|
+
}
|
|
145
169
|
}
|
|
146
170
|
/**
|
|
147
171
|
* Runs the compiler passes over the parsed app, from its module scope and hooks through the element tree to its
|
|
@@ -181,7 +205,7 @@ function lowerProgram(src, opts, wide, stores) {
|
|
|
181
205
|
if (decl.id.type !== 'Identifier' || !decl.init)
|
|
182
206
|
continue;
|
|
183
207
|
try {
|
|
184
|
-
scope
|
|
208
|
+
setBinding(scope, decl.id.name, bindConst(decl.id.name, evalStatic(decl.init, withUndefined(scope), 'boot')));
|
|
185
209
|
}
|
|
186
210
|
catch {
|
|
187
211
|
// A dynamic const must hide a same-named module const, or the JSX quietly renders the module value.
|
|
@@ -229,10 +253,12 @@ function lowerProgram(src, opts, wide, stores) {
|
|
|
229
253
|
stores,
|
|
230
254
|
shadowedClock,
|
|
231
255
|
};
|
|
256
|
+
// A value worked out at boot lowers its slot against the app's environment.
|
|
257
|
+
setBootLowering(env, lowerExpr);
|
|
232
258
|
// Before emit, fold each memo or inline its C expression at each use (no cache needed: dep tracking re-applies).
|
|
233
259
|
for (const [name, expr] of memos) {
|
|
234
260
|
try {
|
|
235
|
-
scope
|
|
261
|
+
setBinding(scope, name, bindConst(name, evalStatic(expr, scope, 'boot')));
|
|
236
262
|
}
|
|
237
263
|
catch {
|
|
238
264
|
const cExpr = emitSourcedWide(expr, env);
|
|
@@ -262,8 +288,11 @@ function lowerProgram(src, opts, wide, stores) {
|
|
|
262
288
|
lowerEffect(effect, env, state, out);
|
|
263
289
|
}
|
|
264
290
|
// app_update() exists only when something has to be re-applied after a state change.
|
|
265
|
-
const hasUpdate = nodesOf(root).some(node => isStateDriven(node) ||
|
|
291
|
+
const hasUpdate = nodesOf(root).some(node => isStateDriven(node) || updatedVectorOf(node) !== null) || out.depEffects.length > 0;
|
|
266
292
|
settleFunctions(out, hasUpdate);
|
|
293
|
+
if (hasUpdate) {
|
|
294
|
+
watchState(nodesOf(root));
|
|
295
|
+
}
|
|
267
296
|
const stateRecords = [...state.byName.values(), ...out.childStateRecords];
|
|
268
297
|
checkStateRecords(stateRecords);
|
|
269
298
|
return {
|
package/aot/compiler/nodes.mjs
CHANGED
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
19
19
|
import { checkNumber } from './check.mjs';
|
|
20
20
|
import { NODE_TYPES } from '../style-map.mjs';
|
|
21
|
-
import { aotError, withLoc } from './diagnostics.mjs';
|
|
21
|
+
import { aotError, checkEngineString, constantText, withLoc, } from './diagnostics.mjs';
|
|
22
|
+
import { buildValueOf, foldBoot } from './boot.mjs';
|
|
22
23
|
import { evalStaticOrThrow, evalStatic, foldScope } from './static-eval.mjs';
|
|
23
24
|
import { lowerExpr } from './expressions.mjs';
|
|
24
25
|
import { isFn } from './collect.mjs';
|
|
@@ -317,17 +318,21 @@ function applyShow(node, show) {
|
|
|
317
318
|
*/
|
|
318
319
|
export function lowerEventHandler(attr, out, env, state) {
|
|
319
320
|
const fn = attrExpr(attr);
|
|
321
|
+
const layout = attr.name.name === 'onLayout';
|
|
320
322
|
if (fn.type === 'Identifier' && env.callbacks?.has(fn.name)) {
|
|
321
323
|
// A useCallback compiles to one shared handler, namespaced by cbPrefix so each child instance gets its own.
|
|
324
|
+
// Its onLayout use gets a handler of its own, since only that event carries the layout rect. The key's
|
|
325
|
+
// `layout:` and the name's `er_cbl_` can't come from an identifier, so they never meet another callback.
|
|
322
326
|
const callbackKey = `${env.cbPrefix ?? ''}${fn.name}`;
|
|
323
|
-
|
|
327
|
+
const emittedKey = layout ? `layout:${callbackKey}` : callbackKey;
|
|
328
|
+
let handlerName = out.cbEmitted.get(emittedKey);
|
|
324
329
|
if (!handlerName) {
|
|
325
|
-
handlerName =
|
|
326
|
-
out.cbEmitted.set(
|
|
330
|
+
handlerName = `${layout ? 'er_cbl_' : 'er_cb_'}${callbackKey}`;
|
|
331
|
+
out.cbEmitted.set(emittedKey, handlerName);
|
|
327
332
|
out.handlers.push({
|
|
328
333
|
kind: 'callback',
|
|
329
334
|
name: handlerName,
|
|
330
|
-
callback: lowerHandler(env.callbacks.get(fn.name), env, state, out),
|
|
335
|
+
callback: lowerHandler(env.callbacks.get(fn.name), { ...env, layout }, state, out),
|
|
331
336
|
});
|
|
332
337
|
}
|
|
333
338
|
return handlerName;
|
|
@@ -339,14 +344,14 @@ export function lowerEventHandler(attr, out, env, state) {
|
|
|
339
344
|
out.handlers.push({
|
|
340
345
|
kind: 'callback',
|
|
341
346
|
name: handlerName,
|
|
342
|
-
callback: lowerHandler(callbackProp.node, callbackProp.env, callbackProp.state, out),
|
|
347
|
+
callback: lowerHandler(callbackProp.node, { ...callbackProp.env, layout }, callbackProp.state, out),
|
|
343
348
|
});
|
|
344
349
|
}
|
|
345
350
|
else if (isFn(fn)) {
|
|
346
351
|
out.handlers.push({
|
|
347
352
|
kind: 'callback',
|
|
348
353
|
name: handlerName,
|
|
349
|
-
callback: lowerHandler(fn, env, state, out),
|
|
354
|
+
callback: lowerHandler(fn, { ...env, layout }, state, out),
|
|
350
355
|
});
|
|
351
356
|
}
|
|
352
357
|
else {
|
|
@@ -467,8 +472,12 @@ function emitNodeImpl(element, scope, out, env, state, opts = {}) {
|
|
|
467
472
|
const text = tag === 'Text' && !spans
|
|
468
473
|
? lowerNodeText(element.children, scope, env)
|
|
469
474
|
: null;
|
|
475
|
+
if (text) {
|
|
476
|
+
checkEngineString(constantText(text), 'ER_TEXT_MAX', 'a <Text>');
|
|
477
|
+
}
|
|
470
478
|
// An <Image>'s resize/tint are static, so fold them into staticAssigns for both the static and dynamic paths.
|
|
471
479
|
const image = tag === 'Image' ? resolveImageAttrs(element, env, out) : null;
|
|
480
|
+
checkEngineString(image?.imageName ?? null, 'ER_IMAGE_NAME_MAX', `image name "${image?.imageName}"`);
|
|
472
481
|
if (image?.resizeMode) {
|
|
473
482
|
staticAssigns.push({ field: 'resize_mode', expr: image.resizeMode });
|
|
474
483
|
}
|
|
@@ -554,7 +563,7 @@ function emitNodeImpl(element, scope, out, env, state, opts = {}) {
|
|
|
554
563
|
image: image?.imageNameDyn != null
|
|
555
564
|
? { kind: 'value', value: image.imageNameDyn }
|
|
556
565
|
: image?.imageName != null
|
|
557
|
-
? { kind: 'static', name: image.imageName
|
|
566
|
+
? { kind: 'static', name: image.imageName }
|
|
558
567
|
: null,
|
|
559
568
|
spans,
|
|
560
569
|
wiring,
|
|
@@ -648,7 +657,11 @@ function omitUndefinedAttrs(element, scope, env) {
|
|
|
648
657
|
undefined,
|
|
649
658
|
});
|
|
650
659
|
try {
|
|
651
|
-
|
|
660
|
+
const value = evalStatic(attr.value.expression, foldingScope, 'boot');
|
|
661
|
+
if (buildValueOf(value) !== undefined)
|
|
662
|
+
return true;
|
|
663
|
+
foldBoot(value); // undefined on this panel only: omitting it assumes the panel
|
|
664
|
+
return false;
|
|
652
665
|
}
|
|
653
666
|
catch {
|
|
654
667
|
return true; // not a compile-time value — its reader decides
|