embedded-react 0.15.0 → 0.17.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.
Files changed (62) hide show
  1. package/aot/compile.mjs +173 -8272
  2. package/aot/compiler/animations.mjs +1001 -0
  3. package/aot/compiler/assemble.mjs +922 -0
  4. package/aot/compiler/boot.mjs +441 -0
  5. package/aot/compiler/branch-merge.mjs +319 -0
  6. package/aot/compiler/c/animations.mjs +362 -0
  7. package/aot/compiler/c/boot.mjs +127 -0
  8. package/aot/compiler/c/expressions.mjs +270 -0
  9. package/aot/compiler/c/functions.mjs +268 -0
  10. package/aot/compiler/c/keyboard.mjs +96 -0
  11. package/aot/compiler/c/nodes.mjs +294 -0
  12. package/aot/compiler/c/pan-responder.mjs +136 -0
  13. package/aot/compiler/c/statements.mjs +271 -0
  14. package/aot/compiler/c/text.mjs +83 -0
  15. package/aot/compiler/c/vectors.mjs +381 -0
  16. package/aot/compiler/c-syntax.mjs +127 -0
  17. package/aot/compiler/check.mjs +165 -0
  18. package/aot/compiler/collect.mjs +785 -0
  19. package/aot/compiler/control-flow.mjs +696 -0
  20. package/aot/compiler/diagnostics.mjs +137 -0
  21. package/aot/compiler/elements/activity-indicator.mjs +160 -0
  22. package/aot/compiler/elements/dial.mjs +346 -0
  23. package/aot/compiler/elements/flat-list.mjs +139 -0
  24. package/aot/compiler/elements/image.mjs +151 -0
  25. package/aot/compiler/elements/modal.mjs +158 -0
  26. package/aot/compiler/elements/props.mjs +474 -0
  27. package/aot/compiler/elements/switch.mjs +183 -0
  28. package/aot/compiler/elements/text-input.mjs +171 -0
  29. package/aot/compiler/expressions.mjs +1579 -0
  30. package/aot/compiler/handlers.mjs +1072 -0
  31. package/aot/compiler/ir/animations.mjs +16 -0
  32. package/aot/compiler/ir/app.mjs +16 -0
  33. package/aot/compiler/ir/boot.mjs +16 -0
  34. package/aot/compiler/ir/expressions.mjs +16 -0
  35. package/aot/compiler/ir/functions.mjs +16 -0
  36. package/aot/compiler/ir/keyboard.mjs +16 -0
  37. package/aot/compiler/ir/nodes.mjs +107 -0
  38. package/aot/compiler/ir/pan-responder.mjs +16 -0
  39. package/aot/compiler/ir/reads.mjs +351 -0
  40. package/aot/compiler/ir/source.mjs +16 -0
  41. package/aot/compiler/ir/statements.mjs +16 -0
  42. package/aot/compiler/ir/text.mjs +16 -0
  43. package/aot/compiler/ir/types.mjs +185 -0
  44. package/aot/compiler/ir/vectors.mjs +16 -0
  45. package/aot/compiler/keyboard.mjs +152 -0
  46. package/aot/compiler/lower.mjs +311 -0
  47. package/aot/compiler/nodes.mjs +688 -0
  48. package/aot/compiler/options.mjs +55 -0
  49. package/aot/compiler/out.mjs +94 -0
  50. package/aot/compiler/pan-responder.mjs +354 -0
  51. package/aot/compiler/parse.mjs +300 -0
  52. package/aot/compiler/static-eval.mjs +454 -0
  53. package/aot/compiler/style-text.mjs +807 -0
  54. package/aot/compiler/svg.mjs +1167 -0
  55. package/aot/compiler/types.mjs +16 -0
  56. package/aot/screenshot-smoke.mjs +95 -55
  57. package/aot/style-map.mjs +366 -304
  58. package/cli.mjs +5 -8
  59. package/package.json +14 -6
  60. package/sim/embedded-react.wasm +0 -0
  61. package/src/embedded-react/FlatList.js +4 -4
  62. package/src/props.js +1 -1
