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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/dist/api/config.d.ts +32 -0
  2. package/dist/api/index.d.ts +1 -1
  3. package/dist/api/schema/types.d.ts +15 -0
  4. package/dist/api/shared/async-runtime-static.d.ts +12 -1
  5. package/dist/api/shared/async-runtime-static.js +69 -24
  6. package/dist/api/shared/async-symbol-detector.d.ts +11 -0
  7. package/dist/api/shared/async-symbol-detector.js +140 -0
  8. package/dist/api/shared/async-types.d.ts +24 -0
  9. package/dist/api/shared/coop-scheduler.d.ts +60 -0
  10. package/dist/api/shared/coop-scheduler.js +149 -0
  11. package/dist/api/shared/display-adapter.d.ts +4 -3
  12. package/dist/api/shared/display-adapter.js +15 -118
  13. package/dist/api/shared/display-adapters/sdl.js +38 -31
  14. package/dist/api/shared/display-profile.d.ts +47 -25
  15. package/dist/api/shared/display-profile.js +31 -164
  16. package/dist/api/shared/framework-manifest-registry.d.ts +9 -0
  17. package/dist/api/shared/framework-manifest-registry.js +27 -0
  18. package/dist/api/shared/framework-manifest.d.ts +581 -0
  19. package/dist/api/shared/framework-manifest.js +182 -0
  20. package/dist/api/shared/glcdfont.d.ts +12 -0
  21. package/dist/api/shared/glcdfont.js +124 -0
  22. package/dist/api/shared/graphics-strategy.d.ts +37 -0
  23. package/dist/api/shared/hal-op-ir.d.ts +755 -1
  24. package/dist/api/shared/hal-op-ir.js +129 -1
  25. package/dist/api/shared/index.d.ts +20 -2
  26. package/dist/api/shared/index.js +25 -1
  27. package/dist/api/shared/ir-core.d.ts +4 -0
  28. package/dist/api/shared/ir-declarations.d.ts +6 -0
  29. package/dist/api/shared/native-display-op-resolver.d.ts +10 -0
  30. package/dist/api/shared/native-display-op-resolver.js +64 -0
  31. package/dist/api/shared/platform-strategy.d.ts +113 -2
  32. package/dist/api/shared/polyfill-helper-registry.js +18 -1
  33. package/dist/api/shared/promise-runtime.d.ts +1 -1
  34. package/dist/api/shared/promise-runtime.js +95 -13
  35. package/dist/api/shared/toolchain-types.d.ts +17 -0
  36. package/dist/api/shared/validate-framework-manifest.d.ts +28 -0
  37. package/dist/api/shared/validate-framework-manifest.js +494 -0
  38. package/dist/api/shared/worker-runtime-polyfill.d.ts +22 -0
  39. package/dist/api/shared/worker-runtime-polyfill.js +34 -0
  40. package/dist/api/shared/worker-runtime.d.ts +69 -0
  41. package/dist/api/shared/worker-runtime.js +163 -0
  42. package/dist/cli.js +186 -82
  43. package/dist/config-loader.d.ts +7 -2
  44. package/dist/config-loader.js +23 -3
  45. package/dist/config-schema.d.ts +112 -70
  46. package/dist/config-schema.js +14 -0
  47. package/dist/contract/board-generator.d.ts +17 -0
  48. package/dist/contract/board-generator.js +57 -0
  49. package/dist/contract/contract-parser.d.ts +217 -0
  50. package/dist/contract/contract-parser.js +224 -0
  51. package/dist/contract/index.d.ts +22 -0
  52. package/dist/contract/index.js +68 -0
  53. package/dist/create/board-codegen.js +4 -4
  54. package/dist/create/board-generators.js +4 -5
  55. package/dist/create/board-spec.d.ts +72 -75
  56. package/dist/create/board-spec.js +0 -1
  57. package/dist/create/init-scaffold.d.ts +9 -2
  58. package/dist/create/init-scaffold.js +0 -14
  59. package/dist/create/init-templates.d.ts +2 -0
  60. package/dist/create/init-templates.js +74 -8
  61. package/dist/create/init-wizard.js +31 -7
  62. package/dist/debug/preprocessor.js +178 -39
  63. package/dist/debug/types.d.ts +23 -0
  64. package/dist/diagnostics/mermaid-builder.d.ts +1 -1
  65. package/dist/diagnostics/mermaid-builder.js +34 -24
  66. package/dist/emit/compliance/arxml-writer.d.ts +11 -0
  67. package/dist/emit/compliance/arxml-writer.js +34 -0
  68. package/dist/emit/compliance/compliance-context.d.ts +57 -0
  69. package/dist/emit/compliance/compliance-context.js +113 -0
  70. package/dist/emit/compliance/deviation-ledger.d.ts +27 -0
  71. package/dist/emit/compliance/deviation-ledger.js +47 -0
  72. package/dist/emit/compliance/deviation-writer.d.ts +30 -0
  73. package/dist/emit/compliance/deviation-writer.js +37 -0
  74. package/dist/emit/compliance/index.d.ts +7 -0
  75. package/dist/emit/compliance/index.js +6 -0
  76. package/dist/emit/compliance/rule-engine.d.ts +13 -0
  77. package/dist/emit/compliance/rule-engine.js +101 -0
  78. package/dist/emit/compliance/rules.d.ts +16 -0
  79. package/dist/emit/compliance/rules.js +191 -0
  80. package/dist/emit/compliance/types.d.ts +59 -0
  81. package/dist/emit/compliance/types.js +8 -0
  82. package/dist/emit/cpp-emitter.js +4 -3
  83. package/dist/emit/emitters/class-emitter.js +6 -1
  84. package/dist/emit/emitters/emitter-context.d.ts +28 -1
  85. package/dist/emit/emitters/function-emitter-impl.js +153 -53
  86. package/dist/emit/emitters/line-appender.js +19 -0
  87. package/dist/emit/emitters/line-marker.d.ts +38 -0
  88. package/dist/emit/emitters/line-marker.js +39 -0
  89. package/dist/emit/emitters/output-finalizer.d.ts +6 -0
  90. package/dist/emit/emitters/output-finalizer.js +101 -12
  91. package/dist/emit/emitters/setup.d.ts +17 -0
  92. package/dist/emit/emitters/setup.js +257 -36
  93. package/dist/emit/emitters/top-level-prep.js +8 -0
  94. package/dist/emit/emitters/type-decl-emitter.js +28 -3
  95. package/dist/emit/emitters/ui-emitter.js +33 -9
  96. package/dist/emit/expression-renderer.d.ts +1 -1
  97. package/dist/emit/expression-renderer.js +91 -6
  98. package/dist/emit/route-hal-op.js +18 -5
  99. package/dist/emit/snprintf-helpers.js +15 -4
  100. package/dist/emit/statement-renderer.d.ts +10 -0
  101. package/dist/emit/statement-renderer.js +34 -5
  102. package/dist/emit/utils/async-state-machine.js +221 -125
  103. package/dist/emit/utils/hal-op-cpp-type.d.ts +6 -0
  104. package/dist/emit/utils/hal-op-cpp-type.js +40 -0
  105. package/dist/framework-package.js +2 -0
  106. package/dist/framework-registry.d.ts +17 -0
  107. package/dist/ir/adc-range-validation.js +14 -1
  108. package/dist/ir/build-ir-state.d.ts +1 -0
  109. package/dist/ir/build-ir-state.js +14 -0
  110. package/dist/ir/build-ir.js +9 -5
  111. package/dist/ir/call-graph.js +16 -0
  112. package/dist/ir/expression-to-ir.js +164 -0
  113. package/dist/ir/feature-registry.js +7 -25
  114. package/dist/ir/function-builder.js +22 -0
  115. package/dist/ir/hal/hal-emitter.d.ts +5 -2
  116. package/dist/ir/hal/hal-emitter.js +50 -18
  117. package/dist/ir/hal/hal-parser.d.ts +6 -0
  118. package/dist/ir/hal/hal-parser.js +81 -0
  119. package/dist/ir/hal/hal-plugins.js +723 -1
  120. package/dist/ir/identifier-collector.js +35 -0
  121. package/dist/ir/interrupt-analysis.d.ts +5 -1
  122. package/dist/ir/interrupt-analysis.js +8 -16
  123. package/dist/ir/network-validation.d.ts +4 -0
  124. package/dist/ir/network-validation.js +184 -0
  125. package/dist/ir/ownership-analysis.js +20 -1
  126. package/dist/ir/pin-capability-validation.js +37 -0
  127. package/dist/ir/pin-mode-validation.d.ts +2 -2
  128. package/dist/ir/pin-mode-validation.js +49 -18
  129. package/dist/ir/program-analysis.d.ts +65 -0
  130. package/dist/ir/program-analysis.js +318 -2
  131. package/dist/ir/render-expr.js +11 -0
  132. package/dist/ir/timing-validation.d.ts +6 -1
  133. package/dist/ir/timing-validation.js +60 -13
  134. package/dist/ir/transformers/call-statement.js +105 -0
  135. package/dist/ir/transformers/expressions.js +62 -0
  136. package/dist/ir/transformers/hal-call-resolver.js +21 -0
  137. package/dist/ir/transformers/hal-emit-helpers.js +1 -1
  138. package/dist/ir/transformers/namespace-methods.js +17 -12
  139. package/dist/ir/transformers/ui-reactive.js +2 -2
  140. package/dist/ir/transformers/variables.js +92 -3
  141. package/dist/ir/type-resolution.js +18 -0
  142. package/dist/ir/ui-element-auto-wire.js +7 -5
  143. package/dist/ir/utils/map-statements.d.ts +4 -0
  144. package/dist/ir/utils/map-statements.js +79 -0
  145. package/dist/ir/validation-orchestrator.js +9 -2
  146. package/dist/ir/worker-analysis.d.ts +10 -0
  147. package/dist/ir/worker-analysis.js +261 -0
  148. package/dist/libdef/c-to-decl.d.ts +27 -0
  149. package/dist/libdef/c-to-decl.js +397 -0
  150. package/dist/libdef/component-decls.d.ts +2 -0
  151. package/dist/libdef/component-decls.js +6 -0
  152. package/dist/libdef/component-discovery.d.ts +43 -0
  153. package/dist/libdef/component-discovery.js +83 -0
  154. package/dist/libdef/cpp-to-decl.d.ts +9 -0
  155. package/dist/libdef/cpp-to-decl.js +72 -0
  156. package/dist/libdef/registry.js +5 -2
  157. package/dist/lint-cache.d.ts +59 -0
  158. package/dist/lint-cache.js +257 -0
  159. package/dist/orchestrator/graph-builder.js +14 -9
  160. package/dist/platform/coop-scheduler-runtime.d.ts +19 -0
  161. package/dist/platform/coop-scheduler-runtime.js +41 -0
  162. package/dist/platform/generic-strategy.d.ts +15 -3
  163. package/dist/platform/generic-strategy.js +49 -4
  164. package/dist/safety/safety-bridge.d.ts +11 -0
  165. package/dist/safety/safety-bridge.js +48 -0
  166. package/dist/safety/sidecar-bridge.d.ts +5 -0
  167. package/dist/safety/sidecar-bridge.js +22 -0
  168. package/dist/safety-hook.d.ts +79 -0
  169. package/dist/safety-hook.js +35 -0
  170. package/dist/testing.d.ts +7 -1
  171. package/dist/testing.js +8 -1
  172. package/dist/transpile.d.ts +3 -0
  173. package/dist/transpile.js +175 -41
  174. package/dist/types.d.ts +13 -2
  175. package/dist/ui-hook.d.ts +17 -3
  176. package/dist/utils/cli.js +78 -4
  177. package/dist/utils/fs.d.ts +13 -0
  178. package/dist/utils/fs.js +50 -0
  179. package/package.json +24 -5
  180. package/dist/api/shared/display-adapters/eink-mono.d.ts +0 -2
  181. package/dist/api/shared/display-adapters/eink-mono.js +0 -53
  182. package/dist/api/shared/display-adapters/ssd1309.d.ts +0 -2
  183. package/dist/api/shared/display-adapters/ssd1309.js +0 -136
  184. package/dist/api/shared/display-adapters/st7796.d.ts +0 -2
  185. package/dist/api/shared/display-adapters/st7796.js +0 -132
  186. package/dist/licenses.d.ts +0 -185
  187. package/dist/licenses.js +0 -963
