@typecad/cuttlefish 1.0.0-alpha.6 → 1.0.0-alpha.8

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 (187) hide show
  1. package/dist/api/config.d.ts +32 -0
  2. package/dist/api/index.d.ts +1 -1
  3. package/dist/api/schema/types.d.ts +15 -0
  4. package/dist/api/shared/async-runtime-static.d.ts +12 -1
  5. package/dist/api/shared/async-runtime-static.js +69 -24
  6. package/dist/api/shared/async-symbol-detector.d.ts +11 -0
  7. package/dist/api/shared/async-symbol-detector.js +140 -0
  8. package/dist/api/shared/async-types.d.ts +24 -0
  9. package/dist/api/shared/coop-scheduler.d.ts +60 -0
  10. package/dist/api/shared/coop-scheduler.js +149 -0
  11. package/dist/api/shared/display-adapter.d.ts +4 -3
  12. package/dist/api/shared/display-adapter.js +15 -118
  13. package/dist/api/shared/display-adapters/sdl.js +38 -31
  14. package/dist/api/shared/display-profile.d.ts +47 -25
  15. package/dist/api/shared/display-profile.js +31 -164
  16. package/dist/api/shared/framework-manifest-registry.d.ts +9 -0
  17. package/dist/api/shared/framework-manifest-registry.js +27 -0
  18. package/dist/api/shared/framework-manifest.d.ts +581 -0
  19. package/dist/api/shared/framework-manifest.js +182 -0
  20. package/dist/api/shared/glcdfont.d.ts +12 -0
  21. package/dist/api/shared/glcdfont.js +124 -0
  22. package/dist/api/shared/graphics-strategy.d.ts +37 -0
  23. package/dist/api/shared/hal-op-ir.d.ts +755 -1
  24. package/dist/api/shared/hal-op-ir.js +129 -1
  25. package/dist/api/shared/index.d.ts +20 -2
  26. package/dist/api/shared/index.js +25 -1
  27. package/dist/api/shared/ir-core.d.ts +4 -0
  28. package/dist/api/shared/ir-declarations.d.ts +6 -0
  29. package/dist/api/shared/native-display-op-resolver.d.ts +10 -0
  30. package/dist/api/shared/native-display-op-resolver.js +64 -0
  31. package/dist/api/shared/platform-strategy.d.ts +113 -2
  32. package/dist/api/shared/polyfill-helper-registry.js +18 -1
  33. package/dist/api/shared/promise-runtime.d.ts +1 -1
  34. package/dist/api/shared/promise-runtime.js +95 -13
  35. package/dist/api/shared/toolchain-types.d.ts +17 -0
  36. package/dist/api/shared/validate-framework-manifest.d.ts +28 -0
  37. package/dist/api/shared/validate-framework-manifest.js +494 -0
  38. package/dist/api/shared/worker-runtime-polyfill.d.ts +22 -0
  39. package/dist/api/shared/worker-runtime-polyfill.js +34 -0
  40. package/dist/api/shared/worker-runtime.d.ts +69 -0
  41. package/dist/api/shared/worker-runtime.js +163 -0
  42. package/dist/cli.js +186 -82
  43. package/dist/config-loader.d.ts +7 -2
  44. package/dist/config-loader.js +23 -3
  45. package/dist/config-schema.d.ts +112 -70
  46. package/dist/config-schema.js +14 -0
  47. package/dist/contract/board-generator.d.ts +17 -0
  48. package/dist/contract/board-generator.js +57 -0
  49. package/dist/contract/contract-parser.d.ts +217 -0
  50. package/dist/contract/contract-parser.js +224 -0
  51. package/dist/contract/index.d.ts +22 -0
  52. package/dist/contract/index.js +68 -0
  53. package/dist/create/board-codegen.js +4 -4
  54. package/dist/create/board-generators.js +4 -5
  55. package/dist/create/board-spec.d.ts +72 -75
  56. package/dist/create/board-spec.js +0 -1
  57. package/dist/create/init-scaffold.d.ts +9 -2
  58. package/dist/create/init-scaffold.js +0 -14
  59. package/dist/create/init-templates.d.ts +2 -0
  60. package/dist/create/init-templates.js +74 -8
  61. package/dist/create/init-wizard.js +31 -7
  62. package/dist/debug/preprocessor.js +178 -39
  63. package/dist/debug/types.d.ts +23 -0
  64. package/dist/diagnostics/mermaid-builder.d.ts +1 -1
  65. package/dist/diagnostics/mermaid-builder.js +34 -24
  66. package/dist/emit/compliance/arxml-writer.d.ts +11 -0
  67. package/dist/emit/compliance/arxml-writer.js +34 -0
  68. package/dist/emit/compliance/compliance-context.d.ts +57 -0
  69. package/dist/emit/compliance/compliance-context.js +113 -0
  70. package/dist/emit/compliance/deviation-ledger.d.ts +27 -0
  71. package/dist/emit/compliance/deviation-ledger.js +47 -0
  72. package/dist/emit/compliance/deviation-writer.d.ts +30 -0
  73. package/dist/emit/compliance/deviation-writer.js +37 -0
  74. package/dist/emit/compliance/index.d.ts +7 -0
  75. package/dist/emit/compliance/index.js +6 -0
  76. package/dist/emit/compliance/rule-engine.d.ts +13 -0
  77. package/dist/emit/compliance/rule-engine.js +101 -0
  78. package/dist/emit/compliance/rules.d.ts +16 -0
  79. package/dist/emit/compliance/rules.js +191 -0
  80. package/dist/emit/compliance/types.d.ts +59 -0
  81. package/dist/emit/compliance/types.js +8 -0
  82. package/dist/emit/cpp-emitter.js +4 -3
  83. package/dist/emit/emitters/class-emitter.js +6 -1
  84. package/dist/emit/emitters/emitter-context.d.ts +28 -1
  85. package/dist/emit/emitters/function-emitter-impl.js +153 -53
  86. package/dist/emit/emitters/line-appender.js +19 -0
  87. package/dist/emit/emitters/line-marker.d.ts +38 -0
  88. package/dist/emit/emitters/line-marker.js +39 -0
  89. package/dist/emit/emitters/output-finalizer.d.ts +6 -0
  90. package/dist/emit/emitters/output-finalizer.js +101 -12
  91. package/dist/emit/emitters/setup.d.ts +17 -0
  92. package/dist/emit/emitters/setup.js +257 -36
  93. package/dist/emit/emitters/top-level-prep.js +8 -0
  94. package/dist/emit/emitters/type-decl-emitter.js +28 -3
  95. package/dist/emit/emitters/ui-emitter.js +33 -9
  96. package/dist/emit/expression-renderer.d.ts +1 -1
  97. package/dist/emit/expression-renderer.js +91 -6
  98. package/dist/emit/route-hal-op.js +18 -5
  99. package/dist/emit/snprintf-helpers.js +15 -4
  100. package/dist/emit/statement-renderer.d.ts +10 -0
  101. package/dist/emit/statement-renderer.js +34 -5
  102. package/dist/emit/utils/async-state-machine.js +221 -125
  103. package/dist/emit/utils/hal-op-cpp-type.d.ts +6 -0
  104. package/dist/emit/utils/hal-op-cpp-type.js +40 -0
  105. package/dist/framework-package.js +2 -0
  106. package/dist/framework-registry.d.ts +17 -0
  107. package/dist/ir/adc-range-validation.js +14 -1
  108. package/dist/ir/build-ir-state.d.ts +1 -0
  109. package/dist/ir/build-ir-state.js +14 -0
  110. package/dist/ir/build-ir.js +9 -5
  111. package/dist/ir/call-graph.js +16 -0
  112. package/dist/ir/expression-to-ir.js +164 -0
  113. package/dist/ir/feature-registry.js +7 -25
  114. package/dist/ir/function-builder.js +22 -0
  115. package/dist/ir/hal/hal-emitter.d.ts +5 -2
  116. package/dist/ir/hal/hal-emitter.js +50 -18
  117. package/dist/ir/hal/hal-parser.d.ts +6 -0
  118. package/dist/ir/hal/hal-parser.js +81 -0
  119. package/dist/ir/hal/hal-plugins.js +723 -1
  120. package/dist/ir/identifier-collector.js +35 -0
  121. package/dist/ir/interrupt-analysis.d.ts +5 -1
  122. package/dist/ir/interrupt-analysis.js +8 -16
  123. package/dist/ir/network-validation.d.ts +4 -0
  124. package/dist/ir/network-validation.js +184 -0
  125. package/dist/ir/ownership-analysis.js +20 -1
  126. package/dist/ir/pin-capability-validation.js +37 -0
  127. package/dist/ir/pin-mode-validation.d.ts +2 -2
  128. package/dist/ir/pin-mode-validation.js +49 -18
  129. package/dist/ir/program-analysis.d.ts +65 -0
  130. package/dist/ir/program-analysis.js +318 -2
  131. package/dist/ir/render-expr.js +11 -0
  132. package/dist/ir/timing-validation.d.ts +6 -1
  133. package/dist/ir/timing-validation.js +60 -13
  134. package/dist/ir/transformers/call-statement.js +105 -0
  135. package/dist/ir/transformers/expressions.js +62 -0
  136. package/dist/ir/transformers/hal-call-resolver.js +21 -0
  137. package/dist/ir/transformers/hal-emit-helpers.js +1 -1
  138. package/dist/ir/transformers/namespace-methods.js +17 -12
  139. package/dist/ir/transformers/ui-reactive.js +2 -2
  140. package/dist/ir/transformers/variables.js +92 -3
  141. package/dist/ir/type-resolution.js +18 -0
  142. package/dist/ir/ui-element-auto-wire.js +7 -5
  143. package/dist/ir/utils/map-statements.d.ts +4 -0
  144. package/dist/ir/utils/map-statements.js +79 -0
  145. package/dist/ir/validation-orchestrator.js +9 -2
  146. package/dist/ir/worker-analysis.d.ts +10 -0
  147. package/dist/ir/worker-analysis.js +261 -0
  148. package/dist/libdef/c-to-decl.d.ts +27 -0
  149. package/dist/libdef/c-to-decl.js +397 -0
  150. package/dist/libdef/component-decls.d.ts +2 -0
  151. package/dist/libdef/component-decls.js +6 -0
  152. package/dist/libdef/component-discovery.d.ts +43 -0
  153. package/dist/libdef/component-discovery.js +83 -0
  154. package/dist/libdef/cpp-to-decl.d.ts +9 -0
  155. package/dist/libdef/cpp-to-decl.js +72 -0
  156. package/dist/libdef/registry.js +5 -2
  157. package/dist/lint-cache.d.ts +59 -0
  158. package/dist/lint-cache.js +257 -0
  159. package/dist/orchestrator/graph-builder.js +14 -9
  160. package/dist/platform/coop-scheduler-runtime.d.ts +19 -0
  161. package/dist/platform/coop-scheduler-runtime.js +41 -0
  162. package/dist/platform/generic-strategy.d.ts +15 -3
  163. package/dist/platform/generic-strategy.js +49 -4
  164. package/dist/safety/safety-bridge.d.ts +11 -0
  165. package/dist/safety/safety-bridge.js +48 -0
  166. package/dist/safety/sidecar-bridge.d.ts +5 -0
  167. package/dist/safety/sidecar-bridge.js +22 -0
  168. package/dist/safety-hook.d.ts +79 -0
  169. package/dist/safety-hook.js +35 -0
  170. package/dist/testing.d.ts +7 -1
  171. package/dist/testing.js +8 -1
  172. package/dist/transpile.d.ts +3 -0
  173. package/dist/transpile.js +175 -41
  174. package/dist/types.d.ts +13 -2
  175. package/dist/ui-hook.d.ts +17 -3
  176. package/dist/utils/cli.js +78 -4
  177. package/dist/utils/fs.d.ts +13 -0
  178. package/dist/utils/fs.js +50 -0
  179. package/package.json +24 -5
  180. package/dist/api/shared/display-adapters/eink-mono.d.ts +0 -2
  181. package/dist/api/shared/display-adapters/eink-mono.js +0 -53
  182. package/dist/api/shared/display-adapters/ssd1309.d.ts +0 -2
  183. package/dist/api/shared/display-adapters/ssd1309.js +0 -136
  184. package/dist/api/shared/display-adapters/st7796.d.ts +0 -2
  185. package/dist/api/shared/display-adapters/st7796.js +0 -132
  186. package/dist/licenses.d.ts +0 -185
  187. package/dist/licenses.js +0 -963
