@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,174 @@
1
+ import type { ProgramIR, StatementIR, ParameterIR } from "../../api/index.js";
2
+ import type { PlatformStrategy } from "../../api/shared/index.js";
3
+ import type { ProgramAnalysisResult } from "../../ir/program-analysis.js";
4
+ import type { EmissionScopeState } from "../snprintf-helpers.js";
5
+ import type { ExpressionRenderer } from "../expression-renderer.js";
6
+ import type { StatementRenderer } from "../statement-renderer.js";
7
+ import type { Diagnostic, EmitMode, SourceMapEntry, SourceSpan } from "../../types.js";
8
+ import type { ResolvedNpmPackage } from "../../transpile/resolution.js";
9
+ import type { BoardConstants } from "../../ir/board-resolver.js";
10
+ import type { LibraryDefinition } from "../../types.js";
11
+ /** Options controlling C++ emission. */
12
+ export interface EmitterOptions {
13
+ outDir: string;
14
+ emitMode: EmitMode;
15
+ target: string;
16
+ libdefs: Map<string, LibraryDefinition>;
17
+ emitMaps: boolean;
18
+ platformContext?: Record<string, unknown>;
19
+ npmPackage?: ResolvedNpmPackage;
20
+ npmPackages?: Map<string, ResolvedNpmPackage>;
21
+ isEntryFile?: boolean;
22
+ strategy?: PlatformStrategy;
23
+ nativeModules?: Map<string, {
24
+ declPath: string;
25
+ cppPath: string;
26
+ moduleKey: string;
27
+ }>;
28
+ crossModuleClasses?: Set<string>;
29
+ crossModuleClassFieldTypes?: Map<string, Map<string, string>>;
30
+ /** Getters/setters declared on classes in OTHER files, keyed by class name.
31
+ * Lets `obj.getter` access rewrite to `obj->getX()`/`Cls::getX()` even when
32
+ * the class is imported (demo #14 Finding E — cross-file getter access). */
33
+ crossModuleClassAccessors?: Map<string, Map<string, "getter" | "setter" | "both">>;
34
+ crossModuleFunctionReturnTypes?: Map<string, string>;
35
+ crossModuleEnumNames?: Set<string>;
36
+ crossModuleStringEnumNames?: Set<string>;
37
+ crossModuleVariableTypes?: Map<string, string>;
38
+ }
39
+ export interface MappedFunction {
40
+ name: string;
41
+ returnType: string;
42
+ sourceSpan: SourceSpan;
43
+ leadingComments?: string[];
44
+ trailingComments?: string[];
45
+ parameters: ParameterIR[];
46
+ isAsync?: boolean;
47
+ typeParameters?: string[];
48
+ typeParameterConstraints?: Map<string, string>;
49
+ isReadonlyReturnType?: boolean;
50
+ isGenerator?: boolean;
51
+ isExported?: boolean;
52
+ statements: StatementIR[];
53
+ }
54
+ export interface CallbackFunction {
55
+ name: string;
56
+ params: string[];
57
+ statements: StatementIR[];
58
+ debounceMs?: number;
59
+ /**
60
+ * Return type of the synthesized free function. Defaults to "void" (the
61
+ * historical ISR/HAL-callback case). Populated from a hoisted lambda's
62
+ * return-type annotation so a `(x): int16_t => {...}` callback lowers to
63
+ * `int16_t name(int16_t)` rather than `void name()`.
64
+ */
65
+ returnType?: string;
66
+ /**
67
+ * Typed parameters of the synthesized free function, carrying both the C++
68
+ * type and the name. Defaults to [] (the void() ISR case). Populated from a
69
+ * hoisted lambda's typed params. Used both to render the signature and to
70
+ * seed the body's emission scope so the params are resolvable.
71
+ */
72
+ typedParams?: {
73
+ name: string;
74
+ cppType: string;
75
+ }[];
76
+ }
77
+ export interface AsyncTaskClass {
78
+ classDef: string;
79
+ instanceDecl: string;
80
+ taskVarName: string;
81
+ }
82
+ export interface FixPointerFieldAccessFn {
83
+ (callee: string): string;
84
+ }
85
+ /**
86
+ * Shared state bag passed between all sub-emitter steps.
87
+ */
88
+ export interface EmitterContext {
89
+ program: ProgramIR;
90
+ options: EmitterOptions;
91
+ strategy: PlatformStrategy;
92
+ programAnalysis: ProgramAnalysisResult;
93
+ enumNames: Set<string>;
94
+ stringEnumNames: Set<string>;
95
+ largeEnumNames: Set<string>;
96
+ namespaceNames: Set<string>;
97
+ symbolMap: Record<string, string>;
98
+ includes: string[];
99
+ shimLines: string[];
100
+ baseName: string;
101
+ effectiveEmitMode: EmitMode;
102
+ isEntryFile: boolean;
103
+ isNpmPackage: boolean;
104
+ isrPrefix: string;
105
+ reservedNames: ReadonlySet<string>;
106
+ knownFunctionReturnTypes: Map<string, string>;
107
+ mappedFunctions: MappedFunction[];
108
+ /**
109
+ * Names of non-exported free functions that are CALLED from at least one
110
+ * class method body (a getter/setter/method/constructor). In split mode an
111
+ * inline class method body lives in the header, so such a function must be
112
+ * visible in the header too — otherwise the method body sees
113
+ * "'fn' was not declared in this scope". These functions are therefore
114
+ * emitted non-static with a header prototype (like exported functions).
115
+ * Demo #18 Finding B.
116
+ */
117
+ freeFunctionsCalledFromClassMethods: Set<string>;
118
+ topLevelScope: EmissionScopeState;
119
+ snprintfCounter: {
120
+ value: number;
121
+ };
122
+ stringVarNames: Set<string>;
123
+ varAccessorNames: Map<string, Map<string, "getter" | "setter" | "both">>;
124
+ exprRenderer: ExpressionRenderer;
125
+ statementRenderer: StatementRenderer;
126
+ classNameMap?: Map<string, string>;
127
+ boardConstants?: BoardConstants;
128
+ restParamFunctions?: Map<string, string>;
129
+ asyncTaskClasses: AsyncTaskClass[];
130
+ asyncFunctionOriginalNames: Set<string>;
131
+ asyncFunctionMappedNames: Set<string>;
132
+ hasAsyncRuntime: boolean;
133
+ hasPromiseRuntime: boolean;
134
+ usesTimers: boolean;
135
+ emittedPolyfills?: {
136
+ declarations: string[];
137
+ definitions: string[];
138
+ includes: string[];
139
+ };
140
+ sourceLines: string[];
141
+ headerLines: string[];
142
+ sourceMapEntries: SourceMapEntry[];
143
+ headerMapEntries: SourceMapEntry[];
144
+ cArrayVarNames: Set<string>;
145
+ fnCArrayVarNames: Map<string, Set<string>>;
146
+ globalPointerVarTypes: Map<string, string>;
147
+ promotedVarDecls: Map<string, {
148
+ cppType: string;
149
+ index: number;
150
+ }>;
151
+ callbackFunctions: CallbackFunction[];
152
+ filteredTopLevelExecutables: StatementIR[];
153
+ filteredTopLevelDeclarations: StatementIR[];
154
+ emittedTopLevelStatements: StatementIR[];
155
+ compiletimeVarNames: Set<string>;
156
+ fixPointerFieldAccess: FixPointerFieldAccessFn;
157
+ knownTopLevelObjectTypes: Map<string, string>;
158
+ knownTopLevelObjectFields: Map<string, Map<string, string>>;
159
+ currentClassPointerFields?: string[];
160
+ currentClassPointerFieldTypes?: Map<string, string>;
161
+ profileDiagnostics: Diagnostic[];
162
+ /**
163
+ * Diagnostics produced during emission (e.g. an unregistered HAL operation
164
+ * the strategy couldn't resolve, surfaced as a warning). Kept separate from
165
+ * profileDiagnostics for clarity; merged into the final diagnostics list by
166
+ * finalizeOutput. Shared by reference with ExpressionRenderer /
167
+ * StatementRenderer so their fallback paths can report without throwing.
168
+ */
169
+ emitDiagnostics: Diagnostic[];
170
+ templateInterfaceNames: Set<string>;
171
+ interfaceNamespaceMap: Map<string, string>;
172
+ /** Map of interface name to its field types (e.g., "Task" -> Map("id" -> "std::string", "title" -> "std::string")) */
173
+ interfaceFieldTypes: Map<string, Map<string, string>>;
174
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { EmitterContext } from "./emitter-context.js";
2
+ export declare function synthesizeEntrypoints(ctx: EmitterContext): void;
@@ -0,0 +1,175 @@
1
+ import { entryHasUI } from "../../ui-hook.js";
2
+ import { uiPressBindings, watchPinSpecs } from "../../ir/transformers/ui-call-resolver.js";
3
+ import { getDisplayProfile } from "../../stores/display-profile-store.js";
4
+ function isDisplayInitStatement(statement) {
5
+ return statement.kind === "hal-op" && statement.operation.operation === "display.init";
6
+ }
7
+ export function synthesizeEntrypoints(ctx) {
8
+ const { program, strategy, isEntryFile, mappedFunctions } = ctx;
9
+ const entrypointFunctionName = strategy.entrypointFunctionName();
10
+ // Merge top-level executables into the entrypoint function
11
+ if (isEntryFile && ctx.filteredTopLevelExecutables.length > 0) {
12
+ const epName = entrypointFunctionName;
13
+ const existingEp = mappedFunctions.find(fn => fn.name === epName);
14
+ const setupInitLines = strategy.setupInitCode?.(program, ctx.options.platformContext) ?? [];
15
+ const setupInitStmts = setupInitLines.map(line => ({
16
+ kind: "call",
17
+ callee: `__RAW_STMT__${line}`,
18
+ args: [],
19
+ sourceSpan: { filePath: program.fileName, startOffset: 0, endOffset: 0, startLine: 1, startColumn: 1, endLine: 1, endColumn: 1 },
20
+ }));
21
+ const displayInitStmts = [];
22
+ const topLevelExecutableStmts = ctx.filteredTopLevelExecutables.filter((statement) => {
23
+ if (isDisplayInitStatement(statement)) {
24
+ displayInitStmts.push(statement);
25
+ return false;
26
+ }
27
+ return true;
28
+ });
29
+ // UI hardware/runtime setup. Only emitted when a UI is mounted.
30
+ const uiSetupStmts = [];
31
+ if (entryHasUI()) {
32
+ // Touch controller begin (if touch is configured). Hardware setup runs
33
+ // before ui_init() so the first frame starts from a fully initialized
34
+ // display/touch stack.
35
+ const tProfile = getDisplayProfile();
36
+ if (tProfile.touch) {
37
+ uiSetupStmts.push({ kind: "call", callee: `__RAW_STMT__touch_init();`, args: [],
38
+ sourceSpan: { filePath: program.fileName, startOffset: 0, endOffset: 0, startLine: 1, startColumn: 1, endLine: 1, endColumn: 1 } });
39
+ }
40
+ // ISR-based press/release wiring (legacy) + pin-watchers (ui.watchPin).
41
+ // These are GPIO-hardware APIs: pinMode/attachInterrupt/digitalPinToInterrupt
42
+ // are Arduino core symbols, and ui_poll_inputs reads pins via digitalRead.
43
+ // On a host target with no GPIO (SDL native: strategy.modelsGpio()===false)
44
+ // they have no equivalent — emitting them yields undefined symbols or a
45
+ // silent no-op. Gate on modelsGpio and surface a clear diagnostic instead.
46
+ const modelsGpio = strategy.modelsGpio?.() ?? true;
47
+ const pressBindings = uiPressBindings();
48
+ const pinWatchers = watchPinSpecs();
49
+ if (!modelsGpio && (pressBindings.length > 0 || pinWatchers.length > 0)) {
50
+ const which = pressBindings.length > 0 && pinWatchers.length > 0
51
+ ? "ui.press and ui.watchPin"
52
+ : pressBindings.length > 0 ? "ui.press" : "ui.watchPin";
53
+ ctx.emitDiagnostics.push({
54
+ severity: "error",
55
+ code: "gpio-unsupported-on-target",
56
+ message: `${which} require GPIO hardware, which this target (${ctx.options.target}) does not model. Use the browser preview to exercise pin-driven UI, or target @typecad/framework-arduino.`,
57
+ source: program.fileName,
58
+ });
59
+ }
60
+ if (modelsGpio) {
61
+ for (const pb of pressBindings) {
62
+ const mode = pb.edge === "press" ? "FALLING" : "RISING";
63
+ uiSetupStmts.push({ kind: "call", callee: `__RAW_STMT__pinMode(${pb.pin}, INPUT_PULLUP);`, args: [],
64
+ sourceSpan: { filePath: program.fileName, startOffset: 0, endOffset: 0, startLine: 1, startColumn: 1, endLine: 1, endColumn: 1 } }, { kind: "call", callee: `__RAW_STMT__attachInterrupt(digitalPinToInterrupt(${pb.pin}), ${pb.handlerName}, ${mode});`, args: [],
65
+ sourceSpan: { filePath: program.fileName, startOffset: 0, endOffset: 0, startLine: 1, startColumn: 1, endLine: 1, endColumn: 1 } });
66
+ }
67
+ // Pin-watchers (from ui.watchPin): set pin mode so ui_poll_inputs can read it
68
+ for (const wp of pinWatchers) {
69
+ uiSetupStmts.push({ kind: "call", callee: `__RAW_STMT__pinMode(${wp.pin}, INPUT_PULLUP);`, args: [],
70
+ sourceSpan: { filePath: program.fileName, startOffset: 0, endOffset: 0, startLine: 1, startColumn: 1, endLine: 1, endColumn: 1 } });
71
+ }
72
+ }
73
+ // Initial draw: mark all UI nodes dirty so the first ui_tick renders.
74
+ uiSetupStmts.push({ kind: "call", callee: `__RAW_STMT__ui_init();`, args: [],
75
+ sourceSpan: { filePath: program.fileName, startOffset: 0, endOffset: 0, startLine: 1, startColumn: 1, endLine: 1, endColumn: 1 } });
76
+ }
77
+ const allSetupInitStmts = [...setupInitStmts, ...displayInitStmts, ...uiSetupStmts];
78
+ if (existingEp) {
79
+ existingEp.statements = [...allSetupInitStmts, ...topLevelExecutableStmts, ...existingEp.statements];
80
+ }
81
+ else {
82
+ const isMain = epName === "main";
83
+ // Route through mapReturnType so platform strategies can special-case the
84
+ // entrypoint signature (e.g. NativeStrategy keeps main → int instead of
85
+ // normalizing int → long long). The emitted return type is then treated
86
+ // as final by mapReturnTypeForEmit (no re-normalisation).
87
+ const mapReturnType = (fnName, tsType) => ctx.statementRenderer.mapReturnType(fnName, tsType);
88
+ const returnType = mapReturnType(epName, isMain ? "int" : "void");
89
+ const stmts = isMain
90
+ ? [...allSetupInitStmts, ...topLevelExecutableStmts, { kind: "return", sourceSpan: { filePath: program.fileName, startOffset: 0, endOffset: 0, startLine: 1, startColumn: 1, endLine: 1, endColumn: 1 }, value: { kind: "number", value: 0 } }]
91
+ : [...allSetupInitStmts, ...topLevelExecutableStmts];
92
+ const insertFn = {
93
+ name: epName,
94
+ originalName: epName,
95
+ returnType,
96
+ sourceSpan: { filePath: program.fileName, startOffset: 0, endOffset: 0, startLine: 1, startColumn: 1, endLine: 1, endColumn: 1 },
97
+ leadingComments: [`// Auto-generated ${epName}() for top-level statements`],
98
+ trailingComments: undefined,
99
+ parameters: [],
100
+ isAsync: false,
101
+ typeParameters: undefined,
102
+ typeParameterConstraints: undefined,
103
+ isReadonlyReturnType: false,
104
+ statements: stmts,
105
+ };
106
+ if (isMain) {
107
+ mappedFunctions.push(insertFn);
108
+ }
109
+ else {
110
+ mappedFunctions.unshift(insertFn);
111
+ }
112
+ }
113
+ }
114
+ // Ensure the entrypoint function exists even when all executables were filtered
115
+ if (isEntryFile && !mappedFunctions.some((fn) => fn.name === entrypointFunctionName)) {
116
+ const isMain = entrypointFunctionName === "main";
117
+ const mapReturnType = (fnName, tsType) => ctx.statementRenderer.mapReturnType(fnName, tsType);
118
+ const returnType = mapReturnType(entrypointFunctionName, isMain ? "int" : "void");
119
+ const stmts = isMain
120
+ ? [{ kind: "return", sourceSpan: { filePath: program.fileName, startOffset: 0, endOffset: 0, startLine: 1, startColumn: 1, endLine: 1, endColumn: 1 }, value: { kind: "number", value: 0 } }]
121
+ : [];
122
+ const insertFn = {
123
+ name: entrypointFunctionName,
124
+ returnType,
125
+ sourceSpan: { filePath: program.fileName, startOffset: 0, endOffset: 0, startLine: 1, startColumn: 1, endLine: 1, endColumn: 1 },
126
+ leadingComments: undefined,
127
+ trailingComments: undefined,
128
+ parameters: [],
129
+ isAsync: false,
130
+ typeParameters: undefined,
131
+ typeParameterConstraints: undefined,
132
+ isReadonlyReturnType: false,
133
+ statements: stmts,
134
+ };
135
+ if (isMain) {
136
+ mappedFunctions.push(insertFn);
137
+ }
138
+ else {
139
+ mappedFunctions.unshift(insertFn);
140
+ }
141
+ }
142
+ // Some platforms require a loop function even if empty
143
+ if (isEntryFile && strategy.requiresLoopFunction() && !mappedFunctions.some((fn) => fn.name === "loop")) {
144
+ mappedFunctions.push({
145
+ name: "loop",
146
+ returnType: "void",
147
+ sourceSpan: { filePath: program.fileName, startOffset: 0, endOffset: 0, startLine: 1, startColumn: 1, endLine: 1, endColumn: 1 },
148
+ leadingComments: ctx.hasAsyncRuntime ? ["// Auto-generated loop() for async microtask pumping"] : undefined,
149
+ trailingComments: undefined,
150
+ parameters: [],
151
+ isAsync: false,
152
+ typeParameters: undefined,
153
+ typeParameterConstraints: undefined,
154
+ isReadonlyReturnType: false,
155
+ statements: [],
156
+ });
157
+ }
158
+ // Only generate main() for entry files when there's no loop-based strategy
159
+ if (isEntryFile && ctx.hasAsyncRuntime && !strategy.requiresLoopFunction() && !mappedFunctions.some((fn) => fn.name === "main")) {
160
+ const mapReturnType = (fnName, tsType) => ctx.statementRenderer.mapReturnType(fnName, tsType);
161
+ mappedFunctions.push({
162
+ name: "main",
163
+ returnType: mapReturnType("main", "int"),
164
+ sourceSpan: { filePath: program.fileName, startOffset: 0, endOffset: 0, startLine: 1, startColumn: 1, endLine: 1, endColumn: 1 },
165
+ leadingComments: ["// Auto-generated main() for async microtask pumping"],
166
+ trailingComments: undefined,
167
+ parameters: [],
168
+ isAsync: false,
169
+ typeParameters: undefined,
170
+ typeParameterConstraints: undefined,
171
+ isReadonlyReturnType: false,
172
+ statements: [{ kind: "return", sourceSpan: { filePath: program.fileName, startOffset: 0, endOffset: 0, startLine: 1, startColumn: 1, endLine: 1, endColumn: 1 }, value: { kind: "number", value: 0 } }],
173
+ });
174
+ }
175
+ }
@@ -0,0 +1,19 @@
1
+ import type { EmitterContext } from "./emitter-context.js";
2
+ export declare function emitPostClassDeclarations(ctx: EmitterContext): void;
3
+ export declare function emitCallbackFunctions(ctx: EmitterContext): void;
4
+ export declare function emitFunctions(ctx: EmitterContext): void;
5
+ /**
6
+ * Emit forward declarations for ALL free functions (and ISR callbacks) BEFORE
7
+ * class bodies. A class method may call a free function declared later in the
8
+ * same source file; if that function's forward declaration only appears after
9
+ * the class (as it did historically via emitCallbackFunctions/emitFunctions),
10
+ * g++ reports "'fn' was not declared in this scope" inside the class body.
11
+ *
12
+ * This runs at cpp-emitter.ts step 6.5, ahead of emitClasses (step 7). The
13
+ * definition-only emission in emitCallbackFunctions/emitFunctions below no
14
+ * longer re-emits these declarations (they are dropped there to avoid
15
+ * duplicates). Template/generic functions get template prototypes here so
16
+ * earlier functions can call them before their definitions later in the same
17
+ * translation unit.
18
+ */
19
+ export declare function emitFunctionForwardDeclarations(ctx: EmitterContext): void;