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,319 +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 { cScalarType, cstr } from '../c-syntax.mjs';
|
|
20
|
-
import { printAnimationStart } from './animations.mjs';
|
|
21
|
-
import { printUpdateVector } from './vectors.mjs';
|
|
22
|
-
import { printCondition, printExpr } from './expressions.mjs';
|
|
23
|
-
import { formatArgs, printText } from './text.mjs';
|
|
24
|
-
import { slotOf } from '../ir/types.mjs';
|
|
25
|
-
/*----------------------------------------------------------------------------------------------------------------------
|
|
26
|
-
- Constants
|
|
27
|
-
---------------------------------------------------------------------------------------------------------------------*/
|
|
28
|
-
/** One level of indentation. */
|
|
29
|
-
const INDENT = ' ';
|
|
30
|
-
/** The line that re-applies state-dependent props after a body set state. */
|
|
31
|
-
export const APP_UPDATE_CALL = ' app_update();';
|
|
32
|
-
/** The indent list operations print at, whatever block they sit in. */
|
|
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
|
-
`;
|
|
50
|
-
/*----------------------------------------------------------------------------------------------------------------------
|
|
51
|
-
- Implementation
|
|
52
|
-
---------------------------------------------------------------------------------------------------------------------*/
|
|
53
|
-
/**
|
|
54
|
-
* Matches `<member>` as a whole C lvalue, so `s_state.label` does not also match `s_state.label2`.
|
|
55
|
-
*
|
|
56
|
-
* @param member A C lvalue.
|
|
57
|
-
*
|
|
58
|
-
* @returns A pattern that finds it in the C source.
|
|
59
|
-
*/
|
|
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;`] : [];
|
|
71
|
-
/**
|
|
72
|
-
* A timer as the C call that starts it and evaluates to its id. A timestamp or float delay goes through
|
|
73
|
-
* ToInt32 and a floor at 0, as Flow A's setTimeout does.
|
|
74
|
-
*
|
|
75
|
-
* @param timer The timer.
|
|
76
|
-
*
|
|
77
|
-
* @returns The C call.
|
|
78
|
-
*/
|
|
79
|
-
function printTimerAdd(timer) {
|
|
80
|
-
const delay = timer.delay;
|
|
81
|
-
const delayMs = !delay
|
|
82
|
-
? '0'
|
|
83
|
-
: delay.type.kind === 'int64'
|
|
84
|
-
? `app_delay_ms64(${printExpr(delay)})`
|
|
85
|
-
: delay.type.kind === 'float'
|
|
86
|
-
? `app_delay_msf(${printExpr(delay)})`
|
|
87
|
-
: printExpr(delay);
|
|
88
|
-
return `er_timer_add((int)(${delayMs}), ${timer.isRepeating ? 'true' : 'false'}, ${timer.fn})`;
|
|
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`;
|
|
122
|
-
/**
|
|
123
|
-
* A string state write. snprintf's source and destination may not overlap, so a value that reads the slot
|
|
124
|
-
* itself (`setLabel(label + '!')`) is built in a temporary first.
|
|
125
|
-
*
|
|
126
|
-
* @param stmt The write.
|
|
127
|
-
* @param indent The statement's indentation.
|
|
128
|
-
*
|
|
129
|
-
* @returns The C lines.
|
|
130
|
-
*/
|
|
131
|
-
function printSetStateText(stmt, indent) {
|
|
132
|
-
const member = stmt.state.cMember;
|
|
133
|
-
const format = printText(stmt.text);
|
|
134
|
-
const report = cutShort(`state '${stmt.state.name}'`);
|
|
135
|
-
if (format.args.some(formatArg => readsMember(member).test(formatArg))) {
|
|
136
|
-
return [
|
|
137
|
-
`${indent}{`,
|
|
138
|
-
`${indent} char next[sizeof(${member})];`,
|
|
139
|
-
...printStringWrite('next', formatArgs(format), false, report, indent + INDENT),
|
|
140
|
-
`${indent} memcpy(${member}, next, strlen(next) + 1);`,
|
|
141
|
-
`${indent}}`,
|
|
142
|
-
];
|
|
143
|
-
}
|
|
144
|
-
return printStringWrite(member, formatArgs(format), !format.args.length, report, indent);
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* An appended list item: fill the next free slot's fields and count it, or report a full list.
|
|
148
|
-
*
|
|
149
|
-
* @param stmt The append.
|
|
150
|
-
*
|
|
151
|
-
* @returns The C lines.
|
|
152
|
-
*/
|
|
153
|
-
function printAppendItem(stmt) {
|
|
154
|
-
const { name, arrayName, countMember, cap } = stmt.list;
|
|
155
|
-
const lines = [
|
|
156
|
-
`${LIST_INDENT}if (${countMember} < ${cap})`,
|
|
157
|
-
`${LIST_INDENT}{`,
|
|
158
|
-
];
|
|
159
|
-
for (const itemValue of stmt.values) {
|
|
160
|
-
const slot = `${arrayName}[${countMember}].${itemValue.field.key}`;
|
|
161
|
-
if ('text' in itemValue) {
|
|
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));
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
lines.push(`${LIST_INDENT}${INDENT}${slot} = ${printExpr(itemValue.value)};`);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
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}}`);
|
|
170
|
-
return lines;
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Prints a statement as C lines.
|
|
174
|
-
*
|
|
175
|
-
* @param stmt The statement.
|
|
176
|
-
* @param indent Its indentation.
|
|
177
|
-
*
|
|
178
|
-
* @returns Its C lines.
|
|
179
|
-
*/
|
|
180
|
-
function printStmt(stmt, indent) {
|
|
181
|
-
switch (stmt.kind) {
|
|
182
|
-
case 'declareLocal': {
|
|
183
|
-
// A string local is a buffer of its own, so a later write to the state it copied cannot change it.
|
|
184
|
-
const init = stmt.init;
|
|
185
|
-
if (init.type.kind === 'string') {
|
|
186
|
-
const declaration = stmt.isHoisted
|
|
187
|
-
? []
|
|
188
|
-
: [`${indent}char ${stmt.name}[${stmt.stringCap}];`];
|
|
189
|
-
return [
|
|
190
|
-
...declaration,
|
|
191
|
-
...printStringWrite(stmt.name, `"%s", ${printExpr(init)}`, init.kind === 'string', cutShort(`local '${stmt.name}'`), indent),
|
|
192
|
-
];
|
|
193
|
-
}
|
|
194
|
-
const declaredType = stmt.isHoisted
|
|
195
|
-
? ''
|
|
196
|
-
: cScalarType(slotOf(init.type)) + ' ';
|
|
197
|
-
return [`${indent}${declaredType}${stmt.name} = ${printExpr(init)};`];
|
|
198
|
-
}
|
|
199
|
-
case 'startTimer': {
|
|
200
|
-
const timerAdd = printTimerAdd(stmt.timer);
|
|
201
|
-
if (!stmt.idLocal) {
|
|
202
|
-
return [`${indent}${timerAdd};`];
|
|
203
|
-
}
|
|
204
|
-
// The id is only read by a later clear*(); `(void)` keeps the compiler quiet when nothing does.
|
|
205
|
-
const { name, isHoisted } = stmt.idLocal;
|
|
206
|
-
return [
|
|
207
|
-
`${indent}${isHoisted ? '' : 'int '}${name} = ${timerAdd};`,
|
|
208
|
-
`${indent}(void)${name};`,
|
|
209
|
-
];
|
|
210
|
-
}
|
|
211
|
-
case 'clearTimer':
|
|
212
|
-
return [`${indent}er_timer_clear(${printExpr(stmt.id)});`];
|
|
213
|
-
case 'setState':
|
|
214
|
-
return [
|
|
215
|
-
`${indent}${stmt.state.cMember} = ${printExpr(stmt.value)};`,
|
|
216
|
-
...printChangedFlag(stmt.state, indent),
|
|
217
|
-
];
|
|
218
|
-
case 'setStateText':
|
|
219
|
-
return [
|
|
220
|
-
...printSetStateText(stmt, indent),
|
|
221
|
-
...printChangedFlag(stmt.state, indent),
|
|
222
|
-
];
|
|
223
|
-
case 'clearList':
|
|
224
|
-
return [
|
|
225
|
-
`${LIST_INDENT}${stmt.list.countMember} = 0;`,
|
|
226
|
-
...printChangedFlag(stmt.list, LIST_INDENT),
|
|
227
|
-
];
|
|
228
|
-
case 'appendItem':
|
|
229
|
-
return [
|
|
230
|
-
...printAppendItem(stmt),
|
|
231
|
-
...printChangedFlag(stmt.list, LIST_INDENT),
|
|
232
|
-
];
|
|
233
|
-
case 'dropLastItem': {
|
|
234
|
-
const count = stmt.list.countMember;
|
|
235
|
-
return [
|
|
236
|
-
`${LIST_INDENT}if (${count} > 0) ${count}--;`,
|
|
237
|
-
...printChangedFlag(stmt.list, LIST_INDENT),
|
|
238
|
-
];
|
|
239
|
-
}
|
|
240
|
-
case 'keepFirstItems': {
|
|
241
|
-
const count = stmt.list.countMember;
|
|
242
|
-
return [
|
|
243
|
-
`${LIST_INDENT}${count} = (${count} < ${stmt.count}) ? ${count} : ${stmt.count};`,
|
|
244
|
-
...printChangedFlag(stmt.list, LIST_INDENT),
|
|
245
|
-
];
|
|
246
|
-
}
|
|
247
|
-
case 'sliceItems': {
|
|
248
|
-
const count = stmt.list.countMember;
|
|
249
|
-
return [
|
|
250
|
-
`${LIST_INDENT}${count} = app_slice_len(${count}, ${printExpr(stmt.end)});`,
|
|
251
|
-
...printChangedFlag(stmt.list, LIST_INDENT),
|
|
252
|
-
];
|
|
253
|
-
}
|
|
254
|
-
case 'writeRef':
|
|
255
|
-
return [`${indent}${stmt.ref.cVar} ${stmt.op} ${printExpr(stmt.value)};`];
|
|
256
|
-
case 'stepRef':
|
|
257
|
-
return [`${indent}${stmt.ref.cVar}${stmt.op};`];
|
|
258
|
-
case 'stopAnimations': {
|
|
259
|
-
const lines = stmt.handles.map(handle => `${indent}er_anim_value_set(${handle}, er_anim_value_get(${handle}));`);
|
|
260
|
-
if (stmt.waitOwner === null) {
|
|
261
|
-
return lines;
|
|
262
|
-
}
|
|
263
|
-
// Waits are detached before a frozen value's completion can start a new run, and reported after it.
|
|
264
|
-
return [
|
|
265
|
-
`${indent}app_wait_detach(${stmt.waitOwner});`,
|
|
266
|
-
...lines,
|
|
267
|
-
`${indent}app_wait_report(${stmt.waitOwner});`,
|
|
268
|
-
];
|
|
269
|
-
}
|
|
270
|
-
case 'if': {
|
|
271
|
-
// Each branch is a nested C block.
|
|
272
|
-
const lines = [
|
|
273
|
-
`${indent}if (${printCondition(stmt.test)})`,
|
|
274
|
-
`${indent}{`,
|
|
275
|
-
...printStmts(stmt.consequent, indent + INDENT),
|
|
276
|
-
`${indent}}`,
|
|
277
|
-
];
|
|
278
|
-
if (stmt.alternate) {
|
|
279
|
-
lines.push(`${indent}else`, `${indent}{`, ...printStmts(stmt.alternate, indent + INDENT), `${indent}}`);
|
|
280
|
-
}
|
|
281
|
-
return lines;
|
|
282
|
-
}
|
|
283
|
-
case 'return':
|
|
284
|
-
return [`${indent}return;`];
|
|
285
|
-
case 'armCleanup':
|
|
286
|
-
return [`${indent}${stmt.flag} = 1;`];
|
|
287
|
-
case 'startAnimations':
|
|
288
|
-
case 'startChain':
|
|
289
|
-
case 'completeAfter':
|
|
290
|
-
return printAnimationStart(stmt);
|
|
291
|
-
case 'updateVector':
|
|
292
|
-
return printUpdateVector(stmt).map(line => indent + line);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* Prints statements as C lines.
|
|
297
|
-
*
|
|
298
|
-
* @param stmts The statements.
|
|
299
|
-
* @param indent Their indentation.
|
|
300
|
-
*
|
|
301
|
-
* @returns Their C lines.
|
|
302
|
-
*/
|
|
303
|
-
export function printStmts(stmts, indent) {
|
|
304
|
-
return stmts.flatMap(stmt => printStmt(stmt, indent));
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* A callback's function body: its statements, then app_update() when it set state.
|
|
308
|
-
*
|
|
309
|
-
* @param callback The callback.
|
|
310
|
-
*
|
|
311
|
-
* @returns The C lines.
|
|
312
|
-
*/
|
|
313
|
-
export function printCallback(callback) {
|
|
314
|
-
const lines = printStmts(callback.body, INDENT);
|
|
315
|
-
if (callback.updatesState) {
|
|
316
|
-
lines.push(APP_UPDATE_CALL);
|
|
317
|
-
}
|
|
318
|
-
return lines;
|
|
319
|
-
}
|
package/aot/compiler/c/text.mjs
DELETED
|
@@ -1,83 +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 { printExpr } from './expressions.mjs';
|
|
21
|
-
/*----------------------------------------------------------------------------------------------------------------------
|
|
22
|
-
- Implementation
|
|
23
|
-
---------------------------------------------------------------------------------------------------------------------*/
|
|
24
|
-
/**
|
|
25
|
-
* A value as one printf spec and its argument. `%lld` needs a long long, and int64_t is `long` on 64-bit
|
|
26
|
-
* Linux. A float goes through app_ftoa, which prints Infinity, -Infinity, NaN, and 0 where %g prints inf,
|
|
27
|
-
* -inf, nan and -0, and anything else as %g, into a buffer the call site lends it: one per float, so two
|
|
28
|
-
* floats in one snprintf keep their own.
|
|
29
|
-
*
|
|
30
|
-
* @param value The value.
|
|
31
|
-
*
|
|
32
|
-
* @returns Its printf spec and argument.
|
|
33
|
-
*/
|
|
34
|
-
function printfPart(value) {
|
|
35
|
-
const code = printExpr(value);
|
|
36
|
-
if (value.type.kind === 'string') {
|
|
37
|
-
return { spec: '%s', code };
|
|
38
|
-
}
|
|
39
|
-
if (value.type.kind === 'float') {
|
|
40
|
-
return { spec: '%s', code: `app_ftoa((char[16]){0}, ${code})` };
|
|
41
|
-
}
|
|
42
|
-
if (value.type.kind === 'int64') {
|
|
43
|
-
return { spec: '%lld', code: `(long long)(${code})` };
|
|
44
|
-
}
|
|
45
|
-
return { spec: '%d', code };
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Prints a text as one printf format and its arguments, for a char-buffer destination.
|
|
49
|
-
*
|
|
50
|
-
* @param text The text.
|
|
51
|
-
*
|
|
52
|
-
* @returns The format, with literal `%` escaped as `%%`, and its arguments.
|
|
53
|
-
*/
|
|
54
|
-
export function printText(text) {
|
|
55
|
-
let format = '';
|
|
56
|
-
const args = [];
|
|
57
|
-
for (const part of text.parts) {
|
|
58
|
-
// Literal text joins the format; each runtime value adds a spec and its argument.
|
|
59
|
-
if (part.kind === 'literal') {
|
|
60
|
-
format += part.text.replace(/%/g, '%%');
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
const { spec, code } = part.kind === 'booleanWord'
|
|
64
|
-
? {
|
|
65
|
-
spec: '%s',
|
|
66
|
-
code: `((${printExpr(part.value)}) ? "true" : "false")`,
|
|
67
|
-
}
|
|
68
|
-
: printfPart(part.value);
|
|
69
|
-
format += spec;
|
|
70
|
-
args.push(code);
|
|
71
|
-
}
|
|
72
|
-
return { format, args };
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Renders a printed text as snprintf's trailing arguments (a constant string keeps its `%s` form).
|
|
76
|
-
*
|
|
77
|
-
* @param result The format and its arguments.
|
|
78
|
-
*
|
|
79
|
-
* @returns The arguments after the buffer and its size, as C.
|
|
80
|
-
*/
|
|
81
|
-
export const formatArgs = ({ format, args }) => args.length
|
|
82
|
-
? `${cstr(format)}, ${args.join(', ')}`
|
|
83
|
-
: `"%s", ${cstr(format.replace(/%%/g, '%'))}`;
|