@typecad/cuttlefish 0.1.0-alpha.2 → 1.0.0-alpha.11

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 (224) hide show
  1. package/README.md +10 -10
  2. package/dist/api/board-types.d.ts +1 -1
  3. package/dist/api/config.d.ts +38 -2
  4. package/dist/api/index.d.ts +1 -1
  5. package/dist/api/schema/types.d.ts +15 -0
  6. package/dist/api/shared/async-runtime-static.d.ts +12 -1
  7. package/dist/api/shared/async-runtime-static.js +69 -24
  8. package/dist/api/shared/async-symbol-detector.d.ts +11 -0
  9. package/dist/api/shared/async-symbol-detector.js +140 -0
  10. package/dist/api/shared/async-types.d.ts +24 -0
  11. package/dist/api/shared/coop-scheduler.d.ts +60 -0
  12. package/dist/api/shared/coop-scheduler.js +149 -0
  13. package/dist/api/shared/display-adapter.d.ts +4 -3
  14. package/dist/api/shared/display-adapter.js +15 -118
  15. package/dist/api/shared/display-adapters/sdl.js +38 -31
  16. package/dist/api/shared/display-profile.d.ts +47 -25
  17. package/dist/api/shared/display-profile.js +31 -164
  18. package/dist/api/shared/framework-manifest-registry.d.ts +9 -0
  19. package/dist/api/shared/framework-manifest-registry.js +27 -0
  20. package/dist/api/shared/framework-manifest.d.ts +595 -0
  21. package/dist/api/shared/framework-manifest.js +193 -0
  22. package/dist/api/shared/glcdfont.d.ts +12 -0
  23. package/dist/api/shared/glcdfont.js +124 -0
  24. package/dist/api/shared/graphics-strategy.d.ts +37 -0
  25. package/dist/api/shared/hal-op-ir.d.ts +764 -1
  26. package/dist/api/shared/hal-op-ir.js +129 -1
  27. package/dist/api/shared/index.d.ts +22 -2
  28. package/dist/api/shared/index.js +26 -1
  29. package/dist/api/shared/ir-core.d.ts +4 -0
  30. package/dist/api/shared/ir-declarations.d.ts +6 -0
  31. package/dist/api/shared/native-display-op-resolver.d.ts +10 -0
  32. package/dist/api/shared/native-display-op-resolver.js +64 -0
  33. package/dist/api/shared/platform-strategy.d.ts +119 -2
  34. package/dist/api/shared/polyfill-helper-registry.js +18 -1
  35. package/dist/api/shared/promise-runtime.d.ts +1 -1
  36. package/dist/api/shared/promise-runtime.js +95 -13
  37. package/dist/api/shared/spdx-licenses.d.ts +139 -0
  38. package/dist/api/shared/spdx-licenses.js +385 -0
  39. package/dist/api/shared/toolchain-types.d.ts +17 -0
  40. package/dist/api/shared/types.d.ts +8 -0
  41. package/dist/api/shared/validate-framework-manifest.d.ts +28 -0
  42. package/dist/api/shared/validate-framework-manifest.js +494 -0
  43. package/dist/api/shared/worker-runtime-polyfill.d.ts +22 -0
  44. package/dist/api/shared/worker-runtime-polyfill.js +34 -0
  45. package/dist/api/shared/worker-runtime.d.ts +69 -0
  46. package/dist/api/shared/worker-runtime.js +163 -0
  47. package/dist/cli-utils.d.ts +1 -0
  48. package/dist/cli-utils.js +3 -1
  49. package/dist/cli.js +249 -32
  50. package/dist/config-loader.d.ts +7 -2
  51. package/dist/config-loader.js +23 -3
  52. package/dist/config-schema.d.ts +112 -70
  53. package/dist/config-schema.js +14 -0
  54. package/dist/contract/board-generator.d.ts +17 -0
  55. package/dist/contract/board-generator.js +57 -0
  56. package/dist/contract/contract-parser.d.ts +217 -0
  57. package/dist/contract/contract-parser.js +224 -0
  58. package/dist/contract/index.d.ts +22 -0
  59. package/dist/contract/index.js +68 -0
  60. package/dist/create/board-codegen.js +4 -4
  61. package/dist/create/board-generators.js +4 -5
  62. package/dist/create/board-spec.d.ts +72 -75
  63. package/dist/create/board-spec.js +0 -1
  64. package/dist/create/framework-catalog.d.ts +64 -0
  65. package/dist/create/framework-catalog.js +136 -0
  66. package/dist/create/index.d.ts +5 -1
  67. package/dist/create/index.js +3 -1
  68. package/dist/create/init-scaffold.d.ts +12 -3
  69. package/dist/create/init-scaffold.js +49 -14
  70. package/dist/create/init-templates.d.ts +4 -0
  71. package/dist/create/init-templates.js +271 -17
  72. package/dist/create/init-wizard.js +41 -27
  73. package/dist/create/install-deps.d.ts +32 -0
  74. package/dist/create/install-deps.js +46 -0
  75. package/dist/debug/preprocessor.js +178 -39
  76. package/dist/debug/types.d.ts +23 -0
  77. package/dist/diagnostics/mermaid-builder.d.ts +1 -1
  78. package/dist/diagnostics/mermaid-builder.js +34 -24
  79. package/dist/emit/compliance/arxml-writer.d.ts +11 -0
  80. package/dist/emit/compliance/arxml-writer.js +34 -0
  81. package/dist/emit/compliance/compliance-context.d.ts +57 -0
  82. package/dist/emit/compliance/compliance-context.js +113 -0
  83. package/dist/emit/compliance/deviation-ledger.d.ts +27 -0
  84. package/dist/emit/compliance/deviation-ledger.js +47 -0
  85. package/dist/emit/compliance/deviation-writer.d.ts +30 -0
  86. package/dist/emit/compliance/deviation-writer.js +37 -0
  87. package/dist/emit/compliance/index.d.ts +7 -0
  88. package/dist/emit/compliance/index.js +6 -0
  89. package/dist/emit/compliance/rule-engine.d.ts +13 -0
  90. package/dist/emit/compliance/rule-engine.js +101 -0
  91. package/dist/emit/compliance/rules.d.ts +16 -0
  92. package/dist/emit/compliance/rules.js +191 -0
  93. package/dist/emit/compliance/types.d.ts +59 -0
  94. package/dist/emit/compliance/types.js +8 -0
  95. package/dist/emit/cpp-emitter.js +4 -3
  96. package/dist/emit/emitters/class-emitter.js +6 -1
  97. package/dist/emit/emitters/emitter-context.d.ts +28 -1
  98. package/dist/emit/emitters/function-emitter-impl.js +153 -53
  99. package/dist/emit/emitters/line-appender.js +19 -0
  100. package/dist/emit/emitters/line-marker.d.ts +38 -0
  101. package/dist/emit/emitters/line-marker.js +39 -0
  102. package/dist/emit/emitters/output-finalizer.d.ts +6 -0
  103. package/dist/emit/emitters/output-finalizer.js +101 -12
  104. package/dist/emit/emitters/setup.d.ts +17 -0
  105. package/dist/emit/emitters/setup.js +372 -30
  106. package/dist/emit/emitters/top-level-prep.js +8 -0
  107. package/dist/emit/emitters/type-decl-emitter.js +28 -3
  108. package/dist/emit/emitters/ui-emitter.js +33 -9
  109. package/dist/emit/expression-renderer.d.ts +1 -1
  110. package/dist/emit/expression-renderer.js +91 -6
  111. package/dist/emit/route-hal-op.js +18 -5
  112. package/dist/emit/snprintf-helpers.js +15 -4
  113. package/dist/emit/statement-renderer.d.ts +10 -0
  114. package/dist/emit/statement-renderer.js +34 -5
  115. package/dist/emit/utils/async-state-machine.js +221 -125
  116. package/dist/emit/utils/hal-op-cpp-type.d.ts +6 -0
  117. package/dist/emit/utils/hal-op-cpp-type.js +40 -0
  118. package/dist/framework-package.js +2 -0
  119. package/dist/framework-registry.d.ts +17 -0
  120. package/dist/install/framework-catalog.d.ts +53 -0
  121. package/dist/install/framework-catalog.js +107 -0
  122. package/dist/install/handle-install.d.ts +35 -0
  123. package/dist/install/handle-install.js +177 -0
  124. package/dist/install/index.d.ts +4 -0
  125. package/dist/install/index.js +3 -0
  126. package/dist/ir/adc-range-validation.js +40 -26
  127. package/dist/ir/build-ir-state.d.ts +1 -0
  128. package/dist/ir/build-ir-state.js +14 -0
  129. package/dist/ir/build-ir.js +9 -5
  130. package/dist/ir/call-graph.js +16 -0
  131. package/dist/ir/expression-to-ir.js +207 -6
  132. package/dist/ir/feature-registry.js +7 -25
  133. package/dist/ir/function-builder.js +22 -0
  134. package/dist/ir/hal/hal-emitter.d.ts +5 -2
  135. package/dist/ir/hal/hal-emitter.js +50 -18
  136. package/dist/ir/hal/hal-parser.d.ts +6 -0
  137. package/dist/ir/hal/hal-parser.js +81 -0
  138. package/dist/ir/hal/hal-plugins.js +733 -1
  139. package/dist/ir/identifier-collector.js +35 -0
  140. package/dist/ir/interrupt-analysis.d.ts +5 -1
  141. package/dist/ir/interrupt-analysis.js +16 -19
  142. package/dist/ir/memory-budget-validation.js +1 -0
  143. package/dist/ir/network-validation.d.ts +4 -0
  144. package/dist/ir/network-validation.js +184 -0
  145. package/dist/ir/ownership-analysis.js +39 -1
  146. package/dist/ir/peripheral-ownership.js +5 -0
  147. package/dist/ir/peripheral-validation.d.ts +1 -1
  148. package/dist/ir/peripheral-validation.js +6 -3
  149. package/dist/ir/pin-alias-conflict.d.ts +1 -1
  150. package/dist/ir/pin-alias-conflict.js +2 -1
  151. package/dist/ir/pin-capability-validation.js +71 -32
  152. package/dist/ir/pin-mode-validation.d.ts +2 -2
  153. package/dist/ir/pin-mode-validation.js +54 -18
  154. package/dist/ir/pin-safety.d.ts +1 -1
  155. package/dist/ir/pin-safety.js +2 -1
  156. package/dist/ir/program-analysis.d.ts +81 -0
  157. package/dist/ir/program-analysis.js +429 -0
  158. package/dist/ir/pulldown-validation.d.ts +1 -1
  159. package/dist/ir/pulldown-validation.js +2 -1
  160. package/dist/ir/pwm-timer-sharing.d.ts +1 -1
  161. package/dist/ir/pwm-timer-sharing.js +2 -1
  162. package/dist/ir/render-expr.js +11 -0
  163. package/dist/ir/resource-analysis.js +2 -0
  164. package/dist/ir/timer0-pwm-timing-conflict.d.ts +1 -1
  165. package/dist/ir/timer0-pwm-timing-conflict.js +2 -1
  166. package/dist/ir/timing-validation.d.ts +6 -1
  167. package/dist/ir/timing-validation.js +61 -13
  168. package/dist/ir/transformers/call-statement.js +105 -0
  169. package/dist/ir/transformers/expressions.js +62 -0
  170. package/dist/ir/transformers/hal-call-resolver.js +21 -0
  171. package/dist/ir/transformers/hal-emit-helpers.js +1 -1
  172. package/dist/ir/transformers/namespace-methods.js +17 -12
  173. package/dist/ir/transformers/ui-reactive.js +2 -2
  174. package/dist/ir/transformers/variables.js +137 -19
  175. package/dist/ir/try-catch-validation.js +2 -0
  176. package/dist/ir/type-resolution.js +20 -2
  177. package/dist/ir/ui-element-auto-wire.js +7 -5
  178. package/dist/ir/unit-suspicion-validation.js +9 -7
  179. package/dist/ir/utils/map-statements.d.ts +4 -0
  180. package/dist/ir/utils/map-statements.js +79 -0
  181. package/dist/ir/validation-orchestrator.js +15 -8
  182. package/dist/ir/worker-analysis.d.ts +10 -0
  183. package/dist/ir/worker-analysis.js +261 -0
  184. package/dist/libdef/c-to-decl.d.ts +27 -0
  185. package/dist/libdef/c-to-decl.js +397 -0
  186. package/dist/libdef/component-decls.d.ts +2 -0
  187. package/dist/libdef/component-decls.js +6 -0
  188. package/dist/libdef/component-discovery.d.ts +43 -0
  189. package/dist/libdef/component-discovery.js +83 -0
  190. package/dist/libdef/cpp-to-decl.d.ts +9 -0
  191. package/dist/libdef/cpp-to-decl.js +72 -0
  192. package/dist/libdef/registry.js +5 -2
  193. package/dist/lint-cache.d.ts +59 -0
  194. package/dist/lint-cache.js +257 -0
  195. package/dist/orchestrator/graph-builder.js +14 -9
  196. package/dist/platform/coop-scheduler-runtime.d.ts +19 -0
  197. package/dist/platform/coop-scheduler-runtime.js +41 -0
  198. package/dist/platform/generic-strategy.d.ts +15 -3
  199. package/dist/platform/generic-strategy.js +49 -4
  200. package/dist/safety/safety-bridge.d.ts +11 -0
  201. package/dist/safety/safety-bridge.js +48 -0
  202. package/dist/safety/sidecar-bridge.d.ts +5 -0
  203. package/dist/safety/sidecar-bridge.js +22 -0
  204. package/dist/safety-hook.d.ts +79 -0
  205. package/dist/safety-hook.js +35 -0
  206. package/dist/testing.d.ts +8 -2
  207. package/dist/testing.js +9 -2
  208. package/dist/transpile.d.ts +3 -0
  209. package/dist/transpile.js +191 -49
  210. package/dist/types.d.ts +22 -3
  211. package/dist/ui-hook.d.ts +17 -3
  212. package/dist/utils/cli.js +123 -2
  213. package/dist/utils/fs.d.ts +13 -0
  214. package/dist/utils/fs.js +50 -0
  215. package/dist/utils/ui.js +3 -1
  216. package/package.json +23 -3
  217. package/dist/api/shared/display-adapters/eink-mono.d.ts +0 -2
  218. package/dist/api/shared/display-adapters/eink-mono.js +0 -53
  219. package/dist/api/shared/display-adapters/ssd1309.d.ts +0 -2
  220. package/dist/api/shared/display-adapters/ssd1309.js +0 -136
  221. package/dist/api/shared/display-adapters/st7796.d.ts +0 -2
  222. package/dist/api/shared/display-adapters/st7796.js +0 -132
  223. package/dist/ir/heap-array-validation.d.ts +0 -24
  224. package/dist/ir/heap-array-validation.js +0 -29