@@ -15,4 +15,132 @@
15
15
  // the MCU package's pin mapping. The `pin` field provides backward
16
16
  // compatibility as a legacy framework pin number.
17
17
  // ---------------------------------------------------------------------------
18
- export {};
18
+ /**
19
+ * Runtime registry of every HAL operation discriminator, parallel to
20
+ * {@link DISPLAY_OPERATION_KINDS}. Lets tests and the manifest validator
21
+ * enumerate HAL op kinds without parsing types (which are erased at runtime).
22
+ * Keep in sync with {@link HALOpIR} above.
23
+ *
24
+ * Note: `display.*` ops are NOT listed here — they live in
25
+ * {@link DISPLAY_OPERATION_KINDS} in `display-op-ir.ts`. The manifest
26
+ * validator imports both and unions them when probing display ops.
27
+ */
28
+ export const HAL_OPERATION_KINDS = [
29
+ // GPIO
30
+ 'gpio.write', 'gpio.read', 'gpio.toggle', 'gpio.set_mode',
31
+ // PWM
32
+ 'pwm.write', 'pwm.get_frequency', 'pwm.get_resolution',
33
+ // RMT
34
+ 'rmt.tx_init', 'rmt.tx_write_bytes', 'rmt.tx_write_symbols',
35
+ 'rmt.tx_wait_done', 'rmt.tx_deinit',
36
+ 'rmt.rx_init', 'rmt.rx_on_received', 'rmt.rx_start',
37
+ 'rmt.rx_stop', 'rmt.rx_read', 'rmt.rx_deinit',
38
+ // ADC
39
+ 'adc.read', 'adc.get_resolution', 'adc.set_reference',
40
+ 'adc.get_reference', 'adc.read_voltage',
41
+ // DAC
42
+ 'dac.write',
43
+ // Interrupts
44
+ 'interrupt.attach', 'interrupt.detach',
45
+ // Tone
46
+ 'tone.play', 'tone.stop',
47
+ // Timing
48
+ 'timing.delay', 'timing.delay_microseconds', 'timing.millis',
49
+ 'timing.micros', 'timing.free_heap', 'timing.set_interval',
50
+ 'timing.set_timeout', 'timing.clear_interval', 'timing.clear_timeout',
51
+ // Power
52
+ 'power.deep_sleep', 'power.light_sleep', 'power.set_cpu_frequency', 'power.deep_sleep_pin',
53
+ // I2C
54
+ 'i2c.begin', 'i2c.end', 'i2c.set_clock', 'i2c.begin_transmission',
55
+ 'i2c.write', 'i2c.write_bytes', 'i2c.write_buffer', 'i2c.read_buffer',
56
+ 'i2c.end_transmission', 'i2c.request_from', 'i2c.available', 'i2c.read',
57
+ 'i2c.recover',
58
+ // SPI
59
+ 'spi.begin', 'spi.end', 'spi.transfer', 'spi.begin_transaction',
60
+ 'spi.end_transaction', 'spi.set_mode', 'spi.set_bit_order',
61
+ 'spi.cs_low', 'spi.cs_high', 'spi.read_buffer',
62
+ // UART
63
+ 'uart.begin', 'uart.end', 'uart.print', 'uart.println', 'uart.printf',
64
+ 'uart.write', 'uart.read', 'uart.peek', 'uart.available', 'uart.flush',
65
+ // Pulse
66
+ 'pulse.in', 'pulse.in_long',
67
+ // Shift
68
+ 'shift.out', 'shift.in',
69
+ // Board
70
+ 'board.resolve',
71
+ // Watchdog timer
72
+ 'wdt.enable', 'wdt.reset', 'wdt.disable',
73
+ // Snprintf
74
+ 'snprintf.emit',
75
+ // WiFi
76
+ 'wifi.connect', 'wifi.connect_start', 'wifi.disconnect', 'wifi.status',
77
+ 'wifi.is_connected', 'wifi.local_ip', 'wifi.rssi', 'wifi.mac',
78
+ 'wifi.set_hostname', 'wifi.set_static_ip', 'wifi.set_auto_reconnect',
79
+ 'wifi.set_power_save', 'wifi.set_tx_power', 'wifi.on_event',
80
+ 'wifi.ap_start', 'wifi.ap_stop', 'wifi.ap_client_count', 'wifi.ap_ip',
81
+ 'wifi.ap_set_channel', 'wifi.ap_set_hidden', 'wifi.ap_set_max_clients',
82
+ 'wifi.scan', 'wifi.scan_start', 'wifi.scan_done', 'wifi.scan_count',
83
+ 'wifi.scan_ssid', 'wifi.scan_rssi', 'wifi.scan_encryption',
84
+ 'wifi.scan_channel', 'wifi.save_credentials', 'wifi.connect_saved',
85
+ 'wifi.clear_credentials', 'wifi.wait_connected', 'wifi.wait_disconnected',
86
+ // HTTP
87
+ 'http.begin', 'http.reset', 'http.set_header', 'http.set_timeout',
88
+ 'http.set_max_body', 'http.set_body', 'http.set_insecure',
89
+ 'http.set_ca_cert', 'http.send', 'http.send_start', 'http.done',
90
+ 'http.status', 'http.ok', 'http.body', 'http.content_length',
91
+ 'http.response_header',
92
+ // Worker offload (generalized request-in / poll-out over a worker pool)
93
+ 'worker.submit', 'worker.done',
94
+ // BLE (NimBLE GATT peripheral)
95
+ 'ble.server_begin', 'ble.advertise_start', 'ble.advertise_stop',
96
+ 'ble.add_service', 'ble.add_char',
97
+ 'ble.on_read', 'ble.on_write', 'ble.on_connect', 'ble.on_disconnect', 'ble.notify',
98
+ 'ble.is_connected', 'ble.client_count', 'ble.set_name',
99
+ 'ble.until_connected', 'ble.until_connected_start',
100
+ 'ble.set_tx_power', 'ble.status',
101
+ // Preferences (NVS)
102
+ 'preferences.begin', 'preferences.end', 'preferences.clear', 'preferences.remove',
103
+ 'preferences.put_int', 'preferences.get_int',
104
+ 'preferences.put_uint', 'preferences.get_uint',
105
+ 'preferences.put_bool', 'preferences.get_bool',
106
+ 'preferences.put_float', 'preferences.get_float',
107
+ 'preferences.put_string', 'preferences.get_string',
108
+ // Random
109
+ 'random.int', 'random.range', 'random.seed',
110
+ // FS (filesystem)
111
+ 'fs.begin', 'fs.read_text', 'fs.write_text', 'fs.exists', 'fs.remove',
112
+ // mDNS
113
+ 'mdns.start', 'mdns.set_hostname', 'mdns.add_service', 'mdns.announce', 'mdns.stop',
114
+ // MQTT
115
+ 'mqtt.connect', 'mqtt.on_message', 'mqtt.subscribe', 'mqtt.publish', 'mqtt.connected', 'mqtt.disconnect',
116
+ // OTA
117
+ 'ota.from_url', 'ota.begin', 'ota.write', 'ota.apply',
118
+ // Temperature
119
+ 'temp.read',
120
+ // Hardware timer
121
+ 'hwtimer.set_frequency', 'hwtimer.on_overflow', 'hwtimer.start', 'hwtimer.stop',
122
+ // Capacitive touch pins
123
+ 'capacitive.read',
124
+ // I2S / digital audio (unimplemented — declared unsupported by all frameworks)
125
+ 'i2s.init', 'i2s.write', 'i2s.read',
126
+ // TWAI / CAN (unimplemented)
127
+ 'twai.init', 'twai.send', 'twai.receive',
128
+ // USB OTG / USB-Serial-JTAG (unimplemented)
129
+ 'usb.init', 'usb.write', 'usb.read',
130
+ // Ethernet MAC (unimplemented)
131
+ 'eth.init', 'eth.start', 'eth.is_linked',
132
+ // ESPNOW (unimplemented)
133
+ 'espnow.init', 'espnow.add_peer', 'espnow.send', 'espnow.on_receive',
134
+ // Hardware crypto (unimplemented)
135
+ 'crypto.aes_encrypt', 'crypto.sha256', 'crypto.hmac',
136
+ // Pulse counter (unimplemented)
137
+ 'pcnt.init', 'pcnt.count', 'pcnt.clear',
138
+ // Motor control PWM (unimplemented)
139
+ 'mcpwm.init', 'mcpwm.set_duty', 'mcpwm.start',
140
+ // Raw passthrough
141
+ 'raw',
142
+ ];
143
+ // Compile-time exhaustiveness check: every HAL_OPERATION_KINDS entry must
144
+ // be a valid HALOpIR["operation"]. If you add an op to the const but not the
145
+ // union (or vice versa), this assignment fails to type-check.
146
+ const _halOpKindsExhaustive = [...HAL_OPERATION_KINDS];
@@ -1,13 +1,18 @@
1
1
  export type { Diagnostic, PlatformContext, SourceSpan, TargetProfile } from './types.js';
