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.
- package/NOTICE +5 -0
- package/README.md +8 -3
- package/aot/app-file-loader.mjs +116 -0
- package/aot/compile.mjs +180 -90
- package/aot/compiler/animations.mjs +568 -317
- package/aot/compiler/boot.mjs +97 -35
- package/aot/compiler/branch-merge.mjs +4 -3
- package/aot/compiler/check.mjs +70 -18
- package/aot/compiler/collect.mjs +787 -288
- package/aot/compiler/contexts.mjs +391 -0
- package/aot/compiler/control-flow.mjs +439 -268
- package/aot/compiler/custom-hooks.mjs +686 -0
- package/aot/compiler/diagnostics.mjs +22 -25
- package/aot/compiler/elements/activity-indicator.mjs +25 -24
- package/aot/compiler/elements/button.mjs +182 -0
- package/aot/compiler/elements/dial.mjs +91 -77
- package/aot/compiler/elements/flat-list.mjs +24 -22
- package/aot/compiler/elements/image-background.mjs +76 -0
- package/aot/compiler/elements/image.mjs +52 -50
- package/aot/compiler/elements/modal.mjs +31 -30
- package/aot/compiler/elements/props.mjs +61 -26
- package/aot/compiler/elements/rewrite.mjs +118 -0
- package/aot/compiler/elements/section-list.mjs +370 -0
- package/aot/compiler/elements/switch.mjs +42 -34
- package/aot/compiler/elements/text-input.mjs +34 -32
- package/aot/compiler/expressions.mjs +1685 -392
- package/aot/compiler/handlers.mjs +2029 -547
- package/aot/compiler/helper-values.mjs +312 -0
- package/aot/compiler/ir/functions.mjs +11 -1
- package/aot/compiler/ir/nodes.mjs +43 -4
- package/aot/compiler/ir/reads.mjs +223 -22
- package/aot/compiler/ir/text.mjs +5 -1
- package/aot/compiler/ir/types.mjs +26 -14
- package/aot/compiler/ir/vectors.mjs +5 -1
- package/aot/compiler/kept-states.mjs +177 -0
- package/aot/compiler/keyboard.mjs +17 -7
- package/aot/compiler/list-items.mjs +226 -0
- package/aot/compiler/list-order.mjs +586 -0
- package/aot/compiler/list-split.mjs +259 -0
- package/aot/compiler/loops.mjs +582 -0
- package/aot/compiler/lower.mjs +246 -111
- package/aot/compiler/native-files.mjs +439 -0
- package/aot/compiler/native-header.mjs +335 -0
- package/aot/compiler/native-modules.mjs +1173 -0
- package/aot/compiler/nodes.mjs +195 -172
- package/aot/compiler/options.mjs +37 -31
- package/aot/compiler/out.mjs +32 -23
- package/aot/compiler/package/animations.mjs +779 -0
- package/aot/compiler/package/arena.mjs +252 -0
- package/aot/compiler/package/assemble.mjs +175 -0
- package/aot/compiler/package/bytecode.mjs +315 -0
- package/aot/compiler/package/checks.mjs +1026 -0
- package/aot/compiler/package/codegen.mjs +2168 -0
- package/aot/compiler/package/enums.mjs +148 -0
- package/aot/compiler/package/format.mjs +771 -0
- package/aot/compiler/package/layouts.mjs +136 -0
- package/aot/compiler/package/lower.mjs +2103 -0
- package/aot/compiler/package/props.mjs +118 -0
- package/aot/compiler/package/string-caps.mjs +515 -0
- package/aot/compiler/package/tables.mjs +127 -0
- package/aot/compiler/package/vectors.mjs +502 -0
- package/aot/compiler/package/writer.mjs +686 -0
- package/aot/compiler/pan-responder.mjs +69 -61
- package/aot/compiler/parse.mjs +23 -21
- package/aot/compiler/record-shapes.mjs +246 -0
- package/aot/compiler/records.mjs +654 -0
- package/aot/compiler/reducers.mjs +272 -0
- package/aot/compiler/static-eval.mjs +340 -30
- package/aot/compiler/style-text.mjs +178 -174
- package/aot/compiler/svg.mjs +480 -251
- package/aot/compiler/switch-cases.mjs +198 -0
- package/aot/compiler/tagged-records.mjs +450 -0
- package/aot/compiler/typing.mjs +307 -0
- package/aot/compiler/updaters.mjs +320 -0
- package/aot/compiler/window-dimensions.mjs +94 -0
- package/aot/compiler/worked-values.mjs +319 -0
- package/aot/demo-file.mjs +30 -0
- package/aot/screenshot-smoke.mjs +54 -40
- package/aot/style-map.mjs +152 -92
- 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 +11 -7
- package/assets/emit-c.mjs +77 -58
- package/assets/emit-container.mjs +123 -37
- 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 +23 -13
- package/cli.mjs +402 -172
- package/compile-bin.mjs +3 -3
- package/flash.mjs +537 -0
- package/hotreload/dev-device.mjs +90 -33
- package/hotreload/pack-app.mjs +55 -43
- package/hotreload/pack-split.mjs +62 -64
- package/hotreload/package-transfer.mjs +175 -0
- package/hotreload/protocol.mjs +50 -37
- package/hotreload/uploader.mjs +38 -27
- package/hotreload/watch-tree.mjs +19 -19
- package/pack-container.mjs +37 -21
- package/package.json +7 -8
- 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 +113 -94
- package/src/embedded-react/Animated.js +24 -24
- package/src/embedded-react/Dimensions.js +37 -0
- package/src/embedded-react/Easing.js +1 -1
- package/src/embedded-react/FlatList.js +3 -3
- 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 +7 -9
- package/src/embedded-react/StyleSheet.js +4 -3
- package/src/embedded-react/TouchableOpacity.js +13 -8
- package/src/embedded-react/index.d.ts +88 -8
- package/src/embedded-react/index.js +2 -0
- 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/nativeModule.js +462 -0
- 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
|
@@ -17,14 +17,19 @@
|
|
|
17
17
|
- Imports
|
|
18
18
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
19
19
|
import { attemptLowering } from './check.mjs';
|
|
20
|
-
import { INT } from './ir/types.mjs';
|
|
20
|
+
import { BOOL, INT } from './ir/types.mjs';
|
|
21
21
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
22
22
|
- Constants
|
|
23
23
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
24
24
|
/** The kinds of value a boot slot holds. */
|
|
25
25
|
const SLOT_KINDS = new Set(['bool', 'int', 'float', 'string']);
|
|
26
|
+
/** The name the panel's size is read by once `useWindowDimensions()` is rewritten, which no name in the app can take. */
|
|
27
|
+
export const PANEL_KEY = '<panel>';
|
|
26
28
|
/** The current compile's boot values, or null outside a compile. */
|
|
27
29
|
let context = null;
|
|
30
|
+
/** The longest source text an error quotes, and what ends a longer one. */
|
|
31
|
+
const MAX_QUOTED_LENGTH = 80;
|
|
32
|
+
const ELLIPSIS = '...';
|
|
28
33
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
29
34
|
- Implementation
|
|
30
35
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
@@ -161,7 +166,7 @@ export function nameBootValues(value, name) {
|
|
|
161
166
|
}
|
|
162
167
|
}
|
|
163
168
|
/**
|
|
164
|
-
* The `screen` global: its width and height are boot values, set from
|
|
169
|
+
* The `screen` global: its width and height are boot values, set from the panel the app boots on.
|
|
165
170
|
*
|
|
166
171
|
* @param screen The panel the build is compiled for.
|
|
167
172
|
* @param screen.width Its width.
|
|
@@ -173,12 +178,38 @@ export const screenBinding = (screen) => ({
|
|
|
173
178
|
width: new BootValue(null, {}, screen.width, true, null, 'width'),
|
|
174
179
|
height: new BootValue(null, {}, screen.height, true, null, 'height'),
|
|
175
180
|
});
|
|
181
|
+
/**
|
|
182
|
+
* The slot boot reads whether an optional native module is there into, added on first use.
|
|
183
|
+
*
|
|
184
|
+
* @param module The module's index among the optional modules.
|
|
185
|
+
* @param name Its name, which the slot is named after.
|
|
186
|
+
*
|
|
187
|
+
* @returns The slot.
|
|
188
|
+
*/
|
|
189
|
+
export function nativeAvailableSlot(module, name) {
|
|
190
|
+
if (!context) {
|
|
191
|
+
throw new Error('AOT: a native module is read outside a compile');
|
|
192
|
+
}
|
|
193
|
+
const found = context.slots.find(slot => slot.initializer.kind === 'native' && slot.initializer.module === module);
|
|
194
|
+
if (found)
|
|
195
|
+
return found;
|
|
196
|
+
const slot = {
|
|
197
|
+
field: slotField(`${name}_available`),
|
|
198
|
+
type: BOOL,
|
|
199
|
+
initializer: { kind: 'native', module },
|
|
200
|
+
};
|
|
201
|
+
context.slots.push(slot);
|
|
202
|
+
return slot;
|
|
203
|
+
}
|
|
176
204
|
/**
|
|
177
205
|
* Starts recording a compile's boot values.
|
|
206
|
+
*
|
|
207
|
+
* @param source The source text.
|
|
178
208
|
*/
|
|
179
|
-
export function beginBoot() {
|
|
209
|
+
export function beginBoot(source = '') {
|
|
180
210
|
context = {
|
|
181
|
-
|
|
211
|
+
source,
|
|
212
|
+
environment: null,
|
|
182
213
|
lower: null,
|
|
183
214
|
slots: [],
|
|
184
215
|
assumed: new Set(),
|
|
@@ -189,12 +220,12 @@ export function beginBoot() {
|
|
|
189
220
|
/**
|
|
190
221
|
* Gives the compile's boot values the environment and lowering their slots are worked out with.
|
|
191
222
|
*
|
|
192
|
-
* @param
|
|
223
|
+
* @param environment The app's environment.
|
|
193
224
|
* @param lower The expression lowering.
|
|
194
225
|
*/
|
|
195
|
-
export function setBootLowering(
|
|
226
|
+
export function setBootLowering(environment, lower) {
|
|
196
227
|
if (context) {
|
|
197
|
-
context.
|
|
228
|
+
context.environment = environment;
|
|
198
229
|
context.lower = lower;
|
|
199
230
|
}
|
|
200
231
|
}
|
|
@@ -210,30 +241,60 @@ export function endBoot() {
|
|
|
210
241
|
// Look each assumed value's slot up while the context still lowers, so the guard can read it.
|
|
211
242
|
const assumptions = [];
|
|
212
243
|
const guarded = new Set();
|
|
213
|
-
let
|
|
244
|
+
let panelSource = null;
|
|
214
245
|
const assume = (value) => {
|
|
215
246
|
const slot = bootSlotOf(value);
|
|
216
247
|
const buildValue = buildValueOf(value);
|
|
217
248
|
if (slot && isGuardable(buildValue)) {
|
|
218
249
|
if (!guarded.has(slot)) {
|
|
219
250
|
guarded.add(slot);
|
|
220
|
-
assumptions.push({
|
|
251
|
+
assumptions.push({
|
|
252
|
+
kind: 'value',
|
|
253
|
+
slot,
|
|
254
|
+
value: buildValue,
|
|
255
|
+
source: sourceOfValue(value),
|
|
256
|
+
});
|
|
221
257
|
}
|
|
222
258
|
}
|
|
223
259
|
else if (value.basis.length) {
|
|
224
260
|
value.basis.forEach(assume);
|
|
225
261
|
}
|
|
226
262
|
else {
|
|
227
|
-
|
|
263
|
+
panelSource ??= sourceOfValue(value) ?? '';
|
|
228
264
|
}
|
|
229
265
|
};
|
|
230
266
|
ending.assumed.forEach(assume);
|
|
231
|
-
if (
|
|
232
|
-
assumptions.push({ kind: 'panel' });
|
|
267
|
+
if (panelSource !== null) {
|
|
268
|
+
assumptions.push({ kind: 'panel', source: panelSource || null });
|
|
233
269
|
}
|
|
234
270
|
context = null;
|
|
235
271
|
return { slots: ending.slots, assumptions };
|
|
236
272
|
}
|
|
273
|
+
/**
|
|
274
|
+
* An expression's source text, on one line, as an error names it.
|
|
275
|
+
*
|
|
276
|
+
* @param node The expression.
|
|
277
|
+
*
|
|
278
|
+
* @returns The text, or null outside a compile.
|
|
279
|
+
*/
|
|
280
|
+
export function bootSourceText(node) {
|
|
281
|
+
if (!context?.source || node.start == null || node.end == null)
|
|
282
|
+
return null;
|
|
283
|
+
const text = context.source.slice(node.start, node.end).replace(/\s+/g, ' ');
|
|
284
|
+
return text.length > MAX_QUOTED_LENGTH
|
|
285
|
+
? `${text.slice(0, MAX_QUOTED_LENGTH - ELLIPSIS.length)}${ELLIPSIS}`
|
|
286
|
+
: text;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* What a boot value is called in an error: its source, or the panel dimension it is.
|
|
290
|
+
*
|
|
291
|
+
* @param value The value.
|
|
292
|
+
*
|
|
293
|
+
* @returns The text, or null when it has none.
|
|
294
|
+
*/
|
|
295
|
+
const sourceOfValue = (value) => value.dimension
|
|
296
|
+
? `screen.${value.dimension}`
|
|
297
|
+
: value.node && bootSourceText(value.node);
|
|
237
298
|
/**
|
|
238
299
|
* Drops a compile's boot values after it failed.
|
|
239
300
|
*/
|
|
@@ -251,7 +312,7 @@ const isGuardable = (value) => typeof value === 'string' ||
|
|
|
251
312
|
typeof value === 'boolean' ||
|
|
252
313
|
(typeof value === 'number' && Number.isFinite(value));
|
|
253
314
|
/**
|
|
254
|
-
*
|
|
315
|
+
* An identifier for a slot named after `name`, unique among the compile's slots.
|
|
255
316
|
*
|
|
256
317
|
* @param name The name.
|
|
257
318
|
*
|
|
@@ -295,29 +356,29 @@ function sameExpr(first, second) {
|
|
|
295
356
|
* The environment a slot's expression lowers in: the app's, with no runtime names, and `scope` as its
|
|
296
357
|
* constants.
|
|
297
358
|
*
|
|
298
|
-
* @param
|
|
359
|
+
* @param environment The app's environment.
|
|
299
360
|
* @param scope The names the expression reads.
|
|
300
361
|
*
|
|
301
362
|
* @returns The environment.
|
|
302
363
|
*/
|
|
303
|
-
const bootEnv = (
|
|
304
|
-
...
|
|
364
|
+
const bootEnv = (environment, scope) => ({
|
|
365
|
+
...environment,
|
|
305
366
|
state: new Map(),
|
|
306
367
|
locals: new Map(),
|
|
307
|
-
|
|
368
|
+
constants: scope,
|
|
308
369
|
animations: new Map(),
|
|
309
370
|
refs: new Map(),
|
|
310
371
|
pans: new Map(),
|
|
311
372
|
callbacks: new Map(),
|
|
312
373
|
helpers: new Map(),
|
|
313
374
|
children: null,
|
|
314
|
-
|
|
315
|
-
|
|
375
|
+
functionProps: undefined,
|
|
376
|
+
callbackPrefix: undefined,
|
|
316
377
|
event: null,
|
|
317
378
|
gesture: null,
|
|
318
379
|
pan: null,
|
|
319
|
-
math64:
|
|
320
|
-
|
|
380
|
+
math64: undefined,
|
|
381
|
+
animationLocals: undefined,
|
|
321
382
|
});
|
|
322
383
|
/**
|
|
323
384
|
* The environment a boot value's own expression lowers in, for a caller that lowers it some other way than
|
|
@@ -328,9 +389,9 @@ const bootEnv = (env, scope) => ({
|
|
|
328
389
|
* @returns The environment, or null when boot cannot work the value out.
|
|
329
390
|
*/
|
|
330
391
|
export function bootEnvOf(value) {
|
|
331
|
-
if (!context?.
|
|
392
|
+
if (!context?.environment || !value.lowerable || !value.node)
|
|
332
393
|
return null;
|
|
333
|
-
return bootEnv(context.
|
|
394
|
+
return bootEnv(context.environment, value.scope);
|
|
334
395
|
}
|
|
335
396
|
/**
|
|
336
397
|
* The slot boot reads a value from, lowered on first use, after the slots its expression reads. A value boot
|
|
@@ -343,7 +404,7 @@ export function bootEnvOf(value) {
|
|
|
343
404
|
export function bootSlotOf(value) {
|
|
344
405
|
if (value.slot !== undefined)
|
|
345
406
|
return value.slot;
|
|
346
|
-
if (!context?.
|
|
407
|
+
if (!context?.environment || !context.lower)
|
|
347
408
|
return null;
|
|
348
409
|
// Null first, so an expression that reads itself has no slot.
|
|
349
410
|
value.slot = null;
|
|
@@ -352,18 +413,18 @@ export function bootSlotOf(value) {
|
|
|
352
413
|
slot = {
|
|
353
414
|
field: slotField(`screen_${value.dimension}`),
|
|
354
415
|
type: INT,
|
|
355
|
-
|
|
416
|
+
initializer: { kind: 'screen', dimension: value.dimension },
|
|
356
417
|
};
|
|
357
418
|
}
|
|
358
419
|
else {
|
|
359
420
|
if (!value.lowerable || !value.node)
|
|
360
421
|
return null;
|
|
361
|
-
const {
|
|
362
|
-
let
|
|
422
|
+
const { environment, lower } = context;
|
|
423
|
+
let expression;
|
|
363
424
|
const { lowering } = context;
|
|
364
425
|
lowering.add(value.node);
|
|
365
426
|
try {
|
|
366
|
-
|
|
427
|
+
expression = attemptLowering(() => lower(value.node, bootEnv(environment, value.scope)));
|
|
367
428
|
}
|
|
368
429
|
catch {
|
|
369
430
|
return null;
|
|
@@ -371,22 +432,23 @@ export function bootSlotOf(value) {
|
|
|
371
432
|
finally {
|
|
372
433
|
lowering.delete(value.node);
|
|
373
434
|
}
|
|
374
|
-
if (!SLOT_KINDS.has(
|
|
435
|
+
if (!SLOT_KINDS.has(expression.type.kind))
|
|
375
436
|
return null;
|
|
376
437
|
// 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
|
|
438
|
+
if (expression.kind === 'boot') {
|
|
439
|
+
value.slot = expression.slot;
|
|
440
|
+
return expression.slot;
|
|
380
441
|
}
|
|
381
|
-
const sameSlot = context.slots.find(slot => slot.
|
|
442
|
+
const sameSlot = context.slots.find(slot => slot.initializer.kind === 'expr' &&
|
|
443
|
+
sameExpr(slot.initializer.expression, expression));
|
|
382
444
|
if (sameSlot) {
|
|
383
445
|
value.slot = sameSlot;
|
|
384
446
|
return sameSlot;
|
|
385
447
|
}
|
|
386
448
|
slot = {
|
|
387
449
|
field: slotField(value.name ?? 'value'),
|
|
388
|
-
type:
|
|
389
|
-
|
|
450
|
+
type: expression.type,
|
|
451
|
+
initializer: { kind: 'expr', expression },
|
|
390
452
|
};
|
|
391
453
|
}
|
|
392
454
|
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
|
@@ -27,7 +27,10 @@ const MAX_INTERPOLATION_POINTS = 8;
|
|
|
27
27
|
const MAX_MILLISECONDS = 2 ** 31 - 1;
|
|
28
28
|
/** The most stops a <Dial indicatorGradient> holds (the engine's ER_GRADIENT_MAX_STOPS). */
|
|
29
29
|
export const DIAL_MAX_GRADIENT_STOPS = 4;
|
|
30
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* Where lowering records its checks and typing steps while a compile runs, in order, or null outside one, when
|
|
32
|
+
* each runs at once.
|
|
33
|
+
*/
|
|
31
34
|
let recording = null;
|
|
32
35
|
/** How many fallback attempts are running: a check inside one runs at once, so its failure picks the fallback. */
|
|
33
36
|
let attempts = 0;
|
|
@@ -46,7 +49,7 @@ export function numberProblem(rawValue) {
|
|
|
46
49
|
const value = Number(rawValue);
|
|
47
50
|
if (!Number.isFinite(value)) {
|
|
48
51
|
return aotError(`AOT: a numeric constant folded to ` +
|
|
49
|
-
`${rawValue === undefined ? 'undefined' : String(rawValue)}, which
|
|
52
|
+
`${rawValue === undefined ? 'undefined' : String(rawValue)}, which a number slot cannot hold`, 'the value must be a finite number.');
|
|
50
53
|
}
|
|
51
54
|
if (!Number.isFinite(Math.fround(value))) {
|
|
52
55
|
return aotError(`AOT: the numeric constant ${value} is past the float range`, 'a float holds up to about 3.4e38.');
|
|
@@ -54,13 +57,13 @@ export function numberProblem(rawValue) {
|
|
|
54
57
|
return null;
|
|
55
58
|
}
|
|
56
59
|
/**
|
|
57
|
-
* What is wrong with an animation time, if anything: it is rounded to whole milliseconds, and
|
|
60
|
+
* What is wrong with an animation time, if anything: it is rounded to whole milliseconds, and an int holds those
|
|
58
61
|
* from 0 to INT_MAX.
|
|
59
62
|
*
|
|
60
63
|
* @param field What the time is, for the error.
|
|
61
64
|
* @param rawValue The value; anything `Number()` converts.
|
|
62
65
|
*
|
|
63
|
-
* @returns The error to report, or null for a time
|
|
66
|
+
* @returns The error to report, or null for a time an int holds.
|
|
64
67
|
*/
|
|
65
68
|
export function millisecondsProblem(field, rawValue) {
|
|
66
69
|
const hint = `a time is a number of milliseconds from 0 to ${MAX_MILLISECONDS}.`;
|
|
@@ -111,6 +114,8 @@ export function checkProblem(subject) {
|
|
|
111
114
|
return subject.count > DIAL_MAX_GRADIENT_STOPS
|
|
112
115
|
? aotError(`AOT: <Dial indicatorGradient> takes at most ${DIAL_MAX_GRADIENT_STOPS} stops (got ${subject.count})`, "the engine's arc holds 4 (ER_GRADIENT_MAX_STOPS); merge stops that sit close together.")
|
|
113
116
|
: null;
|
|
117
|
+
case 'typing':
|
|
118
|
+
return subject.problem;
|
|
114
119
|
}
|
|
115
120
|
}
|
|
116
121
|
/**
|
|
@@ -118,19 +123,38 @@ export function checkProblem(subject) {
|
|
|
118
123
|
* reported; otherwise, or inside a fallback attempt, it is checked at once.
|
|
119
124
|
*
|
|
120
125
|
* @param subject The subject.
|
|
121
|
-
* @param
|
|
126
|
+
* @param location Where its error is reported, when that is more exact than the node being lowered.
|
|
122
127
|
*/
|
|
123
|
-
export function check(subject,
|
|
128
|
+
export function check(subject, location) {
|
|
124
129
|
if (recording && !attempts) {
|
|
125
|
-
recording.push({ ...subject,
|
|
130
|
+
recording.push({ ...subject, location: location ?? currentLoc() });
|
|
126
131
|
return;
|
|
127
132
|
}
|
|
128
133
|
const problem = checkProblem(subject);
|
|
129
134
|
if (problem) {
|
|
130
|
-
locateError(problem,
|
|
135
|
+
locateError(problem, location);
|
|
131
136
|
throw problem;
|
|
132
137
|
}
|
|
133
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Whether lowering is leaving types to the typing pass: during a compile, outside a fallback attempt.
|
|
141
|
+
*
|
|
142
|
+
* @returns True when a typing step is recorded rather than run.
|
|
143
|
+
*/
|
|
144
|
+
export const defersTyping = () => recording !== null && !attempts;
|
|
145
|
+
/**
|
|
146
|
+
* Runs what depends on a type. During a compile it is recorded for the typing pass, which runs it once the
|
|
147
|
+
* slot widths are known; otherwise, or inside a fallback attempt, it runs at once.
|
|
148
|
+
*
|
|
149
|
+
* @param run The step.
|
|
150
|
+
*/
|
|
151
|
+
export function whenTyped(run) {
|
|
152
|
+
if (recording && !attempts) {
|
|
153
|
+
recording.push({ kind: 'typingStep', run, location: currentLoc() });
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
run();
|
|
157
|
+
}
|
|
134
158
|
/**
|
|
135
159
|
* Checks a number the app stores as a float (see check).
|
|
136
160
|
*
|
|
@@ -162,33 +186,61 @@ export function runChecks(checks) {
|
|
|
162
186
|
for (const recorded of checks) {
|
|
163
187
|
const problem = checkProblem(recorded);
|
|
164
188
|
if (problem) {
|
|
165
|
-
if (recorded.
|
|
166
|
-
problem.aotLoc = recorded.
|
|
189
|
+
if (recorded.location) {
|
|
190
|
+
problem.aotLoc = recorded.location;
|
|
167
191
|
}
|
|
168
192
|
throw problem;
|
|
169
193
|
}
|
|
170
194
|
}
|
|
171
195
|
}
|
|
172
196
|
/**
|
|
173
|
-
* Lowers with its checks recorded rather than run
|
|
174
|
-
*
|
|
197
|
+
* Lowers with its checks and typing steps recorded rather than run, then runs the typing pass: each step, in
|
|
198
|
+
* the order lowering recorded it, until one fails. That one becomes a check, so the check pass reports the first
|
|
199
|
+
* problem in the app. When lowering fails, both passes run over what was recorded before the failure, so the
|
|
200
|
+
* first problem is still the one reported.
|
|
175
201
|
*
|
|
176
202
|
* @param lower The lowering.
|
|
203
|
+
* @param beforeTyping Runs once lowering is over, before the typing pass.
|
|
177
204
|
*
|
|
178
205
|
* @returns What lowering returns, and its checks, in order.
|
|
179
206
|
*/
|
|
180
|
-
export function lowerWithChecks(lower) {
|
|
181
|
-
const
|
|
207
|
+
export function lowerWithChecks(lower, beforeTyping = () => { }) {
|
|
208
|
+
const steps = [];
|
|
182
209
|
const outer = recording;
|
|
183
|
-
recording =
|
|
210
|
+
recording = steps;
|
|
211
|
+
let lowered;
|
|
184
212
|
try {
|
|
185
|
-
|
|
213
|
+
lowered = { result: lower() };
|
|
186
214
|
}
|
|
187
215
|
catch (error) {
|
|
188
|
-
|
|
189
|
-
throw error;
|
|
216
|
+
lowered = { error };
|
|
190
217
|
}
|
|
191
218
|
finally {
|
|
192
219
|
recording = outer;
|
|
193
220
|
}
|
|
221
|
+
beforeTyping();
|
|
222
|
+
const checks = [];
|
|
223
|
+
for (const step of steps) {
|
|
224
|
+
if (step.kind !== 'typingStep') {
|
|
225
|
+
checks.push(step);
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
try {
|
|
229
|
+
step.run();
|
|
230
|
+
}
|
|
231
|
+
catch (error) {
|
|
232
|
+
locateError(error, step.location);
|
|
233
|
+
checks.push({
|
|
234
|
+
kind: 'typing',
|
|
235
|
+
problem: error,
|
|
236
|
+
location: error.aotLoc,
|
|
237
|
+
});
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if ('error' in lowered) {
|
|
242
|
+
runChecks(checks);
|
|
243
|
+
throw lowered.error;
|
|
244
|
+
}
|
|
245
|
+
return { result: lowered.result, checks };
|
|
194
246
|
}
|