@typecad/cuttlefish 0.1.0-alpha.1

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 (377) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +79 -0
  3. package/dist/api/board-types.d.ts +1 -0
  4. package/dist/api/board-types.js +4 -0
  5. package/dist/api/capabilities.d.ts +12 -0
  6. package/dist/api/capabilities.js +1 -0
  7. package/dist/api/config.d.ts +120 -0
  8. package/dist/api/config.js +7 -0
  9. package/dist/api/index.d.ts +5 -0
  10. package/dist/api/index.js +2 -0
  11. package/dist/api/schema/builder.d.ts +14 -0
  12. package/dist/api/schema/builder.js +15 -0
  13. package/dist/api/schema/index.d.ts +2 -0
  14. package/dist/api/schema/index.js +1 -0
  15. package/dist/api/schema/types.d.ts +257 -0
  16. package/dist/api/schema/types.js +4 -0
  17. package/dist/api/shared/async-runtime-static.d.ts +8 -0
  18. package/dist/api/shared/async-runtime-static.js +201 -0
  19. package/dist/api/shared/async-types.d.ts +42 -0
  20. package/dist/api/shared/async-types.js +8 -0
  21. package/dist/api/shared/board-resolver.d.ts +12 -0
  22. package/dist/api/shared/board-resolver.js +7 -0
  23. package/dist/api/shared/cpp-type-ir.d.ts +229 -0
  24. package/dist/api/shared/cpp-type-ir.js +672 -0
  25. package/dist/api/shared/display-adapter.d.ts +12 -0
  26. package/dist/api/shared/display-adapter.js +145 -0
  27. package/dist/api/shared/display-adapters/eink-mono.d.ts +2 -0
  28. package/dist/api/shared/display-adapters/eink-mono.js +53 -0
  29. package/dist/api/shared/display-adapters/sdl.d.ts +2 -0
  30. package/dist/api/shared/display-adapters/sdl.js +452 -0
  31. package/dist/api/shared/display-adapters/ssd1309.d.ts +2 -0
  32. package/dist/api/shared/display-adapters/ssd1309.js +136 -0
  33. package/dist/api/shared/display-adapters/st7796.d.ts +2 -0
  34. package/dist/api/shared/display-adapters/st7796.js +132 -0
  35. package/dist/api/shared/display-capabilities.d.ts +45 -0
  36. package/dist/api/shared/display-capabilities.js +54 -0
  37. package/dist/api/shared/display-op-ir.d.ts +62 -0
  38. package/dist/api/shared/display-op-ir.js +19 -0
  39. package/dist/api/shared/display-profile.d.ts +265 -0
  40. package/dist/api/shared/display-profile.js +338 -0
  41. package/dist/api/shared/graphics-strategy.d.ts +29 -0
  42. package/dist/api/shared/graphics-strategy.js +11 -0
  43. package/dist/api/shared/hal-op-ir.d.ts +393 -0
  44. package/dist/api/shared/hal-op-ir.js +18 -0
  45. package/dist/api/shared/index.d.ts +26 -0
  46. package/dist/api/shared/index.js +21 -0
  47. package/dist/api/shared/ir-core.d.ts +363 -0
  48. package/dist/api/shared/ir-core.js +8 -0
  49. package/dist/api/shared/ir-declarations.d.ts +201 -0
  50. package/dist/api/shared/ir-declarations.js +26 -0
  51. package/dist/api/shared/ir.d.ts +85 -0
  52. package/dist/api/shared/ir.js +13 -0
  53. package/dist/api/shared/platform-strategy.d.ts +402 -0
  54. package/dist/api/shared/platform-strategy.js +14 -0
  55. package/dist/api/shared/polyfill-helper-registry.d.ts +11 -0
  56. package/dist/api/shared/polyfill-helper-registry.js +86 -0
  57. package/dist/api/shared/polyfill-types.d.ts +33 -0
  58. package/dist/api/shared/polyfill-types.js +76 -0
  59. package/dist/api/shared/promise-runtime.d.ts +10 -0
  60. package/dist/api/shared/promise-runtime.js +244 -0
  61. package/dist/api/shared/snprintf-types.d.ts +29 -0
  62. package/dist/api/shared/snprintf-types.js +8 -0
  63. package/dist/api/shared/string-method-registry.d.ts +53 -0
  64. package/dist/api/shared/string-method-registry.js +168 -0
  65. package/dist/api/shared/toolchain-types.d.ts +63 -0
  66. package/dist/api/shared/toolchain-types.js +71 -0
  67. package/dist/api/shared/types.d.ts +50 -0
  68. package/dist/api/shared/types.js +6 -0
  69. package/dist/ast/parse.d.ts +2 -0
  70. package/dist/ast/parse.js +4 -0
  71. package/dist/cache.d.ts +26 -0
  72. package/dist/cache.js +95 -0
  73. package/dist/cli-utils.d.ts +37 -0
  74. package/dist/cli-utils.js +250 -0
  75. package/dist/cli.d.ts +2 -0
  76. package/dist/cli.js +635 -0
  77. package/dist/config-loader.d.ts +78 -0
  78. package/dist/config-loader.js +508 -0
  79. package/dist/config-schema.d.ts +233 -0
  80. package/dist/config-schema.js +83 -0
  81. package/dist/create/board-checklist.d.ts +2 -0
  82. package/dist/create/board-checklist.js +52 -0
  83. package/dist/create/board-codegen.d.ts +9 -0
  84. package/dist/create/board-codegen.js +238 -0
  85. package/dist/create/board-generators.d.ts +12 -0
  86. package/dist/create/board-generators.js +652 -0
  87. package/dist/create/board-spec.d.ts +640 -0
  88. package/dist/create/board-spec.js +215 -0
  89. package/dist/create/eslint-rules-template.d.ts +2 -0
  90. package/dist/create/eslint-rules-template.js +672 -0
  91. package/dist/create/index.d.ts +11 -0
  92. package/dist/create/index.js +8 -0
  93. package/dist/create/init-scaffold.d.ts +27 -0
  94. package/dist/create/init-scaffold.js +150 -0
  95. package/dist/create/init-templates.d.ts +24 -0
  96. package/dist/create/init-templates.js +379 -0
  97. package/dist/create/init-wizard.d.ts +8 -0
  98. package/dist/create/init-wizard.js +168 -0
  99. package/dist/debug/breakpoint-loader.d.ts +24 -0
  100. package/dist/debug/breakpoint-loader.js +137 -0
  101. package/dist/debug/index.d.ts +3 -0
  102. package/dist/debug/index.js +7 -0
  103. package/dist/debug/preprocessor.d.ts +9 -0
  104. package/dist/debug/preprocessor.js +214 -0
  105. package/dist/debug/types.d.ts +32 -0
  106. package/dist/debug/types.js +6 -0
  107. package/dist/diagnostics/diagnostics-report.d.ts +51 -0
  108. package/dist/diagnostics/diagnostics-report.js +333 -0
  109. package/dist/diagnostics/json-schema.d.ts +138 -0
  110. package/dist/diagnostics/json-schema.js +27 -0
  111. package/dist/diagnostics/md-writer.d.ts +10 -0
  112. package/dist/diagnostics/md-writer.js +336 -0
  113. package/dist/diagnostics/mermaid-builder.d.ts +65 -0
  114. package/dist/diagnostics/mermaid-builder.js +681 -0
  115. package/dist/emit/cpp-emitter.d.ts +6 -0
  116. package/dist/emit/cpp-emitter.js +48 -0
  117. package/dist/emit/emitters/class-emitter.d.ts +2 -0
  118. package/dist/emit/emitters/class-emitter.js +523 -0
  119. package/dist/emit/emitters/emitter-context.d.ts +174 -0
  120. package/dist/emit/emitters/emitter-context.js +1 -0
  121. package/dist/emit/emitters/entrypoint-synthesizer.d.ts +2 -0
  122. package/dist/emit/emitters/entrypoint-synthesizer.js +175 -0
  123. package/dist/emit/emitters/function-emitter-impl.d.ts +19 -0
  124. package/dist/emit/emitters/function-emitter-impl.js +428 -0
  125. package/dist/emit/emitters/line-appender.d.ts +15 -0
  126. package/dist/emit/emitters/line-appender.js +344 -0
  127. package/dist/emit/emitters/namespace-emitter.d.ts +2 -0
  128. package/dist/emit/emitters/namespace-emitter.js +324 -0
  129. package/dist/emit/emitters/output-finalizer.d.ts +4 -0
  130. package/dist/emit/emitters/output-finalizer.js +267 -0
  131. package/dist/emit/emitters/setup.d.ts +3 -0
  132. package/dist/emit/emitters/setup.js +851 -0
  133. package/dist/emit/emitters/top-level-prep.d.ts +2 -0
  134. package/dist/emit/emitters/top-level-prep.js +706 -0
  135. package/dist/emit/emitters/type-decl-emitter.d.ts +2 -0
  136. package/dist/emit/emitters/type-decl-emitter.js +251 -0
  137. package/dist/emit/emitters/ui-emitter.d.ts +21 -0
  138. package/dist/emit/emitters/ui-emitter.js +564 -0
  139. package/dist/emit/enum-emitter.d.ts +1 -0
  140. package/dist/emit/enum-emitter.js +1 -0
  141. package/dist/emit/expression-renderer.d.ts +283 -0
  142. package/dist/emit/expression-renderer.js +1477 -0
  143. package/dist/emit/native-helpers-emitter.d.ts +11 -0
  144. package/dist/emit/native-helpers-emitter.js +34 -0
  145. package/dist/emit/route-hal-op.d.ts +5 -0
  146. package/dist/emit/route-hal-op.js +13 -0
  147. package/dist/emit/snprintf-helpers.d.ts +17 -0
  148. package/dist/emit/snprintf-helpers.js +462 -0
  149. package/dist/emit/statement-renderer.d.ts +189 -0
  150. package/dist/emit/statement-renderer.js +948 -0
  151. package/dist/emit/utils/async-state-machine.d.ts +42 -0
  152. package/dist/emit/utils/async-state-machine.js +343 -0
  153. package/dist/emit/utils/comment-helpers.d.ts +20 -0
  154. package/dist/emit/utils/comment-helpers.js +31 -0
  155. package/dist/emit/utils/cpp-helpers.d.ts +47 -0
  156. package/dist/emit/utils/cpp-helpers.js +85 -0
  157. package/dist/emit/utils/include-resolver.d.ts +58 -0
  158. package/dist/emit/utils/include-resolver.js +155 -0
  159. package/dist/emit/utils/index.d.ts +8 -0
  160. package/dist/emit/utils/index.js +12 -0
  161. package/dist/emit/utils/type-inference.d.ts +159 -0
  162. package/dist/emit/utils/type-inference.js +559 -0
  163. package/dist/eslint-check.d.ts +10 -0
  164. package/dist/eslint-check.js +102 -0
  165. package/dist/framework-package.d.ts +10 -0
  166. package/dist/framework-package.js +58 -0
  167. package/dist/framework-registry.d.ts +39 -0
  168. package/dist/framework-registry.js +30 -0
  169. package/dist/incremental-cache.d.ts +116 -0
  170. package/dist/incremental-cache.js +335 -0
  171. package/dist/ir/adc-range-validation.d.ts +11 -0
  172. package/dist/ir/adc-range-validation.js +250 -0
  173. package/dist/ir/ast-node-utils.d.ts +8 -0
  174. package/dist/ir/ast-node-utils.js +32 -0
  175. package/dist/ir/board-pin-utils.d.ts +13 -0
  176. package/dist/ir/board-pin-utils.js +65 -0
  177. package/dist/ir/board-resolver.d.ts +36 -0
  178. package/dist/ir/board-resolver.js +437 -0
  179. package/dist/ir/build-ir-state.d.ts +167 -0
  180. package/dist/ir/build-ir-state.js +306 -0
  181. package/dist/ir/build-ir.d.ts +2 -0
  182. package/dist/ir/build-ir.js +808 -0
  183. package/dist/ir/call-graph.d.ts +35 -0
  184. package/dist/ir/call-graph.js +194 -0
  185. package/dist/ir/compile-time-only.d.ts +2 -0
  186. package/dist/ir/compile-time-only.js +16 -0
  187. package/dist/ir/declaration-builders.d.ts +9 -0
  188. package/dist/ir/declaration-builders.js +608 -0
  189. package/dist/ir/entry-points.d.ts +30 -0
  190. package/dist/ir/entry-points.js +191 -0
  191. package/dist/ir/expression-to-ir.d.ts +5 -0
  192. package/dist/ir/expression-to-ir.js +2249 -0
  193. package/dist/ir/extract-property-chain.d.ts +10 -0
  194. package/dist/ir/extract-property-chain.js +30 -0
  195. package/dist/ir/feature-prescan.d.ts +3 -0
  196. package/dist/ir/feature-prescan.js +43 -0
  197. package/dist/ir/feature-registry.d.ts +30 -0
  198. package/dist/ir/feature-registry.js +816 -0
  199. package/dist/ir/filter.d.ts +7 -0
  200. package/dist/ir/filter.js +85 -0
  201. package/dist/ir/function-builder.d.ts +19 -0
  202. package/dist/ir/function-builder.js +670 -0
  203. package/dist/ir/hal/hal-emitter.d.ts +62 -0
  204. package/dist/ir/hal/hal-emitter.js +735 -0
  205. package/dist/ir/hal/hal-parser.d.ts +61 -0
  206. package/dist/ir/hal/hal-parser.js +473 -0
  207. package/dist/ir/hal/hal-plugins.d.ts +34 -0
  208. package/dist/ir/hal/hal-plugins.js +706 -0
  209. package/dist/ir/hal-resolver.d.ts +5 -0
  210. package/dist/ir/hal-resolver.js +5 -0
  211. package/dist/ir/heap-analysis.d.ts +8 -0
  212. package/dist/ir/heap-analysis.js +350 -0
  213. package/dist/ir/heap-array-validation.d.ts +24 -0
  214. package/dist/ir/heap-array-validation.js +29 -0
  215. package/dist/ir/identifier-collector.d.ts +18 -0
  216. package/dist/ir/identifier-collector.js +439 -0
  217. package/dist/ir/interrupt-analysis.d.ts +39 -0
  218. package/dist/ir/interrupt-analysis.js +467 -0
  219. package/dist/ir/memory-budget-validation.d.ts +10 -0
  220. package/dist/ir/memory-budget-validation.js +86 -0
  221. package/dist/ir/namespace-builder.d.ts +7 -0
  222. package/dist/ir/namespace-builder.js +152 -0
  223. package/dist/ir/ownership-analysis.d.ts +9 -0
  224. package/dist/ir/ownership-analysis.js +1207 -0
  225. package/dist/ir/peripheral-ownership.d.ts +3 -0
  226. package/dist/ir/peripheral-ownership.js +152 -0
  227. package/dist/ir/peripheral-symbols.d.ts +7 -0
  228. package/dist/ir/peripheral-symbols.js +57 -0
  229. package/dist/ir/peripheral-usage.d.ts +54 -0
  230. package/dist/ir/peripheral-usage.js +691 -0
  231. package/dist/ir/peripheral-validation.d.ts +8 -0
  232. package/dist/ir/peripheral-validation.js +77 -0
  233. package/dist/ir/pin-alias-conflict.d.ts +4 -0
  234. package/dist/ir/pin-alias-conflict.js +34 -0
  235. package/dist/ir/pin-capability-validation.d.ts +6 -0
  236. package/dist/ir/pin-capability-validation.js +413 -0
  237. package/dist/ir/pin-mode-validation.d.ts +10 -0
  238. package/dist/ir/pin-mode-validation.js +301 -0
  239. package/dist/ir/pin-safety.d.ts +11 -0
  240. package/dist/ir/pin-safety.js +58 -0
  241. package/dist/ir/program-analysis.d.ts +44 -0
  242. package/dist/ir/program-analysis.js +589 -0
  243. package/dist/ir/pulldown-validation.d.ts +7 -0
  244. package/dist/ir/pulldown-validation.js +49 -0
  245. package/dist/ir/pwm-timer-sharing.d.ts +4 -0
  246. package/dist/ir/pwm-timer-sharing.js +93 -0
  247. package/dist/ir/reachability.d.ts +68 -0
  248. package/dist/ir/reachability.js +224 -0
  249. package/dist/ir/register-decorators.d.ts +6 -0
  250. package/dist/ir/register-decorators.js +49 -0
  251. package/dist/ir/render-expr.d.ts +4 -0
  252. package/dist/ir/render-expr.js +127 -0
  253. package/dist/ir/resource-analysis.d.ts +19 -0
  254. package/dist/ir/resource-analysis.js +153 -0
  255. package/dist/ir/statement-to-ir.d.ts +23 -0
  256. package/dist/ir/statement-to-ir.js +349 -0
  257. package/dist/ir/symbol-table.d.ts +68 -0
  258. package/dist/ir/symbol-table.js +179 -0
  259. package/dist/ir/symbol-types.d.ts +56 -0
  260. package/dist/ir/symbol-types.js +107 -0
  261. package/dist/ir/timer0-pwm-timing-conflict.d.ts +4 -0
  262. package/dist/ir/timer0-pwm-timing-conflict.js +71 -0
  263. package/dist/ir/timing-validation.d.ts +7 -0
  264. package/dist/ir/timing-validation.js +95 -0
  265. package/dist/ir/transformers/array-methods.d.ts +8 -0
  266. package/dist/ir/transformers/array-methods.js +493 -0
  267. package/dist/ir/transformers/call-statement.d.ts +5 -0
  268. package/dist/ir/transformers/call-statement.js +758 -0
  269. package/dist/ir/transformers/callback-context-registry.d.ts +20 -0
  270. package/dist/ir/transformers/callback-context-registry.js +55 -0
  271. package/dist/ir/transformers/canvas-lowering.d.ts +42 -0
  272. package/dist/ir/transformers/canvas-lowering.js +249 -0
  273. package/dist/ir/transformers/control-flow.d.ts +8 -0
  274. package/dist/ir/transformers/control-flow.js +508 -0
  275. package/dist/ir/transformers/expressions.d.ts +7 -0
  276. package/dist/ir/transformers/expressions.js +406 -0
  277. package/dist/ir/transformers/hal-call-resolver.d.ts +29 -0
  278. package/dist/ir/transformers/hal-call-resolver.js +274 -0
  279. package/dist/ir/transformers/hal-emit-helpers.d.ts +14 -0
  280. package/dist/ir/transformers/hal-emit-helpers.js +63 -0
  281. package/dist/ir/transformers/namespace-methods.d.ts +20 -0
  282. package/dist/ir/transformers/namespace-methods.js +110 -0
  283. package/dist/ir/transformers/register-assignment.d.ts +5 -0
  284. package/dist/ir/transformers/register-assignment.js +56 -0
  285. package/dist/ir/transformers/ui-call-resolver.d.ts +149 -0
  286. package/dist/ir/transformers/ui-call-resolver.js +1136 -0
  287. package/dist/ir/transformers/ui-callback-lowering.d.ts +62 -0
  288. package/dist/ir/transformers/ui-callback-lowering.js +623 -0
  289. package/dist/ir/transformers/ui-mount.d.ts +20 -0
  290. package/dist/ir/transformers/ui-mount.js +35 -0
  291. package/dist/ir/transformers/ui-reactive.d.ts +68 -0
  292. package/dist/ir/transformers/ui-reactive.js +129 -0
  293. package/dist/ir/transformers/variables.d.ts +14 -0
  294. package/dist/ir/transformers/variables.js +1045 -0
  295. package/dist/ir/try-catch-validation.d.ts +26 -0
  296. package/dist/ir/try-catch-validation.js +128 -0
  297. package/dist/ir/type-resolution.d.ts +31 -0
  298. package/dist/ir/type-resolution.js +977 -0
  299. package/dist/ir/ui-element-auto-wire.d.ts +50 -0
  300. package/dist/ir/ui-element-auto-wire.js +218 -0
  301. package/dist/ir/unit-suspicion-validation.d.ts +12 -0
  302. package/dist/ir/unit-suspicion-validation.js +296 -0
  303. package/dist/ir/utils/walk-ir.d.ts +6 -0
  304. package/dist/ir/utils/walk-ir.js +162 -0
  305. package/dist/ir/validation-orchestrator.d.ts +4 -0
  306. package/dist/ir/validation-orchestrator.js +45 -0
  307. package/dist/libdef/base-class-resolver.d.ts +23 -0
  308. package/dist/libdef/base-class-resolver.js +50 -0
  309. package/dist/libdef/cpp-to-decl.d.ts +34 -0
  310. package/dist/libdef/cpp-to-decl.js +584 -0
  311. package/dist/libdef/header-parser.d.ts +53 -0
  312. package/dist/libdef/header-parser.js +269 -0
  313. package/dist/libdef/registry.d.ts +10 -0
  314. package/dist/libdef/registry.js +142 -0
  315. package/dist/mapping/peripheral-names.d.ts +23 -0
  316. package/dist/mapping/peripheral-names.js +63 -0
  317. package/dist/mapping/source-map.d.ts +46 -0
  318. package/dist/mapping/source-map.js +207 -0
  319. package/dist/orchestrator/dts-generator.d.ts +17 -0
  320. package/dist/orchestrator/dts-generator.js +83 -0
  321. package/dist/orchestrator/graph-builder.d.ts +18 -0
  322. package/dist/orchestrator/graph-builder.js +218 -0
  323. package/dist/orchestrator/semantic-facts-verifier.d.ts +38 -0
  324. package/dist/orchestrator/semantic-facts-verifier.js +121 -0
  325. package/dist/orchestrator/semantic-facts.d.ts +141 -0
  326. package/dist/orchestrator/semantic-facts.js +652 -0
  327. package/dist/orchestrator/type-checker.d.ts +39 -0
  328. package/dist/orchestrator/type-checker.js +760 -0
  329. package/dist/platform/async-runtime.d.ts +8 -0
  330. package/dist/platform/async-runtime.js +26 -0
  331. package/dist/platform/generic-strategy.d.ts +101 -0
  332. package/dist/platform/generic-strategy.js +289 -0
  333. package/dist/platform/index.d.ts +4 -0
  334. package/dist/platform/index.js +9 -0
  335. package/dist/platform/registry.d.ts +21 -0
  336. package/dist/platform/registry.js +42 -0
  337. package/dist/platform/toolchain.d.ts +4 -0
  338. package/dist/platform/toolchain.js +43 -0
  339. package/dist/preview/client.d.ts +1 -0
  340. package/dist/preview/client.js +137 -0
  341. package/dist/preview/server.d.ts +5 -0
  342. package/dist/preview/server.js +199 -0
  343. package/dist/profiler/index.d.ts +28 -0
  344. package/dist/profiler/index.js +28 -0
  345. package/dist/profiler/profiler.d.ts +95 -0
  346. package/dist/profiler/profiler.js +338 -0
  347. package/dist/profiler/types.d.ts +87 -0
  348. package/dist/profiler/types.js +12 -0
  349. package/dist/stores/display-profile-store.d.ts +16 -0
  350. package/dist/stores/display-profile-store.js +48 -0
  351. package/dist/stores/theme-store.d.ts +13 -0
  352. package/dist/stores/theme-store.js +30 -0
  353. package/dist/testing.d.ts +45 -0
  354. package/dist/testing.js +47 -0
  355. package/dist/transpile/resolution.d.ts +29 -0
  356. package/dist/transpile/resolution.js +282 -0
  357. package/dist/transpile.d.ts +3 -0
  358. package/dist/transpile.js +722 -0
  359. package/dist/types.d.ts +217 -0
  360. package/dist/types.js +1 -0
  361. package/dist/ui/ui-bridge.d.ts +4 -0
  362. package/dist/ui/ui-bridge.js +34 -0
  363. package/dist/ui-hook.d.ts +84 -0
  364. package/dist/ui-hook.js +45 -0
  365. package/dist/utils/cli.d.ts +3 -0
  366. package/dist/utils/cli.js +463 -0
  367. package/dist/utils/fs.d.ts +4 -0
  368. package/dist/utils/fs.js +23 -0
  369. package/dist/utils/logger.d.ts +2 -0
  370. package/dist/utils/logger.js +8 -0
  371. package/dist/utils/strings.d.ts +35 -0
  372. package/dist/utils/strings.js +142 -0
  373. package/dist/utils/ui.d.ts +66 -0
  374. package/dist/utils/ui.js +149 -0
  375. package/dist/watch.d.ts +35 -0
  376. package/dist/watch.js +111 -0
  377. package/package.json +127 -0