2
+ export type { GeneratedSourceMap, SourceMapEntry } from '../../types.js';
2
3
  export type { CppTypeIR, CppTypeKind, CppPrimitiveName, CppFormatKind, } from './cpp-type-ir.js';
3
4
  export { parseCppType, renderCppType, splitTemplateArgs, isPointer, isReference, isContainer, isVector, isMap, isSet, isTuple, isVariant, isStdFunction, isStaticArray, isCArray, isStringLike, isPrimitive, bareType, elementOf, formatKindOf, CppTypeIR as cppTypeIRBuilder, parsedIsPointer, parsedIsStringLike, parsedIsPrimitive, parsedIsContainer, parsedIsVector, parsedIsMap, parsedIsSet, parsedIsTuple, parsedIsVariant, parsedIsStaticArray, parsedIsStdString, parsedElementOf, parsedElementString, parsedBareString, parsedBareType, collectNamedTypes, parsedCollectNamedTypes, needsCStrForStringLike, parsedIsPlainStructType, } from './cpp-type-ir.js';
4
5
  export type { ExpressionIR, StatementIR, ProgramIR, ImportIR, ReExportIR, CallExpressionIR, SuperCallIR, VariableDeclarationIR, AssignmentIR, UpdateIR, ReturnIR, WhileIR, IfIR, ForIR, ForOfIR, ForInIR, BreakIR, ContinueIR, DoWhileIR, SwitchIR, CaseIR, TryIR, ThrowIR, LabeledIR, BlockIR, HALOpStatementIR, FunctionIR, StructDefIR, EnumIR, ClassFieldIR, ClassConstructorIR, ClassMethodIR, ClassGetterIR, ClassSetterIR, ClassIR, InterfaceIR, TypeAliasIR, NamespaceIR, PeripheralUsageIR, RegisterBitFieldIR, RegisterClassIR, ParameterIR, CppType, } from './ir.js';
