@typecad/cuttlefish 1.0.0-alpha.13 → 1.0.0-alpha.15
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 +82 -79
- package/assets/editor-extensions/typecad-debug/README.md +141 -0
- package/assets/editor-extensions/typecad-debug/out/extension.js +347 -0
- package/assets/editor-extensions/typecad-debug/out/extension.js.map +1 -0
- package/assets/editor-extensions/typecad-debug/package.json +76 -0
- package/assets/editor-extensions/typecad-ui/LICENSE +27 -0
- package/assets/editor-extensions/typecad-ui/README.md +52 -0
- package/assets/editor-extensions/typecad-ui/file-icon-dark.png +0 -0
- package/assets/editor-extensions/typecad-ui/file-icon-light.png +0 -0
- package/assets/editor-extensions/typecad-ui/icon.png +0 -0
- package/assets/editor-extensions/typecad-ui/language-configuration.json +43 -0
- package/assets/editor-extensions/typecad-ui/package.json +54 -0
- package/assets/editor-extensions/typecad-ui/snippets/typecad-ui.json +80 -0
- package/assets/editor-extensions/typecad-ui/syntaxes/markdown-ui.json +45 -0
- package/assets/editor-extensions/typecad-ui/syntaxes/typecad-ui.tmLanguage.json +1269 -0
- package/dist/api/config.d.ts +30 -27
- package/dist/api/schema/types.d.ts +20 -3
- package/dist/api/shared/async-runtime-static.d.ts +1 -1
- package/dist/api/shared/async-runtime-static.js +5 -5
- package/dist/api/shared/async-types.d.ts +3 -2
- package/dist/api/shared/board-catalog.d.ts +2 -0
- package/dist/api/shared/board-catalog.js +6 -0
- package/dist/api/shared/board-resolver.d.ts +4 -7
- package/dist/api/shared/board-resolver.js +2 -1
- package/dist/api/shared/coop-scheduler.d.ts +1 -1
- package/dist/api/shared/coop-scheduler.js +1 -1
- package/dist/api/shared/cpp-type-ir.d.ts +1 -1
- package/dist/api/shared/cpp-type-ir.js +1 -1
- package/dist/api/shared/display-profile.d.ts +1 -1
- package/dist/api/shared/display-profile.js +3 -5
- package/dist/api/shared/framework-manifest-registry.d.ts +1 -1
- package/dist/api/shared/framework-manifest-registry.js +0 -1
- package/dist/api/shared/framework-manifest.d.ts +65 -507
- package/dist/api/shared/framework-manifest.js +6 -11
- package/dist/api/shared/hal-op-ir.d.ts +294 -685
- package/dist/api/shared/hal-op-ir.js +31 -65
- package/dist/api/shared/index.d.ts +0 -4
- package/dist/api/shared/index.js +1 -7
- package/dist/api/shared/ir-core.d.ts +6 -0
- package/dist/api/shared/ir-declarations.d.ts +4 -0
- package/dist/api/shared/ir.d.ts +1 -3
- package/dist/api/shared/platform-strategy.d.ts +14 -37
- package/dist/api/shared/polyfill-helper-registry.js +0 -5
- package/dist/api/shared/polyfill-types.js +0 -27
- package/dist/api/shared/promise-runtime.js +3 -3
- package/dist/api/shared/spdx-licenses.d.ts +12 -10
- package/dist/api/shared/spdx-licenses.js +1 -1
- package/dist/api/shared/toolchain-types.d.ts +1 -1
- package/dist/api/shared/toolchain-types.js +3 -3
- package/dist/api/shared/types.d.ts +0 -3
- package/dist/api/shared/validate-framework-manifest.js +13 -33
- package/dist/board-catalog/dts-reader.d.ts +220 -0
- package/dist/board-catalog/dts-reader.js +1052 -0
- package/dist/board-catalog/index.d.ts +11 -0
- package/dist/board-catalog/index.js +12 -0
- package/dist/board-catalog/pinconfig.d.ts +48 -0
- package/dist/board-catalog/pinconfig.js +263 -0
- package/dist/board-catalog/sdk.d.ts +82 -0
- package/dist/board-catalog/sdk.js +180 -0
- package/dist/board-catalog/store.d.ts +196 -0
- package/dist/board-catalog/store.js +363 -0
- package/dist/board-catalog/types.d.ts +233 -0
- package/dist/board-catalog/types.js +7 -0
- package/dist/board-catalog/walker.d.ts +112 -0
- package/dist/board-catalog/walker.js +1101 -0
- package/dist/cli-utils.d.ts +2 -2
- package/dist/cli-utils.js +5 -5
- package/dist/cli.js +227 -244
- package/dist/config-loader.d.ts +14 -19
- package/dist/config-loader.js +242 -78
- package/dist/config-schema.d.ts +19 -227
- package/dist/config-schema.js +9 -8
- package/dist/contract/board-generator.d.ts +4 -4
- package/dist/contract/board-generator.js +16 -5
- package/dist/contract/contract-parser.d.ts +36 -127
- package/dist/contract/contract-parser.js +76 -0
- package/dist/contract/index.d.ts +1 -1
- package/dist/contract/index.js +70 -21
- package/dist/create/active-board-catalog.d.ts +9 -0
- package/dist/create/active-board-catalog.js +94 -0
- package/dist/create/board-catalog.generated.d.ts +96 -0
- package/dist/create/board-catalog.generated.js +128737 -0
- package/dist/create/board-search.d.ts +23 -0
- package/dist/create/board-search.js +88 -0
- package/dist/create/editor-integration.d.ts +32 -0
- package/dist/create/editor-integration.js +257 -0
- package/dist/create/eslint-rules-template.d.ts +2 -2
- package/dist/create/framework-catalog.d.ts +48 -8
- package/dist/create/framework-catalog.js +58 -44
- package/dist/create/index.d.ts +8 -13
- package/dist/create/index.js +5 -9
- package/dist/create/mcu-target.d.ts +39 -0
- package/dist/create/mcu-target.js +80 -0
- package/dist/create/pack-targets.d.ts +19 -0
- package/dist/create/pack-targets.js +56 -0
- package/dist/create/{init-scaffold.d.ts → scaffold.d.ts} +8 -11
- package/dist/create/{init-scaffold.js → scaffold.js} +28 -87
- package/dist/create/templates.d.ts +51 -0
- package/dist/create/{init-templates.js → templates.js} +135 -116
- package/dist/create/wizard.d.ts +19 -0
- package/dist/create/wizard.js +314 -0
- package/dist/debug/preprocessor.d.ts +5 -0
- package/dist/debug/preprocessor.js +31 -7
- package/dist/diagnostics/diagnostics-report.d.ts +1 -1
- package/dist/diagnostics/diagnostics-report.js +3 -11
- package/dist/diagnostics/json-schema.d.ts +1 -1
- package/dist/diagnostics/md-writer.js +2 -2
- package/dist/diagnostics/mermaid-builder.d.ts +1 -1
- package/dist/diagnostics/mermaid-builder.js +1 -1
- package/dist/emit/cpp-emitter.js +4 -1
- package/dist/emit/emitters/class-emitter.js +32 -4
- package/dist/emit/emitters/emitter-context.d.ts +11 -0
- package/dist/emit/emitters/entrypoint-synthesizer.js +1 -1
- package/dist/emit/emitters/function-emitter-impl.js +33 -17
- package/dist/emit/emitters/output-finalizer.d.ts +7 -0
- package/dist/emit/emitters/output-finalizer.js +31 -23
- package/dist/emit/emitters/setup.js +147 -63
- package/dist/emit/emitters/top-level-prep.js +1 -1
- package/dist/emit/emitters/type-decl-emitter.js +13 -8
- package/dist/emit/emitters/ui-emitter.js +1 -1
- package/dist/emit/expression-renderer.d.ts +3 -3
- package/dist/emit/expression-renderer.js +17 -7
- package/dist/emit/route-hal-op.js +17 -48
- package/dist/emit/snprintf-helpers.d.ts +1 -3
- package/dist/emit/snprintf-helpers.js +1 -39
- package/dist/emit/statement-renderer.d.ts +0 -4
- package/dist/emit/statement-renderer.js +54 -45
- package/dist/emit/utils/async-state-machine.d.ts +16 -9
- package/dist/emit/utils/async-state-machine.js +56 -54
- package/dist/emit/utils/comment-helpers.d.ts +0 -8
- package/dist/emit/utils/comment-helpers.js +1 -1
- package/dist/emit/utils/cpp-helpers.d.ts +2 -2
- package/dist/emit/utils/cpp-helpers.js +2 -2
- package/dist/emit/utils/hal-op-cpp-type.js +4 -6
- package/dist/emit/utils/index.d.ts +3 -3
- package/dist/emit/utils/index.js +3 -3
- package/dist/emit/utils/type-inference.d.ts +1 -29
- package/dist/emit/utils/type-inference.js +0 -75
- package/dist/framework-package.d.ts +3 -0
- package/dist/framework-package.js +23 -6
- package/dist/framework-registry.d.ts +5 -5
- package/dist/frameworks/native/graphics/terminal-preview.d.ts +5 -0
- package/dist/frameworks/native/graphics/terminal-preview.js +33 -0
- package/dist/frameworks/native/index.d.ts +3 -0
- package/dist/frameworks/native/index.js +15 -0
- package/dist/frameworks/native/native-compile.d.ts +17 -0
- package/dist/frameworks/native/native-compile.js +170 -0
- package/dist/frameworks/native/native-config.d.ts +41 -0
- package/dist/frameworks/native/native-config.js +7 -0
- package/dist/frameworks/native/strategy.d.ts +97 -0
- package/dist/frameworks/native/strategy.js +664 -0
- package/dist/ir/board-resolver.d.ts +18 -23
- package/dist/ir/board-resolver.js +43 -401
- package/dist/ir/build-ir-state.d.ts +3 -0
- package/dist/ir/build-ir-state.js +42 -0
- package/dist/ir/build-ir.d.ts +1 -1
- package/dist/ir/build-ir.js +64 -45
- package/dist/ir/declaration-builders.js +1 -0
- package/dist/ir/expression-to-ir.js +17 -10
- package/dist/ir/hal/hal-emitter.d.ts +0 -2
- package/dist/ir/hal/hal-emitter.js +92 -41
- package/dist/ir/hal/hal-parser.d.ts +5 -5
- package/dist/ir/hal/hal-parser.js +128 -36
- package/dist/ir/hal/hal-plugins.d.ts +0 -1
- package/dist/ir/hal/hal-plugins.js +425 -716
- package/dist/ir/heap-analysis.js +2 -41
- package/dist/ir/identifier-collector.js +32 -20
- package/dist/ir/network-validation.js +7 -11
- package/dist/ir/ownership-analysis.js +75 -13
- package/dist/ir/peripheral-usage.d.ts +8 -2
- package/dist/ir/peripheral-usage.js +78 -149
- package/dist/ir/peripheral-validation.js +23 -3
- package/dist/ir/pin-capability-validation.d.ts +12 -0
- package/dist/ir/pin-capability-validation.js +61 -97
- package/dist/ir/pin-mode-validation.js +5 -5
- package/dist/ir/program-analysis.d.ts +8 -15
- package/dist/ir/program-analysis.js +140 -323
- package/dist/ir/pulldown-validation.js +11 -4
- package/dist/ir/resource-analysis.js +15 -3
- package/dist/ir/statement-to-ir.js +0 -6
- package/dist/ir/timing-validation.js +1 -1
- package/dist/ir/transformers/array-methods.js +11 -5
- package/dist/ir/transformers/call-statement.js +20 -87
- package/dist/ir/transformers/callback-context-registry.d.ts +1 -1
- package/dist/ir/transformers/callback-context-registry.js +8 -16
- package/dist/ir/transformers/control-flow.js +0 -13
- package/dist/ir/transformers/expressions.js +10 -9
- package/dist/ir/transformers/hal-call-resolver.d.ts +2 -2
- package/dist/ir/transformers/hal-call-resolver.js +24 -10
- package/dist/ir/transformers/hal-emit-helpers.d.ts +2 -2
- package/dist/ir/transformers/hal-emit-helpers.js +2 -2
- package/dist/ir/transformers/namespace-methods.js +1 -1
- package/dist/ir/transformers/ui-callback-lowering.d.ts +0 -2
- package/dist/ir/transformers/ui-callback-lowering.js +0 -24
- package/dist/ir/transformers/variables.js +338 -42
- package/dist/ir/try-catch-validation.js +4 -3
- package/dist/ir/type-resolution.js +15 -4
- package/dist/ir/validation-orchestrator.js +0 -9
- package/dist/libdef/cpp-to-decl.d.ts +0 -9
- package/dist/libdef/cpp-to-decl.js +0 -72
- package/dist/libdef/registry.d.ts +0 -1
- package/dist/libdef/registry.js +1 -24
- package/dist/library/catalog.d.ts +35 -0
- package/dist/library/catalog.js +67 -0
- package/dist/library/cli.d.ts +2 -0
- package/dist/library/cli.js +168 -0
- package/dist/library/init.d.ts +25 -0
- package/dist/library/init.js +397 -0
- package/dist/library/install.d.ts +9 -0
- package/dist/library/install.js +80 -0
- package/dist/library/registry-search.d.ts +34 -0
- package/dist/library/registry-search.js +50 -0
- package/dist/library/validate.d.ts +17 -0
- package/dist/library/validate.js +175 -0
- package/dist/library-packages.d.ts +95 -0
- package/dist/library-packages.js +275 -0
- package/dist/mapping/peripheral-names.js +9 -4
- package/dist/mapping/source-map.d.ts +3 -4
- package/dist/mapping/source-map.js +12 -18
- package/dist/orchestrator/graph-builder.d.ts +3 -3
- package/dist/orchestrator/graph-builder.js +29 -12
- package/dist/orchestrator/type-checker.d.ts +3 -3
- package/dist/orchestrator/type-checker.js +3 -3
- package/dist/platform/async-runtime.js +1 -1
- package/dist/platform/coop-scheduler-runtime.js +2 -2
- package/dist/platform/generic-debug-codegen.d.ts +36 -0
- package/dist/platform/generic-debug-codegen.js +185 -0
- package/dist/platform/generic-strategy.d.ts +3 -4
- package/dist/platform/generic-strategy.js +5 -80
- package/dist/platform/index.js +1 -1
- package/dist/platform/registry.d.ts +2 -2
- package/dist/platform/registry.js +2 -2
- package/dist/preview/client.js +17 -3
- package/dist/safety/asil-decorators.d.ts +32 -0
- package/dist/safety/asil-decorators.js +32 -0
- package/dist/safety/authoring.d.ts +85 -0
- package/dist/safety/authoring.js +61 -0
- package/dist/safety/engine.d.ts +3 -0
- package/dist/safety/engine.js +83 -0
- package/dist/safety/hal/ops.d.ts +48 -0
- package/dist/safety/hal/ops.js +46 -0
- package/dist/safety/iso26262/analyze.d.ts +13 -0
- package/dist/safety/iso26262/analyze.js +29 -0
- package/dist/safety/iso26262/asil.d.ts +10 -0
- package/dist/safety/iso26262/asil.js +22 -0
- package/dist/safety/iso26262/collect.d.ts +14 -0
- package/dist/safety/iso26262/collect.js +137 -0
- package/dist/safety/iso26262/goto-checker.d.ts +10 -0
- package/dist/safety/iso26262/goto-checker.js +72 -0
- package/dist/safety/iso26262/heap-checker.d.ts +7 -0
- package/dist/safety/iso26262/heap-checker.js +57 -0
- package/dist/safety/iso26262/init-checker.d.ts +13 -0
- package/dist/safety/iso26262/init-checker.js +127 -0
- package/dist/safety/iso26262/loop-checker.d.ts +7 -0
- package/dist/safety/iso26262/loop-checker.js +86 -0
- package/dist/safety/iso26262/recursion-checker.d.ts +9 -0
- package/dist/safety/iso26262/recursion-checker.js +134 -0
- package/dist/safety/iso26262/sidecar-writer.d.ts +25 -0
- package/dist/safety/iso26262/sidecar-writer.js +13 -0
- package/dist/safety/passes/pinMode-intercept.d.ts +3 -0
- package/dist/safety/passes/pinMode-intercept.js +60 -0
- package/dist/safety/runtime/mode-table.d.ts +5 -0
- package/dist/safety/runtime/mode-table.js +55 -0
- package/dist/safety/runtime/polyfills.d.ts +6 -0
- package/dist/safety/runtime/polyfills.js +12 -0
- package/dist/safety/runtime/result-struct.d.ts +11 -0
- package/dist/safety/runtime/result-struct.js +98 -0
- package/dist/safety/runtime/safe-int.d.ts +33 -0
- package/dist/safety/runtime/safe-int.js +170 -0
- package/dist/safety/runtime/safe-traits.d.ts +4 -0
- package/dist/safety/runtime/safe-traits.js +95 -0
- package/dist/safety/runtime/safe-variable.d.ts +39 -0
- package/dist/safety/runtime/safe-variable.js +226 -0
- package/dist/safety/runtime/vote.d.ts +8 -0
- package/dist/safety/runtime/vote.js +92 -0
- package/dist/safety/runtime/write-verify.d.ts +8 -0
- package/dist/safety/runtime/write-verify.js +71 -0
- package/dist/safety/safe-int-types.d.ts +45 -0
- package/dist/safety/safe-int-types.js +25 -0
- package/dist/safety/safe-variable-types.d.ts +29 -0
- package/dist/safety/safe-variable-types.js +19 -0
- package/dist/safety/safety-bridge.d.ts +5 -6
- package/dist/safety/safety-bridge.js +15 -28
- package/dist/safety/sidecar-bridge.d.ts +1 -3
- package/dist/safety/sidecar-bridge.js +3 -20
- package/dist/safety/specifiers.d.ts +6 -0
- package/dist/safety/specifiers.js +14 -0
- package/dist/safety-hook.d.ts +8 -7
- package/dist/safety-hook.js +12 -13
- package/dist/testing.d.ts +5 -6
- package/dist/testing.js +5 -5
- package/dist/transpile/resolution.d.ts +1 -1
- package/dist/transpile/resolution.js +18 -9
- package/dist/transpile/test-pins.d.ts +18 -0
- package/dist/transpile/test-pins.js +142 -0
- package/dist/transpile.d.ts +1 -2
- package/dist/transpile.js +90 -29
- package/dist/types.d.ts +45 -26
- package/dist/ui-hook.d.ts +1 -1
- package/dist/utils/cli.d.ts +2 -2
- package/dist/utils/cli.js +160 -157
- package/dist/utils/fs.d.ts +3 -4
- package/dist/utils/fs.js +4 -5
- package/dist/utils/strings.d.ts +0 -1
- package/dist/utils/strings.js +0 -8
- package/dist/utils/ui.d.ts +5 -2
- package/dist/utils/ui.js +13 -3
- package/package.json +158 -149
- package/dist/add-preset.d.ts +0 -4
- package/dist/add-preset.js +0 -74
- package/dist/api/shared/async-symbol-detector.d.ts +0 -11
- package/dist/api/shared/async-symbol-detector.js +0 -140
- package/dist/api/shared/native-display-op-resolver.d.ts +0 -10
- package/dist/api/shared/native-display-op-resolver.js +0 -64
- package/dist/create/board-checklist.d.ts +0 -2
- package/dist/create/board-checklist.js +0 -52
- package/dist/create/board-codegen.d.ts +0 -9
- package/dist/create/board-codegen.js +0 -238
- package/dist/create/board-generators.d.ts +0 -12
- package/dist/create/board-generators.js +0 -651
- package/dist/create/board-spec.d.ts +0 -637
- package/dist/create/board-spec.js +0 -214
- package/dist/create/init-templates.d.ts +0 -28
- package/dist/create/init-wizard.d.ts +0 -8
- package/dist/create/init-wizard.js +0 -182
- package/dist/install/framework-catalog.d.ts +0 -53
- package/dist/install/framework-catalog.js +0 -107
- package/dist/install/handle-install.d.ts +0 -35
- package/dist/install/handle-install.js +0 -177
- package/dist/install/index.d.ts +0 -4
- package/dist/install/index.js +0 -3
- package/dist/ir/pin-state-tracking.d.ts +0 -58
- package/dist/ir/pin-state-tracking.js +0 -182
- package/dist/ir/pwm-timer-sharing.d.ts +0 -4
- package/dist/ir/pwm-timer-sharing.js +0 -94
- package/dist/ir/timer0-pwm-timing-conflict.d.ts +0 -4
- package/dist/ir/timer0-pwm-timing-conflict.js +0 -72
- package/dist/libdef/component-decls.d.ts +0 -2
- package/dist/libdef/component-decls.js +0 -6
- package/dist/libdef/component-discovery.d.ts +0 -43
- package/dist/libdef/component-discovery.js +0 -83
- package/dist/theme-tokens.d.ts +0 -22
- package/dist/theme-tokens.js +0 -172
|
@@ -12,12 +12,23 @@ import { routeHALOp } from "../route-hal-op.js";
|
|
|
12
12
|
* @param str The input string (e.g., "my_function" or "myFunction")
|
|
13
13
|
* @returns PascalCase string (e.g., "MyFunction")
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
function toPascalCaseLocal(str) {
|
|
16
16
|
return str
|
|
17
17
|
.split(/[_\s]+/)
|
|
18
18
|
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
19
19
|
.join("");
|
|
20
20
|
}
|
|
21
|
+
/** Awaited callees that legitimately lower to a plain timed wait (their
|
|
22
|
+
* single numeric argument IS the deadline). Everything else reaching the
|
|
23
|
+
* plain-wait arm would have its call silently dropped — the embedding
|
|
24
|
+
* emitter turns that into a diagnostic via onUnsupportedAwait. */
|
|
25
|
+
const PLAIN_AWAIT_CALLEES = new Set([
|
|
26
|
+
"Async.sleep",
|
|
27
|
+
"AsyncClass.sleep",
|
|
28
|
+
"__cuttlefish_async_sleep",
|
|
29
|
+
"delay",
|
|
30
|
+
"sleep",
|
|
31
|
+
]);
|
|
21
32
|
/**
|
|
22
33
|
* Generates a cooperative state-machine class for an async function.
|
|
23
34
|
*
|
|
@@ -33,9 +44,11 @@ export function toPascalCaseLocal(str) {
|
|
|
33
44
|
* @param knownFunctionReturnTypes Map of function names to their return types
|
|
34
45
|
* @returns The class definition, instance declaration, and task variable name
|
|
35
46
|
*/
|
|
36
|
-
export function generateAsyncTaskClass(fnName, fnStatements, strategy, knownFunctionReturnTypes, renderStatement) {
|
|
47
|
+
export function generateAsyncTaskClass(fnName, fnStatements, strategy, knownFunctionReturnTypes, renderStatement, options) {
|
|
37
48
|
const className = toPascalCaseLocal(fnName) + "Task";
|
|
38
49
|
const instanceName = `${fnName}Task`;
|
|
50
|
+
const owner = options?.ownerClassName;
|
|
51
|
+
const starterName = `__tc_async_start_${fnName}`;
|
|
39
52
|
// Detect whether the body is a single while-loop (cyclic) or linear statements
|
|
40
53
|
let bodyStatements;
|
|
41
54
|
let isCyclic = false;
|
|
@@ -51,7 +64,7 @@ export function generateAsyncTaskClass(fnName, fnStatements, strategy, knownFunc
|
|
|
51
64
|
let currentPre = [];
|
|
52
65
|
for (const stmt of bodyStatements) {
|
|
53
66
|
if (stmt.kind === "call" && stmt.isAwaited) {
|
|
54
|
-
segments.push({ preStatements: currentPre, awaitedCallee: stmt.callee, awaitedArgs: stmt.args });
|
|
67
|
+
segments.push({ preStatements: currentPre, awaitedCallee: stmt.callee, awaitedArgs: stmt.args, awaitedSpan: stmt.sourceSpan });
|
|
55
68
|
currentPre = [];
|
|
56
69
|
}
|
|
57
70
|
else if (
|
|
@@ -65,7 +78,7 @@ export function generateAsyncTaskClass(fnName, fnStatements, strategy, knownFunc
|
|
|
65
78
|
stmt.body[stmt.body.length - 1].isAwaited) {
|
|
66
79
|
const last = stmt.body[stmt.body.length - 1];
|
|
67
80
|
currentPre.push(...stmt.body.slice(0, -1));
|
|
68
|
-
segments.push({ preStatements: currentPre, awaitedCallee: last.callee, awaitedArgs: last.args });
|
|
81
|
+
segments.push({ preStatements: currentPre, awaitedCallee: last.callee, awaitedArgs: last.args, awaitedSpan: last.sourceSpan });
|
|
69
82
|
currentPre = [];
|
|
70
83
|
}
|
|
71
84
|
else {
|
|
@@ -173,7 +186,13 @@ export function generateAsyncTaskClass(fnName, fnStatements, strategy, knownFunc
|
|
|
173
186
|
}
|
|
174
187
|
}
|
|
175
188
|
else {
|
|
176
|
-
// Plain timed wait (await delay(ms)) — arm its deadline.
|
|
189
|
+
// Plain timed wait (await delay(ms)) — arm its deadline. Anything whose
|
|
190
|
+
// callee is not a known timer shape has no cooperative lowering here:
|
|
191
|
+
// the call itself is NOT rendered (only marker/net awaits carry start
|
|
192
|
+
// code), so report it instead of silently dropping it.
|
|
193
|
+
if (!PLAIN_AWAIT_CALLEES.has(seg.awaitedCallee)) {
|
|
194
|
+
options?.onUnsupportedAwait?.(seg.awaitedCallee, seg.awaitedSpan);
|
|
195
|
+
}
|
|
177
196
|
const ms = seg.awaitedArgs[0] ? renderExpression(seg.awaitedArgs[0], strategy) : "0";
|
|
178
197
|
lines.push(`${pad}_waitUntil = ${strategy.currentTimeMillis()} + ${ms};`);
|
|
179
198
|
}
|
|
@@ -265,19 +284,37 @@ export function generateAsyncTaskClass(fnName, fnStatements, strategy, knownFunc
|
|
|
265
284
|
inits.push(`${m}(LOW)`);
|
|
266
285
|
for (const m of tapMemberArr)
|
|
267
286
|
inits.push(`${m}(0)`);
|
|
287
|
+
// Owner pointer (async methods): initialized null, bound by start(owner).
|
|
288
|
+
// Declared last / initialized last so the initializer list order matches.
|
|
289
|
+
if (owner)
|
|
290
|
+
inits.push("_owner(nullptr)");
|
|
268
291
|
const ctorInitList = inits.join(", ");
|
|
269
292
|
const edgeResetList = edgeMemberArr.map(m => ` ${m} = LOW;`).join("");
|
|
270
293
|
const tapResetList = tapMemberArr.map(m => ` ${m} = 0;`).join("");
|
|
271
294
|
const edgeMemberDecls = edgeMemberArr.map(m => ` int ${m};`);
|
|
272
295
|
// __ui_tap_seq is uint32_t; the snapshot must match to detect bumps correctly.
|
|
273
296
|
const tapMemberDecls = tapMemberArr.map(m => ` uint32_t ${m};`);
|
|
297
|
+
const ownerMemberDecl = owner ? [` ${owner}* _owner;`] : [];
|
|
298
|
+
const runGuard = owner ? [` if (_owner == nullptr) { return; }`] : [];
|
|
299
|
+
// start(owner): (re)bind the receiver and rewind the machine. Calling the
|
|
300
|
+
// async method again restarts the task with the new receiver — the task
|
|
301
|
+
// is a singleton per method, mirroring the free-function tasks.
|
|
302
|
+
const startMethod = owner ? [
|
|
303
|
+
` void start(${owner}* owner) {`,
|
|
304
|
+
` _owner = owner;`,
|
|
305
|
+
` _state = ${Q_0};`,
|
|
306
|
+
` _waitUntil = 0;${edgeResetList}${tapResetList}`,
|
|
307
|
+
` }`,
|
|
308
|
+
] : [];
|
|
274
309
|
const classDef = [
|
|
275
310
|
`// Async state machine for ${fnName}`,
|
|
276
311
|
`class ${className} {`,
|
|
277
312
|
`public:`,
|
|
278
313
|
` enum class State { ${stateEnumList} };`,
|
|
279
314
|
` ${className}() : ${ctorInitList} {}`,
|
|
315
|
+
...startMethod,
|
|
280
316
|
` void run() {`,
|
|
317
|
+
...runGuard,
|
|
281
318
|
` switch (_state) {`,
|
|
282
319
|
...caseLines,
|
|
283
320
|
` }`,
|
|
@@ -289,9 +326,13 @@ export function generateAsyncTaskClass(fnName, fnStatements, strategy, knownFunc
|
|
|
289
326
|
` unsigned long _waitUntil;`,
|
|
290
327
|
...edgeMemberDecls,
|
|
291
328
|
...tapMemberDecls,
|
|
329
|
+
...ownerMemberDecl,
|
|
292
330
|
`};`,
|
|
293
331
|
].join("\n");
|
|
294
|
-
|
|
332
|
+
const starterDef = owner
|
|
333
|
+
? `void ${starterName}(${owner}* owner) { ${instanceName}.start(owner); }`
|
|
334
|
+
: undefined;
|
|
335
|
+
return { classDef, instanceDecl: `${className} ${instanceName};`, taskVarName: instanceName, starterDef };
|
|
295
336
|
}
|
|
296
337
|
/**
|
|
297
338
|
* Renders an expression to a string (simplified version for async state machine).
|
|
@@ -346,10 +387,16 @@ function netWaitInfo(op, strategy) {
|
|
|
346
387
|
const route = (routedOp) => routeHALOp(routedOp, strategy);
|
|
347
388
|
const expr = (operation) => route({ operation })?.expression ?? null;
|
|
348
389
|
switch (op.operation) {
|
|
349
|
-
case "timing.
|
|
390
|
+
case "timing.sleep":
|
|
391
|
+
// Pure deadline wait: no start op, no poll — the machine arms
|
|
392
|
+
// _waitUntil and cooperatively yields until it passes. Bare
|
|
393
|
+
// (non-awaited) calls lower to the blocking form (k_msleep).
|
|
350
394
|
return { startLines: [], pollCond: null, timeoutExpr: ms(o.ms) };
|
|
351
|
-
case "wifi.
|
|
352
|
-
|
|
395
|
+
case "wifi.join": {
|
|
396
|
+
// Awaited join splits into the staged association + the L4 poll.
|
|
397
|
+
// (Static-IPv4/power-save facts are join()-side blocking-path extras;
|
|
398
|
+
// the async form associates with defaults and polls connectivity.)
|
|
399
|
+
const start = route({ operation: "wifi.connect_start", ssid: o.ssid, password: o.psk });
|
|
353
400
|
const poll = expr("wifi.is_connected");
|
|
354
401
|
if (start?.code && poll) {
|
|
355
402
|
return {
|
|
@@ -360,24 +407,6 @@ function netWaitInfo(op, strategy) {
|
|
|
360
407
|
}
|
|
361
408
|
break;
|
|
362
409
|
}
|
|
363
|
-
case "wifi.wait_connected": {
|
|
364
|
-
const poll = expr("wifi.is_connected");
|
|
365
|
-
if (poll) {
|
|
366
|
-
return {
|
|
367
|
-
startLines: [],
|
|
368
|
-
pollCond: poll,
|
|
369
|
-
timeoutExpr: isZeroTimeout(o.timeoutMs) ? null : ms(o.timeoutMs),
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
|
-
break;
|
|
373
|
-
}
|
|
374
|
-
case "wifi.wait_disconnected": {
|
|
375
|
-
const poll = expr("wifi.is_connected");
|
|
376
|
-
if (poll) {
|
|
377
|
-
return { startLines: [], pollCond: `!${poll}`, timeoutExpr: null };
|
|
378
|
-
}
|
|
379
|
-
break;
|
|
380
|
-
}
|
|
381
410
|
case "wifi.scan": {
|
|
382
411
|
const start = route({ operation: "wifi.scan_start" });
|
|
383
412
|
const poll = expr("wifi.scan_done");
|
|
@@ -394,33 +423,6 @@ function netWaitInfo(op, strategy) {
|
|
|
394
423
|
}
|
|
395
424
|
break;
|
|
396
425
|
}
|
|
397
|
-
case "ble.until_connected": {
|
|
398
|
-
const start = route({ operation: "ble.until_connected_start" });
|
|
399
|
-
const poll = expr("ble.is_connected");
|
|
400
|
-
if (start?.code && poll) {
|
|
401
|
-
return {
|
|
402
|
-
startLines: [start.code],
|
|
403
|
-
pollCond: poll,
|
|
404
|
-
timeoutExpr: isZeroTimeout(o.timeoutMs) ? null : ms(o.timeoutMs),
|
|
405
|
-
};
|
|
406
|
-
}
|
|
407
|
-
break;
|
|
408
|
-
}
|
|
409
|
-
case "worker.submit": {
|
|
410
|
-
// Worker offload (Phase 3). `await worker.submit(fn, arg)` rewrites to:
|
|
411
|
-
// submit the worker (start), then poll worker.done on the same handle.
|
|
412
|
-
// The submit op is emitted verbatim as the start line; the poll predicate
|
|
413
|
-
// is worker.done(handle) carrying the SAME handleId. This is a predicate-
|
|
414
|
-
// poll resume (same per-frame cost as net/timer awaits), NOT an ISR-driven
|
|
415
|
-
// resume — that defers with DMA-backed awaits.
|
|
416
|
-
const submit = routeHALOp(op, strategy);
|
|
417
|
-
// Carry the handle through to the poll so submit + done agree on the slot.
|
|
418
|
-
const poll = route({ operation: "worker.done", handleId: o.handleId })?.expression ?? null;
|
|
419
|
-
if (submit?.code && poll) {
|
|
420
|
-
return { startLines: [submit.code], pollCond: poll, timeoutExpr: null };
|
|
421
|
-
}
|
|
422
|
-
break;
|
|
423
|
-
}
|
|
424
426
|
}
|
|
425
427
|
// Fallback: run the blocking form immediately and complete on the next tick.
|
|
426
428
|
const blocking = routeHALOp(op, strategy);
|
|
@@ -2,14 +2,6 @@
|
|
|
2
2
|
* Comment handling utilities for C++ code emission.
|
|
3
3
|
* Extracted from cpp-emitter.ts
|
|
4
4
|
*/
|
|
5
|
-
/**
|
|
6
|
-
* Normalizes a comment string into an array of trimmed lines.
|
|
7
|
-
* Removes empty lines and trailing whitespace.
|
|
8
|
-
*
|
|
9
|
-
* @param comment The comment string (may contain newlines)
|
|
10
|
-
* @returns Array of normalized comment lines
|
|
11
|
-
*/
|
|
12
|
-
export declare function normalizeComment(comment: string): string[];
|
|
13
5
|
/**
|
|
14
6
|
* Emits comment lines with proper indentation.
|
|
15
7
|
*
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* @param comment The comment string (may contain newlines)
|
|
10
10
|
* @returns Array of normalized comment lines
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
function normalizeComment(comment) {
|
|
13
13
|
return comment
|
|
14
14
|
.split(/\r?\n/)
|
|
15
15
|
.map((line) => line.trimEnd())
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare function accessorGetterName(prop: string): string;
|
|
2
2
|
export declare function accessorSetterName(prop: string): string;
|
|
3
3
|
/**
|
|
4
|
-
* Matches a C++ INTEGRAL scalar type (the enum↔integral storage boundary
|
|
5
|
-
*
|
|
4
|
+
* Matches a C++ INTEGRAL scalar type (the enum↔integral storage boundary).
|
|
5
|
+
* Used by the enum-storage cast sites to decide whether
|
|
6
6
|
* a value/target is on the integral side of an `enum class` boundary that
|
|
7
7
|
* needs a `static_cast`. Covers the signed/unsigned `char`/`short`/`int`/
|
|
8
8
|
* `long` spellings, the fixed-width `<cstdint>` aliases, `size_t`, and `bool`
|
|
@@ -5,8 +5,8 @@ export function accessorSetterName(prop) {
|
|
|
5
5
|
return `set${prop.charAt(0).toUpperCase()}${prop.slice(1)}`;
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
|
-
* Matches a C++ INTEGRAL scalar type (the enum↔integral storage boundary
|
|
9
|
-
*
|
|
8
|
+
* Matches a C++ INTEGRAL scalar type (the enum↔integral storage boundary).
|
|
9
|
+
* Used by the enum-storage cast sites to decide whether
|
|
10
10
|
* a value/target is on the integral side of an `enum class` boundary that
|
|
11
11
|
* needs a `static_cast`. Covers the signed/unsigned `char`/`short`/`int`/
|
|
12
12
|
* `long` spellings, the fixed-width `<cstdint>` aliases, `size_t`, and `bool`
|
|
@@ -7,33 +7,31 @@ export function cppTypeForHalOp(operation) {
|
|
|
7
7
|
switch (operation) {
|
|
8
8
|
case "wifi.local_ip":
|
|
9
9
|
case "wifi.mac":
|
|
10
|
-
case "wifi.ap_ip":
|
|
11
10
|
case "wifi.scan_ssid":
|
|
12
11
|
case "http.body":
|
|
13
12
|
case "http.response_header":
|
|
14
13
|
return "const char*";
|
|
15
14
|
case "wifi.is_connected":
|
|
16
|
-
case "wifi.
|
|
17
|
-
case "wifi.wait_connected":
|
|
15
|
+
case "wifi.join":
|
|
18
16
|
case "wifi.scan_done":
|
|
19
17
|
case "wifi.ap_start":
|
|
20
|
-
case "wifi.connect_saved":
|
|
21
18
|
case "http.ok":
|
|
22
19
|
case "http.done":
|
|
23
20
|
return "bool";
|
|
24
|
-
case "wifi.status":
|
|
25
21
|
case "wifi.rssi":
|
|
26
22
|
case "wifi.scan":
|
|
27
23
|
case "wifi.scan_count":
|
|
28
24
|
case "wifi.scan_rssi":
|
|
29
25
|
case "wifi.scan_encryption":
|
|
30
26
|
case "wifi.scan_channel":
|
|
31
|
-
case "wifi.ap_client_count":
|
|
32
27
|
case "http.status":
|
|
33
28
|
case "http.content_length":
|
|
34
29
|
return "int";
|
|
35
30
|
case "http.send":
|
|
36
31
|
return "bool";
|
|
32
|
+
// Zephyr's sensor channel value is a double (val1 + val2/1e6).
|
|
33
|
+
case "sensor.get":
|
|
34
|
+
return "double";
|
|
37
35
|
default:
|
|
38
36
|
return undefined;
|
|
39
37
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Emitter utilities barrel export.
|
|
3
3
|
* Re-exports all utility functions for C++ code emission.
|
|
4
4
|
*/
|
|
5
|
-
export { inferObjectFieldType, collectNestedStructDefs, hasArrayInObjectLiteral, hasThrowStatements, hasStdMathCalls,
|
|
6
|
-
export {
|
|
5
|
+
export { inferObjectFieldType, collectNestedStructDefs, hasArrayInObjectLiteral, hasThrowStatements, hasStdMathCalls, isRuntimeExpression, statementRequiresRuntime, collectPointerVarTypes, collectExpressionIdentifiers, } from "./type-inference.js";
|
|
6
|
+
export { generateAsyncTaskClass, type AsyncTaskClassResult, } from "./async-state-machine.js";
|
|
7
7
|
export { isCuttlefishSDKImport, normalizeInclude, dedupe, resolveTranspiledModuleInclude, applySymbolMap, } from "./include-resolver.js";
|
|
8
|
-
export {
|
|
8
|
+
export { emitCommentLines, } from "./comment-helpers.js";
|
package/dist/emit/utils/index.js
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* Re-exports all utility functions for C++ code emission.
|
|
4
4
|
*/
|
|
5
5
|
// Type inference utilities
|
|
6
|
-
export { inferObjectFieldType, collectNestedStructDefs, hasArrayInObjectLiteral, hasThrowStatements, hasStdMathCalls,
|
|
6
|
+
export { inferObjectFieldType, collectNestedStructDefs, hasArrayInObjectLiteral, hasThrowStatements, hasStdMathCalls, isRuntimeExpression, statementRequiresRuntime, collectPointerVarTypes, collectExpressionIdentifiers, } from "./type-inference.js";
|
|
7
7
|
// Async state machine utilities
|
|
8
|
-
export {
|
|
8
|
+
export { generateAsyncTaskClass, } from "./async-state-machine.js";
|
|
9
9
|
// Include resolution utilities
|
|
10
10
|
export { isCuttlefishSDKImport, normalizeInclude, dedupe, resolveTranspiledModuleInclude, applySymbolMap, } from "./include-resolver.js";
|
|
11
11
|
// Comment handling utilities
|
|
12
|
-
export {
|
|
12
|
+
export { emitCommentLines, } from "./comment-helpers.js";
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Type inference utilities for C++ code emission.
|
|
3
3
|
* Pure functions with no side effects - extracted from cpp-emitter.ts
|
|
4
4
|
*/
|
|
5
|
-
import type { ExpressionIR, StatementIR
|
|
5
|
+
import type { ExpressionIR, StatementIR } from "../../api/index.js";
|
|
6
6
|
/**
|
|
7
7
|
* Infers the C++ type for an object field based on its initializer value.
|
|
8
8
|
*
|
|
@@ -104,34 +104,6 @@ export declare function hasStdMathCalls(program: {
|
|
|
104
104
|
};
|
|
105
105
|
}>;
|
|
106
106
|
}): boolean;
|
|
107
|
-
/**
|
|
108
|
-
* Checks if a program contains console.* calls (console.log, console.error, etc.)
|
|
109
|
-
*
|
|
110
|
-
* @param program The program IR to analyze
|
|
111
|
-
* @returns true if console calls are found
|
|
112
|
-
*/
|
|
113
|
-
export declare function hasConsoleCalls(program: {
|
|
114
|
-
topLevelStatements: StatementIR[];
|
|
115
|
-
functions: Array<{
|
|
116
|
-
statements: StatementIR[];
|
|
117
|
-
}>;
|
|
118
|
-
classes: Array<{
|
|
119
|
-
methods: Array<{
|
|
120
|
-
statements: StatementIR[];
|
|
121
|
-
}>;
|
|
122
|
-
constructor?: {
|
|
123
|
-
statements: StatementIR[];
|
|
124
|
-
};
|
|
125
|
-
}>;
|
|
126
|
-
}, strategy?: PlatformStrategy): boolean;
|
|
127
|
-
/**
|
|
128
|
-
* Checks if a callee is a console method call (e.g., "console.log", "console.error")
|
|
129
|
-
*/
|
|
130
|
-
export declare function isConsoleCall(callee: string, strategy?: PlatformStrategy): boolean;
|
|
131
|
-
/**
|
|
132
|
-
* Gets the console method name from a callee (e.g., "log" from "console.log")
|
|
133
|
-
*/
|
|
134
|
-
export declare function getConsoleMethod(callee: string): string;
|
|
135
107
|
/**
|
|
136
108
|
* Checks if an expression requires runtime execution (cannot be evaluated at global scope in C++).
|
|
137
109
|
* Compile-time expressions can be placed at global scope; runtime expressions must go in setup()/main().
|
|
@@ -330,81 +330,6 @@ export function hasStdMathCalls(program) {
|
|
|
330
330
|
}
|
|
331
331
|
return false;
|
|
332
332
|
}
|
|
333
|
-
/**
|
|
334
|
-
* Checks if a program contains console.* calls (console.log, console.error, etc.)
|
|
335
|
-
*
|
|
336
|
-
* @param program The program IR to analyze
|
|
337
|
-
* @returns true if console calls are found
|
|
338
|
-
*/
|
|
339
|
-
export function hasConsoleCalls(program, strategy) {
|
|
340
|
-
const checkStatements = (statements) => {
|
|
341
|
-
for (const stmt of statements) {
|
|
342
|
-
if (stmt.kind === "call" && isConsoleCall(stmt.callee, strategy)) {
|
|
343
|
-
return true;
|
|
344
|
-
}
|
|
345
|
-
// Check nested statements in control flow
|
|
346
|
-
if ("body" in stmt && Array.isArray(stmt.body)) {
|
|
347
|
-
if (checkStatements(stmt.body))
|
|
348
|
-
return true;
|
|
349
|
-
}
|
|
350
|
-
if ("thenBranch" in stmt && Array.isArray(stmt.thenBranch)) {
|
|
351
|
-
if (checkStatements(stmt.thenBranch))
|
|
352
|
-
return true;
|
|
353
|
-
}
|
|
354
|
-
if ("elseBranch" in stmt && Array.isArray(stmt.elseBranch)) {
|
|
355
|
-
if (checkStatements(stmt.elseBranch))
|
|
356
|
-
return true;
|
|
357
|
-
}
|
|
358
|
-
if ("cases" in stmt && Array.isArray(stmt.cases)) {
|
|
359
|
-
for (const c of stmt.cases) {
|
|
360
|
-
if (checkStatements(c.body))
|
|
361
|
-
return true;
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
if ("tryBlock" in stmt && Array.isArray(stmt.tryBlock)) {
|
|
365
|
-
if (checkStatements(stmt.tryBlock))
|
|
366
|
-
return true;
|
|
367
|
-
}
|
|
368
|
-
if ("catchBlock" in stmt && Array.isArray(stmt.catchBlock)) {
|
|
369
|
-
if (checkStatements(stmt.catchBlock))
|
|
370
|
-
return true;
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
return false;
|
|
374
|
-
};
|
|
375
|
-
// Check all functions
|
|
376
|
-
for (const fn of program.functions) {
|
|
377
|
-
if (checkStatements(fn.statements))
|
|
378
|
-
return true;
|
|
379
|
-
}
|
|
380
|
-
// Check top-level statements
|
|
381
|
-
if (checkStatements(program.topLevelStatements))
|
|
382
|
-
return true;
|
|
383
|
-
// Check class methods
|
|
384
|
-
for (const cls of program.classes) {
|
|
385
|
-
for (const method of cls.methods) {
|
|
386
|
-
if (checkStatements(method.statements))
|
|
387
|
-
return true;
|
|
388
|
-
}
|
|
389
|
-
if (cls.constructor && checkStatements(cls.constructor.statements))
|
|
390
|
-
return true;
|
|
391
|
-
}
|
|
392
|
-
return false;
|
|
393
|
-
}
|
|
394
|
-
/**
|
|
395
|
-
* Checks if a callee is a console method call (e.g., "console.log", "console.error")
|
|
396
|
-
*/
|
|
397
|
-
export function isConsoleCall(callee, strategy) {
|
|
398
|
-
if (strategy)
|
|
399
|
-
return strategy.isConsoleCall(callee);
|
|
400
|
-
return callee.startsWith("console.");
|
|
401
|
-
}
|
|
402
|
-
/**
|
|
403
|
-
* Gets the console method name from a callee (e.g., "log" from "console.log")
|
|
404
|
-
*/
|
|
405
|
-
export function getConsoleMethod(callee) {
|
|
406
|
-
return callee.slice("console.".length);
|
|
407
|
-
}
|
|
408
333
|
/**
|
|
409
334
|
* Checks if an expression requires runtime execution (cannot be evaluated at global scope in C++).
|
|
410
335
|
* Compile-time expressions can be placed at global scope; runtime expressions must go in setup()/main().
|
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
* Optional exports include `Toolchain`, `SYMBOL_KINDS`, library resolver,
|
|
6
6
|
* class name map builder, and lib declaration generator.
|
|
7
7
|
*
|
|
8
|
+
* Built-in frameworks (see BUILTIN_FRAMEWORK_MODULES) are loaded from this
|
|
9
|
+
* package directly; everything else resolves from the project directory.
|
|
10
|
+
*
|
|
8
11
|
* Returns the raw module for backward compatibility.
|
|
9
12
|
*/
|
|
10
13
|
export declare function loadFrameworkPackage(packageName: string, fromDir?: string): any;
|
|
@@ -2,7 +2,18 @@ import path from "node:path";
|
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { setLoadedFramework } from "./framework-registry.js";
|
|
4
4
|
import { registerPlatformStrategy } from "./platform/registry.js";
|
|
5
|
+
import * as nativeFramework from "./frameworks/native/index.js";
|
|
5
6
|
const require = createRequire(import.meta.url);
|
|
7
|
+
/**
|
|
8
|
+
* Frameworks that ship inside @typecad/cuttlefish instead of as separate
|
|
9
|
+
* @typecad/framework-* npm packages. Their config string stays the historical
|
|
10
|
+
* package name for continuity; the module is loaded directly instead of via
|
|
11
|
+
* require.resolve. (The native framework was merged in from the former
|
|
12
|
+
* @typecad/framework-native package.)
|
|
13
|
+
*/
|
|
14
|
+
const BUILTIN_FRAMEWORK_MODULES = {
|
|
15
|
+
"@typecad/framework-native": nativeFramework,
|
|
16
|
+
};
|
|
6
17
|
function resolveFrameworkPackage(packageName, fromDir = process.cwd()) {
|
|
7
18
|
try {
|
|
8
19
|
const resolved = require.resolve(packageName, { paths: [path.resolve(fromDir)] });
|
|
@@ -29,15 +40,21 @@ function extractToolchain(mod) {
|
|
|
29
40
|
* Optional exports include `Toolchain`, `SYMBOL_KINDS`, library resolver,
|
|
30
41
|
* class name map builder, and lib declaration generator.
|
|
31
42
|
*
|
|
43
|
+
* Built-in frameworks (see BUILTIN_FRAMEWORK_MODULES) are loaded from this
|
|
44
|
+
* package directly; everything else resolves from the project directory.
|
|
45
|
+
*
|
|
32
46
|
* Returns the raw module for backward compatibility.
|
|
33
47
|
*/
|
|
34
48
|
export function loadFrameworkPackage(packageName, fromDir = process.cwd()) {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
49
|
+
const builtin = BUILTIN_FRAMEWORK_MODULES[packageName];
|
|
50
|
+
const mod = builtin ?? (() => {
|
|
51
|
+
const packagePath = resolveFrameworkPackage(packageName, fromDir);
|
|
52
|
+
if (!packagePath) {
|
|
53
|
+
throw new Error(`Unable to resolve framework package '${packageName}' from '${fromDir}'. ` +
|
|
54
|
+
`Install it or pass a different framework package name in your TypeCAD config.`);
|
|
55
|
+
}
|
|
56
|
+
return require(packagePath);
|
|
57
|
+
})();
|
|
41
58
|
// Populate the registry with the loaded framework components
|
|
42
59
|
if (mod.FrameworkStrategy) {
|
|
43
60
|
const strategy = new mod.FrameworkStrategy();
|
|
@@ -4,11 +4,11 @@ import type { CompileResult, UploadResult, ToolchainOptions } from "./api/shared
|
|
|
4
4
|
* Components loaded from a framework package.
|
|
5
5
|
*/
|
|
6
6
|
export interface LoadedFramework {
|
|
7
|
-
/** The platform strategy (e.g.
|
|
7
|
+
/** The platform strategy (e.g. ZephyrStrategy, NativeStrategy) */
|
|
8
8
|
strategy: PlatformStrategy;
|
|
9
9
|
/** Optional toolchain for compile/upload/monitor (framework-specific) */
|
|
10
10
|
toolchain?: FrameworkToolchain;
|
|
11
|
-
/** Framework library import resolution (e.g.,
|
|
11
|
+
/** Framework library import resolution (e.g., framework library detection) */
|
|
12
12
|
libraryResolver?: FrameworkLibraryResolver;
|
|
13
13
|
/** Framework class name mapping for library imports */
|
|
14
14
|
classNameMapBuilder?: (imports: any[]) => Map<string, string>;
|
|
@@ -18,15 +18,15 @@ export interface LoadedFramework {
|
|
|
18
18
|
* Optional subcommand presenters owned by the framework. Cuttlefish dispatches
|
|
19
19
|
* `cuttlefish doctor` / `cuttlefish licenses` to these when the loaded
|
|
20
20
|
* framework provides them; otherwise it prints a no-support message. Each
|
|
21
|
-
* framework decides what (if anything) these do — e.g. framework-
|
|
22
|
-
* checks
|
|
21
|
+
* framework decides what (if anything) these do — e.g. framework-zephyr
|
|
22
|
+
* checks west + board target (doctor) and scans library licenses
|
|
23
23
|
* (licenses).
|
|
24
24
|
*/
|
|
25
25
|
doctor?: () => void;
|
|
26
26
|
licenses?: (strict: boolean, all: boolean) => void;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
-
* Resolves framework-specific library imports
|
|
29
|
+
* Resolves framework-specific library imports.
|
|
30
30
|
*/
|
|
31
31
|
export interface FrameworkLibraryResolver {
|
|
32
32
|
isFrameworkLibraryImport(moduleSpecifier: string): boolean;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Terminal preview — renders display ops as ANSI-colored cells to stdout
|
|
3
|
+
//
|
|
4
|
+
// Lets authors preview a UI on the host with no hardware. Colors map rgb565
|
|
5
|
+
// back to the nearest ANSI 16-color for display only.
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
/** Map an rgb565 value to an ANSI color code (approximate). */
|
|
8
|
+
function rgb565ToAnsi(c) {
|
|
9
|
+
const r5 = (c >> 11) & 0x1f;
|
|
10
|
+
const g6 = (c >> 5) & 0x3f;
|
|
11
|
+
const b5 = c & 0x1f;
|
|
12
|
+
const r = r5 >> 3, g = g6 >> 4, b = b5 >> 3; // 0/1 per channel
|
|
13
|
+
// ANSI 16-color: foreground 30+bit pattern
|
|
14
|
+
return 30 + (r ? 1 : 0) + (g ? 2 : 0) + (b ? 4 : 0);
|
|
15
|
+
}
|
|
16
|
+
export function resolveTerminalPreviewOp(op) {
|
|
17
|
+
switch (op.operation) {
|
|
18
|
+
case "display.init":
|
|
19
|
+
return { code: `/* native preview: ${op.driver} ${op.width}x${op.height} initialized */` };
|
|
20
|
+
case "display.fill_rect":
|
|
21
|
+
return {
|
|
22
|
+
code: `/* preview fill_rect ${op.x},${op.y} ${op.w}x${op.h} color=0x${op.color.toString(16)} ansi=${rgb565ToAnsi(op.color)} */`,
|
|
23
|
+
};
|
|
24
|
+
case "display.draw_rect":
|
|
25
|
+
return { code: `/* preview draw_rect ${op.x},${op.y} ${op.w}x${op.h} */` };
|
|
26
|
+
case "display.draw_text":
|
|
27
|
+
return { code: `/* preview draw_text ${op.x},${op.y} "${op.text}" */` };
|
|
28
|
+
case "display.flush":
|
|
29
|
+
return { code: `/* preview flush ${op.rects.length} rect(s) */` };
|
|
30
|
+
default:
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Native C++ framework — built into @typecad/cuttlefish
|
|
3
|
+
//
|
|
4
|
+
// Outputs standard C++ for portable Windows/Linux desktop executables.
|
|
5
|
+
// Uses main(), std::string, and std::thread-based async.
|
|
6
|
+
//
|
|
7
|
+
// Usage:
|
|
8
|
+
// In cuttlefish.config.ts:
|
|
9
|
+
// framework: '@typecad/framework-native'
|
|
10
|
+
// (The config string keeps the historical package name; the module is
|
|
11
|
+
// loaded directly by framework-package.ts, no npm package involved.)
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
export { NativeStrategy, NativeStrategy as FrameworkStrategy } from './strategy.js';
|
|
14
|
+
// Native C++ toolchain (g++/clang++ compilation)
|
|
15
|
+
export { NativeToolchain as Toolchain } from './native-compile.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CompileResult, ToolchainOptions } from '../../api/shared/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Resolve the -l link libraries for a native build.
|
|
4
|
+
*
|
|
5
|
+
* The SDL display driver (#include <SDL2/SDL.h>) requires core SDL2 at link
|
|
6
|
+
* time on every platform; Windows/MSYS2 additionally needs -lmingw32 and
|
|
7
|
+
* -lSDL2main for the Win32 GUI entry-point glue (the SDL_MAIN_HANDLED define
|
|
8
|
+
* + SDL_SetMainReady() in display_init). Because the cuttlefish config loader
|
|
9
|
+
* is AST-only (it cannot evaluate process.platform conditionals), these libs
|
|
10
|
+
* are auto-provided here when the `sdl` display driver is active, so a single
|
|
11
|
+
* config links on both Windows and Linux without a platform-specific
|
|
12
|
+
* `native.libraries` array. User-supplied libraries are appended (deduped).
|
|
13
|
+
*/
|
|
14
|
+
export declare function resolveLinkLibraries(display: Record<string, unknown> | undefined, userLibs: string[]): string[];
|
|
15
|
+
export declare const NativeToolchain: {
|
|
16
|
+
compile(options: ToolchainOptions): CompileResult;
|
|
17
|
+
};
|