@@ -1,13 +1,16 @@
1
1
  import path from "node:path";
2
2
  import { filterPolyfillHelpers, isStringEnum } from "../../api/shared/index.js";
3
+ import { hasSafetyHook, requireSafetyHook } from "../../safety-hook.js";
3
4
  import { analyzeProgram } from "../../ir/program-analysis.js";
4
5
  import { collectStatementIdentifiers } from "../../ir/identifier-collector.js";
5
6
  import { ensureDir } from "../../utils/fs.js";
6
7
  import { resolveImport } from "../../libdef/registry.js";
7
8
  import { emitPolyfillBoilerplate } from "../native-helpers-emitter.js";
8
9
  import { resolveStrategy } from "../../platform/registry.js";
10
+ import { buildCoopSchedulerPolyfill } from "../../platform/coop-scheduler-runtime.js";
9
11
  import { getLoadedFramework } from "../../framework-registry.js";
10
12
  import { entryHasUI } from "../../ui-hook.js";
13
+ import { ComplianceContext } from "../compliance/compliance-context.js";
11
14
  import { createEmissionScopeState, statementNeedsSnprintf, } from "../snprintf-helpers.js";
12
15
  import { ExpressionRenderer } from "../expression-renderer.js";
13
16
  import { StatementRenderer } from "../statement-renderer.js";