5
6
  export type { HALOpIR, HALOperationKind, } from './hal-op-ir.js';
7
+ export { HAL_OPERATION_KINDS } from './hal-op-ir.js';
6
8
  export type { DisplayInitOp, DisplayFillRectOp, DisplayDrawTextOp, DisplayDrawRectOp, DisplayFlushOp, DisplayHALOp, } from './display-op-ir.js';
7
9
  export { DISPLAY_OPERATION_KINDS } from './display-op-ir.js';
8
10
  export type { PlatformGraphicsStrategy, GraphicsCapacity } from './graphics-strategy.js';
9
- export type { DisplayProfile, DisplayConfig, DisplaySize, TouchProfile, TouchLibrary, ResolvedDisplay } from './display-profile.js';
10
- export { effectiveDisplaySize, normalizeDisplayRotation, resolveDisplayProfile, resolveScrollConfig, DEFAULT_SCROLL_CANVAS_BUDGET_BYTES } from './display-profile.js';
11
+ export type { DisplayProfile, DisplayConfig, DisplaySize, TouchProfile, TouchLibrary, TouchAdapterCodegen, ResolvedDisplay } from './display-profile.js';
12
+ export { effectiveDisplaySize, normalizeDisplayRotation, resolveDisplayProfile, resolveScrollConfig } from './display-profile.js';
13
+ export { GLCDFONT_BYTES, renderGlcdfontArray } from './glcdfont.js';
14
+ export type { DisplayAdapterCode, DisplayAdapterGenerator } from './display-adapter.js';
15
+ export { resolveNativeDisplayOp } from './native-display-op-resolver.js';
11
16
  export type { DisplayCapabilities, DisplayFeatureFlags, NativeFormat, RefreshModel, PartialRefreshScope, } from './display-capabilities.js';
