@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/programs.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
coreTables,
|
|
3
|
+
type GeneratedObject,
|
|
4
|
+
type PlcProgram,
|
|
5
|
+
type Task,
|
|
6
|
+
} from "@tsplc/compiler/ir";
|
|
2
7
|
import type { IoChannel } from "./global-lists";
|
|
8
|
+
import { scanClock } from "./numeric";
|
|
3
9
|
import type { CodesysPlan } from "./plan";
|
|
4
|
-
import {
|
|
10
|
+
import { required } from "./required";
|
|
11
|
+
import { noResult } from "./statements";
|
|
12
|
+
import type { EmissionContext } from "./symbols";
|
|
5
13
|
import { accessedStorage } from "./task-access";
|
|
6
14
|
|
|
7
15
|
/** The PROGRAM a task calls for a program: its IO scan around a call of the authored routine. */
|
|
@@ -10,29 +18,28 @@ export function emitScanProgram(
|
|
|
10
18
|
ioChannels: readonly IoChannel[],
|
|
11
19
|
program: PlcProgram,
|
|
12
20
|
): GeneratedObject {
|
|
13
|
-
const { core
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const name = explicit ?? names.allocateObject("PRG", program.name);
|
|
22
|
-
const fn = required(core.functions.find((item) => item.id === program.entry));
|
|
23
|
-
const used = accessedStorage(fn, core);
|
|
21
|
+
const { core } = plan;
|
|
22
|
+
const name =
|
|
23
|
+
plan.programNames.get(program.name) ??
|
|
24
|
+
symbols.names.allocateObject("PRG", program.name);
|
|
25
|
+
const used = accessedStorage(
|
|
26
|
+
coreTables(core).functionOf(program.entry),
|
|
27
|
+
core,
|
|
28
|
+
);
|
|
24
29
|
const channels = ioChannels.filter((channel) => used.has(channel.root));
|
|
25
30
|
const stateful = symbols.programRoutines.has(program.entry);
|
|
26
|
-
const call = `${functionNames.get(program.entry)}();`;
|
|
31
|
+
const call = `${required(symbols.functionNames.get(program.entry))}();`;
|
|
27
32
|
// The first program of a task with a ring runs its sender first, which counts the scan and reads the clock.
|
|
28
33
|
const task = plan.deployment.tasks.find(
|
|
29
34
|
(item) => item.programs[0] === program.name,
|
|
30
35
|
);
|
|
31
36
|
const ring = task && instrumentation.rings.get(task.name);
|
|
32
37
|
const clock = task && instrumentation.scanClocks.get(task.name);
|
|
38
|
+
// The scan snapshots physical inputs before the authored routine and commits outputs
|
|
39
|
+
// afterwards. RETURN in an authored routine cannot skip that epilogue.
|
|
33
40
|
const lines = [
|
|
34
41
|
...(ring ? [`${instrumentation.global}.${ring}();`] : []),
|
|
35
|
-
...(clock ? [`${clock} :=
|
|
42
|
+
...(clock ? [`${instrumentation.global}.${clock} := ${scanClock};`] : []),
|
|
36
43
|
...channels
|
|
37
44
|
.filter((channel) => channel.input)
|
|
38
45
|
.map(
|
|
@@ -50,7 +57,7 @@ export function emitScanProgram(
|
|
|
50
57
|
name,
|
|
51
58
|
declaration: stateful
|
|
52
59
|
? `PROGRAM ${name}\n`
|
|
53
|
-
: `PROGRAM ${name}\nVAR\n plc_discard :
|
|
60
|
+
: `PROGRAM ${name}\nVAR\n plc_discard : ${noResult.type};\nEND_VAR\n`,
|
|
54
61
|
implementation: `${lines.join("\n")}\n`,
|
|
55
62
|
};
|
|
56
63
|
}
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import type
|
|
2
|
-
EmitResult,
|
|
3
|
-
PlcType,
|
|
4
|
-
VerifiedCoreModule,
|
|
5
|
-
} from "@tsplc/compiler/ir";
|
|
1
|
+
import { isLogicalIo, type VerifiedCoreModule } from "@tsplc/compiler/ir";
|
|
6
2
|
import type { Publication } from "@tsplc/config";
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
import { type CodesysSymbols, required } from "./symbols";
|
|
3
|
+
import type { ServiceChannel } from "@tsplc/server/wire";
|
|
4
|
+
import { required } from "./required";
|
|
5
|
+
import { moduleFile, moduleName, storagePath } from "./storage";
|
|
6
|
+
import type { EmissionContext } from "./symbols";
|
|
12
7
|
|
|
13
8
|
const globals = (core: VerifiedCoreModule) =>
|
|
14
9
|
core.variables.filter(
|
|
@@ -22,7 +17,7 @@ export const publicationSelectors = (core: VerifiedCoreModule): string[] => {
|
|
|
22
17
|
...new Set(
|
|
23
18
|
variables.flatMap((variable) => [
|
|
24
19
|
moduleName(variable),
|
|
25
|
-
|
|
20
|
+
storagePath(variable),
|
|
26
21
|
]),
|
|
27
22
|
),
|
|
28
23
|
].sort();
|
|
@@ -35,11 +30,7 @@ export const resolvePublication = (
|
|
|
35
30
|
const variables = globals(core);
|
|
36
31
|
const errors: string[] = [];
|
|
37
32
|
const select = (selectors: readonly string[]) => {
|
|
38
|
-
const selected = new Set(
|
|
39
|
-
variables
|
|
40
|
-
.filter((variable) => variable.exposure)
|
|
41
|
-
.map((variable) => variable.id),
|
|
42
|
-
);
|
|
33
|
+
const selected = new Set<string>();
|
|
43
34
|
const seen = new Set<string>();
|
|
44
35
|
for (const selector of selectors) {
|
|
45
36
|
if (seen.has(selector)) {
|
|
@@ -49,15 +40,15 @@ export const resolvePublication = (
|
|
|
49
40
|
const candidates = variables.filter(
|
|
50
41
|
(variable) =>
|
|
51
42
|
selector === moduleName(variable) ||
|
|
52
|
-
selector ===
|
|
43
|
+
selector === storagePath(variable),
|
|
53
44
|
);
|
|
54
45
|
if (!candidates.length) {
|
|
55
46
|
errors.push(
|
|
56
|
-
`Unknown publication selector ${selector}; select an exported
|
|
47
|
+
`Unknown publication selector ${selector}; select an exported state root or a field of one, such as counter or counter.total.`,
|
|
57
48
|
);
|
|
58
49
|
continue;
|
|
59
50
|
}
|
|
60
|
-
if (new Set(candidates.map(moduleFile)).size !== 1) {
|
|
51
|
+
if (new Set(candidates.map(({ id }) => moduleFile(id))).size !== 1) {
|
|
61
52
|
errors.push(`Ambiguous publication selector ${selector}.`);
|
|
62
53
|
continue;
|
|
63
54
|
}
|
|
@@ -78,15 +69,11 @@ export const resolvePublication = (
|
|
|
78
69
|
|
|
79
70
|
/** The global symbols a build publishes for each target: its selected storage, logical IO and service channels. */
|
|
80
71
|
export const publishedSymbols = (
|
|
81
|
-
plan:
|
|
82
|
-
|
|
83
|
-
rpcChannels: readonly RpcChannel[],
|
|
72
|
+
{ plan, symbols }: EmissionContext,
|
|
73
|
+
rpcChannels: readonly ServiceChannel[],
|
|
84
74
|
): Publication => {
|
|
85
75
|
const logicalIo = plan.core.variables
|
|
86
|
-
.filter(
|
|
87
|
-
(variable) =>
|
|
88
|
-
variable.storage === "input" || variable.storage === "output",
|
|
89
|
-
)
|
|
76
|
+
.filter(isLogicalIo)
|
|
90
77
|
.map((variable) => variable.id);
|
|
91
78
|
const rpcSymbols = [
|
|
92
79
|
...new Set(
|
|
@@ -110,63 +97,3 @@ export const publishedSymbols = (
|
|
|
110
97
|
development: published(plan.publication.development),
|
|
111
98
|
};
|
|
112
99
|
};
|
|
113
|
-
|
|
114
|
-
/** The JavaScript type an exposed field is read as. */
|
|
115
|
-
const telemetryKind = (type: PlcType | undefined) => {
|
|
116
|
-
if (type?.kind === "bool") {
|
|
117
|
-
return "boolean";
|
|
118
|
-
}
|
|
119
|
-
return type?.kind === "string" ? "string" : "number";
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
/** `exposures.json` and `machines.ts`: the read-only interface of each exposed machine, and the service channels. */
|
|
123
|
-
export const machineInterfaces = (
|
|
124
|
-
{ core }: CodesysPlan,
|
|
125
|
-
symbols: CodesysSymbols,
|
|
126
|
-
rpcChannels: readonly RpcChannel[],
|
|
127
|
-
): EmitResult["artifacts"] => {
|
|
128
|
-
const exposures = Object.fromEntries(
|
|
129
|
-
core.variables.flatMap((variable) => {
|
|
130
|
-
const { exposure } = variable;
|
|
131
|
-
if (!exposure) {
|
|
132
|
-
return [];
|
|
133
|
-
}
|
|
134
|
-
const record = symbols.typeMap.get(variable.type);
|
|
135
|
-
if (record?.kind !== "record") {
|
|
136
|
-
throw new Error("Invalid exposure record.");
|
|
137
|
-
}
|
|
138
|
-
const root = required(symbols.references.get(variable.id));
|
|
139
|
-
const fields = Object.fromEntries(
|
|
140
|
-
record.fields
|
|
141
|
-
.filter((field) => field.name !== "contractVersion")
|
|
142
|
-
.map((field) => [
|
|
143
|
-
field.name,
|
|
144
|
-
{
|
|
145
|
-
path: `${root}.${symbols.targetTypes.field(record.id, field.name)}`,
|
|
146
|
-
kind: telemetryKind(symbols.typeMap.get(field.type)),
|
|
147
|
-
},
|
|
148
|
-
]),
|
|
149
|
-
);
|
|
150
|
-
return [
|
|
151
|
-
[
|
|
152
|
-
exposure.name,
|
|
153
|
-
{
|
|
154
|
-
version: exposure.version,
|
|
155
|
-
versionPath: `${root}.${symbols.targetTypes.field(record.id, "contractVersion")}`,
|
|
156
|
-
telemetry: fields,
|
|
157
|
-
},
|
|
158
|
-
],
|
|
159
|
-
];
|
|
160
|
-
}),
|
|
161
|
-
);
|
|
162
|
-
return [
|
|
163
|
-
{
|
|
164
|
-
path: "exposures.json",
|
|
165
|
-
content: `${JSON.stringify(exposures, null, 2)}\n`,
|
|
166
|
-
},
|
|
167
|
-
{
|
|
168
|
-
path: emittedFiles.machines,
|
|
169
|
-
content: `// Generated explicit read-only machine interfaces. Do not edit.\nexport const machines=${JSON.stringify(exposures, null, 2)} as const;\nexport const serviceChannels=${JSON.stringify(rpcChannels, null, 2)} as const;\n`,
|
|
170
|
-
},
|
|
171
|
-
];
|
|
172
|
-
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// All symbol relationships were checked by normalization and planning. Failure
|
|
2
|
+
// here is an emitter invariant violation, rather than a recoverable source error.
|
|
3
|
+
export function required<T>(value: T | undefined): T {
|
|
4
|
+
if (value === undefined) {
|
|
5
|
+
throw new Error("Missing verified CODESYS symbol.");
|
|
6
|
+
}
|
|
7
|
+
return value;
|
|
8
|
+
}
|