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.
- package/NOTICE +1 -1
- package/README.md +8 -4
- package/aot/compile.mjs +178 -58
- package/aot/compiler/animations.mjs +290 -281
- package/aot/compiler/boot.mjs +70 -33
- package/aot/compiler/branch-merge.mjs +4 -3
- package/aot/compiler/check.mjs +9 -9
- package/aot/compiler/collect.mjs +324 -205
- package/aot/compiler/control-flow.mjs +209 -197
- package/aot/compiler/diagnostics.mjs +22 -25
- package/aot/compiler/elements/activity-indicator.mjs +25 -24
- package/aot/compiler/elements/dial.mjs +91 -77
- package/aot/compiler/elements/flat-list.mjs +24 -22
- package/aot/compiler/elements/image.mjs +51 -50
- package/aot/compiler/elements/modal.mjs +31 -30
- package/aot/compiler/elements/props.mjs +23 -23
- package/aot/compiler/elements/switch.mjs +42 -34
- package/aot/compiler/elements/text-input.mjs +34 -32
- package/aot/compiler/expressions.mjs +372 -333
- package/aot/compiler/handlers.mjs +473 -387
- package/aot/compiler/ir/functions.mjs +11 -1
- package/aot/compiler/ir/nodes.mjs +4 -4
- package/aot/compiler/ir/reads.mjs +19 -19
- package/aot/compiler/ir/types.mjs +14 -14
- package/aot/compiler/ir/vectors.mjs +5 -1
- package/aot/compiler/keyboard.mjs +17 -7
- package/aot/compiler/lower.mjs +77 -80
- package/aot/compiler/nodes.mjs +169 -152
- package/aot/compiler/options.mjs +35 -30
- package/aot/compiler/out.mjs +18 -22
- package/aot/compiler/package/animations.mjs +669 -0
- package/aot/compiler/package/arena.mjs +252 -0
- package/aot/compiler/package/assemble.mjs +177 -0
- package/aot/compiler/package/bytecode.mjs +286 -0
- package/aot/compiler/package/checks.mjs +1022 -0
- package/aot/compiler/package/codegen.mjs +1329 -0
- package/aot/compiler/package/enums.mjs +138 -0
- package/aot/compiler/package/format.mjs +760 -0
- package/aot/compiler/package/layouts.mjs +136 -0
- package/aot/compiler/package/lower.mjs +1606 -0
- package/aot/compiler/package/props.mjs +118 -0
- package/aot/compiler/package/tables.mjs +103 -0
- package/aot/compiler/package/vectors.mjs +502 -0
- package/aot/compiler/package/writer.mjs +664 -0
- package/aot/compiler/pan-responder.mjs +69 -61
- package/aot/compiler/parse.mjs +21 -21
- package/aot/compiler/static-eval.mjs +25 -23
- package/aot/compiler/style-text.mjs +161 -172
- package/aot/compiler/svg.mjs +477 -251
- package/aot/screenshot-smoke.mjs +55 -41
- package/aot/style-map.mjs +102 -90
- package/assets/bake-font.mjs +123 -77
- package/assets/bake-image.mjs +39 -22
- package/assets/bake-svg.mjs +361 -262
- package/assets/build-builtin-font.mjs +14 -10
- package/assets/emit-c.mjs +83 -62
- package/assets/emit-container.mjs +124 -38
- package/assets/emit-pack.mjs +77 -67
- package/assets/font-config.mjs +9 -6
- package/assets/font-sizes.mjs +163 -123
- package/assets/glyph-coverage.mjs +74 -54
- package/assets/index.mjs +31 -9
- package/assets/rasterize.mjs +126 -99
- package/assets/svg-loader.mjs +8 -8
- package/build.mjs +16 -14
- package/cli.mjs +359 -172
- package/compile-bin.mjs +5 -5
- package/flash.mjs +537 -0
- package/hotreload/dev-device.mjs +90 -33
- package/hotreload/pack-app.mjs +55 -43
- package/hotreload/pack-split.mjs +46 -37
- package/hotreload/package-transfer.mjs +175 -0
- package/hotreload/protocol.mjs +51 -38
- package/hotreload/uploader.mjs +38 -27
- package/hotreload/watch-tree.mjs +19 -19
- package/pack-container.mjs +31 -23
- package/package.json +11 -12
- package/persist-transform.mjs +34 -28
- package/qjsc-wasm.mjs +25 -14
- package/sim/embedded-react.cjs +1 -1
- package/sim/embedded-react.js +1 -1
- package/sim/embedded-react.wasm +0 -0
- package/sim/index.html +94 -85
- package/sim-server.mjs +101 -82
- package/src/embedded-react/Animated.js +24 -24
- package/src/embedded-react/Easing.js +1 -1
- package/src/embedded-react/FlatList.js +4 -4
- package/src/embedded-react/LayoutAnimation.js +8 -5
- package/src/embedded-react/PanResponder.js +75 -71
- package/src/embedded-react/Pressable.js +2 -8
- package/src/embedded-react/SectionList.js +6 -6
- package/src/embedded-react/StyleSheet.js +4 -3
- package/src/embedded-react/TouchableOpacity.js +13 -8
- package/src/embedded-react/index.d.ts +5 -5
- package/src/embedded-react/layout-anim-config.js +10 -4
- package/src/embedded-react/list-child.js +5 -5
- package/src/embedded-react/named-colors.js +1 -1
- package/src/embedded-react/split-style.js +11 -11
- package/src/embedded-react/svg-ops.js +760 -593
- package/src/embedded-react/useHostValue.js +3 -3
- package/src/embedded-react/usePersistentState.js +6 -6
- package/src/embedded-react/warn-props.js +1 -1
- package/src/host-config.js +60 -53
- package/src/props.js +49 -41
- package/src/renderer.js +7 -4
- package/aot/compiler/assemble.mjs +0 -944
- package/aot/compiler/c/animations.mjs +0 -436
- package/aot/compiler/c/boot.mjs +0 -127
- package/aot/compiler/c/expressions.mjs +0 -270
- package/aot/compiler/c/functions.mjs +0 -268
- package/aot/compiler/c/keyboard.mjs +0 -96
- package/aot/compiler/c/nodes.mjs +0 -303
- package/aot/compiler/c/pan-responder.mjs +0 -136
- package/aot/compiler/c/statements.mjs +0 -319
- package/aot/compiler/c/text.mjs +0 -83
- package/aot/compiler/c/vectors.mjs +0 -381
- package/aot/compiler/c-syntax.mjs +0 -127
package/aot/compiler/boot.mjs
CHANGED
|
@@ -25,6 +25,9 @@ import { INT } from './ir/types.mjs';
|
|
|
25
25
|
const SLOT_KINDS = new Set(['bool', 'int', 'float', 'string']);
|
|
26
26
|
/** The current compile's boot values, or null outside a compile. */
|
|
27
27
|
let context = null;
|
|
28
|
+
/** The longest source text an error quotes, and what ends a longer one. */
|
|
29
|
+
const MAX_QUOTED_LENGTH = 80;
|
|
30
|
+
const ELLIPSIS = '...';
|
|
28
31
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
29
32
|
- Implementation
|
|
30
33
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
@@ -161,7 +164,7 @@ export function nameBootValues(value, name) {
|
|
|
161
164
|
}
|
|
162
165
|
}
|
|
163
166
|
/**
|
|
164
|
-
* The `screen` global: its width and height are boot values, set from
|
|
167
|
+
* The `screen` global: its width and height are boot values, set from the panel the app boots on.
|
|
165
168
|
*
|
|
166
169
|
* @param screen The panel the build is compiled for.
|
|
167
170
|
* @param screen.width Its width.
|
|
@@ -175,10 +178,13 @@ export const screenBinding = (screen) => ({
|
|
|
175
178
|
});
|
|
176
179
|
/**
|
|
177
180
|
* Starts recording a compile's boot values.
|
|
181
|
+
*
|
|
182
|
+
* @param source The source text.
|
|
178
183
|
*/
|
|
179
|
-
export function beginBoot() {
|
|
184
|
+
export function beginBoot(source = '') {
|
|
180
185
|
context = {
|
|
181
|
-
|
|
186
|
+
source,
|
|
187
|
+
environment: null,
|
|
182
188
|
lower: null,
|
|
183
189
|
slots: [],
|
|
184
190
|
assumed: new Set(),
|
|
@@ -189,12 +195,12 @@ export function beginBoot() {
|
|
|
189
195
|
/**
|
|
190
196
|
* Gives the compile's boot values the environment and lowering their slots are worked out with.
|
|
191
197
|
*
|
|
192
|
-
* @param
|
|
198
|
+
* @param environment The app's environment.
|
|
193
199
|
* @param lower The expression lowering.
|
|
194
200
|
*/
|
|
195
|
-
export function setBootLowering(
|
|
201
|
+
export function setBootLowering(environment, lower) {
|
|
196
202
|
if (context) {
|
|
197
|
-
context.
|
|
203
|
+
context.environment = environment;
|
|
198
204
|
context.lower = lower;
|
|
199
205
|
}
|
|
200
206
|
}
|
|
@@ -210,30 +216,60 @@ export function endBoot() {
|
|
|
210
216
|
// Look each assumed value's slot up while the context still lowers, so the guard can read it.
|
|
211
217
|
const assumptions = [];
|
|
212
218
|
const guarded = new Set();
|
|
213
|
-
let
|
|
219
|
+
let panelSource = null;
|
|
214
220
|
const assume = (value) => {
|
|
215
221
|
const slot = bootSlotOf(value);
|
|
216
222
|
const buildValue = buildValueOf(value);
|
|
217
223
|
if (slot && isGuardable(buildValue)) {
|
|
218
224
|
if (!guarded.has(slot)) {
|
|
219
225
|
guarded.add(slot);
|
|
220
|
-
assumptions.push({
|
|
226
|
+
assumptions.push({
|
|
227
|
+
kind: 'value',
|
|
228
|
+
slot,
|
|
229
|
+
value: buildValue,
|
|
230
|
+
source: sourceOfValue(value),
|
|
231
|
+
});
|
|
221
232
|
}
|
|
222
233
|
}
|
|
223
234
|
else if (value.basis.length) {
|
|
224
235
|
value.basis.forEach(assume);
|
|
225
236
|
}
|
|
226
237
|
else {
|
|
227
|
-
|
|
238
|
+
panelSource ??= sourceOfValue(value) ?? '';
|
|
228
239
|
}
|
|
229
240
|
};
|
|
230
241
|
ending.assumed.forEach(assume);
|
|
231
|
-
if (
|
|
232
|
-
assumptions.push({ kind: 'panel' });
|
|
242
|
+
if (panelSource !== null) {
|
|
243
|
+
assumptions.push({ kind: 'panel', source: panelSource || null });
|
|
233
244
|
}
|
|
234
245
|
context = null;
|
|
235
246
|
return { slots: ending.slots, assumptions };
|
|
236
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* An expression's source text, on one line, as an error names it.
|
|
250
|
+
*
|
|
251
|
+
* @param node The expression.
|
|
252
|
+
*
|
|
253
|
+
* @returns The text, or null outside a compile.
|
|
254
|
+
*/
|
|
255
|
+
export function bootSourceText(node) {
|
|
256
|
+
if (!context?.source || node.start == null || node.end == null)
|
|
257
|
+
return null;
|
|
258
|
+
const text = context.source.slice(node.start, node.end).replace(/\s+/g, ' ');
|
|
259
|
+
return text.length > MAX_QUOTED_LENGTH
|
|
260
|
+
? `${text.slice(0, MAX_QUOTED_LENGTH - ELLIPSIS.length)}${ELLIPSIS}`
|
|
261
|
+
: text;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* What a boot value is called in an error: its source, or the panel dimension it is.
|
|
265
|
+
*
|
|
266
|
+
* @param value The value.
|
|
267
|
+
*
|
|
268
|
+
* @returns The text, or null when it has none.
|
|
269
|
+
*/
|
|
270
|
+
const sourceOfValue = (value) => value.dimension
|
|
271
|
+
? `screen.${value.dimension}`
|
|
272
|
+
: value.node && bootSourceText(value.node);
|
|
237
273
|
/**
|
|
238
274
|
* Drops a compile's boot values after it failed.
|
|
239
275
|
*/
|
|
@@ -251,7 +287,7 @@ const isGuardable = (value) => typeof value === 'string' ||
|
|
|
251
287
|
typeof value === 'boolean' ||
|
|
252
288
|
(typeof value === 'number' && Number.isFinite(value));
|
|
253
289
|
/**
|
|
254
|
-
*
|
|
290
|
+
* An identifier for a slot named after `name`, unique among the compile's slots.
|
|
255
291
|
*
|
|
256
292
|
* @param name The name.
|
|
257
293
|
*
|
|
@@ -295,29 +331,29 @@ function sameExpr(first, second) {
|
|
|
295
331
|
* The environment a slot's expression lowers in: the app's, with no runtime names, and `scope` as its
|
|
296
332
|
* constants.
|
|
297
333
|
*
|
|
298
|
-
* @param
|
|
334
|
+
* @param environment The app's environment.
|
|
299
335
|
* @param scope The names the expression reads.
|
|
300
336
|
*
|
|
301
337
|
* @returns The environment.
|
|
302
338
|
*/
|
|
303
|
-
const bootEnv = (
|
|
304
|
-
...
|
|
339
|
+
const bootEnv = (environment, scope) => ({
|
|
340
|
+
...environment,
|
|
305
341
|
state: new Map(),
|
|
306
342
|
locals: new Map(),
|
|
307
|
-
|
|
343
|
+
constants: scope,
|
|
308
344
|
animations: new Map(),
|
|
309
345
|
refs: new Map(),
|
|
310
346
|
pans: new Map(),
|
|
311
347
|
callbacks: new Map(),
|
|
312
348
|
helpers: new Map(),
|
|
313
349
|
children: null,
|
|
314
|
-
|
|
315
|
-
|
|
350
|
+
functionProps: undefined,
|
|
351
|
+
callbackPrefix: undefined,
|
|
316
352
|
event: null,
|
|
317
353
|
gesture: null,
|
|
318
354
|
pan: null,
|
|
319
355
|
math64: false,
|
|
320
|
-
|
|
356
|
+
animationLocals: undefined,
|
|
321
357
|
});
|
|
322
358
|
/**
|
|
323
359
|
* The environment a boot value's own expression lowers in, for a caller that lowers it some other way than
|
|
@@ -328,9 +364,9 @@ const bootEnv = (env, scope) => ({
|
|
|
328
364
|
* @returns The environment, or null when boot cannot work the value out.
|
|
329
365
|
*/
|
|
330
366
|
export function bootEnvOf(value) {
|
|
331
|
-
if (!context?.
|
|
367
|
+
if (!context?.environment || !value.lowerable || !value.node)
|
|
332
368
|
return null;
|
|
333
|
-
return bootEnv(context.
|
|
369
|
+
return bootEnv(context.environment, value.scope);
|
|
334
370
|
}
|
|
335
371
|
/**
|
|
336
372
|
* The slot boot reads a value from, lowered on first use, after the slots its expression reads. A value boot
|
|
@@ -343,7 +379,7 @@ export function bootEnvOf(value) {
|
|
|
343
379
|
export function bootSlotOf(value) {
|
|
344
380
|
if (value.slot !== undefined)
|
|
345
381
|
return value.slot;
|
|
346
|
-
if (!context?.
|
|
382
|
+
if (!context?.environment || !context.lower)
|
|
347
383
|
return null;
|
|
348
384
|
// Null first, so an expression that reads itself has no slot.
|
|
349
385
|
value.slot = null;
|
|
@@ -352,18 +388,18 @@ export function bootSlotOf(value) {
|
|
|
352
388
|
slot = {
|
|
353
389
|
field: slotField(`screen_${value.dimension}`),
|
|
354
390
|
type: INT,
|
|
355
|
-
|
|
391
|
+
initializer: { kind: 'screen', dimension: value.dimension },
|
|
356
392
|
};
|
|
357
393
|
}
|
|
358
394
|
else {
|
|
359
395
|
if (!value.lowerable || !value.node)
|
|
360
396
|
return null;
|
|
361
|
-
const {
|
|
362
|
-
let
|
|
397
|
+
const { environment, lower } = context;
|
|
398
|
+
let expression;
|
|
363
399
|
const { lowering } = context;
|
|
364
400
|
lowering.add(value.node);
|
|
365
401
|
try {
|
|
366
|
-
|
|
402
|
+
expression = attemptLowering(() => lower(value.node, bootEnv(environment, value.scope)));
|
|
367
403
|
}
|
|
368
404
|
catch {
|
|
369
405
|
return null;
|
|
@@ -371,22 +407,23 @@ export function bootSlotOf(value) {
|
|
|
371
407
|
finally {
|
|
372
408
|
lowering.delete(value.node);
|
|
373
409
|
}
|
|
374
|
-
if (!SLOT_KINDS.has(
|
|
410
|
+
if (!SLOT_KINDS.has(expression.type.kind))
|
|
375
411
|
return null;
|
|
376
412
|
// A value that only reads another slot shares it, as does one worked out the same way as an earlier slot.
|
|
377
|
-
if (
|
|
378
|
-
value.slot =
|
|
379
|
-
return
|
|
413
|
+
if (expression.kind === 'boot') {
|
|
414
|
+
value.slot = expression.slot;
|
|
415
|
+
return expression.slot;
|
|
380
416
|
}
|
|
381
|
-
const sameSlot = context.slots.find(slot => slot.
|
|
417
|
+
const sameSlot = context.slots.find(slot => slot.initializer.kind === 'expr' &&
|
|
418
|
+
sameExpr(slot.initializer.expression, expression));
|
|
382
419
|
if (sameSlot) {
|
|
383
420
|
value.slot = sameSlot;
|
|
384
421
|
return sameSlot;
|
|
385
422
|
}
|
|
386
423
|
slot = {
|
|
387
424
|
field: slotField(value.name ?? 'value'),
|
|
388
|
-
type:
|
|
389
|
-
|
|
425
|
+
type: expression.type,
|
|
426
|
+
initializer: { kind: 'expr', expression },
|
|
390
427
|
};
|
|
391
428
|
}
|
|
392
429
|
context.slots.push(slot);
|
|
@@ -122,11 +122,12 @@ function isLowerableMath(node) {
|
|
|
122
122
|
node.callee.object.type !== 'Identifier' ||
|
|
123
123
|
node.callee.object.name !== 'Math' ||
|
|
124
124
|
node.callee.property.type !== 'Identifier' ||
|
|
125
|
-
node.arguments.some(
|
|
125
|
+
node.arguments.some(argument => argument.type === 'SpreadElement')) {
|
|
126
126
|
return false;
|
|
127
127
|
}
|
|
128
|
-
const
|
|
129
|
-
return (Object.hasOwn(MATH_ARITY,
|
|
128
|
+
const mathFunction = node.callee.property.name;
|
|
129
|
+
return (Object.hasOwn(MATH_ARITY, mathFunction) &&
|
|
130
|
+
MATH_ARITY[mathFunction] === node.arguments.length);
|
|
130
131
|
}
|
|
131
132
|
/**
|
|
132
133
|
* `test ? whenTrue : whenFalse`, entry by entry where both are object or array literals of the same shape, so
|
package/aot/compiler/check.mjs
CHANGED
|
@@ -46,7 +46,7 @@ export function numberProblem(rawValue) {
|
|
|
46
46
|
const value = Number(rawValue);
|
|
47
47
|
if (!Number.isFinite(value)) {
|
|
48
48
|
return aotError(`AOT: a numeric constant folded to ` +
|
|
49
|
-
`${rawValue === undefined ? 'undefined' : String(rawValue)}, which
|
|
49
|
+
`${rawValue === undefined ? 'undefined' : String(rawValue)}, which a number slot cannot hold`, 'the value must be a finite number.');
|
|
50
50
|
}
|
|
51
51
|
if (!Number.isFinite(Math.fround(value))) {
|
|
52
52
|
return aotError(`AOT: the numeric constant ${value} is past the float range`, 'a float holds up to about 3.4e38.');
|
|
@@ -54,13 +54,13 @@ export function numberProblem(rawValue) {
|
|
|
54
54
|
return null;
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
|
-
* What is wrong with an animation time, if anything: it is rounded to whole milliseconds, and
|
|
57
|
+
* What is wrong with an animation time, if anything: it is rounded to whole milliseconds, and an int holds those
|
|
58
58
|
* from 0 to INT_MAX.
|
|
59
59
|
*
|
|
60
60
|
* @param field What the time is, for the error.
|
|
61
61
|
* @param rawValue The value; anything `Number()` converts.
|
|
62
62
|
*
|
|
63
|
-
* @returns The error to report, or null for a time
|
|
63
|
+
* @returns The error to report, or null for a time an int holds.
|
|
64
64
|
*/
|
|
65
65
|
export function millisecondsProblem(field, rawValue) {
|
|
66
66
|
const hint = `a time is a number of milliseconds from 0 to ${MAX_MILLISECONDS}.`;
|
|
@@ -118,16 +118,16 @@ export function checkProblem(subject) {
|
|
|
118
118
|
* reported; otherwise, or inside a fallback attempt, it is checked at once.
|
|
119
119
|
*
|
|
120
120
|
* @param subject The subject.
|
|
121
|
-
* @param
|
|
121
|
+
* @param location Where its error is reported, when that is more exact than the node being lowered.
|
|
122
122
|
*/
|
|
123
|
-
export function check(subject,
|
|
123
|
+
export function check(subject, location) {
|
|
124
124
|
if (recording && !attempts) {
|
|
125
|
-
recording.push({ ...subject,
|
|
125
|
+
recording.push({ ...subject, location: location ?? currentLoc() });
|
|
126
126
|
return;
|
|
127
127
|
}
|
|
128
128
|
const problem = checkProblem(subject);
|
|
129
129
|
if (problem) {
|
|
130
|
-
locateError(problem,
|
|
130
|
+
locateError(problem, location);
|
|
131
131
|
throw problem;
|
|
132
132
|
}
|
|
133
133
|
}
|
|
@@ -162,8 +162,8 @@ export function runChecks(checks) {
|
|
|
162
162
|
for (const recorded of checks) {
|
|
163
163
|
const problem = checkProblem(recorded);
|
|
164
164
|
if (problem) {
|
|
165
|
-
if (recorded.
|
|
166
|
-
problem.aotLoc = recorded.
|
|
165
|
+
if (recorded.location) {
|
|
166
|
+
problem.aotLoc = recorded.location;
|
|
167
167
|
}
|
|
168
168
|
throw problem;
|
|
169
169
|
}
|