@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/types.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import type { Constant, GeneratedObject, PlcType } from "@tsplc/compiler/ir";
|
|
2
|
-
import { instancedBlock
|
|
2
|
+
import { instancedBlock } from "@tsplc/compiler/ir";
|
|
3
|
+
import {
|
|
4
|
+
arrayTypeText,
|
|
5
|
+
nanosecondsPerMillisecond,
|
|
6
|
+
stringTypeText,
|
|
7
|
+
} from "@tsplc/iec";
|
|
3
8
|
import { escapeString } from "@tsplc/iec/st";
|
|
4
9
|
import { Names } from "./names";
|
|
5
10
|
import { scalarLiteral } from "./numeric";
|
|
11
|
+
import { required } from "./required";
|
|
6
12
|
|
|
7
13
|
/** A type's name as its source declares it: the last segment of its id. */
|
|
8
14
|
export const sourceTypeName = (id: string) => id.slice(id.lastIndexOf(":") + 1);
|
|
@@ -24,74 +30,69 @@ const stEscapes: ReadonlyMap<string, string> = new Map([
|
|
|
24
30
|
export const stStringLiteral = (text: string) =>
|
|
25
31
|
`'${[...text].map((character) => stEscapes.get(character) ?? character).join("")}'`;
|
|
26
32
|
|
|
27
|
-
/**
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
/** The text of a string or array type: `STRING(n)`, or `ARRAY[l..u] OF T` of its element's name. */
|
|
34
|
+
const typeText = (
|
|
35
|
+
type: Extract<PlcType, { kind: "string" | "array" }>,
|
|
36
|
+
element: (id: string) => string,
|
|
37
|
+
) =>
|
|
38
|
+
type.kind === "string"
|
|
39
|
+
? stringTypeText({
|
|
40
|
+
wide: type.encoding !== "utf8",
|
|
41
|
+
capacity: type.capacity,
|
|
42
|
+
})
|
|
43
|
+
: arrayTypeText({
|
|
44
|
+
lower: type.lowerBound,
|
|
45
|
+
upper: type.lowerBound + type.length - 1,
|
|
46
|
+
element: element(type.element),
|
|
47
|
+
});
|
|
36
48
|
|
|
37
49
|
export class CodesysTypes {
|
|
38
50
|
readonly objects: GeneratedObject[] = [];
|
|
39
51
|
private readonly names = new Map<string, string>();
|
|
40
52
|
private readonly fields = new Map<string, Map<string, string>>();
|
|
41
|
-
/** Anonymous record types declared by an identical one's DUT. */
|
|
42
|
-
private readonly aliases = new Set<string>();
|
|
43
|
-
private readonly shapes = new Map<string, string | null>();
|
|
44
53
|
|
|
45
54
|
constructor(
|
|
46
55
|
private readonly types: ReadonlyMap<string, PlcType>,
|
|
47
56
|
names: Names,
|
|
48
57
|
blockNames: ReadonlyMap<string, string>,
|
|
49
58
|
) {
|
|
50
|
-
// Register every type and member name before following layout dependencies.
|
|
51
|
-
// record types with the same fields share one DUT: an elaborated program states such a
|
|
52
|
-
// type once per instance.
|
|
53
|
-
const anonymous = new Map<string, string>();
|
|
59
|
+
// Register every type and member name before following layout dependencies.
|
|
54
60
|
for (const type of types.values()) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
if (shape !== null) {
|
|
64
|
-
anonymous.set(shape, type.id);
|
|
65
|
-
}
|
|
66
|
-
if (type.kind === "block") {
|
|
67
|
-
const name = blockNames.get(type.block);
|
|
68
|
-
if (!name) {
|
|
69
|
-
throw new Error("Missing verified block name");
|
|
70
|
-
}
|
|
71
|
-
this.names.set(type.id, name);
|
|
72
|
-
}
|
|
73
|
-
if (["record", "array", "enum", "string"].includes(type.kind)) {
|
|
74
|
-
const label = sourceTypeName(type.id);
|
|
75
|
-
if (type.kind === "record" || type.kind === "enum") {
|
|
61
|
+
switch (type.kind) {
|
|
62
|
+
case "block":
|
|
63
|
+
this.names.set(type.id, required(blockNames.get(type.block)));
|
|
64
|
+
break;
|
|
65
|
+
case "record":
|
|
66
|
+
case "enum": {
|
|
76
67
|
const prefix = type.kind === "record" ? "ST" : "E";
|
|
77
|
-
this.names.set(
|
|
78
|
-
|
|
79
|
-
|
|
68
|
+
this.names.set(
|
|
69
|
+
type.id,
|
|
70
|
+
names.allocateObject(prefix, sourceTypeName(type.id)),
|
|
71
|
+
);
|
|
72
|
+
const members = new Names();
|
|
73
|
+
this.fields.set(
|
|
74
|
+
type.id,
|
|
75
|
+
new Map(
|
|
76
|
+
(type.kind === "record" ? type.fields : type.members).map(
|
|
77
|
+
(member) => [member.name, members.allocate(member.name)],
|
|
78
|
+
),
|
|
79
|
+
),
|
|
80
|
+
);
|
|
81
|
+
break;
|
|
80
82
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
this.fields.set(type.id, fields);
|
|
83
|
+
case "array":
|
|
84
|
+
case "string":
|
|
85
|
+
if (!this.inline(type)) {
|
|
86
|
+
this.names.set(
|
|
87
|
+
type.id,
|
|
88
|
+
names.allocate(`T_${sourceTypeName(type.id)}`),
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
break;
|
|
91
92
|
}
|
|
92
93
|
}
|
|
93
94
|
|
|
94
|
-
// Verified layouts are acyclic.
|
|
95
|
+
// Verified layouts are acyclic.
|
|
95
96
|
const emitted = new Set<string>();
|
|
96
97
|
const emit = (type: PlcType): void => {
|
|
97
98
|
if (type.kind === "array" && this.inline(type)) {
|
|
@@ -101,7 +102,6 @@ export class CodesysTypes {
|
|
|
101
102
|
if (
|
|
102
103
|
instancedBlock(type.id, types) ||
|
|
103
104
|
!this.names.has(type.id) ||
|
|
104
|
-
this.aliases.has(type.id) ||
|
|
105
105
|
emitted.has(type.id)
|
|
106
106
|
) {
|
|
107
107
|
return;
|
|
@@ -124,29 +124,6 @@ export class CodesysTypes {
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
/**
|
|
128
|
-
* A type literal's structure, which identifies it among anonymous record types, or null for
|
|
129
|
-
* a named or non-record type. Field types are compared by their own shape, so nested literals
|
|
130
|
-
* that match share too.
|
|
131
|
-
*/
|
|
132
|
-
private anonymousShape(type: PlcType): string | null {
|
|
133
|
-
if (type.kind !== "record" || !anonymousRecordId.test(type.id)) {
|
|
134
|
-
return null;
|
|
135
|
-
}
|
|
136
|
-
const known = this.shapes.get(type.id);
|
|
137
|
-
if (known !== undefined) {
|
|
138
|
-
return known;
|
|
139
|
-
}
|
|
140
|
-
const shape = JSON.stringify(
|
|
141
|
-
type.fields.map((field) => [
|
|
142
|
-
field.name,
|
|
143
|
-
this.anonymousShape(this.type(field.type)) ?? field.type,
|
|
144
|
-
]),
|
|
145
|
-
);
|
|
146
|
-
this.shapes.set(type.id, shape);
|
|
147
|
-
return shape;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
127
|
/** The declaration of a data type's DUT. */
|
|
151
128
|
private dutDeclaration(type: PlcType, name: string): string {
|
|
152
129
|
if (type.kind === "record") {
|
|
@@ -165,12 +142,12 @@ END_TYPE
|
|
|
165
142
|
}
|
|
166
143
|
if (type.kind === "array") {
|
|
167
144
|
// Typegen publishes each key of a `Record<Enum, T>` as its own contract variable.
|
|
168
|
-
return `${type.index ? "{attribute 'tsplc_keyed'}\n" : ""}TYPE ${name} :
|
|
145
|
+
return `${type.index ? "{attribute 'tsplc_keyed'}\n" : ""}TYPE ${name} : ${typeText(type, (id) => this.name(id))};
|
|
169
146
|
END_TYPE
|
|
170
147
|
`;
|
|
171
148
|
}
|
|
172
149
|
if (type.kind === "string") {
|
|
173
|
-
return `TYPE ${name} : ${
|
|
150
|
+
return `TYPE ${name} : ${typeText(type, (id) => this.name(id))};
|
|
174
151
|
END_TYPE
|
|
175
152
|
`;
|
|
176
153
|
}
|
|
@@ -193,11 +170,7 @@ END_TYPE
|
|
|
193
170
|
}
|
|
194
171
|
|
|
195
172
|
private type(id: string): PlcType {
|
|
196
|
-
|
|
197
|
-
if (!type) {
|
|
198
|
-
throw new Error("Missing verified type");
|
|
199
|
-
}
|
|
200
|
-
return type;
|
|
173
|
+
return required(this.types.get(id));
|
|
201
174
|
}
|
|
202
175
|
|
|
203
176
|
name(id: string): string {
|
|
@@ -206,11 +179,11 @@ END_TYPE
|
|
|
206
179
|
return named;
|
|
207
180
|
}
|
|
208
181
|
const type = this.types.get(id);
|
|
209
|
-
if (
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
return
|
|
182
|
+
if (
|
|
183
|
+
(type?.kind === "string" || type?.kind === "array") &&
|
|
184
|
+
this.inline(type)
|
|
185
|
+
) {
|
|
186
|
+
return typeText(type, (element) => this.name(element));
|
|
214
187
|
}
|
|
215
188
|
return id;
|
|
216
189
|
}
|
|
@@ -233,11 +206,7 @@ END_TYPE
|
|
|
233
206
|
}
|
|
234
207
|
|
|
235
208
|
field(id: string, name: string): string {
|
|
236
|
-
|
|
237
|
-
if (!field) {
|
|
238
|
-
throw new Error("Missing verified field");
|
|
239
|
-
}
|
|
240
|
-
return field;
|
|
209
|
+
return required(this.fields.get(id)?.get(name));
|
|
241
210
|
}
|
|
242
211
|
|
|
243
212
|
declarationInitializer(value: Constant, id: string): string {
|
|
@@ -269,10 +238,7 @@ END_TYPE
|
|
|
269
238
|
return this.literal(value, id);
|
|
270
239
|
}
|
|
271
240
|
const fields = type.fields.flatMap((field) => {
|
|
272
|
-
const initial = value.fields[field.name];
|
|
273
|
-
if (!initial) {
|
|
274
|
-
throw new Error("Missing verified record initializer");
|
|
275
|
-
}
|
|
241
|
+
const initial = required(value.fields[field.name]);
|
|
276
242
|
return this.type(field.type).kind !== "enum" && this.isZero(initial)
|
|
277
243
|
? []
|
|
278
244
|
: [
|
|
@@ -308,12 +274,9 @@ END_TYPE
|
|
|
308
274
|
literal(value: Constant, id: string): string {
|
|
309
275
|
const type = this.type(id);
|
|
310
276
|
if (type.kind === "enum" && value.kind === "integer") {
|
|
311
|
-
const member =
|
|
312
|
-
(member) => member.value === value.value,
|
|
277
|
+
const member = required(
|
|
278
|
+
type.members.find((member) => member.value === value.value),
|
|
313
279
|
);
|
|
314
|
-
if (!member) {
|
|
315
|
-
throw new Error("Missing verified enum member");
|
|
316
|
-
}
|
|
317
280
|
return `${this.name(id)}.${this.field(id, member.name)}`;
|
|
318
281
|
}
|
|
319
282
|
if (type.kind === "string" && value.kind === "string") {
|
|
@@ -324,13 +287,10 @@ END_TYPE
|
|
|
324
287
|
return `[${value.items.map((item) => this.literal(item, type.element)).join(", ")}]`;
|
|
325
288
|
}
|
|
326
289
|
if (type.kind === "record" && value.kind === "record") {
|
|
327
|
-
const fields = type.fields.map(
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
}
|
|
332
|
-
return `${this.field(id, field.name)} := ${this.literal(initial, field.type)}`;
|
|
333
|
-
});
|
|
290
|
+
const fields = type.fields.map(
|
|
291
|
+
(field) =>
|
|
292
|
+
`${this.field(id, field.name)} := ${this.literal(required(value.fields[field.name]), field.type)}`,
|
|
293
|
+
);
|
|
334
294
|
return `(${fields.join(", ")})`;
|
|
335
295
|
}
|
|
336
296
|
if (type.kind === "duration" && value.kind === "duration") {
|
package/src/codesys/vendor.ts
CHANGED
|
@@ -1,28 +1,8 @@
|
|
|
1
1
|
import { CodesysCompilerError } from "@tsplc/build";
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
EmitResult,
|
|
5
|
-
GeneratedObject,
|
|
6
|
-
} from "@tsplc/compiler/ir";
|
|
7
|
-
import type { SourceMapping } from "./emit";
|
|
8
|
-
import { declarationFile } from "./st-files";
|
|
2
|
+
import type { Diagnostic } from "@tsplc/compiler/ir";
|
|
3
|
+
import type { CodesysBundle } from "./emit";
|
|
9
4
|
|
|
10
|
-
type MappedBundle = Pick<
|
|
11
|
-
mappings: readonly SourceMapping[];
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
/** The generated file a vendor location is in: its object's declaration, or its implementation when it has one. */
|
|
15
|
-
const sectionFile = (
|
|
16
|
-
match: { object: GeneratedObject; declaration: string } | undefined,
|
|
17
|
-
section: "declaration" | "implementation",
|
|
18
|
-
): string | undefined => {
|
|
19
|
-
if (section === "declaration") {
|
|
20
|
-
return match?.declaration;
|
|
21
|
-
}
|
|
22
|
-
return match?.object.implementation === undefined
|
|
23
|
-
? undefined
|
|
24
|
-
: match.declaration.replace(/declaration\.st$/, "implementation.st");
|
|
25
|
-
};
|
|
5
|
+
type MappedBundle = Pick<CodesysBundle, "objects" | "mappings">;
|
|
26
6
|
|
|
27
7
|
/** An object's path below the Application, when the vendor's identity of it proves one. */
|
|
28
8
|
const applicationObjectPath = (
|
|
@@ -33,9 +13,7 @@ const applicationObjectPath = (
|
|
|
33
13
|
}
|
|
34
14
|
const relative = identity.applicationPath;
|
|
35
15
|
if (
|
|
36
|
-
|
|
37
|
-
relative.length > 0 &&
|
|
38
|
-
relative.every((part) => typeof part === "string") &&
|
|
16
|
+
relative?.length &&
|
|
39
17
|
identity.isApplicationChild === (relative.length === 1) &&
|
|
40
18
|
identity.path.length > relative.length &&
|
|
41
19
|
identity.path
|
|
@@ -49,7 +27,6 @@ const applicationObjectPath = (
|
|
|
49
27
|
identity.isApplicationChild === true &&
|
|
50
28
|
identity.path.length >= 2
|
|
51
29
|
) {
|
|
52
|
-
// A verified immediate Application parent proves the root identity.
|
|
53
30
|
return identity.name;
|
|
54
31
|
}
|
|
55
32
|
return undefined;
|
|
@@ -74,31 +51,17 @@ export function diagnoseCodesys(
|
|
|
74
51
|
const identity = item.object;
|
|
75
52
|
const objectPath = identity && applicationObjectPath(identity);
|
|
76
53
|
const objects = objectPath
|
|
77
|
-
? bundle.objects.
|
|
78
|
-
|
|
79
|
-
object.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
? declaration.replace(
|
|
83
|
-
/\/methods\/([^/]+\/declaration\.st)$/,
|
|
84
|
-
"/$1",
|
|
85
|
-
)
|
|
86
|
-
: declaration
|
|
87
|
-
).replace(
|
|
88
|
-
object.implementation === undefined
|
|
89
|
-
? /\.st$/
|
|
90
|
-
: /\/declaration\.st$/,
|
|
91
|
-
"",
|
|
92
|
-
);
|
|
93
|
-
return object.name === identity?.name && nativePath === objectPath
|
|
94
|
-
? [{ object, declaration }]
|
|
95
|
-
: [];
|
|
96
|
-
})
|
|
54
|
+
? bundle.objects.filter(
|
|
55
|
+
(object) =>
|
|
56
|
+
object.name === identity?.name &&
|
|
57
|
+
object.nativePath === objectPath,
|
|
58
|
+
)
|
|
97
59
|
: [];
|
|
98
60
|
const match = objects.length === 1 ? objects[0] : undefined;
|
|
99
|
-
const
|
|
100
|
-
location?.[3] === "Decl"
|
|
101
|
-
|
|
61
|
+
const path =
|
|
62
|
+
location?.[3] === "Decl"
|
|
63
|
+
? match?.sourcePath
|
|
64
|
+
: match?.implementationPath;
|
|
102
65
|
const mappings =
|
|
103
66
|
location && path
|
|
104
67
|
? bundle.mappings.filter(
|