@@ -86,18 +89,18 @@ function programUsesWdt(program) {
86
89
  };
87
90
  if (visit(program.topLevelStatements))
88
91
  return true;
89
- for (const fn of program.functions) {
92
+ for (const fn of program.functions ?? []) {
90
93
  if (visit(fn.statements))
91
94
  return true;
92
95
  }
93
- for (const cls of program.classes) {
94
- for (const m of cls.methods)
96
+ for (const cls of program.classes ?? []) {
97
+ for (const m of cls.methods ?? [])
95
98
  if (visit(m.statements))
96
99
  return true;
97
- for (const g of cls.getters)
100
+ for (const g of cls.getters ?? [])
98
101
  if (visit(g.statements))
99
102
  return true;
100
- for (const s of cls.setters)
103
+ for (const s of cls.setters ?? [])
101
104
  if (visit(s.statements))
102
105
  return true;
103
106
  if (cls.constructor && visit(cls.constructor.statements))
@@ -106,12 +109,109 @@ function programUsesWdt(program) {
106
109
  return false;
107
110
  }
108
111
  /**
109
- * Extract a `#ifndef MACRO ... #endif` include-guard block from a shim line
110
- * list. Used to emit just the macro definition (e.g. CUTTLEFISH_UNDEFINED) in
111
- * non-entry files of a split compilation, where the full helper shim belongs
112
- * to the entry file but the macro token is still referenced here.
113
- * Returns an empty array if no matching guard is found.
112
+ * Detect whether a program uses @typecad/safety. The safety transform pass
113
+ * injects safety.* ops when in use; strategies consult this to decide
114
+ * whether to emit the __tc_gpio_read shim that the safety voter calls.
115
+ * Mirrors programUsesWdt() above (same inline walker pattern).
116
+ *
117
+ * `hal-expr` (the expression-position safety.read_safe lowering produced
118
+ * by `const r = safe.read(pin)`) lives in expression trees, not at statement
119
+ * level — but it's carried inside a var_decl statement whose initializer is
120
+ * the hal-expr, and the var_decl gets visited as a top-level statement. We
121
+ * detect both: statement-level `hal-op` operations, and any statement whose
122
+ * rendered initializer text mentions safety.* (a defensive catch for the
123
+ * hal-expr-in-initializer case). The latter is rarely needed because the
124
+ * voter's read_safe op is also captured at the call site, but kept for
125
+ * robustness.
114
126
  */
127
+ export function programUsesSafety(program) {
128
+ // Defensive: some test fixtures and partial-program callers pass a minimal
129
+ // object (e.g. `{} as any`). Treat a missing iterable field as "no safety
130
+ // ops" rather than crashing — matches how the existing ArduinoStrategy path
131
+ // behaves when given a partial program.
132
+ if (!program)
133
+ return false;
134
+ const visitStatement = (stmt) => {
135
+ if (stmt.kind === "hal-op") {
136
+ const opName = stmt.operation?.operation;
137
+ if (typeof opName === "string" && opName.startsWith("safety."))
138
+ return true;
139
+ }
140
+ switch (stmt.kind) {
141
+ case "block":
142
+ case "labeled":
143
+ return visit(stmt.body);
144
+ case "if":
145
+ return visit(stmt.thenBranch) || visit(stmt.elseBranch ?? []);
146
+ case "for":
147
+ return visit(stmt.body)
148
+ || (stmt.initializer ? visitStatement(stmt.initializer) : false);
149
+ case "while":
150
+ case "do_while":
151
+ case "for_of":
152
+ case "for_in":
153
+ return visit(stmt.body);
154
+ case "switch":
155
+ return stmt.cases.some((c) => visit(c.body ?? []));
156
+ case "try":
157
+ return visit(stmt.tryBlock) || visit(stmt.catchBlock ?? []) || visit(stmt.finallyBlock ?? []);
158
+ default:
159
+ return false;
160
+ }
161
+ };
162
+ const visit = (statements) => {
163
+ if (!statements)
164
+ return false;
165
+ for (const stmt of statements) {
166
+ if (visitStatement(stmt))
167
+ return true;
168
+ }
169
+ return false;
170
+ };
171
+ if (visit(program.topLevelStatements))
172
+ return true;
173
+ for (const fn of program.functions ?? []) {
174
+ if (visit(fn.statements))
175
+ return true;
176
+ }
177
+ for (const cls of program.classes ?? []) {
178
+ for (const m of cls.methods ?? [])
179
+ if (visit(m.statements))
180
+ return true;
181
+ for (const g of cls.getters ?? [])
182
+ if (visit(g.statements))
183
+ return true;
184
+ for (const s of cls.setters ?? [])
185
+ if (visit(s.statements))
186
+ return true;
187
+ if (cls.constructor && visit(cls.constructor.statements))
188
+ return true;
189
+ }
190
+ // SafeInt<T> / SafeVariable<T> usage does not produce safety.* hal-ops
191
+ // (they are plain C++ template types), so the op-walk above misses them.
192
+ // Detect via the var_decl cppType: any declaration whose type starts with
193
+ // "SafeInt" or "SafeVariable" needs the corresponding polyfill to ship.
194
+ const usesSafeWrapperType = (statements) => {
195
+ if (!statements)
196
+ return false;
197
+ for (const stmt of statements) {
198
+ if (stmt.kind === "var_decl") {
199
+ const cppType = stmt.cppType;
200
+ if (typeof cppType === "string" && (cppType.startsWith("SafeInt") || cppType.startsWith("SafeVariable"))) {
201
+ return true;
202
+ }
203
+ }
204
+ }
205
+ return false;
206
+ };
207
+ if (usesSafeWrapperType(program.topLevelStatements))
208
+ return true;
209
+ for (const fn of program.functions ?? []) {
210
+ if (usesSafeWrapperType(fn.statements))
211
+ return true;
212
+ }
213
+ return false;
214
+ }
115
215
  function extractShimMacro(lines, macroName) {
116
216
  const ifndefIdx = lines.findIndex(l => {
117
217
  const trimmed = l.trim();
@@ -174,9 +274,29 @@ export function buildEmitterContext(program, options) {
174
274
  stringEnumNames.add(name);
175
275
  }
176
276
  }
277
+ // When @typecad/safety is active, register its enum names so the expression
278
+ // renderer uses :: (C++ enum-class scope resolution) instead of . (TS dot
279
+ // access) for member access like SafetyFaultCategory.Configuration. The
280
+ // graph-builder skips @typecad/safety (its source isn't parsed), so these
281
+ // enum names never enter program.enums — we register them manually here.
282
+ if (hasSafetyHook()) {
283
+ enumNames.add("SafetyFaultCategory");
284
+ enumNames.add("SafetyFaultCode");
285
+ enumNames.add("SafetyStatus");
286
+ }
177
287
  const strategy = options.strategy ?? resolveStrategy(options.target ?? "generic");
178
288
  strategy.setLargeEnumNames?.(largeEnumNames);
179
- const reservedNames = strategy.reservedNames();
289
+ // When @typecad/safety is active, `safe` is a compile-time-only construct
290
+ // (its methods are intercepted at IR-build time). Its top-level var_decl
291
+ // (from the parsed safety module source) must NOT be emitted as a C++
292
+ // _safe_t struct — add it to reservedNames so the top-level-prep filter
293
+ // strips it. Mirrors how platform reserved names (HIGH, LOW, etc.) are
294
+ // kept out of user-code emission.
295
+ let reservedNames = new Set(strategy.reservedNames());
296
+ if (hasSafetyHook()) {
297
+ reservedNames = new Set(reservedNames);
298
+ reservedNames.add("safe");
299
+ }
180
300
  ensureDir(options.outDir);
181
301
  const classNameMap = (() => {
182
302
  try {
@@ -226,14 +346,50 @@ export function buildEmitterContext(program, options) {
226
346
  ? (strategy.generateNativePolyfills?.(program, options.platformContext) ?? [])
227
347
  : (strategy.generateNativePolyfills?.(program, options.platformContext) ?? []);
228
348
  let filteredNativePolyfills = filterPolyfillHelpers(nativePolyfills, programAnalysis.usedPolyfillHelpers);
229
- if (!programAnalysis.hasThrowStatements) {
349
+ // cuttlefish_halt: keep when the program throws (throw lowers to cuttlefish_halt)
350
+ // OR explicitly calls cuttlefish_halt in lowered raw text.
351
+ if (!programAnalysis.hasThrowStatements && !programAnalysis.usesHalt) {
230
352
  filteredNativePolyfills = filteredNativePolyfills.filter(p => p.id !== "cuttlefish_halt");
231
353
  }
354
+ // static_array: the __tc_StaticArray struct has no __tc_*() call pattern, so
355
+ // filterPolyfillHelpers' per-function tree-shaker can't drop it (it sees no
356
+ // extractable name). Gate at the polyfill-id level instead: keep only when
357
+ // __tc_StaticArray genuinely appears in used code.
358
+ if (!programAnalysis.usedPolyfillHelpers.has('__tc_StaticArray')) {
359
+ filteredNativePolyfills = filteredNativePolyfills.filter(p => p.id !== "static_array");
360
+ }
232
361
  const usesTimers = programAnalysis.usedPolyfillHelpers.has('__tc_setInterval') ||
233
362
  programAnalysis.usedPolyfillHelpers.has('__tc_setTimeout');
234
363
  if (!usesTimers) {
235
364
  filteredNativePolyfills = filteredNativePolyfills.filter(p => p.id !== "timer_methods");
236
365
  }
366
+ // Safety polyfills (mode table + voter + SafeVariable + SafeInt). Gated on
367
+ // programUsesSafety(program) so they ONLY appear when the sketch actually
368
+ // references a safety construct — emitting them unconditionally (just because
369
+ // @typecad/safety is installed and registered its hook) leaks ~200 lines of
370
+ // polyfill into every sketch, and SafeInt's `return *this` chaining methods
371
+ // tripped byte-identity / lowering assertions that expect no `this` token.
372
+ // programUsesSafety walks the IR for any safety.* hal-op.
373
+ if (isEntryFile && hasSafetyHook() && programUsesSafety(program)) {
374
+ const safetyPolyfills = filterPolyfillHelpers(requireSafetyHook().buildPolyfills?.() ?? [], programAnalysis.usedPolyfillHelpers);
375
+ filteredNativePolyfills = [...filteredNativePolyfills, ...safetyPolyfills];
376
+ }
377
+ // Cooperative scheduler polyfill (Phase 0). Injected centrally when the
378
+ // strategy opts into priority/time-budget scheduling AND there is per-frame
379
+ // work to schedule (async tasks, the std::function microtask pump, or the
380
+ // cooperative timer pump). The polyfill carries only the no-STL CoopSched
381
+ // namespace; per-program trampoline registration is emitted by the function
382
+ // emitter around the driver's loop injection. STL-free so it links on
383
+ // minimal-libc targets (Zephyr) where the Promise runtime does not.
384
+ const coopConfig = strategy.getAsyncRuntimeConfig?.();
385
+ const hasCoopWork = program.functions.some(fn => fn.isAsync) ||
386
+ programAnalysis.usedPolyfillHelpers.has('__tc_setInterval') ||
387
+ programAnalysis.usedPolyfillHelpers.has('__tc_setTimeout');
388
+ if (isEntryFile && coopConfig && hasCoopWork) {
389
+ const coop = buildCoopSchedulerPolyfill(program, coopConfig, strategy.currentTimeMillis());
390
+ if (coop)
391
+ filteredNativePolyfills = [...filteredNativePolyfills, coop];
392
+ }
237
393
  const allPolyfills = filteredNativePolyfills;
238
394
  const emittedPolyfills = allPolyfills.length > 0
239
395
  ? emitPolyfillBoilerplate(allPolyfills)
@@ -243,23 +399,15 @@ export function buildEmitterContext(program, options) {
243
399
  if (!isNpmPackage) {
244
400
  includes.push(...strategy.forcedIncludes(program, options.platformContext));
245
401
  Object.assign(symbolMap, strategy.symbolAliases(program, options.platformContext));
246
- if (isEntryFile) {
247
- shimLines = [...strategy.shimLines(program, options.platformContext)];
248
- }
249
- else {
250
- // Non-entry files in split compilation: always emit the full shim
251
- // block. A class method body that uses `??` lowers to a
252
- // cuttlefish_nullish(...) call, but the helper lives in the entry
253
- // file's shim which isn't visible from this header. We used to gate
254
- // this on programAnalysis.usesNullish, but that flag is unreliable:
255
- // the analysis runs before the expression renderer, which can
256
- // introduce cuttlefish_nullish calls (e.g. for default-param
257
- // destructuring, or `??` inside class methods on abstract bases)
258
- // that the analysis pass didn't see, leaving the header referencing
259
- // an undeclared helper. The shim is fully idempotent (#ifndef
260
- // guards), so emitting it unconditionally is safe and cheap.
261
- shimLines = [...strategy.shimLines(program, options.platformContext)];
262
- }
402
+ // Both entry and non-entry files get the strategy's shim lines, then the
403
+ // Layer B filters below strip unused blocks based on programAnalysis. For
404
+ // non-entry (split-file) headers, the per-file pre-render analysis can miss
405
+ // renderer-introduced calls (e.g. cuttlefish_nullish from `??` lowering);
406
+ // output-finalizer.ts handles that case with a post-render text scan that
407
+ // re-injects the nullish helper shim into a header whose emitted lines
408
+ // actually contain a cuttlefish_nullish( call. So gating here is safe the
409
+ // post-render injection covers the one unreliable pre-render signal.
410
+ shimLines = [...strategy.shimLines(program, options.platformContext)];
263
411
  if (!programAnalysis.usesStringConversion) {
264
412
  shimLines = shimLines.filter(l => !l.includes('std::string String('));
265
413
  }
@@ -311,7 +459,9 @@ export function buildEmitterContext(program, options) {
311
459
  // these filters are no-ops there. The strategies also self-gate on the
312
460
  // same flags; this is the defensive backstop (mirrors how usesWDT/etc.
313
461
  // backstop the strategy-side gating above).
314
- if (!programAnalysis.usesUart) {
462
+ // Keep the UART block when console calls are present (console_log etc.
463
+ // call _uart_* functions) even if no direct uart.* HAL ops are used.
464
+ if (!programAnalysis.usesUart && !programAnalysis.hasConsoleCalls) {
315
465
  shimLines = filterShimBlock(shimLines, '// CUTTLEFISH_UART_BEGIN', '// CUTTLEFISH_UART_END');
316
466
  shimLines = filterShimBlock(shimLines, '// CUTTLEFISH_UART_EXT_BEGIN', '// CUTTLEFISH_UART_EXT_END');
317
467
  }
@@ -321,12 +471,69 @@ export function buildEmitterContext(program, options) {
321
471
  if (!programAnalysis.usesI2C) {
322
472
  shimLines = filterShimBlock(shimLines, '// CUTTLEFISH_TWI_BEGIN', '// CUTTLEFISH_TWI_END');
323
473
  }
324
- if (!programAnalysis.usesEEPROM) {
474
+ if (!programAnalysis.usesEEPROM && !programAnalysis.usesPreferences) {
325
475
  shimLines = filterShimBlock(shimLines, '// CUTTLEFISH_EEPROM_BEGIN', '// CUTTLEFISH_EEPROM_END');
326
476
  }
327
477
  if (!programAnalysis.usesTone) {
328
478
  shimLines = filterShimBlock(shimLines, '// CUTTLEFISH_TONE_BEGIN', '// CUTTLEFISH_TONE_END');
329
479
  }
480
+ // framework-esp32 native peripheral driver shims. Same defensive-backstop
481
+ // pattern as the UART/SPI/TWI/EEPROM/tone blocks above. framework-arduino's
482
+ // and framework-avr's shimLines contain none of these markers, so these
483
+ // filters are no-ops there.
484
+ if (!programAnalysis.usesGPIO) {
485
+ shimLines = filterShimBlock(shimLines, '// CUTTLEFISH_GPIO_BEGIN', '// CUTTLEFISH_GPIO_END');
486
+ }
487
+ if (!programAnalysis.usesPWM) {
488
+ shimLines = filterShimBlock(shimLines, '// CUTTLEFISH_PWM_BEGIN', '// CUTTLEFISH_PWM_END');
489
+ }
490
+ if (!programAnalysis.usesADC) {
491
+ shimLines = filterShimBlock(shimLines, '// CUTTLEFISH_ADC_BEGIN', '// CUTTLEFISH_ADC_END');
492
+ }
493
+ if (!programAnalysis.usesDAC) {
494
+ shimLines = filterShimBlock(shimLines, '// CUTTLEFISH_DAC_BEGIN', '// CUTTLEFISH_DAC_END');
495
+ }
496
+ if (!programAnalysis.usesPower) {
497
+ shimLines = filterShimBlock(shimLines, '// CUTTLEFISH_POWER_BEGIN', '// CUTTLEFISH_POWER_END');
498
+ }
499
+ if (!programAnalysis.usesWdt) {
500
+ shimLines = filterShimBlock(shimLines, '// CUTTLEFISH_WDT_BEGIN', '// CUTTLEFISH_WDT_END');
501
+ }
502
+ if (!programAnalysis.usesInterrupts) {
503
+ shimLines = filterShimBlock(shimLines, '// CUTTLEFISH_INTR_BEGIN', '// CUTTLEFISH_INTR_END');
504
+ }
505
+ if (!programAnalysis.usesPulse) {
506
+ shimLines = filterShimBlock(shimLines, '// CUTTLEFISH_PULSE_BEGIN', '// CUTTLEFISH_PULSE_END');
507
+ }
508
+ if (!programAnalysis.usesShift) {
509
+ shimLines = filterShimBlock(shimLines, '// CUTTLEFISH_SHIFT_BEGIN', '// CUTTLEFISH_SHIFT_END');
510
+ }
511
+ if (!programAnalysis.usesWifi) {
512
+ shimLines = filterShimBlock(shimLines, '// CUTTLEFISH_WIFI_BEGIN', '// CUTTLEFISH_WIFI_END');
513
+ }
514
+ else {
515
+ if (!programAnalysis.usesWifiConnect) {
516
+ shimLines = filterShimBlock(shimLines, '// CUTTLEFISH_WIFI_CONNECT_BEGIN', '// CUTTLEFISH_WIFI_CONNECT_END');
517
+ }
518
+ if (!programAnalysis.usesWifiConnectBlocking) {
519
+ shimLines = filterShimBlock(shimLines, '// CUTTLEFISH_WIFI_CONNECT_BLOCKING_BEGIN', '// CUTTLEFISH_WIFI_CONNECT_BLOCKING_END');
520
+ }
521
+ if (!programAnalysis.usesWifiQuery) {
522
+ shimLines = filterShimBlock(shimLines, '// CUTTLEFISH_WIFI_QUERY_BEGIN', '// CUTTLEFISH_WIFI_QUERY_END');
523
+ }
524
+ if (!programAnalysis.usesWifiScan) {
525
+ shimLines = filterShimBlock(shimLines, '// CUTTLEFISH_WIFI_SCAN_BEGIN', '// CUTTLEFISH_WIFI_SCAN_END');
526
+ }
527
+ if (!programAnalysis.usesWifiConfig) {
528
+ shimLines = filterShimBlock(shimLines, '// CUTTLEFISH_WIFI_CONFIG_BEGIN', '// CUTTLEFISH_WIFI_CONFIG_END');
529
+ }
530
+ }
531
+ if (!programAnalysis.usesHttp) {
532
+ shimLines = filterShimBlock(shimLines, '// CUTTLEFISH_HTTP_BEGIN', '// CUTTLEFISH_HTTP_END');
533
+ }
534
+ if (!programAnalysis.usesPreferences) {
535
+ shimLines = filterShimBlock(shimLines, '// CUTTLEFISH_PREFERENCES_BEGIN', '// CUTTLEFISH_PREFERENCES_END');
536
+ }
330
537
  profileDiagnostics = [...strategy.profileDiagnostics(program, options.platformContext)];
331
538
  }
332
539
  for (const imported of program.imports) {
@@ -362,11 +569,11 @@ export function buildEmitterContext(program, options) {
362
569
  symbolMap[defaultName] = defaultName;
363
570
  continue;
364
571
  }
365
- // Compile-time-only packages (@typecad/ui, @typecad/ui): their calls are
366
- // intercepted at IR-build time; the package emits NO C++ module/header.
367
- // Register the imported symbols so references resolve, but skip the
368
- // #include generation (there is no Ui.h to include).
369
- if (imported.moduleSpecifier === "@typecad/ui" || imported.moduleSpecifier === "@typecad/ui") {
572
+ // Compile-time-only packages: their calls are intercepted at IR-build
573
+ // time; the package emits NO C++ module/header. Register the imported
574
+ // symbols so references resolve, but skip the #include generation.
575
+ if (imported.moduleSpecifier === "@typecad/ui" ||
576
+ imported.moduleSpecifier === "@typecad/safety") {
370
577
  for (const symbol of imported.namedImports) {
371
578
  symbolMap[symbol] = symbol;
372
579
  }
@@ -719,6 +926,10 @@ export function buildEmitterContext(program, options) {
719
926
  knownTopLevelObjectTypes,
720
927
  diagnostics: emitDiagnostics,
721
928
  });
929
+ // Construct the compliance context early so it can be threaded into the
930
+ // renderers (StatementRenderer needs it for A3-9-1 fixed-width integer
931
+ // default). It's also returned in the EmitterContext at the end.
932
+ const compliance = new ComplianceContext(options.autosar ?? "off");
722
933
  const statementRenderer = new StatementRenderer({
723
934
  strategy,
724
935
  boardConstants: program.boardConstants,
@@ -737,6 +948,7 @@ export function buildEmitterContext(program, options) {
737
948
  interfaceFieldTypes,
738
949
  crossModuleClassNames: classNames,
739
950
  diagnostics: emitDiagnostics,
951
+ compliance,
740
952
  });
741
953
  const asyncFunctionOriginalNames = new Set(program.functions.filter((fn) => fn.isAsync).map((fn) => fn.originalName));
742
954
  const mapFunctionNameLocal = (originalName) => statementRenderer.mapFunctionName(originalName);
@@ -951,6 +1163,14 @@ export function buildEmitterContext(program, options) {
951
1163
  headerLines: ["#pragma once", ""],
952
1164
  sourceMapEntries: [],
953
1165
  headerMapEntries: [],
1166
+ // GDB debug mode: emit #line markers at appendSourceLine when 'gdb'.
1167
+ // Resolved once from strategy.debugMode(buildTarget); defaults to 'printf'
1168
+ // so all existing paths keep their pre-marker behavior.
1169
+ debugMode: (() => {
1170
+ const buildTarget = options.platformContext?.frameworkData?.buildTarget;
1171
+ return strategy.debugMode?.(buildTarget) ?? 'printf';
1172
+ })(),
1173
+ lastEmittedSource: null,
954
1174
  cArrayVarNames: new Set(),
955
1175
  fnCArrayVarNames: new Map(),
956
1176
  globalPointerVarTypes,
@@ -968,5 +1188,6 @@ export function buildEmitterContext(program, options) {
968
1188
  templateInterfaceNames,
969
1189
  interfaceNamespaceMap,
970
1190
  interfaceFieldTypes,
1191
+ compliance,
971
1192
  };
972
1193
  }
@@ -187,6 +187,12 @@ function collectCallbackFromExpression(expr, callbackFunctions, isrPrefix, count
187
187
  function collectCallbacks(statements, callbackFunctions, isrPrefix, counter) {
188
188
  for (const stmt of statements) {
189
189
  if (stmt.kind === "call") {
190
+ // __EXPR_STMT__ statements carry an expression IR (args[0]) that the
191
+ // statement renderer renders at EMIT time via the expression renderer
192
+ // (which handles lambdas inline via renderLambda). Do NOT hoist lambdas
193
+ // from these — they must stay inline to preserve closure captures.
194
+ if (stmt.callee === "__EXPR_STMT__")
195
+ continue;
190
196
  for (const arg of stmt.args) {
191
197
  collectCallbackFromExpression(arg, callbackFunctions, isrPrefix, counter);
192
198
  }
@@ -597,6 +603,8 @@ export function runTopLevelPreprocessing(ctx) {
597
603
  statements: callbackIR.statements ?? callbackIR.body ?? [],
598
604
  debounceMs: callbackIR.debounceMs,
599
605
  isInterruptHandler: callbackIR.isInterruptHandler,
606
+ ...(callbackIR.returnType ? { returnType: callbackIR.returnType } : {}),
607
+ ...(callbackIR.typedParams ? { typedParams: callbackIR.typedParams } : {}),
600
608
  });
601
609
  replacePlaceholderInAllStatements(filteredTopLevelExecutables, rc.placeholderName, callbackName);
602
610
  for (const fn of mappedFunctions) {
@@ -5,7 +5,27 @@ import { isStringEnum } from "../../api/shared/index.js";
5
5
  import { resolveEnumValues, narrowestEnumUnderlying } from "../utils/cpp-helpers.js";
6
6
  export function emitTypeDeclarations(ctx) {
7
7
  const { program, strategy, effectiveEmitMode, reservedNames, emittedTopLevelStatements, topLevelScope } = ctx;
8
- const normalizeCppTypeForTarget = (cppType) => strategy.normalizeCppType(cppType);
8
+ const normalizeCppTypeForTarget = (cppType) => {
9
+ // A3-9-1: resolve "auto" and substitute "int" with the fixed-width
10
+ // default — but ONLY when autosar is active. When off, fall through to
11
+ // the strategy's normalizeCppType (Arduino returns "auto" for "auto").
12
+ const autosarOn = ctx.compliance.isEnabled() && ctx.compliance.isBanned("A3-9-1");
13
+ if (autosarOn && (cppType === "auto" || cppType === "int")) {
14
+ return strategy.defaultNumericType(ctx.compliance);
15
+ }
16
+ // Also apply the int->int32_t substitution to the inner template argument
17
+ // of safety wrappers (SafeInt<int> -> SafeInt<int32_t>, SafeVariable<int>
18
+ // -> SafeVariable<int32_t>). The whole-type check above misses these
19
+ // because the full string is "Name<int>", not "int".
20
+ if (autosarOn) {
21
+ const wrapperMatch = cppType.match(/^(Safe(?:Int|Variable))<int>$/);
22
+ if (wrapperMatch) {
23
+ const fixedWidth = strategy.defaultNumericType(ctx.compliance);
24
+ return `${wrapperMatch[1]}<${fixedWidth}>`;
25
+ }
26
+ }
27
+ return strategy.normalizeCppType(cppType);
28
+ };
9
29
  // Split-mode header include + forward declarations
10
30
  if (effectiveEmitMode === "split") {
11
31
  appendSourceLine(ctx, `#include \"${ctx.baseName}.h\"`);
@@ -222,7 +242,12 @@ export function emitTypeDeclarations(ctx) {
222
242
  cppType = strategy.normalizeCppType(resolved);
223
243
  }
224
244
  const isConst = statement.storage === "const";
225
- const constPrefix = isConst ? "const " : "";
245
+ // A const-qualified top-level variable whose cppType already begins with
246
+ // `const` (e.g. a string-literal global lowered as `const char*`) would
247
+ // otherwise emit `extern const const char* X;` — a duplicate-const error.
248
+ // Don't prepend the storage qualifier when the type already carries it.
249
+ const typeAlreadyConst = cppType.trimStart().startsWith("const");
250
+ const constPrefix = isConst && !typeAlreadyConst ? "const " : "";
226
251
  const varName = escapeCppKeyword(statement.name, platformReservedNames);
227
252
  // Array-typed top-level consts (e.g. `export const ARR: T[] = [...]`)
228
253
  // lower with cppType "auto" and a `{ kind: "array", elementType }`
@@ -234,7 +259,7 @@ export function emitTypeDeclarations(ctx) {
234
259
  if (cppType === "auto" && statement.initializer && statement.initializer.kind === "array") {
235
260
  const elemType = statement.initializer.elementType && statement.initializer.elementType !== "auto"
236
261
  ? strategy.normalizeCppType(statement.initializer.elementType)
237
- : strategy.defaultNumericType();
262
+ : strategy.defaultNumericType(ctx.compliance.isEnabled() ? ctx.compliance : undefined);
238
263
  appendHeaderLine(ctx, `extern ${constPrefix}${elemType} ${varName}[];`);
239
264
  emitted = true;
240
265
  continue;
@@ -34,7 +34,7 @@ import { getRadioGroups } from "../../ir/ui-element-auto-wire.js";
34
34
  // minPressure gate is skipped for them. Resistive controllers (XPT2046,
35
35
  // STMPE610, Adafruit_TouchScreen) keep the gate.
36
36
  // ---------------------------------------------------------------------------
37
- const CAPACITIVE_TOUCH_LIBS = new Set(["FT6336U", "sdl"]);
37
+ const CAPACITIVE_TOUCH_LIBS = new Set(["FT6336U", "GT911", "CST816S", "sdl"]);
38
38
  /** Generate the ui_poll_touch() body, or null for the no-touch path. */
39
39
  export function generateTouchPollBody(input) {
40
40
  const { library, minPressure, calibration, profile } = input;
@@ -141,9 +141,14 @@ export function emitUIRuntime(ctx) {
141
141
  // display-adapter registry. Must precede the runtime header so the
142
142
  // adapter functions (__tc_display, display_init, etc.) are available.
143
143
  const profile = getDisplayProfile();
144
- // 0. SPI-bus display drivers (ILI9341, ST7796, …) need the SPI library.
145
- // Host render targets (sdl, native-preview) have no SPI bus, so skip it.
146
- const spiDriver = profile?.driver !== "sdl" && profile?.driver !== "native-preview";
144
+ // 0. SPI-bus display drivers (ILI9341, ST7796, …) need the Arduino SPI
145
+ // library but ONLY on the Adafruit path. Native adapters (AVR, ESP32)
146
+ // emit their own bus setup and would break on <SPI.h>. Host render targets
147
+ // (sdl, native-preview) have no SPI bus at all.
148
+ const nativeAdapter = ctx.strategy?.providesDisplayAdapter?.() ?? false;
149
+ const spiDriver = profile?.driver !== "sdl"
150
+ && profile?.driver !== "native-preview"
151
+ && !nativeAdapter;
147
152
  if (spiDriver && !ctx.includes.includes("<SPI.h>")) {
148
153
  ctx.includes.push("<SPI.h>");
149
154
  }
@@ -151,7 +156,7 @@ export function emitUIRuntime(ctx) {
151
156
  // buildEmitterContext (setup.ts), NOT here — emitPreamble runs before this
152
157
  // function, so a push here would be too late to land in the output.
153
158
  if (profile) {
154
- const adapter = generateDisplayAdapter(profile);
159
+ const adapter = generateDisplayAdapter(profile, ctx.strategy);
155
160
  // Prepend includes to the very front — Arduino's auto-prototyper scans
156
161
  // the whole .ino and generates prototypes that reference GFXcanvas16
157
162
  // etc. before any #include, so the GFX header must come first.
@@ -164,6 +169,23 @@ export function emitUIRuntime(ctx) {
164
169
  ctx.sourceLines.push(is888
165
170
  ? "#define UI_COLOR_DEPTH 888\n#define UI_COLOR_T uint32_t\n#define UI_DIM_MASK 0x7F7F7Fu"
166
171
  : "#define UI_COLOR_DEPTH 565\n#define UI_COLOR_T uint16_t\n#define UI_DIM_MASK 0x7BEFu");
172
+ // The native CuttlefishGFX/CuttlefishCanvas16 class slice is emitted ONLY
173
+ // for adapters that instantiate CuttlefishGFX by value (the planned
174
+ // framework-avr/framework-esp32 native panel drivers). Adapters that alias
175
+ // the token via macro — the Adafruit path (`#define CuttlefishCanvas16
176
+ // GFXcanvas16`) and the SDL path (`#define CuttlefishCanvas16 SdlGfxCanvas`)
177
+ // — own the canvas type; emitting the class slice alongside the macro makes
178
+ // `class CuttlefishCanvas16` macro-expand into a redefinition of Adafruit's
179
+ // GFXcanvas16. Detect the macro-alias path from the adapter's own includes
180
+ // and suppress the slice there. The previous gate reused
181
+ // providesDisplayAdapter(), which merely means "the strategy owns its
182
+ // adapters" (true for Arduino/Adafruit) and is unrelated to whether the
183
+ // native GFX class is wanted — it wrongly emitted the slice on every
184
+ // Arduino build, breaking compilation.
185
+ const macroAliasesCanvas16 = /^\s*#\s*define\s+CuttlefishCanvas16\b/m.test(adapter.includes);
186
+ if (!macroAliasesCanvas16) {
187
+ ctx.sourceLines.push(ui.emitCuttlefishGfx(true));
188
+ }
167
189
  ctx.sourceLines.push(adapter.declaration);
168
190
  ctx.sourceLines.push(adapter.functions);
169
191
  }
@@ -173,7 +195,7 @@ export function emitUIRuntime(ctx) {
173
195
  if (profile.touch) {
174
196
  const t = profile.touch;
175
197
  if (t.library) {
176
- touchAdapter = generateTouchAdapter(t);
198
+ touchAdapter = generateTouchAdapter(t, ctx.strategy);
177
199
  // Prepend includes to the front (Arduino auto-prototyper safety).
178
200
  ctx.sourceLines.unshift(touchAdapter.includes[0]);
179
201
  for (let i = 1; i < touchAdapter.includes.length; i++) {
@@ -252,13 +274,15 @@ export function emitUIRuntime(ctx) {
252
274
  // header so its #ifndef guards adopt them. Source of truth:
253
275
  // resolveScrollConfig(profile.scroll). Defaults derive from the declared
254
276
  // touch hardware, so the demo (XPT2046) gets resistive+full with no config.
255
- const scroll = resolveScrollConfig(profile, { buildTarget: profile._buildTarget });
256
- ctx.sourceLines.push(`#define UI_SCROLL_MAX_OVERSCROLL ${scroll.maxOverscroll}`, `#define UI_SCROLL_STIFFNESS_X10 ${Math.round(scroll.stiffness * 10)}`, `#define UI_SCROLL_EDGE_SNAP_PX ${scroll.edgeSnapPx}`, `#define UI_SCROLL_DRAG_SCALE_X10 ${Math.round(scroll.dragScale * 10)}`, `#define UI_SCROLL_INPUT_TIER_CAPACITIVE ${scroll.inputTier === "capacitive" ? 1 : 0}`, `#define UI_SCROLL_INPUT_TIER_RESISTIVE ${scroll.inputTier === "resistive" ? 1 : 0}`, `#define UI_SCROLL_INPUT_TIER_NONE ${scroll.inputTier === "none" ? 1 : 0}`, `#define UI_SCROLL_RENDER_TIER_FULL ${scroll.renderTier === "full" ? 1 : 0}`, `#define UI_SCROLL_RENDER_TIER_CONSTRAINED ${scroll.renderTier === "constrained" ? 1 : 0}`, `#define UI_SCROLL_CANVAS_BUDGET_BYTES ${scroll.scrollCanvasBudgetBytes}`, ...(scroll.debug ? [`#define UI_SCROLL_DEBUG 1`] : []));
277
+ const scroll = resolveScrollConfig(profile);
278
+ ctx.sourceLines.push(`#define UI_SCROLL_MAX_OVERSCROLL ${scroll.maxOverscroll}`, `#define UI_SCROLL_STIFFNESS_X10 ${Math.round(scroll.stiffness * 10)}`, `#define UI_SCROLL_EDGE_SNAP_PX ${scroll.edgeSnapPx}`, `#define UI_SCROLL_DRAG_SCALE_X10 ${Math.round(scroll.dragScale * 10)}`, `#define UI_SCROLL_INPUT_TIER_CAPACITIVE ${scroll.inputTier === "capacitive" ? 1 : 0}`, `#define UI_SCROLL_INPUT_TIER_RESISTIVE ${scroll.inputTier === "resistive" ? 1 : 0}`, `#define UI_SCROLL_INPUT_TIER_NONE ${scroll.inputTier === "none" ? 1 : 0}`, `#define UI_SCROLL_RENDER_TIER_FULL ${scroll.renderTier === "full" ? 1 : 0}`, `#define UI_SCROLL_RENDER_TIER_CONSTRAINED ${scroll.renderTier === "constrained" ? 1 : 0}`, ...(scroll.debug ? [`#define UI_SCROLL_DEBUG 1`] : []));
257
279
  // Forward-declare __ui_kb_set_onchange before the runtime header: the
258
280
  // header's keyboard-open function calls it, but the definition is emitted
259
281
  // later (section 8b). On native (single TU) this must precede the header.
260
282
  ctx.sourceLines.push(`void __ui_kb_set_onchange();`);
261
- ctx.sourceLines.push(emitRuntimeHeader());
283
+ ctx.sourceLines.push(emitRuntimeHeader({
284
+ nativeDisplayActive: ctx.strategy?.providesDisplayAdapter?.() ?? false,
285
+ }));
262
286
  // 1.5. Touch poll function (uses the adapter pattern). Body is generated by
263
287
  // generateTouchPollBody — extracted for unit-testability of the capacitive
264
288
  // vs resistive branch (FT6336U/SDL skip the minPressure gate).
@@ -88,7 +88,7 @@ export declare class ExpressionRenderer {
88
88
  private readonly stringEnumNames;
89
89
  private readonly largeEnumNames;
90
90
  private readonly knownFunctionReturnTypes?;
91
- private readonly knownVariableTypes?;
91
+ private knownVariableTypes?;
92
92
  private readonly pointerVarTypes?;
93
93
  private readonly globalPointerVarTypes?;
94
94
  private readonly stringVarNames?;