@tsplc/compiler 0.2.16 → 0.2.18
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 +2 -2
- package/dist/cli.js +920 -943
- package/dist/cli.js.map +13 -10
- package/dist/codesys.js +3893 -3352
- package/dist/codesys.js.map +29 -20
- package/dist/elaborate-capture.js +33 -17
- package/dist/elaborate-capture.js.map +3 -3
- package/dist/index.js +8787 -6855
- package/dist/index.js.map +40 -20
- package/dist/ir.js +1575 -1072
- package/dist/ir.js.map +21 -17
- package/dist/math.js.map +2 -2
- package/dist/project.js +154 -60
- package/dist/project.js.map +5 -5
- package/dist/telemetry.js +27 -9
- package/dist/telemetry.js.map +5 -5
- package/package.json +112 -112
- package/src/codesys/config.ts +50 -0
- package/src/codesys/debug.ts +670 -0
- package/src/codesys/emit.ts +142 -0
- package/src/codesys/engineering.ts +109 -0
- package/src/codesys/expressions.ts +92 -0
- package/src/codesys/global-lists.ts +250 -0
- package/src/codesys/global-names.ts +68 -0
- package/src/codesys/http.ts +890 -0
- package/src/codesys/index.ts +30 -0
- package/src/codesys/instrumentation.ts +430 -0
- package/src/codesys/io-paths.ts +140 -0
- package/src/codesys/manifest.ts +643 -0
- package/src/codesys/names.ts +81 -0
- package/src/codesys/numeric.ts +409 -0
- package/src/codesys/operands.ts +62 -0
- package/src/codesys/plan.ts +605 -0
- package/src/codesys/programs.ts +53 -0
- package/src/codesys/publication.ts +171 -0
- package/src/codesys/routines.ts +603 -0
- package/src/codesys/sources.ts +71 -0
- package/src/codesys/st-files.ts +115 -0
- package/src/codesys/storage.ts +97 -0
- package/src/codesys/symbols.ts +220 -0
- package/src/codesys/task-access.ts +320 -0
- package/src/codesys/telemetry.ts +732 -0
- package/src/codesys/types.ts +250 -0
- package/src/codesys/vendor.ts +150 -0
- package/src/frontend/analyzer.ts +794 -0
- package/src/frontend/async.ts +317 -1137
- package/src/frontend/blocks.ts +537 -403
- package/src/frontend/configuration.ts +176 -144
- package/src/frontend/const-functions.ts +183 -148
- package/src/frontend/cooperative.ts +73 -43
- package/src/frontend/coroutines.ts +1032 -0
- package/src/frontend/elaborate/calls.ts +535 -0
- package/src/frontend/elaborate/capture.ts +157 -101
- package/src/frontend/elaborate/dialect.ts +257 -0
- package/src/frontend/elaborate/expressions.ts +992 -0
- package/src/frontend/elaborate/frame.ts +53 -0
- package/src/frontend/elaborate/graph.ts +116 -71
- package/src/frontend/elaborate/imports.ts +70 -0
- package/src/frontend/elaborate/index.ts +435 -331
- package/src/frontend/elaborate/initializers.ts +198 -0
- package/src/frontend/elaborate/layouts.ts +591 -384
- package/src/frontend/elaborate/model.ts +264 -169
- package/src/frontend/elaborate/specialize.ts +343 -2586
- package/src/frontend/elaborate/statements.ts +606 -0
- package/src/frontend/elaborate/storage.ts +546 -0
- package/src/frontend/elaborate/values.ts +58 -0
- package/src/frontend/elaborate/writes.ts +100 -0
- package/src/frontend/exposure.ts +172 -140
- package/src/frontend/expressions.ts +1383 -0
- package/src/frontend/intrinsics.ts +337 -0
- package/src/frontend/module-graph.ts +89 -59
- package/src/frontend/positions.ts +271 -200
- package/src/frontend/promise-chains.ts +897 -0
- package/src/frontend/promises.ts +390 -747
- package/src/frontend/routines.ts +181 -0
- package/src/frontend/sdk.ts +82 -0
- package/src/frontend/services.ts +506 -372
- package/src/frontend/statements.ts +855 -0
- package/src/frontend/tasks.ts +471 -0
- package/src/frontend/telemetry.ts +174 -0
- package/src/frontend/types.ts +845 -551
- package/src/frontend/typescript.ts +323 -2543
- package/src/index.ts +5 -5
- package/src/ir/aggregates.ts +275 -0
- package/src/ir/allocation.ts +84 -0
- package/src/ir/core-model.ts +146 -0
- package/src/ir/declarations.ts +295 -0
- package/src/ir/diagnostics.ts +61 -0
- package/src/ir/domains.ts +152 -0
- package/src/ir/fold.ts +342 -0
- package/src/ir/index.ts +90 -0
- package/{ir/errors.ts → src/ir/job-errors.ts} +12 -10
- package/src/ir/layouts.ts +181 -0
- package/src/ir/link.ts +354 -0
- package/src/ir/model.ts +386 -0
- package/{ir → src/ir}/normalization-error.ts +4 -4
- package/src/ir/normalize.ts +70 -0
- package/src/ir/numeric.ts +171 -0
- package/src/ir/ranges.ts +256 -0
- package/src/ir/routine.ts +1163 -0
- package/src/ir/scalars.ts +321 -0
- package/src/ir/types.ts +127 -0
- package/src/project/artifacts.ts +342 -0
- package/src/project/cli.ts +177 -0
- package/src/project/debugger.ts +82 -0
- package/src/project/index.ts +6 -0
- package/src/project/plant.ts +467 -0
- package/src/project/project-commands.ts +372 -0
- package/src/project/project.ts +457 -0
- package/src/project/release.ts +153 -0
- package/src/project/server.ts +150 -0
- package/src/project/terminal.ts +32 -0
- package/stdlib/math.ts +14 -10
- package/stdlib/telemetry.ts +71 -47
- package/types/async.d.ts +46 -40
- package/types/data-types.d.ts +26 -26
- package/types/globals.d.ts +41 -38
- package/types/index.d.ts +96 -51
- package/types/plc.d.ts +3 -4
- package/types/telemetry.d.ts +14 -14
- package/backends/codesys/config.ts +0 -54
- package/backends/codesys/debug.ts +0 -509
- package/backends/codesys/emit.ts +0 -1738
- package/backends/codesys/engineering.ts +0 -88
- package/backends/codesys/global-names.ts +0 -49
- package/backends/codesys/http.ts +0 -675
- package/backends/codesys/index.ts +0 -13
- package/backends/codesys/io-paths.ts +0 -105
- package/backends/codesys/manifest.ts +0 -312
- package/backends/codesys/names.ts +0 -76
- package/backends/codesys/numeric.ts +0 -356
- package/backends/codesys/plan.ts +0 -457
- package/backends/codesys/publication.ts +0 -59
- package/backends/codesys/storage.ts +0 -70
- package/backends/codesys/task-access.ts +0 -293
- package/backends/codesys/telemetry.ts +0 -593
- package/backends/codesys/types.ts +0 -179
- package/backends/codesys/vendor.ts +0 -108
- package/ir/aggregates.ts +0 -333
- package/ir/allocation.ts +0 -74
- package/ir/core-model.ts +0 -129
- package/ir/core.ts +0 -64
- package/ir/declarations.ts +0 -208
- package/ir/diagnostics.ts +0 -43
- package/ir/domains.ts +0 -96
- package/ir/index.ts +0 -8
- package/ir/link.ts +0 -185
- package/ir/model.ts +0 -346
- package/ir/routine.ts +0 -859
- package/ir/scalars.ts +0 -675
- package/ir/types.ts +0 -76
- package/project/artifacts.ts +0 -277
- package/project/cli.ts +0 -395
- package/project/index.ts +0 -1
- package/project/plant.ts +0 -509
- package/project/project.ts +0 -358
- package/project/server.ts +0 -113
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import type { Publication } from "@tsplc/config";
|
|
2
|
+
import type {
|
|
3
|
+
EmitResult,
|
|
4
|
+
PlcType,
|
|
5
|
+
VerifiedCoreModule,
|
|
6
|
+
} from "@tsplc/compiler/ir";
|
|
7
|
+
import type { RpcChannel } from "./http.ts";
|
|
8
|
+
import type { CodesysPlan } from "./plan.ts";
|
|
9
|
+
import { moduleFile, moduleName } from "./storage.ts";
|
|
10
|
+
import { type CodesysSymbols, required } from "./symbols.ts";
|
|
11
|
+
|
|
12
|
+
const globals = (core: VerifiedCoreModule) =>
|
|
13
|
+
core.variables.filter(
|
|
14
|
+
(variable) => variable.storage === "module" && variable.exported,
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
/** Source names are independent of CODESYS name allocation and the active build target. */
|
|
18
|
+
export const publicationSelectors = (core: VerifiedCoreModule): string[] => {
|
|
19
|
+
const variables = globals(core);
|
|
20
|
+
return [
|
|
21
|
+
...new Set(
|
|
22
|
+
variables.flatMap((variable) => [
|
|
23
|
+
moduleName(variable),
|
|
24
|
+
`${moduleName(variable)}.${variable.name}`,
|
|
25
|
+
]),
|
|
26
|
+
),
|
|
27
|
+
].sort();
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const resolvePublication = (
|
|
31
|
+
core: VerifiedCoreModule,
|
|
32
|
+
policy: Publication,
|
|
33
|
+
): { publication: Publication; errors: string[] } => {
|
|
34
|
+
const variables = globals(core);
|
|
35
|
+
const errors: string[] = [];
|
|
36
|
+
const select = (selectors: readonly string[]) => {
|
|
37
|
+
const selected = new Set(
|
|
38
|
+
variables
|
|
39
|
+
.filter((variable) => variable.exposure)
|
|
40
|
+
.map((variable) => variable.id),
|
|
41
|
+
);
|
|
42
|
+
const seen = new Set<string>();
|
|
43
|
+
for (const selector of selectors) {
|
|
44
|
+
if (seen.has(selector)) {
|
|
45
|
+
errors.push(`Duplicate publication selector ${selector}.`);
|
|
46
|
+
}
|
|
47
|
+
seen.add(selector);
|
|
48
|
+
const candidates = variables.filter(
|
|
49
|
+
(variable) =>
|
|
50
|
+
selector === moduleName(variable) ||
|
|
51
|
+
selector === `${moduleName(variable)}.${variable.name}`,
|
|
52
|
+
);
|
|
53
|
+
if (!candidates.length) {
|
|
54
|
+
errors.push(
|
|
55
|
+
`Unknown publication selector ${selector}; select an exported mutable global or its module.`,
|
|
56
|
+
);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (new Set(candidates.map(moduleFile)).size !== 1) {
|
|
60
|
+
errors.push(`Ambiguous publication selector ${selector}.`);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
for (const variable of candidates) {
|
|
64
|
+
selected.add(variable.id);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return variables
|
|
68
|
+
.filter((variable) => selected.has(variable.id))
|
|
69
|
+
.map((variable) => variable.id);
|
|
70
|
+
};
|
|
71
|
+
const publication = {
|
|
72
|
+
production: select(policy.production),
|
|
73
|
+
development: select(policy.development),
|
|
74
|
+
};
|
|
75
|
+
return { publication, errors };
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/** The global symbols a build publishes for each target: its selected storage, logical IO and service channels. */
|
|
79
|
+
export const publishedSymbols = (
|
|
80
|
+
plan: CodesysPlan,
|
|
81
|
+
symbols: CodesysSymbols,
|
|
82
|
+
rpcChannels: readonly RpcChannel[],
|
|
83
|
+
): Publication => {
|
|
84
|
+
const logicalIo = plan.core.variables
|
|
85
|
+
.filter(
|
|
86
|
+
(variable) =>
|
|
87
|
+
variable.storage === "input" || variable.storage === "output",
|
|
88
|
+
)
|
|
89
|
+
.map((variable) => variable.id);
|
|
90
|
+
const rpcSymbols = [
|
|
91
|
+
...new Set(
|
|
92
|
+
rpcChannels.flatMap((channel) =>
|
|
93
|
+
[
|
|
94
|
+
channel.request,
|
|
95
|
+
channel.requestId,
|
|
96
|
+
channel.reply,
|
|
97
|
+
channel.replyId,
|
|
98
|
+
channel.epoch,
|
|
99
|
+
].map((path) => path.replace(/\[\d+\]$/, "")),
|
|
100
|
+
),
|
|
101
|
+
),
|
|
102
|
+
];
|
|
103
|
+
const published = (ids: readonly string[]) =>
|
|
104
|
+
[...ids, ...logicalIo]
|
|
105
|
+
.map((id) => required(symbols.references.get(id)))
|
|
106
|
+
.concat(rpcSymbols);
|
|
107
|
+
return {
|
|
108
|
+
production: published(plan.publication.production),
|
|
109
|
+
development: published(plan.publication.development),
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/** The JavaScript type an exposed field is read as. */
|
|
114
|
+
const telemetryKind = (type: PlcType | undefined) => {
|
|
115
|
+
if (type?.kind === "bool") {
|
|
116
|
+
return "boolean";
|
|
117
|
+
}
|
|
118
|
+
return type?.kind === "string" ? "string" : "number";
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/** `exposures.json` and `machines.ts`: the read-only interface of each exposed machine, and the service channels. */
|
|
122
|
+
export const machineInterfaces = (
|
|
123
|
+
{ core }: CodesysPlan,
|
|
124
|
+
symbols: CodesysSymbols,
|
|
125
|
+
rpcChannels: readonly RpcChannel[],
|
|
126
|
+
): EmitResult["artifacts"] => {
|
|
127
|
+
const exposures = Object.fromEntries(
|
|
128
|
+
core.variables.flatMap((variable) => {
|
|
129
|
+
const { exposure } = variable;
|
|
130
|
+
if (!exposure) {
|
|
131
|
+
return [];
|
|
132
|
+
}
|
|
133
|
+
const record = symbols.typeMap.get(variable.type);
|
|
134
|
+
if (record?.kind !== "record") {
|
|
135
|
+
throw new Error("Invalid exposure record.");
|
|
136
|
+
}
|
|
137
|
+
const root = required(symbols.references.get(variable.id));
|
|
138
|
+
const fields = Object.fromEntries(
|
|
139
|
+
record.fields
|
|
140
|
+
.filter((field) => field.name !== "contractVersion")
|
|
141
|
+
.map((field) => [
|
|
142
|
+
field.name,
|
|
143
|
+
{
|
|
144
|
+
path: `${root}.${symbols.targetTypes.field(record.id, field.name)}`,
|
|
145
|
+
kind: telemetryKind(symbols.typeMap.get(field.type)),
|
|
146
|
+
},
|
|
147
|
+
]),
|
|
148
|
+
);
|
|
149
|
+
return [
|
|
150
|
+
[
|
|
151
|
+
exposure.name,
|
|
152
|
+
{
|
|
153
|
+
version: exposure.version,
|
|
154
|
+
versionPath: `${root}.${symbols.targetTypes.field(record.id, "contractVersion")}`,
|
|
155
|
+
telemetry: fields,
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
];
|
|
159
|
+
}),
|
|
160
|
+
);
|
|
161
|
+
return [
|
|
162
|
+
{
|
|
163
|
+
path: "exposures.json",
|
|
164
|
+
content: JSON.stringify(exposures, null, 2) + "\n",
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
path: "machines.ts",
|
|
168
|
+
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`,
|
|
169
|
+
},
|
|
170
|
+
];
|
|
171
|
+
};
|