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
|
@@ -1,436 +0,0 @@
|
|
|
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
|
-
- Imports
|
|
18
|
-
---------------------------------------------------------------------------------------------------------------------*/
|
|
19
|
-
import { floatLit } from '../c-syntax.mjs';
|
|
20
|
-
import { printExpr } from './expressions.mjs';
|
|
21
|
-
/*----------------------------------------------------------------------------------------------------------------------
|
|
22
|
-
- Implementation
|
|
23
|
-
---------------------------------------------------------------------------------------------------------------------*/
|
|
24
|
-
/**
|
|
25
|
-
* One animation as a scoped ERAnimConfig and the er_anim_value_animate call that starts it. Animation lines
|
|
26
|
-
* carry their own indent, whatever block they sit in.
|
|
27
|
-
*
|
|
28
|
-
* @param animation The animation.
|
|
29
|
-
* @param configName The config's name, unique within the function.
|
|
30
|
-
* @param onComplete The C function to run when it completes, or null.
|
|
31
|
-
* @param userData What the engine passes that function as user_data, or null.
|
|
32
|
-
*
|
|
33
|
-
* @returns The C block.
|
|
34
|
-
*/
|
|
35
|
-
export function printAnimation(animation, configName, onComplete, userData = null) {
|
|
36
|
-
const set = (field, value) => ` ${configName}.${field} = ${value};`;
|
|
37
|
-
const lines = [
|
|
38
|
-
' {',
|
|
39
|
-
` ERAnimConfig ${configName};`,
|
|
40
|
-
` memset(&${configName}, 0, sizeof(${configName}));`,
|
|
41
|
-
];
|
|
42
|
-
// The curve's own fields.
|
|
43
|
-
const curve = animation.curve;
|
|
44
|
-
if (curve.kind === 'spring') {
|
|
45
|
-
lines.push(set('type', 'ER_ANIM_SPRING'), set('stiffness', floatLit(curve.stiffness)), set('damping', floatLit(curve.damping)), set('mass', floatLit(curve.mass)));
|
|
46
|
-
}
|
|
47
|
-
else if (curve.kind === 'decay') {
|
|
48
|
-
lines.push(set('type', 'ER_ANIM_DECAY'), set('deceleration', floatLit(curve.deceleration)), set('velocity', floatLit(curve.velocity)));
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
lines.push(set('type', 'ER_ANIM_TIMING'), set('duration_ms', String(curve.durationMs)), set('easing', curve.easing));
|
|
52
|
-
if (curve.bezier) {
|
|
53
|
-
const [x1, y1, x2, y2] = curve.bezier.map(point => floatLit(point));
|
|
54
|
-
lines.push(` ${configName}.bezier_x1 = ${x1}; ${configName}.bezier_y1 = ${y1};`, ` ${configName}.bezier_x2 = ${x2}; ${configName}.bezier_y2 = ${y2};`);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
// The fields every curve shares.
|
|
58
|
-
if (animation.delayMs > 0) {
|
|
59
|
-
lines.push(set('delay_ms', String(animation.delayMs)));
|
|
60
|
-
}
|
|
61
|
-
if (animation.isLooping) {
|
|
62
|
-
lines.push(set('loop', 'true'));
|
|
63
|
-
}
|
|
64
|
-
if (onComplete) {
|
|
65
|
-
lines.push(set('on_complete', onComplete));
|
|
66
|
-
}
|
|
67
|
-
if (userData) {
|
|
68
|
-
lines.push(set('on_complete_user_data', userData));
|
|
69
|
-
}
|
|
70
|
-
// Decay with no target is given the value it holds now.
|
|
71
|
-
const to = animation.to
|
|
72
|
-
? printExpr(animation.to)
|
|
73
|
-
: `er_anim_value_get(${animation.handle})`;
|
|
74
|
-
lines.push(` er_anim_value_animate(${animation.handle}, (float)(${to}), &${configName});`, ' }');
|
|
75
|
-
return lines;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Runs a completion as finished, outside the engine's own on_complete.
|
|
79
|
-
*
|
|
80
|
-
* @param completion The completion.
|
|
81
|
-
*
|
|
82
|
-
* @returns The C line.
|
|
83
|
-
*/
|
|
84
|
-
export const printCompletionCall = (completion) => ` ${completion.name}(true, NULL);`;
|
|
85
|
-
/**
|
|
86
|
-
* Starts a completion wait for one run of a composition.
|
|
87
|
-
*
|
|
88
|
-
* @param owner The composition.
|
|
89
|
-
* @param delayMs The wait.
|
|
90
|
-
* @param completion The completion it runs.
|
|
91
|
-
*
|
|
92
|
-
* @returns The C line.
|
|
93
|
-
*/
|
|
94
|
-
const printWaitStart = (owner, delayMs, completion) => ` app_wait_start(${owner}, ${delayMs}, ${completion.name});`;
|
|
95
|
-
/**
|
|
96
|
-
* The completion-wait table and the helpers that drive it, each helper only when the generated code calls it
|
|
97
|
-
* (an unused static function would warn). Every run of a composition has a wait of its own, so starting one never
|
|
98
|
-
* ends another; a stop ends every run of its composition.
|
|
99
|
-
*
|
|
100
|
-
* @param callers The generated code, to look for calls in.
|
|
101
|
-
*
|
|
102
|
-
* @returns The C block.
|
|
103
|
-
*/
|
|
104
|
-
export function printWaitDeclarations(callers) {
|
|
105
|
-
const blocks = [
|
|
106
|
-
`#ifndef ER_AOT_MAX_WAITS
|
|
107
|
-
#define ER_AOT_MAX_WAITS 8
|
|
108
|
-
#endif
|
|
109
|
-
|
|
110
|
-
/* The wait between a run's last animation and its completion: the composition it belongs to (which a stop
|
|
111
|
-
names), the time left, the animations of a joined run still running, and the completion it runs. */
|
|
112
|
-
typedef struct
|
|
113
|
-
{
|
|
114
|
-
int remaining_ms;
|
|
115
|
-
int owner;
|
|
116
|
-
ERAnimCompleteFn done;
|
|
117
|
-
uint8_t state;
|
|
118
|
-
uint8_t parts;
|
|
119
|
-
} ErAnimWait;
|
|
120
|
-
enum
|
|
121
|
-
{
|
|
122
|
-
APP_WAIT_FREE,
|
|
123
|
-
APP_WAIT_PENDING,
|
|
124
|
-
APP_WAIT_DUE,
|
|
125
|
-
APP_WAIT_STOPPING,
|
|
126
|
-
/* A joined run that has completed, kept until its animations still running have reported. */
|
|
127
|
-
APP_WAIT_DRAINING
|
|
128
|
-
};
|
|
129
|
-
static ErAnimWait s_waits[ER_AOT_MAX_WAITS];
|
|
130
|
-
|
|
131
|
-
/* Takes a free wait for one run; runs never share one. */
|
|
132
|
-
static int app_wait_claim(int owner, int ms, int parts, ERAnimCompleteFn done)
|
|
133
|
-
{
|
|
134
|
-
for (int i = 0; i < ER_AOT_MAX_WAITS; i++)
|
|
135
|
-
{
|
|
136
|
-
if (s_waits[i].state == APP_WAIT_FREE)
|
|
137
|
-
{
|
|
138
|
-
s_waits[i].remaining_ms = ms;
|
|
139
|
-
s_waits[i].owner = owner;
|
|
140
|
-
s_waits[i].done = done;
|
|
141
|
-
s_waits[i].parts = (uint8_t)parts;
|
|
142
|
-
s_waits[i].state = APP_WAIT_PENDING;
|
|
143
|
-
return i;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/* The table is full: the run cannot wait, so it ends now, as not finished. A run that completion starts
|
|
148
|
-
while the table is still full is dropped instead of recursing. */
|
|
149
|
-
APP_LIMIT("wait table full, raise ER_AOT_MAX_WAITS");
|
|
150
|
-
static bool s_reporting_full;
|
|
151
|
-
if (!s_reporting_full)
|
|
152
|
-
{
|
|
153
|
-
s_reporting_full = true;
|
|
154
|
-
done(false, NULL);
|
|
155
|
-
s_reporting_full = false;
|
|
156
|
-
}
|
|
157
|
-
return -1;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/* Counts down every wait, then completes the ones that ran out. A joined run that runs out first holds until
|
|
161
|
-
its animations finish. A wait a completion starts here waits its full time. */
|
|
162
|
-
static void app_wait_tick(int dt_ms)
|
|
163
|
-
{
|
|
164
|
-
for (int i = 0; i < ER_AOT_MAX_WAITS; i++)
|
|
165
|
-
{
|
|
166
|
-
if (s_waits[i].state == APP_WAIT_PENDING && s_waits[i].remaining_ms > 0)
|
|
167
|
-
{
|
|
168
|
-
s_waits[i].remaining_ms -= dt_ms;
|
|
169
|
-
}
|
|
170
|
-
if (s_waits[i].state == APP_WAIT_PENDING && s_waits[i].remaining_ms <= 0 && s_waits[i].parts == 0)
|
|
171
|
-
{
|
|
172
|
-
s_waits[i].state = APP_WAIT_DUE;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
for (int i = 0; i < ER_AOT_MAX_WAITS; i++)
|
|
176
|
-
{
|
|
177
|
-
if (s_waits[i].state == APP_WAIT_DUE)
|
|
178
|
-
{
|
|
179
|
-
s_waits[i].state = APP_WAIT_FREE;
|
|
180
|
-
s_waits[i].done(true, NULL);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}`,
|
|
184
|
-
];
|
|
185
|
-
if (callers.includes('app_wait_start(')) {
|
|
186
|
-
blocks.push(`/* Starts the wait between a run's last animation and its completion. */
|
|
187
|
-
static void app_wait_start(int owner, int ms, ERAnimCompleteFn done)
|
|
188
|
-
{
|
|
189
|
-
(void)app_wait_claim(owner, ms, 0, done);
|
|
190
|
-
}`);
|
|
191
|
-
}
|
|
192
|
-
if (callers.includes('app_wait_join(')) {
|
|
193
|
-
blocks.push(`/* Starts a run that waits for its animations as well as its delay: it completes as finished once ms have passed
|
|
194
|
-
and all of its parts (animations) have finished, and as not finished as soon as one is interrupted. Each
|
|
195
|
-
animation runs app_wait_part when it ends, with what this returns as its user_data (NULL: the table was full,
|
|
196
|
-
so the run has already ended). */
|
|
197
|
-
static void* app_wait_join(int owner, int ms, int parts, ERAnimCompleteFn done)
|
|
198
|
-
{
|
|
199
|
-
const int i = app_wait_claim(owner, ms, parts, done);
|
|
200
|
-
return i < 0 ? NULL : (void*)(intptr_t)(i + 1);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/* An animation of a joined run has ended. */
|
|
204
|
-
static void app_wait_part(bool finished, void* user_data)
|
|
205
|
-
{
|
|
206
|
-
if (!user_data)
|
|
207
|
-
{
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
ErAnimWait* wait = &s_waits[(intptr_t)user_data - 1];
|
|
212
|
-
wait->parts--;
|
|
213
|
-
if (wait->state == APP_WAIT_DRAINING)
|
|
214
|
-
{
|
|
215
|
-
if (wait->parts == 0)
|
|
216
|
-
{
|
|
217
|
-
wait->state = APP_WAIT_FREE;
|
|
218
|
-
}
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/* A stop in progress reports the run itself (see app_wait_report). */
|
|
223
|
-
if (wait->state != APP_WAIT_PENDING)
|
|
224
|
-
{
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
if (!finished)
|
|
228
|
-
{
|
|
229
|
-
wait->state = wait->parts ? APP_WAIT_DRAINING : APP_WAIT_FREE;
|
|
230
|
-
wait->done(false, NULL);
|
|
231
|
-
}
|
|
232
|
-
else if (wait->parts == 0 && wait->remaining_ms <= 0)
|
|
233
|
-
{
|
|
234
|
-
wait->state = APP_WAIT_FREE;
|
|
235
|
-
wait->done(true, NULL);
|
|
236
|
-
}
|
|
237
|
-
}`);
|
|
238
|
-
}
|
|
239
|
-
if (callers.includes('app_wait_detach(')) {
|
|
240
|
-
blocks.push(`/* A stop's two halves: detach the composition's waits, then report them as not finished. Anything a
|
|
241
|
-
completion in between starts is a new run, which the stop leaves alone. */
|
|
242
|
-
static void app_wait_detach(int owner)
|
|
243
|
-
{
|
|
244
|
-
for (int i = 0; i < ER_AOT_MAX_WAITS; i++)
|
|
245
|
-
{
|
|
246
|
-
if (s_waits[i].owner == owner &&
|
|
247
|
-
(s_waits[i].state == APP_WAIT_PENDING || s_waits[i].state == APP_WAIT_DUE))
|
|
248
|
-
{
|
|
249
|
-
s_waits[i].state = APP_WAIT_STOPPING;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
static void app_wait_report(int owner)
|
|
255
|
-
{
|
|
256
|
-
for (int i = 0; i < ER_AOT_MAX_WAITS; i++)
|
|
257
|
-
{
|
|
258
|
-
if (s_waits[i].owner == owner && s_waits[i].state == APP_WAIT_STOPPING)
|
|
259
|
-
{
|
|
260
|
-
s_waits[i].state = s_waits[i].parts ? APP_WAIT_DRAINING : APP_WAIT_FREE;
|
|
261
|
-
s_waits[i].done(false, NULL);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}`);
|
|
265
|
-
}
|
|
266
|
-
return blocks.join('\n\n');
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* The name of a chain's callback that starts step `index` (step 0's starts a repeat).
|
|
270
|
-
*
|
|
271
|
-
* @param chain The chain.
|
|
272
|
-
* @param index The step.
|
|
273
|
-
*
|
|
274
|
-
* @returns The C function's name.
|
|
275
|
-
*/
|
|
276
|
-
const chainCallback = (chain, index) => `er_seqcb_${chain.id}_${index}`;
|
|
277
|
-
/** The slot that counts a counted loop's passes. */
|
|
278
|
-
const passCounter = (chain) => `s_loop${chain.id}_n`;
|
|
279
|
-
/** The slot that keeps where a looped value started. */
|
|
280
|
-
const startValue = (chain) => `s_loop${chain.id}_from`;
|
|
281
|
-
/**
|
|
282
|
-
* The callback the step after `index` is started from, or what runs after the last step: the repeat for a
|
|
283
|
-
* loop, else the completion.
|
|
284
|
-
*
|
|
285
|
-
* @param chain The chain.
|
|
286
|
-
* @param index The step.
|
|
287
|
-
*
|
|
288
|
-
* @returns The C function's name, or null for nothing.
|
|
289
|
-
*/
|
|
290
|
-
function afterStep(chain, index) {
|
|
291
|
-
if (index < chain.steps.length - 1) {
|
|
292
|
-
return chainCallback(chain, index + 1);
|
|
293
|
-
}
|
|
294
|
-
if (chain.loop) {
|
|
295
|
-
return chainCallback(chain, 0);
|
|
296
|
-
}
|
|
297
|
-
return chain.completionWait?.callback ?? chain.completion?.name ?? null;
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* Calls the completion with `finished`, from inside a chain callback.
|
|
301
|
-
*
|
|
302
|
-
* @param completion The completion, or null.
|
|
303
|
-
* @param finished The C value passed as `finished`.
|
|
304
|
-
*
|
|
305
|
-
* @returns The C line, or none.
|
|
306
|
-
*/
|
|
307
|
-
const callCompletion = (completion, finished) => completion ? [` ${completion.name}(${finished}, NULL);`] : [];
|
|
308
|
-
/**
|
|
309
|
-
* Ends a chain or composition when the animation before was interrupted, calling the completion as not finished.
|
|
310
|
-
*
|
|
311
|
-
* @param completion The completion, or null.
|
|
312
|
-
*
|
|
313
|
-
* @returns The C lines.
|
|
314
|
-
*/
|
|
315
|
-
const endIfInterrupted = (completion) => [
|
|
316
|
-
' if (!finished)',
|
|
317
|
-
' {',
|
|
318
|
-
...callCompletion(completion, 'false'),
|
|
319
|
-
' return;',
|
|
320
|
-
' }',
|
|
321
|
-
];
|
|
322
|
-
/**
|
|
323
|
-
* The on_complete callback that starts a completion's wait once the last animation has finished.
|
|
324
|
-
*
|
|
325
|
-
* @param completion The completion.
|
|
326
|
-
* @param wait The wait.
|
|
327
|
-
*
|
|
328
|
-
* @returns The C function.
|
|
329
|
-
*/
|
|
330
|
-
export const printCompletionWait = (completion, wait) => ({
|
|
331
|
-
name: wait.callback,
|
|
332
|
-
body: [
|
|
333
|
-
...endIfInterrupted(completion),
|
|
334
|
-
printWaitStart(wait.owner, wait.delayMs, completion),
|
|
335
|
-
],
|
|
336
|
-
});
|
|
337
|
-
/**
|
|
338
|
-
* A chain's file-scope callbacks and loop slots. Each callback first ends the chain if the step before it was
|
|
339
|
-
* interrupted, as JS does.
|
|
340
|
-
*
|
|
341
|
-
* @param chain The chain.
|
|
342
|
-
*
|
|
343
|
-
* @returns The callbacks and declarations.
|
|
344
|
-
*/
|
|
345
|
-
export function printChainFunctions(chain) {
|
|
346
|
-
const interrupted = endIfInterrupted(chain.completion);
|
|
347
|
-
// The wait after the last step comes first, then steps n..1, each started from the callback of the step before.
|
|
348
|
-
const callbacks = [];
|
|
349
|
-
if (chain.completion && chain.completionWait) {
|
|
350
|
-
callbacks.push(printCompletionWait(chain.completion, chain.completionWait));
|
|
351
|
-
}
|
|
352
|
-
for (let index = chain.steps.length - 1; index >= 1; index--) {
|
|
353
|
-
callbacks.push({
|
|
354
|
-
name: chainCallback(chain, index),
|
|
355
|
-
body: [
|
|
356
|
-
...interrupted,
|
|
357
|
-
...printAnimation(chain.steps[index], `cfg${chain.id}_${index}`, afterStep(chain, index)),
|
|
358
|
-
],
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
const decls = [];
|
|
362
|
-
const loop = chain.loop;
|
|
363
|
-
if (!loop) {
|
|
364
|
-
return { callbacks, decls };
|
|
365
|
-
}
|
|
366
|
-
// The repeat runs when the last step finishes: it counts the pass, resets the value, and starts step 0 again.
|
|
367
|
-
const repeat = [...interrupted];
|
|
368
|
-
if (loop.iterations >= 0) {
|
|
369
|
-
const counter = passCounter(chain);
|
|
370
|
-
decls.push(`static int ${counter};`);
|
|
371
|
-
const finish = loop.finalWait && chain.completion
|
|
372
|
-
? [
|
|
373
|
-
' ' +
|
|
374
|
-
printWaitStart(loop.finalWait.owner, loop.finalWait.delayMs, chain.completion),
|
|
375
|
-
]
|
|
376
|
-
: callCompletion(chain.completion, 'true');
|
|
377
|
-
repeat.push(` if (${counter} >= ${loop.iterations})`, ' {', ...finish, ' return;', ' }', ` ${counter}++;`);
|
|
378
|
-
}
|
|
379
|
-
if (loop.resetHandle) {
|
|
380
|
-
decls.push(`static float ${startValue(chain)};`);
|
|
381
|
-
repeat.push(` er_anim_value_set(${loop.resetHandle}, ${startValue(chain)});`);
|
|
382
|
-
}
|
|
383
|
-
repeat.push(...printAnimation(loop.restart, `cfg${chain.id}_0`, afterStep(chain, 0)));
|
|
384
|
-
callbacks.push({ name: chainCallback(chain, 0), body: repeat });
|
|
385
|
-
return { callbacks, decls };
|
|
386
|
-
}
|
|
387
|
-
/**
|
|
388
|
-
* The C that starts an animation where `.start()` was called. A chain's callbacks and slots are file-scope
|
|
389
|
-
* (see printChainFunctions).
|
|
390
|
-
*
|
|
391
|
-
* @param start The start.
|
|
392
|
-
*
|
|
393
|
-
* @returns The C lines, which carry their own indent.
|
|
394
|
-
*/
|
|
395
|
-
export function printAnimationStart(start) {
|
|
396
|
-
switch (start.kind) {
|
|
397
|
-
case 'startAnimations': {
|
|
398
|
-
// A completion nothing can run (an endless loop of delays) is still referenced, so -Werror builds pass.
|
|
399
|
-
if (!start.animations.length) {
|
|
400
|
-
return start.completion ? [` (void)${start.completion.name};`] : [];
|
|
401
|
-
}
|
|
402
|
-
// A joined run takes its wait first, and every animation reports to it.
|
|
403
|
-
const join = start.completionJoin;
|
|
404
|
-
if (join && start.completion) {
|
|
405
|
-
return [
|
|
406
|
-
' {',
|
|
407
|
-
` void* join = app_wait_join(${join.owner}, ${join.delayMs}, ${start.animations.length}, ${start.completion.name});`,
|
|
408
|
-
...start.animations.flatMap((animation, index) => printAnimation(animation, `cfg${start.firstConfig + index}`, 'app_wait_part', 'join').map(line => ` ${line}`)),
|
|
409
|
-
' }',
|
|
410
|
-
];
|
|
411
|
-
}
|
|
412
|
-
// The completion (or its wait) goes on the last animation, the only one when there is a completion.
|
|
413
|
-
const last = start.animations.length - 1;
|
|
414
|
-
const onComplete = start.completionWait?.callback ?? start.completion?.name ?? null;
|
|
415
|
-
return start.animations.flatMap((animation, index) => printAnimation(animation, `cfg${start.firstConfig + index}`, index === last ? onComplete : null));
|
|
416
|
-
}
|
|
417
|
-
case 'completeAfter':
|
|
418
|
-
return start.owner !== null
|
|
419
|
-
? [printWaitStart(start.owner, start.delayMs, start.completion)]
|
|
420
|
-
: [printCompletionCall(start.completion)];
|
|
421
|
-
case 'startChain': {
|
|
422
|
-
// A loop first records the pass and where the value starts, then step 0 starts inline.
|
|
423
|
-
const lines = [];
|
|
424
|
-
if (start.loop && start.loop.iterations >= 0) {
|
|
425
|
-
lines.push(` ${passCounter(start)} = 1;`);
|
|
426
|
-
}
|
|
427
|
-
if (start.loop?.resetHandle) {
|
|
428
|
-
lines.push(` ${startValue(start)} = er_anim_value_get(${start.loop.resetHandle});`);
|
|
429
|
-
}
|
|
430
|
-
return [
|
|
431
|
-
...lines,
|
|
432
|
-
...printAnimation(start.steps[0], `cfg${start.id}_0`, afterStep(start, 0)),
|
|
433
|
-
];
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
}
|
package/aot/compiler/c/boot.mjs
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
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
|
-
- Imports
|
|
18
|
-
---------------------------------------------------------------------------------------------------------------------*/
|
|
19
|
-
import { cstr } from '../c-syntax.mjs';
|
|
20
|
-
import { doubleLit, printExpr, printInDoubles } from './expressions.mjs';
|
|
21
|
-
/*----------------------------------------------------------------------------------------------------------------------
|
|
22
|
-
- Constants
|
|
23
|
-
---------------------------------------------------------------------------------------------------------------------*/
|
|
24
|
-
/**
|
|
25
|
-
* How far a fraction a guard reads may stray from the build's, relative to its size. Boot works in doubles as JS
|
|
26
|
-
* does, so only a libm function's last digit can differ; any other panel's value is far outside this.
|
|
27
|
-
*/
|
|
28
|
-
const FLOAT_TOLERANCE = 1e-9;
|
|
29
|
-
/*----------------------------------------------------------------------------------------------------------------------
|
|
30
|
-
- Implementation
|
|
31
|
-
---------------------------------------------------------------------------------------------------------------------*/
|
|
32
|
-
/**
|
|
33
|
-
* Whether an app works anything out at boot or assumes anything of its panel, so it has an app_boot().
|
|
34
|
-
*
|
|
35
|
-
* @param boot The app's boot values.
|
|
36
|
-
*
|
|
37
|
-
* @returns True when it does.
|
|
38
|
-
*/
|
|
39
|
-
export const hasBoot = (boot) => boot.slots.length > 0 || boot.assumptions.length > 0;
|
|
40
|
-
/**
|
|
41
|
-
* A slot's C declaration in the ErAppBoot struct. A fraction is a double, as JS holds it.
|
|
42
|
-
*
|
|
43
|
-
* @param slot The slot.
|
|
44
|
-
*
|
|
45
|
-
* @returns The C line.
|
|
46
|
-
*/
|
|
47
|
-
function printSlotDecl(slot) {
|
|
48
|
-
const cType = slot.type.kind === 'float'
|
|
49
|
-
? 'double'
|
|
50
|
-
: slot.type.kind === 'string'
|
|
51
|
-
? 'const char*'
|
|
52
|
-
: 'int';
|
|
53
|
-
return ` ${cType} ${slot.field};`;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* The file-scope struct of the values er_app_build() works out at boot.
|
|
57
|
-
*
|
|
58
|
-
* @param boot The app's boot values.
|
|
59
|
-
*
|
|
60
|
-
* @returns The C, or '' when there are none.
|
|
61
|
-
*/
|
|
62
|
-
export const printBootDecls = (boot) => boot.slots.length
|
|
63
|
-
? `/* The values that depend on the panel size, worked out once by er_app_build(). */\n` +
|
|
64
|
-
`typedef struct\n{\n${boot.slots.map(printSlotDecl).join('\n')}\n} ErAppBoot;\n\n` +
|
|
65
|
-
`static ErAppBoot s_boot;\n`
|
|
66
|
-
: '';
|
|
67
|
-
/**
|
|
68
|
-
* The C test that a panel meets one assumption.
|
|
69
|
-
*
|
|
70
|
-
* @param assumption The assumption.
|
|
71
|
-
* @param screen The panel the build was compiled for.
|
|
72
|
-
*
|
|
73
|
-
* @returns The C condition.
|
|
74
|
-
*/
|
|
75
|
-
function printAssumption(assumption, screen) {
|
|
76
|
-
if (assumption.kind === 'panel') {
|
|
77
|
-
return `(screen_w == ${screen.width} && screen_h == ${screen.height})`;
|
|
78
|
-
}
|
|
79
|
-
const read = `s_boot.${assumption.slot.field}`;
|
|
80
|
-
const { value } = assumption;
|
|
81
|
-
if (typeof value === 'string')
|
|
82
|
-
return `(strcmp(${read}, ${cstr(value)}) == 0)`;
|
|
83
|
-
if (typeof value === 'boolean')
|
|
84
|
-
return value ? read : `!${read}`;
|
|
85
|
-
if (assumption.slot.type.kind !== 'float') {
|
|
86
|
-
return `(${read} == ${value})`;
|
|
87
|
-
}
|
|
88
|
-
// A fraction within a small margin: boot and the compiler need not round its last digit alike.
|
|
89
|
-
const margin = doubleLit(FLOAT_TOLERANCE * (1 + Math.abs(value)));
|
|
90
|
-
const expected = doubleLit(value);
|
|
91
|
-
return `(${read} - ${expected} <= ${margin} && ${expected} - ${read} <= ${margin})`;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* app_boot(): sets each boot value from the panel size, then reports whether the panel meets everything the
|
|
95
|
-
* build assumed of it.
|
|
96
|
-
*
|
|
97
|
-
* @param boot The app's boot values.
|
|
98
|
-
* @param screen The panel the build was compiled for.
|
|
99
|
-
*
|
|
100
|
-
* @returns The C function, or '' when the app has no boot values.
|
|
101
|
-
*/
|
|
102
|
-
export function printBootFunction(boot, screen) {
|
|
103
|
-
if (!hasBoot(boot))
|
|
104
|
-
return '';
|
|
105
|
-
const lines = boot.slots.map(({ field, init }) => {
|
|
106
|
-
const value = init.kind === 'expr'
|
|
107
|
-
? printInDoubles(() => printExpr(init.expr))
|
|
108
|
-
: init.dimension === 'width'
|
|
109
|
-
? 'screen_w'
|
|
110
|
-
: 'screen_h';
|
|
111
|
-
return ` s_boot.${field} = ${value};`;
|
|
112
|
-
});
|
|
113
|
-
const body = lines.join('\n');
|
|
114
|
-
const reads = (name) => new RegExp(`\\b${name}\\b`).test(body);
|
|
115
|
-
const guards = boot.assumptions.map(assumption => printAssumption(assumption, screen));
|
|
116
|
-
const unused = ['screen_w', 'screen_h']
|
|
117
|
-
.filter(name => !reads(name) && !guards.some(guard => guard.includes(name)))
|
|
118
|
-
.map(name => ` (void)${name};`);
|
|
119
|
-
const verdict = guards.length
|
|
120
|
-
? ` return ${guards.join('\n && ')};`
|
|
121
|
-
: ' return true;';
|
|
122
|
-
return ('/* Works out the values that depend on the panel size, and whether this panel takes the layout the app\n' +
|
|
123
|
-
' was compiled for: what the compiler folded at its panel has to come out the same here. */\n' +
|
|
124
|
-
'static bool app_boot(int screen_w, int screen_h)\n{\n' +
|
|
125
|
-
[...unused, ...lines, verdict].join('\n') +
|
|
126
|
-
'\n}');
|
|
127
|
-
}
|