@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
package/src/codesys/plan.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
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 {
|
|
3
2
|
type Constant,
|
|
4
3
|
type CoreExpression,
|
|
5
4
|
type CoreStatement,
|
|
5
|
+
type CoreTables,
|
|
6
|
+
coreTables,
|
|
6
7
|
type Deployment,
|
|
7
8
|
type Diagnostic,
|
|
8
9
|
foldConstantRoutines,
|
|
9
10
|
forwardTemporaries,
|
|
11
|
+
freeze,
|
|
10
12
|
instancedBlock,
|
|
13
|
+
isLogicalIo,
|
|
11
14
|
isVerifiedCore,
|
|
12
15
|
nestedBodies,
|
|
13
16
|
type PlcType,
|
|
@@ -18,22 +21,23 @@ import {
|
|
|
18
21
|
type VerifiedCoreModule,
|
|
19
22
|
} from "@tsplc/compiler/ir";
|
|
20
23
|
import type {
|
|
24
|
+
Environment,
|
|
21
25
|
Publication,
|
|
22
26
|
ResolvedDebugConfig,
|
|
23
27
|
ResolvedHmiConfig,
|
|
24
28
|
ResolvedTelemetryConfig,
|
|
25
|
-
|
|
29
|
+
ServerConfig,
|
|
26
30
|
} from "@tsplc/config";
|
|
27
|
-
import { cyclicTasksSchema } from "@tsplc/config/build";
|
|
28
|
-
import { ioScalarBits, sizePrefixes } from "@tsplc/iec";
|
|
29
|
-
import { ioLayout } from "@tsplc/typegen/hardware";
|
|
30
|
-
import { type CodesysOptions, optionsSchema } from "./config";
|
|
31
31
|
import {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
} from "
|
|
32
|
+
cyclicTasksSchema,
|
|
33
|
+
scheduleRepeats,
|
|
34
|
+
taskPriority,
|
|
35
|
+
} from "@tsplc/config/build";
|
|
36
|
+
import { ioScalarBits } from "@tsplc/iec";
|
|
37
|
+
import { addressBits, ioLayout, regionOf } from "@tsplc/typegen/hardware";
|
|
38
|
+
import { type CodesysOptions, optionsSchema } from "./config";
|
|
39
|
+
import { type HttpEndpoint, resolveHttpEndpoint } from "./endpoints";
|
|
40
|
+
import { httpLayout, serviceBlock } from "./http";
|
|
37
41
|
import { writerPaths } from "./instrumentation";
|
|
38
42
|
import {
|
|
39
43
|
iecSpelling,
|
|
@@ -44,21 +48,18 @@ import {
|
|
|
44
48
|
import type { ProjectHardware } from "./manifest";
|
|
45
49
|
import { isIecIdentifier } from "./names";
|
|
46
50
|
import { resolvePublication } from "./publication";
|
|
51
|
+
import { required } from "./required";
|
|
52
|
+
import { schedulePrograms } from "./scheduling";
|
|
47
53
|
import { storageLayout } from "./storage";
|
|
48
54
|
import {
|
|
49
55
|
accessedStorage,
|
|
50
56
|
routineTasks,
|
|
51
|
-
schedulePrograms,
|
|
52
57
|
taskStorageOwnership,
|
|
53
58
|
} from "./task-access";
|
|
54
|
-
import {
|
|
55
|
-
planTelemetry,
|
|
56
|
-
type TelemetryPlan,
|
|
57
|
-
telemetryClient,
|
|
58
|
-
} from "./telemetry";
|
|
59
|
+
import { planTelemetry, type TelemetryPlan } from "./telemetry";
|
|
59
60
|
|
|
60
|
-
// Only this planner can admit a target configuration for emission
|
|
61
|
-
//
|
|
61
|
+
// Only this planner can admit a target configuration for emission: other modules cannot write the
|
|
62
|
+
// brand, and a copy of a plan is not in `plans`.
|
|
62
63
|
const planned: unique symbol = Symbol("CODESYS plan");
|
|
63
64
|
export interface CodesysPlan {
|
|
64
65
|
readonly [planned]: true;
|
|
@@ -74,16 +75,25 @@ export interface CodesysPlan {
|
|
|
74
75
|
readonly sharedRoutines: ReadonlyMap<string, string>;
|
|
75
76
|
readonly deployment: Deployment;
|
|
76
77
|
readonly options: CodesysOptions;
|
|
78
|
+
/** The IEC name `programNames` gives a program, by program name. */
|
|
79
|
+
readonly programNames: ReadonlyMap<string, string>;
|
|
77
80
|
/** `io` keys that name authored storage, resolved against the verified types. */
|
|
78
81
|
readonly storageBindings: readonly StorageBinding[];
|
|
79
82
|
/** The storage paths `debug.writers.paths` matches, each recorded in a last-writer slot. */
|
|
80
83
|
readonly writerPaths: readonly StorageBinding[];
|
|
81
84
|
readonly publication: Publication;
|
|
85
|
+
/** The endpoint each service block calls, by block id. */
|
|
82
86
|
readonly http: Readonly<Record<string, HttpEndpoint>>;
|
|
83
87
|
readonly project: CodesysProject;
|
|
84
88
|
/** Each task's records and their sender, when the program has telemetry. */
|
|
85
89
|
readonly telemetry?: TelemetryPlan;
|
|
86
90
|
}
|
|
91
|
+
|
|
92
|
+
const plans = new WeakSet<CodesysPlan>();
|
|
93
|
+
|
|
94
|
+
/** Whether `plan` is one `planCodesys` returned rather than a copy or a lookalike. */
|
|
95
|
+
export const isPlanned = (plan: CodesysPlan): boolean => plans.has(plan);
|
|
96
|
+
|
|
87
97
|
/**
|
|
88
98
|
* What the debug manifest describes beyond the program, the instrumentation `debug` asks for,
|
|
89
99
|
* and the telemetry settings and server its records go to.
|
|
@@ -93,18 +103,16 @@ export interface CodesysProject {
|
|
|
93
103
|
root: string;
|
|
94
104
|
debug?: ResolvedDebugConfig;
|
|
95
105
|
telemetry?: ResolvedTelemetryConfig;
|
|
96
|
-
server?: Pick<
|
|
97
|
-
NonNullable<ResolvedTsplcConfig["server"]>,
|
|
98
|
-
"transport" | "baseUrlEnv"
|
|
99
|
-
>;
|
|
106
|
+
server?: Pick<ServerConfig, "transport" | "baseUrlEnv">;
|
|
100
107
|
hardware?: ProjectHardware;
|
|
101
108
|
/** The HMI's controls, whose targets the debugger names as clients that write. */
|
|
102
109
|
hmi?: Pick<ResolvedHmiConfig, "controls">;
|
|
103
110
|
/** Where HTTP credentials and the telemetry base URL are read from; this process's environment by default. */
|
|
104
|
-
environment?:
|
|
111
|
+
environment?: Environment;
|
|
105
112
|
}
|
|
106
|
-
|
|
107
|
-
export
|
|
113
|
+
/** Where a check of the plan sends what it refuses, each becoming a diagnostic. */
|
|
114
|
+
export type Report = (message: string, span?: SourceSpan) => void;
|
|
115
|
+
function diagnostic(message: string, span?: SourceSpan): Diagnostic {
|
|
108
116
|
return {
|
|
109
117
|
origin: "backend",
|
|
110
118
|
code: "PLC7001",
|
|
@@ -113,9 +121,6 @@ export function diagnostic(message: string, span?: SourceSpan): Diagnostic {
|
|
|
113
121
|
...(span && { span }),
|
|
114
122
|
};
|
|
115
123
|
}
|
|
116
|
-
export function isCodesysPlan(plan: CodesysPlan): boolean {
|
|
117
|
-
return plans.has(plan);
|
|
118
|
-
}
|
|
119
124
|
|
|
120
125
|
export function planCodesys(
|
|
121
126
|
specialized: VerifiedCoreModule,
|
|
@@ -146,61 +151,49 @@ export function planCodesys(
|
|
|
146
151
|
const report = (message: string, span?: SourceSpan): void => {
|
|
147
152
|
diagnostics.push(diagnostic(message, span));
|
|
148
153
|
};
|
|
149
|
-
const { core, routines } =
|
|
154
|
+
const { core, routines, tasks, specializedTasks } = scheduledRoutines(
|
|
150
155
|
specialized,
|
|
151
156
|
deployment,
|
|
152
157
|
project.debug,
|
|
158
|
+
report,
|
|
153
159
|
);
|
|
154
|
-
const scheduled: Deployment = {
|
|
155
|
-
|
|
156
|
-
};
|
|
160
|
+
const scheduled: Deployment = { tasks };
|
|
161
|
+
const { types } = coreTables(core);
|
|
157
162
|
const http = new Map<string, HttpEndpoint>();
|
|
158
|
-
for (const block of core.blocks) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
new Map(core.types.map((type) => [type.id, type])),
|
|
164
|
-
);
|
|
165
|
-
http.set(
|
|
166
|
-
block.id,
|
|
167
|
-
block.runtime.kind === "rpc"
|
|
168
|
-
? {
|
|
169
|
-
transport: "opcua",
|
|
170
|
-
host: "",
|
|
171
|
-
port: 0,
|
|
172
|
-
authority: "",
|
|
173
|
-
path: block.runtime.path,
|
|
174
|
-
token: "",
|
|
175
|
-
timeoutMs: options.http.timeoutMs,
|
|
176
|
-
tls: false,
|
|
177
|
-
}
|
|
178
|
-
: resolveHttpEndpoint(block.runtime.url, options.http, environment),
|
|
179
|
-
);
|
|
180
|
-
} catch (cause) {
|
|
181
|
-
report(
|
|
182
|
-
cause instanceof Error ? cause.message : String(cause),
|
|
183
|
-
block.span,
|
|
184
|
-
);
|
|
185
|
-
}
|
|
163
|
+
for (const block of core.blocks.filter(serviceBlock)) {
|
|
164
|
+
const layout = httpLayout(block, types);
|
|
165
|
+
if ("error" in layout) {
|
|
166
|
+
report(layout.error, block.span);
|
|
167
|
+
continue;
|
|
186
168
|
}
|
|
169
|
+
const endpoint: HttpEndpoint | { error: string } =
|
|
170
|
+
block.runtime.kind === "rpc"
|
|
171
|
+
? {
|
|
172
|
+
transport: "opcua",
|
|
173
|
+
path: block.runtime.path,
|
|
174
|
+
timeoutMs: options.http.timeoutMs,
|
|
175
|
+
}
|
|
176
|
+
: resolveHttpEndpoint(block.runtime.url, options.http, environment);
|
|
177
|
+
if ("error" in endpoint) {
|
|
178
|
+
report(endpoint.error, block.span);
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
http.set(block.id, endpoint);
|
|
187
182
|
}
|
|
188
183
|
|
|
189
184
|
const storageBindings = validateIo(core, options, report);
|
|
190
185
|
const writerBindings = writerPaths(core, project.debug, report);
|
|
191
186
|
validateTasks(core, scheduled, report);
|
|
192
|
-
|
|
187
|
+
validateProgramNames(core, options.programNames, report);
|
|
188
|
+
validateRetain(core, report);
|
|
193
189
|
validateConstants(core, report);
|
|
194
|
-
const
|
|
190
|
+
const telemetry = planTelemetry(
|
|
195
191
|
core,
|
|
196
192
|
scheduled,
|
|
197
193
|
options,
|
|
198
194
|
{ ...project, environment, trace: project.debug?.trace },
|
|
199
195
|
report,
|
|
200
196
|
);
|
|
201
|
-
if (endpoint) {
|
|
202
|
-
http.set(telemetryClient, endpoint);
|
|
203
|
-
}
|
|
204
197
|
const { publication, errors } = resolvePublication(core, options.publish);
|
|
205
198
|
for (const error of errors) {
|
|
206
199
|
report(error);
|
|
@@ -213,12 +206,11 @@ export function planCodesys(
|
|
|
213
206
|
const plan: CodesysPlan = Object.freeze({
|
|
214
207
|
core,
|
|
215
208
|
specialized,
|
|
216
|
-
specializedTasks: {
|
|
217
|
-
tasks: schedulePrograms(specialized, deployment.tasks, () => {}),
|
|
218
|
-
},
|
|
209
|
+
specializedTasks: { tasks: specializedTasks },
|
|
219
210
|
sharedRoutines: routines,
|
|
220
211
|
deployment: structuredClone(scheduled),
|
|
221
|
-
options
|
|
212
|
+
options,
|
|
213
|
+
programNames: new Map(Object.entries(options.programNames)),
|
|
222
214
|
storageBindings,
|
|
223
215
|
writerPaths: writerBindings,
|
|
224
216
|
publication,
|
|
@@ -227,16 +219,6 @@ export function planCodesys(
|
|
|
227
219
|
...(telemetry && { telemetry }),
|
|
228
220
|
[planned]: true as const,
|
|
229
221
|
});
|
|
230
|
-
// Parsed options can contain nested engineering settings; detach and freeze the complete plan.
|
|
231
|
-
const freeze = (value: unknown): void => {
|
|
232
|
-
if (typeof value !== "object" || value === null || Object.isFrozen(value)) {
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
for (const child of Object.values(value)) {
|
|
236
|
-
freeze(child);
|
|
237
|
-
}
|
|
238
|
-
Object.freeze(value);
|
|
239
|
-
};
|
|
240
222
|
freeze(plan.deployment);
|
|
241
223
|
freeze(plan.specializedTasks);
|
|
242
224
|
freeze(plan.options);
|
|
@@ -247,41 +229,58 @@ export function planCodesys(
|
|
|
247
229
|
return { plan, diagnostics: [] };
|
|
248
230
|
}
|
|
249
231
|
|
|
250
|
-
type Report = (message: string, span?: SourceSpan) => void;
|
|
251
|
-
|
|
252
232
|
/**
|
|
253
233
|
* Routines specialized per instance, merged where they run the same code in the same task, calls
|
|
254
234
|
* of routines that only return a constant replaced by it, and temporaries read right after they
|
|
255
|
-
* are written folded into their reader
|
|
256
|
-
* calls them, and joining them named the
|
|
235
|
+
* are written folded into their reader, with each task's programs in the module that results.
|
|
236
|
+
* Continuation programs stay apart: each task's wrapper calls them, and joining them named the
|
|
237
|
+
* joined program after whichever came first.
|
|
257
238
|
* The debugger's instrumentation is written per statement of each routine, so a program built
|
|
258
|
-
* with `debug` keeps every instance's own routine, as does one whose scheduling is invalid
|
|
259
|
-
* diagnostics name the routines as written.
|
|
239
|
+
* with `debug` keeps every instance's own routine, as does one whose scheduling is invalid or
|
|
240
|
+
* names a program the module lacks: its diagnostics name the routines as written.
|
|
260
241
|
*/
|
|
261
|
-
function
|
|
262
|
-
|
|
242
|
+
function scheduledRoutines(
|
|
243
|
+
specialized: VerifiedCoreModule,
|
|
263
244
|
deployment: Deployment,
|
|
264
245
|
debug: ResolvedDebugConfig | undefined,
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
if (debug) {
|
|
268
|
-
return unshared;
|
|
269
|
-
}
|
|
246
|
+
report: Report,
|
|
247
|
+
) {
|
|
270
248
|
const issues: string[] = [];
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
249
|
+
const specializedTasks = schedulePrograms(
|
|
250
|
+
specialized,
|
|
251
|
+
deployment.tasks,
|
|
252
|
+
(message) => {
|
|
253
|
+
issues.push(message);
|
|
254
|
+
},
|
|
255
|
+
);
|
|
256
|
+
const programs = new Set(specialized.programs.map((program) => program.name));
|
|
257
|
+
const unknown = deployment.tasks.some((task) =>
|
|
258
|
+
task.programs.some((name) => !programs.has(name)),
|
|
259
|
+
);
|
|
260
|
+
if (debug || issues.length || unknown) {
|
|
261
|
+
for (const message of issues) {
|
|
262
|
+
report(message);
|
|
263
|
+
}
|
|
264
|
+
return {
|
|
265
|
+
core: specialized,
|
|
266
|
+
routines: new Map<string, string>(),
|
|
267
|
+
tasks: specializedTasks,
|
|
268
|
+
specializedTasks,
|
|
269
|
+
};
|
|
276
270
|
}
|
|
277
|
-
const folded = foldConstantRoutines(
|
|
278
|
-
const
|
|
271
|
+
const folded = foldConstantRoutines(specialized);
|
|
272
|
+
const foldedTasks = routineTasks(folded.core, {
|
|
279
273
|
tasks: schedulePrograms(folded.core, deployment.tasks, () => {}),
|
|
280
274
|
});
|
|
281
|
-
const shared = shareRoutines(folded.core, (routine) =>
|
|
275
|
+
const shared = shareRoutines(folded.core, (routine) =>
|
|
276
|
+
foldedTasks.get(routine.id),
|
|
277
|
+
);
|
|
278
|
+
const core = forwardTemporaries(shared.core);
|
|
282
279
|
return {
|
|
283
|
-
core
|
|
280
|
+
core,
|
|
284
281
|
routines: shared.routines,
|
|
282
|
+
tasks: schedulePrograms(core, deployment.tasks, report),
|
|
283
|
+
specializedTasks,
|
|
285
284
|
};
|
|
286
285
|
}
|
|
287
286
|
|
|
@@ -291,9 +290,7 @@ function validateIo(
|
|
|
291
290
|
options: CodesysOptions,
|
|
292
291
|
report: Report,
|
|
293
292
|
): StorageBinding[] {
|
|
294
|
-
|
|
295
|
-
// Different widths can still overlap.
|
|
296
|
-
const types = new Map(core.types.map((type) => [type.id, type]));
|
|
293
|
+
const tables = coreTables(core);
|
|
297
294
|
const targets: {
|
|
298
295
|
name: string;
|
|
299
296
|
binding: CodesysOptions["io"][string];
|
|
@@ -302,9 +299,7 @@ function validateIo(
|
|
|
302
299
|
span?: SourceSpan;
|
|
303
300
|
}[] = [];
|
|
304
301
|
const names = new Set<string>();
|
|
305
|
-
for (const item of core.variables.filter(
|
|
306
|
-
(item) => item.storage === "input" || item.storage === "output",
|
|
307
|
-
)) {
|
|
302
|
+
for (const item of core.variables.filter(isLogicalIo)) {
|
|
308
303
|
if (names.has(item.name)) {
|
|
309
304
|
report(
|
|
310
305
|
`Ambiguous I/O name ${item.name}; logical I/O names must be unique.`,
|
|
@@ -322,16 +317,15 @@ function validateIo(
|
|
|
322
317
|
targets.push({
|
|
323
318
|
name: item.name,
|
|
324
319
|
binding,
|
|
325
|
-
type:
|
|
326
|
-
region: item.storage
|
|
320
|
+
type: tables.typeOf(item.type),
|
|
321
|
+
region: regionOf(item.storage),
|
|
327
322
|
span: item.span,
|
|
328
323
|
});
|
|
329
324
|
}
|
|
330
325
|
|
|
331
326
|
const scheduled = new Set<string>();
|
|
332
327
|
for (const program of core.programs) {
|
|
333
|
-
const
|
|
334
|
-
for (const id of accessedStorage(fn, core)) {
|
|
328
|
+
for (const id of accessedStorage(tables.functionOf(program.entry), core)) {
|
|
335
329
|
scheduled.add(id);
|
|
336
330
|
}
|
|
337
331
|
}
|
|
@@ -365,14 +359,14 @@ function validateIo(
|
|
|
365
359
|
name,
|
|
366
360
|
binding,
|
|
367
361
|
type: resolved.type,
|
|
368
|
-
region: binding.address
|
|
362
|
+
region: required(addressBits(binding.address)).region,
|
|
369
363
|
});
|
|
370
364
|
}
|
|
371
365
|
|
|
372
|
-
const
|
|
373
|
-
region:
|
|
374
|
-
start:
|
|
375
|
-
end:
|
|
366
|
+
const placed: {
|
|
367
|
+
region: "I" | "Q";
|
|
368
|
+
start: number;
|
|
369
|
+
end: number;
|
|
376
370
|
name: string;
|
|
377
371
|
shared?: boolean;
|
|
378
372
|
}[] = [];
|
|
@@ -380,66 +374,58 @@ function validateIo(
|
|
|
380
374
|
// An array binds at its first element; the remaining elements follow at
|
|
381
375
|
// consecutive addresses of the same width, like an EDS byte/word span.
|
|
382
376
|
const array = type.kind === "array" ? type : undefined;
|
|
383
|
-
const element = array ?
|
|
377
|
+
const element = array ? tables.typeOf(array.element) : type;
|
|
384
378
|
// Typegen spells channels as IEC types; equal layouts bind (an EDS UINT flag word into a WORD).
|
|
385
|
-
const layout =
|
|
379
|
+
const layout = ioSpelling(type, tables, ioLayout);
|
|
386
380
|
if (binding.type && (!layout || ioLayout(binding.type) !== layout)) {
|
|
387
381
|
report(
|
|
388
382
|
`I/O type mismatch for ${name}: ${type.id} cannot bind to ${binding.type}.`,
|
|
389
383
|
span,
|
|
390
384
|
);
|
|
391
385
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
const size = sizePrefixes.get(binding.address.charAt(2))?.bits;
|
|
399
|
-
if (!match || size === undefined) {
|
|
400
|
-
continue;
|
|
386
|
+
const address = required(addressBits(binding.address));
|
|
387
|
+
if (address.region !== region) {
|
|
388
|
+
report(
|
|
389
|
+
`Wrong address region for ${name}: expected %${region}${binding.address.charAt(2)}.`,
|
|
390
|
+
span,
|
|
391
|
+
);
|
|
401
392
|
}
|
|
402
|
-
if (region === "I" && element
|
|
393
|
+
if (region === "I" && element.kind === "float") {
|
|
403
394
|
report(
|
|
404
395
|
"Floating logical inputs require an explicit runtime nonfinite policy, which is not supported yet.",
|
|
405
396
|
span,
|
|
406
397
|
);
|
|
407
398
|
}
|
|
408
|
-
if (array && element
|
|
399
|
+
if (array && element.kind === "bool") {
|
|
409
400
|
report(
|
|
410
401
|
`BOOL arrays are not bit-packed in CODESYS I/O; bind each element of ${name} separately.`,
|
|
411
402
|
span,
|
|
412
403
|
);
|
|
413
404
|
}
|
|
414
|
-
|
|
415
|
-
element && ioScalarBits(iecSpelling(element, types) ?? "");
|
|
416
|
-
if (elementBits !== size) {
|
|
405
|
+
if (ioSpelling(element, tables, ioScalarBits) !== address.bits) {
|
|
417
406
|
report(`Address size does not match ${name}:${type.id}.`, span);
|
|
418
407
|
}
|
|
419
|
-
|
|
420
|
-
const
|
|
421
|
-
const offset = BigInt(match[3]!);
|
|
422
|
-
const start = offset * unit + BigInt(match[4] ?? 0);
|
|
423
|
-
const end = start + BigInt(size) * BigInt(array?.length ?? 1);
|
|
408
|
+
const start = address.offsetBits;
|
|
409
|
+
const end = start + address.bits * (array?.length ?? 1);
|
|
424
410
|
if (
|
|
425
411
|
binding.inverted &&
|
|
426
|
-
(region !== "I" || element
|
|
412
|
+
(region !== "I" || element.kind !== "bool" || array)
|
|
427
413
|
) {
|
|
428
414
|
report(`Only a BOOL input can be inverted: ${name}.`, span);
|
|
429
415
|
}
|
|
430
416
|
if (binding.shared && region !== "I") {
|
|
431
417
|
report(`Only an input can be shared: ${name}.`, span);
|
|
432
418
|
}
|
|
433
|
-
const collision =
|
|
434
|
-
(
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
start <
|
|
419
|
+
const collision = placed.find(
|
|
420
|
+
(other) =>
|
|
421
|
+
other.region === address.region &&
|
|
422
|
+
other.start < end &&
|
|
423
|
+
start < other.end &&
|
|
438
424
|
!(
|
|
439
425
|
binding.shared &&
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
426
|
+
other.shared &&
|
|
427
|
+
other.start === start &&
|
|
428
|
+
other.end === end
|
|
443
429
|
),
|
|
444
430
|
);
|
|
445
431
|
if (collision) {
|
|
@@ -448,20 +434,32 @@ function validateIo(
|
|
|
448
434
|
span,
|
|
449
435
|
);
|
|
450
436
|
}
|
|
451
|
-
|
|
452
|
-
region:
|
|
437
|
+
placed.push({
|
|
438
|
+
region: address.region,
|
|
453
439
|
start,
|
|
454
440
|
end,
|
|
455
441
|
name,
|
|
456
442
|
shared: binding.shared,
|
|
457
443
|
});
|
|
458
|
-
|
|
444
|
+
// The address's number, which CODESYS counts in elements of its size: %IW12 is bytes 24-25.
|
|
445
|
+
const unit = address.bits === 1 ? 8 : address.bits;
|
|
446
|
+
if (Math.floor(address.offsetBits / unit) > 0x7fff_ffff) {
|
|
459
447
|
report(`I/O offset is too large: ${binding.address}.`, span);
|
|
460
448
|
}
|
|
461
449
|
}
|
|
462
450
|
return storageBindings;
|
|
463
451
|
}
|
|
464
452
|
|
|
453
|
+
/** What `read` makes of a type's IEC spelling, or undefined for a type typegen does not spell. */
|
|
454
|
+
const ioSpelling = <T>(
|
|
455
|
+
type: PlcType,
|
|
456
|
+
tables: CoreTables,
|
|
457
|
+
read: (spelling: string) => T,
|
|
458
|
+
): T | undefined => {
|
|
459
|
+
const spelling = iecSpelling(type, tables.types);
|
|
460
|
+
return spelling === undefined ? undefined : read(spelling);
|
|
461
|
+
};
|
|
462
|
+
|
|
465
463
|
/** Two storage bindings conflict when one target contains the other. */
|
|
466
464
|
function nested(left: StorageBinding, right: StorageBinding): boolean {
|
|
467
465
|
return (
|
|
@@ -478,76 +476,76 @@ function nested(left: StorageBinding, right: StorageBinding): boolean {
|
|
|
478
476
|
);
|
|
479
477
|
}
|
|
480
478
|
|
|
481
|
-
//
|
|
482
|
-
// task
|
|
483
|
-
//
|
|
484
|
-
const taskSchema = cyclicTasksSchema.element.shape;
|
|
485
|
-
|
|
479
|
+
// `planCodesys` callers pass deployments that no config schema has seen, so the planner checks
|
|
480
|
+
// each task against the raw ST schedule's rules, and the rules that need the program: CODESYS
|
|
481
|
+
// task names are identifiers, and each program runs in exactly one task.
|
|
486
482
|
function validateTasks(
|
|
487
483
|
core: VerifiedCoreModule,
|
|
488
484
|
deployment: Deployment,
|
|
489
485
|
report: Report,
|
|
490
486
|
): void {
|
|
487
|
+
const issues =
|
|
488
|
+
cyclicTasksSchema.safeParse(deployment.tasks).error?.issues ?? [];
|
|
489
|
+
const refused = (index: number, field: string) =>
|
|
490
|
+
issues.filter(({ path }) => path[0] === index && path[1] === field);
|
|
491
|
+
// zod skips the schema's own repeat check once any task has a type issue.
|
|
492
|
+
const repeats = scheduleRepeats(deployment.tasks);
|
|
493
|
+
const repeated = (task: number, position: number | null) =>
|
|
494
|
+
repeats.some((item) => item.task === task && item.position === position);
|
|
491
495
|
const programs = new Map(
|
|
492
496
|
core.programs.map((program) => [program.name, program]),
|
|
493
497
|
);
|
|
494
|
-
const assignment = new Map<string, string>();
|
|
495
|
-
const taskNames = new Set<string>();
|
|
496
498
|
const checkOwnership = taskStorageOwnership(core, report);
|
|
497
|
-
|
|
499
|
+
deployment.tasks.forEach((task, index) => {
|
|
498
500
|
if (!isIecIdentifier(task.name)) {
|
|
499
501
|
report(`Invalid task name ${task.name}.`);
|
|
500
502
|
}
|
|
501
|
-
if (
|
|
503
|
+
if (repeated(index, null)) {
|
|
502
504
|
report(`Duplicate task name ${task.name}.`);
|
|
503
505
|
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
506
|
+
if (refused(index, "priority").length) {
|
|
507
|
+
report(
|
|
508
|
+
`Task ${task.name} priority must be ${taskPriority.minValue}..${taskPriority.maxValue}.`,
|
|
509
|
+
);
|
|
507
510
|
}
|
|
508
|
-
const interval =
|
|
509
|
-
|
|
510
|
-
);
|
|
511
|
-
if (interval.error?.issues.some(({ code }) => code === "invalid_format")) {
|
|
511
|
+
const interval = refused(index, "intervalNanoseconds");
|
|
512
|
+
if (interval.some(({ code }) => code === "invalid_format")) {
|
|
512
513
|
report(`Invalid task interval for ${task.name}.`);
|
|
513
|
-
} else if (interval.
|
|
514
|
+
} else if (interval.length) {
|
|
514
515
|
report(
|
|
515
516
|
`Task ${task.name} requires an exact positive TIME interval in milliseconds.`,
|
|
516
517
|
);
|
|
517
518
|
}
|
|
518
|
-
if (
|
|
519
|
+
if (refused(index, "programs").some(({ path }) => path.length === 2)) {
|
|
519
520
|
report(`Task ${task.name} has no programs.`);
|
|
520
521
|
}
|
|
521
|
-
|
|
522
|
+
task.programs.forEach((name, position) => {
|
|
522
523
|
const program = programs.get(name);
|
|
523
524
|
if (!program) {
|
|
524
525
|
report(`Unknown task program ${name}.`);
|
|
525
|
-
|
|
526
|
+
return;
|
|
526
527
|
}
|
|
527
|
-
if (
|
|
528
|
+
if (repeated(index, position)) {
|
|
528
529
|
report(`Program ${name} must belong to exactly one task.`);
|
|
529
530
|
}
|
|
530
|
-
assignment.set(name, task.name);
|
|
531
531
|
checkOwnership(task.name, program);
|
|
532
|
-
}
|
|
533
|
-
}
|
|
532
|
+
});
|
|
533
|
+
});
|
|
534
|
+
const scheduled = new Set(deployment.tasks.flatMap((task) => task.programs));
|
|
534
535
|
for (const name of programs.keys()) {
|
|
535
|
-
if (!
|
|
536
|
+
if (!scheduled.has(name)) {
|
|
536
537
|
report(`Program ${name} has no cyclic task.`);
|
|
537
538
|
}
|
|
538
539
|
}
|
|
539
540
|
}
|
|
540
541
|
|
|
541
|
-
function
|
|
542
|
+
function validateProgramNames(
|
|
542
543
|
core: VerifiedCoreModule,
|
|
543
|
-
|
|
544
|
+
programNames: Readonly<Record<string, string>>,
|
|
544
545
|
report: Report,
|
|
545
546
|
): void {
|
|
546
|
-
const programs = new Map(
|
|
547
|
-
core.programs.map((program) => [program.name, program]),
|
|
548
|
-
);
|
|
549
547
|
if (core.blocks.some((block) => block.standard === "Blinker")) {
|
|
550
|
-
for (const target of Object.values(
|
|
548
|
+
for (const target of Object.values(programNames)) {
|
|
551
549
|
if (target.toUpperCase() === "UTIL") {
|
|
552
550
|
report(
|
|
553
551
|
`IEC object name ${target} shadows the Util library namespace required by Blinker.`,
|
|
@@ -555,8 +553,9 @@ function validateStorage(
|
|
|
555
553
|
}
|
|
556
554
|
}
|
|
557
555
|
}
|
|
556
|
+
const programs = new Set(core.programs.map((program) => program.name));
|
|
558
557
|
const explicitNames = new Set<string>();
|
|
559
|
-
for (const [name, target] of Object.entries(
|
|
558
|
+
for (const [name, target] of Object.entries(programNames)) {
|
|
560
559
|
if (!programs.has(name)) {
|
|
561
560
|
report(`Unknown program name override ${name}.`);
|
|
562
561
|
}
|
|
@@ -565,12 +564,16 @@ function validateStorage(
|
|
|
565
564
|
}
|
|
566
565
|
explicitNames.add(target.toUpperCase());
|
|
567
566
|
}
|
|
568
|
-
|
|
569
|
-
const blocks = new Map(core.blocks.map((block) => [block.id, block]));
|
|
567
|
+
}
|
|
570
568
|
|
|
571
|
-
|
|
569
|
+
/**
|
|
570
|
+
* InOut addresses must not survive a retained restart, including nested children. CODESYS accepts
|
|
571
|
+
* one persistent variable list in an application, so only one module's storage may persist.
|
|
572
|
+
*/
|
|
573
|
+
function validateRetain(core: VerifiedCoreModule, report: Report): void {
|
|
574
|
+
const { types, blockOf } = coreTables(core);
|
|
572
575
|
const blockHasInOut = (id: string): boolean => {
|
|
573
|
-
const block =
|
|
576
|
+
const block = blockOf(id);
|
|
574
577
|
return (
|
|
575
578
|
block.inputs.some((input) => input.mode === "inOut") ||
|
|
576
579
|
block.state.some((field) => {
|
|
@@ -591,19 +594,28 @@ function validateStorage(
|
|
|
591
594
|
}
|
|
592
595
|
for (const variable of core.variables) {
|
|
593
596
|
const type = instancedBlock(variable.type, types);
|
|
594
|
-
if (variable.
|
|
597
|
+
if (variable.retention !== "none" && type && blockHasInOut(type.block)) {
|
|
595
598
|
report(
|
|
596
599
|
"Retained function blocks cannot contain direct or nested InOut references.",
|
|
597
600
|
variable.span,
|
|
598
601
|
);
|
|
599
602
|
}
|
|
600
603
|
}
|
|
604
|
+
const [, ...others] = layout.globalLists.filter(
|
|
605
|
+
(list) => list.kind === "persistent",
|
|
606
|
+
);
|
|
607
|
+
for (const list of others) {
|
|
608
|
+
report(
|
|
609
|
+
"CODESYS keeps one persistent variable list per application: persist the storage of one module only.",
|
|
610
|
+
list.variables[0]?.span,
|
|
611
|
+
);
|
|
612
|
+
}
|
|
601
613
|
}
|
|
602
614
|
|
|
603
615
|
function validateConstants(core: VerifiedCoreModule, report: Report): void {
|
|
604
|
-
const
|
|
616
|
+
const { typeOf } = coreTables(core);
|
|
605
617
|
const constant = (value: Constant, id: string, span?: SourceSpan): void => {
|
|
606
|
-
const type =
|
|
618
|
+
const type = typeOf(id);
|
|
607
619
|
if (type.kind === "string" && value.kind === "string") {
|
|
608
620
|
if (
|
|
609
621
|
type.encoding === "utf8" &&
|
|
@@ -631,7 +643,7 @@ function validateConstants(core: VerifiedCoreModule, report: Report): void {
|
|
|
631
643
|
}
|
|
632
644
|
if (type.kind === "record" && value.kind === "record") {
|
|
633
645
|
for (const field of type.fields) {
|
|
634
|
-
constant(value.fields[field.name]
|
|
646
|
+
constant(required(value.fields[field.name]), field.type, span);
|
|
635
647
|
}
|
|
636
648
|
}
|
|
637
649
|
};
|