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
|
@@ -0,0 +1,286 @@
|
|
|
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
|
+
* Builds one function's bytecode: typed registers, instructions in the forms erb_format.h gives each opcode,
|
|
18
|
+
* and forward branches to labels placed later.
|
|
19
|
+
*/
|
|
20
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
21
|
+
- Imports
|
|
22
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
23
|
+
import { aotError } from '../diagnostics.mjs';
|
|
24
|
+
import { OPCODES, ValueType } from './format.mjs';
|
|
25
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
26
|
+
- Constants
|
|
27
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
28
|
+
/** Each opcode by name, with its number and length. */
|
|
29
|
+
export const OP = Object.fromEntries(OPCODES.map(([name, , words], index) => [name, { code: index + 1, words }]));
|
|
30
|
+
/** Register cells a function may have: the function record counts them in a byte. */
|
|
31
|
+
const MAX_REGISTERS = 255;
|
|
32
|
+
/** The longest branch forward, in words: a branch keeps its offset in a signed 16 bits. */
|
|
33
|
+
const MAX_BRANCH_OFFSET = 0x7fff;
|
|
34
|
+
/** The register types that take two cells. */
|
|
35
|
+
const WIDE = new Set(['int64', 'double', 'node']);
|
|
36
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
37
|
+
- Classes
|
|
38
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
39
|
+
/**
|
|
40
|
+
* One function as it is built. Temporaries go back to a pool by type when released, so a long function
|
|
41
|
+
* doesn't run out of registers.
|
|
42
|
+
*
|
|
43
|
+
* @class FunctionBuilder
|
|
44
|
+
*/
|
|
45
|
+
export class FunctionBuilder {
|
|
46
|
+
code = [];
|
|
47
|
+
/** Each cell's type, as the types table holds it. */
|
|
48
|
+
cellTypes = [];
|
|
49
|
+
pool = new Map();
|
|
50
|
+
/** Released runs of consecutive registers, by their types, at their first cell. */
|
|
51
|
+
runs = new Map();
|
|
52
|
+
/** The types of each run, by its first cell. */
|
|
53
|
+
runTypes = new Map();
|
|
54
|
+
/** Registers in use, in the order they were taken, for checkpoints. */
|
|
55
|
+
taken = [];
|
|
56
|
+
/** Where each run of the code starts in the source, for the debug table. */
|
|
57
|
+
lines = [];
|
|
58
|
+
kind;
|
|
59
|
+
what;
|
|
60
|
+
/**
|
|
61
|
+
* @param kind The function's kind (a FunctionKind or an EREventType).
|
|
62
|
+
* @param what What the function is, for an error.
|
|
63
|
+
*/
|
|
64
|
+
constructor(kind, what) {
|
|
65
|
+
this.kind = kind;
|
|
66
|
+
this.what = what;
|
|
67
|
+
}
|
|
68
|
+
/** The next instruction's word index. */
|
|
69
|
+
get position() {
|
|
70
|
+
return this.code.length;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Marks the code from here on as lowered from a place in the source.
|
|
74
|
+
*
|
|
75
|
+
* @param location The place, if it has one.
|
|
76
|
+
*/
|
|
77
|
+
at(location) {
|
|
78
|
+
if (!location) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
// A mark nothing was written after is replaced.
|
|
82
|
+
if (this.lines.at(-1)?.offset === this.position) {
|
|
83
|
+
this.lines.pop();
|
|
84
|
+
}
|
|
85
|
+
const last = this.lines.at(-1);
|
|
86
|
+
if (last?.line !== location.line || last.column !== location.column) {
|
|
87
|
+
this.lines.push({
|
|
88
|
+
offset: this.position,
|
|
89
|
+
line: location.line,
|
|
90
|
+
column: location.column,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* A register of a type: a released one when there is one, else a new one.
|
|
96
|
+
*
|
|
97
|
+
* @param type Its type.
|
|
98
|
+
*
|
|
99
|
+
* @returns The register.
|
|
100
|
+
*/
|
|
101
|
+
register(type) {
|
|
102
|
+
const reused = this.pool.get(type)?.pop();
|
|
103
|
+
const register = { index: reused ?? this.newRegister(type), type };
|
|
104
|
+
this.taken.push(register);
|
|
105
|
+
return register;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* A register of a type that is never released, for the rest of the function. Registers start at zero, so
|
|
109
|
+
* one nothing writes keeps that value.
|
|
110
|
+
*
|
|
111
|
+
* @param type Its type.
|
|
112
|
+
*
|
|
113
|
+
* @returns The register.
|
|
114
|
+
*/
|
|
115
|
+
reserved(type) {
|
|
116
|
+
return { index: this.newRegister(type), type };
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Registers of one-cell types in consecutive cells, as APPEND reads a row: a released run of the same types when
|
|
120
|
+
* there is one, else new ones. A run is released whole, and only ever reused as a run.
|
|
121
|
+
*
|
|
122
|
+
* @param types Their types.
|
|
123
|
+
*
|
|
124
|
+
* @returns The registers.
|
|
125
|
+
*/
|
|
126
|
+
consecutive(types) {
|
|
127
|
+
const key = types.join(' ');
|
|
128
|
+
let first = this.runs.get(key)?.pop();
|
|
129
|
+
if (first === undefined) {
|
|
130
|
+
first = this.cellTypes.length;
|
|
131
|
+
types.forEach(type => this.newRegister(type));
|
|
132
|
+
this.runTypes.set(first, key);
|
|
133
|
+
}
|
|
134
|
+
const registers = types.map((type, index) => ({
|
|
135
|
+
index: first + index,
|
|
136
|
+
type,
|
|
137
|
+
}));
|
|
138
|
+
this.taken.push(registers[0]);
|
|
139
|
+
return registers;
|
|
140
|
+
}
|
|
141
|
+
newRegister(type) {
|
|
142
|
+
// A two-cell register starts on an even cell.
|
|
143
|
+
if (WIDE.has(type) && this.cellTypes.length % 2) {
|
|
144
|
+
this.cellTypes.push(ValueType.int);
|
|
145
|
+
}
|
|
146
|
+
const index = this.cellTypes.length;
|
|
147
|
+
this.cellTypes.push(ValueType[type]);
|
|
148
|
+
if (WIDE.has(type)) {
|
|
149
|
+
this.cellTypes.push(ValueType.pair);
|
|
150
|
+
}
|
|
151
|
+
if (this.cellTypes.length > MAX_REGISTERS) {
|
|
152
|
+
throw aotError(`AOT: ${this.what} needs more than ${MAX_REGISTERS} registers in a package`, 'split it into smaller pieces.');
|
|
153
|
+
}
|
|
154
|
+
return index;
|
|
155
|
+
}
|
|
156
|
+
/** Where the registers taken so far end, for release. */
|
|
157
|
+
checkpoint() {
|
|
158
|
+
return this.taken.length;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Releases every register taken since a checkpoint, except those kept.
|
|
162
|
+
*
|
|
163
|
+
* @param checkpoint The checkpoint.
|
|
164
|
+
* @param keep Registers still in use.
|
|
165
|
+
*/
|
|
166
|
+
release(checkpoint, ...keep) {
|
|
167
|
+
const kept = this.taken.splice(checkpoint).filter(register => {
|
|
168
|
+
if (keep.includes(register)) {
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
const run = this.runTypes.get(register.index);
|
|
172
|
+
if (run !== undefined) {
|
|
173
|
+
this.runs.set(run, [...(this.runs.get(run) ?? []), register.index]);
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
const free = this.pool.get(register.type) ?? [];
|
|
177
|
+
free.push(register.index);
|
|
178
|
+
this.pool.set(register.type, free);
|
|
179
|
+
return false;
|
|
180
|
+
});
|
|
181
|
+
this.taken.push(...kept);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* An instruction with A, B and C.
|
|
185
|
+
*
|
|
186
|
+
* @param name The opcode.
|
|
187
|
+
* @param operandA A.
|
|
188
|
+
* @param operandB B.
|
|
189
|
+
* @param operandC C.
|
|
190
|
+
* @param extension The extension word, for an opcode that has one.
|
|
191
|
+
*/
|
|
192
|
+
abc(name, operandA = 0, operandB = 0, operandC = 0, extension) {
|
|
193
|
+
this.emit(name, (operandA & 0xff) | ((operandB & 0xff) << 8) | ((operandC & 0xff) << 16), extension);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* An instruction with A and a 16-bit Bx.
|
|
197
|
+
*
|
|
198
|
+
* @param name The opcode.
|
|
199
|
+
* @param operandA A.
|
|
200
|
+
* @param operandBx Bx, an index or a signed immediate.
|
|
201
|
+
* @param extension The extension word, for an opcode that has one.
|
|
202
|
+
*/
|
|
203
|
+
abx(name, operandA, operandBx, extension) {
|
|
204
|
+
this.emit(name, (operandA & 0xff) | ((operandBx & 0xffff) << 8), extension);
|
|
205
|
+
}
|
|
206
|
+
emit(name, operands, extension) {
|
|
207
|
+
const opcode = OP[name];
|
|
208
|
+
this.code.push((opcode.code | (operands << 8)) >>> 0);
|
|
209
|
+
if (opcode.words === 2) {
|
|
210
|
+
this.code.push((extension ?? 0) >>> 0);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/** A label to branch to, placed later. */
|
|
214
|
+
label() {
|
|
215
|
+
return { at: null, branches: [] };
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Places a label here, and points the branches to it here.
|
|
219
|
+
*
|
|
220
|
+
* @param label The label.
|
|
221
|
+
*/
|
|
222
|
+
place(label) {
|
|
223
|
+
label.at = this.position;
|
|
224
|
+
for (const at of label.branches) {
|
|
225
|
+
const offset = label.at - (at + wordsOf(this.code[at]));
|
|
226
|
+
if (offset > MAX_BRANCH_OFFSET) {
|
|
227
|
+
throw aotError(`AOT: ${this.what} has a branch too long for a package`, 'split it into smaller pieces.');
|
|
228
|
+
}
|
|
229
|
+
this.code[at] = ((this.code[at] & 0xffff) | (offset << 16)) >>> 0;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* A forward branch to a label: JMP, or JT / JF on a bool register.
|
|
234
|
+
*
|
|
235
|
+
* @param name JMP, JT or JF.
|
|
236
|
+
* @param label Where it goes.
|
|
237
|
+
* @param test The bool register JT and JF test.
|
|
238
|
+
*/
|
|
239
|
+
branch(name, label, test) {
|
|
240
|
+
label.branches.push(this.position);
|
|
241
|
+
this.abx(name, test?.index ?? 0, 0);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* A branch to a label when any of a dirty word's bits is set in this update pass.
|
|
245
|
+
*
|
|
246
|
+
* @param word The dirty word.
|
|
247
|
+
* @param mask Its bits.
|
|
248
|
+
* @param label Where it goes.
|
|
249
|
+
*/
|
|
250
|
+
branchIfDirty(word, mask, label) {
|
|
251
|
+
label.branches.push(this.position);
|
|
252
|
+
this.abx('JDIRTY', word, 0, mask);
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* The finished function, ending in RET.
|
|
256
|
+
*
|
|
257
|
+
* @param parameters Parameter cells.
|
|
258
|
+
* @param result What it returns, for a function that returns a value.
|
|
259
|
+
*
|
|
260
|
+
* @returns The function.
|
|
261
|
+
*/
|
|
262
|
+
finish(parameters = 0, result) {
|
|
263
|
+
this.abc('RET', result?.index ?? 0);
|
|
264
|
+
return {
|
|
265
|
+
kind: this.kind,
|
|
266
|
+
parameters,
|
|
267
|
+
result: result ? ValueType[result.type] : 0,
|
|
268
|
+
types: [...this.cellTypes],
|
|
269
|
+
code: [...this.code],
|
|
270
|
+
debug: { name: this.what, lines: [...this.lines] },
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
275
|
+
- Implementation
|
|
276
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
277
|
+
/**
|
|
278
|
+
* An instruction's length, from its first word.
|
|
279
|
+
*
|
|
280
|
+
* @param word The word.
|
|
281
|
+
*
|
|
282
|
+
* @returns Its length in words.
|
|
283
|
+
*/
|
|
284
|
+
function wordsOf(word) {
|
|
285
|
+
return OPCODES[(word & 0xff) - 1][2];
|
|
286
|
+
}
|