@@ -0,0 +1,402 @@
1
+ import type { ExpressionIR, ProgramIR } from './ir.js';
2
+ import type { HALOpIR } from './hal-op-ir.js';
3
+ import type { Diagnostic, PlatformContext } from './types.js';
4
+ import type { BoardConstants } from './board-resolver.js';
5
+ import type { AsyncRuntimeConfig } from './async-types.js';
6
+ import type { RuntimePolyfillIR, StdLibSupport } from './polyfill-types.js';
7
+ import type { PlatformGraphicsStrategy } from './graphics-strategy.js';
8
+ export interface PlatformProfileStrategy {
9
+ /** System #include headers forced at the top of every emitted file. */
10
+ forcedIncludes(program: ProgramIR, ctx?: PlatformContext): string[];
11
+ /** Symbol aliases (TypeScript name → C++ name). */
12
+ symbolAliases(program: ProgramIR, ctx?: PlatformContext): Record<string, string>;
13
+ /** Extra shim lines emitted after includes (e.g. #define fallbacks). */
14
+ shimLines(program: ProgramIR, ctx?: PlatformContext): string[];
15
+ /** Diagnostics produced during profile resolution. */
16
+ profileDiagnostics(program: ProgramIR, ctx?: PlatformContext): Diagnostic[];
17
+ /** Extension for the output source file ("ino", "cpp", "c"). */
18
+ sourceExtension(isEntryFile: boolean, isNpmPackage: boolean): string;
19
+ /**
20
+ * Returns code to insert at the beginning of setup()/main().
21
+ * Used for platform-specific initialization (e.g., UART init for native console).
22
+ */
23
+ setupInitCode?(program: ProgramIR, ctx?: PlatformContext): string[];
24
+ /** Name of the entrypoint function ("setup" for embedded, "main" for hosted). */
25
+ entrypointFunctionName(): string;
26
+ /** Whether a no-arg loop function must be auto-generated (embedded targets need loop()). */
27
+ requiresLoopFunction(): boolean;
28
+ /** Base name override for the output file (some targets use the output dir name). */
29
+ overrideBaseName(originalBaseName: string, outDirBaseName: string, isEntryFile: boolean, isNpmPackage: boolean): string;
30
+ /** Effective emit mode – some targets force "cpp" regardless of user choice. */
31
+ effectiveEmitMode(requestedMode: string, isNpmPackage: boolean): string;
32
+ /** Whether <iostream> should be included (for std::cout). */
33
+ needsIostream(): boolean;
34
+ /** Whether <string> should be included. */
35
+ needsStdString(): boolean;
36
+ /** Whether <vector> should be included. */
37
+ needsStdVector(): boolean;
38
+ /** Whether <stdexcept> should be included. */
39
+ needsStdExcept(): boolean;
40
+ /** Whether <functional> should be included. */
41
+ needsStdFunction(): boolean;
42
+ /** Math header name ("<cmath>" or "<math.h>"). */
43
+ mathHeader(): string;
44
+ /** cstring header name ("<cstring>" on hosted, "<string.h>" on embedded/AVR). */
45
+ cstringHeader(): string;
46
+ /** Whether the vector operator<< overload should be emitted. */
47
+ needsVectorOverload(): boolean;
48
+ /** Whether a large enum needs an explicit underlying type. */
49
+ needsLargeEnumUnderlying(): boolean;
50
+ /** Whether to skip a type alias for this platform (e.g. std::string where unsupported). */
51
+ shouldSkipTypeAlias(cppType: string): boolean;
52
+ /** Extra diagnostics to add during emit. */
53
+ emitDiagnostics(emitMode: string): Diagnostic[];
54
+ /**
55
+ * Names of functions that must be excluded from forward declarations
56
+ * (e.g., entry points like setup/loop/main that the platform defines).
57
+ */
58
+ forwardDeclarationExclusions?(): string[];
59
+ /**
60
+ * Platform-specific ambient TypeScript type declarations appended to
61
+ * the generated cuttlefish-env.d.ts file.
62
+ * Return an empty array if no platform-specific declarations are needed.
63
+ */
64
+ ambientTypeDeclarations?(): string[];
65
+ }
66
+ export interface PlatformPolyfillStrategy {
67
+ /**
68
+ * Returns a set of polyfill IDs that this strategy handles natively.
69
+ * The emitter will skip emitting these polyfills from the global system.
70
+ */
71
+ nativePolyfills?(): Set<string>;
72
+ /**
73
+ * Returns polyfill IR for polyfills that this strategy provides natively.
74
+ */
75
+ generateNativePolyfills?(program: ProgramIR, ctx?: PlatformContext): RuntimePolyfillIR[];
76
+ }
77
+ export interface PlatformTypeStrategy {
78
+ /** Map a C++ type string to the platform-safe equivalent. */
79
+ normalizeCppType(typeName: string): string;
80
+ /** Return type to use for a named function (e.g. setup/loop → void). */
81
+ mapReturnType(functionName: string, returnType: string): string;
82
+ /** Whether a C++ type behaves like a string (needs .c_str() or is const char*). */
83
+ isStringLikeType(cppType: string): boolean;
84
+ /** Whether a C++ type is a pointer (needs -> instead of .). */
85
+ isPointerType(cppType: string): boolean;
86
+ /** Map a function name to the platform entrypoint (e.g. void/__cuttlefish_entrypoint__ → setup). */
87
+ mapFunctionName(originalName: string): string;
88
+ /**
89
+ * Prefix an enum member name if it conflicts with a platform macro.
90
+ * Return the original name if no rename is needed.
91
+ */
92
+ renameEnumMember(enumName: string, memberName: string): string;
93
+ /**
94
+ * Whether enum member access should be wrapped in static_cast<int/long>.
95
+ * Returns the cast type ("int", "long") or undefined for no cast.
96
+ */
97
+ enumCastType(enumName: string): string | undefined;
98
+ /**
99
+ * Enum names whose member access should render as bare C identifiers
100
+ * (no scoped prefix). For example, if "AnalogReference" is a passthrough
101
+ * enum, `AnalogReference.INTERNAL` renders as just `INTERNAL` — useful
102
+ * when the enum members map directly to platform preprocessor macros.
103
+ */
104
+ passthroughEnumNames?(): ReadonlySet<string>;
105
+ /** Default numeric type for the platform (e.g. "int" on hosted, "int32_t" on embedded). */
106
+ defaultNumericType(): string;
107
+ /**
108
+ * Inform the strategy which enums have values exceeding the signed 16-bit range.
109
+ * The strategy can use this to choose an appropriate underlying type.
110
+ */
111
+ setLargeEnumNames?(names: ReadonlySet<string>): void;
112
+ /** Rename a struct field if it conflicts with platform-reserved names. */
113
+ renameStructField(fieldName: string): string;
114
+ /**
115
+ * Override how a struct initializer field renders its value.
116
+ * Return undefined to use default rendering.
117
+ */
118
+ structFieldInitializer(fieldValue: ExpressionIR, compiletimeVarNames: Set<string>, renderExpr: (e: ExpressionIR) => string): string | undefined;
119
+ }
120
+ export interface PlatformExpressionStrategy {
121
+ /**
122
+ * Platform-specific normalisation of raw expression strings.
123
+ * Applied after the common === → == and !== → != transforms.
124
+ */
125
+ normalizeRawExpression(value: string): string;
126
+ /** How to render a null/undefined identifier value. */
127
+ nullValue(): string;
128
+ /** Whether string-literal + concatenation needs wrapping (e.g. String(...) on Arduino). */
129
+ wrapStringConcat(leftRendered: string, rightRendered: string, leftIsString: boolean): string | undefined;
130
+ /** Wrap an expression in the platform's string object type (e.g. String(...) on Arduino). */
131
+ wrapStringObject(expr: string): string;
132
+ /** Platform-specific expression for current time in milliseconds (e.g. "millis()" on Arduino, "std::chrono" on hosted). */
133
+ currentTimeMillis(): string;
134
+ /**
135
+ * Whether string concat / template interpolation should use snprintf()
136
+ * instead of platform string objects.
137
+ */
138
+ useSnprintfForStrings(): boolean;
139
+ /**
140
+ * Whether integer division should be promoted to double to match JavaScript
141
+ * semantics where 7 / 2 === 3.5.
142
+ */
143
+ promoteDivisionToDouble?(): boolean;
144
+ /**
145
+ * Convert a float expression to an snprintf-compatible argument.
146
+ * Return undefined to let the emitter use generic %g / %.Nf formatting.
147
+ */
148
+ floatToSnprintfArg?(renderedExpr: string, precision: number | undefined, tempId: number): {
149
+ format: string;
150
+ arg: string;
151
+ estimatedLength: number;
152
+ preludeLines: string[];
153
+ } | undefined;
154
+ /**
155
+ * Try to render a Board.definition.* property access.
156
+ * Return `undefined` to fall back to default rendering.
157
+ */
158
+ renderBoardDefinitionAccess(chain: string[], boardConstants?: BoardConstants): string | undefined;
159
+ /**
160
+ * Maps a generic peripheral name (e.g., I2C0, UART0) to a platform-specific C++ name (e.g., Wire, Serial).
161
+ * Returns undefined if the strategy does not recognize the name.
162
+ */
163
+ mapPeripheralIdentifier?(name: string): string | undefined;
164
+ /**
165
+ * Resolve the C++ type for a pin field on a board object (e.g., Pins.D2).
166
+ * Return `undefined` to use default type inference.
167
+ */
168
+ resolvePinType?(objectName: string, fieldName: string): string | undefined;
169
+ }
170
+ export interface PlatformStatementStrategy {
171
+ /**
172
+ * How to render a `throw` statement on this platform.
173
+ * Embedded targets without exception support may emit an infinite loop or halt.
174
+ */
175
+ renderThrow(valueExpr: string): string;
176
+ /**
177
+ * Transform console.log/error/warn calls to platform output.
178
+ */
179
+ isConsoleCall(callee: string): boolean;
180
+ /** Transform console.log/error/warn calls based on target platform. */
181
+ transformConsoleCall(method: string, renderedArgs: string, forHeader: boolean): string;
182
+ /**
183
+ * Transform console expressions that return values (e.g., console.readLine, console.readCharacter).
184
+ * Returns the C++ expression that evaluates to the result.
185
+ * Return undefined to fall back to default rendering.
186
+ */
187
+ transformConsoleExpression?(method: string, renderedArgs: string): string | undefined;
188
+ /**
189
+ * Fallback value for an object initializer field on this platform.
190
+ * Some targets use "0" for nested objects; hosted targets pass through.
191
+ */
192
+ objectFieldInitializer(fieldValue: ExpressionIR, renderExpr: (e: ExpressionIR) => string): string | undefined;
193
+ /**
194
+ * Override a class field type when platform-specific types differ.
195
+ * E.g. interrupt handlers may need function-pointer types on embedded targets.
196
+ */
197
+ overrideClassFieldType(fieldName: string, normalizedType: string): string;
198
+ /**
199
+ * Render a serial print/println call that uses a pre-formatted snprintf buffer.
200
+ * Called when a cuttlefish-call for a serial peripheral has a snprintf-formatted argument.
201
+ * Return `undefined` to use default method-call rendering.
202
+ */
203
+ renderSerialPrintWithSnprintf?(params: {
204
+ receiver: string;
205
+ method: string;
206
+ bufferName: string;
207
+ }): {
208
+ finalLine: string;
209
+ } | undefined;
210
+ /**
211
+ * Optional attribute prefix placed before ISR function declarations and
212
+ * definitions. Required on ESP32/Xtensa to place ISR code in IRAM so it
213
+ * can execute while flash is being accessed.
214
+ *
215
+ * Returns an empty string on platforms that do not need an attribute
216
+ * (e.g. AVR). Includes a trailing space when non-empty.
217
+ *
218
+ * Example: `"IRAM_ATTR "` (note the trailing space).
219
+ */
220
+ isrFunctionAttribute?(): string;
221
+ }
222
+ export interface PlatformSafetyStrategy {
223
+ /**
224
+ * Names that must not be re-declared because the platform already defines them
225
+ * (e.g. platform macros like HIGH, LOW, Serial, A0 on Arduino).
226
+ */
227
+ reservedNames(): ReadonlySet<string>;
228
+ /**
229
+ * Identifier names that are platform *value/function-like macros* (e.g.
230
+ * INPUT, OUTPUT, HIGH, LOW on Arduino) and therefore must pass through
231
+ * verbatim when referenced in an expression — they must NOT be escaped
232
+ * (suffixed with `_`) the way a conflicting declaration would be.
233
+ *
234
+ * These names typically also appear in `reservedNames()` (so user
235
+ * declarations with these names are still escaped), but a *reference* to
236
+ * such a macro should be emitted as-is.
237
+ */
238
+ passthroughMacroNames(): ReadonlySet<string>;
239
+ /**
240
+ * Enum class names already declared as typedefs by the platform framework.
241
+ * These get a `#if !defined(...)` guard in the emitted code.
242
+ */
243
+ apiReservedEnumNames(): ReadonlySet<string>;
244
+ /**
245
+ * The preprocessor guard expression for API-reserved enums
246
+ * (e.g. "ARDUINO_API_VERSION" on Arduino).
247
+ */
248
+ apiReservedEnumGuard(): string;
249
+ /**
250
+ * Operations that are unsafe to use inside interrupt handlers.
251
+ * Returns a map of operation name/prefix → { reason, severity }.
252
+ */
253
+ isrUnsafeOperations?(): Map<string, {
254
+ reason: string;
255
+ severity: 'warning' | 'info';
256
+ }>;
257
+ /**
258
+ * Whether heap allocation via `operator new` is unsafe on the given architecture.
259
+ * Frameworks return true for memory-constrained targets (e.g. AVR with 2 KB SRAM).
260
+ */
261
+ isHeapAllocationUnsafe?(architecture: string): boolean;
262
+ /**
263
+ * Whether C++ exceptions are disabled on the given architecture.
264
+ * Frameworks return true for targets compiled with -fno-exceptions (e.g. AVR-GCC).
265
+ */
266
+ isExceptionSupportDisabled?(architecture: string): boolean;
267
+ /**
268
+ * Whether an array literal (`const a: T[] = [...]`) lowers to a fixed-capacity
269
+ * `__tc_StaticArray<T, N>` (true) or a `std::vector<T>` (false). Embedded and
270
+ * generic targets return true (StaticArray avoids heap); the native/hosted
271
+ * target returns false (std::vector). Defaults to true. Used by the structural
272
+ * array-method lowering to decide whether `.push`/`.pop`/`.indexOf` emit the
273
+ * StaticArray wrapper's methods or the std::vector/__tc_* helper form.
274
+ */
275
+ promotesArrayLiteralsToStaticArray?(): boolean;
276
+ }
277
+ export interface PlatformBuildStrategy {
278
+ /** Queue capacity for the async microtask ring buffer. */
279
+ asyncQueueCapacity(): number;
280
+ /** Output subdirectory relative to base dir. */
281
+ outputSubdirectory(baseName: string): string;
282
+ /** Whether to generate a separate header file. */
283
+ generateHeaderFile(): boolean;
284
+ /**
285
+ * Preprocessor guard for API-reserved enums.
286
+ * Return undefined for no guard.
287
+ */
288
+ enumApiGuard(enumName: string): {
289
+ open: string;
290
+ close: string;
291
+ } | undefined;
292
+ /** Standard library support for the given architecture. */
293
+ getStdLibSupport(architecture?: string): StdLibSupport;
294
+ }
295
+ /**
296
+ * Debug code generation sub-interface.
297
+ * Frameworks implement these to provide platform-specific debug output
298
+ * (e.g., Serial.println on embedded, std::cout on hosted targets).
299
+ */
300
+ export interface PlatformDebugStrategy {
301
+ /** Generate initialization code for the debug subsystem. */
302
+ generateDebugInitCode?(): string[];
303
+ /** Generate code for a breakpoint with optional condition and variable dump. */
304
+ generateDebugBreakpointCode?(params: {
305
+ fileName: string;
306
+ lineNum: number;
307
+ originalLine: string;
308
+ variables: Array<{
309
+ name: string;
310
+ isFunction?: boolean;
311
+ }>;
312
+ normalizedCondition?: string;
313
+ }): string[];
314
+ /** Generate code for a logpoint with interpolated message parts. */
315
+ generateDebugLogpointCode?(params: {
316
+ fileName: string;
317
+ lineNum: number;
318
+ parts: Array<{
319
+ type: 'text' | 'variable';
320
+ value: string;
321
+ }>;
322
+ variables: Array<{
323
+ name: string;
324
+ isFunction?: boolean;
325
+ }>;
326
+ }): string[];
327
+ }
328
+ export interface PlatformAsyncStrategy {
329
+ /**
330
+ * Returns the async runtime configuration for this platform.
331
+ * The emitter uses this to decide:
332
+ * - Whether to include the MicrotaskQueue + Promise<T> runtime
333
+ * - How to implement waitForRising/waitForFalling
334
+ * - What headers to include
335
+ * - What queue capacity to use
336
+ */
337
+ getAsyncRuntimeConfig(): AsyncRuntimeConfig;
338
+ /**
339
+ * Lines to inject into the loop/run function body to drive async tasks.
340
+ */
341
+ asyncLoopInjection(taskVarNames: string[], config: AsyncRuntimeConfig): string[];
342
+ /**
343
+ * The function name where microtask pumping and async task driving happens.
344
+ * Embedded targets: "loop"; Hosted: "main".
345
+ */
346
+ asyncDriverFunctionName(): string;
347
+ /** Optional host event-loop scaffolding wrapping ui_tick in the driver
348
+ * function. Return null/undefined for single-shot (today's native behavior)
349
+ * or the Arduino repeatedly-called loop(). When provided, the emitter
350
+ * declares `flagName` as a bool, then wraps the per-frame work in
351
+ * `while (continueCondition) { preIteration; <tick>; postIteration; }`.
352
+ * Used by the SDL native target to pump SDL events and present each frame. */
353
+ hostEventLoop?(): {
354
+ flagName: string;
355
+ continueCondition: string;
356
+ preIteration: string;
357
+ postIteration: string;
358
+ } | null;
359
+ }
360
+ /**
361
+ * Strategy for resolving semantic HAL operations to framework-specific C++.
362
+ *
363
+ * When the transpiler encounters a HAL method call that has been resolved to
364
+ * a {@link HALOpIR} node, it calls {@link resolveHALOperation} so the
365
+ * framework can produce the correct C++ for the target platform.
366
+ *
367
+ * Returning `undefined` signals that the strategy does not handle the
368
+ * operation; the emitter will fall back to a default or raw emission.
369
+ */
370
+ export interface PlatformHALStrategy {
371
+ /**
372
+ * Resolve a HAL operation to C++ code.
373
+ *
374
+ * @param op The semantic hardware operation to translate.
375
+ * @returns An object with either `code` (for statements) or `expression`
376
+ * (for value-returning operations), or `undefined` to fall back.
377
+ */
378
+ resolveHALOperation?(op: HALOpIR): {
379
+ code?: string;
380
+ expression?: string;
381
+ } | undefined;
382
+ /**
383
+ * Whether this target models GPIO pins. Hardware targets (Arduino, AVR,
384
+ * ESP32) return true; host/desktop targets (SDL native) return false. Used to
385
+ * gate GPIO-dependent APIs (ui.watchPin, ui.press) — when false, those APIs
386
+ * produce a transpile-time diagnostic instead of emitting pinMode/
387
+ * attachInterrupt calls that would be undefined symbols or silent no-ops.
388
+ * Default true (preserves existing behavior for hardware strategies).
389
+ */
390
+ modelsGpio?(): boolean;
391
+ }
392
+ /**
393
+ * Full platform strategy composed from focused sub-interfaces.
394
+ *
395
+ * Existing implementations that implement PlatformStrategy automatically
396
+ * satisfy every sub-interface. New code that only needs a subset can accept
397
+ * e.g. `PlatformExpressionStrategy` instead of the full interface.
398
+ */
399
+ export interface PlatformStrategy extends PlatformProfileStrategy, PlatformPolyfillStrategy, PlatformTypeStrategy, PlatformExpressionStrategy, PlatformStatementStrategy, PlatformSafetyStrategy, PlatformBuildStrategy, PlatformDebugStrategy, PlatformAsyncStrategy, PlatformHALStrategy, PlatformGraphicsStrategy {
400
+ /** Unique identifier for this strategy (e.g. "arduino", "generic"). */
401
+ readonly id: string;
402
+ }
@@ -0,0 +1,14 @@
1
+ // ---------------------------------------------------------------------------
2
+ // PlatformStrategy — abstract interface for target-specific C++ emit decisions
3
+ //
4
+ // Framework packages provide concrete implementations (e.g. ArduinoStrategy,
5
+ // NativeStrategy) so the emitter stays target-agnostic. Each framework
6
+ // registers its strategy via the platform registry; the emitter calls methods
7
+ // on the interface without knowing which framework is active.
8
+ //
9
+ // The full interface is composed from focused sub-interfaces so that
10
+ // call-sites can accept a narrower type when they only need a subset of the
11
+ // strategy. All existing implementations automatically satisfy every sub-interface
12
+ // since they already implement the full PlatformStrategy.
13
+ // ---------------------------------------------------------------------------
14
+ export {};
@@ -0,0 +1,11 @@
1
+ import type { RuntimePolyfillIR } from './polyfill-types.js';
2
+ /**
3
+ * Maps a JS method call pattern (substring) to the __tc_* C++ helper
4
+ * function names that normalizeRawExpression will emit for it.
5
+ */
6
+ export declare const POLYFILL_HELPER_MAP: Record<string, string[]>;
7
+ /**
8
+ * Filter helper functions in RuntimePolyfillIR objects to only those
9
+ * whose names appear in the usedHelpers set. Non-__tc_ helpers are always kept.
10
+ */
11
+ export declare function filterPolyfillHelpers(polyfills: RuntimePolyfillIR[], usedHelpers: Set<string>): RuntimePolyfillIR[];
@@ -0,0 +1,86 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Polyfill helper registry
3
+ //
4
+ // Maps JS method call patterns to the __tc_* C++ helper function names
5
+ // that normalizeRawExpression produces. Used by program analysis to detect
6
+ // which polyfill helpers are actually needed by a program.
7
+ // ---------------------------------------------------------------------------
8
+ /**
9
+ * Maps a JS method call pattern (substring) to the __tc_* C++ helper
10
+ * function names that normalizeRawExpression will emit for it.
11
+ */
12
+ export const POLYFILL_HELPER_MAP = {
13
+ // String methods
14
+ '.toUpperCase(': ['__tc_toUpperCase'],
15
+ '.toLowerCase(': ['__tc_toLowerCase'],
16
+ '.trim(': ['__tc_trim'],
17
+ '.endsWith(': ['__tc_endsWith'],
18
+ '.lastIndexOf(': ['__tc_lastIndexOf'],
19
+ '.padStart(': ['__tc_padStart', '__tc_padStart_default'],
20
+ '.padEnd(': ['__tc_padEnd', '__tc_padEnd_default'],
21
+ '.repeat(': ['__tc_repeat'],
22
+ '.charAt(': ['__tc_charAt'],
23
+ '.charCodeAt(': ['__tc_charCodeAt'],
24
+ '.replace(': ['__tc_replace'],
25
+ '.split(': ['__tc_split'],
26
+ '.substring(': ['__tc_substring2', '__tc_substring1'],
27
+ '.includes(': ['__tc_includes'],
28
+ '.indexOf(': ['__tc_indexOf'],
29
+ '.slice(': ['__tc_slice2', '__tc_slice1'],
30
+ // Timer methods
31
+ 'setTimeout(': ['__tc_setTimeout'],
32
+ 'setInterval(': ['__tc_setInterval'],
33
+ 'clearTimeout(': ['__tc_clearTimeout'],
34
+ 'clearInterval(': ['__tc_clearInterval'],
35
+ // Math methods
36
+ 'Math.random(': ['__tc_random'],
37
+ // Array methods
38
+ '.join(': ['__tc_join'],
39
+ '.reverse(': ['__tc_reverse'],
40
+ '.shift(': ['__tc_shift'],
41
+ '.pop(': ['__tc_pop'],
42
+ '.unshift(': ['__tc_unshift'],
43
+ '.sort(': ['__tc_sort', '__tc_sort_fn'],
44
+ '.fill(': ['__tc_fill', '__tc_fill3'],
45
+ '.concat(': ['__tc_concat'],
46
+ '.splice(': ['__tc_splice1', '__tc_splice2'],
47
+ '.filter(': ['__tc_filter'],
48
+ '.map(': ['__tc_map'],
49
+ '.reduce(': ['__tc_reduce', '__tc_reduce_no_init'],
50
+ '.find(': ['__tc_find'],
51
+ '.findIndex(': ['__tc_findIndex'],
52
+ '.every(': ['__tc_every'],
53
+ '.some(': ['__tc_some'],
54
+ // Map helper methods (Object.keys/values/entries AND Map.values/keys/entries)
55
+ '__tc_mapKeys(': ['__tc_mapKeys'],
56
+ '__tc_mapValues(': ['__tc_mapValues'],
57
+ '__tc_mapEntries(': ['__tc_mapEntries'],
58
+ '__tc_fromEntries(': ['__tc_fromEntries'],
59
+ // Set helper methods (Set.values()/keys()/entries()) — demo #15 fix A
60
+ '__tc_setValues(': ['__tc_setValues'],
61
+ '__tc_setEntries(': ['__tc_setEntries'],
62
+ // JSON helpers
63
+ '__tc_jsonStringify(': ['__tc_jsonStringify'],
64
+ '__tc_jsonParse(': ['__tc_jsonParse'],
65
+ };
66
+ function extractHelperFunctionNames(funcDef) {
67
+ const matches = funcDef.matchAll(/\b(__tc_[A-Za-z0-9_]+)\s*\(/g);
68
+ return [...new Set([...matches].map(m => m[1]))];
69
+ }
70
+ /**
71
+ * Filter helper functions in RuntimePolyfillIR objects to only those
72
+ * whose names appear in the usedHelpers set. Non-__tc_ helpers are always kept.
73
+ */
74
+ export function filterPolyfillHelpers(polyfills, usedHelpers) {
75
+ return polyfills.map(polyfill => ({
76
+ ...polyfill,
77
+ helperFunctions: polyfill.helperFunctions.filter(func => {
78
+ const names = extractHelperFunctionNames(func);
79
+ if (names.length === 0)
80
+ return true;
81
+ return names.some(name => usedHelpers.has(name));
82
+ }),
83
+ })).filter(polyfill => polyfill.helperFunctions.length > 0 ||
84
+ polyfill.forwardDeclarations.length > 0 ||
85
+ polyfill.helperStructs.length > 0);
86
+ }
@@ -0,0 +1,33 @@
1
+ export interface RuntimePolyfillIR {
2
+ kind: "polyfill";
3
+ id: string;
4
+ domain: "standard" | "embedded" | (string & {});
5
+ requiredIncludes: string[];
6
+ forwardDeclarations: string[];
7
+ helperStructs: string[];
8
+ helperFunctions: string[];
9
+ shimMacros: string[];
10
+ dependencies: string[];
11
+ /**
12
+ * Variable names of async task instances generated by the async polyfill.
13
+ * The emitter uses these to call `taskVar.run()` inside `loop()`.
14
+ */
15
+ asyncTaskVars?: string[];
16
+ /**
17
+ * True when the Promise/MicrotaskQueue runtime was emitted (requires <functional>/<vector>).
18
+ * False for architectures that lack the C++ standard library.
19
+ * When false, the emitter must NOT emit cuttlefish_pump_microtasks() calls.
20
+ */
21
+ hasPromiseRuntime?: boolean;
22
+ }
23
+ export interface StdLibSupport {
24
+ hasVector: boolean;
25
+ hasString: boolean;
26
+ hasIostream: boolean;
27
+ hasExceptions: boolean;
28
+ hasRTTI: boolean;
29
+ recommendedArrayImpl: "std_vector" | "static_array";
30
+ recommendedStringImpl: "std_string" | "static_string";
31
+ }
32
+ export declare const DEFAULT_STDLIB_SUPPORT: StdLibSupport;
33
+ export declare function getStdLibSupport(architecture?: string): StdLibSupport;
@@ -0,0 +1,76 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Polyfill types
3
+ //
4
+ // Types for runtime polyfill generation via platform strategies.
5
+ // ---------------------------------------------------------------------------
6
+ export const DEFAULT_STDLIB_SUPPORT = {
7
+ hasVector: true,
8
+ hasString: true,
9
+ hasIostream: true,
10
+ hasExceptions: true,
11
+ hasRTTI: true,
12
+ recommendedArrayImpl: "std_vector",
13
+ recommendedStringImpl: "std_string",
14
+ };
15
+ const STDLIB_SUPPORT = {
16
+ avr: {
17
+ hasVector: false,
18
+ hasString: false,
19
+ hasIostream: false,
20
+ hasExceptions: false,
21
+ hasRTTI: false,
22
+ recommendedArrayImpl: "static_array",
23
+ recommendedStringImpl: "static_string",
24
+ },
25
+ esp32: {
26
+ hasVector: true,
27
+ hasString: true,
28
+ hasIostream: true,
29
+ hasExceptions: true,
30
+ hasRTTI: true,
31
+ recommendedArrayImpl: "std_vector",
32
+ recommendedStringImpl: "std_string",
33
+ },
34
+ esp8266: {
35
+ hasVector: true,
36
+ hasString: true,
37
+ hasIostream: true,
38
+ hasExceptions: true,
39
+ hasRTTI: true,
40
+ recommendedArrayImpl: "std_vector",
41
+ recommendedStringImpl: "std_string",
42
+ },
43
+ rp2040: {
44
+ hasVector: true,
45
+ hasString: true,
46
+ hasIostream: true,
47
+ hasExceptions: true,
48
+ hasRTTI: true,
49
+ recommendedArrayImpl: "std_vector",
50
+ recommendedStringImpl: "std_string",
51
+ },
52
+ samd: {
53
+ hasVector: true,
54
+ hasString: true,
55
+ hasIostream: true,
56
+ hasExceptions: true,
57
+ hasRTTI: true,
58
+ recommendedArrayImpl: "std_vector",
59
+ recommendedStringImpl: "std_string",
60
+ },
61
+ megaavr: {
62
+ hasVector: false,
63
+ hasString: false,
64
+ hasIostream: false,
65
+ hasExceptions: false,
66
+ hasRTTI: false,
67
+ recommendedArrayImpl: "static_array",
68
+ recommendedStringImpl: "static_string",
69
+ },
70
+ default: DEFAULT_STDLIB_SUPPORT,
71
+ };
72
+ export function getStdLibSupport(architecture) {
73
+ if (!architecture)
74
+ return DEFAULT_STDLIB_SUPPORT;
75
+ return STDLIB_SUPPORT[architecture.toLowerCase()] ?? DEFAULT_STDLIB_SUPPORT;
76
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Generate the cooperative microtask queue + minimal Promise runtime for C++.
3
+ *
4
+ * @param queueCapacity Maximum number of pending microtasks in the queue.
5
+ * Use a smaller value (e.g. 32) for memory-constrained targets like AVR,
6
+ * and a larger value (e.g. 256) for targets with more RAM.
7
+ * @param includeWaitForPinEdge Whether to include the `waitForPinEdge` stub
8
+ * (used by Arduino targets).
9
+ */
10
+ export declare function generatePromiseRuntime(queueCapacity: number, includeWaitForPinEdge?: boolean): string;