@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,20 @@
1
+ export type CallbackContextId = "setInterval" | "ui-event-callback" | "ui-draw-canvas";
2
+ export interface CallbackContextCapabilities {
3
+ id: CallbackContextId;
4
+ /** Human label used in diagnostic messages, e.g. "UI event callback". */
5
+ label: string;
6
+ /** Statement-level control-flow constructs this context lowers. */
7
+ statements: readonly string[];
8
+ /** Expression-level / side-effecting forms this context recognizes. */
9
+ expressions: readonly string[];
10
+ /** Actionable next step when a statement/expression isn't supported here. */
11
+ escapeHatch: string;
12
+ }
13
+ export declare const CALLBACK_CONTEXTS: Readonly<Record<CallbackContextId, CallbackContextCapabilities>>;
14
+ /** Human-readable name for a context, used in diagnostic messages. */
15
+ export declare function callbackContextLabel(id: CallbackContextId): string;
16
+ /** Render a context's declared capabilities into the hint text shown
17
+ * alongside a "statement not lowerable here" diagnostic, so the message
18
+ * always matches what lowerCallbackStatements for that context actually
19
+ * implements. */
20
+ export declare function unsupportedStatementHint(id: CallbackContextId): string;
@@ -0,0 +1,55 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Declarative capability registry for UI callback contexts.
3
+ //
4
+ // UI callback bodies (setInterval, ui.bind/onClick/onToggle/watchPin,
5
+ // ui.drawCanvas) each lower through lowerCallbackStatements →
6
+ // lowerStatementList (the same pipeline setInterval uses). This registry is
7
+ // the single declarative source of truth for diagnostics: each context lists
8
+ // what it lowers, and unsupportedStatementHint() renders that list into the
9
+ // hint text shown next to fatal "ui-callback-unsupported-statement"
10
+ // diagnostics.
11
+ // ---------------------------------------------------------------------------
12
+ export const CALLBACK_CONTEXTS = {
13
+ setInterval: {
14
+ id: "setInterval",
15
+ label: "setInterval callback",
16
+ statements: ["const/let", "if/else", "for", "while", "do/while", "break/continue", "nested blocks"],
17
+ expressions: ["the full statement-to-IR expression pipeline — the same one top-level code uses"],
18
+ escapeHatch: "setInterval callbacks already route through the main statement-to-IR pipeline, so a failure here reflects a general transpiler limitation rather than a callback-context restriction",
19
+ },
20
+ "ui-event-callback": {
21
+ id: "ui-event-callback",
22
+ label: "UI event callback",
23
+ statements: ["const/let", "if/else", "for", "while", "do/while", "break/continue"],
24
+ expressions: [
25
+ "signal.set(value)",
26
+ "signal() reads",
27
+ "console.* calls",
28
+ "any other expression via the standard expression pipeline (arithmetic, comparisons, ternaries, color literals, ...)",
29
+ ],
30
+ escapeHatch: "move the logic to setInterval or a plain function",
31
+ },
32
+ "ui-draw-canvas": {
33
+ id: "ui-draw-canvas",
34
+ label: "ui.drawCanvas callback",
35
+ statements: ["const/let", "if/else", "for", "while", "do/while", "break/continue"],
36
+ expressions: [
37
+ "ctx.*() draw calls (drawPixel, fillRect, rect, fillRoundRect, roundRect, line, hline, vline, fillCircle, circle, rgbBitmap, text, fillScreen)",
38
+ ],
39
+ escapeHatch: "move non-drawing side effects (calls not on ctx, e.g. signal writes or console output) to setInterval",
40
+ },
41
+ };
42
+ /** Human-readable name for a context, used in diagnostic messages. */
43
+ export function callbackContextLabel(id) {
44
+ return CALLBACK_CONTEXTS[id].label;
45
+ }
46
+ /** Render a context's declared capabilities into the hint text shown
47
+ * alongside a "statement not lowerable here" diagnostic, so the message
48
+ * always matches what lowerCallbackStatements for that context actually
49
+ * implements. */
50
+ export function unsupportedStatementHint(id) {
51
+ const ctx = CALLBACK_CONTEXTS[id];
52
+ return (`${ctx.label}s support ${ctx.statements.join(", ")} for control flow, ` +
53
+ `plus ${ctx.expressions.join("; ")}. If you hit this, the statement kind used ` +
54
+ `isn't lowerable here — ${ctx.escapeHatch}.`);
55
+ }
@@ -0,0 +1,42 @@
1
+ import ts from "typescript";
2
+ import { Diagnostic, type SourceSpan } from "../../types.js";
3
+ import type { StatementIR } from "../../api/shared/ir-core.js";
4
+ /** One user draw callback: the node it targets + IR body (preferred) or
5
+ * lowered C++ body string (fallback / tests). */
6
+ export interface DrawCanvasSpec {
7
+ nodeIndex: number;
8
+ fnName: string;
9
+ /** @deprecated Prefer bodyStatements; kept for compact-string fallbacks. */
10
+ callbackBody: string;
11
+ /** Statement IR produced by lowerCallbackStatements (main pipeline). */
12
+ bodyStatements?: StatementIR[];
13
+ /** Source span of the original (ctx) => {...} callback, when known. */
14
+ sourceSpan?: SourceSpan;
15
+ }
16
+ export declare function resetCanvasBindings(): void;
17
+ export declare function canvasBindings(): DrawCanvasSpec[];
18
+ export declare function recordCanvasBinding(spec: DrawCanvasSpec): void;
19
+ export declare function getCanvasBindingsCount(): number;
20
+ /**
21
+ * If `call` is a `<ctxName>.method(args)` call we recognize, return the lowered
22
+ * C++ statement(s) (each terminated with `;`). Otherwise return null (and push
23
+ * a diagnostic if it IS a ctx call with an unknown method).
24
+ */
25
+ export declare function rewriteCanvasCall(call: ts.CallExpression, ctxName: string, diagnostics: Diagnostic[], sourceText?: string): string | null;
26
+ /**
27
+ * Lower an entire ui.drawCanvas callback body through the main statement-to-IR
28
+ * pipeline (ambient canvas ctx rewrites ctx.* during lowering). Returns a
29
+ * compact-rendered C++ string for unit tests / callers that still want text.
30
+ */
31
+ export declare function lowerCanvasBody(cbArg: ts.ArrowFunction | ts.FunctionExpression, sourceText: string, diagnostics: Diagnostic[], fileName?: string): string;
32
+ /** Emit the canvas binding table + callback functions.
33
+ *
34
+ * When `emitStatements` is provided, bodyStatements are rendered through it
35
+ * (StatementRenderer path). Otherwise falls back to compact string paste of
36
+ * callbackBody (tests / no-emitter contexts). */
37
+ export declare function emitCanvasBindings(specs: DrawCanvasSpec[], emitLine?: (line: string, span?: SourceSpan) => void, emitStatements?: (statements: StatementIR[], indent: string, span?: SourceSpan) => void): string;
38
+ /**
39
+ * Resolve a `ui.drawCanvas(node, (ctx) => {...})` call.
40
+ * Records a DrawCanvasSpec with bodyStatements from the main IR pipeline.
41
+ */
42
+ export declare function resolveDrawCanvasCall(call: ts.CallExpression, fileName: string, sourceText: string, diagnostics: Diagnostic[]): StatementIR | null;
@@ -0,0 +1,249 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Canvas callback lowering: rewrite `ctx.method(args)` calls inside a
3
+ // ui.drawCanvas(node, (ctx) => {...}) body into ui_display_* shim calls.
4
+ //
5
+ // `ctx` is a compile-time fiction — at runtime the callback draws into the
6
+ // node's offscreen CuttlefishCanvas16 set as the active __ui_gfx target, so the
7
+ // lowered body uses the SAME ui_display_* wrappers every other draw path uses.
8
+ // Colors resolve to RGB565 via the existing resolver; ctx.width/ctx.height map
9
+ // to __ui_canvas_w / __ui_canvas_h locals set by the emitted wrapper.
10
+ //
11
+ // Block-body callbacks lower through lowerCallbackStatements (main
12
+ // statement-to-IR pipeline, same as setInterval / onClick), with an ambient
13
+ // canvas ctx so callToStatement / expressionToIR rewrite ctx.* forms. The
14
+ // resulting StatementIR[] is stored on DrawCanvasSpec and rendered at emit.
15
+ // ---------------------------------------------------------------------------
16
+ import ts from "typescript";
17
+ import { expressionToIR } from "../expression-to-ir.js";
18
+ import { renderExprAsText } from "../render-expr.js";
19
+ import { requireUIHook } from "../../ui-hook.js";
20
+ import { getDisplayProfile } from "../../stores/display-profile-store.js";
21
+ import { resolveColorIR, lowerCallbackStatements, renderStatementsCompact, } from "./ui-callback-lowering.js";
22
+ import { makeSourceSpan } from "../ast-node-utils.js";
23
+ import { resolveNodeIndex, resolveUIModuleImport, pushUnknownElementDiagnostic } from "./ui-call-resolver.js";
24
+ const _canvasBindings = [];
25
+ export function resetCanvasBindings() {
26
+ _canvasBindings.length = 0;
27
+ }
28
+ export function canvasBindings() {
29
+ return _canvasBindings;
30
+ }
31
+ export function recordCanvasBinding(spec) {
32
+ _canvasBindings.push(spec);
33
+ }
34
+ export function getCanvasBindingsCount() {
35
+ return _canvasBindings.length;
36
+ }
37
+ /** True if `text` is a quoted CSS color string. */
38
+ function isColorLiteral(text) {
39
+ const t = text.trim();
40
+ return /^["'](#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})|[a-z]+|rgba?\([^)]*\))["']$/i.test(t);
41
+ }
42
+ /** Lower a CSS color string to the target's internal color literal, or null if not a color. */
43
+ function tryColor(text) {
44
+ if (!isColorLiteral(text))
45
+ return null;
46
+ const color = text.trim().replace(/^["']|["']$/g, "");
47
+ try {
48
+ return requireUIHook().resolveColorInternal(color, getDisplayProfile().colorFormat);
49
+ }
50
+ catch {
51
+ return null;
52
+ }
53
+ }
54
+ /** Substitute ctx.width/ctx.height references (bare or embedded in a
55
+ * compound expression, e.g. `ctx.height - 4`) with the wrapper's locals. */
56
+ function substituteCanvasDims(raw, ctxName) {
57
+ return raw
58
+ .replace(new RegExp(`\\b${ctxName}\\.width\\b`, "g"), "__ui_canvas_w")
59
+ .replace(new RegExp(`\\b${ctxName}\\.height\\b`, "g"), "__ui_canvas_h");
60
+ }
61
+ /** Lower one argument expression to its C++ text. Color strings → rgb565 hex. */
62
+ function lowerArg(arg, ctxName, sourceText, diagnostics) {
63
+ if (ts.isPropertyAccessExpression(arg) &&
64
+ ts.isIdentifier(arg.expression) &&
65
+ arg.expression.text === ctxName &&
66
+ (arg.name.text === "width" || arg.name.text === "height")) {
67
+ return arg.name.text === "width" ? "__ui_canvas_w" : "__ui_canvas_h";
68
+ }
69
+ let raw = renderExprAsText(expressionToIR(arg, sourceText, diagnostics));
70
+ raw = substituteCanvasDims(raw, ctxName);
71
+ const color = tryColor(raw);
72
+ if (color !== null)
73
+ raw = `0x${color.toString(16)}`;
74
+ return raw;
75
+ }
76
+ /** Lower an argument known (by its position) to be a color. Resolves color
77
+ * string literals at the IR level (via resolveColorIR) BEFORE rendering, so
78
+ * ternaries like `temp() > 25 ? '#a33' : '#33a'` resolve both branches. */
79
+ function lowerColorArg(arg, ctxName, sourceText, diagnostics) {
80
+ const ir = resolveColorIR(expressionToIR(arg, sourceText, diagnostics));
81
+ return substituteCanvasDims(renderExprAsText(ir), ctxName);
82
+ }
83
+ /** ctx method name → shim callee. */
84
+ const CANVAS_METHODS = {
85
+ drawPixel: "ui_display_draw_pixel",
86
+ fillRect: "ui_display_fill_rect",
87
+ rect: "ui_display_draw_rect",
88
+ fillRoundRect: "ui_display_fill_round_rect",
89
+ roundRect: "ui_display_draw_round_rect",
90
+ line: "ui_display_draw_line",
91
+ hline: "ui_display_draw_fast_hline",
92
+ vline: "ui_display_draw_fast_vline",
93
+ fillCircle: "ui_display_fill_circle",
94
+ circle: "ui_display_draw_circle",
95
+ rgbBitmap: "ui_display_draw_rgb_bitmap",
96
+ };
97
+ /** Argument index (0-based) of the color parameter for each ctx method. */
98
+ const COLOR_ARG_INDEX = {
99
+ drawPixel: 2,
100
+ fillRect: 4,
101
+ rect: 4,
102
+ fillRoundRect: 5,
103
+ roundRect: 5,
104
+ line: 4,
105
+ hline: 3,
106
+ vline: 3,
107
+ fillCircle: 3,
108
+ circle: 3,
109
+ };
110
+ /**
111
+ * If `call` is a `<ctxName>.method(args)` call we recognize, return the lowered
112
+ * C++ statement(s) (each terminated with `;`). Otherwise return null (and push
113
+ * a diagnostic if it IS a ctx call with an unknown method).
114
+ */
115
+ export function rewriteCanvasCall(call, ctxName, diagnostics, sourceText = "") {
116
+ if (!ts.isPropertyAccessExpression(call.expression) ||
117
+ !ts.isIdentifier(call.expression.expression) ||
118
+ call.expression.expression.text !== ctxName) {
119
+ return null;
120
+ }
121
+ const method = call.expression.name.text;
122
+ const args = call.arguments;
123
+ if (method === "text") {
124
+ if (args.length < 3) {
125
+ diagnostics.push({
126
+ severity: "error", code: "ui-canvas-method",
127
+ message: `ctx.text() requires at least 3 arguments (x, y, text); got ${args.length}.`,
128
+ source: sourceText.slice(Math.max(0, call.getStart() - 20), call.getEnd()).trim(),
129
+ });
130
+ return null;
131
+ }
132
+ const x = lowerArg(args[0], ctxName, sourceText, diagnostics);
133
+ const y = lowerArg(args[1], ctxName, sourceText, diagnostics);
134
+ const str = renderExprAsText(expressionToIR(args[2], sourceText, diagnostics));
135
+ const colorText = args.length >= 4 ? lowerColorArg(args[3], ctxName, sourceText, diagnostics) : "0xffff";
136
+ return `ui_display_set_cursor(${x}, ${y}); ui_display_set_text_color_solid(${colorText}); ui_display_print(${str});`;
137
+ }
138
+ if (method === "fillScreen") {
139
+ if (args.length < 1) {
140
+ diagnostics.push({
141
+ severity: "error", code: "ui-canvas-method",
142
+ message: `ctx.fillScreen() requires a color argument.`,
143
+ source: sourceText.slice(Math.max(0, call.getStart() - 20), call.getEnd()).trim(),
144
+ });
145
+ return null;
146
+ }
147
+ const colorText = lowerColorArg(args[0], ctxName, sourceText, diagnostics);
148
+ return `ui_display_fill_rect(0, 0, __ui_canvas_w, __ui_canvas_h, ${colorText});`;
149
+ }
150
+ const shim = CANVAS_METHODS[method];
151
+ if (!shim) {
152
+ diagnostics.push({
153
+ severity: "error", code: "ui-canvas-method",
154
+ message: `Unknown canvas method ctx.${method}() — supported: drawPixel, fillRect, rect, fillRoundRect, roundRect, line, hline, vline, fillCircle, circle, rgbBitmap, text, fillScreen`,
155
+ source: sourceText.slice(Math.max(0, call.getStart() - 20), call.getEnd()).trim(),
156
+ });
157
+ return null;
158
+ }
159
+ const colorIdx = COLOR_ARG_INDEX[method];
160
+ const loweredArgs = args
161
+ .map((a, i) => (i === colorIdx ? lowerColorArg(a, ctxName, sourceText, diagnostics) : lowerArg(a, ctxName, sourceText, diagnostics)))
162
+ .join(", ");
163
+ return `${shim}(${loweredArgs});`;
164
+ }
165
+ /**
166
+ * Lower an entire ui.drawCanvas callback body through the main statement-to-IR
167
+ * pipeline (ambient canvas ctx rewrites ctx.* during lowering). Returns a
168
+ * compact-rendered C++ string for unit tests / callers that still want text.
169
+ */
170
+ export function lowerCanvasBody(cbArg, sourceText, diagnostics, fileName = "canvas.ts") {
171
+ const statements = lowerCallbackStatements(cbArg, fileName, sourceText, diagnostics, "ui-draw-canvas");
172
+ return renderStatementsCompact(statements);
173
+ }
174
+ /** Emit the canvas binding table + callback functions.
175
+ *
176
+ * When `emitStatements` is provided, bodyStatements are rendered through it
177
+ * (StatementRenderer path). Otherwise falls back to compact string paste of
178
+ * callbackBody (tests / no-emitter contexts). */
179
+ export function emitCanvasBindings(specs, emitLine, emitStatements) {
180
+ const lines = [];
181
+ const push = (line, span) => {
182
+ lines.push(line);
183
+ emitLine?.(line, span);
184
+ };
185
+ if (specs.length === 0) {
186
+ push(`UICanvasBinding __ui_canvas_bindings[] = {};`);
187
+ push(`const uint16_t __ui_canvas_binding_count = 0;`);
188
+ return lines.join("\n");
189
+ }
190
+ for (const spec of specs) {
191
+ push(`void ${spec.fnName}(CuttlefishCanvas16* __c) {`, spec.sourceSpan);
192
+ push(` int16_t __ui_canvas_w = __c ? display_canvasWidth(__c) : __ui_canvas_fallback_w;`);
193
+ push(` int16_t __ui_canvas_h = __c ? display_canvasHeight(__c) : __ui_canvas_fallback_h;`);
194
+ if (spec.bodyStatements && emitStatements) {
195
+ emitStatements(spec.bodyStatements, " ", spec.sourceSpan);
196
+ }
197
+ else if (spec.bodyStatements) {
198
+ push(` ${renderStatementsCompact(spec.bodyStatements)}`, spec.sourceSpan);
199
+ }
200
+ else {
201
+ push(` ${spec.callbackBody || ""}`, spec.sourceSpan);
202
+ }
203
+ push(`}`);
204
+ }
205
+ push(`UICanvasBinding __ui_canvas_bindings[] = {`);
206
+ for (const spec of specs) {
207
+ push(` { .node=${spec.nodeIndex}, .fn=${spec.fnName} },`);
208
+ }
209
+ push(`};`);
210
+ push(`const uint16_t __ui_canvas_binding_count = ${specs.length};`);
211
+ return lines.join("\n");
212
+ }
213
+ /**
214
+ * Resolve a `ui.drawCanvas(node, (ctx) => {...})` call.
215
+ * Records a DrawCanvasSpec with bodyStatements from the main IR pipeline.
216
+ */
217
+ export function resolveDrawCanvasCall(call, fileName, sourceText, diagnostics) {
218
+ const nodeArg = call.arguments[0];
219
+ const cbArg = call.arguments[1];
220
+ if (!nodeArg || !ts.isPropertyAccessExpression(nodeArg) || !ts.isIdentifier(nodeArg.expression))
221
+ return null;
222
+ if (!cbArg || !(ts.isArrowFunction(cbArg) || ts.isFunctionExpression(cbArg)))
223
+ return null;
224
+ const treeName = nodeArg.expression.text;
225
+ const id = nodeArg.name.text;
226
+ const htmlPath = resolveUIModuleImport(treeName);
227
+ if (!htmlPath)
228
+ return null;
229
+ const nodeIndex = resolveNodeIndex(htmlPath, id);
230
+ if (nodeIndex < 0) {
231
+ pushUnknownElementDiagnostic(diagnostics, "ui.drawCanvas", id, treeName);
232
+ return null;
233
+ }
234
+ const bodyStatements = lowerCallbackStatements(cbArg, fileName, sourceText, diagnostics, "ui-draw-canvas");
235
+ const fnName = `__ui_canvas_draw_${getCanvasBindingsCount()}`;
236
+ recordCanvasBinding({
237
+ nodeIndex,
238
+ fnName,
239
+ // Legacy compact string for tests / emitCanvasBindings without emitStatements.
240
+ callbackBody: renderStatementsCompact(bodyStatements),
241
+ bodyStatements,
242
+ sourceSpan: makeSourceSpan(cbArg, fileName, sourceText),
243
+ });
244
+ return {
245
+ kind: "block",
246
+ sourceSpan: makeSourceSpan(call, fileName, sourceText),
247
+ body: [],
248
+ };
249
+ }
@@ -0,0 +1,8 @@
1
+ import ts from "typescript";
2
+ import { Diagnostic } from "../../types.js";
3
+ import { StatementIR } from "../../api/index.js";
4
+ import { CppTypeHint } from "../type-resolution.js";
5
+ import { PointerTracker } from "../build-ir-state.js";
6
+ export declare function forInitializerToIR(declarationList: ts.VariableDeclarationList, fileName: string, sourceText: string, diagnostics: Diagnostic[], functionReturnTypes: Map<string, CppTypeHint>, localVariableTypes: Map<string, CppTypeHint>): StatementIR | undefined;
7
+ export declare function incrementorToIR(expr: ts.Expression, sourceText: string, diagnostics: Diagnostic[], localVariableTypes: Map<string, CppTypeHint>): StatementIR | undefined;
8
+ export declare function lowerControlFlowStatement(statement: ts.Statement, fileName: string, sourceText: string, diagnostics: Diagnostic[], functionReturnTypes: Map<string, CppTypeHint>, localVariableTypes: Map<string, CppTypeHint>, functionNameForDiagnostics: string, typeAliases?: Map<string, ts.TypeNode>, pointerVars?: PointerTracker): StatementIR[] | null;