@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
|
@@ -4,7 +4,7 @@ import { createRequire } from "node:module";
|
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import ts from "typescript";
|
|
6
6
|
import { parseSource } from "../../ast/parse.js";
|
|
7
|
-
import { requiredIncludes, getCurrentBoardConstants, mcuPinForwardMap, mcuPinReverseMap, halInstances, topLevelAliasReceivers } from "../build-ir-state.js";
|
|
7
|
+
import { requiredIncludes, getCurrentBoardConstants, mcuPinForwardMap, mcuPinReverseMap, halInstances, topLevelAliasReceivers, pinAliasMap } from "../build-ir-state.js";
|
|
8
8
|
import { mapPeripheralName } from "../../mapping/peripheral-names.js";
|
|
9
9
|
import { escapeCppStringLiteral } from "../../utils/strings.js";
|
|
10
10
|
const require = createRequire(import.meta.url);
|
|
@@ -167,6 +167,18 @@ export function loadHALModules(force = false) {
|
|
|
167
167
|
let instanceName;
|
|
168
168
|
let includes;
|
|
169
169
|
const defaultFields = new Map();
|
|
170
|
+
const fieldDefaults = new Map();
|
|
171
|
+
for (const member of stmt.members) {
|
|
172
|
+
// Instance property initializers with literal values (`private
|
|
173
|
+
// readonly _spiHz: number = 1000000;`) are static facts — the
|
|
174
|
+
// default a method body sees when construction didn't override.
|
|
175
|
+
if (ts.isPropertyDeclaration(member) && ts.isIdentifier(member.name) && member.initializer) {
|
|
176
|
+
const init = member.initializer;
|
|
177
|
+
if (ts.isNumericLiteral(init) || ts.isStringLiteral(init)) {
|
|
178
|
+
fieldDefaults.set(member.name.text, init.text);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
170
182
|
for (const member of stmt.members) {
|
|
171
183
|
if (ts.isPropertyDeclaration(member) &&
|
|
172
184
|
member.modifiers?.some(m => m.kind === ts.SyntaxKind.StaticKeyword) &&
|
|
@@ -186,7 +198,7 @@ export function loadHALModules(force = false) {
|
|
|
186
198
|
}
|
|
187
199
|
}
|
|
188
200
|
}
|
|
189
|
-
halClassRegistry.set(className, { ctorFieldMap, ctorDefaults, methods });
|
|
201
|
+
halClassRegistry.set(className, { ctorFieldMap, ctorDefaults, fieldDefaults, methods });
|
|
190
202
|
if (instanceName) {
|
|
191
203
|
halSingletons.set(instanceName, { className, fieldValues: defaultFields, includes });
|
|
192
204
|
}
|
|
@@ -210,21 +222,79 @@ export function loadHALModules(force = false) {
|
|
|
210
222
|
export function getCtorIncludes(className) {
|
|
211
223
|
return halCtorIncludes.get(className) ?? [];
|
|
212
224
|
}
|
|
213
|
-
/** Map an HttpClass factory method name to its HTTP verb, or null. */
|
|
214
|
-
export function httpFactoryVerb(methodName) {
|
|
215
|
-
switch (methodName) {
|
|
216
|
-
case "get": return "GET";
|
|
217
|
-
case "post": return "POST";
|
|
218
|
-
case "put": return "PUT";
|
|
219
|
-
case "del": return "DELETE";
|
|
220
|
-
case "head": return "HEAD";
|
|
221
|
-
case "patch": return "PATCH";
|
|
222
|
-
default: return null;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
225
|
/** Render an Http factory URL argument as C++ expression text (string
|
|
226
226
|
* literals quoted, identifiers/member accesses verbatim), or null when the
|
|
227
227
|
* argument shape can't be resolved at compile time. */
|
|
228
|
+
/** Capture `new Request(method, url, opts?)` construction facts into
|
|
229
|
+
* fieldValues (method token/string → verb, URL as C++ text, opts with
|
|
230
|
+
* class-default sentinels so send()'s setter calls always resolve).
|
|
231
|
+
* Returns null when the arg shapes don't resolve. */
|
|
232
|
+
/** Top-level `const NAME = "literal"` lookup, or null. One pass over the
|
|
233
|
+
* file's statements — cheap and cached by the TS compiler. */
|
|
234
|
+
function topLevelStringConst(sourceFile, name) {
|
|
235
|
+
for (const stmt of sourceFile.statements) {
|
|
236
|
+
if (!ts.isVariableStatement(stmt))
|
|
237
|
+
continue;
|
|
238
|
+
for (const decl of stmt.declarationList.declarations) {
|
|
239
|
+
if (ts.isIdentifier(decl.name) && decl.name.text === name
|
|
240
|
+
&& decl.initializer && ts.isStringLiteral(decl.initializer)) {
|
|
241
|
+
return decl.initializer.text;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
export function requestCtorFields(ctorArgs, sourceFile) {
|
|
248
|
+
if (!ctorArgs || ctorArgs.length < 2)
|
|
249
|
+
return null;
|
|
250
|
+
const fieldValues = new Map();
|
|
251
|
+
const methodArg = ctorArgs[0];
|
|
252
|
+
if (ts.isStringLiteral(methodArg)) {
|
|
253
|
+
fieldValues.set("_method", methodArg.text.toUpperCase());
|
|
254
|
+
}
|
|
255
|
+
else if (ts.isPropertyAccessExpression(methodArg) && methodArg.expression.getText() === "Request") {
|
|
256
|
+
fieldValues.set("_method", methodArg.name.text);
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
return null;
|
|
260
|
+
}
|
|
261
|
+
const urlText = httpUrlArgText(ctorArgs[1]);
|
|
262
|
+
if (!urlText)
|
|
263
|
+
return null;
|
|
264
|
+
fieldValues.set("_url", urlText);
|
|
265
|
+
fieldValues.set("_timeoutMs", "10000");
|
|
266
|
+
fieldValues.set("_body", '""');
|
|
267
|
+
fieldValues.set("_json", "false");
|
|
268
|
+
fieldValues.set("_insecure", "false");
|
|
269
|
+
fieldValues.set("_caCert", '""');
|
|
270
|
+
const opts = ctorArgs[2];
|
|
271
|
+
if (opts && ts.isObjectLiteralExpression(opts)) {
|
|
272
|
+
for (const prop of opts.properties) {
|
|
273
|
+
if (!ts.isPropertyAssignment(prop) || !ts.isIdentifier(prop.name))
|
|
274
|
+
continue;
|
|
275
|
+
const name = prop.name.text;
|
|
276
|
+
if (name === "timeoutMs" && ts.isNumericLiteral(prop.initializer)) {
|
|
277
|
+
fieldValues.set("_timeoutMs", prop.initializer.text.replace(/_/g, ""));
|
|
278
|
+
}
|
|
279
|
+
else if (name === "body" || name === "caCert") {
|
|
280
|
+
// Literal, or an identifier resolving to a top-level string const
|
|
281
|
+
// (the PEM-as-const pattern the hardware suite uses).
|
|
282
|
+
if (ts.isStringLiteral(prop.initializer)) {
|
|
283
|
+
fieldValues.set("_" + name, JSON.stringify(prop.initializer.text));
|
|
284
|
+
}
|
|
285
|
+
else if (ts.isIdentifier(prop.initializer) && sourceFile) {
|
|
286
|
+
const lit = topLevelStringConst(sourceFile, prop.initializer.text);
|
|
287
|
+
if (lit !== null)
|
|
288
|
+
fieldValues.set("_" + name, JSON.stringify(lit));
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
else if (name === "json" || name === "insecure") {
|
|
292
|
+
fieldValues.set("_" + name, prop.initializer.kind === ts.SyntaxKind.TrueKeyword ? "true" : "false");
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return fieldValues;
|
|
297
|
+
}
|
|
228
298
|
export function httpUrlArgText(arg) {
|
|
229
299
|
if (ts.isStringLiteral(arg) || ts.isNoSubstitutionTemplateLiteral(arg))
|
|
230
300
|
return JSON.stringify(arg.text);
|
|
@@ -242,7 +312,7 @@ export function resolveHALReceiver(receiver) {
|
|
|
242
312
|
const inst = halInstances.get(receiver.text);
|
|
243
313
|
if (inst)
|
|
244
314
|
return inst;
|
|
245
|
-
// Metadata-driven singleton resolution (e.g., ADC,
|
|
315
|
+
// Metadata-driven singleton resolution (e.g., ADC, WDT)
|
|
246
316
|
const singleton = halSingletons.get(receiver.text);
|
|
247
317
|
if (singleton) {
|
|
248
318
|
if (singleton.includes) {
|
|
@@ -265,13 +335,35 @@ export function resolveHALReceiver(receiver) {
|
|
|
265
335
|
if (mappedName) {
|
|
266
336
|
const canonical = name.toUpperCase();
|
|
267
337
|
if (canonical.startsWith("UART"))
|
|
268
|
-
return {
|
|
338
|
+
return {
|
|
339
|
+
className: "UART",
|
|
340
|
+
fieldValues: new Map([["_port", mappedName], ["_bus", mappedName], ["_baud", "115200"], ["_rxBufferBytes", "64"]]),
|
|
341
|
+
};
|
|
342
|
+
if (canonical.startsWith("USB"))
|
|
343
|
+
return { className: "USBConsole", fieldValues: new Map([["_port", mappedName]]) };
|
|
269
344
|
if (canonical.startsWith("I2C"))
|
|
270
345
|
return { className: "I2CBus", fieldValues: new Map([["_bus", mappedName]]) };
|
|
271
346
|
if (canonical.startsWith("SPI"))
|
|
272
347
|
return { className: "SPIBus", fieldValues: new Map([["_bus", mappedName]]) };
|
|
273
348
|
}
|
|
274
|
-
//
|
|
349
|
+
// Board-module pin constant (LED, BUTTON, D0, A0, connector labels,
|
|
350
|
+
// datasheet-named pins — anything the generated board manifest maps
|
|
351
|
+
// through pins.aliases.*). Checked BEFORE the legacy Arduino D/A
|
|
352
|
+
// arithmetic below: the alias carries the board's actual wiring, which
|
|
353
|
+
// the Arduino-style offset math cannot know (the XIAO's D0 is
|
|
354
|
+
// gpio0.2, not Arduino pin 0).
|
|
355
|
+
const aliasNum = pinAliasMap.get(name);
|
|
356
|
+
if (getCurrentBoardConstants() && aliasNum !== undefined) {
|
|
357
|
+
const portName = mcuPinReverseMap.get(aliasNum);
|
|
358
|
+
const fields = new Map([["_pin", aliasNum]]);
|
|
359
|
+
if (portName)
|
|
360
|
+
fields.set("_port", portName);
|
|
361
|
+
const inst = { className: "Pin", fieldValues: fields };
|
|
362
|
+
halInstances.set(name, inst);
|
|
363
|
+
return inst;
|
|
364
|
+
}
|
|
365
|
+
// Legacy Arduino-style D/A fallback (no board manifest — the old
|
|
366
|
+
// package-less path or bare-silicon configs).
|
|
275
367
|
const dMatch = name.match(/^D(\d+)$/);
|
|
276
368
|
if (dMatch) {
|
|
277
369
|
const arduinoPin = dMatch[1];
|
|
@@ -323,11 +415,18 @@ export function resolveHALReceiver(receiver) {
|
|
|
323
415
|
const returnClassName = methodName === "asOutput" ? "OutputPin" : "InputPin";
|
|
324
416
|
return { className: returnClassName, fieldValues: new Map(innerInstance.fieldValues) };
|
|
325
417
|
}
|
|
326
|
-
// Specialized handling for device() factory pattern (I2CBus/SPIBus ->
|
|
418
|
+
// Specialized handling for device() factory pattern (I2CBus/SPIBus -> I2CTarget/SPITarget)
|
|
327
419
|
// This allows propagating the address/CS pin from the call argument to the new instance.
|
|
328
420
|
if (methodName === "device" && (innerInstance.className === "I2CBus" || innerInstance.className === "SPIBus") && receiver.arguments.length > 0) {
|
|
329
|
-
const
|
|
421
|
+
const isSpi = innerInstance.className === "SPIBus";
|
|
422
|
+
const returnClassName = isSpi ? "SPITarget" : "I2CTarget";
|
|
330
423
|
const fieldValues = new Map(innerInstance.fieldValues);
|
|
424
|
+
// The targets' __default_fields channel does not reach factory-made
|
|
425
|
+
// instances; carry the class defaults so `this._hz`/`this._mode`
|
|
426
|
+
// resolve in the inlined method bodies.
|
|
427
|
+
fieldValues.set("_hz", isSpi ? "1000000" : "0");
|
|
428
|
+
if (isSpi)
|
|
429
|
+
fieldValues.set("_mode", "0");
|
|
331
430
|
const arg = receiver.arguments[0];
|
|
332
431
|
let argVal = null;
|
|
333
432
|
if (ts.isNumericLiteral(arg))
|
|
@@ -360,22 +459,6 @@ export function resolveHALReceiver(receiver) {
|
|
|
360
459
|
return { className: "ToneChain", fieldValues };
|
|
361
460
|
}
|
|
362
461
|
}
|
|
363
|
-
// Specialized handling for Http factory chaining
|
|
364
|
-
// (Http.get(url).header(...).send()): the factory records the HTTP
|
|
365
|
-
// verb and URL into the HttpRequest instance so send() can resolve
|
|
366
|
-
// this._method / this._url.
|
|
367
|
-
if (innerInstance.className === "HttpClass") {
|
|
368
|
-
const verb = httpFactoryVerb(methodName);
|
|
369
|
-
if (verb && receiver.arguments.length > 0) {
|
|
370
|
-
const urlText = httpUrlArgText(receiver.arguments[0]);
|
|
371
|
-
if (urlText) {
|
|
372
|
-
return {
|
|
373
|
-
className: "HttpRequest",
|
|
374
|
-
fieldValues: new Map([["_method", verb], ["_url", urlText]]),
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
462
|
// Specialized handling for BLE factory chaining
|
|
380
463
|
// (Ble.server(name).characteristic(uuid,type,perms).onRead(handler)):
|
|
381
464
|
// server() creates a BleServer. The characteristic index is taken from a
|
|
@@ -431,6 +514,11 @@ export function resolveHALReceiver(receiver) {
|
|
|
431
514
|
// Inline new expression: new Pin(x).method()
|
|
432
515
|
if (ts.isNewExpression(receiver) && ts.isIdentifier(receiver.expression)) {
|
|
433
516
|
const className = receiver.expression.text;
|
|
517
|
+
if (className === "Request") {
|
|
518
|
+
const reqFields = requestCtorFields(receiver.arguments, receiver.getSourceFile());
|
|
519
|
+
if (reqFields)
|
|
520
|
+
return { className, fieldValues: reqFields };
|
|
521
|
+
}
|
|
434
522
|
const classEntry = halClassRegistry.get(className);
|
|
435
523
|
if (!classEntry)
|
|
436
524
|
return null;
|
|
@@ -474,8 +562,12 @@ export function resolveHALReceiver(receiver) {
|
|
|
474
562
|
}
|
|
475
563
|
// I2C/SPI device factory: bus → device with address/cs from args
|
|
476
564
|
if (entry.method === "device" && (resolvedInst.className === "I2CBus" || resolvedInst.className === "SPIBus")) {
|
|
477
|
-
const
|
|
565
|
+
const isSpi = resolvedInst.className === "SPIBus";
|
|
566
|
+
const returnClassName = isSpi ? "SPITarget" : "I2CTarget";
|
|
478
567
|
const fieldValues = new Map(resolvedInst.fieldValues);
|
|
568
|
+
fieldValues.set("_hz", isSpi ? "1000000" : "0");
|
|
569
|
+
if (isSpi)
|
|
570
|
+
fieldValues.set("_mode", "0");
|
|
479
571
|
const fieldName = resolvedInst.className === "SPIBus" ? "_cs" : "_address";
|
|
480
572
|
if (entry.args && entry.args.length > 0) {
|
|
481
573
|
// Resolve identifier args (e.g. D10 → 10) via halInstances.
|
|
@@ -2,7 +2,6 @@ import ts from "typescript";
|
|
|
2
2
|
import { HALOpIR } from "../../api/index.js";
|
|
3
3
|
import { HALInstance } from "./hal-parser.js";
|
|
4
4
|
import type { ExpressionIR } from "../../api/index.js";
|
|
5
|
-
/** Resolve a single argument from a semantic call's AST node list. */
|
|
6
5
|
export declare function resolveSemanticArg(args: readonly ts.Expression[], idx: number, instance: HALInstance, paramNames: string[], callArgTexts: string[], paramDefaults: Map<string, string> | undefined): string | null;
|
|
7
6
|
/** Resolve a numeric argument, returning its numeric value or null. */
|
|
8
7
|
export declare function resolveNumericArg(args: readonly ts.Expression[], idx: number, instance: HALInstance, paramNames: string[], callArgTexts: string[], paramDefaults: Map<string, string> | undefined): number | null;
|