@@ -0,0 +1,69 @@
1
+ export interface WorkerRuntimeOptions {
2
+ /** Number of fixed worker slots in the pool. Default 4. */
3
+ poolSize?: number;
4
+ /** Per-slot worker stack size in bytes (ESP32). Default 8192. */
5
+ stackSize?: number;
6
+ }
7
+ /**
8
+ * Per-framework backing primitives injected into the shared contract.
9
+ * Undefined fields mean "unsupported" and the runtime is not emitted.
10
+ */
11
+ export interface WorkerBacking {
12
+ /**
13
+ * Statements that spawn the worker trampoline for slot `handleId`.
14
+ *
15
+ * `trampolineName` is the C++ symbol of the per-slot worker function the
16
+ * shared runtime generated (it reads fn/arg from the slot, runs them, then
17
+ * signals completion). `waiterExpr` is the C++ lvalue the backing should set
18
+ * to the current waiter handle before spawning (the shared runtime reads it
19
+ * via signalDoneExpr/isDoneExpr).
20
+ *
21
+ * The shared runtime has already stored the submitted fn/arg into the slot
22
+ * and cleared `done` before this runs; the backing need only record the
23
+ * waiter and spawn `trampolineName`.
24
+ */
25
+ spawnLines: (handleId: number, trampolineName: string, waiterExpr: string) => string[];
26
+ /** Expression the worker calls after finishing + writing outputs (barrier). */
27
+ signalDoneExpr: (handleId: number) => string;
28
+ /** Boolean expression polled by __tc_worker_done (observes the barrier). */
29
+ isDoneExpr: (handleId: number) => string;
30
+ /** C++ headers required by the primitives (e.g. '<freertos/FreeRTOS.h>'). */
31
+ requiredIncludes: string[];
32
+ /** Any backing declarations (e.g. semaphore objects) emitted before the pool. */
33
+ declarations?: string[];
34
+ /**
35
+ * Per-slot backing declarations emitted inside the namespace, one call per
36
+ * slot, before the submit/done functions. Used by backings that need a named
37
+ * per-slot object bound to the trampoline at definition time — e.g. Zephyr's
38
+ * `K_WORK_DEFINE(_work_<i>, __tc_worker_fn_<i>)` + a per-slot semaphore.
39
+ * `trampolineName` is the per-slot worker symbol the shared runtime emitted.
40
+ */
41
+ slotDeclarations?: (handleId: number, trampolineName: string) => string[];
42
+ }
43
+ /**
44
+ * Generate the worker-offload runtime C++ for a framework that supplies a
45
+ * backing. Returns null if `backing` is null (unsupported on this framework).
46
+ *
47
+ * The emitted code defines, for each slot i in [0, poolSize):
48
+ * - a worker trampoline __tc_worker_fn_i(void* arg) that runs the recorded
49
+ * fn and then signals completion via signalDoneExpr,
50
+ * - __tc_worker_submit(i, fn, arg) — records the waiter, clears done, spawns,
51
+ * - __tc_worker_done(i) — poll predicate.
52
+ *
53
+ * AUTOSAR C++14: fixed-width types, static_cast, final structs, no STL, no heap.
54
+ */
55
+ export declare function generateWorkerRuntime(backing: WorkerBacking | null, options?: WorkerRuntimeOptions): string | null;
56
+ /**
57
+ * Resolve a HAL worker.* op to C++ against the shared contract.
58
+ * Returns undefined for ops the caller did not lower (unsupported).
59
+ *
60
+ * Note: the worker function itself (fnRef) and its argument (argRef) come from
61
+ * the IR as flat-scalar strings (per the hal-op-ir flat-fields contract). The
62
+ * lowering emits a straight call into __tc_worker_submit / __tc_worker_done.
63
+ */
64
+ export declare function lowerWorkerOp(op: {
65
+ operation: string;
66
+ }): {
67
+ code?: string;
68
+ expression?: string;
69
+ } | undefined;
@@ -0,0 +1,163 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Shared worker-offload runtime C++ code generator
3
+ //
4
+ // Generates the generic worker pool + the __tc_worker_submit / __tc_worker_done
5
+ // contract that generalizes the one-off ESP32 HTTP offload pattern
6
+ // (framework-esp32/src/lowering/http.ts: the __tc_http_send_task /
7
+ // __tc_http_send_start / __tc_http_done trio). The pool and contract live here;
8
+ // the per-framework spawn/signal/poll PRIMITIVES are injected via the strategy
9
+ // hooks workerSpawnLines / workerSignalDoneExpr / workerIsDoneExpr.
10
+ //
11
+ // Design (the safety property, per the approved plan):
12
+ // - The worker runtime is request-in / poll-out: the worker function receives
13
+ // its inputs by value and exposes outputs only through the opaque handle.
14
+ // - No mutex/semaphore is added to the IR. The worker-isolation analyzer
15
+ // (worker-analysis.ts) makes shared mutable state a transpile-time error.
16
+ // - STL-free: fixed-size static slot table, function-pointer + void*. Links
17
+ // on minimal-libc targets (Zephyr).
18
+ //
19
+ // The memory-barrier contract is load-bearing on dual-core targets: the signal
20
+ // primitive (workerSignalDoneExpr) MUST issue a full barrier so the consumer
21
+ // observes the worker's preceding output writes once it observes completion.
22
+ // ESP32 xTaskNotifyGive and Zephyr k_sem_give both satisfy this; bare volatile
23
+ // does NOT across cores.
24
+ // ---------------------------------------------------------------------------
25
+ /**
26
+ * Generate the worker-offload runtime C++ for a framework that supplies a
27
+ * backing. Returns null if `backing` is null (unsupported on this framework).
28
+ *
29
+ * The emitted code defines, for each slot i in [0, poolSize):
30
+ * - a worker trampoline __tc_worker_fn_i(void* arg) that runs the recorded
31
+ * fn and then signals completion via signalDoneExpr,
32
+ * - __tc_worker_submit(i, fn, arg) — records the waiter, clears done, spawns,
33
+ * - __tc_worker_done(i) — poll predicate.
34
+ *
35
+ * AUTOSAR C++14: fixed-width types, static_cast, final structs, no STL, no heap.
36
+ */
37
+ export function generateWorkerRuntime(backing, options = {}) {
38
+ if (!backing)
39
+ return null;
40
+ const poolSize = options.poolSize ?? 4;
41
+ const stackSize = options.stackSize ?? 8192;
42
+ const lines = [];
43
+ lines.push(`// ── Worker offload runtime (generalized request-in / poll-out) ──────────────`);
44
+ lines.push(`// Slot table + __tc_worker_submit/done contract. Per-framework primitives`);
45
+ lines.push(`// (spawn/signal/poll) are injected by the framework strategy. STL-free so`);
46
+ lines.push(`// this links on minimal-libc targets. See worker-runtime.ts.`);
47
+ lines.push(`namespace typecad_worker {`);
48
+ lines.push(` using WorkerFn = void (*)(void*);`);
49
+ lines.push(``);
50
+ lines.push(` struct WorkerSlot final {`);
51
+ lines.push(` volatile bool done;`);
52
+ lines.push(` void* waiter; // framework-specific waiter handle (opaque)`);
53
+ lines.push(` WorkerFn fn;`);
54
+ lines.push(` void* arg;`);
55
+ lines.push(` };`);
56
+ lines.push(``);
57
+ // Per-slot static instances.
58
+ for (let i = 0; i < poolSize; i++) {
59
+ lines.push(` static WorkerSlot __slot_${i};`);
60
+ }
61
+ lines.push(``);
62
+ // Forward-declare the per-slot trampolines so backings that need to bind a
63
+ // named handler to one (e.g. Zephyr K_WORK_DEFINE(_work_i, handler_i)) can
64
+ // reference it before the trampoline definition appears below.
65
+ for (let i = 0; i < poolSize; i++) {
66
+ lines.push(` static void __tc_worker_fn_${i}(void* arg);`);
67
+ }
68
+ lines.push(``);
69
+ // Per-slot backing declarations (e.g. Zephyr K_SEM_DEFINE + K_WORK_DEFINE +
70
+ // a work handler that forwards to the trampoline). Emitted BEFORE the
71
+ // trampoline definitions so the trampoline bodies can reference per-slot
72
+ // objects declared here (e.g. the completion semaphore used by the signal
73
+ // expression). Backings must only forward-declare, not define, the
74
+ // trampoline itself.
75
+ if (backing.slotDeclarations) {
76
+ for (let i = 0; i < poolSize; i++) {
77
+ const trampolineName = `__tc_worker_fn_${i}`;
78
+ for (const d of backing.slotDeclarations(i, trampolineName)) {
79
+ lines.push(` ${d}`);
80
+ }
81
+ }
82
+ lines.push(``);
83
+ }
84
+ // Per-slot worker trampolines: run fn(arg), then signal completion.
85
+ for (let i = 0; i < poolSize; i++) {
86
+ const signal = backing.signalDoneExpr(i);
87
+ lines.push(` // Worker trampoline for slot ${i}.`);
88
+ lines.push(` static void __tc_worker_fn_${i}(void* arg) {`);
89
+ lines.push(` // The shared runtime recorded fn/waiter before spawn; run it.`);
90
+ lines.push(` if (__slot_${i}.fn != nullptr) { __slot_${i}.fn(arg); }`);
91
+ lines.push(` __slot_${i}.done = true;`);
92
+ lines.push(` ${signal}; // barrier: makes the fn's output writes visible`);
93
+ lines.push(` }`);
94
+ lines.push(``);
95
+ }
96
+ // submit / done per slot.
97
+ for (let i = 0; i < poolSize; i++) {
98
+ const trampolineName = `__tc_worker_fn_${i}`;
99
+ const spawn = backing.spawnLines(i, trampolineName, `__slot_${i}.waiter`);
100
+ lines.push(` static inline void __tc_worker_submit_${i}(WorkerFn fn, void* arg) {`);
101
+ lines.push(` __slot_${i}.done = false;`);
102
+ lines.push(` __slot_${i}.fn = fn;`);
103
+ lines.push(` __slot_${i}.arg = arg;`);
104
+ lines.push(` // waiter is set by the framework spawn primitive below.`);
105
+ for (const s of spawn)
106
+ lines.push(` ${s}`);
107
+ lines.push(` }`);
108
+ lines.push(``);
109
+ const poll = backing.isDoneExpr(i);
110
+ lines.push(` static inline bool __tc_worker_done_${i}(void) {`);
111
+ lines.push(` if (__slot_${i}.done) { return true; } // fast path`);
112
+ lines.push(` if (${poll}) { __slot_${i}.done = true; return true; }`);
113
+ lines.push(` return false;`);
114
+ lines.push(` }`);
115
+ lines.push(``);
116
+ }
117
+ lines.push(`} // namespace typecad_worker`);
118
+ lines.push(``);
119
+ // Global dispatch aliases so HAL emit (worker.submit / worker.done) resolves.
120
+ lines.push(`// Global dispatch: select the per-slot submit/done by handle id.`);
121
+ lines.push(`inline void __tc_worker_submit(int32_t handle, typecad_worker::WorkerFn fn, void* arg) {`);
122
+ lines.push(` switch (handle) {`);
123
+ for (let i = 0; i < poolSize; i++) {
124
+ lines.push(` case ${i}: typecad_worker::__tc_worker_submit_${i}(fn, arg); return;`);
125
+ }
126
+ lines.push(` default: break; // out-of-range handle: no-op`);
127
+ lines.push(` }`);
128
+ lines.push(`}`);
129
+ lines.push(`inline bool __tc_worker_done(int32_t handle) {`);
130
+ lines.push(` switch (handle) {`);
131
+ for (let i = 0; i < poolSize; i++) {
132
+ lines.push(` case ${i}: return typecad_worker::__tc_worker_done_${i}();`);
133
+ }
134
+ lines.push(` default: return true; // out-of-range handle: treat as already done`);
135
+ lines.push(` }`);
136
+ lines.push(`}`);
137
+ return lines.join("\n");
138
+ }
139
+ /**
140
+ * Resolve a HAL worker.* op to C++ against the shared contract.
141
+ * Returns undefined for ops the caller did not lower (unsupported).
142
+ *
143
+ * Note: the worker function itself (fnRef) and its argument (argRef) come from
144
+ * the IR as flat-scalar strings (per the hal-op-ir flat-fields contract). The
145
+ * lowering emits a straight call into __tc_worker_submit / __tc_worker_done.
146
+ */
147
+ export function lowerWorkerOp(op) {
148
+ const o = op;
149
+ switch (op.operation) {
150
+ case 'worker.submit': {
151
+ const handle = Number(o.handleId);
152
+ const fn = String(o.fnRef);
153
+ const arg = o.argRef != null ? String(o.argRef) : 'nullptr';
154
+ return { code: `__tc_worker_submit(static_cast<int32_t>(${handle}), ${fn}, ${arg});` };
155
+ }
156
+ case 'worker.done': {
157
+ const handle = Number(o.handleId);
158
+ return { expression: `__tc_worker_done(static_cast<int32_t>(${handle}))` };
159
+ }
160
+ default:
161
+ return undefined;
162
+ }
163
+ }
@@ -13,6 +13,7 @@ export declare function printDiagnostics(diagnostics: Array<Diagnostic | {
13
13
  line?: number;
14
14
  column?: number;
15
15
  code?: string;
16
+ filePath?: string;
16
17
  sourceLine?: string;
17
18
  }>): void;
