embedded-react 0.19.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/README.md +7 -3
- 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 +54 -40
- 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 +11 -7
- package/assets/emit-c.mjs +77 -58
- package/assets/emit-container.mjs +123 -37
- package/assets/emit-pack.mjs +77 -67
- package/assets/font-config.mjs +9 -6
- package/assets/font-sizes.mjs +163 -123
- package/assets/glyph-coverage.mjs +74 -54
- package/assets/index.mjs +31 -9
- package/assets/rasterize.mjs +126 -99
- package/assets/svg-loader.mjs +8 -8
- package/build.mjs +14 -12
- package/cli.mjs +359 -172
- package/compile-bin.mjs +3 -3
- package/flash.mjs +537 -0
- package/hotreload/dev-device.mjs +90 -33
- package/hotreload/pack-app.mjs +55 -43
- package/hotreload/pack-split.mjs +46 -37
- package/hotreload/package-transfer.mjs +175 -0
- package/hotreload/protocol.mjs +50 -37
- package/hotreload/uploader.mjs +38 -27
- package/hotreload/watch-tree.mjs +19 -19
- package/pack-container.mjs +28 -20
- package/package.json +7 -8
- package/persist-transform.mjs +34 -28
- package/qjsc-wasm.mjs +25 -14
- package/sim/embedded-react.cjs +1 -1
- package/sim/embedded-react.js +1 -1
- package/sim/embedded-react.wasm +0 -0
- package/sim/index.html +94 -85
- package/sim-server.mjs +101 -82
- package/src/embedded-react/Animated.js +24 -24
- package/src/embedded-react/Easing.js +1 -1
- package/src/embedded-react/FlatList.js +3 -3
- package/src/embedded-react/LayoutAnimation.js +8 -5
- package/src/embedded-react/PanResponder.js +75 -71
- package/src/embedded-react/Pressable.js +2 -8
- package/src/embedded-react/SectionList.js +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
|
@@ -13,4 +13,14 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
17
|
+
- Implementation
|
|
18
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
19
|
+
/**
|
|
20
|
+
* The name of the slot that says an effect's cleanup is due.
|
|
21
|
+
*
|
|
22
|
+
* @param effectId The effect's number.
|
|
23
|
+
*
|
|
24
|
+
* @returns The slot's name.
|
|
25
|
+
*/
|
|
26
|
+
export const armedFlag = (effectId) => `effect${effectId}_armed`;
|
|
@@ -31,8 +31,8 @@ export const hasRuntimeProps = (node) => (node.text?.parts.some(part => part.kin
|
|
|
31
31
|
node.stateProps.length > 0 ||
|
|
32
32
|
node.image?.kind === 'value';
|
|
33
33
|
/**
|
|
34
|
-
* Whether state drives any of a node's props, text or image, so it keeps a handle and
|
|
35
|
-
* props again. Props that read-only values worked out at boot are set once, by
|
|
34
|
+
* Whether state drives any of a node's props, text or image, so it keeps a handle and the update sets its
|
|
35
|
+
* props again. Props that read-only values worked out at boot are set once, by the build.
|
|
36
36
|
*
|
|
37
37
|
* @param node The node.
|
|
38
38
|
*
|
|
@@ -41,7 +41,7 @@ export const hasRuntimeProps = (node) => (node.text?.parts.some(part => part.kin
|
|
|
41
41
|
export const isStateDriven = (node) => hasRuntimeProps(node) && !isBootOnlyNode(node);
|
|
42
42
|
/**
|
|
43
43
|
* The drawing state drives on a node if it has one: a drawing that reads only values worked out at boot is
|
|
44
|
-
* built once, by
|
|
44
|
+
* built once, by the build.
|
|
45
45
|
*
|
|
46
46
|
* @param node The node.
|
|
47
47
|
*
|
|
@@ -67,7 +67,7 @@ export function stateDrivenVectorOf(node) {
|
|
|
67
67
|
return null;
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
|
-
* Every node under an element, each before its children, in the order
|
|
70
|
+
* Every node under an element, each before its children, in the order the build creates them.
|
|
71
71
|
*
|
|
72
72
|
* @param element The element.
|
|
73
73
|
*
|
|
@@ -56,7 +56,7 @@ function readSource(source, found) {
|
|
|
56
56
|
found.untracked = true;
|
|
57
57
|
return;
|
|
58
58
|
case 'fixed':
|
|
59
|
-
readExpr(source.
|
|
59
|
+
readExpr(source.expression, found);
|
|
60
60
|
return;
|
|
61
61
|
case 'unary':
|
|
62
62
|
readSource(source.operand, found);
|
|
@@ -72,37 +72,37 @@ function readSource(source, found) {
|
|
|
72
72
|
readSource(source.alternate, found);
|
|
73
73
|
return;
|
|
74
74
|
case 'math':
|
|
75
|
-
source.
|
|
75
|
+
source.callArguments.forEach(argument => readSource(argument, found));
|
|
76
76
|
return;
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
80
|
* Records what an expression reads.
|
|
81
81
|
*
|
|
82
|
-
* @param
|
|
82
|
+
* @param expression The expression.
|
|
83
83
|
* @param found What the walk has found.
|
|
84
84
|
*/
|
|
85
|
-
function readExpr(
|
|
86
|
-
switch (
|
|
85
|
+
function readExpr(expression, found) {
|
|
86
|
+
switch (expression.kind) {
|
|
87
87
|
case 'number':
|
|
88
88
|
case 'string':
|
|
89
89
|
case 'boolean':
|
|
90
90
|
case 'pi':
|
|
91
91
|
return;
|
|
92
92
|
case 'state':
|
|
93
|
-
found.states.add(
|
|
93
|
+
found.states.add(expression.state);
|
|
94
94
|
return;
|
|
95
95
|
case 'boot':
|
|
96
96
|
found.boot = true;
|
|
97
97
|
return;
|
|
98
98
|
case 'local':
|
|
99
|
-
readLocal(
|
|
99
|
+
readLocal(expression.local, found);
|
|
100
100
|
return;
|
|
101
101
|
case 'listLength':
|
|
102
|
-
found.states.add(
|
|
102
|
+
found.states.add(expression.list);
|
|
103
103
|
return;
|
|
104
104
|
case 'itemField':
|
|
105
|
-
readLocal(
|
|
105
|
+
readLocal(expression.item, found);
|
|
106
106
|
return;
|
|
107
107
|
case 'ref':
|
|
108
108
|
case 'clock':
|
|
@@ -116,11 +116,11 @@ function readExpr(expr, found) {
|
|
|
116
116
|
case 'wholeRound':
|
|
117
117
|
case 'trunc':
|
|
118
118
|
case 'toInt':
|
|
119
|
-
readExpr(
|
|
119
|
+
readExpr(expression.operand, found);
|
|
120
120
|
return;
|
|
121
121
|
case 'helper':
|
|
122
122
|
case 'floatMath':
|
|
123
|
-
|
|
123
|
+
expression.callArguments.forEach(argument => readExpr(argument, found));
|
|
124
124
|
return;
|
|
125
125
|
case 'arithmetic':
|
|
126
126
|
case 'floatDivide':
|
|
@@ -129,13 +129,13 @@ function readExpr(expr, found) {
|
|
|
129
129
|
case 'stringEquals':
|
|
130
130
|
case 'logical':
|
|
131
131
|
case 'pick':
|
|
132
|
-
readExpr(
|
|
133
|
-
readExpr(
|
|
132
|
+
readExpr(expression.left, found);
|
|
133
|
+
readExpr(expression.right, found);
|
|
134
134
|
return;
|
|
135
135
|
case 'conditional':
|
|
136
|
-
readExpr(
|
|
137
|
-
readExpr(
|
|
138
|
-
readExpr(
|
|
136
|
+
readExpr(expression.test, found);
|
|
137
|
+
readExpr(expression.consequent, found);
|
|
138
|
+
readExpr(expression.alternate, found);
|
|
139
139
|
return;
|
|
140
140
|
}
|
|
141
141
|
}
|
|
@@ -253,7 +253,7 @@ function readPaintColor(color, found) {
|
|
|
253
253
|
*/
|
|
254
254
|
const readsOf = (found) => found.untracked ? null : found.states;
|
|
255
255
|
/**
|
|
256
|
-
* The state a node's props, text and image read.
|
|
256
|
+
* The state a node's props, text and image read. the update sets them all again together, so this is
|
|
257
257
|
* everything any of them reads.
|
|
258
258
|
*
|
|
259
259
|
* @param node The node.
|
|
@@ -262,7 +262,7 @@ const readsOf = (found) => found.untracked ? null : found.states;
|
|
|
262
262
|
*/
|
|
263
263
|
export const nodeReads = (node) => readsOf(nodeFound(node));
|
|
264
264
|
/**
|
|
265
|
-
* Whether a node's runtime props read only values worked out at boot, so
|
|
265
|
+
* Whether a node's runtime props read only values worked out at boot, so the build sets them once.
|
|
266
266
|
*
|
|
267
267
|
* @param node The node.
|
|
268
268
|
*
|
|
@@ -270,7 +270,7 @@ export const nodeReads = (node) => readsOf(nodeFound(node));
|
|
|
270
270
|
*/
|
|
271
271
|
export const isBootOnlyNode = (node) => isBootOnly(nodeFound(node));
|
|
272
272
|
/**
|
|
273
|
-
* Whether a drawing reads only values worked out at boot, so
|
|
273
|
+
* Whether a drawing reads only values worked out at boot, so the build builds it once.
|
|
274
274
|
*
|
|
275
275
|
* @param vector The drawing.
|
|
276
276
|
*
|
|
@@ -45,7 +45,7 @@ export function slotOf(type) {
|
|
|
45
45
|
case 'struct':
|
|
46
46
|
return undefined;
|
|
47
47
|
case 'node':
|
|
48
|
-
return '
|
|
48
|
+
return 'node'; // a handle, which no number or text slot holds
|
|
49
49
|
default:
|
|
50
50
|
return type.kind;
|
|
51
51
|
}
|
|
@@ -62,12 +62,12 @@ export const int64Of = (source) => source === 'time' ? TIME : source === 'number
|
|
|
62
62
|
* The type of a value whose slot is known: a boolean when it holds one, a time when it is a 64-bit slot.
|
|
63
63
|
*
|
|
64
64
|
* @param slot The slot's kind.
|
|
65
|
-
* @param
|
|
65
|
+
* @param holdsBoolean The value is a JS boolean.
|
|
66
66
|
*
|
|
67
67
|
* @returns The type.
|
|
68
68
|
*/
|
|
69
|
-
export function typeOfSlot(slot,
|
|
70
|
-
if (
|
|
69
|
+
export function typeOfSlot(slot, holdsBoolean = false) {
|
|
70
|
+
if (holdsBoolean) {
|
|
71
71
|
if (slot !== 'int') {
|
|
72
72
|
throw new Error(`AOT internal: a boolean in a "${slot}" slot`);
|
|
73
73
|
}
|
|
@@ -89,20 +89,20 @@ export function typeOfSlot(slot, isBool = false) {
|
|
|
89
89
|
return NODE;
|
|
90
90
|
}
|
|
91
91
|
/**
|
|
92
|
-
* The type of a value
|
|
92
|
+
* The type of a value from its slot, and what the slot records about it.
|
|
93
93
|
*
|
|
94
94
|
* @param value The lowered value.
|
|
95
95
|
*
|
|
96
96
|
* @returns The type.
|
|
97
97
|
*/
|
|
98
|
-
export function
|
|
99
|
-
if (value.
|
|
100
|
-
if (value.
|
|
98
|
+
export function typeOfSlotValue(value) {
|
|
99
|
+
if (value.isLiteral || value.wide) {
|
|
100
|
+
if (value.slotKind !== 'i64' || (value.isLiteral && value.wide)) {
|
|
101
101
|
throw new Error('AOT internal: a 64-bit source on a value that is not one 64-bit number');
|
|
102
102
|
}
|
|
103
|
-
return value.
|
|
103
|
+
return value.isLiteral ? INT64_NUMBER : INT64_MATH;
|
|
104
104
|
}
|
|
105
|
-
return typeOfSlot(value.
|
|
105
|
+
return typeOfSlot(value.slotKind, value.isBoolean);
|
|
106
106
|
}
|
|
107
107
|
/**
|
|
108
108
|
* Whether a value is a time: a 64-bit number computed at runtime from a clock.
|
|
@@ -168,9 +168,9 @@ const wideSlotType = (widened) => widened === 'number' ? INT64_NUMBER : TIME;
|
|
|
168
168
|
*
|
|
169
169
|
* @returns Its type.
|
|
170
170
|
*/
|
|
171
|
-
export const stateType = (state) => state.
|
|
171
|
+
export const stateType = (state) => state.slotKind === 'i64'
|
|
172
172
|
? wideSlotType(state.widened)
|
|
173
|
-
: typeOfSlot(state.
|
|
173
|
+
: typeOfSlot(state.slotKind, state.isBoolean);
|
|
174
174
|
/**
|
|
175
175
|
* The type of a ref's current value.
|
|
176
176
|
*
|
|
@@ -180,6 +180,6 @@ export const stateType = (state) => state.cType === 'i64'
|
|
|
180
180
|
*/
|
|
181
181
|
export const refType = (ref) => ref.kind === 'node'
|
|
182
182
|
? NODE
|
|
183
|
-
: ref.
|
|
183
|
+
: ref.slotKind === 'i64'
|
|
184
184
|
? wideSlotType(ref.widened)
|
|
185
|
-
: typeOfSlot(ref.
|
|
185
|
+
: typeOfSlot(ref.slotKind);
|
|
@@ -13,4 +13,8 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
17
|
+
- Constants
|
|
18
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
19
|
+
/** The most stops the engine's gradient holds (ER_VECTOR_GRADIENT_MAX_STOPS). */
|
|
20
|
+
export const MAX_GRADIENT_STOPS = 8;
|
|
@@ -95,11 +95,11 @@ function lowerKey(key, layerIndex) {
|
|
|
95
95
|
*
|
|
96
96
|
* @returns The config.
|
|
97
97
|
*/
|
|
98
|
-
const lowerConfig = withLoc((
|
|
98
|
+
const lowerConfig = withLoc((configArgument) => {
|
|
99
99
|
// Fold the config object at compile time.
|
|
100
100
|
let config;
|
|
101
101
|
try {
|
|
102
|
-
config = evalStatic(
|
|
102
|
+
config = evalStatic(configArgument, {});
|
|
103
103
|
}
|
|
104
104
|
catch {
|
|
105
105
|
throw aotError('AOT: setKeyboardConfig(...) needs a statically-foldable config object', 'pass an object literal of colors/sizes (+ an optional `layers` array) — no state or runtime values.');
|
|
@@ -107,7 +107,7 @@ const lowerConfig = withLoc((configArg) => {
|
|
|
107
107
|
if (config == null || typeof config !== 'object') {
|
|
108
108
|
throw aotError('AOT: setKeyboardConfig(...) needs a config object');
|
|
109
109
|
}
|
|
110
|
-
// Lower the layout when the app gives one, layer by layer and row by row;
|
|
110
|
+
// Lower the layout when the app gives one, layer by layer and row by row; an empty table holds nothing.
|
|
111
111
|
let layers = null;
|
|
112
112
|
if (Array.isArray(config.layers)) {
|
|
113
113
|
if (!config.layers.length) {
|
|
@@ -127,10 +127,20 @@ const lowerConfig = withLoc((configArg) => {
|
|
|
127
127
|
return row.map(key => lowerKey(key, layerIndex));
|
|
128
128
|
});
|
|
129
129
|
});
|
|
130
|
+
// A layer key switching to a layer that isn't there would leave the keyboard with no keys.
|
|
131
|
+
const layerCount = layers.length;
|
|
132
|
+
for (const key of layers.flat(2)) {
|
|
133
|
+
if (key.kind === 'layer' &&
|
|
134
|
+
!(Number.isInteger(key.layer) &&
|
|
135
|
+
key.layer >= 0 &&
|
|
136
|
+
key.layer < layerCount)) {
|
|
137
|
+
throw aotError(`AOT: a setKeyboardConfig layer key switches to layer ${key.layer}, but there are only ${layerCount}`, `use a layer from 0 to ${layerCount - 1}.`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
130
140
|
}
|
|
131
141
|
return {
|
|
132
142
|
layers,
|
|
133
|
-
|
|
143
|
+
gridColumns: kbdSize(config.gridColumns),
|
|
134
144
|
rowHeight: kbdSize(config.rowHeight),
|
|
135
145
|
keyGap: kbdSize(config.keyGap),
|
|
136
146
|
keyRadius: kbdSize(config.keyRadius),
|
|
@@ -152,15 +162,15 @@ const lowerConfig = withLoc((configArg) => {
|
|
|
152
162
|
*/
|
|
153
163
|
export function lowerKeyboardConfig(program) {
|
|
154
164
|
// Find the first top-level setKeyboardConfig(...) call; without one, the built-in keyboard stays as is.
|
|
155
|
-
let
|
|
165
|
+
let configArgument = null;
|
|
156
166
|
for (const statement of program.body) {
|
|
157
167
|
if (statement.type === 'ExpressionStatement' &&
|
|
158
168
|
statement.expression.type === 'CallExpression' &&
|
|
159
169
|
statement.expression.callee.type === 'Identifier' &&
|
|
160
170
|
statement.expression.callee.name === 'setKeyboardConfig') {
|
|
161
|
-
|
|
171
|
+
configArgument = statement.expression.arguments[0];
|
|
162
172
|
break;
|
|
163
173
|
}
|
|
164
174
|
}
|
|
165
|
-
return
|
|
175
|
+
return configArgument ? lowerConfig(configArgument) : null;
|
|
166
176
|
}
|
package/aot/compiler/lower.mjs
CHANGED
|
@@ -17,11 +17,10 @@
|
|
|
17
17
|
- Imports
|
|
18
18
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
19
19
|
import { checkNumber, lowerWithChecks, runChecks } from './check.mjs';
|
|
20
|
-
import { aotError } from './diagnostics.mjs';
|
|
21
20
|
import { evalStatic, setBinding, withUndefined } from './static-eval.mjs';
|
|
22
21
|
import { abandonBoot, beginBoot, endBoot, setBootLowering } from './boot.mjs';
|
|
23
|
-
import { findShadowedClockCalls,
|
|
24
|
-
import { findComponent, declaredNames, moduleScope, collectState, findReturnJSX, collectComponents, collectHelpers, collectImageImports, collectSvgImports, collectCallbacks, collectMemos, collectEffects, bindConst, } from './collect.mjs';
|
|
22
|
+
import { findShadowedClockCalls, lowerSourcedWide, lowerExpr, } from './expressions.mjs';
|
|
23
|
+
import { findComponent, declaredNames, moduleScope, collectState, settleBootInitials, findReturnJSX, collectComponents, collectHelpers, collectImageImports, collectSvgImports, collectCallbacks, collectMemos, collectEffects, bindConst, } from './collect.mjs';
|
|
25
24
|
import { collectAnims, collectRefs } from './animations.mjs';
|
|
26
25
|
import { lowerEffect } from './handlers.mjs';
|
|
27
26
|
import { collectPanResponders } from './pan-responder.mjs';
|
|
@@ -35,26 +34,27 @@ import { nodeReads, vectorReads } from './ir/reads.mjs';
|
|
|
35
34
|
- Implementation
|
|
36
35
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
37
36
|
/**
|
|
38
|
-
* Settles what only the whole app decides. With nothing for
|
|
39
|
-
* so no body ends by
|
|
37
|
+
* Settles what only the whole app decides. With nothing for an update to re-apply there is no update,
|
|
38
|
+
* so no body ends by asking for one. A composition that no start waits on has no waits for a stop to end.
|
|
40
39
|
*
|
|
41
|
-
* @param
|
|
42
|
-
* @param hasUpdate The app has an
|
|
40
|
+
* @param output The lowered app's functions.
|
|
41
|
+
* @param hasUpdate The app has an update.
|
|
43
42
|
*/
|
|
44
|
-
function settleFunctions(
|
|
45
|
-
const idleOwners = new Set([...
|
|
43
|
+
function settleFunctions(output, hasUpdate) {
|
|
44
|
+
const idleOwners = new Set([...output.animationWaits.values()]
|
|
46
45
|
.filter(record => !record.isStarted)
|
|
47
46
|
.map(record => record.owner));
|
|
48
|
-
const settleStmts = (
|
|
49
|
-
for (const
|
|
50
|
-
if (
|
|
51
|
-
if (
|
|
52
|
-
|
|
47
|
+
const settleStmts = (statements) => {
|
|
48
|
+
for (const statement of statements) {
|
|
49
|
+
if (statement.kind === 'stopAnimations') {
|
|
50
|
+
if (statement.waitOwner !== null &&
|
|
51
|
+
idleOwners.has(statement.waitOwner)) {
|
|
52
|
+
statement.waitOwner = null;
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
else if (
|
|
56
|
-
settleStmts(
|
|
57
|
-
settleStmts(
|
|
55
|
+
else if (statement.kind === 'if') {
|
|
56
|
+
settleStmts(statement.consequent);
|
|
57
|
+
settleStmts(statement.alternate ?? []);
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
};
|
|
@@ -66,7 +66,7 @@ function settleFunctions(out, hasUpdate) {
|
|
|
66
66
|
}
|
|
67
67
|
settleStmts(callback.body);
|
|
68
68
|
};
|
|
69
|
-
for (const handler of
|
|
69
|
+
for (const handler of output.handlers) {
|
|
70
70
|
if (handler.kind === 'callback') {
|
|
71
71
|
settle(handler.callback);
|
|
72
72
|
}
|
|
@@ -74,15 +74,15 @@ function settleFunctions(out, hasUpdate) {
|
|
|
74
74
|
settle(handler.event.callback);
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
-
for (const timer of
|
|
77
|
+
for (const timer of output.timerFunctions) {
|
|
78
78
|
settle(timer.callback);
|
|
79
79
|
}
|
|
80
|
-
for (const animationCallback of
|
|
80
|
+
for (const animationCallback of output.animationCallbacks) {
|
|
81
81
|
if (animationCallback.kind === 'completion') {
|
|
82
82
|
settle(animationCallback.completion);
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
-
for (const effectFunction of
|
|
85
|
+
for (const effectFunction of output.effectFunctions) {
|
|
86
86
|
if (effectFunction.kind === 'mount') {
|
|
87
87
|
settleStmts(effectFunction.body);
|
|
88
88
|
}
|
|
@@ -93,7 +93,7 @@ function settleFunctions(out, hasUpdate) {
|
|
|
93
93
|
settleStmts(effectFunction.effect.body);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
for (const mountEffect of
|
|
96
|
+
for (const mountEffect of output.mountEffects) {
|
|
97
97
|
if (mountEffect.kind === 'inline') {
|
|
98
98
|
settle(mountEffect.callback);
|
|
99
99
|
}
|
|
@@ -103,7 +103,7 @@ function settleFunctions(out, hasUpdate) {
|
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
106
|
-
* Flags each state a node or drawing reads, so a write to it marks it changed and
|
|
106
|
+
* Flags each state a node or drawing reads, so a write to it marks it changed and the update sets them again.
|
|
107
107
|
* A node that also reads something untracked is set on every update, so its reads need no flag.
|
|
108
108
|
*
|
|
109
109
|
* @param nodes The app's nodes.
|
|
@@ -119,7 +119,7 @@ function watchState(nodes) {
|
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
/**
|
|
122
|
-
* Refuses state
|
|
122
|
+
* Refuses state a package cannot hold: a number in a list item that isn't finite, and a host value that would take
|
|
123
123
|
* the name of the setter every app exports for the wall clock. A field an item leaves out starts at 0.
|
|
124
124
|
*
|
|
125
125
|
* @param stateRecords The app's state, then each inlined instance's.
|
|
@@ -140,25 +140,22 @@ function checkStateRecords(stateRecords) {
|
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
|
-
if (stateRecords.some(record => record.kind === 'scalar' && record.host && record.name === 'wall_clock')) {
|
|
144
|
-
throw aotError('AOT: useHostValue("wall_clock") would collide with er_app_set_wall_clock()', 'rename the host value — every app exports er_app_set_wall_clock() for Date.now().');
|
|
145
|
-
}
|
|
146
143
|
}
|
|
147
144
|
/**
|
|
148
145
|
* Lowers a Flow B app's JSX (or TSX) source, then runs the check pass over what lowering recorded. Pure (no
|
|
149
|
-
* I/O);
|
|
146
|
+
* I/O); the package backend (package/) writes the result.
|
|
150
147
|
*
|
|
151
|
-
* @param
|
|
152
|
-
* @param
|
|
148
|
+
* @param source The App.jsx/App.tsx source text.
|
|
149
|
+
* @param options compilePackage's options, resolved (see resolveOptions).
|
|
153
150
|
* @param wide State/ref slots to declare 64-bit (see compileWidened).
|
|
154
151
|
* @param stores Collects every value stored into an int slot.
|
|
155
152
|
*
|
|
156
153
|
* @returns The lowered app.
|
|
157
154
|
*/
|
|
158
|
-
export function lowerApp(
|
|
159
|
-
beginBoot();
|
|
155
|
+
export function lowerApp(source, options, wide, stores) {
|
|
156
|
+
beginBoot(source);
|
|
160
157
|
try {
|
|
161
|
-
const { result, checks } = lowerWithChecks(() => lowerProgram(
|
|
158
|
+
const { result, checks } = lowerWithChecks(() => lowerProgram(source, options, wide, stores));
|
|
162
159
|
const app = { ...result, boot: endBoot(), checks };
|
|
163
160
|
runChecks(app.checks);
|
|
164
161
|
return app;
|
|
@@ -171,26 +168,26 @@ export function lowerApp(src, opts, wide, stores) {
|
|
|
171
168
|
* Runs the compiler passes over the parsed app, from its module scope and hooks through the element tree to its
|
|
172
169
|
* effects, recording the values the check pass checks.
|
|
173
170
|
*
|
|
174
|
-
* @param
|
|
175
|
-
* @param
|
|
171
|
+
* @param source The App.jsx/App.tsx source text.
|
|
172
|
+
* @param options compilePackage's options, resolved (see resolveOptions).
|
|
176
173
|
* @param wide State/ref slots to declare 64-bit (see compileWidened).
|
|
177
174
|
* @param stores Collects every value stored into an int slot.
|
|
178
175
|
*
|
|
179
176
|
* @returns The lowered app, without its checks.
|
|
180
177
|
*/
|
|
181
|
-
function lowerProgram(
|
|
178
|
+
function lowerProgram(source, options, wide, stores) {
|
|
182
179
|
// Parse the app and prepare the AST for the passes below.
|
|
183
|
-
const ast = parseApp(
|
|
180
|
+
const ast = parseApp(source, options);
|
|
184
181
|
normalizeUndefined(ast);
|
|
185
182
|
const shadowedClock = findShadowedClockCalls(ast);
|
|
186
183
|
// Seed the module scope with image imports (each is its baked-name string) so consts that use them can fold.
|
|
187
|
-
const { screen } =
|
|
184
|
+
const { screen } = options;
|
|
188
185
|
const imageImports = collectImageImports(ast.program);
|
|
189
186
|
const svgImports = collectSvgImports(ast.program);
|
|
190
187
|
const imageSeed = Object.fromEntries([...imageImports].map(([local, imageImport]) => [local, imageImport.name]));
|
|
191
188
|
const scope = moduleScope(ast.program, screen, imageSeed);
|
|
192
189
|
// Snapshot module bindings before App's consts fold in: child components close over these, not App's shadows.
|
|
193
|
-
const
|
|
190
|
+
const moduleConstants = { ...scope };
|
|
194
191
|
const component = findComponent(ast.program);
|
|
195
192
|
// Hide redeclared module names, then fold the body's static consts so responsive `if`s resolve at compile time.
|
|
196
193
|
for (const name of declaredNames(component.body.body)) {
|
|
@@ -201,28 +198,28 @@ function lowerProgram(src, opts, wide, stores) {
|
|
|
201
198
|
statement.kind !== 'const') {
|
|
202
199
|
continue;
|
|
203
200
|
}
|
|
204
|
-
for (const
|
|
205
|
-
if (
|
|
201
|
+
for (const declarator of statement.declarations) {
|
|
202
|
+
if (declarator.id.type !== 'Identifier' || !declarator.init)
|
|
206
203
|
continue;
|
|
207
204
|
try {
|
|
208
|
-
setBinding(scope,
|
|
205
|
+
setBinding(scope, declarator.id.name, bindConst(declarator.id.name, evalStatic(declarator.init, withUndefined(scope), 'boot')));
|
|
209
206
|
}
|
|
210
207
|
catch {
|
|
211
208
|
// A dynamic const must hide a same-named module const, or the JSX quietly renders the module value.
|
|
212
|
-
delete scope[
|
|
209
|
+
delete scope[declarator.id.name];
|
|
213
210
|
}
|
|
214
211
|
}
|
|
215
212
|
}
|
|
216
213
|
// Collect the component's state; a state name hides any module const of the same name from the folds.
|
|
217
|
-
const state = collectState(component.body, scope,
|
|
214
|
+
const state = collectState(component.body, scope, options.caps, '', wide);
|
|
218
215
|
for (const name of state.byName.keys()) {
|
|
219
216
|
delete scope[name];
|
|
220
217
|
}
|
|
221
218
|
// Collect the component's other hooks, plus the file's helpers and child components.
|
|
222
219
|
const rootJSX = findReturnJSX(component.body, scope);
|
|
223
|
-
const
|
|
220
|
+
const animations = collectAnims(component.body, scope);
|
|
224
221
|
const refs = collectRefs(component.body, scope, '', wide);
|
|
225
|
-
for (const name of [...
|
|
222
|
+
for (const name of [...animations.keys(), ...refs.keys()]) {
|
|
226
223
|
delete scope[name];
|
|
227
224
|
}
|
|
228
225
|
const pans = collectPanResponders(component.body);
|
|
@@ -235,77 +232,77 @@ function lowerProgram(src, opts, wide, stores) {
|
|
|
235
232
|
imageImport.importPath,
|
|
236
233
|
])); // asset name → path
|
|
237
234
|
// The expression environment every emitter compiles against.
|
|
238
|
-
const
|
|
235
|
+
const environment = {
|
|
239
236
|
state: state.byName,
|
|
240
237
|
locals: new Map(),
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
animations:
|
|
238
|
+
constants: scope,
|
|
239
|
+
moduleConstants, // what an inlined child component sees (see emitComponent)
|
|
240
|
+
animations: animations,
|
|
244
241
|
refs,
|
|
245
242
|
pans,
|
|
246
243
|
callbacks,
|
|
247
244
|
helpers,
|
|
248
245
|
imageNames,
|
|
249
246
|
svgImports,
|
|
250
|
-
svgArtifacts:
|
|
251
|
-
caps:
|
|
247
|
+
svgArtifacts: options.svgArtifacts || {},
|
|
248
|
+
caps: options.caps,
|
|
252
249
|
wide,
|
|
253
250
|
stores,
|
|
254
251
|
shadowedClock,
|
|
255
252
|
};
|
|
256
253
|
// A value worked out at boot lowers its slot against the app's environment.
|
|
257
|
-
setBootLowering(
|
|
258
|
-
|
|
259
|
-
|
|
254
|
+
setBootLowering(environment, lowerExpr);
|
|
255
|
+
settleBootInitials(state.byName.values());
|
|
256
|
+
// Before emit, fold each memo or inline its expression at each use (no cache needed: dep tracking re-applies).
|
|
257
|
+
for (const [name, expression] of memos) {
|
|
260
258
|
try {
|
|
261
|
-
setBinding(scope, name, bindConst(name, evalStatic(
|
|
259
|
+
setBinding(scope, name, bindConst(name, evalStatic(expression, scope, 'boot')));
|
|
262
260
|
}
|
|
263
261
|
catch {
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
262
|
+
const memo = lowerSourcedWide(expression, environment);
|
|
263
|
+
environment.locals.set(name, {
|
|
264
|
+
slotKind: memo.slotKind,
|
|
265
|
+
isBoolean: memo.isBoolean,
|
|
266
|
+
isLiteral: memo.isLiteral,
|
|
267
|
+
wide: memo.wide,
|
|
268
|
+
source: memo.source,
|
|
269
|
+
expression: memo.expression,
|
|
272
270
|
});
|
|
273
271
|
delete scope[name]; // a runtime binding beats a module const of its name in every fold
|
|
274
272
|
}
|
|
275
273
|
}
|
|
276
|
-
// Emit the scene graph from the root JSX; `
|
|
277
|
-
const
|
|
274
|
+
// Emit the scene graph from the root JSX; `output` collects everything else it lowers.
|
|
275
|
+
const output = new Out(components, ast.program);
|
|
278
276
|
const keyboard = lowerKeyboardConfig(ast.program); // a module-level setKeyboardConfig({...})
|
|
279
|
-
const root = emitNode(rootJSX, scope,
|
|
277
|
+
const root = emitNode(rootJSX, scope, output, environment, state);
|
|
280
278
|
// Emit registered only the images it reached; a dynamic source can't be enumerated, so bake every import.
|
|
281
|
-
if (
|
|
279
|
+
if (output.bakeAllImages) {
|
|
282
280
|
for (const [, imageImport] of imageImports) {
|
|
283
|
-
|
|
281
|
+
output.images.set(imageImport.name, imageImport.importPath);
|
|
284
282
|
}
|
|
285
283
|
}
|
|
286
|
-
// Lower effects (mount-once or dep-driven) after emit, so
|
|
284
|
+
// Lower effects (mount-once or dep-driven) after emit, so output.timerFunctions includes handler timers too.
|
|
287
285
|
for (const effect of collectEffects(component.body)) {
|
|
288
|
-
lowerEffect(effect,
|
|
286
|
+
lowerEffect(effect, environment, state, output);
|
|
289
287
|
}
|
|
290
|
-
//
|
|
291
|
-
const hasUpdate = nodesOf(root).some(node => isStateDriven(node) || updatedVectorOf(node) !== null) ||
|
|
292
|
-
settleFunctions(
|
|
288
|
+
// An update exists only when something has to be re-applied after a state change.
|
|
289
|
+
const hasUpdate = nodesOf(root).some(node => isStateDriven(node) || updatedVectorOf(node) !== null) || output.dependencyEffects.length > 0;
|
|
290
|
+
settleFunctions(output, hasUpdate);
|
|
293
291
|
if (hasUpdate) {
|
|
294
292
|
watchState(nodesOf(root));
|
|
295
293
|
}
|
|
296
|
-
const stateRecords = [...state.byName.values(), ...
|
|
294
|
+
const stateRecords = [...state.byName.values(), ...output.childStateRecords];
|
|
297
295
|
checkStateRecords(stateRecords);
|
|
298
296
|
return {
|
|
299
297
|
state: stateRecords,
|
|
300
|
-
refs: [...refs.values(), ...
|
|
301
|
-
animations: [...
|
|
298
|
+
refs: [...refs.values(), ...output.childRefs],
|
|
299
|
+
animations: [...animations.values(), ...output.childAnimations],
|
|
302
300
|
keyboard,
|
|
303
301
|
root,
|
|
304
|
-
|
|
305
|
-
images: [...out.images.entries()].map(([name, importPath]) => ({
|
|
302
|
+
images: [...output.images.entries()].map(([name, importPath]) => ({
|
|
306
303
|
name,
|
|
307
304
|
importPath,
|
|
308
305
|
})),
|
|
309
|
-
|
|
306
|
+
output,
|
|
310
307
|
};
|
|
311
308
|
}
|