12
17
  export { defaultTftCapabilities, deriveCapabilities } from './display-capabilities.js';
13
18
  export type { BoardConstants } from './board-resolver.js';
@@ -21,6 +26,19 @@ export { POLYFILL_HELPER_MAP, filterPolyfillHelpers } from './polyfill-helper-re
21
26
  export { STRING_METHODS, STRING_METHOD_NAMES, applyStringMethodRewrites } from './string-method-registry.js';
22
27
  export type { StringMethodSpec, StringMethodArgForm } from './string-method-registry.js';
23
28
  export { isStringEnum } from './ir-declarations.js';
29
+ export { mapProgramStatements } from '../../ir/utils/map-statements.js';
30
+ export { programUsesSafety } from '../../emit/emitters/setup.js';
24
31
  export type { AsyncRuntimeConfig } from './async-types.js';
25
32
  export { generatePromiseRuntime } from './promise-runtime.js';
26
33
  export { generateStaticAsyncRuntime } from './async-runtime-static.js';
34
+ export { generateCoopScheduler, buildCoopSchedInjection } from './coop-scheduler.js';
35
+ export type { CoopWorkUnit, CoopSchedOptions } from './coop-scheduler.js';
36
+ export { generateWorkerRuntime, lowerWorkerOp } from './worker-runtime.js';
37
+ export type { WorkerRuntimeOptions, WorkerBacking } from './worker-runtime.js';
38
+ export { buildWorkerRuntimePolyfill } from './worker-runtime-polyfill.js';
39
+ export { FrameworkManifestSchema, defineFrameworkManifest, HAL_CATEGORIES, POLYFILL_BACKED_OPS, } from './framework-manifest.js';
40
+ export type { FrameworkManifest, HalCategory, } from './framework-manifest.js';
41
+ export { KNOWN_FRAMEWORK_PACKAGES, loadFrameworkManifest, } from './framework-manifest-registry.js';
42
+ export type { KnownFrameworkPackage } from './framework-manifest-registry.js';
43
+ export { validateFrameworkManifest } from './validate-framework-manifest.js';
44
+ export type { ManifestValidationContext, ManifestValidationResult, ManifestValidationError, ManifestValidationWarning, } from './validate-framework-manifest.js';
@@ -4,8 +4,16 @@
4
4
  // Re-exports all shared types for use by CLI and framework packages.
5
5
  // ---------------------------------------------------------------------------
6
6
  export { parseCppType, renderCppType, splitTemplateArgs, isPointer, isReference, isContainer, isVector, isMap, isSet, isTuple, isVariant, isStdFunction, isStaticArray, isCArray, isStringLike, isPrimitive, bareType, elementOf, formatKindOf, CppTypeIR as cppTypeIRBuilder, parsedIsPointer, parsedIsStringLike, parsedIsPrimitive, parsedIsContainer, parsedIsVector, parsedIsMap, parsedIsSet, parsedIsTuple, parsedIsVariant, parsedIsStaticArray, parsedIsStdString, parsedElementOf, parsedElementString, parsedBareString, parsedBareType, collectNamedTypes, parsedCollectNamedTypes, needsCStrForStringLike, parsedIsPlainStructType, } from './cpp-type-ir.js';
7
+ export { HAL_OPERATION_KINDS } from './hal-op-ir.js';
7
8
  export { DISPLAY_OPERATION_KINDS } from './display-op-ir.js';
8
- export { effectiveDisplaySize, normalizeDisplayRotation, resolveDisplayProfile, resolveScrollConfig, DEFAULT_SCROLL_CANVAS_BUDGET_BYTES } from './display-profile.js';
9
+ export { effectiveDisplaySize, normalizeDisplayRotation, resolveDisplayProfile, resolveScrollConfig } from './display-profile.js';
10
+ // Shared 5x7 glcdfont table (Adafruit public-domain source). Consumed by
11
+ // the SDL preview adapter and the native CuttlefishGFX runtime-header slice.
12
+ export { GLCDFONT_BYTES, renderGlcdfontArray } from './glcdfont.js';
13
+ // Native display-op resolver — lowers display.* HAL ops into calls against
14
+ // the adapter surface (display_init / display_targetFillRect / etc.). Used
15
+ // by NativeAVRStrategy and Esp32Strategy's resolveDisplayOp overrides.
16
+ export { resolveNativeDisplayOp } from './native-display-op-resolver.js';
9
17
  export { defaultTftCapabilities, deriveCapabilities } from './display-capabilities.js';
10
18
  export { getStdLibSupport, DEFAULT_STDLIB_SUPPORT } from './polyfill-types.js';
11
19
  export { parseCompileErrors, collectCppFiles } from './toolchain-types.js';
@@ -15,7 +23,23 @@ export { POLYFILL_HELPER_MAP, filterPolyfillHelpers } from './polyfill-helper-re
15
23
  export { STRING_METHODS, STRING_METHOD_NAMES, applyStringMethodRewrites } from './string-method-registry.js';
16
24
  // Runtime helpers
17
25
  export { isStringEnum } from './ir-declarations.js';
26
+ // IR transform helpers (used by the optional @typecad/safety package's pass)
27
+ export { mapProgramStatements } from '../../ir/utils/map-statements.js';
28
+ // Safety-use detector (used by framework strategies to gate __tc_gpio_read
29
+ // shim emission — mirrors programUsesWdt for the watchdog).
30
+ export { programUsesSafety } from '../../emit/emitters/setup.js';
18
31
  // Promise runtime generator (heap-based: ESP32/ESP8266/rp2040/samd/…)
