@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.
- package/LICENSE +21 -0
- package/README.md +79 -0
- package/dist/api/board-types.d.ts +1 -0
- package/dist/api/board-types.js +4 -0
- package/dist/api/capabilities.d.ts +12 -0
- package/dist/api/capabilities.js +1 -0
- package/dist/api/config.d.ts +120 -0
- package/dist/api/config.js +7 -0
- package/dist/api/index.d.ts +5 -0
- package/dist/api/index.js +2 -0
- package/dist/api/schema/builder.d.ts +14 -0
- package/dist/api/schema/builder.js +15 -0
- package/dist/api/schema/index.d.ts +2 -0
- package/dist/api/schema/index.js +1 -0
- package/dist/api/schema/types.d.ts +257 -0
- package/dist/api/schema/types.js +4 -0
- package/dist/api/shared/async-runtime-static.d.ts +8 -0
- package/dist/api/shared/async-runtime-static.js +201 -0
- package/dist/api/shared/async-types.d.ts +42 -0
- package/dist/api/shared/async-types.js +8 -0
- package/dist/api/shared/board-resolver.d.ts +12 -0
- package/dist/api/shared/board-resolver.js +7 -0
- package/dist/api/shared/cpp-type-ir.d.ts +229 -0
- package/dist/api/shared/cpp-type-ir.js +672 -0
- package/dist/api/shared/display-adapter.d.ts +12 -0
- package/dist/api/shared/display-adapter.js +145 -0
- package/dist/api/shared/display-adapters/eink-mono.d.ts +2 -0
- package/dist/api/shared/display-adapters/eink-mono.js +53 -0
- package/dist/api/shared/display-adapters/sdl.d.ts +2 -0
- package/dist/api/shared/display-adapters/sdl.js +452 -0
- package/dist/api/shared/display-adapters/ssd1309.d.ts +2 -0
- package/dist/api/shared/display-adapters/ssd1309.js +136 -0
- package/dist/api/shared/display-adapters/st7796.d.ts +2 -0
- package/dist/api/shared/display-adapters/st7796.js +132 -0
- package/dist/api/shared/display-capabilities.d.ts +45 -0
- package/dist/api/shared/display-capabilities.js +54 -0
- package/dist/api/shared/display-op-ir.d.ts +62 -0
- package/dist/api/shared/display-op-ir.js +19 -0
- package/dist/api/shared/display-profile.d.ts +265 -0
- package/dist/api/shared/display-profile.js +338 -0
- package/dist/api/shared/graphics-strategy.d.ts +29 -0
- package/dist/api/shared/graphics-strategy.js +11 -0
- package/dist/api/shared/hal-op-ir.d.ts +393 -0
- package/dist/api/shared/hal-op-ir.js +18 -0
- package/dist/api/shared/index.d.ts +26 -0
- package/dist/api/shared/index.js +21 -0
- package/dist/api/shared/ir-core.d.ts +363 -0
- package/dist/api/shared/ir-core.js +8 -0
- package/dist/api/shared/ir-declarations.d.ts +201 -0
- package/dist/api/shared/ir-declarations.js +26 -0
- package/dist/api/shared/ir.d.ts +85 -0
- package/dist/api/shared/ir.js +13 -0
- package/dist/api/shared/platform-strategy.d.ts +402 -0
- package/dist/api/shared/platform-strategy.js +14 -0
- package/dist/api/shared/polyfill-helper-registry.d.ts +11 -0
- package/dist/api/shared/polyfill-helper-registry.js +86 -0
- package/dist/api/shared/polyfill-types.d.ts +33 -0
- package/dist/api/shared/polyfill-types.js +76 -0
- package/dist/api/shared/promise-runtime.d.ts +10 -0
- package/dist/api/shared/promise-runtime.js +244 -0
- package/dist/api/shared/snprintf-types.d.ts +29 -0
- package/dist/api/shared/snprintf-types.js +8 -0
- package/dist/api/shared/string-method-registry.d.ts +53 -0
- package/dist/api/shared/string-method-registry.js +168 -0
- package/dist/api/shared/toolchain-types.d.ts +63 -0
- package/dist/api/shared/toolchain-types.js +71 -0
- package/dist/api/shared/types.d.ts +50 -0
- package/dist/api/shared/types.js +6 -0
- package/dist/ast/parse.d.ts +2 -0
- package/dist/ast/parse.js +4 -0
- package/dist/cache.d.ts +26 -0
- package/dist/cache.js +95 -0
- package/dist/cli-utils.d.ts +37 -0
- package/dist/cli-utils.js +250 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +635 -0
- package/dist/config-loader.d.ts +78 -0
- package/dist/config-loader.js +508 -0
- package/dist/config-schema.d.ts +233 -0
- package/dist/config-schema.js +83 -0
- package/dist/create/board-checklist.d.ts +2 -0
- package/dist/create/board-checklist.js +52 -0
- package/dist/create/board-codegen.d.ts +9 -0
- package/dist/create/board-codegen.js +238 -0
- package/dist/create/board-generators.d.ts +12 -0
- package/dist/create/board-generators.js +652 -0
- package/dist/create/board-spec.d.ts +640 -0
- package/dist/create/board-spec.js +215 -0
- package/dist/create/eslint-rules-template.d.ts +2 -0
- package/dist/create/eslint-rules-template.js +672 -0
- package/dist/create/index.d.ts +11 -0
- package/dist/create/index.js +8 -0
- package/dist/create/init-scaffold.d.ts +27 -0
- package/dist/create/init-scaffold.js +150 -0
- package/dist/create/init-templates.d.ts +24 -0
- package/dist/create/init-templates.js +379 -0
- package/dist/create/init-wizard.d.ts +8 -0
- package/dist/create/init-wizard.js +168 -0
- package/dist/debug/breakpoint-loader.d.ts +24 -0
- package/dist/debug/breakpoint-loader.js +137 -0
- package/dist/debug/index.d.ts +3 -0
- package/dist/debug/index.js +7 -0
- package/dist/debug/preprocessor.d.ts +9 -0
- package/dist/debug/preprocessor.js +214 -0
- package/dist/debug/types.d.ts +32 -0
- package/dist/debug/types.js +6 -0
- package/dist/diagnostics/diagnostics-report.d.ts +51 -0
- package/dist/diagnostics/diagnostics-report.js +333 -0
- package/dist/diagnostics/json-schema.d.ts +138 -0
- package/dist/diagnostics/json-schema.js +27 -0
- package/dist/diagnostics/md-writer.d.ts +10 -0
- package/dist/diagnostics/md-writer.js +336 -0
- package/dist/diagnostics/mermaid-builder.d.ts +65 -0
- package/dist/diagnostics/mermaid-builder.js +681 -0
- package/dist/emit/cpp-emitter.d.ts +6 -0
- package/dist/emit/cpp-emitter.js +48 -0
- package/dist/emit/emitters/class-emitter.d.ts +2 -0
- package/dist/emit/emitters/class-emitter.js +523 -0
- package/dist/emit/emitters/emitter-context.d.ts +174 -0
- package/dist/emit/emitters/emitter-context.js +1 -0
- package/dist/emit/emitters/entrypoint-synthesizer.d.ts +2 -0
- package/dist/emit/emitters/entrypoint-synthesizer.js +175 -0
- package/dist/emit/emitters/function-emitter-impl.d.ts +19 -0
- package/dist/emit/emitters/function-emitter-impl.js +428 -0
- package/dist/emit/emitters/line-appender.d.ts +15 -0
- package/dist/emit/emitters/line-appender.js +344 -0
- package/dist/emit/emitters/namespace-emitter.d.ts +2 -0
- package/dist/emit/emitters/namespace-emitter.js +324 -0
- package/dist/emit/emitters/output-finalizer.d.ts +4 -0
- package/dist/emit/emitters/output-finalizer.js +267 -0
- package/dist/emit/emitters/setup.d.ts +3 -0
- package/dist/emit/emitters/setup.js +851 -0
- package/dist/emit/emitters/top-level-prep.d.ts +2 -0
- package/dist/emit/emitters/top-level-prep.js +706 -0
- package/dist/emit/emitters/type-decl-emitter.d.ts +2 -0
- package/dist/emit/emitters/type-decl-emitter.js +251 -0
- package/dist/emit/emitters/ui-emitter.d.ts +21 -0
- package/dist/emit/emitters/ui-emitter.js +564 -0
- package/dist/emit/enum-emitter.d.ts +1 -0
- package/dist/emit/enum-emitter.js +1 -0
- package/dist/emit/expression-renderer.d.ts +283 -0
- package/dist/emit/expression-renderer.js +1477 -0
- package/dist/emit/native-helpers-emitter.d.ts +11 -0
- package/dist/emit/native-helpers-emitter.js +34 -0
- package/dist/emit/route-hal-op.d.ts +5 -0
- package/dist/emit/route-hal-op.js +13 -0
- package/dist/emit/snprintf-helpers.d.ts +17 -0
- package/dist/emit/snprintf-helpers.js +462 -0
- package/dist/emit/statement-renderer.d.ts +189 -0
- package/dist/emit/statement-renderer.js +948 -0
- package/dist/emit/utils/async-state-machine.d.ts +42 -0
- package/dist/emit/utils/async-state-machine.js +343 -0
- package/dist/emit/utils/comment-helpers.d.ts +20 -0
- package/dist/emit/utils/comment-helpers.js +31 -0
- package/dist/emit/utils/cpp-helpers.d.ts +47 -0
- package/dist/emit/utils/cpp-helpers.js +85 -0
- package/dist/emit/utils/include-resolver.d.ts +58 -0
- package/dist/emit/utils/include-resolver.js +155 -0
- package/dist/emit/utils/index.d.ts +8 -0
- package/dist/emit/utils/index.js +12 -0
- package/dist/emit/utils/type-inference.d.ts +159 -0
- package/dist/emit/utils/type-inference.js +559 -0
- package/dist/eslint-check.d.ts +10 -0
- package/dist/eslint-check.js +102 -0
- package/dist/framework-package.d.ts +10 -0
- package/dist/framework-package.js +58 -0
- package/dist/framework-registry.d.ts +39 -0
- package/dist/framework-registry.js +30 -0
- package/dist/incremental-cache.d.ts +116 -0
- package/dist/incremental-cache.js +335 -0
- package/dist/ir/adc-range-validation.d.ts +11 -0
- package/dist/ir/adc-range-validation.js +250 -0
- package/dist/ir/ast-node-utils.d.ts +8 -0
- package/dist/ir/ast-node-utils.js +32 -0
- package/dist/ir/board-pin-utils.d.ts +13 -0
- package/dist/ir/board-pin-utils.js +65 -0
- package/dist/ir/board-resolver.d.ts +36 -0
- package/dist/ir/board-resolver.js +437 -0
- package/dist/ir/build-ir-state.d.ts +167 -0
- package/dist/ir/build-ir-state.js +306 -0
- package/dist/ir/build-ir.d.ts +2 -0
- package/dist/ir/build-ir.js +808 -0
- package/dist/ir/call-graph.d.ts +35 -0
- package/dist/ir/call-graph.js +194 -0
- package/dist/ir/compile-time-only.d.ts +2 -0
- package/dist/ir/compile-time-only.js +16 -0
- package/dist/ir/declaration-builders.d.ts +9 -0
- package/dist/ir/declaration-builders.js +608 -0
- package/dist/ir/entry-points.d.ts +30 -0
- package/dist/ir/entry-points.js +191 -0
- package/dist/ir/expression-to-ir.d.ts +5 -0
- package/dist/ir/expression-to-ir.js +2249 -0
- package/dist/ir/extract-property-chain.d.ts +10 -0
- package/dist/ir/extract-property-chain.js +30 -0
- package/dist/ir/feature-prescan.d.ts +3 -0
- package/dist/ir/feature-prescan.js +43 -0
- package/dist/ir/feature-registry.d.ts +30 -0
- package/dist/ir/feature-registry.js +816 -0
- package/dist/ir/filter.d.ts +7 -0
- package/dist/ir/filter.js +85 -0
- package/dist/ir/function-builder.d.ts +19 -0
- package/dist/ir/function-builder.js +670 -0
- package/dist/ir/hal/hal-emitter.d.ts +62 -0
- package/dist/ir/hal/hal-emitter.js +735 -0
- package/dist/ir/hal/hal-parser.d.ts +61 -0
- package/dist/ir/hal/hal-parser.js +473 -0
- package/dist/ir/hal/hal-plugins.d.ts +34 -0
- package/dist/ir/hal/hal-plugins.js +706 -0
- package/dist/ir/hal-resolver.d.ts +5 -0
- package/dist/ir/hal-resolver.js +5 -0
- package/dist/ir/heap-analysis.d.ts +8 -0
- package/dist/ir/heap-analysis.js +350 -0
- package/dist/ir/heap-array-validation.d.ts +24 -0
- package/dist/ir/heap-array-validation.js +29 -0
- package/dist/ir/identifier-collector.d.ts +18 -0
- package/dist/ir/identifier-collector.js +439 -0
- package/dist/ir/interrupt-analysis.d.ts +39 -0
- package/dist/ir/interrupt-analysis.js +467 -0
- package/dist/ir/memory-budget-validation.d.ts +10 -0
- package/dist/ir/memory-budget-validation.js +86 -0
- package/dist/ir/namespace-builder.d.ts +7 -0
- package/dist/ir/namespace-builder.js +152 -0
- package/dist/ir/ownership-analysis.d.ts +9 -0
- package/dist/ir/ownership-analysis.js +1207 -0
- package/dist/ir/peripheral-ownership.d.ts +3 -0
- package/dist/ir/peripheral-ownership.js +152 -0
- package/dist/ir/peripheral-symbols.d.ts +7 -0
- package/dist/ir/peripheral-symbols.js +57 -0
- package/dist/ir/peripheral-usage.d.ts +54 -0
- package/dist/ir/peripheral-usage.js +691 -0
- package/dist/ir/peripheral-validation.d.ts +8 -0
- package/dist/ir/peripheral-validation.js +77 -0
- package/dist/ir/pin-alias-conflict.d.ts +4 -0
- package/dist/ir/pin-alias-conflict.js +34 -0
- package/dist/ir/pin-capability-validation.d.ts +6 -0
- package/dist/ir/pin-capability-validation.js +413 -0
- package/dist/ir/pin-mode-validation.d.ts +10 -0
- package/dist/ir/pin-mode-validation.js +301 -0
- package/dist/ir/pin-safety.d.ts +11 -0
- package/dist/ir/pin-safety.js +58 -0
- package/dist/ir/program-analysis.d.ts +44 -0
- package/dist/ir/program-analysis.js +589 -0
- package/dist/ir/pulldown-validation.d.ts +7 -0
- package/dist/ir/pulldown-validation.js +49 -0
- package/dist/ir/pwm-timer-sharing.d.ts +4 -0
- package/dist/ir/pwm-timer-sharing.js +93 -0
- package/dist/ir/reachability.d.ts +68 -0
- package/dist/ir/reachability.js +224 -0
- package/dist/ir/register-decorators.d.ts +6 -0
- package/dist/ir/register-decorators.js +49 -0
- package/dist/ir/render-expr.d.ts +4 -0
- package/dist/ir/render-expr.js +127 -0
- package/dist/ir/resource-analysis.d.ts +19 -0
- package/dist/ir/resource-analysis.js +153 -0
- package/dist/ir/statement-to-ir.d.ts +23 -0
- package/dist/ir/statement-to-ir.js +349 -0
- package/dist/ir/symbol-table.d.ts +68 -0
- package/dist/ir/symbol-table.js +179 -0
- package/dist/ir/symbol-types.d.ts +56 -0
- package/dist/ir/symbol-types.js +107 -0
- package/dist/ir/timer0-pwm-timing-conflict.d.ts +4 -0
- package/dist/ir/timer0-pwm-timing-conflict.js +71 -0
- package/dist/ir/timing-validation.d.ts +7 -0
- package/dist/ir/timing-validation.js +95 -0
- package/dist/ir/transformers/array-methods.d.ts +8 -0
- package/dist/ir/transformers/array-methods.js +493 -0
- package/dist/ir/transformers/call-statement.d.ts +5 -0
- package/dist/ir/transformers/call-statement.js +758 -0
- package/dist/ir/transformers/callback-context-registry.d.ts +20 -0
- package/dist/ir/transformers/callback-context-registry.js +55 -0
- package/dist/ir/transformers/canvas-lowering.d.ts +42 -0
- package/dist/ir/transformers/canvas-lowering.js +249 -0
- package/dist/ir/transformers/control-flow.d.ts +8 -0
- package/dist/ir/transformers/control-flow.js +508 -0
- package/dist/ir/transformers/expressions.d.ts +7 -0
- package/dist/ir/transformers/expressions.js +406 -0
- package/dist/ir/transformers/hal-call-resolver.d.ts +29 -0
- package/dist/ir/transformers/hal-call-resolver.js +274 -0
- package/dist/ir/transformers/hal-emit-helpers.d.ts +14 -0
- package/dist/ir/transformers/hal-emit-helpers.js +63 -0
- package/dist/ir/transformers/namespace-methods.d.ts +20 -0
- package/dist/ir/transformers/namespace-methods.js +110 -0
- package/dist/ir/transformers/register-assignment.d.ts +5 -0
- package/dist/ir/transformers/register-assignment.js +56 -0
- package/dist/ir/transformers/ui-call-resolver.d.ts +149 -0
- package/dist/ir/transformers/ui-call-resolver.js +1136 -0
- package/dist/ir/transformers/ui-callback-lowering.d.ts +62 -0
- package/dist/ir/transformers/ui-callback-lowering.js +623 -0
- package/dist/ir/transformers/ui-mount.d.ts +20 -0
- package/dist/ir/transformers/ui-mount.js +35 -0
- package/dist/ir/transformers/ui-reactive.d.ts +68 -0
- package/dist/ir/transformers/ui-reactive.js +129 -0
- package/dist/ir/transformers/variables.d.ts +14 -0
- package/dist/ir/transformers/variables.js +1045 -0
- package/dist/ir/try-catch-validation.d.ts +26 -0
- package/dist/ir/try-catch-validation.js +128 -0
- package/dist/ir/type-resolution.d.ts +31 -0
- package/dist/ir/type-resolution.js +977 -0
- package/dist/ir/ui-element-auto-wire.d.ts +50 -0
- package/dist/ir/ui-element-auto-wire.js +218 -0
- package/dist/ir/unit-suspicion-validation.d.ts +12 -0
- package/dist/ir/unit-suspicion-validation.js +296 -0
- package/dist/ir/utils/walk-ir.d.ts +6 -0
- package/dist/ir/utils/walk-ir.js +162 -0
- package/dist/ir/validation-orchestrator.d.ts +4 -0
- package/dist/ir/validation-orchestrator.js +45 -0
- package/dist/libdef/base-class-resolver.d.ts +23 -0
- package/dist/libdef/base-class-resolver.js +50 -0
- package/dist/libdef/cpp-to-decl.d.ts +34 -0
- package/dist/libdef/cpp-to-decl.js +584 -0
- package/dist/libdef/header-parser.d.ts +53 -0
- package/dist/libdef/header-parser.js +269 -0
- package/dist/libdef/registry.d.ts +10 -0
- package/dist/libdef/registry.js +142 -0
- package/dist/mapping/peripheral-names.d.ts +23 -0
- package/dist/mapping/peripheral-names.js +63 -0
- package/dist/mapping/source-map.d.ts +46 -0
- package/dist/mapping/source-map.js +207 -0
- package/dist/orchestrator/dts-generator.d.ts +17 -0
- package/dist/orchestrator/dts-generator.js +83 -0
- package/dist/orchestrator/graph-builder.d.ts +18 -0
- package/dist/orchestrator/graph-builder.js +218 -0
- package/dist/orchestrator/semantic-facts-verifier.d.ts +38 -0
- package/dist/orchestrator/semantic-facts-verifier.js +121 -0
- package/dist/orchestrator/semantic-facts.d.ts +141 -0
- package/dist/orchestrator/semantic-facts.js +652 -0
- package/dist/orchestrator/type-checker.d.ts +39 -0
- package/dist/orchestrator/type-checker.js +760 -0
- package/dist/platform/async-runtime.d.ts +8 -0
- package/dist/platform/async-runtime.js +26 -0
- package/dist/platform/generic-strategy.d.ts +101 -0
- package/dist/platform/generic-strategy.js +289 -0
- package/dist/platform/index.d.ts +4 -0
- package/dist/platform/index.js +9 -0
- package/dist/platform/registry.d.ts +21 -0
- package/dist/platform/registry.js +42 -0
- package/dist/platform/toolchain.d.ts +4 -0
- package/dist/platform/toolchain.js +43 -0
- package/dist/preview/client.d.ts +1 -0
- package/dist/preview/client.js +137 -0
- package/dist/preview/server.d.ts +5 -0
- package/dist/preview/server.js +199 -0
- package/dist/profiler/index.d.ts +28 -0
- package/dist/profiler/index.js +28 -0
- package/dist/profiler/profiler.d.ts +95 -0
- package/dist/profiler/profiler.js +338 -0
- package/dist/profiler/types.d.ts +87 -0
- package/dist/profiler/types.js +12 -0
- package/dist/stores/display-profile-store.d.ts +16 -0
- package/dist/stores/display-profile-store.js +48 -0
- package/dist/stores/theme-store.d.ts +13 -0
- package/dist/stores/theme-store.js +30 -0
- package/dist/testing.d.ts +45 -0
- package/dist/testing.js +47 -0
- package/dist/transpile/resolution.d.ts +29 -0
- package/dist/transpile/resolution.js +282 -0
- package/dist/transpile.d.ts +3 -0
- package/dist/transpile.js +722 -0
- package/dist/types.d.ts +217 -0
- package/dist/types.js +1 -0
- package/dist/ui/ui-bridge.d.ts +4 -0
- package/dist/ui/ui-bridge.js +34 -0
- package/dist/ui-hook.d.ts +84 -0
- package/dist/ui-hook.js +45 -0
- package/dist/utils/cli.d.ts +3 -0
- package/dist/utils/cli.js +463 -0
- package/dist/utils/fs.d.ts +4 -0
- package/dist/utils/fs.js +23 -0
- package/dist/utils/logger.d.ts +2 -0
- package/dist/utils/logger.js +8 -0
- package/dist/utils/strings.d.ts +35 -0
- package/dist/utils/strings.js +142 -0
- package/dist/utils/ui.d.ts +66 -0
- package/dist/utils/ui.js +149 -0
- package/dist/watch.d.ts +35 -0
- package/dist/watch.js +111 -0
- package/package.json +127 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ProgramIR } from "../api/index.js";
|
|
2
|
+
import type { PlatformContext } from "./../types.js";
|
|
3
|
+
import type { RuntimePolyfillIR } from "../api/shared/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Build a RuntimePolyfillIR for the async Promise runtime, if the program
|
|
6
|
+
* has async functions and the target architecture has stdlib support.
|
|
7
|
+
*/
|
|
8
|
+
export declare function buildAsyncRuntimePolyfill(program: ProgramIR, ctx: PlatformContext | undefined, target: string, queueCapacity?: number): RuntimePolyfillIR | null;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { getStdLibSupport, generatePromiseRuntime } from "../api/shared/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Build a RuntimePolyfillIR for the async Promise runtime, if the program
|
|
4
|
+
* has async functions and the target architecture has stdlib support.
|
|
5
|
+
*/
|
|
6
|
+
export function buildAsyncRuntimePolyfill(program, ctx, target, queueCapacity) {
|
|
7
|
+
const hasAsync = program.functions.some(fn => fn.isAsync);
|
|
8
|
+
if (!hasAsync)
|
|
9
|
+
return null;
|
|
10
|
+
const architecture = ctx?.architecture;
|
|
11
|
+
const stdlib = getStdLibSupport(architecture);
|
|
12
|
+
if (!stdlib.hasVector || !stdlib.hasString)
|
|
13
|
+
return null;
|
|
14
|
+
return {
|
|
15
|
+
kind: "polyfill",
|
|
16
|
+
id: "async_runtime",
|
|
17
|
+
domain: "standard",
|
|
18
|
+
requiredIncludes: ["<functional>", "<vector>", "<utility>", "<string>"],
|
|
19
|
+
forwardDeclarations: [],
|
|
20
|
+
helperStructs: [generatePromiseRuntime(queueCapacity ?? 256)],
|
|
21
|
+
helperFunctions: [],
|
|
22
|
+
shimMacros: [],
|
|
23
|
+
dependencies: [],
|
|
24
|
+
hasPromiseRuntime: true,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { PlatformStrategy, AsyncRuntimeConfig } from "../api/shared/index.js";
|
|
2
|
+
import type { ExpressionIR, ProgramIR } from "../api/index.js";
|
|
3
|
+
import type { BoardConstants } from "../api/shared/index.js";
|
|
4
|
+
import type { Diagnostic, PlatformContext } from "../types.js";
|
|
5
|
+
import type { RuntimePolyfillIR, StdLibSupport } from "../api/shared/index.js";
|
|
6
|
+
import type { GraphicsCapacity, DisplayHALOp } from "../api/shared/index.js";
|
|
7
|
+
export declare class GenericStrategy implements PlatformStrategy {
|
|
8
|
+
readonly id = "generic";
|
|
9
|
+
private _largeEnumNames;
|
|
10
|
+
forcedIncludes(_program: ProgramIR, _ctx?: PlatformContext): string[];
|
|
11
|
+
symbolAliases(_program: ProgramIR, _ctx?: PlatformContext): Record<string, string>;
|
|
12
|
+
shimLines(_program: ProgramIR, _ctx?: PlatformContext): string[];
|
|
13
|
+
profileDiagnostics(_program: ProgramIR, _ctx?: PlatformContext): Diagnostic[];
|
|
14
|
+
sourceExtension(_isEntryFile: boolean, _isNpmPackage: boolean): string;
|
|
15
|
+
entrypointFunctionName(): string;
|
|
16
|
+
requiresLoopFunction(): boolean;
|
|
17
|
+
overrideBaseName(originalBaseName: string, _outDirBaseName: string, _isEntryFile: boolean, _isNpmPackage: boolean): string;
|
|
18
|
+
effectiveEmitMode(requestedMode: string, _isNpmPackage: boolean): string;
|
|
19
|
+
normalizeCppType(typeName: string): string;
|
|
20
|
+
defaultNumericType(): string;
|
|
21
|
+
mapReturnType(_functionName: string, returnType: string): string;
|
|
22
|
+
isStringLikeType(cppType: string): boolean;
|
|
23
|
+
isPointerType(cppType: string): boolean;
|
|
24
|
+
mapFunctionName(originalName: string): string;
|
|
25
|
+
normalizeRawExpression(value: string): string;
|
|
26
|
+
nullValue(): string;
|
|
27
|
+
wrapStringConcat(_leftRendered: string, _rightRendered: string, _leftIsString: boolean): string | undefined;
|
|
28
|
+
wrapStringObject(expr: string): string;
|
|
29
|
+
useSnprintfForStrings(): boolean;
|
|
30
|
+
renameEnumMember(_enumName: string, memberName: string): string;
|
|
31
|
+
setLargeEnumNames(names: ReadonlySet<string>): void;
|
|
32
|
+
enumCastType(enumName: string): string | undefined;
|
|
33
|
+
renderBoardDefinitionAccess(_chain: string[], _boardConstants?: BoardConstants): string | undefined;
|
|
34
|
+
renderThrow(valueExpr: string): string;
|
|
35
|
+
isConsoleCall(callee: string): boolean;
|
|
36
|
+
transformConsoleCall(method: string, renderedArgs: string, forHeader: boolean): string;
|
|
37
|
+
transformConsoleExpression(method: string, _renderedArgs: string): string | undefined;
|
|
38
|
+
objectFieldInitializer(_fieldValue: ExpressionIR, _renderExpr: (e: ExpressionIR) => string): string | undefined;
|
|
39
|
+
overrideClassFieldType(_fieldName: string, _normalizedType: string): string;
|
|
40
|
+
reservedNames(): ReadonlySet<string>;
|
|
41
|
+
passthroughMacroNames(): ReadonlySet<string>;
|
|
42
|
+
apiReservedEnumNames(): ReadonlySet<string>;
|
|
43
|
+
apiReservedEnumGuard(): string;
|
|
44
|
+
needsIostream(): boolean;
|
|
45
|
+
needsStdString(): boolean;
|
|
46
|
+
needsStdVector(): boolean;
|
|
47
|
+
needsStdExcept(): boolean;
|
|
48
|
+
needsStdFunction(): boolean;
|
|
49
|
+
mathHeader(): string;
|
|
50
|
+
cstringHeader(): string;
|
|
51
|
+
needsVectorOverload(): boolean;
|
|
52
|
+
needsLargeEnumUnderlying(): boolean;
|
|
53
|
+
renameStructField(fieldName: string): string;
|
|
54
|
+
structFieldInitializer(_fieldValue: ExpressionIR, _compiletimeVarNames: Set<string>, _renderExpr: (e: ExpressionIR) => string): string | undefined;
|
|
55
|
+
getAsyncRuntimeConfig(): AsyncRuntimeConfig;
|
|
56
|
+
generateNativePolyfills(program: ProgramIR, ctx?: PlatformContext): RuntimePolyfillIR[];
|
|
57
|
+
asyncLoopInjection(_taskVarNames: string[], config: AsyncRuntimeConfig): string[];
|
|
58
|
+
asyncLoopInjection(_taskVarNames: string[], hasPromiseRuntime: boolean): string[];
|
|
59
|
+
asyncDriverFunctionName(): string;
|
|
60
|
+
shouldSkipTypeAlias(_cppType: string): boolean;
|
|
61
|
+
emitDiagnostics(_emitMode: string): Diagnostic[];
|
|
62
|
+
currentTimeMillis(): string;
|
|
63
|
+
asyncQueueCapacity(): number;
|
|
64
|
+
outputSubdirectory(_baseName: string): string;
|
|
65
|
+
generateHeaderFile(): boolean;
|
|
66
|
+
enumApiGuard(_enumName: string): {
|
|
67
|
+
open: string;
|
|
68
|
+
close: string;
|
|
69
|
+
} | undefined;
|
|
70
|
+
getStdLibSupport(_architecture?: string): StdLibSupport;
|
|
71
|
+
generateDebugInitCode(): string[];
|
|
72
|
+
generateDebugBreakpointCode(params: {
|
|
73
|
+
fileName: string;
|
|
74
|
+
lineNum: number;
|
|
75
|
+
originalLine: string;
|
|
76
|
+
variables: Array<{
|
|
77
|
+
name: string;
|
|
78
|
+
isFunction?: boolean;
|
|
79
|
+
}>;
|
|
80
|
+
normalizedCondition?: string;
|
|
81
|
+
}): string[];
|
|
82
|
+
generateDebugLogpointCode(params: {
|
|
83
|
+
fileName: string;
|
|
84
|
+
lineNum: number;
|
|
85
|
+
parts: Array<{
|
|
86
|
+
type: 'text' | 'variable';
|
|
87
|
+
value: string;
|
|
88
|
+
}>;
|
|
89
|
+
variables: Array<{
|
|
90
|
+
name: string;
|
|
91
|
+
isFunction?: boolean;
|
|
92
|
+
}>;
|
|
93
|
+
}): string[];
|
|
94
|
+
resolveDisplayOp(_op: DisplayHALOp): {
|
|
95
|
+
code?: string;
|
|
96
|
+
expression?: string;
|
|
97
|
+
} | undefined;
|
|
98
|
+
supportedDisplayDrivers(): ReadonlySet<string>;
|
|
99
|
+
colorFormat(): "rgb565" | "rgb666" | "rgb888" | "mono";
|
|
100
|
+
graphicsCapacity(): GraphicsCapacity;
|
|
101
|
+
}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// GenericStrategy — standard C++ target (std::cout, main(), <cmath> …)
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
import { escapeCppStringLiteral } from "../utils/strings.js";
|
|
5
|
+
import { DEFAULT_STDLIB_SUPPORT } from "../api/shared/index.js";
|
|
6
|
+
import { parsedIsPointer } from "../api/shared/cpp-type-ir.js";
|
|
7
|
+
import { buildAsyncRuntimePolyfill } from "./async-runtime.js";
|
|
8
|
+
export class GenericStrategy {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.id = "generic";
|
|
11
|
+
this._largeEnumNames = new Set();
|
|
12
|
+
}
|
|
13
|
+
// ── Profile ─────────────────────────────────────────────────────────────
|
|
14
|
+
forcedIncludes(_program, _ctx) {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
symbolAliases(_program, _ctx) {
|
|
18
|
+
return {};
|
|
19
|
+
}
|
|
20
|
+
shimLines(_program, _ctx) {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
profileDiagnostics(_program, _ctx) {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
// ── File shape ──────────────────────────────────────────────────────────
|
|
27
|
+
sourceExtension(_isEntryFile, _isNpmPackage) {
|
|
28
|
+
return "cpp";
|
|
29
|
+
}
|
|
30
|
+
entrypointFunctionName() {
|
|
31
|
+
return "main";
|
|
32
|
+
}
|
|
33
|
+
requiresLoopFunction() {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
overrideBaseName(originalBaseName, _outDirBaseName, _isEntryFile, _isNpmPackage) {
|
|
37
|
+
return originalBaseName;
|
|
38
|
+
}
|
|
39
|
+
effectiveEmitMode(requestedMode, _isNpmPackage) {
|
|
40
|
+
return requestedMode;
|
|
41
|
+
}
|
|
42
|
+
// ── Type normalisation ──────────────────────────────────────────────────
|
|
43
|
+
normalizeCppType(typeName) {
|
|
44
|
+
if (typeName === "auto")
|
|
45
|
+
return "int";
|
|
46
|
+
return typeName;
|
|
47
|
+
}
|
|
48
|
+
defaultNumericType() { return "int"; }
|
|
49
|
+
mapReturnType(_functionName, returnType) {
|
|
50
|
+
return this.normalizeCppType(returnType);
|
|
51
|
+
}
|
|
52
|
+
isStringLikeType(cppType) {
|
|
53
|
+
// Note: this is the platform-policy definition of "string-like" — kept as
|
|
54
|
+
// an exact set (std::string, const char*, char*) because platform overrides
|
|
55
|
+
// (Arduino's `String`, etc.) extend it with platform-specific types. The
|
|
56
|
+
// broader structural `parsedIsStringLike` is used at consumer sites that
|
|
57
|
+
// don't depend on platform policy.
|
|
58
|
+
return cppType === "std::string" || cppType === "const char*" || cppType === "char*";
|
|
59
|
+
}
|
|
60
|
+
isPointerType(cppType) {
|
|
61
|
+
return parsedIsPointer(cppType);
|
|
62
|
+
}
|
|
63
|
+
mapFunctionName(originalName) {
|
|
64
|
+
if (originalName === "__cuttlefish_entrypoint__")
|
|
65
|
+
return "main";
|
|
66
|
+
return originalName;
|
|
67
|
+
}
|
|
68
|
+
// ── Expression rendering ────────────────────────────────────────────────
|
|
69
|
+
normalizeRawExpression(value) {
|
|
70
|
+
return value;
|
|
71
|
+
}
|
|
72
|
+
nullValue() {
|
|
73
|
+
return "";
|
|
74
|
+
}
|
|
75
|
+
wrapStringConcat(_leftRendered, _rightRendered, _leftIsString) {
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
wrapStringObject(expr) {
|
|
79
|
+
return `std::to_string(${expr})`;
|
|
80
|
+
}
|
|
81
|
+
useSnprintfForStrings() {
|
|
82
|
+
// Native uses snprintf for string concatenation so that non-arithmetic
|
|
83
|
+
// values (enums, class instances) never hit std::to_string() and floats
|
|
84
|
+
// get JS-compatible formatting. This unifies native with the Arduino/AVR
|
|
85
|
+
// snprintf path; see inferFormatSpecifier for per-type format specifiers.
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
renameEnumMember(_enumName, memberName) {
|
|
89
|
+
return memberName;
|
|
90
|
+
}
|
|
91
|
+
setLargeEnumNames(names) {
|
|
92
|
+
this._largeEnumNames = names;
|
|
93
|
+
}
|
|
94
|
+
enumCastType(enumName) {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
renderBoardDefinitionAccess(_chain, _boardConstants) {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
// ── Statement rendering ─────────────────────────────────────────────────
|
|
101
|
+
renderThrow(valueExpr) {
|
|
102
|
+
return `throw ${valueExpr};`;
|
|
103
|
+
}
|
|
104
|
+
isConsoleCall(callee) {
|
|
105
|
+
return callee.startsWith("console.");
|
|
106
|
+
}
|
|
107
|
+
transformConsoleCall(method, renderedArgs, forHeader) {
|
|
108
|
+
const semi = forHeader ? "" : ";";
|
|
109
|
+
switch (method) {
|
|
110
|
+
case "log":
|
|
111
|
+
case "info":
|
|
112
|
+
case "debug":
|
|
113
|
+
return `std::cout << ${renderedArgs} << std::endl${semi}`;
|
|
114
|
+
case "error":
|
|
115
|
+
return `std::cerr << "[ERROR] " << ${renderedArgs} << std::endl${semi}`;
|
|
116
|
+
case "warn":
|
|
117
|
+
return `std::cerr << "[WARN] " << ${renderedArgs} << std::endl${semi}`;
|
|
118
|
+
case "readLine":
|
|
119
|
+
case "readCharacter":
|
|
120
|
+
return this.transformConsoleExpression(method, renderedArgs) + semi;
|
|
121
|
+
default:
|
|
122
|
+
return `std::cout << ${renderedArgs} << std::endl${semi}`;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
transformConsoleExpression(method, _renderedArgs) {
|
|
126
|
+
switch (method) {
|
|
127
|
+
case 'readLine':
|
|
128
|
+
return '([]() -> std::string { std::string s; std::getline(std::cin, s); return s; })()';
|
|
129
|
+
case 'readCharacter':
|
|
130
|
+
return '([&]() -> char { std::cout << "> " << std::flush; return std::cin.get(); })()';
|
|
131
|
+
default:
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
objectFieldInitializer(_fieldValue, _renderExpr) {
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
overrideClassFieldType(_fieldName, _normalizedType) {
|
|
139
|
+
return _normalizedType;
|
|
140
|
+
}
|
|
141
|
+
// ── Name guards ─────────────────────────────────────────────────────────
|
|
142
|
+
reservedNames() {
|
|
143
|
+
return new Set();
|
|
144
|
+
}
|
|
145
|
+
passthroughMacroNames() {
|
|
146
|
+
return new Set();
|
|
147
|
+
}
|
|
148
|
+
apiReservedEnumNames() {
|
|
149
|
+
return new Set();
|
|
150
|
+
}
|
|
151
|
+
apiReservedEnumGuard() {
|
|
152
|
+
return "";
|
|
153
|
+
}
|
|
154
|
+
// ── Includes ────────────────────────────────────────────────────────────
|
|
155
|
+
needsIostream() { return true; }
|
|
156
|
+
needsStdString() { return true; }
|
|
157
|
+
needsStdVector() { return true; }
|
|
158
|
+
needsStdExcept() { return true; }
|
|
159
|
+
needsStdFunction() { return true; }
|
|
160
|
+
mathHeader() { return "<cmath>"; }
|
|
161
|
+
cstringHeader() { return "<cstring>"; }
|
|
162
|
+
needsVectorOverload() { return true; }
|
|
163
|
+
// ── Enum underlying type ────────────────────────────────────────────────
|
|
164
|
+
needsLargeEnumUnderlying() { return false; }
|
|
165
|
+
// ── Struct field handling ───────────────────────────────────────────────
|
|
166
|
+
renameStructField(fieldName) { return fieldName; }
|
|
167
|
+
structFieldInitializer(_fieldValue, _compiletimeVarNames, _renderExpr) {
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
// ── Async ───────────────────────────────────────────────────────────────
|
|
171
|
+
getAsyncRuntimeConfig() {
|
|
172
|
+
return {
|
|
173
|
+
queueCapacity: this.asyncQueueCapacity(),
|
|
174
|
+
scheduler: "microtask",
|
|
175
|
+
waitForPinEdge: "stub",
|
|
176
|
+
hasPromiseRuntime: true,
|
|
177
|
+
hasTimers: false,
|
|
178
|
+
requiredIncludes: ["<functional>", "<vector>", "<utility>", "<string>"],
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
generateNativePolyfills(program, ctx) {
|
|
182
|
+
const helpers = [];
|
|
183
|
+
const asyncRuntime = buildAsyncRuntimePolyfill(program, ctx, "generic", this.asyncQueueCapacity());
|
|
184
|
+
if (asyncRuntime)
|
|
185
|
+
helpers.push(asyncRuntime);
|
|
186
|
+
return helpers;
|
|
187
|
+
}
|
|
188
|
+
asyncLoopInjection(_taskVarNames, configOrBool) {
|
|
189
|
+
let hasPromiseRuntime;
|
|
190
|
+
if (typeof configOrBool === 'boolean') {
|
|
191
|
+
hasPromiseRuntime = configOrBool;
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
hasPromiseRuntime = configOrBool.hasPromiseRuntime;
|
|
195
|
+
}
|
|
196
|
+
const lines = [];
|
|
197
|
+
if (hasPromiseRuntime)
|
|
198
|
+
lines.push(" cuttlefish_pump_microtasks();");
|
|
199
|
+
return lines;
|
|
200
|
+
}
|
|
201
|
+
asyncDriverFunctionName() { return "main"; }
|
|
202
|
+
// ── Type aliases ────────────────────────────────────────────────────────
|
|
203
|
+
shouldSkipTypeAlias(_cppType) { return false; }
|
|
204
|
+
// ── Diagnostics ─────────────────────────────────────────────────────────
|
|
205
|
+
emitDiagnostics(_emitMode) { return []; }
|
|
206
|
+
currentTimeMillis() {
|
|
207
|
+
return 'std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count()';
|
|
208
|
+
}
|
|
209
|
+
// ── Build configuration ─────────────────────────────────────────────────
|
|
210
|
+
asyncQueueCapacity() { return 256; }
|
|
211
|
+
outputSubdirectory(_baseName) { return ".build"; }
|
|
212
|
+
generateHeaderFile() { return true; }
|
|
213
|
+
enumApiGuard(_enumName) { return undefined; }
|
|
214
|
+
getStdLibSupport(_architecture) { return DEFAULT_STDLIB_SUPPORT; }
|
|
215
|
+
// ── Debug code generation ─────────────────────────────────────────────────
|
|
216
|
+
generateDebugInitCode() {
|
|
217
|
+
return [
|
|
218
|
+
'// === DEBUG: Initialize ===',
|
|
219
|
+
'std::cout << "TypeCAD Debug Mode Active" << std::endl;',
|
|
220
|
+
'// === END DEBUG INIT ===',
|
|
221
|
+
'',
|
|
222
|
+
];
|
|
223
|
+
}
|
|
224
|
+
generateDebugBreakpointCode(params) {
|
|
225
|
+
const lines = [];
|
|
226
|
+
lines.push(` // === BREAKPOINT: ${params.fileName}:${params.lineNum} ===`);
|
|
227
|
+
if (params.normalizedCondition) {
|
|
228
|
+
lines.push(` if (${params.normalizedCondition}) {`);
|
|
229
|
+
}
|
|
230
|
+
lines.push(` ${params.normalizedCondition ? ' ' : ''}std::cout << "━━━━━━━━━━━━━━━━━━━━━━━━━━━━" << std::endl;`);
|
|
231
|
+
lines.push(` ${params.normalizedCondition ? ' ' : ''}std::cout << "BREAKPOINT: ${params.fileName}:${params.lineNum}" << std::endl;`);
|
|
232
|
+
lines.push(` ${params.normalizedCondition ? ' ' : ''}std::cout << " ${params.originalLine.replace(/"/g, '\\"')}" << std::endl;`);
|
|
233
|
+
if (params.variables.length > 0) {
|
|
234
|
+
lines.push(` ${params.normalizedCondition ? ' ' : ''}std::cout << " Variables:" << std::endl;`);
|
|
235
|
+
for (const v of params.variables) {
|
|
236
|
+
if (v.isFunction) {
|
|
237
|
+
lines.push(` ${params.normalizedCondition ? ' ' : ''}std::cout << " ${v.name} = [function]" << std::endl;`);
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
lines.push(` ${params.normalizedCondition ? ' ' : ''}std::cout << " ${v.name} = " << ${v.name} << std::endl;`);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
lines.push(` ${params.normalizedCondition ? ' ' : ''}std::cout << "━━━━━━━━━━━━━━━━━━━━━━━━━━━━" << std::endl;`);
|
|
245
|
+
if (params.normalizedCondition) {
|
|
246
|
+
lines.push(` }`);
|
|
247
|
+
}
|
|
248
|
+
lines.push(` // === END BREAKPOINT ===`);
|
|
249
|
+
return lines;
|
|
250
|
+
}
|
|
251
|
+
generateDebugLogpointCode(params) {
|
|
252
|
+
const lines = [];
|
|
253
|
+
lines.push(` // === LOGPOINT: ${params.fileName}:${params.lineNum} ===`);
|
|
254
|
+
const parts = [`"[LOG ${params.fileName}:${params.lineNum}] "`];
|
|
255
|
+
for (const part of params.parts) {
|
|
256
|
+
if (part.type === 'text') {
|
|
257
|
+
parts.push(`"${escapeCppStringLiteral(part.value)}"`);
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
const varExists = params.variables.some(v => v.name === part.value && !v.isFunction);
|
|
261
|
+
parts.push(varExists ? part.value : `"${escapeCppStringLiteral(part.value)}"`);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
lines.push(` std::cout << ${parts.join(' << ')} << std::endl;`);
|
|
265
|
+
lines.push(` // === END LOGPOINT ===`);
|
|
266
|
+
return lines;
|
|
267
|
+
}
|
|
268
|
+
// ── Graphics (fallback) ────────────────────────────────────────────────
|
|
269
|
+
resolveDisplayOp(_op) {
|
|
270
|
+
// Generic target has no display hardware. Returning undefined lets the
|
|
271
|
+
// emitter fall back; if a UI is mounted against the generic target the
|
|
272
|
+
// mount-time validation should have already errored.
|
|
273
|
+
return undefined;
|
|
274
|
+
}
|
|
275
|
+
supportedDisplayDrivers() {
|
|
276
|
+
return new Set();
|
|
277
|
+
}
|
|
278
|
+
colorFormat() {
|
|
279
|
+
return "rgb565";
|
|
280
|
+
}
|
|
281
|
+
graphicsCapacity() {
|
|
282
|
+
return {
|
|
283
|
+
maxNodes: 256,
|
|
284
|
+
maxBindings: 64,
|
|
285
|
+
maxActiveTransitions: 32,
|
|
286
|
+
nodeStorage: "flash",
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Platform strategy exports
|
|
3
|
+
//
|
|
4
|
+
// Re-exports platform strategies for use within the CLI and by consumers.
|
|
5
|
+
// Framework-specific strategies (e.g. ArduinoStrategy) are provided by their
|
|
6
|
+
// respective framework packages, which register via registerPlatformStrategy().
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
export { GenericStrategy } from './generic-strategy.js';
|
|
9
|
+
export { resolveStrategy, registerPlatformStrategy } from './registry.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { PlatformStrategy } from "../api/shared/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Register a custom platform strategy. Framework packages call this from
|
|
4
|
+
* their entry point to override the default strategy for a target.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* // In @typecad/framework-arduino
|
|
8
|
+
* import { registerPlatformStrategy } from "@typecad/cuttlefish/platform/registry";
|
|
9
|
+
* registerPlatformStrategy(new ArduinoStrategy());
|
|
10
|
+
*/
|
|
11
|
+
export declare function registerPlatformStrategy(strategy: PlatformStrategy): void;
|
|
12
|
+
/**
|
|
13
|
+
* Resolve a PlatformStrategy for the given target profile.
|
|
14
|
+
* Falls back to the "generic" strategy if no match is found.
|
|
15
|
+
*/
|
|
16
|
+
export declare function resolveStrategy(target: string): PlatformStrategy;
|
|
17
|
+
/**
|
|
18
|
+
* Clear profile caches on all registered strategies.
|
|
19
|
+
* Should be called between transpilations to ensure fresh profile resolution.
|
|
20
|
+
*/
|
|
21
|
+
export declare function clearAllProfileCaches(): void;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Platform strategy registry
|
|
3
|
+
//
|
|
4
|
+
// Maps target profile strings to PlatformStrategy implementations.
|
|
5
|
+
// Framework packages call `registerPlatformStrategy()` to plug in custom
|
|
6
|
+
// strategies at import time.
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
import { GenericStrategy } from "./generic-strategy.js";
|
|
9
|
+
const _genericStrategy = new GenericStrategy();
|
|
10
|
+
const _registry = new Map([
|
|
11
|
+
["generic", _genericStrategy],
|
|
12
|
+
]);
|
|
13
|
+
/**
|
|
14
|
+
* Register a custom platform strategy. Framework packages call this from
|
|
15
|
+
* their entry point to override the default strategy for a target.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // In @typecad/framework-arduino
|
|
19
|
+
* import { registerPlatformStrategy } from "@typecad/cuttlefish/platform/registry";
|
|
20
|
+
* registerPlatformStrategy(new ArduinoStrategy());
|
|
21
|
+
*/
|
|
22
|
+
export function registerPlatformStrategy(strategy) {
|
|
23
|
+
_registry.set(strategy.id, strategy);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Resolve a PlatformStrategy for the given target profile.
|
|
27
|
+
* Falls back to the "generic" strategy if no match is found.
|
|
28
|
+
*/
|
|
29
|
+
export function resolveStrategy(target) {
|
|
30
|
+
return _registry.get(target) ?? _registry.get("generic");
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Clear profile caches on all registered strategies.
|
|
34
|
+
* Should be called between transpilations to ensure fresh profile resolution.
|
|
35
|
+
*/
|
|
36
|
+
export function clearAllProfileCaches() {
|
|
37
|
+
for (const strategy of _registry.values()) {
|
|
38
|
+
if (typeof strategy.clearProfileCache === "function") {
|
|
39
|
+
strategy.clearProfileCache();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ToolchainOptions, CompileResult, UploadResult } from "../api/shared/index.js";
|
|
2
|
+
export declare function compileSource(options: ToolchainOptions): CompileResult;
|
|
3
|
+
export declare function uploadFirmware(options: ToolchainOptions): UploadResult;
|
|
4
|
+
export declare function monitorDevice(options: ToolchainOptions): void;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Generic toolchain delegation
|
|
3
|
+
//
|
|
4
|
+
// Provides framework-agnostic compile/upload/monitor functions that delegate
|
|
5
|
+
// to whatever toolchain the active framework provides.
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
import { getLoadedFramework, hasLoadedFramework } from "../framework-registry.js";
|
|
8
|
+
import { loadFrameworkPackage } from "../framework-package.js";
|
|
9
|
+
function getToolchain(fromDir, frameworkPackage) {
|
|
10
|
+
if (hasLoadedFramework()) {
|
|
11
|
+
const { toolchain } = getLoadedFramework();
|
|
12
|
+
if (toolchain)
|
|
13
|
+
return toolchain;
|
|
14
|
+
}
|
|
15
|
+
if (frameworkPackage) {
|
|
16
|
+
loadFrameworkPackage(frameworkPackage, fromDir);
|
|
17
|
+
if (hasLoadedFramework()) {
|
|
18
|
+
const { toolchain } = getLoadedFramework();
|
|
19
|
+
if (toolchain)
|
|
20
|
+
return toolchain;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
throw new Error("No framework toolchain available. Specify a framework package in your TypeCAD config " +
|
|
24
|
+
"or ensure a framework with compile/upload support is installed.");
|
|
25
|
+
}
|
|
26
|
+
export function compileSource(options) {
|
|
27
|
+
const toolchain = getToolchain(options.outputDir);
|
|
28
|
+
return toolchain.compile(options);
|
|
29
|
+
}
|
|
30
|
+
export function uploadFirmware(options) {
|
|
31
|
+
const toolchain = getToolchain(options.outputDir);
|
|
32
|
+
if (!toolchain.upload) {
|
|
33
|
+
throw new Error("The active framework does not support upload.");
|
|
34
|
+
}
|
|
35
|
+
return toolchain.upload(options);
|
|
36
|
+
}
|
|
37
|
+
export function monitorDevice(options) {
|
|
38
|
+
const toolchain = getToolchain(options.outputDir);
|
|
39
|
+
if (!toolchain.monitor) {
|
|
40
|
+
throw new Error("The active framework does not support device monitoring.");
|
|
41
|
+
}
|
|
42
|
+
toolchain.monitor(options);
|
|
43
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|