18
19
  /**
package/dist/cli-utils.js CHANGED
@@ -50,6 +50,7 @@ export function printDiagnostics(diagnostics) {
50
50
  for (const diagnostic of diagnostics) {
51
51
  const position = diagnostic.line && diagnostic.column ? chalk.gray(`(${diagnostic.line},${diagnostic.column})`) : "";
52
52
  const code = diagnostic.code ? chalk.gray(` [${diagnostic.code}]`) : "";
53
+ const file = 'filePath' in diagnostic && diagnostic.filePath ? chalk.cyan(diagnostic.filePath) : "";
53
54
  let severityLabel;
54
55
  let hintColor;
55
56
  if (diagnostic.severity === "error") {
@@ -65,7 +66,8 @@ export function printDiagnostics(diagnostics) {
65
66
  hintColor = chalk.cyan;
66
67
  }
67
68
  const location = position ? ` ${position}` : "";
68
- const header = `${severityLabel}${code}${location}: ${chalk.white(diagnostic.message)}`;
69
+ const filePrefix = file ? `${file} ` : "";
70
+ const header = `${filePrefix}${severityLabel}${code}${location}: ${chalk.white(diagnostic.message)}`;
69
71
  if (diagnostic.severity === "error") {
70
72
  console.error(header);
71
73
  }