@@ -0,0 +1,16 @@
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
+ export {};
@@ -14,17 +14,19 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- // `npm run aot:smoke` — automated compile-and-screenshot smoke test for the Flow B (AOT) demos.
18
- //
19
- // For each demo it: (1) compiles App.jsx → dist/app.gen.{c,h} (`node aot/compile.mjs`), (2) rebuilds the
20
- // linux-aot SDL host (which links the generated C), (3) runs it headless via ER_AOT_SHOT to render ONE
21
- // frame to a BMP, and (4) checks the image actually has content (distinct colours above a floor) — i.e. it
22
- // compiled, linked, and rendered something rather than crashing or drawing a blank screen. Exits non-zero
23
- // if any demo fails, so it can gate CI.
24
- //
25
- // Prereq: the linux-aot CMake build must be configurable (SDL2 found). It reuses examples/linux-aot/build;
26
- // if that isn't configured yet, set CMAKE_TOOLCHAIN_FILE (e.g. a vcpkg toolchain) and it will configure it.
27
- // Needs a display (SDL video); on a headless box run under a virtual framebuffer.
17
+ /*
18
+ * `npm run aot:smoke` — automated compile-and-screenshot smoke test for the Flow B (AOT) demos.
19
+ *
20
+ * For each demo it: (1) compiles App.jsx → dist/app.gen.{c,h} (`node aot/compile.mts`), (2) rebuilds the
21
+ * linux-aot SDL host (which links the generated C), (3) runs it headless via ER_AOT_SHOT to render ONE
22
+ * frame to a BMP, and (4) checks the image actually has content (distinct colors above a floor) — i.e., it
23
+ * compiled, linked, and rendered something rather than crashing or drawing a blank screen. Exits non-zero
24
+ * if any demo fails, so it can gate CI.
25
+ *
26
+ * Prereq: the linux-aot CMake build must be configurable (SDL2 found). It reuses examples/linux-aot/build;
27
+ * if that isn't configured yet, set CMAKE_TOOLCHAIN_FILE (e.g. a vcpkg toolchain) and it will configure it.
28
+ * Needs a display (SDL video); on a headless box run under a virtual framebuffer.
29
+ */
28
30
  import {execFileSync} from 'node:child_process';
29
31
  import {existsSync, mkdirSync, readFileSync, rmSync} from 'node:fs';
30
32
  import {resolve, dirname} from 'node:path';
@@ -43,79 +45,117 @@ const exe = resolve(
43
45
  );
44
46
  const tmpDir = resolve(jsDir, 'dist', '.smoke');
45
47
 
46
- // Demos to smoke-test. `screen` (optional) sets ER_AOT_SCREEN_W/H so the responsive thermostat folds to its
47
- // `solo` (AOT-compilable) branch. `minColors` is the floor of distinct sampled colours for "rendered".
48
+ /**
49
+ * The demos to smoke-test. `screen` sets ER_AOT_SCREEN_W/H so the responsive thermostat folds to its `solo`
50
+ * (AOT-compilable) branch; `minColors` is the floor of distinct sampled colors that counts as "rendered".
51
+ */
48
52
  const DEMOS = [
49
53
  {name: 'watch-face', screen: {w: 240, h: 280}, minColors: 40},
50
54
  {name: 'thermostat', screen: {w: 240, h: 320}, minColors: 40},
51
55
  ];
52
56
 
