@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,306 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { getDefaultBoardConstants } from "./board-resolver.js";
|
|
3
|
+
// IrTypeScope replaces the three proxied globals (activeLocalTypes,
|
|
4
|
+
// activeGlobalTypes, activeClassFieldTypes) that previously lived on this
|
|
5
|
+
// module as createMapProxy exports. The scope lifecycle is managed here via
|
|
6
|
+
// the reset hooks (resetBuildState creates a fresh scope per file;
|
|
7
|
+
// resetFunctionScopeState re-seeds locals from classFields between functions).
|
|
8
|
+
// See symbol-types.ts for the full design.
|
|
9
|
+
import { createIrTypeScope, setCurrentIrTypeScope, getCurrentIrTypeScope, resetIrTypeScopeFunctionState, } from "./symbol-types.js";
|
|
10
|
+
export class CompilationContext {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.topLevelClasses = new Map();
|
|
13
|
+
this.registerFieldMap = new Map();
|
|
14
|
+
this.hoistedNestedFunctions = [];
|
|
15
|
+
this.hoistedNestedClasses = [];
|
|
16
|
+
this.hoistedNestedEnums = [];
|
|
17
|
+
this.hoistedNestedInterfaces = [];
|
|
18
|
+
this.hoistedNestedTypeAliases = [];
|
|
19
|
+
this.nestedFunctionAliases = new Map();
|
|
20
|
+
this.nestedClassAliases = new Map();
|
|
21
|
+
this.activeCArrayVars = new Set();
|
|
22
|
+
this.activeArrayLiteralVars = new Set();
|
|
23
|
+
this.activeStringVars = new Set();
|
|
24
|
+
this.mutableArrayVars = new Set();
|
|
25
|
+
this.arrayLiteralSizes = new Map();
|
|
26
|
+
this.filteredArrayLengthVars = new Map();
|
|
27
|
+
this.activeNamespaceNames = new Set();
|
|
28
|
+
this.topLevelClassNames = new Set();
|
|
29
|
+
// Names of top-level interfaces. Interfaces lower to C++ structs (value
|
|
30
|
+
// types), so a variable of an interface type is a value — never a pointer,
|
|
31
|
+
// never null. Tracked separately from topLevelClassNames (classes are always
|
|
32
|
+
// reference types / pointers) so the null-comparison guard in
|
|
33
|
+
// expression-to-ir can recognize an interface-typed value as a value type.
|
|
34
|
+
this.topLevelInterfaceNames = new Set();
|
|
35
|
+
this.classTypeNames = new Set();
|
|
36
|
+
this.activeEnumNames = new Set();
|
|
37
|
+
this.activeStringEnumNames = new Set();
|
|
38
|
+
this.activePinUsage = new Map();
|
|
39
|
+
this.activePeripheralUsage = new Map();
|
|
40
|
+
this.peripheralAliasMap = new Map();
|
|
41
|
+
this.pinAliasMap = new Map();
|
|
42
|
+
this.mcuPinForwardMap = new Map();
|
|
43
|
+
this.mcuPinReverseMap = new Map();
|
|
44
|
+
this.requiredIncludes = new Set();
|
|
45
|
+
this.registeredCallbacks = [];
|
|
46
|
+
this._currentBoardConstants = undefined;
|
|
47
|
+
// The three type maps that used to live here (activeLocalTypes,
|
|
48
|
+
// activeGlobalTypes, activeClassFieldTypes) now live on the IrTypeScope
|
|
49
|
+
// managed in symbol-types.ts. They are NOT context-scoped: the IR build is
|
|
50
|
+
// synchronous per file and the scope pointer is a module-local variable.
|
|
51
|
+
// See symbol-types.ts for the full rationale.
|
|
52
|
+
this.activeExtendsClass = undefined;
|
|
53
|
+
this.contextId = Math.random().toString(36).slice(2, 8);
|
|
54
|
+
this.halInstances = new Map();
|
|
55
|
+
/**
|
|
56
|
+
* Top-level `const x = <receiver>.<method>(...)` alias declarations, recorded
|
|
57
|
+
* as varName → receiver source text in a cheap up-front pass (no resolution).
|
|
58
|
+
* `resolveHALReceiver` follows this lazily so a function that references `x`
|
|
59
|
+
* resolves correctly even when declared before the `const x = ...`. This makes
|
|
60
|
+
* HAL resolution order-independent (demo #34 Finding C). Only mode-setter
|
|
61
|
+
* methods (asOutput/asInput/...) are recorded here — value-bearing reads are
|
|
62
|
+
* excluded so they don't alias the pin (Finding B).
|
|
63
|
+
*/
|
|
64
|
+
this.topLevelAliasReceivers = new Map();
|
|
65
|
+
this.floatVariables = new Set();
|
|
66
|
+
this.snprintfCounter = 0;
|
|
67
|
+
this.callbackPlaceholderCounter = 0;
|
|
68
|
+
this.activeStrategy = null;
|
|
69
|
+
this.restParamFunctions = new Map();
|
|
70
|
+
/**
|
|
71
|
+
* Diagnostics sink for the current file build. Populated by buildProgramIR
|
|
72
|
+
* with the same array returned in ProgramIR.diagnostics, so diagnostics
|
|
73
|
+
* pushed from deep in IR lowering (e.g. renderExprAsText's fallback paths)
|
|
74
|
+
* flow into the fatal-gate check in transpile.ts without that diagnostic
|
|
75
|
+
* array having to be threaded through ~80 call sites. May be empty before
|
|
76
|
+
* buildProgramIR assigns it; callers must null-check.
|
|
77
|
+
*/
|
|
78
|
+
this.diagnostics = [];
|
|
79
|
+
/**
|
|
80
|
+
* Module-level free-function return types for the file currently being
|
|
81
|
+
* lowered. Populated by buildProgramIR so UI callbacks / timers can resolve
|
|
82
|
+
* helper return types. Cleared in resetBuildState.
|
|
83
|
+
*/
|
|
84
|
+
this.activeFunctionReturnTypes = new Map();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* AsyncLocalStorage for context isolation across parallel transpilations.
|
|
89
|
+
* When no store is active (e.g. in tests or non-async code paths), the
|
|
90
|
+
* globalDefaultContext is used as fallback.
|
|
91
|
+
*
|
|
92
|
+
* IMPORTANT: `resetBuildState()` must be called between transpilations to
|
|
93
|
+
* clear the globalDefaultContext. In watch mode, this is done automatically
|
|
94
|
+
* at the start of each `transpileFile()` call.
|
|
95
|
+
*/
|
|
96
|
+
export const contextStorage = new AsyncLocalStorage();
|
|
97
|
+
const globalDefaultContext = new CompilationContext();
|
|
98
|
+
export function getContext() {
|
|
99
|
+
return contextStorage.getStore() || globalDefaultContext;
|
|
100
|
+
}
|
|
101
|
+
// 3. Helper Proxy creators
|
|
102
|
+
function createMapProxy(getContextKey) {
|
|
103
|
+
return new Proxy(new Map(), {
|
|
104
|
+
get(target, prop) {
|
|
105
|
+
const actual = getContextKey(getContext());
|
|
106
|
+
const value = Reflect.get(actual, prop, actual);
|
|
107
|
+
return typeof value === 'function' ? value.bind(actual) : value;
|
|
108
|
+
},
|
|
109
|
+
set(target, prop, value) {
|
|
110
|
+
const actual = getContextKey(getContext());
|
|
111
|
+
return Reflect.set(actual, prop, value, actual);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
function createSetProxy(getContextKey) {
|
|
116
|
+
return new Proxy(new Set(), {
|
|
117
|
+
get(target, prop) {
|
|
118
|
+
const actual = getContextKey(getContext());
|
|
119
|
+
const value = Reflect.get(actual, prop, actual);
|
|
120
|
+
return typeof value === 'function' ? value.bind(actual) : value;
|
|
121
|
+
},
|
|
122
|
+
set(target, prop, value) {
|
|
123
|
+
const actual = getContextKey(getContext());
|
|
124
|
+
return Reflect.set(actual, prop, value, actual);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
function createArrayProxy(getContextKey) {
|
|
129
|
+
return new Proxy([], {
|
|
130
|
+
get(target, prop) {
|
|
131
|
+
const actual = getContextKey(getContext());
|
|
132
|
+
const value = Reflect.get(actual, prop, actual);
|
|
133
|
+
return typeof value === 'function' ? value.bind(actual) : value;
|
|
134
|
+
},
|
|
135
|
+
set(target, prop, value) {
|
|
136
|
+
const actual = getContextKey(getContext());
|
|
137
|
+
return Reflect.set(actual, prop, value, actual);
|
|
138
|
+
},
|
|
139
|
+
ownKeys(target) {
|
|
140
|
+
return Reflect.ownKeys(getContextKey(getContext()));
|
|
141
|
+
},
|
|
142
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
143
|
+
return Reflect.getOwnPropertyDescriptor(getContextKey(getContext()), prop);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
// 4. Export proxies matching the original module API
|
|
148
|
+
export const topLevelClasses = createMapProxy(ctx => ctx.topLevelClasses);
|
|
149
|
+
export const registerFieldMap = createMapProxy(ctx => ctx.registerFieldMap);
|
|
150
|
+
export const halInstances = createMapProxy(ctx => ctx.halInstances);
|
|
151
|
+
export const topLevelAliasReceivers = createMapProxy(ctx => ctx.topLevelAliasReceivers);
|
|
152
|
+
export const floatVariables = createSetProxy(ctx => ctx.floatVariables);
|
|
153
|
+
export const hoistedNestedFunctions = createArrayProxy(ctx => ctx.hoistedNestedFunctions);
|
|
154
|
+
export const hoistedNestedClasses = createArrayProxy(ctx => ctx.hoistedNestedClasses);
|
|
155
|
+
export const hoistedNestedEnums = createArrayProxy(ctx => ctx.hoistedNestedEnums);
|
|
156
|
+
export const hoistedNestedInterfaces = createArrayProxy(ctx => ctx.hoistedNestedInterfaces);
|
|
157
|
+
export const hoistedNestedTypeAliases = createArrayProxy(ctx => ctx.hoistedNestedTypeAliases);
|
|
158
|
+
export const nestedFunctionAliases = createMapProxy(ctx => ctx.nestedFunctionAliases);
|
|
159
|
+
export const nestedClassAliases = createMapProxy(ctx => ctx.nestedClassAliases);
|
|
160
|
+
export const activeCArrayVars = createSetProxy(ctx => ctx.activeCArrayVars);
|
|
161
|
+
export const activeArrayLiteralVars = createSetProxy(ctx => ctx.activeArrayLiteralVars);
|
|
162
|
+
export const activeStringVars = createSetProxy(ctx => ctx.activeStringVars);
|
|
163
|
+
export const mutableArrayVars = createSetProxy(ctx => ctx.mutableArrayVars);
|
|
164
|
+
export const arrayLiteralSizes = createMapProxy(ctx => ctx.arrayLiteralSizes);
|
|
165
|
+
export const filteredArrayLengthVars = createMapProxy(ctx => ctx.filteredArrayLengthVars);
|
|
166
|
+
export const activeNamespaceNames = createSetProxy(ctx => ctx.activeNamespaceNames);
|
|
167
|
+
export const topLevelClassNames = createSetProxy(ctx => ctx.topLevelClassNames);
|
|
168
|
+
export const topLevelInterfaceNames = createSetProxy(ctx => ctx.topLevelInterfaceNames);
|
|
169
|
+
export const classTypeNames = createSetProxy(ctx => ctx.classTypeNames);
|
|
170
|
+
export const activeEnumNames = createSetProxy(ctx => ctx.activeEnumNames);
|
|
171
|
+
export const activeStringEnumNames = createSetProxy(ctx => ctx.activeStringEnumNames);
|
|
172
|
+
export const activePinUsage = createMapProxy(ctx => ctx.activePinUsage);
|
|
173
|
+
export const activePeripheralUsage = createMapProxy(ctx => ctx.activePeripheralUsage);
|
|
174
|
+
export const peripheralAliasMap = createMapProxy(ctx => ctx.peripheralAliasMap);
|
|
175
|
+
export const pinAliasMap = createMapProxy(ctx => ctx.pinAliasMap);
|
|
176
|
+
export const mcuPinForwardMap = createMapProxy(ctx => ctx.mcuPinForwardMap);
|
|
177
|
+
export const mcuPinReverseMap = createMapProxy(ctx => ctx.mcuPinReverseMap);
|
|
178
|
+
export const requiredIncludes = createSetProxy(ctx => ctx.requiredIncludes);
|
|
179
|
+
export const registeredCallbacks = createArrayProxy(ctx => ctx.registeredCallbacks);
|
|
180
|
+
// activeLocalTypes / activeGlobalTypes / activeClassFieldTypes were proxied
|
|
181
|
+
// globals; they now live on the IrTypeScope (symbol-types.ts). Callers that
|
|
182
|
+
// still reference these by name must migrate to getCurrentIrTypeScope().
|
|
183
|
+
export const discriminatedUnionVariantNames = new Map();
|
|
184
|
+
export const restParamFunctions = createMapProxy(ctx => ctx.restParamFunctions);
|
|
185
|
+
export const activeFunctionReturnTypes = createMapProxy(ctx => ctx.activeFunctionReturnTypes);
|
|
186
|
+
export function getActiveExtendsClass() { return getContext().activeExtendsClass; }
|
|
187
|
+
export function setActiveExtendsClass(v) { getContext().activeExtendsClass = v; }
|
|
188
|
+
// Static configurations
|
|
189
|
+
export const PIN_FACTORY_FUNCTIONS = new Set([
|
|
190
|
+
"createDigitalPin",
|
|
191
|
+
"createPWMPin",
|
|
192
|
+
"createAnalogPin",
|
|
193
|
+
"createInterruptPin",
|
|
194
|
+
]);
|
|
195
|
+
export const CONSTANT_FOLD_FUNCTIONS = new Set([]);
|
|
196
|
+
export const TYPED_ARRAY_ELEMENT_MAP = {
|
|
197
|
+
Uint8Array: "uint8_t",
|
|
198
|
+
Int8Array: "int8_t",
|
|
199
|
+
Uint16Array: "uint16_t",
|
|
200
|
+
Int16Array: "int16_t",
|
|
201
|
+
Uint32Array: "uint32_t",
|
|
202
|
+
Int32Array: "int32_t",
|
|
203
|
+
Float32Array: "float",
|
|
204
|
+
Float64Array: "double",
|
|
205
|
+
};
|
|
206
|
+
// 5. Getter/Setter for BoardConstants
|
|
207
|
+
export function getCurrentBoardConstants() {
|
|
208
|
+
return getContext()._currentBoardConstants || getDefaultBoardConstants();
|
|
209
|
+
}
|
|
210
|
+
export function setCurrentBoardConstants(v) {
|
|
211
|
+
const ctx = getContext();
|
|
212
|
+
ctx._currentBoardConstants = v;
|
|
213
|
+
if (v) {
|
|
214
|
+
// Populate peripheral aliases (e.g. UART0 -> Serial, I2C0 -> Wire)
|
|
215
|
+
for (const [key, value] of v.entries()) {
|
|
216
|
+
if (key.startsWith("peripherals.aliases.")) {
|
|
217
|
+
const alias = key.slice("peripherals.aliases.".length);
|
|
218
|
+
peripheralAliasMap.set(alias, String(value));
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
// Populate pin aliases (e.g. D0 -> 0, A0 -> 14, LED -> 13)
|
|
222
|
+
const pinNames = new Map();
|
|
223
|
+
const pinNumbers = new Map();
|
|
224
|
+
for (const [key, value] of v.entries()) {
|
|
225
|
+
const nameMatch = key.match(/^pins\.all\.(\d+)\.name$/);
|
|
226
|
+
if (nameMatch) {
|
|
227
|
+
pinNames.set(parseInt(nameMatch[1]), String(value));
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
const numMatch = key.match(/^pins\.all\.(\d+)\.number$/);
|
|
231
|
+
if (numMatch) {
|
|
232
|
+
pinNumbers.set(parseInt(numMatch[1]), String(value));
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
const directMatch = key.match(/^pins\.([a-z_][a-z0-9_]*)$/);
|
|
236
|
+
if (directMatch && typeof value !== 'object') {
|
|
237
|
+
const pinName = directMatch[1].toUpperCase();
|
|
238
|
+
if (pinName !== 'ALL' && pinName !== 'DIGITAL' && pinName !== 'ANALOG' && pinName !== 'PWM' && pinName !== 'UNSAFE' && pinName !== 'I2C' && pinName !== 'SPI' && pinName !== 'UART') {
|
|
239
|
+
pinAliasMap.set(pinName, String(value));
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
for (const [idx, name] of pinNames) {
|
|
244
|
+
const num = pinNumbers.get(idx);
|
|
245
|
+
if (num !== undefined) {
|
|
246
|
+
pinAliasMap.set(name, num);
|
|
247
|
+
mcuPinForwardMap.set(name, num);
|
|
248
|
+
mcuPinReverseMap.set(num, name);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
// 6. State management hooks
|
|
254
|
+
export function resetBuildState() {
|
|
255
|
+
hoistedNestedFunctions.length = 0;
|
|
256
|
+
hoistedNestedClasses.length = 0;
|
|
257
|
+
hoistedNestedEnums.length = 0;
|
|
258
|
+
hoistedNestedInterfaces.length = 0;
|
|
259
|
+
hoistedNestedTypeAliases.length = 0;
|
|
260
|
+
nestedFunctionAliases.clear();
|
|
261
|
+
topLevelAliasReceivers.clear();
|
|
262
|
+
nestedClassAliases.clear();
|
|
263
|
+
resetFunctionScopeState();
|
|
264
|
+
activeNamespaceNames.clear();
|
|
265
|
+
topLevelClassNames.clear();
|
|
266
|
+
topLevelInterfaceNames.clear();
|
|
267
|
+
classTypeNames.clear();
|
|
268
|
+
activeEnumNames.clear();
|
|
269
|
+
activeStringEnumNames.clear();
|
|
270
|
+
topLevelClasses.clear();
|
|
271
|
+
// Start a fresh IrTypeScope for this file. The old activeGlobalTypes was a
|
|
272
|
+
// file-scoped map cleared here; activeLocalTypes/activeClassFieldTypes were
|
|
273
|
+
// function/class-scoped and cleared in resetFunctionScopeState. Creating a
|
|
274
|
+
// new scope object clears all three at once and re-binds the current scope.
|
|
275
|
+
setCurrentIrTypeScope(createIrTypeScope());
|
|
276
|
+
peripheralAliasMap.clear();
|
|
277
|
+
pinAliasMap.clear();
|
|
278
|
+
mcuPinForwardMap.clear();
|
|
279
|
+
mcuPinReverseMap.clear();
|
|
280
|
+
activePinUsage.clear();
|
|
281
|
+
activePeripheralUsage.clear();
|
|
282
|
+
requiredIncludes.clear();
|
|
283
|
+
registeredCallbacks.length = 0;
|
|
284
|
+
discriminatedUnionVariantNames.clear();
|
|
285
|
+
restParamFunctions.clear();
|
|
286
|
+
activeFunctionReturnTypes.clear();
|
|
287
|
+
getContext()._currentBoardConstants = undefined;
|
|
288
|
+
}
|
|
289
|
+
export function resetFunctionScopeState() {
|
|
290
|
+
activeCArrayVars.clear();
|
|
291
|
+
activeArrayLiteralVars.clear();
|
|
292
|
+
activeStringVars.clear();
|
|
293
|
+
mutableArrayVars.clear();
|
|
294
|
+
arrayLiteralSizes.clear();
|
|
295
|
+
filteredArrayLengthVars.clear();
|
|
296
|
+
// Clear the function-scoped portion of the current IrTypeScope (locals) and
|
|
297
|
+
// re-seed it from classFields so `this->field` lookups keep resolving in the
|
|
298
|
+
// next method. Mirrors the old behavior where resetFunctionScopeState copied
|
|
299
|
+
// activeClassFieldTypes into activeLocalTypes. globals/classFields survive
|
|
300
|
+
// (they are file-scoped, not function-scoped).
|
|
301
|
+
const scope = getCurrentIrTypeScope();
|
|
302
|
+
if (scope) {
|
|
303
|
+
resetIrTypeScopeFunctionState(scope);
|
|
304
|
+
}
|
|
305
|
+
getContext().activeExtendsClass = undefined;
|
|
306
|
+
}
|