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
|
@@ -37,6 +37,22 @@ const FLOAT_MATH_C = {
|
|
|
37
37
|
pow: 'powf',
|
|
38
38
|
mod: 'fmodf',
|
|
39
39
|
};
|
|
40
|
+
/** The C function each float Math function prints as when a boot value is worked out in double precision. */
|
|
41
|
+
const DOUBLE_MATH_C = {
|
|
42
|
+
sin: 'sin',
|
|
43
|
+
cos: 'cos',
|
|
44
|
+
tan: 'tan',
|
|
45
|
+
sqrt: 'sqrt',
|
|
46
|
+
abs: 'fabs',
|
|
47
|
+
round: 'app_round',
|
|
48
|
+
floor: 'floor',
|
|
49
|
+
ceil: 'ceil',
|
|
50
|
+
min: 'fmin',
|
|
51
|
+
max: 'fmax',
|
|
52
|
+
atan2: 'atan2',
|
|
53
|
+
pow: 'pow',
|
|
54
|
+
mod: 'fmod',
|
|
55
|
+
};
|
|
40
56
|
/** The field of the engine's ERRect each onLayout field reads. */
|
|
41
57
|
const LAYOUT_RECT_C = {
|
|
42
58
|
x: 'x',
|
|
@@ -46,6 +62,8 @@ const LAYOUT_RECT_C = {
|
|
|
46
62
|
};
|
|
47
63
|
/** The smallest C int. */
|
|
48
64
|
const INT_MIN = -(2 ** 31);
|
|
65
|
+
/** Whether a fraction prints as a double, as JS computes it, rather than a float (see printInDoubles). */
|
|
66
|
+
let inDoubles = false;
|
|
49
67
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
50
68
|
- Implementation
|
|
51
69
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
@@ -96,7 +114,7 @@ function printGestureField(expr) {
|
|
|
96
114
|
*/
|
|
97
115
|
function printNumber(expr) {
|
|
98
116
|
if (expr.type.kind === 'float') {
|
|
99
|
-
return floatLit(expr.value);
|
|
117
|
+
return inDoubles ? doubleLit(expr.value) : floatLit(expr.value);
|
|
100
118
|
}
|
|
101
119
|
if (expr.type.kind === 'int64') {
|
|
102
120
|
return i64Lit(expr.value);
|
|
@@ -104,6 +122,32 @@ function printNumber(expr) {
|
|
|
104
122
|
// `-2147483648` is `-` applied to 2147483648, which does not fit an int.
|
|
105
123
|
return expr.value === INT_MIN ? '(-2147483647 - 1)' : String(expr.value);
|
|
106
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* A number as a C double constant.
|
|
127
|
+
*
|
|
128
|
+
* @param value The number.
|
|
129
|
+
*
|
|
130
|
+
* @returns Its C constant.
|
|
131
|
+
*/
|
|
132
|
+
export const doubleLit = (value) => floatLit(value).replace(/f$/, '');
|
|
133
|
+
/**
|
|
134
|
+
* Prints with every fraction worked out in double precision, as JS works it out: a value set once at boot then
|
|
135
|
+
* rounds exactly as the compiler's own fold would have.
|
|
136
|
+
*
|
|
137
|
+
* @param print The printing.
|
|
138
|
+
*
|
|
139
|
+
* @returns What it prints.
|
|
140
|
+
*/
|
|
141
|
+
export function printInDoubles(print) {
|
|
142
|
+
const outer = inDoubles;
|
|
143
|
+
inDoubles = true;
|
|
144
|
+
try {
|
|
145
|
+
return print();
|
|
146
|
+
}
|
|
147
|
+
finally {
|
|
148
|
+
inDoubles = outer;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
107
151
|
/**
|
|
108
152
|
* An expression as a C condition (see asCond).
|
|
109
153
|
*
|
|
@@ -112,6 +156,12 @@ function printNumber(expr) {
|
|
|
112
156
|
* @returns C that is true exactly when JS would find it truthy.
|
|
113
157
|
*/
|
|
114
158
|
export const printCondition = (expr) => asCond({ code: printExpr(expr), cType: slotOf(expr.type) });
|
|
159
|
+
/**
|
|
160
|
+
* The C type a fraction is worked out in.
|
|
161
|
+
*
|
|
162
|
+
* @returns `double` while printing in doubles, else `float`.
|
|
163
|
+
*/
|
|
164
|
+
const fraction = () => (inDoubles ? 'double' : 'float');
|
|
115
165
|
/**
|
|
116
166
|
* Prints an expression as C.
|
|
117
167
|
*
|
|
@@ -129,6 +179,8 @@ export function printExpr(expr) {
|
|
|
129
179
|
return expr.value ? '1' : '0';
|
|
130
180
|
case 'state':
|
|
131
181
|
return expr.state.cMember;
|
|
182
|
+
case 'boot':
|
|
183
|
+
return `s_boot.${expr.slot.field}`;
|
|
132
184
|
case 'local':
|
|
133
185
|
return expr.local.code;
|
|
134
186
|
case 'ref':
|
|
@@ -144,11 +196,11 @@ export function printExpr(expr) {
|
|
|
144
196
|
case 'clock':
|
|
145
197
|
return expr.clock === 'Date' ? 'app_date_now()' : 'app_perf_now()';
|
|
146
198
|
case 'pi':
|
|
147
|
-
return '(float)M_PI';
|
|
199
|
+
return inDoubles ? 'M_PI' : '(float)M_PI';
|
|
148
200
|
case 'gesture':
|
|
149
201
|
return printGestureField(expr);
|
|
150
202
|
case 'toFloat':
|
|
151
|
-
return `((
|
|
203
|
+
return `((${fraction()})${printExpr(expr.operand)})`;
|
|
152
204
|
case 'unary': {
|
|
153
205
|
// The operand is parenthesized so `-` on a negative operand prints `(-(-x))`, not `(--x)` (a decrement).
|
|
154
206
|
const operand = expr.op === '!'
|
|
@@ -161,19 +213,22 @@ export function printExpr(expr) {
|
|
|
161
213
|
case 'arithmetic':
|
|
162
214
|
return `(${printExpr(expr.left)} ${expr.op} ${printExpr(expr.right)})`;
|
|
163
215
|
case 'floatDivide':
|
|
164
|
-
return `((
|
|
216
|
+
return `((${fraction()})(${printExpr(expr.left)}) / (${fraction()})(${printExpr(expr.right)}))`;
|
|
165
217
|
case 'narrowRemainder':
|
|
166
218
|
return `((int)(${printExpr(expr.left)} % ${printExpr(expr.right)}))`;
|
|
167
219
|
case 'floatMath': {
|
|
168
|
-
const args = expr.args.map(arg => `(
|
|
169
|
-
|
|
220
|
+
const args = expr.args.map(arg => `(${fraction()})(${printExpr(arg)})`);
|
|
221
|
+
const fn = (inDoubles ? DOUBLE_MATH_C : FLOAT_MATH_C)[expr.fn];
|
|
222
|
+
return `${fn}(${args.join(', ')})`;
|
|
170
223
|
}
|
|
171
224
|
case 'wholeRound':
|
|
172
225
|
return printExpr(expr.operand);
|
|
173
226
|
case 'trunc':
|
|
174
|
-
return
|
|
227
|
+
return inDoubles
|
|
228
|
+
? `app_d2i((double)(${printExpr(expr.operand)}))`
|
|
229
|
+
: `app_f2i((float)(${printExpr(expr.operand)}))`;
|
|
175
230
|
case 'toInt':
|
|
176
|
-
return
|
|
231
|
+
return `${inDoubles ? 'app_d2i' : 'app_f2i'}(${printExpr(expr.operand)})`;
|
|
177
232
|
case 'compare':
|
|
178
233
|
return `(${printExpr(expr.left)} ${expr.op} ${printExpr(expr.right)})`;
|
|
179
234
|
case 'stringEquals':
|
package/aot/compiler/c/nodes.mjs
CHANGED
|
@@ -19,9 +19,10 @@
|
|
|
19
19
|
import { cstr, floatLit } from '../c-syntax.mjs';
|
|
20
20
|
import { printCondition, printExpr } from './expressions.mjs';
|
|
21
21
|
import { panEventName, panQueryName } from './pan-responder.mjs';
|
|
22
|
-
import {
|
|
22
|
+
import { printStringWrite } from './statements.mjs';
|
|
23
|
+
import { formatArgs, printText } from './text.mjs';
|
|
23
24
|
import { printStateDrivenVectorWiring, printVectorOps } from './vectors.mjs';
|
|
24
|
-
import { branchElements, isStateDriven } from '../ir/nodes.mjs';
|
|
25
|
+
import { branchElements, hasRuntimeProps, isStateDriven } from '../ir/nodes.mjs';
|
|
25
26
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
26
27
|
- Implementation
|
|
27
28
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
@@ -93,6 +94,18 @@ function printBind(node, bind, index) {
|
|
|
93
94
|
const interp = bind.interp;
|
|
94
95
|
const name = `interp_${node.id}_${index}`;
|
|
95
96
|
const input = interp.input.map(floatLit).join(', ');
|
|
97
|
+
if (interp.colors) {
|
|
98
|
+
const colors = interp.colors
|
|
99
|
+
.map(c => `0x${c.toString(16).padStart(8, '0').toUpperCase()}u`)
|
|
100
|
+
.join(', ');
|
|
101
|
+
return [
|
|
102
|
+
` {`,
|
|
103
|
+
` static const ERColorInterpolation ${name} = { { ${input} }, { ${colors} }, ` +
|
|
104
|
+
`${interp.input.length}, ${interp.exLeft}, ${interp.exRight} };`,
|
|
105
|
+
` er_anim_value_bind_color(${bind.cVar}, ${node.id}, ${bind.prop}, &${name});`,
|
|
106
|
+
` }`,
|
|
107
|
+
];
|
|
108
|
+
}
|
|
96
109
|
const output = interp.output.map(floatLit).join(', ');
|
|
97
110
|
const table = node.type === 'ER_NODE_ARC'
|
|
98
111
|
? [
|
|
@@ -142,10 +155,10 @@ export function printNode(node) {
|
|
|
142
155
|
const text = node.text ? printText(node.text) : null;
|
|
143
156
|
const imageName = node.image?.kind === 'value'
|
|
144
157
|
? printExpr(node.image.value)
|
|
145
|
-
: node.image
|
|
158
|
+
: node.image
|
|
146
159
|
? cstr(node.image.name)
|
|
147
160
|
: null;
|
|
148
|
-
const build = [` ${id} =
|
|
161
|
+
const build = [` ${id} = app_node_create(${node.type});`];
|
|
149
162
|
let update = null;
|
|
150
163
|
if (isStateDriven(node)) {
|
|
151
164
|
build.push(` s_${id} = ${id};`);
|
|
@@ -158,6 +171,17 @@ export function printNode(node) {
|
|
|
158
171
|
placeholder: node.placeholder,
|
|
159
172
|
};
|
|
160
173
|
}
|
|
174
|
+
else if (hasRuntimeProps(node)) {
|
|
175
|
+
// Props that read-only values worked out at boot are set once, here.
|
|
176
|
+
build.push(...printNodeUpdate({
|
|
177
|
+
nodeId: id,
|
|
178
|
+
styleAssigns: node.constantProps,
|
|
179
|
+
text,
|
|
180
|
+
dynAssigns: node.stateProps,
|
|
181
|
+
imageName,
|
|
182
|
+
placeholder: node.placeholder,
|
|
183
|
+
}, id));
|
|
184
|
+
}
|
|
161
185
|
else {
|
|
162
186
|
build.push(` er_props_default(&p);`);
|
|
163
187
|
for (const prop of node.constantProps) {
|
|
@@ -252,10 +276,11 @@ export function printElementTree(element) {
|
|
|
252
276
|
* A state-driven node's app_update() entry: its props built again, then set.
|
|
253
277
|
*
|
|
254
278
|
* @param update The node's entry.
|
|
279
|
+
* @param target The node's variable: its file-scope handle, unless er_app_build() sets it.
|
|
255
280
|
*
|
|
256
281
|
* @returns The C lines.
|
|
257
282
|
*/
|
|
258
|
-
export function printNodeUpdate(update) {
|
|
283
|
+
export function printNodeUpdate(update, target = `s_${update.nodeId}`) {
|
|
259
284
|
const lines = [` er_props_default(&p);`];
|
|
260
285
|
for (const assign of update.styleAssigns) {
|
|
261
286
|
lines.push(` p.${assign.field} = ${assign.expr};`);
|
|
@@ -266,17 +291,13 @@ export function printNodeUpdate(update) {
|
|
|
266
291
|
if (update.placeholder != null) {
|
|
267
292
|
lines.push(` snprintf(p.placeholder, sizeof(p.placeholder), "%s", ${cstr(update.placeholder)});`);
|
|
268
293
|
}
|
|
294
|
+
// A static image name was checked at compile time; one from state is checked here.
|
|
269
295
|
if (update.imageName != null) {
|
|
270
|
-
lines.push(
|
|
296
|
+
lines.push(...printStringWrite('p.image_name', `"%s", ${update.imageName}`, update.imageName.startsWith('"'), 'image name cut short at ER_IMAGE_NAME_MAX', ' '));
|
|
271
297
|
}
|
|
272
298
|
if (update.text) {
|
|
273
|
-
|
|
274
|
-
lines.push(` snprintf(p.text, sizeof(p.text), ${cstr(update.text.format)}, ${update.text.args.join(', ')});`);
|
|
275
|
-
}
|
|
276
|
-
else {
|
|
277
|
-
lines.push(` snprintf(p.text, sizeof(p.text), "%s", ${cstr(update.text.format.replace(/%%/g, '%'))});`);
|
|
278
|
-
}
|
|
299
|
+
lines.push(...printStringWrite('p.text', formatArgs(update.text), !update.text.args.length, 'text cut short at ER_TEXT_MAX', ' '));
|
|
279
300
|
}
|
|
280
|
-
lines.push(` er_node_set_props(
|
|
301
|
+
lines.push(` er_node_set_props(${target}, &p);`);
|
|
281
302
|
return lines;
|
|
282
303
|
}
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
17
17
|
- Imports
|
|
18
18
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
19
|
-
import { cScalarType } from '../c-syntax.mjs';
|
|
19
|
+
import { cScalarType, cstr } from '../c-syntax.mjs';
|
|
20
20
|
import { printAnimationStart } from './animations.mjs';
|
|
21
21
|
import { printUpdateVector } from './vectors.mjs';
|
|
22
22
|
import { printCondition, printExpr } from './expressions.mjs';
|
|
@@ -31,6 +31,22 @@ const INDENT = ' ';
|
|
|
31
31
|
export const APP_UPDATE_CALL = ' app_update();';
|
|
32
32
|
/** The indent list operations print at, whatever block they sit in. */
|
|
33
33
|
const LIST_INDENT = INDENT;
|
|
34
|
+
/** The file-scope flags that record which state was written since app_update() last ran. */
|
|
35
|
+
export const CHANGED_FLAGS = 's_changed';
|
|
36
|
+
/** Reports a fixed limit the app ran past to stderr, once per place it can happen. */
|
|
37
|
+
export const APP_LIMIT_DEFINITION = `/* Reports a fixed limit the app ran past, once per place it can happen, so a timer appending to a full list
|
|
38
|
+
cannot flood the log. */
|
|
39
|
+
#define APP_LIMIT(msg) \\
|
|
40
|
+
do \\
|
|
41
|
+
{ \\
|
|
42
|
+
static bool reported_; \\
|
|
43
|
+
if (!reported_) \\
|
|
44
|
+
{ \\
|
|
45
|
+
reported_ = true; \\
|
|
46
|
+
fprintf(stderr, "AOT: %s\\n", msg); \\
|
|
47
|
+
} \\
|
|
48
|
+
} while (0)
|
|
49
|
+
`;
|
|
34
50
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
35
51
|
- Implementation
|
|
36
52
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
@@ -42,6 +58,16 @@ const LIST_INDENT = INDENT;
|
|
|
42
58
|
* @returns A pattern that finds it in the C source.
|
|
43
59
|
*/
|
|
44
60
|
const readsMember = (member) => new RegExp(`(^|[^\\w.])${member.replace(/\./g, '\\.')}(?![\\w])`);
|
|
61
|
+
/**
|
|
62
|
+
* The line that flags a state as written, so app_update() sets the nodes that read it again; none when no node
|
|
63
|
+
* reads it.
|
|
64
|
+
*
|
|
65
|
+
* @param state The state.
|
|
66
|
+
* @param indent The line's indentation.
|
|
67
|
+
*
|
|
68
|
+
* @returns The C lines.
|
|
69
|
+
*/
|
|
70
|
+
export const printChangedFlag = (state, indent) => state.isWatched ? [`${indent}${CHANGED_FLAGS}.${state.cField} = 1;`] : [];
|
|
45
71
|
/**
|
|
46
72
|
* A timer as the C call that starts it and evaluates to its id. A timestamp or float delay goes through
|
|
47
73
|
* ToInt32 and a floor at 0, as Flow A's setTimeout does.
|
|
@@ -61,6 +87,38 @@ function printTimerAdd(timer) {
|
|
|
61
87
|
: printExpr(delay);
|
|
62
88
|
return `er_timer_add((int)(${delayMs}), ${timer.isRepeating ? 'true' : 'false'}, ${timer.fn})`;
|
|
63
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* A write into a fixed string buffer. One that can come out too long reports, once, when snprintf cuts it
|
|
92
|
+
* short; a constant was checked to fit at compile time.
|
|
93
|
+
*
|
|
94
|
+
* @param buffer The buffer, as a C lvalue.
|
|
95
|
+
* @param args snprintf's arguments after the buffer and its size.
|
|
96
|
+
* @param isConstant The value is a constant.
|
|
97
|
+
* @param report What APP_LIMIT reports when the value is cut short.
|
|
98
|
+
* @param indent The statement's indentation.
|
|
99
|
+
*
|
|
100
|
+
* @returns The C lines.
|
|
101
|
+
*/
|
|
102
|
+
export function printStringWrite(buffer, args, isConstant, report, indent) {
|
|
103
|
+
const write = `snprintf(${buffer}, sizeof(${buffer}), ${args})`;
|
|
104
|
+
if (isConstant) {
|
|
105
|
+
return [`${indent}${write};`];
|
|
106
|
+
}
|
|
107
|
+
return [
|
|
108
|
+
`${indent}if (${write} >= (int)sizeof(${buffer}))`,
|
|
109
|
+
`${indent}{`,
|
|
110
|
+
`${indent}${INDENT}APP_LIMIT(${cstr(report)});`,
|
|
111
|
+
`${indent}}`,
|
|
112
|
+
];
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The report for an app string buffer cut short.
|
|
116
|
+
*
|
|
117
|
+
* @param what What the buffer holds.
|
|
118
|
+
*
|
|
119
|
+
* @returns The report.
|
|
120
|
+
*/
|
|
121
|
+
const cutShort = (what) => `${what} cut short, raise ER_AOT_LIST_STR_CAP`;
|
|
64
122
|
/**
|
|
65
123
|
* A string state write. snprintf's source and destination may not overlap, so a value that reads the slot
|
|
66
124
|
* itself (`setLabel(label + '!')`) is built in a temporary first.
|
|
@@ -68,31 +126,32 @@ function printTimerAdd(timer) {
|
|
|
68
126
|
* @param stmt The write.
|
|
69
127
|
* @param indent The statement's indentation.
|
|
70
128
|
*
|
|
71
|
-
* @returns The C
|
|
129
|
+
* @returns The C lines.
|
|
72
130
|
*/
|
|
73
131
|
function printSetStateText(stmt, indent) {
|
|
74
132
|
const member = stmt.state.cMember;
|
|
75
133
|
const format = printText(stmt.text);
|
|
134
|
+
const report = cutShort(`state '${stmt.state.name}'`);
|
|
76
135
|
if (format.args.some(formatArg => readsMember(member).test(formatArg))) {
|
|
77
136
|
return [
|
|
78
137
|
`${indent}{`,
|
|
79
138
|
`${indent} char next[sizeof(${member})];`,
|
|
80
|
-
|
|
139
|
+
...printStringWrite('next', formatArgs(format), false, report, indent + INDENT),
|
|
81
140
|
`${indent} memcpy(${member}, next, strlen(next) + 1);`,
|
|
82
141
|
`${indent}}`,
|
|
83
|
-
]
|
|
142
|
+
];
|
|
84
143
|
}
|
|
85
|
-
return
|
|
144
|
+
return printStringWrite(member, formatArgs(format), !format.args.length, report, indent);
|
|
86
145
|
}
|
|
87
146
|
/**
|
|
88
|
-
* An appended list item: fill the next free slot's fields and count it,
|
|
147
|
+
* An appended list item: fill the next free slot's fields and count it, or report a full list.
|
|
89
148
|
*
|
|
90
149
|
* @param stmt The append.
|
|
91
150
|
*
|
|
92
151
|
* @returns The C lines.
|
|
93
152
|
*/
|
|
94
153
|
function printAppendItem(stmt) {
|
|
95
|
-
const { arrayName, countMember, cap } = stmt.list;
|
|
154
|
+
const { name, arrayName, countMember, cap } = stmt.list;
|
|
96
155
|
const lines = [
|
|
97
156
|
`${LIST_INDENT}if (${countMember} < ${cap})`,
|
|
98
157
|
`${LIST_INDENT}{`,
|
|
@@ -100,13 +159,14 @@ function printAppendItem(stmt) {
|
|
|
100
159
|
for (const itemValue of stmt.values) {
|
|
101
160
|
const slot = `${arrayName}[${countMember}].${itemValue.field.key}`;
|
|
102
161
|
if ('text' in itemValue) {
|
|
103
|
-
|
|
162
|
+
const format = printText(itemValue.text);
|
|
163
|
+
lines.push(...printStringWrite(slot, formatArgs(format), !format.args.length, cutShort(`field '${itemValue.field.key}' of list '${name}'`), LIST_INDENT + INDENT));
|
|
104
164
|
}
|
|
105
165
|
else {
|
|
106
166
|
lines.push(`${LIST_INDENT}${INDENT}${slot} = ${printExpr(itemValue.value)};`);
|
|
107
167
|
}
|
|
108
168
|
}
|
|
109
|
-
lines.push(`${LIST_INDENT}${INDENT}${countMember}++;`, `${LIST_INDENT}}`);
|
|
169
|
+
lines.push(`${LIST_INDENT}${INDENT}${countMember}++;`, `${LIST_INDENT}}`, `${LIST_INDENT}else`, `${LIST_INDENT}{`, `${LIST_INDENT}${INDENT}APP_LIMIT(${cstr(`list '${name}' full, raise ER_AOT_LIST_CAP`)});`, `${LIST_INDENT}}`);
|
|
110
170
|
return lines;
|
|
111
171
|
}
|
|
112
172
|
/**
|
|
@@ -128,7 +188,7 @@ function printStmt(stmt, indent) {
|
|
|
128
188
|
: [`${indent}char ${stmt.name}[${stmt.stringCap}];`];
|
|
129
189
|
return [
|
|
130
190
|
...declaration,
|
|
131
|
-
|
|
191
|
+
...printStringWrite(stmt.name, `"%s", ${printExpr(init)}`, init.kind === 'string', cutShort(`local '${stmt.name}'`), indent),
|
|
132
192
|
];
|
|
133
193
|
}
|
|
134
194
|
const declaredType = stmt.isHoisted
|
|
@@ -151,27 +211,44 @@ function printStmt(stmt, indent) {
|
|
|
151
211
|
case 'clearTimer':
|
|
152
212
|
return [`${indent}er_timer_clear(${printExpr(stmt.id)});`];
|
|
153
213
|
case 'setState':
|
|
154
|
-
return [
|
|
214
|
+
return [
|
|
215
|
+
`${indent}${stmt.state.cMember} = ${printExpr(stmt.value)};`,
|
|
216
|
+
...printChangedFlag(stmt.state, indent),
|
|
217
|
+
];
|
|
155
218
|
case 'setStateText':
|
|
156
|
-
return [
|
|
219
|
+
return [
|
|
220
|
+
...printSetStateText(stmt, indent),
|
|
221
|
+
...printChangedFlag(stmt.state, indent),
|
|
222
|
+
];
|
|
157
223
|
case 'clearList':
|
|
158
|
-
return [
|
|
224
|
+
return [
|
|
225
|
+
`${LIST_INDENT}${stmt.list.countMember} = 0;`,
|
|
226
|
+
...printChangedFlag(stmt.list, LIST_INDENT),
|
|
227
|
+
];
|
|
159
228
|
case 'appendItem':
|
|
160
|
-
return
|
|
229
|
+
return [
|
|
230
|
+
...printAppendItem(stmt),
|
|
231
|
+
...printChangedFlag(stmt.list, LIST_INDENT),
|
|
232
|
+
];
|
|
161
233
|
case 'dropLastItem': {
|
|
162
234
|
const count = stmt.list.countMember;
|
|
163
|
-
return [
|
|
235
|
+
return [
|
|
236
|
+
`${LIST_INDENT}if (${count} > 0) ${count}--;`,
|
|
237
|
+
...printChangedFlag(stmt.list, LIST_INDENT),
|
|
238
|
+
];
|
|
164
239
|
}
|
|
165
240
|
case 'keepFirstItems': {
|
|
166
241
|
const count = stmt.list.countMember;
|
|
167
242
|
return [
|
|
168
243
|
`${LIST_INDENT}${count} = (${count} < ${stmt.count}) ? ${count} : ${stmt.count};`,
|
|
244
|
+
...printChangedFlag(stmt.list, LIST_INDENT),
|
|
169
245
|
];
|
|
170
246
|
}
|
|
171
247
|
case 'sliceItems': {
|
|
172
248
|
const count = stmt.list.countMember;
|
|
173
249
|
return [
|
|
174
250
|
`${LIST_INDENT}${count} = app_slice_len(${count}, ${printExpr(stmt.end)});`,
|
|
251
|
+
...printChangedFlag(stmt.list, LIST_INDENT),
|
|
175
252
|
];
|
|
176
253
|
}
|
|
177
254
|
case 'writeRef':
|
package/aot/compiler/check.mjs
CHANGED
|
@@ -17,12 +17,14 @@
|
|
|
17
17
|
- Imports
|
|
18
18
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
19
19
|
import { GRAD_MAX_STOPS } from '../../src/embedded-react/svg-ops.js';
|
|
20
|
-
import { aotError, currentLoc } from './diagnostics.mjs';
|
|
20
|
+
import { aotError, currentLoc, locateError } from './diagnostics.mjs';
|
|
21
21
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
22
22
|
- Constants
|
|
23
23
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
24
24
|
/** The most breakpoints an interpolation holds (the engine's ER_INTERPOLATE_MAX_POINTS). */
|
|
25
25
|
const MAX_INTERPOLATION_POINTS = 8;
|
|
26
|
+
/** The longest time an animation can wait or run for: INT_MAX, since the waits the app counts down take an int. */
|
|
27
|
+
const MAX_MILLISECONDS = 2 ** 31 - 1;
|
|
26
28
|
/** The most stops a <Dial indicatorGradient> holds (the engine's ER_GRADIENT_MAX_STOPS). */
|
|
27
29
|
export const DIAL_MAX_GRADIENT_STOPS = 4;
|
|
28
30
|
/** Where lowering records its checks while a compile runs, or null outside one, when a check runs at once. */
|
|
@@ -51,6 +53,29 @@ export function numberProblem(rawValue) {
|
|
|
51
53
|
}
|
|
52
54
|
return null;
|
|
53
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* What is wrong with an animation time, if anything: it is rounded to whole milliseconds, and C holds those
|
|
58
|
+
* from 0 to INT_MAX.
|
|
59
|
+
*
|
|
60
|
+
* @param field What the time is, for the error.
|
|
61
|
+
* @param rawValue The value; anything `Number()` converts.
|
|
62
|
+
*
|
|
63
|
+
* @returns The error to report, or null for a time C holds.
|
|
64
|
+
*/
|
|
65
|
+
export function millisecondsProblem(field, rawValue) {
|
|
66
|
+
const hint = `a time is a number of milliseconds from 0 to ${MAX_MILLISECONDS}.`;
|
|
67
|
+
const value = Math.round(Number(rawValue));
|
|
68
|
+
if (!Number.isFinite(value)) {
|
|
69
|
+
return aotError(`AOT: ${field} folded to ` +
|
|
70
|
+
`${rawValue === undefined ? 'undefined' : String(rawValue)}, which is not a time`, hint);
|
|
71
|
+
}
|
|
72
|
+
if (value < 0) {
|
|
73
|
+
return aotError(`AOT: ${field} is ${value} ms; a time cannot be negative`, hint);
|
|
74
|
+
}
|
|
75
|
+
return value > MAX_MILLISECONDS
|
|
76
|
+
? aotError(`AOT: ${field} is ${value} ms, past the int range`, hint)
|
|
77
|
+
: null;
|
|
78
|
+
}
|
|
54
79
|
/**
|
|
55
80
|
* What is wrong with a recorded subject, if anything.
|
|
56
81
|
*
|
|
@@ -62,6 +87,8 @@ export function checkProblem(subject) {
|
|
|
62
87
|
switch (subject.kind) {
|
|
63
88
|
case 'number':
|
|
64
89
|
return numberProblem(subject.value);
|
|
90
|
+
case 'milliseconds':
|
|
91
|
+
return millisecondsProblem(subject.field, subject.value);
|
|
65
92
|
case 'interpolationPoints':
|
|
66
93
|
return subject.count > MAX_INTERPOLATION_POINTS
|
|
67
94
|
? aotError(`AOT: .interpolate() supports up to ${MAX_INTERPOLATION_POINTS} breakpoints ` +
|
|
@@ -91,14 +118,16 @@ export function checkProblem(subject) {
|
|
|
91
118
|
* reported; otherwise, or inside a fallback attempt, it is checked at once.
|
|
92
119
|
*
|
|
93
120
|
* @param subject The subject.
|
|
121
|
+
* @param loc Where its error is reported, when that is more exact than the node being lowered.
|
|
94
122
|
*/
|
|
95
|
-
export function check(subject) {
|
|
123
|
+
export function check(subject, loc) {
|
|
96
124
|
if (recording && !attempts) {
|
|
97
|
-
recording.push({ ...subject, loc: currentLoc() });
|
|
125
|
+
recording.push({ ...subject, loc: loc ?? currentLoc() });
|
|
98
126
|
return;
|
|
99
127
|
}
|
|
100
128
|
const problem = checkProblem(subject);
|
|
101
129
|
if (problem) {
|
|
130
|
+
locateError(problem, loc);
|
|
102
131
|
throw problem;
|
|
103
132
|
}
|
|
104
133
|
}
|