53
- /** Counts distinct colours in an uncompressed 24/32-bpp BMP (sampled) — a quick "is anything drawn?" signal. */
57
+ /**
58
+ * Counts the distinct colors in an uncompressed 24/32-bpp BMP, sampling every `step` pixels — a quick
59
+ * "is anything drawn?" signal.
60
+ *
61
+ * @param path The BMP file.
62
+ * @param step The sampling stride, in pixels, along both axes.
63
+ *
64
+ * @returns The number of distinct colors sampled.
65
+ */
54
66
  function bmpDistinctColors(path, step = 4) {
55
- const b = readFileSync(path);
56
- if (b[0] !== 0x42 || b[1] !== 0x4d) throw new Error(`not a BMP: ${path}`);
57
- const off = b.readUInt32LE(10);
58
- const w = b.readInt32LE(18);
59
- const h = Math.abs(b.readInt32LE(22));
60
- const bpp = b.readUInt16LE(28);
61
- if (bpp !== 24 && bpp !== 32) throw new Error(`unexpected BMP bpp ${bpp}`);
62
- const bytesPP = bpp / 8;
63
- const rowSize = Math.floor((bpp * w + 31) / 32) * 4; // rows padded to 4 bytes
67
+ const bmp = readFileSync(path);
68
+ if (bmp[0] !== 0x42 || bmp[1] !== 0x4d) {
69
+ throw new Error(`not a BMP: ${path}`);
70
+ }
71
+ const pixelOffset = bmp.readUInt32LE(10);
72
+ const width = bmp.readInt32LE(18);
73
+ const height = Math.abs(bmp.readInt32LE(22));
74
+ const bitsPerPixel = bmp.readUInt16LE(28);
75
+ if (bitsPerPixel !== 24 && bitsPerPixel !== 32) {
76
+ throw new Error(`unexpected BMP bpp ${bitsPerPixel}`);
77
+ }
78
+ const bytesPerPixel = bitsPerPixel / 8;
79
+ const rowSize = Math.floor((bitsPerPixel * width + 31) / 32) * 4; // rows padded to 4 bytes
64
80
  const colors = new Set();
65
- for (let y = 0; y < h; y += step) {
66
- for (let x = 0; x < w; x += step) {
67
- const p = off + y * rowSize + x * bytesPP;
68
- colors.add((b[p] << 16) | (b[p + 1] << 8) | b[p + 2]); // BGR triplet
81
+ for (let y = 0; y < height; y += step) {
82
+ for (let x = 0; x < width; x += step) {
83
+ const index = pixelOffset + y * rowSize + x * bytesPerPixel;
84
+ colors.add((bmp[index] << 16) | (bmp[index + 1] << 8) | bmp[index + 2]); // BGR triplet
69
85
  }
70
86
  }
71
87
  return colors.size;
72
88
  }
73
89
 
74
- function run(cmd, args, opts = {}) {
75
- execFileSync(cmd, args, {stdio: 'pipe', ...opts});
90
+ function run(command, args, options = {}) {
91
+ execFileSync(command, args, {stdio: 'pipe', ...options});
76
92
  }
77
93
 
94
+ /** Configures the linux-aot CMake build on the first run. */
78
95
  function ensureConfigured() {
79
96
  if (existsSync(resolve(buildDir, 'CMakeCache.txt'))) return;
80
97
  console.log('• configuring linux-aot build (first run)…');
81
98
  const args = ['-S', exampleDir, '-B', buildDir];
82
- if (process.env.CMAKE_TOOLCHAIN_FILE)
99
+ if (process.env.CMAKE_TOOLCHAIN_FILE) {
83
100
  args.push(`-DCMAKE_TOOLCHAIN_FILE=${process.env.CMAKE_TOOLCHAIN_FILE}`);
84
- if (process.platform === 'win32') args.push('-G', 'MinGW Makefiles');
101
+ }
102
+ if (process.platform === 'win32') {
103
+ args.push('-G', 'MinGW Makefiles');
104
+ }
85
105
  run('cmake', args);
86
106
  }
87
107
 
108
+ /**
109
+ * Compiles one demo, relinks the host, renders one frame and checks the frame has content. A step that cannot
110
+ * run (the compiler, the build or the host) throws.
111
+ *
112
+ * @param demo The demo, from DEMOS.
113
+ *
114
+ * @returns Why the demo failed, or null when it rendered.
115
+ */
116
+ function smokeTest(demo) {
117
+ const shot = resolve(tmpDir, `${demo.name}.bmp`);
118
+ rmSync(shot, {force: true});
119
+
120
+ // Compile with the demo's screen size, relink the host, then render one frame to the BMP.
121
+ const compileEnv = {...process.env};
122
+ if (demo.screen) {
123
+ compileEnv.ER_AOT_SCREEN_W = String(demo.screen.w);
124
+ compileEnv.ER_AOT_SCREEN_H = String(demo.screen.h);
125
+ }
126
+ run('node', [resolve(here, 'compile.mts'), demo.name], {
127
+ cwd: jsDir,
128
+ env: compileEnv,
129
+ });
130
+ run('cmake', ['--build', buildDir]);
131
+ run(exe, [], {cwd: buildDir, env: {...process.env, ER_AOT_SHOT: shot}});
132
+
133
+ // The frame must exist and show more than a blank screen.
134
+ if (!existsSync(shot)) {
135
+ return 'no screenshot written (host crashed before present?)';
136
+ }
137
+ const colors = bmpDistinctColors(shot);
138
+ if (colors < demo.minColors) {
139
+ return `screenshot looks blank (${colors} distinct colors < ${demo.minColors})`;
140
+ }
141
+ console.log(`✓ ${demo.name}: rendered (${colors} distinct colors)`);
142
+ return null;
143
+ }
144
+
88
145
  let failures = 0;
89
146
  mkdirSync(tmpDir, {recursive: true});
90
147
  ensureConfigured();
91
148
 
92
149
  for (const demo of DEMOS) {
93
- const shot = resolve(tmpDir, `${demo.name}.bmp`);
150
+ let failure;
94
151
  try {
95
- rmSync(shot, {force: true});
96
- const genEnv = {...process.env};
97
- if (demo.screen) {
98
- genEnv.ER_AOT_SCREEN_W = String(demo.screen.w);
99
- genEnv.ER_AOT_SCREEN_H = String(demo.screen.h);
100
- }
101
- run('node', [resolve(here, 'compile.mjs'), demo.name], {
102
- cwd: jsDir,
103
- env: genEnv,
104
- }); // → dist/app.gen.{c,h}
105
- run('cmake', ['--build', buildDir]); // relink the generated C
106
- run(exe, [], {cwd: buildDir, env: {...process.env, ER_AOT_SHOT: shot}}); // render one frame → BMP
107
-
108
- if (!existsSync(shot))
109
- throw new Error('no screenshot written (host crashed before present?)');
110
- const colors = bmpDistinctColors(shot);
111
- if (colors < demo.minColors)
112
- throw new Error(
113
- `screenshot looks blank (${colors} distinct colours < ${demo.minColors})`,
114
- );
115
- console.log(`✓ ${demo.name}: rendered (${colors} distinct colours)`);
116
- } catch (e) {
152
+ failure = smokeTest(demo);
153
+ } catch (error) {
154
+ failure = error.message?.split('\n')[0] || String(error);
155
+ }
156
+ if (failure) {
117
157
  failures++;
118
- console.error(`✗ ${demo.name}: ${e.message?.split('\n')[0] || e}`);
158
+ console.error(`✗ ${demo.name}: ${failure}`);
119
159
  }
120
160
  }
121
161