@tsplc/compiler 0.5.13 → 0.5.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 +33 -8
- package/dist/cli.js +794 -621
- package/dist/cli.js.map +19 -16
- package/dist/clock.js +5 -2
- package/dist/clock.js.map +5 -4
- package/dist/codesys.js +4162 -4157
- package/dist/codesys.js.map +43 -29
- package/dist/index.js +7852 -6549
- package/dist/index.js.map +53 -50
- package/dist/ir.js +2482 -2277
- package/dist/ir.js.map +28 -25
- package/dist/retain.js +3 -1
- package/dist/retain.js.map +3 -3
- package/dist/signals.js +115 -0
- package/dist/signals.js.map +10 -0
- package/dist/telemetry.js +25 -20
- package/dist/telemetry.js.map +6 -6
- package/package.json +19 -39
- package/src/codesys/config.ts +3 -3
- package/src/codesys/debug.ts +92 -108
- package/src/codesys/emit.ts +100 -88
- package/src/codesys/endpoints.ts +111 -0
- package/src/codesys/engineering.ts +30 -54
- package/src/codesys/explain/expressions.ts +445 -0
- package/src/codesys/explain/flags.ts +134 -0
- package/src/codesys/explain/parameters.ts +53 -0
- package/src/codesys/explain/rows.ts +182 -0
- package/src/codesys/explain/tables.ts +79 -0
- package/src/codesys/explain/tasks.ts +68 -0
- package/src/codesys/explain/writes.ts +497 -0
- package/src/codesys/explain.ts +85 -1401
- package/src/codesys/expressions.ts +41 -33
- package/src/codesys/global-lists.ts +114 -94
- package/src/codesys/global-names.ts +12 -14
- package/src/codesys/http.ts +428 -388
- package/src/codesys/instrumentation.ts +142 -148
- package/src/codesys/io-paths.ts +31 -23
- package/src/codesys/loops.ts +101 -0
- package/src/codesys/manifest.ts +269 -269
- package/src/codesys/names.ts +10 -33
- package/src/codesys/numeric.ts +89 -42
- package/src/codesys/plan.ts +202 -190
- package/src/codesys/programs.ts +23 -16
- package/src/codesys/publication.ts +13 -86
- package/src/codesys/required.ts +8 -0
- package/src/codesys/routines.ts +103 -489
- package/src/codesys/scheduling.ts +96 -0
- package/src/codesys/service-channels.ts +23 -0
- package/src/codesys/sources.ts +34 -28
- package/src/codesys/st-files.ts +112 -105
- package/src/codesys/statements.ts +409 -0
- package/src/codesys/storage.ts +41 -23
- package/src/codesys/symbols.ts +130 -119
- package/src/codesys/task-access.ts +65 -221
- package/src/codesys/telemetry-settings.ts +19 -0
- package/src/codesys/telemetry.ts +185 -148
- package/src/codesys/types.ts +69 -109
- package/src/codesys/vendor.ts +13 -50
- package/src/frontend/analyzer.ts +66 -111
- package/src/frontend/async.ts +316 -128
- package/src/frontend/blocks.ts +178 -154
- package/src/frontend/configuration.ts +49 -153
- package/src/frontend/const-functions.ts +50 -40
- package/src/frontend/control-flow.ts +164 -129
- package/src/frontend/cooperative.ts +17 -9
- package/src/frontend/coroutines.ts +539 -441
- package/src/frontend/dialect-names.ts +104 -0
- package/src/frontend/elaborate/array-searches.ts +77 -69
- package/src/frontend/elaborate/assignments.ts +68 -77
- package/src/frontend/elaborate/calls.ts +878 -512
- package/src/frontend/elaborate/capture-protocol.ts +118 -21
- package/src/frontend/elaborate/capture.ts +196 -109
- package/src/frontend/elaborate/declarations.ts +124 -0
- package/src/frontend/elaborate/dialect.ts +119 -46
- package/src/frontend/elaborate/expressions.ts +763 -442
- package/src/frontend/elaborate/filtered-arrays.ts +127 -91
- package/src/frontend/elaborate/frame.ts +50 -2
- package/src/frontend/elaborate/generics.ts +20 -34
- package/src/frontend/elaborate/graph.ts +13 -87
- package/src/frontend/elaborate/imports.ts +0 -5
- package/src/frontend/elaborate/index.ts +416 -169
- package/src/frontend/elaborate/initializers.ts +64 -42
- package/src/frontend/elaborate/iterators.ts +228 -364
- package/src/frontend/elaborate/layouts.ts +477 -116
- package/src/frontend/elaborate/model.ts +113 -55
- package/src/frontend/elaborate/references.ts +116 -138
- package/src/frontend/elaborate/retention.ts +137 -59
- package/src/frontend/elaborate/specialize.ts +617 -308
- package/src/frontend/elaborate/statements.ts +436 -247
- package/src/frontend/elaborate/storage.ts +280 -213
- package/src/frontend/elaborate/time-constructors.ts +34 -0
- package/src/frontend/elaborate/values.ts +77 -7
- package/src/frontend/elaborate/writes.ts +98 -84
- package/src/frontend/expressions.ts +149 -151
- package/src/frontend/generated-names.ts +3 -3
- package/src/frontend/intrinsics.ts +31 -17
- package/src/frontend/lowering-key.ts +23 -0
- package/src/frontend/module-graph.ts +105 -43
- package/src/frontend/positions.ts +43 -35
- package/src/frontend/promise-chains.ts +226 -266
- package/src/frontend/promises.ts +88 -67
- package/src/frontend/routines.ts +122 -65
- package/src/frontend/sdk.ts +104 -5
- package/src/frontend/services.ts +149 -102
- package/src/frontend/statements.ts +60 -64
- package/src/frontend/tasks.ts +151 -96
- package/src/frontend/telemetry.ts +1 -1
- package/src/frontend/types.ts +366 -181
- package/src/frontend/typescript.ts +239 -112
- package/src/index.ts +2 -1
- package/src/ir/aggregates.ts +90 -75
- package/src/ir/allocation.ts +29 -18
- package/src/ir/conditions.ts +38 -78
- package/src/ir/core-model.ts +128 -11
- package/src/ir/declarations.ts +18 -32
- package/src/ir/diagnostics.ts +25 -18
- package/src/ir/domains.ts +26 -23
- package/src/ir/fold.ts +55 -50
- package/src/ir/identity.ts +10 -0
- package/src/ir/index.ts +31 -7
- package/src/ir/job-errors.ts +30 -8
- package/src/ir/layouts.ts +63 -34
- package/src/ir/link.ts +11 -46
- package/src/ir/model.ts +25 -6
- package/src/ir/normalize.ts +3 -28
- package/src/ir/numeric.ts +45 -18
- package/src/ir/operands.ts +102 -0
- package/src/ir/ranges.ts +242 -67
- package/src/ir/routine.ts +126 -183
- package/src/ir/scalars.ts +29 -25
- package/src/ir/share.ts +323 -343
- package/src/ir/short-circuit.ts +140 -0
- package/src/ir/tables.ts +111 -0
- package/src/ir/temporaries.ts +15 -113
- package/src/ir/types.ts +32 -8
- package/src/project/artifacts.ts +143 -71
- package/src/project/cli.ts +104 -87
- package/src/project/debugger.ts +48 -34
- package/src/project/deployments.ts +12 -68
- package/src/project/flags.ts +14 -0
- package/src/project/plant.ts +293 -225
- package/src/project/project-commands.ts +254 -192
- package/src/project/project.ts +184 -141
- package/src/project/release.ts +22 -28
- package/src/project/server.ts +22 -26
- package/src/project/terminal.ts +13 -2
- package/src/runtime/async.ts +17 -13
- package/src/runtime/launch.ts +5 -2
- package/src/runtime/main.ts +8 -3
- package/src/runtime/missing-file.ts +3 -0
- package/src/runtime/process.ts +24 -19
- package/src/runtime/program.ts +20 -53
- package/src/runtime/retain.ts +18 -10
- package/src/runtime/runtime.ts +47 -60
- package/src/runtime/settings.ts +27 -0
- package/src/runtime/storage.ts +49 -74
- package/src/runtime/symbols.ts +19 -75
- package/src/runtime/telemetry.ts +37 -14
- package/src/runtime/transport.ts +26 -30
- package/stdlib/clock.ts +4 -2
- package/stdlib/plc-time.ts +2 -0
- package/stdlib/retain.ts +2 -0
- package/stdlib/signals.ts +142 -0
- package/stdlib/telemetry.ts +5 -12
- package/types/dialect.d.ts +49 -0
- package/types/globals.d.ts +2 -42
- package/types/index.d.ts +3 -1
- package/types/retain.d.ts +8 -2
- package/types/telemetry.d.ts +3 -0
- package/dist/bun-runtime.js +0 -1472
- package/dist/bun-runtime.js.map +0 -26
- package/dist/elaborate-capture.js +0 -304
- package/dist/elaborate-capture.js.map +0 -11
- package/dist/math.js +0 -24
- package/dist/math.js.map +0 -10
- package/dist/project.js +0 -626
- package/dist/project.js.map +0 -12
- package/dist/server-check.js +0 -59
- package/dist/server-check.js.map +0 -11
- package/src/frontend/exposure.ts +0 -181
- package/src/project/index.ts +0 -6
- package/src/runtime/.runtime-65O4JH/server/router.ts +0 -17
- package/src/runtime/.runtime-65O4JH/src/cell.ts +0 -45
- package/src/runtime/.runtime-65O4JH/src/controller.ts +0 -58
- package/src/runtime/.runtime-65O4JH/src/lane.ts +0 -6
- package/src/runtime/.runtime-65O4JH/src/main.ts +0 -11
- package/src/runtime/.runtime-65O4JH/src/services.ts +0 -8
- package/src/runtime/.runtime-65O4JH/tsconfig.json +0 -13
- package/src/runtime/.runtime-65O4JH/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-Brw2kO/server/router.ts +0 -17
- package/src/runtime/.runtime-Brw2kO/src/cell.ts +0 -45
- package/src/runtime/.runtime-Brw2kO/src/controller.ts +0 -58
- package/src/runtime/.runtime-Brw2kO/src/lane.ts +0 -6
- package/src/runtime/.runtime-Brw2kO/src/main.ts +0 -11
- package/src/runtime/.runtime-Brw2kO/src/services.ts +0 -8
- package/src/runtime/.runtime-Brw2kO/tsconfig.json +0 -13
- package/src/runtime/.runtime-Brw2kO/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-NHfu1D/server/router.ts +0 -17
- package/src/runtime/.runtime-NHfu1D/src/cell.ts +0 -45
- package/src/runtime/.runtime-NHfu1D/src/controller.ts +0 -58
- package/src/runtime/.runtime-NHfu1D/src/lane.ts +0 -6
- package/src/runtime/.runtime-NHfu1D/src/main.ts +0 -11
- package/src/runtime/.runtime-NHfu1D/src/services.ts +0 -8
- package/src/runtime/.runtime-NHfu1D/tsconfig.json +0 -13
- package/src/runtime/.runtime-NHfu1D/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-VaUSOu/server/router.ts +0 -17
- package/src/runtime/.runtime-VaUSOu/src/cell.ts +0 -45
- package/src/runtime/.runtime-VaUSOu/src/controller.ts +0 -58
- package/src/runtime/.runtime-VaUSOu/src/lane.ts +0 -6
- package/src/runtime/.runtime-VaUSOu/src/main.ts +0 -11
- package/src/runtime/.runtime-VaUSOu/src/services.ts +0 -8
- package/src/runtime/.runtime-VaUSOu/tsconfig.json +0 -13
- package/src/runtime/.runtime-VaUSOu/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-WbtNvR/server/router.ts +0 -17
- package/src/runtime/.runtime-WbtNvR/src/cell.ts +0 -45
- package/src/runtime/.runtime-WbtNvR/src/controller.ts +0 -58
- package/src/runtime/.runtime-WbtNvR/src/lane.ts +0 -6
- package/src/runtime/.runtime-WbtNvR/src/main.ts +0 -11
- package/src/runtime/.runtime-WbtNvR/src/services.ts +0 -8
- package/src/runtime/.runtime-WbtNvR/tsconfig.json +0 -13
- package/src/runtime/.runtime-WbtNvR/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-opcua-GMPUt8/server/router.ts +0 -17
- package/src/runtime/.runtime-opcua-GMPUt8/src/cell.ts +0 -45
- package/src/runtime/.runtime-opcua-GMPUt8/src/controller.ts +0 -58
- package/src/runtime/.runtime-opcua-GMPUt8/src/lane.ts +0 -6
- package/src/runtime/.runtime-opcua-GMPUt8/src/main.ts +0 -11
- package/src/runtime/.runtime-opcua-GMPUt8/src/services.ts +0 -8
- package/src/runtime/.runtime-opcua-GMPUt8/tsconfig.json +0 -13
- package/src/runtime/.runtime-opcua-GMPUt8/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-opcua-UwafxO/server/router.ts +0 -17
- package/src/runtime/.runtime-opcua-UwafxO/src/cell.ts +0 -45
- package/src/runtime/.runtime-opcua-UwafxO/src/controller.ts +0 -58
- package/src/runtime/.runtime-opcua-UwafxO/src/lane.ts +0 -6
- package/src/runtime/.runtime-opcua-UwafxO/src/main.ts +0 -11
- package/src/runtime/.runtime-opcua-UwafxO/src/services.ts +0 -8
- package/src/runtime/.runtime-opcua-UwafxO/tsconfig.json +0 -13
- package/src/runtime/.runtime-opcua-UwafxO/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-opcua-ecaSee/server/router.ts +0 -17
- package/src/runtime/.runtime-opcua-ecaSee/src/cell.ts +0 -45
- package/src/runtime/.runtime-opcua-ecaSee/src/controller.ts +0 -58
- package/src/runtime/.runtime-opcua-ecaSee/src/lane.ts +0 -6
- package/src/runtime/.runtime-opcua-ecaSee/src/main.ts +0 -11
- package/src/runtime/.runtime-opcua-ecaSee/src/services.ts +0 -8
- package/src/runtime/.runtime-opcua-ecaSee/tsconfig.json +0 -13
- package/src/runtime/.runtime-opcua-ecaSee/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-opcua-y91UCm/server/router.ts +0 -17
- package/src/runtime/.runtime-opcua-y91UCm/src/cell.ts +0 -45
- package/src/runtime/.runtime-opcua-y91UCm/src/controller.ts +0 -58
- package/src/runtime/.runtime-opcua-y91UCm/src/lane.ts +0 -6
- package/src/runtime/.runtime-opcua-y91UCm/src/main.ts +0 -11
- package/src/runtime/.runtime-opcua-y91UCm/src/services.ts +0 -8
- package/src/runtime/.runtime-opcua-y91UCm/tsconfig.json +0 -13
- package/src/runtime/.runtime-opcua-y91UCm/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-ybIxYh/server/router.ts +0 -17
- package/src/runtime/.runtime-ybIxYh/src/cell.ts +0 -45
- package/src/runtime/.runtime-ybIxYh/src/controller.ts +0 -58
- package/src/runtime/.runtime-ybIxYh/src/lane.ts +0 -6
- package/src/runtime/.runtime-ybIxYh/src/main.ts +0 -11
- package/src/runtime/.runtime-ybIxYh/src/services.ts +0 -8
- package/src/runtime/.runtime-ybIxYh/tsconfig.json +0 -13
- package/src/runtime/.runtime-ybIxYh/tsplc.config.ts +0 -31
- package/stdlib/math.ts +0 -23
- package/types/plc.d.ts +0 -4
|
@@ -1,20 +1,28 @@
|
|
|
1
|
-
// biome-ignore-all lint/style/noNonNullAssertion: Retain existing non-null assertions during the tooling migration; changing their contracts requires a separate review.
|
|
2
1
|
import { basename } from "node:path";
|
|
2
|
+
import { pascalCase } from "@tsplc/compiler/ir";
|
|
3
3
|
import ts from "typescript";
|
|
4
|
-
import
|
|
4
|
+
import { hasModifier } from "../types";
|
|
5
|
+
import type { CapturedValue } from "./capture-protocol";
|
|
5
6
|
import type { EntryImports } from "./imports";
|
|
6
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
arrayLayout,
|
|
9
|
+
type Layouts,
|
|
10
|
+
recordTypes,
|
|
11
|
+
statelessLayout,
|
|
12
|
+
} from "./layouts";
|
|
7
13
|
import {
|
|
8
14
|
children,
|
|
9
15
|
type Model,
|
|
10
16
|
type ModelNode,
|
|
11
17
|
type Owner,
|
|
18
|
+
ownerAt,
|
|
12
19
|
type Root,
|
|
13
20
|
type Step,
|
|
21
|
+
stepPath,
|
|
14
22
|
tsPath,
|
|
15
23
|
} from "./model";
|
|
16
24
|
import { referable, referenceLayout, referenceType } from "./references";
|
|
17
|
-
import {
|
|
25
|
+
import { capturedPrimitive, type Value } from "./values";
|
|
18
26
|
import { ScanWrites } from "./writes";
|
|
19
27
|
|
|
20
28
|
/** A primitive scan code read from setup and folded, at its TypeScript path. */
|
|
@@ -27,6 +35,13 @@ interface FoldedField {
|
|
|
27
35
|
iec?: string;
|
|
28
36
|
}
|
|
29
37
|
|
|
38
|
+
/** A stored field of a flattened root: a global of the root's storage module. */
|
|
39
|
+
interface RootField {
|
|
40
|
+
name: string;
|
|
41
|
+
layout: string;
|
|
42
|
+
declaration: ts.Node | undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
30
45
|
/**
|
|
31
46
|
* Where the state setup built lives in the PLC, and how scan code reads it. A field is stored when
|
|
32
47
|
* scan code writes it or its root is exported; what setup fixed otherwise folds where it is read.
|
|
@@ -74,10 +89,7 @@ export class Storage {
|
|
|
74
89
|
if (!holder.type) {
|
|
75
90
|
return undefined;
|
|
76
91
|
}
|
|
77
|
-
|
|
78
|
-
return (
|
|
79
|
-
variant.getProperty(name) ?? this.checker.getPropertyOfType(variant, name)
|
|
80
|
-
);
|
|
92
|
+
return this.model.variant(holder.type, holder.captured).getProperty(name);
|
|
81
93
|
}
|
|
82
94
|
|
|
83
95
|
/** Whether a field holds state the PLC stores, rather than a value fixed at setup. */
|
|
@@ -88,6 +100,23 @@ export class Storage {
|
|
|
88
100
|
return this.written(holder, name);
|
|
89
101
|
}
|
|
90
102
|
|
|
103
|
+
/**
|
|
104
|
+
* Whether a stored field still reads as the value setup gave it: a readonly field scan code never
|
|
105
|
+
* assigns, as a collection's capacity is, which an exported root stores for the HMI to read. A
|
|
106
|
+
* root `io` reaches is the hardware's to write, so none of its fields is fixed.
|
|
107
|
+
*/
|
|
108
|
+
private fixed(holder: ModelNode, name: string): boolean {
|
|
109
|
+
const declaration = this.fieldDeclaration(holder, name);
|
|
110
|
+
return (
|
|
111
|
+
holder.owner !== undefined &&
|
|
112
|
+
!holder.owner.root.bound &&
|
|
113
|
+
declaration !== undefined &&
|
|
114
|
+
ts.canHaveModifiers(declaration) &&
|
|
115
|
+
hasModifier(declaration, ts.SyntaxKind.ReadonlyKeyword) &&
|
|
116
|
+
!this.written(holder, name)
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
91
120
|
/** Whether scan code assigns the field itself. */
|
|
92
121
|
private written(holder: ModelNode, name: string): boolean {
|
|
93
122
|
const symbol = this.fieldSymbol(holder, name);
|
|
@@ -133,40 +162,43 @@ export class Storage {
|
|
|
133
162
|
return { references: [], referenceFields: [] };
|
|
134
163
|
}
|
|
135
164
|
return {
|
|
136
|
-
references: this.model.nodes.flatMap((node) =>
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
165
|
+
references: this.model.nodes.flatMap((node) =>
|
|
166
|
+
referable(node) && node.owner
|
|
167
|
+
? [{ id: node.reference, path: this.storagePlace(node.owner) }]
|
|
168
|
+
: [],
|
|
169
|
+
),
|
|
170
|
+
referenceFields: this.references.flatMap(({ holder, name }) =>
|
|
171
|
+
holder.owner ? [`${this.storagePlace(holder.owner)}.${name}`] : [],
|
|
172
|
+
),
|
|
144
173
|
};
|
|
145
174
|
}
|
|
146
175
|
|
|
147
|
-
/** A
|
|
148
|
-
private storagePlace(
|
|
149
|
-
const
|
|
150
|
-
if (!owner) {
|
|
151
|
-
return undefined;
|
|
152
|
-
}
|
|
176
|
+
/** A place as module storage: its root's module, the root unless flattened, then fields and indexes. */
|
|
177
|
+
private storagePlace(owner: Owner): string {
|
|
178
|
+
const module = basename(this.rootModule(owner.root), ".ts");
|
|
153
179
|
const root = this.flattened(owner.root)
|
|
154
|
-
?
|
|
155
|
-
: `${
|
|
156
|
-
return (
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
180
|
+
? module
|
|
181
|
+
: `${module}.${owner.root.name}`;
|
|
182
|
+
return root + this.stepsText(owner, (_, key) => key);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* The steps from a place's root down to it, as storage spells them: an element of a mixed-state
|
|
187
|
+
* array is a field of its record, and `key` spells a numeric key of the object holding it.
|
|
188
|
+
*/
|
|
189
|
+
private stepsText(
|
|
190
|
+
owner: Owner,
|
|
191
|
+
key: (holder: ModelNode | undefined, key: string) => string,
|
|
192
|
+
): string {
|
|
193
|
+
return owner.steps
|
|
194
|
+
.map((step, index) => {
|
|
195
|
+
const holder = this.model.at(owner.root, owner.steps.slice(0, index));
|
|
196
|
+
if (step.kind === "index" && holder && this.mixedStates(holder)) {
|
|
197
|
+
return `.${mixedItem(step.index)}`;
|
|
198
|
+
}
|
|
199
|
+
return stepPath(step, (name) => key(holder, name));
|
|
200
|
+
})
|
|
201
|
+
.join("");
|
|
170
202
|
}
|
|
171
203
|
|
|
172
204
|
/** Asked of every field each time an instance's layout is, so answered once. */
|
|
@@ -193,37 +225,27 @@ export class Storage {
|
|
|
193
225
|
);
|
|
194
226
|
}
|
|
195
227
|
|
|
196
|
-
/** Dialect text for a stored node's place. */
|
|
228
|
+
/** Dialect text for a stored node's place. Generated code then reads its root's storage, so this stores the root. */
|
|
197
229
|
pathText(node: ModelNode): string {
|
|
198
230
|
const owner = node.owner;
|
|
199
231
|
if (!owner) {
|
|
200
232
|
throw new Error("An object with no owner has no storage.");
|
|
201
233
|
}
|
|
202
|
-
this.
|
|
203
|
-
|
|
234
|
+
return this.placeText(owner);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** Dialect text for a place, which stores its root; a `Record<Enum, T>` key indexes by its enum member. */
|
|
238
|
+
private placeText(owner: Owner): string {
|
|
239
|
+
const namespace = this.reach(owner.root);
|
|
204
240
|
const root = this.flattened(owner.root)
|
|
205
241
|
? namespace
|
|
206
242
|
: `${namespace}.${owner.root.name}`;
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
)
|
|
243
|
+
return (
|
|
244
|
+
root +
|
|
245
|
+
this.stepsText(owner, (holder, key) =>
|
|
246
|
+
holder?.type ? this.keyText(holder.type, key) : key,
|
|
247
|
+
)
|
|
212
248
|
);
|
|
213
|
-
return root + steps.join("");
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/** Dialect text for one step down from `holder`: a `Record<Enum, T>` key indexes by its enum member. */
|
|
217
|
-
private placeStep(holder: ModelNode | undefined, step: Step): string {
|
|
218
|
-
if (step.kind === "index") {
|
|
219
|
-
return holder && this.mixedStates(holder)
|
|
220
|
-
? `.${mixedItem(step.index)}`
|
|
221
|
-
: `[${step.index}]`;
|
|
222
|
-
}
|
|
223
|
-
if (/^\d+$/.test(step.name) && holder?.type) {
|
|
224
|
-
return `[${this.keyText(holder.type, step.name)}]`;
|
|
225
|
-
}
|
|
226
|
-
return `.${step.name}`;
|
|
227
249
|
}
|
|
228
250
|
|
|
229
251
|
/** The enum member naming a key of a `Record<Enum, T>`. */
|
|
@@ -232,8 +254,7 @@ export class Storage {
|
|
|
232
254
|
if (!keyType) {
|
|
233
255
|
return key;
|
|
234
256
|
}
|
|
235
|
-
|
|
236
|
-
return member ? `${this.layouts.text(keyType)}.${member}` : key;
|
|
257
|
+
return this.layouts.enumMember(keyType, Number(key)) ?? key;
|
|
237
258
|
}
|
|
238
259
|
|
|
239
260
|
/** A record or instance root becomes its own global list, one global per field. */
|
|
@@ -244,17 +265,22 @@ export class Storage {
|
|
|
244
265
|
);
|
|
245
266
|
}
|
|
246
267
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
268
|
+
/**
|
|
269
|
+
* Stores a root and has the entry module import its storage module, and returns the namespace
|
|
270
|
+
* generated code reads that module through.
|
|
271
|
+
*/
|
|
272
|
+
private reach(root: Root): string {
|
|
273
|
+
const module = this.rootModule(root);
|
|
274
|
+
const pascal = pascalCase(basename(module, ".ts"));
|
|
275
|
+
const namespace = this.typeNames.has(pascal) ? `${pascal}Root` : pascal;
|
|
276
|
+
this.storedRoots.add(root);
|
|
277
|
+
this.imports.namespaces.set(namespace, module);
|
|
278
|
+
return namespace;
|
|
252
279
|
}
|
|
253
280
|
|
|
254
281
|
/** Stores a root whether or not scan code reads it, as exported data must be. */
|
|
255
282
|
use(root: Root): void {
|
|
256
|
-
this.
|
|
257
|
-
this.namespace(root);
|
|
283
|
+
this.reach(root);
|
|
258
284
|
}
|
|
259
285
|
|
|
260
286
|
/** Roots generated code reached, which need storage declarations. */
|
|
@@ -274,10 +300,12 @@ export class Storage {
|
|
|
274
300
|
if (captured.kind === "array") {
|
|
275
301
|
return (
|
|
276
302
|
this.storedArray(node) ||
|
|
277
|
-
captured.items.some((item) => {
|
|
303
|
+
captured.items.some((item, index) => {
|
|
278
304
|
const inner = this.model.node(item);
|
|
279
305
|
return (
|
|
280
|
-
inner !== undefined &&
|
|
306
|
+
inner !== undefined &&
|
|
307
|
+
this.owns(node, inner, { kind: "index", index }) &&
|
|
308
|
+
this.hasState(inner)
|
|
281
309
|
);
|
|
282
310
|
})
|
|
283
311
|
);
|
|
@@ -290,7 +318,7 @@ export class Storage {
|
|
|
290
318
|
const inner = this.model.node(value);
|
|
291
319
|
return (
|
|
292
320
|
inner !== undefined &&
|
|
293
|
-
|
|
321
|
+
this.owns(node, inner, { kind: "field", name }) &&
|
|
294
322
|
this.hasState(inner)
|
|
295
323
|
);
|
|
296
324
|
});
|
|
@@ -312,6 +340,7 @@ export class Storage {
|
|
|
312
340
|
return this.layoutName(
|
|
313
341
|
`${captured.name}State`,
|
|
314
342
|
fields.map(([field, text]) => `${field}: ${text};`).join(" "),
|
|
343
|
+
this.model.classOf(node),
|
|
315
344
|
);
|
|
316
345
|
}
|
|
317
346
|
if (captured.kind === "array") {
|
|
@@ -323,29 +352,25 @@ export class Storage {
|
|
|
323
352
|
"MixedStates",
|
|
324
353
|
states
|
|
325
354
|
.map(
|
|
326
|
-
(state, index) =>
|
|
355
|
+
(state, index) =>
|
|
356
|
+
`${mixedItem(index)}: ${state ?? statelessLayout};`,
|
|
327
357
|
)
|
|
328
358
|
.join(" "),
|
|
359
|
+
this.holderDeclaration(node),
|
|
329
360
|
);
|
|
330
361
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
"MixedStates",
|
|
335
|
-
states
|
|
336
|
-
.map(
|
|
337
|
-
(state, index) => `${mixedItem(index)}: ${state ?? "boolean"};`,
|
|
338
|
-
)
|
|
339
|
-
.join(" "),
|
|
340
|
-
);
|
|
341
|
-
}
|
|
342
|
-
return `FixedArray<${states[0]}, ${captured.items.length}>`;
|
|
362
|
+
const state = states?.[0];
|
|
363
|
+
if (first?.captured.kind === "instance" && state) {
|
|
364
|
+
return arrayLayout(state, captured.items.length).text;
|
|
343
365
|
}
|
|
344
366
|
}
|
|
345
367
|
if (!node.type) {
|
|
346
368
|
throw new Error("Stored state needs a declared type.");
|
|
347
369
|
}
|
|
348
|
-
return this.layouts.
|
|
370
|
+
return this.layouts.declaredText(this.holderDeclaration(node), node.type, {
|
|
371
|
+
kind: "node",
|
|
372
|
+
id: node.id,
|
|
373
|
+
});
|
|
349
374
|
}
|
|
350
375
|
|
|
351
376
|
/**
|
|
@@ -385,15 +410,15 @@ export class Storage {
|
|
|
385
410
|
if (captured.kind !== "array") {
|
|
386
411
|
return undefined;
|
|
387
412
|
}
|
|
388
|
-
const items = captured.items.
|
|
389
|
-
|
|
413
|
+
const items = captured.items.flatMap((item) => {
|
|
414
|
+
const inner = this.model.node(item);
|
|
415
|
+
return inner ? [inner] : [];
|
|
416
|
+
});
|
|
417
|
+
if (items.length !== captured.items.length) {
|
|
390
418
|
return undefined;
|
|
391
419
|
}
|
|
392
420
|
const element = node.type && this.model.elementType(node.type);
|
|
393
421
|
return items.map((item) => {
|
|
394
|
-
if (!item) {
|
|
395
|
-
return undefined;
|
|
396
|
-
}
|
|
397
422
|
if (item.captured.kind === "instance") {
|
|
398
423
|
return this.storageType(item);
|
|
399
424
|
}
|
|
@@ -417,15 +442,17 @@ export class Storage {
|
|
|
417
442
|
const fields = this.model.fields(this.model.classOf(node));
|
|
418
443
|
return fields.flatMap((member): [string, string][] => {
|
|
419
444
|
const name = member.name.getText();
|
|
420
|
-
const value =
|
|
445
|
+
const value = this.model.field(node, name);
|
|
421
446
|
const inner = this.model.node(value);
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
447
|
+
const type = this.model.capturedFieldType(node, name);
|
|
448
|
+
if (!type) {
|
|
449
|
+
throw new Error(`${captured.name}.${name} has no declared type.`);
|
|
450
|
+
}
|
|
451
|
+
const owned =
|
|
452
|
+
inner !== undefined && this.owns(node, inner, { kind: "field", name });
|
|
426
453
|
if (this.referenceField(node, name)) {
|
|
427
454
|
// The object setup put there is stored through this field, which a reference would replace.
|
|
428
|
-
if (
|
|
455
|
+
if (owned) {
|
|
429
456
|
throw new Error(
|
|
430
457
|
`${captured.name}.${name} is assigned in scan code, but it is where setup first put the object it starts with, so that object is stored there. Give the object another owner: a module constant, or a readonly field setup assigns before this one.`,
|
|
431
458
|
);
|
|
@@ -433,22 +460,23 @@ export class Storage {
|
|
|
433
460
|
return [[name, referenceLayout]];
|
|
434
461
|
}
|
|
435
462
|
if (inner) {
|
|
436
|
-
if (
|
|
437
|
-
inner.captured.kind === "function" ||
|
|
438
|
-
inner.captured.kind === "closure" ||
|
|
439
|
-
inner.captured.kind === "service"
|
|
440
|
-
) {
|
|
463
|
+
if (callable(inner)) {
|
|
441
464
|
return [];
|
|
442
465
|
}
|
|
443
|
-
if (!
|
|
466
|
+
if (!owned) {
|
|
444
467
|
if (!this.stored(node, name)) {
|
|
445
468
|
return [];
|
|
446
469
|
}
|
|
447
|
-
// A stored field holds its own copy of the record setup gave it.
|
|
448
|
-
|
|
470
|
+
// A stored field holds its own copy of the record setup gave it. A copied instance
|
|
471
|
+
// keeps the record its class's type describes, which emitted ST names `ST_<Class>`.
|
|
472
|
+
const layout =
|
|
473
|
+
inner.captured.kind === "instance"
|
|
474
|
+
? this.layouts.text(type, value)
|
|
475
|
+
: this.layouts.declaredText(member, type, value);
|
|
476
|
+
return [[name, layout]];
|
|
449
477
|
}
|
|
450
478
|
if (inner.captured.kind !== "instance" && this.stored(node, name)) {
|
|
451
|
-
return [[name, this.layouts.
|
|
479
|
+
return [[name, this.layouts.declaredText(member, type, value)]];
|
|
452
480
|
}
|
|
453
481
|
const text = this.storageType(inner);
|
|
454
482
|
return text ? [[name, text]] : [];
|
|
@@ -460,19 +488,70 @@ export class Storage {
|
|
|
460
488
|
});
|
|
461
489
|
}
|
|
462
490
|
|
|
463
|
-
|
|
491
|
+
/** A flattened root's stored fields, each a global of its storage module; an exported record stores every field. */
|
|
492
|
+
rootFields(root: Root): RootField[] {
|
|
493
|
+
const node = this.model.node(root.value);
|
|
494
|
+
if (node?.captured.kind === "instance") {
|
|
495
|
+
const declaration = this.model.classOf(node);
|
|
496
|
+
return this.instanceFields(node).map(([name, layout]) => ({
|
|
497
|
+
name,
|
|
498
|
+
layout,
|
|
499
|
+
declaration: this.model.member(declaration, name),
|
|
500
|
+
}));
|
|
501
|
+
}
|
|
502
|
+
if (node?.captured.kind !== "object") {
|
|
503
|
+
return [];
|
|
504
|
+
}
|
|
505
|
+
return Object.entries(node.captured.fields).flatMap(
|
|
506
|
+
([name, value]): RootField[] => {
|
|
507
|
+
const declared = this.model.capturedFieldType(node, name);
|
|
508
|
+
if (!declared) {
|
|
509
|
+
return [];
|
|
510
|
+
}
|
|
511
|
+
const declaration = this.fieldDeclaration(node, name);
|
|
512
|
+
const inner = this.model.node(value);
|
|
513
|
+
if (inner && callable(inner)) {
|
|
514
|
+
return [];
|
|
515
|
+
}
|
|
516
|
+
if (root.exported || (!inner && this.stored(node, name))) {
|
|
517
|
+
const hint = name.charAt(0).toUpperCase() + name.slice(1);
|
|
518
|
+
return [
|
|
519
|
+
{
|
|
520
|
+
name,
|
|
521
|
+
layout: this.layouts.declaredText(
|
|
522
|
+
declaration,
|
|
523
|
+
declared,
|
|
524
|
+
value,
|
|
525
|
+
hint,
|
|
526
|
+
),
|
|
527
|
+
declaration,
|
|
528
|
+
},
|
|
529
|
+
];
|
|
530
|
+
}
|
|
531
|
+
if (!inner) {
|
|
532
|
+
return [];
|
|
533
|
+
}
|
|
534
|
+
// A record scan code assigns as a whole holds its own copy of what setup gave it.
|
|
535
|
+
const layout =
|
|
536
|
+
inner.captured.kind === "object" && this.stored(node, name)
|
|
537
|
+
? this.layouts.declaredText(declaration, declared, value)
|
|
538
|
+
: this.storageType(inner);
|
|
539
|
+
return layout ? [{ name, layout, declaration }] : [];
|
|
540
|
+
},
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
private layoutName(
|
|
545
|
+
base: string,
|
|
546
|
+
body: string,
|
|
547
|
+
origin: ts.Node | undefined,
|
|
548
|
+
): string {
|
|
464
549
|
const known = this.layoutNames.get(body);
|
|
465
550
|
if (known) {
|
|
466
551
|
return known;
|
|
467
552
|
}
|
|
468
|
-
const name =
|
|
469
|
-
base,
|
|
470
|
-
(candidate) =>
|
|
471
|
-
[...this.layoutNames.values()].includes(candidate) ||
|
|
472
|
-
this.layouts.declarations.has(candidate),
|
|
473
|
-
);
|
|
553
|
+
const name = this.layouts.declare(base, body, origin);
|
|
474
554
|
this.layoutNames.set(body, name);
|
|
475
|
-
this.layouts.declarations.set(name, `export interface ${name} { ${body} }`);
|
|
476
555
|
return name;
|
|
477
556
|
}
|
|
478
557
|
|
|
@@ -480,7 +559,12 @@ export class Storage {
|
|
|
480
559
|
const value = root.value;
|
|
481
560
|
if (value.kind === "node") {
|
|
482
561
|
const node = this.model.node(value);
|
|
483
|
-
|
|
562
|
+
// Scan code calls a service client or a task, so it stays an object setup built.
|
|
563
|
+
if (
|
|
564
|
+
this.kept(root.file) &&
|
|
565
|
+
node.captured.kind !== "service" &&
|
|
566
|
+
node.captured.kind !== "task"
|
|
567
|
+
) {
|
|
484
568
|
return this.keptRoot(root);
|
|
485
569
|
}
|
|
486
570
|
return { kind: "static", node };
|
|
@@ -489,18 +573,18 @@ export class Storage {
|
|
|
489
573
|
this.kept(root.file) ||
|
|
490
574
|
ts.getCombinedNodeFlags(root.declaration) & ts.NodeFlags.Const
|
|
491
575
|
) {
|
|
492
|
-
return
|
|
576
|
+
return capturedPrimitive(value);
|
|
493
577
|
}
|
|
494
578
|
// A module `let` of a plain module is state in its own global list.
|
|
495
|
-
const namespace = this.
|
|
496
|
-
this.
|
|
579
|
+
const namespace = this.reach(root);
|
|
580
|
+
const input = this.input({ root, steps: [] });
|
|
497
581
|
return {
|
|
498
582
|
kind: "code",
|
|
499
583
|
text: `${namespace}.${root.name}`,
|
|
500
584
|
declared: this.checker.getTypeAtLocation(root.declaration.name),
|
|
501
585
|
place: true,
|
|
502
586
|
iec: this.layouts.iecName(root.declaration),
|
|
503
|
-
|
|
587
|
+
...(input && { input }),
|
|
504
588
|
};
|
|
505
589
|
}
|
|
506
590
|
|
|
@@ -529,30 +613,23 @@ export class Storage {
|
|
|
529
613
|
step.kind === "field" &&
|
|
530
614
|
this.written(holder, step.name)
|
|
531
615
|
) {
|
|
532
|
-
return
|
|
533
|
-
holder,
|
|
534
|
-
step
|
|
535
|
-
node.captured.kind === "array" ? value : undefined,
|
|
536
|
-
);
|
|
616
|
+
return node.captured.kind === "array"
|
|
617
|
+
? this.storedArrayField(holder, step.name, node)
|
|
618
|
+
: this.storedField(holder, step);
|
|
537
619
|
}
|
|
538
620
|
return { kind: "static", node };
|
|
539
621
|
}
|
|
540
622
|
const stored =
|
|
541
623
|
step.kind === "field"
|
|
542
|
-
? this.stored(holder, step.name)
|
|
624
|
+
? this.stored(holder, step.name) && !this.fixed(holder, step.name)
|
|
543
625
|
: this.storedArray(holder);
|
|
544
626
|
if (stored) {
|
|
545
627
|
return this.storedField(holder, step);
|
|
546
628
|
}
|
|
547
629
|
if (holder.owner) {
|
|
548
|
-
this.readConstants.add(
|
|
549
|
-
tsPath({
|
|
550
|
-
root: holder.owner.root,
|
|
551
|
-
steps: [...holder.owner.steps, step],
|
|
552
|
-
}),
|
|
553
|
-
);
|
|
630
|
+
this.readConstants.add(tsPath(ownerAt(holder.owner, step)));
|
|
554
631
|
}
|
|
555
|
-
return
|
|
632
|
+
return capturedPrimitive(value);
|
|
556
633
|
}
|
|
557
634
|
|
|
558
635
|
/** A captured field's declaration: a class member or a record's property. */
|
|
@@ -570,9 +647,9 @@ export class Storage {
|
|
|
570
647
|
return this.layouts.iecName(this.fieldDeclaration(holder, name));
|
|
571
648
|
}
|
|
572
649
|
|
|
573
|
-
/** The declaration of the field holding
|
|
574
|
-
private
|
|
575
|
-
const owner =
|
|
650
|
+
/** The declaration of the field holding a record or array. */
|
|
651
|
+
private holderDeclaration(node: ModelNode): ts.Node | undefined {
|
|
652
|
+
const owner = node.owner;
|
|
576
653
|
const last = owner?.steps.at(-1);
|
|
577
654
|
if (!owner || last?.kind !== "field") {
|
|
578
655
|
return undefined;
|
|
@@ -583,7 +660,7 @@ export class Storage {
|
|
|
583
660
|
|
|
584
661
|
/** The IEC width of an array's elements, from the declaration holding the array. */
|
|
585
662
|
private arrayElementIec(array: ModelNode): string | undefined {
|
|
586
|
-
return this.layouts.elementIec(this.
|
|
663
|
+
return this.layouts.elementIec(this.holderDeclaration(array));
|
|
587
664
|
}
|
|
588
665
|
|
|
589
666
|
/**
|
|
@@ -602,14 +679,11 @@ export class Storage {
|
|
|
602
679
|
this.storedWhole(node)) ||
|
|
603
680
|
(captured.kind === "array" && this.storedArray(node));
|
|
604
681
|
for (const [step, value] of children(captured)) {
|
|
605
|
-
const at
|
|
682
|
+
const at = ownerAt(owner, step);
|
|
606
683
|
const inner = this.model.node(value);
|
|
607
684
|
if (inner) {
|
|
608
685
|
// Visit what this node owns; other places holding it refer to its owner.
|
|
609
|
-
if (
|
|
610
|
-
inner.owner?.root === at.root &&
|
|
611
|
-
tsPath(inner.owner) === tsPath(at)
|
|
612
|
-
) {
|
|
686
|
+
if (this.model.ownsAt(inner, at)) {
|
|
613
687
|
visit(inner, at, stores);
|
|
614
688
|
}
|
|
615
689
|
continue;
|
|
@@ -627,7 +701,7 @@ export class Storage {
|
|
|
627
701
|
const declaration =
|
|
628
702
|
step.kind === "field"
|
|
629
703
|
? this.fieldDeclaration(node, step.name)
|
|
630
|
-
: this.
|
|
704
|
+
: this.holderDeclaration(node);
|
|
631
705
|
const iec =
|
|
632
706
|
step.kind === "field"
|
|
633
707
|
? this.fieldIec(node, step.name)
|
|
@@ -653,25 +727,22 @@ export class Storage {
|
|
|
653
727
|
return found;
|
|
654
728
|
}
|
|
655
729
|
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
): Value {
|
|
730
|
+
private storedField(holder: ModelNode, step: Step): Value {
|
|
731
|
+
const owner = holder.owner;
|
|
732
|
+
if (!owner) {
|
|
733
|
+
throw new Error("An object with no owner has no storage.");
|
|
734
|
+
}
|
|
662
735
|
const declared =
|
|
663
736
|
step.kind === "index"
|
|
664
737
|
? holder.type && this.model.elementType(holder.type)
|
|
665
738
|
: this.model.capturedFieldType(holder, step.name);
|
|
666
|
-
const
|
|
667
|
-
step.kind === "field" &&
|
|
668
|
-
holder.owner?.steps.length === 0 &&
|
|
669
|
-
this.flattened(holder.owner.root);
|
|
739
|
+
const input = this.input(ownerAt(owner, step));
|
|
670
740
|
return {
|
|
671
741
|
kind: "code",
|
|
672
|
-
text:
|
|
742
|
+
text: this.placeText(ownerAt(owner, step)),
|
|
673
743
|
declared,
|
|
674
744
|
place: true,
|
|
745
|
+
...(input && { input }),
|
|
675
746
|
...(step.kind === "field"
|
|
676
747
|
? {
|
|
677
748
|
iec: this.fieldIec(holder, step.name),
|
|
@@ -680,29 +751,56 @@ export class Storage {
|
|
|
680
751
|
),
|
|
681
752
|
}
|
|
682
753
|
: { iec: this.arrayElementIec(holder) }),
|
|
683
|
-
...(global && {
|
|
684
|
-
setter: `${this.pathText(holder)}.${setterName(step.name)}`,
|
|
685
|
-
}),
|
|
686
|
-
...(array &&
|
|
687
|
-
declared &&
|
|
688
|
-
this.checker.isArrayType(declared) &&
|
|
689
|
-
step.kind === "field" && {
|
|
690
|
-
layout: this.layouts.declaredText(
|
|
691
|
-
this.fieldDeclaration(holder, step.name),
|
|
692
|
-
declared,
|
|
693
|
-
array,
|
|
694
|
-
),
|
|
695
|
-
length: this.capturedLength(array),
|
|
696
|
-
}),
|
|
697
754
|
};
|
|
698
755
|
}
|
|
699
756
|
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
757
|
+
/** An input the hardware writes at `place` or inside it, which scan code must not assign. */
|
|
758
|
+
private input(place: Owner): { path: string; address: string } | undefined {
|
|
759
|
+
const path = tsPath(place);
|
|
760
|
+
for (const [bound, address] of this.model.inputs) {
|
|
761
|
+
if (
|
|
762
|
+
bound === path ||
|
|
763
|
+
bound.startsWith(`${path}.`) ||
|
|
764
|
+
bound.startsWith(`${path}[`)
|
|
765
|
+
) {
|
|
766
|
+
return { path: bound, address };
|
|
767
|
+
}
|
|
703
768
|
}
|
|
704
|
-
|
|
705
|
-
|
|
769
|
+
return undefined;
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
/** A stored array field, with the layout and length of the array setup put there, which an array parameter takes when the field is passed to one. */
|
|
773
|
+
private storedArrayField(
|
|
774
|
+
holder: ModelNode,
|
|
775
|
+
name: string,
|
|
776
|
+
array: ModelNode,
|
|
777
|
+
): Value {
|
|
778
|
+
const stored = this.storedField(holder, { kind: "field", name });
|
|
779
|
+
if (
|
|
780
|
+
stored.kind !== "code" ||
|
|
781
|
+
!stored.declared ||
|
|
782
|
+
!this.checker.isArrayType(stored.declared) ||
|
|
783
|
+
array.captured.kind !== "array"
|
|
784
|
+
) {
|
|
785
|
+
return stored;
|
|
786
|
+
}
|
|
787
|
+
return {
|
|
788
|
+
...stored,
|
|
789
|
+
layout: this.layouts.declaredArray(
|
|
790
|
+
this.fieldDeclaration(holder, name),
|
|
791
|
+
stored.declared,
|
|
792
|
+
{ kind: "node", id: array.id },
|
|
793
|
+
),
|
|
794
|
+
length: array.captured.items.length,
|
|
795
|
+
};
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
/** Whether `holder` owns `node` at `step`. */
|
|
799
|
+
private owns(holder: ModelNode, node: ModelNode, step: Step): boolean {
|
|
800
|
+
return (
|
|
801
|
+
holder.owner !== undefined &&
|
|
802
|
+
this.model.ownsAt(node, ownerAt(holder.owner, step))
|
|
803
|
+
);
|
|
706
804
|
}
|
|
707
805
|
|
|
708
806
|
storedNode(node: ModelNode): boolean {
|
|
@@ -712,47 +810,16 @@ export class Storage {
|
|
|
712
810
|
}
|
|
713
811
|
}
|
|
714
812
|
|
|
715
|
-
/**
|
|
716
|
-
const
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
return constant(BigInt(value.value));
|
|
722
|
-
default:
|
|
723
|
-
return constant(value.value);
|
|
724
|
-
}
|
|
725
|
-
};
|
|
726
|
-
|
|
727
|
-
/** The function a storage module exports to set one of its globals. */
|
|
728
|
-
export const setterName = (name: string): string => `tsplcSet_${name}`;
|
|
729
|
-
|
|
730
|
-
/** Whether `holder` owns `node` directly, at its field `field` when one is given. */
|
|
731
|
-
const isChild = (
|
|
732
|
-
node: ModelNode,
|
|
733
|
-
holder: ModelNode,
|
|
734
|
-
field?: string,
|
|
735
|
-
): boolean => {
|
|
736
|
-
const owner = node.owner;
|
|
737
|
-
const parent = holder.owner;
|
|
738
|
-
if (!owner || !parent || owner.root !== parent.root) {
|
|
739
|
-
return false;
|
|
740
|
-
}
|
|
741
|
-
const last = owner.steps.at(-1);
|
|
742
|
-
const path = owner.steps.slice(0, -1).map(stepText);
|
|
743
|
-
const parentPath = parent.steps.map(stepText);
|
|
744
|
-
if (
|
|
745
|
-
last === undefined ||
|
|
746
|
-
path.length !== parentPath.length ||
|
|
747
|
-
path.some((text, index) => text !== parentPath[index])
|
|
748
|
-
) {
|
|
749
|
-
return false;
|
|
750
|
-
}
|
|
751
|
-
return field === undefined || (last.kind === "field" && last.name === field);
|
|
752
|
-
};
|
|
753
|
-
|
|
754
|
-
const stepText = (step: Step): string =>
|
|
755
|
-
step.kind === "index" ? `[${step.index}]` : `.${step.name}`;
|
|
813
|
+
/** Whether setup built a function, service client or task: scan code calls it, and the PLC stores nothing for it. */
|
|
814
|
+
const callable = (node: ModelNode): boolean =>
|
|
815
|
+
node.captured.kind === "function" ||
|
|
816
|
+
node.captured.kind === "closure" ||
|
|
817
|
+
node.captured.kind === "service" ||
|
|
818
|
+
node.captured.kind === "task";
|
|
756
819
|
|
|
757
820
|
/** The field of a mixed-state array's record that holds element `index`. */
|
|
758
821
|
const mixedItem = (index: number): string => `item${index}`;
|
|
822
|
+
|
|
823
|
+
/** A mixed-state array's record holding each element's value, given as text. */
|
|
824
|
+
export const mixedStateText = (items: readonly string[]): string =>
|
|
825
|
+
`{ ${items.map((item, index) => `${mixedItem(index)}: ${item}`).join(", ")} }`;
|