19
32
  export { generatePromiseRuntime } from './promise-runtime.js';
20
33
  // Heap-free static async runtime generator (AVR / megaavr / no-<vector> targets)
21
34
  export { generateStaticAsyncRuntime } from './async-runtime-static.js';
35
+ // No-STL cooperative scheduler (priority + time-budget) — Zephyr-friendly
36
+ export { generateCoopScheduler, buildCoopSchedInjection } from './coop-scheduler.js';
37
+ // Worker offload runtime (generalized request-in / poll-out)
38
+ export { generateWorkerRuntime, lowerWorkerOp } from './worker-runtime.js';
39
+ export { buildWorkerRuntimePolyfill } from './worker-runtime-polyfill.js';
40
+ // Framework manifest schema + helper
41
+ export { FrameworkManifestSchema, defineFrameworkManifest, HAL_CATEGORIES, POLYFILL_BACKED_OPS, } from './framework-manifest.js';
42
+ // Framework manifest discovery
43
+ export { KNOWN_FRAMEWORK_PACKAGES, loadFrameworkManifest, } from './framework-manifest-registry.js';
44
+ // Framework manifest validator
45
+ export { validateFrameworkManifest } from './validate-framework-manifest.js';
@@ -134,7 +134,11 @@ export type ExpressionIR = {
134
134
  isPointer?: boolean;
135
135
  restElementType?: string;
136
136
  cppType?: string;
137
+ receiverExpr?: ExpressionIR;
138
+ methodName?: string;
137
139
  }
140
+ /** A receiverless call: `Name(args)` (free function or constructor). Method-on-receiver calls lower as "method-call"; this is the receiverless form, e.g. `SafeInt(x)`. */
141
+ | CallExpressionIR
138
142
  /** Array element access: `object[index]`. */
