@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.
- package/README.md +10 -10
- package/dist/api/board-types.d.ts +1 -1
- package/dist/api/config.d.ts +38 -2
- package/dist/api/index.d.ts +1 -1
- package/dist/api/schema/types.d.ts +15 -0
- package/dist/api/shared/async-runtime-static.d.ts +12 -1
- package/dist/api/shared/async-runtime-static.js +69 -24
- package/dist/api/shared/async-symbol-detector.d.ts +11 -0
- package/dist/api/shared/async-symbol-detector.js +140 -0
- package/dist/api/shared/async-types.d.ts +24 -0
- package/dist/api/shared/coop-scheduler.d.ts +60 -0
- package/dist/api/shared/coop-scheduler.js +149 -0
- package/dist/api/shared/display-adapter.d.ts +4 -3
- package/dist/api/shared/display-adapter.js +15 -118
- package/dist/api/shared/display-adapters/sdl.js +38 -31
- package/dist/api/shared/display-profile.d.ts +47 -25
- package/dist/api/shared/display-profile.js +31 -164
- package/dist/api/shared/framework-manifest-registry.d.ts +9 -0
- package/dist/api/shared/framework-manifest-registry.js +27 -0
- package/dist/api/shared/framework-manifest.d.ts +595 -0
- package/dist/api/shared/framework-manifest.js +193 -0
- package/dist/api/shared/glcdfont.d.ts +12 -0
- package/dist/api/shared/glcdfont.js +124 -0
- package/dist/api/shared/graphics-strategy.d.ts +37 -0
- package/dist/api/shared/hal-op-ir.d.ts +764 -1
- package/dist/api/shared/hal-op-ir.js +129 -1
- package/dist/api/shared/index.d.ts +22 -2
- package/dist/api/shared/index.js +26 -1
- package/dist/api/shared/ir-core.d.ts +4 -0
- package/dist/api/shared/ir-declarations.d.ts +6 -0
- package/dist/api/shared/native-display-op-resolver.d.ts +10 -0
- package/dist/api/shared/native-display-op-resolver.js +64 -0
- package/dist/api/shared/platform-strategy.d.ts +119 -2
- package/dist/api/shared/polyfill-helper-registry.js +18 -1
- package/dist/api/shared/promise-runtime.d.ts +1 -1
- package/dist/api/shared/promise-runtime.js +95 -13
- package/dist/api/shared/spdx-licenses.d.ts +139 -0
- package/dist/api/shared/spdx-licenses.js +385 -0
- package/dist/api/shared/toolchain-types.d.ts +17 -0
- package/dist/api/shared/types.d.ts +8 -0
- package/dist/api/shared/validate-framework-manifest.d.ts +28 -0
- package/dist/api/shared/validate-framework-manifest.js +494 -0
- package/dist/api/shared/worker-runtime-polyfill.d.ts +22 -0
- package/dist/api/shared/worker-runtime-polyfill.js +34 -0
- package/dist/api/shared/worker-runtime.d.ts +69 -0
- package/dist/api/shared/worker-runtime.js +163 -0
- package/dist/cli-utils.d.ts +1 -0
- package/dist/cli-utils.js +3 -1
- package/dist/cli.js +249 -32
- package/dist/config-loader.d.ts +7 -2
- package/dist/config-loader.js +23 -3
- package/dist/config-schema.d.ts +112 -70
- package/dist/config-schema.js +14 -0
- package/dist/contract/board-generator.d.ts +17 -0
- package/dist/contract/board-generator.js +57 -0
- package/dist/contract/contract-parser.d.ts +217 -0
- package/dist/contract/contract-parser.js +224 -0
- package/dist/contract/index.d.ts +22 -0
- package/dist/contract/index.js +68 -0
- package/dist/create/board-codegen.js +4 -4
- package/dist/create/board-generators.js +4 -5
- package/dist/create/board-spec.d.ts +72 -75
- package/dist/create/board-spec.js +0 -1
- package/dist/create/framework-catalog.d.ts +64 -0
- package/dist/create/framework-catalog.js +136 -0
- package/dist/create/index.d.ts +5 -1
- package/dist/create/index.js +3 -1
- package/dist/create/init-scaffold.d.ts +12 -3
- package/dist/create/init-scaffold.js +49 -14
- package/dist/create/init-templates.d.ts +4 -0
- package/dist/create/init-templates.js +271 -17
- package/dist/create/init-wizard.js +41 -27
- package/dist/create/install-deps.d.ts +32 -0
- package/dist/create/install-deps.js +46 -0
- package/dist/debug/preprocessor.js +178 -39
- package/dist/debug/types.d.ts +23 -0
- package/dist/diagnostics/mermaid-builder.d.ts +1 -1
- package/dist/diagnostics/mermaid-builder.js +34 -24
- package/dist/emit/compliance/arxml-writer.d.ts +11 -0
- package/dist/emit/compliance/arxml-writer.js +34 -0
- package/dist/emit/compliance/compliance-context.d.ts +57 -0
- package/dist/emit/compliance/compliance-context.js +113 -0
- package/dist/emit/compliance/deviation-ledger.d.ts +27 -0
- package/dist/emit/compliance/deviation-ledger.js +47 -0
- package/dist/emit/compliance/deviation-writer.d.ts +30 -0
- package/dist/emit/compliance/deviation-writer.js +37 -0
- package/dist/emit/compliance/index.d.ts +7 -0
- package/dist/emit/compliance/index.js +6 -0
- package/dist/emit/compliance/rule-engine.d.ts +13 -0
- package/dist/emit/compliance/rule-engine.js +101 -0
- package/dist/emit/compliance/rules.d.ts +16 -0
- package/dist/emit/compliance/rules.js +191 -0
- package/dist/emit/compliance/types.d.ts +59 -0
- package/dist/emit/compliance/types.js +8 -0
- package/dist/emit/cpp-emitter.js +4 -3
- package/dist/emit/emitters/class-emitter.js +6 -1
- package/dist/emit/emitters/emitter-context.d.ts +28 -1
- package/dist/emit/emitters/function-emitter-impl.js +153 -53
- package/dist/emit/emitters/line-appender.js +19 -0
- package/dist/emit/emitters/line-marker.d.ts +38 -0
- package/dist/emit/emitters/line-marker.js +39 -0
- package/dist/emit/emitters/output-finalizer.d.ts +6 -0
- package/dist/emit/emitters/output-finalizer.js +101 -12
- package/dist/emit/emitters/setup.d.ts +17 -0
- package/dist/emit/emitters/setup.js +372 -30
- package/dist/emit/emitters/top-level-prep.js +8 -0
- package/dist/emit/emitters/type-decl-emitter.js +28 -3
- package/dist/emit/emitters/ui-emitter.js +33 -9
- package/dist/emit/expression-renderer.d.ts +1 -1
- package/dist/emit/expression-renderer.js +91 -6
- package/dist/emit/route-hal-op.js +18 -5
- package/dist/emit/snprintf-helpers.js +15 -4
- package/dist/emit/statement-renderer.d.ts +10 -0
- package/dist/emit/statement-renderer.js +34 -5
- package/dist/emit/utils/async-state-machine.js +221 -125
- package/dist/emit/utils/hal-op-cpp-type.d.ts +6 -0
- package/dist/emit/utils/hal-op-cpp-type.js +40 -0
- package/dist/framework-package.js +2 -0
- package/dist/framework-registry.d.ts +17 -0
- package/dist/install/framework-catalog.d.ts +53 -0
- package/dist/install/framework-catalog.js +107 -0
- package/dist/install/handle-install.d.ts +35 -0
- package/dist/install/handle-install.js +177 -0
- package/dist/install/index.d.ts +4 -0
- package/dist/install/index.js +3 -0
- package/dist/ir/adc-range-validation.js +40 -26
- package/dist/ir/build-ir-state.d.ts +1 -0
- package/dist/ir/build-ir-state.js +14 -0
- package/dist/ir/build-ir.js +9 -5
- package/dist/ir/call-graph.js +16 -0
- package/dist/ir/expression-to-ir.js +207 -6
- package/dist/ir/feature-registry.js +7 -25
- package/dist/ir/function-builder.js +22 -0
- package/dist/ir/hal/hal-emitter.d.ts +5 -2
- package/dist/ir/hal/hal-emitter.js +50 -18
- package/dist/ir/hal/hal-parser.d.ts +6 -0
- package/dist/ir/hal/hal-parser.js +81 -0
- package/dist/ir/hal/hal-plugins.js +733 -1
- package/dist/ir/identifier-collector.js +35 -0
- package/dist/ir/interrupt-analysis.d.ts +5 -1
- package/dist/ir/interrupt-analysis.js +16 -19
- package/dist/ir/memory-budget-validation.js +1 -0
- package/dist/ir/network-validation.d.ts +4 -0
- package/dist/ir/network-validation.js +184 -0
- package/dist/ir/ownership-analysis.js +39 -1
- package/dist/ir/peripheral-ownership.js +5 -0
- package/dist/ir/peripheral-validation.d.ts +1 -1
- package/dist/ir/peripheral-validation.js +6 -3
- package/dist/ir/pin-alias-conflict.d.ts +1 -1
- package/dist/ir/pin-alias-conflict.js +2 -1
- package/dist/ir/pin-capability-validation.js +71 -32
- package/dist/ir/pin-mode-validation.d.ts +2 -2
- package/dist/ir/pin-mode-validation.js +54 -18
- package/dist/ir/pin-safety.d.ts +1 -1
- package/dist/ir/pin-safety.js +2 -1
- package/dist/ir/program-analysis.d.ts +81 -0
- package/dist/ir/program-analysis.js +429 -0
- package/dist/ir/pulldown-validation.d.ts +1 -1
- package/dist/ir/pulldown-validation.js +2 -1
- package/dist/ir/pwm-timer-sharing.d.ts +1 -1
- package/dist/ir/pwm-timer-sharing.js +2 -1
- package/dist/ir/render-expr.js +11 -0
- package/dist/ir/resource-analysis.js +2 -0
- package/dist/ir/timer0-pwm-timing-conflict.d.ts +1 -1
- package/dist/ir/timer0-pwm-timing-conflict.js +2 -1
- package/dist/ir/timing-validation.d.ts +6 -1
- package/dist/ir/timing-validation.js +61 -13
- package/dist/ir/transformers/call-statement.js +105 -0
- package/dist/ir/transformers/expressions.js +62 -0
- package/dist/ir/transformers/hal-call-resolver.js +21 -0
- package/dist/ir/transformers/hal-emit-helpers.js +1 -1
- package/dist/ir/transformers/namespace-methods.js +17 -12
- package/dist/ir/transformers/ui-reactive.js +2 -2
- package/dist/ir/transformers/variables.js +137 -19
- package/dist/ir/try-catch-validation.js +2 -0
- package/dist/ir/type-resolution.js +20 -2
- package/dist/ir/ui-element-auto-wire.js +7 -5
- package/dist/ir/unit-suspicion-validation.js +9 -7
- package/dist/ir/utils/map-statements.d.ts +4 -0
- package/dist/ir/utils/map-statements.js +79 -0
- package/dist/ir/validation-orchestrator.js +15 -8
- package/dist/ir/worker-analysis.d.ts +10 -0
- package/dist/ir/worker-analysis.js +261 -0
- package/dist/libdef/c-to-decl.d.ts +27 -0
- package/dist/libdef/c-to-decl.js +397 -0
- package/dist/libdef/component-decls.d.ts +2 -0
- package/dist/libdef/component-decls.js +6 -0
- package/dist/libdef/component-discovery.d.ts +43 -0
- package/dist/libdef/component-discovery.js +83 -0
- package/dist/libdef/cpp-to-decl.d.ts +9 -0
- package/dist/libdef/cpp-to-decl.js +72 -0
- package/dist/libdef/registry.js +5 -2
- package/dist/lint-cache.d.ts +59 -0
- package/dist/lint-cache.js +257 -0
- package/dist/orchestrator/graph-builder.js +14 -9
- package/dist/platform/coop-scheduler-runtime.d.ts +19 -0
- package/dist/platform/coop-scheduler-runtime.js +41 -0
- package/dist/platform/generic-strategy.d.ts +15 -3
- package/dist/platform/generic-strategy.js +49 -4
- package/dist/safety/safety-bridge.d.ts +11 -0
- package/dist/safety/safety-bridge.js +48 -0
- package/dist/safety/sidecar-bridge.d.ts +5 -0
- package/dist/safety/sidecar-bridge.js +22 -0
- package/dist/safety-hook.d.ts +79 -0
- package/dist/safety-hook.js +35 -0
- package/dist/testing.d.ts +8 -2
- package/dist/testing.js +9 -2
- package/dist/transpile.d.ts +3 -0
- package/dist/transpile.js +191 -49
- package/dist/types.d.ts +22 -3
- package/dist/ui-hook.d.ts +17 -3
- package/dist/utils/cli.js +123 -2
- package/dist/utils/fs.d.ts +13 -0
- package/dist/utils/fs.js +50 -0
- package/dist/utils/ui.js +3 -1
- package/package.json +23 -3
- package/dist/api/shared/display-adapters/eink-mono.d.ts +0 -2
- package/dist/api/shared/display-adapters/eink-mono.js +0 -53
- package/dist/api/shared/display-adapters/ssd1309.d.ts +0 -2
- package/dist/api/shared/display-adapters/ssd1309.js +0 -136
- package/dist/api/shared/display-adapters/st7796.d.ts +0 -2
- package/dist/api/shared/display-adapters/st7796.js +0 -132
- package/dist/ir/heap-array-validation.d.ts +0 -24
- 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
|
+
}
|
package/dist/cli-utils.d.ts
CHANGED
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
|
|
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
|
}
|