139
143
  | {
140
144
  kind: "element-access";
@@ -19,6 +19,10 @@ export interface FunctionIR {
19
19
  isGenerator?: boolean;
20
20
  /** True when the function is exported (has `export` keyword). */
21
21
  isExported?: boolean;
22
+ /** Decorators applied to this function (e.g. ["asilD"]). Mirrors
23
+ * ClassIR.decorators. Used by the safety hook's analyzeIR to gate
24
+ * ISO 26262 rule enforcement by ASIL level. */
25
+ decorators?: string[];
22
26
  }
23
27
  export interface StructDefIR {
24
28
  name: string;
@@ -80,6 +84,8 @@ export interface ClassMethodIR {
80
84
  typeParameters?: string[];
81
85
  /** True when this is a generator method. */
82
86
  isGenerator?: boolean;
87
+ /** Decorators applied to this method (e.g. ["asilD"]). */
88
+ decorators?: string[];
83
89
  }
84
90
  export interface ClassGetterIR {
85
91
  name: string;
@@ -0,0 +1,10 @@
1
+ import type { DisplayHALOp } from "./display-op-ir.js";
2
+ /**
3
+ * Resolve a display HAL op to a call into the native adapter surface
4
+ * (display_init / display_targetFillRect / etc.). Returns undefined for ops
5
+ * this resolver does not handle.
6
+ */
7
+ export declare function resolveNativeDisplayOp(op: DisplayHALOp): {
8
+ code?: string;
9
+ expression?: string;
10
+ } | undefined;
@@ -0,0 +1,64 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Shared display-op resolver for native (non-Arduino) display strategies.
3
+ //
4
+ // Both NativeAVRStrategy and Esp32Strategy override resolveDisplayOp to return
5
+ // undefined for display.* ops (the design intent: display ops are resolved
6
+ // through the adapter path, not per-op HAL lowering). But the HAL lowering
7
+ // layer still calls resolveDisplayOp for every display.* op emitted by user
8
+ // code (display.init via ui.mount, display.fill_rect/draw_rect/draw_text via
9
+ // direct HAL calls, display.flush per frame).
10
+ //
11
+ // Those ops need to lower to CALLS INTO the adapter surface — the same
12
+ // display_init() / display_targetFillRect() / etc. functions the Adafruit
13
+ // path calls. The native adapters emit those functions with identical
14
+ // signatures, so the lowering is identical across native strategies.
15
+ //
16
+ // This module provides that lowering. Each native strategy's resolveDisplayOp
17
+ // delegates here instead of returning undefined.
18
+ // ---------------------------------------------------------------------------
19
+ /** Render a color value as a C++ hex literal (e.g. 0x07e0) for readable RGB565. */
20
+ function hexColor(c) {
21
+ return `0x${c.toString(16)}`;
22
+ }
23
+ /**
24
+ * Resolve a display HAL op to a call into the native adapter surface
25
+ * (display_init / display_targetFillRect / etc.). Returns undefined for ops
26
+ * this resolver does not handle.
27
+ */
28
+ export function resolveNativeDisplayOp(op) {
29
+ switch (op.operation) {
30
+ case "display.init":
31
+ // The adapter's display_init() does bus setup, panel init sequence,
32
+ // rotation, and the initial fillScreen. No backlight GPIO parameter
33
+ // on native paths — the Adafruit-style backlight pin is handled in
34
+ // the mount config if needed.
35
+ return { code: `display_init();` };
36
+ case "display.fill_rect":
37
+ // Delegate to the polymorphic target draw so the same call works
38
+ // whether the active target is the panel or an offscreen canvas.
39
+ return {
40
+ code: `display_targetFillRect(display_defaultTarget(), ${op.x}, ${op.y}, ${op.w}, ${op.h}, ${hexColor(op.color)});`,
41
+ };
42
+ case "display.draw_rect":
43
+ return {
44
+ code: `display_targetDrawRect(display_defaultTarget(), ${op.x}, ${op.y}, ${op.w}, ${op.h}, ${hexColor(op.color)});`,
45
+ };
46
+ case "display.draw_text":
47
+ return {
48
+ code: [
49
+ `display_targetSetCursor(display_defaultTarget(), ${op.x}, ${op.y});`,
50
+ `display_targetSetTextColor(display_defaultTarget(), ${hexColor(op.color)});`,
51
+ `display_targetSetTextSize(display_defaultTarget(), 2);`,
52
+ `display_targetPrint(display_defaultTarget(), ${JSON.stringify(op.text)});`,
53
+ ].join("\n"),
54
+ };
55
+ case "display.flush":
56
+ // Direct-mode panels (ILI9341, ST7796S) draw immediately — no flush.
57
+ // Buffered panels (SSD1309) flush via display_partial_refresh, which
58
+ // the runtime calls through display_partial_refresh directly (not via
59
+ // HAL op) at frame end.
60
+ return { code: `/* flush: ${op.rects.length} rect(s) — native display */` };
61
+ default:
62
+ return undefined;
63
+ }
64
+ }
@@ -108,8 +108,13 @@ export interface PlatformTypeStrategy {
108
108
  * when the enum members map directly to platform preprocessor macros.
109
109
  */
110
110
  passthroughEnumNames?(): ReadonlySet<string>;
111
- /** Default numeric type for the platform (e.g. "int" on hosted, "int32_t" on embedded). */
112
- defaultNumericType(): string;
111
+ /**
112
+ * Default numeric type for the platform (e.g. "int" on hosted, "int32_t" on embedded).
113
+ * Optional compliance context: when A3-9-1 is enforced, returns a fixed-width type.
114
+ */
115
+ defaultNumericType(compliance?: {
116
+ isBanned(ruleId: string): boolean;
117
+ }): string;
113
118
  /**
114
119
  * Inform the strategy which enums have values exceeding the signed 16-bit range.
115
120
  * The strategy can use this to choose an appropriate underlying type.
@@ -279,6 +284,15 @@ export interface PlatformSafetyStrategy {
279
284
  * StaticArray wrapper's methods or the std::vector/__tc_* helper form.
280
285
  */
281
286
  promotesArrayLiteralsToStaticArray?(): boolean;
287
+ /**
288
+ * Whether this target runs on a preemptive RTOS where blocking calls
289
+ * (e.g. vTaskDelay) yield the CPU to other tasks. When true, delay() inside
290
+ * loop() does NOT freeze the async queue or UI rendering — the timing
291
+ * validator suppresses the 'blocking-delay-in-loop' warning for plain delay().
292
+ * Defaults to false (Arduino/AVR use cooperative scheduling where delay
293
+ * freezes everything). ESP-IDF (FreeRTOS) returns true.
294
+ */
295
+ isRtosTarget?(): boolean;
282
296
  }
283
297
  export interface PlatformBuildStrategy {
284
298
  /** Queue capacity for the async microtask ring buffer. */
@@ -298,12 +312,32 @@ export interface PlatformBuildStrategy {
298
312
  /** Standard library support for the given architecture. */
299
313
  getStdLibSupport(architecture?: string): StdLibSupport;
300
314
  }
315
+ /**
316
+ * Coarse C++ type category carried per debug variable, so printf-based codegens
317
+ * (ESP-IDF) can pick the right format specifier. Inferred by the debug
318
+ * preprocessor from AST shape (no TypeChecker); `unknown` is the fallback.
319
+ * Mirrors `DebugCppType` in cuttlefish/src/debug/types.ts — duplicated here to
320
+ * avoid a cross-module import from the api surface.
321
+ */
322
+ export type DebugCppType = 'bool' | 'int' | 'long' | 'float' | 'string' | 'unknown';
301
323
  /**
302
324
  * Debug code generation sub-interface.
303
325
  * Frameworks implement these to provide platform-specific debug output
304
326
  * (e.g., Serial.println on embedded, std::cout on hosted targets).
305
327
  */
306
328
  export interface PlatformDebugStrategy {
329
+ /**
330
+ * Debug mode for the given build target. Controls whether `--debug` emits
331
+ * GDB-oriented output (`#line` directives + debug config artifacts, value
332
+ * `'gdb'`) or the legacy printf/Serial instrumentation (`'printf'`).
333
+ *
334
+ * Frameworks that support native source-level debugging for a chip return
335
+ * `'gdb'` for that target; everything else inherits the `'printf'` default
336
+ * and the existing instrumentation path is used unchanged.
337
+ *
338
+ * @param target the frameworkData.buildTarget value (e.g. 'esp32s3')
339
+ */
340
+ debugMode?(target?: string): 'gdb' | 'printf';
307
341
  /** Generate initialization code for the debug subsystem. */
308
342
  generateDebugInitCode?(): string[];
309
343
  /** Generate code for a breakpoint with optional condition and variable dump. */
@@ -314,8 +348,16 @@ export interface PlatformDebugStrategy {
314
348
  variables: Array<{
315
349
  name: string;
316
350
  isFunction?: boolean;
351
+ cppType?: DebugCppType;
317
352
  }>;
318
353
  normalizedCondition?: string;
354
+ /**
355
+ * Stable per-file ID assigned by the preprocessor. When present, the
356
+ * codegen emits a `static bool __tc_bp_disabled_<id>` flag and wraps the
357
+ * halt in `if (!__tc_bp_disabled_<id>)`, so the user can skip/disable this
358
+ * one breakpoint for the rest of the run (the 's' key sets the flag).
359
+ */
360
+ breakpointId?: number;
319
361
  }): string[];
320
362
  /** Generate code for a logpoint with interpolated message parts. */
321
363
  generateDebugLogpointCode?(params: {
@@ -328,6 +370,7 @@ export interface PlatformDebugStrategy {
328
370
  variables: Array<{
329
371
  name: string;
330
372
  isFunction?: boolean;
373
+ cppType?: DebugCppType;
331
374
  }>;
332
375
  }): string[];
333
376
  }
@@ -362,6 +405,27 @@ export interface PlatformAsyncStrategy {
362
405
  preIteration: string;
363
406
  postIteration: string;
364
407
  } | null;
408
+ /**
409
+ * C++ statements that spawn the worker for slot `handleId`, running
410
+ * `fn(arg)`. Emitted as the body of __tc_worker_submit. Return undefined
411
+ * to declare worker offload unsupported on this framework.
412
+ *
413
+ * The shared runtime has already recorded `waiter`/set `done=false` before
414
+ * this runs; the hook need only spawn. `fn` and `arg` are C++ expressions
415
+ * (a function pointer and a void*).
416
+ */
417
+ workerSpawnLines?(handleId: number, fn: string, arg: string): string[] | undefined;
418
+ /**
419
+ * C++ expression the worker calls AFTER completing its work and writing its
420
+ * outputs, to signal completion to the waiter. Emitted inside the worker
421
+ * trampoline. Must issue a memory barrier. Return undefined if unsupported.
422
+ */
423
+ workerSignalDoneExpr?(handleId: number): string | undefined;
424
+ /**
425
+ * C++ boolean expression polled by __tc_worker_done to test completion.
426
+ * Must observe the signal's memory barrier. Return undefined if unsupported.
427
+ */
428
+ workerIsDoneExpr?(handleId: number): string | undefined;
365
429
  }
366
430
  /**
367
431
  * Strategy for resolving semantic HAL operations to framework-specific C++.
@@ -394,6 +458,53 @@ export interface PlatformHALStrategy {
394
458
  * Default true (preserves existing behavior for hardware strategies).
395
459
  */
396
460
  modelsGpio?(): boolean;
461
+ /**
462
+ * C++ expression that reads the digital level of a pin (HIGH/LOW).
463
+ * ArduinoStrategy returns `digitalRead(${pin})`. GenericStrategy returns a
464
+ * documented no-op stub (no GPIO on host).
465
+ */
466
+ readDigitalPin?(pin: string): string;
467
+ /**
468
+ * C++ expression that reads a raw analog value from an ADC pin.
469
+ * ArduinoStrategy returns `analogRead(${pin})`. GenericStrategy stubs.
470
+ */
471
+ readAnalogPin?(pin: string): string;
472
+ /**
473
+ * C++ statement that writes a digital level to a pin.
474
+ * ArduinoStrategy returns `digitalWrite(${pin}, ${val})`. Cuttlefish does not
475
+ * call this in the current emit path (display reset moves to the framework),
476
+ * but it is part of the atomic surface for completeness/future use.
477
+ */
478
+ writeDigitalPin?(pin: string, val: string): string;
479
+ /**
480
+ * C++ statement that configures a pin's mode.
481
+ * ArduinoStrategy returns `pinMode(${pin}, ${mode})`.
482
+ */
483
+ setPinMode?(pin: string, mode: string): string;
484
+ /**
485
+ * C++ statement that blocks for a number of milliseconds.
486
+ * ArduinoStrategy returns `delay(${ms})`.
487
+ */
488
+ delayMs?(ms: string): string;
489
+ /**
490
+ * C++ statement that blocks for a number of microseconds.
491
+ * ArduinoStrategy returns `delayMicroseconds(${us})`.
492
+ */
493
+ delayMicroseconds?(us: string): string;
494
+ /**
495
+ * The full set of HAL call names this framework's emitted code may contain
496
+ * (digitalRead, analogRead, Serial, tone, millis, …). Used to recognize HAL
497
+ * calls in rendered C++ text where no structured HAL-IR node is available.
498
+ */
499
+ halCallNames?(): ReadonlySet<string>;
500
+ /** Membership test against {@link halCallNames}. Default false on generic. */
501
+ isHalCall?(name: string): boolean;
502
+ /**
503
+ * The subset of {@link halCallNames} that return an analog-read integer
504
+ * value (e.g. analogRead). Used by adc-range-validation to detect ADC reads
505
+ * in lowered raw text.
506
+ */
507
+ analogReadCallNames?(): ReadonlySet<string>;
397
508
  }
398
509
  /**
399
510
  * Full platform strategy composed from focused sub-interfaces.
@@ -62,6 +62,22 @@ export const POLYFILL_HELPER_MAP = {
62
62
  // JSON helpers
63
63
  '__tc_jsonStringify(': ['__tc_jsonStringify'],
64
64
  '__tc_jsonParse(': ['__tc_jsonParse'],
65
+ // Safety helpers — emitted by @typecad/safety's polyfills as global-scope
66
+ // __tc_safety_* free functions (the polyfill-helper-registry extractor
67
+ // expects __tc_* immediately followed by `(`, so namespaced names would be
68
+ // missed). The call-pattern keys are the substrings program analysis scans
69
+ // source for; the values are the __tc_safety_* names that
70
+ // filterPolyfillHelpers matches in helperFunctions text.
71
+ //
72
+ // Two key forms per helper: the user-facing safe.* source spelling (which
73
+ // program analysis sees in raw IR before lowering) and the lowered
74
+ // __tc_safety_* spelling (which appears after the safety call-statement
75
+ // transformer emits hal-op resolution text). Both map to the same helper.
76
+ 'safe.read(': ['__tc_safety_read_safe'],
77
+ 'safe.write(': ['__tc_safety_write_verify'],
78
+ '__tc_safety_record_pin_mode(': ['__tc_safety_record_pin_mode'],
79
+ '__tc_safety_read_safe(': ['__tc_safety_read_safe'],
80
+ '__tc_safety_write_verify(': ['__tc_safety_write_verify'],
65
81
  };
66
82
  function extractHelperFunctionNames(funcDef) {
67
83
  const matches = funcDef.matchAll(/\b(__tc_[A-Za-z0-9_]+)\s*\(/g);
@@ -82,5 +98,6 @@ export function filterPolyfillHelpers(polyfills, usedHelpers) {
82
98
  }),
83
99
  })).filter(polyfill => polyfill.helperFunctions.length > 0 ||
84
100
  polyfill.forwardDeclarations.length > 0 ||
85
- polyfill.helperStructs.length > 0);
101
+ polyfill.helperStructs.length > 0 ||
102
+ polyfill.shimMacros.length > 0);
86
103
  }
@@ -7,4 +7,4 @@
7
7
  * @param includeWaitForPinEdge Whether to include the `waitForPinEdge` stub
8
8
  * (used by Arduino targets).
9
9
  */
10
- export declare function generatePromiseRuntime(queueCapacity: number, includeWaitForPinEdge?: boolean): string;
10
+ export declare function generatePromiseRuntime(queueCapacity: number, includeWaitForPinEdge?: boolean, strategy?: import("./platform-strategy.js").PlatformStrategy): string;