@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/frontend/analyzer.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
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 { resolve } from "node:path";
|
|
3
2
|
import {
|
|
4
3
|
aggregate,
|
|
@@ -16,7 +15,7 @@ import {
|
|
|
16
15
|
ExpressionLowering,
|
|
17
16
|
type LoweringScope,
|
|
18
17
|
} from "./expressions";
|
|
19
|
-
import { runtimeSources } from "./module-graph";
|
|
18
|
+
import { runtimeImport, runtimeSources } from "./module-graph";
|
|
20
19
|
import type { Positions } from "./positions";
|
|
21
20
|
import { methodAccess, RoutineTable } from "./routines";
|
|
22
21
|
import { inSdk, unaliased } from "./sdk";
|
|
@@ -24,10 +23,10 @@ import { StatementLowering } from "./statements";
|
|
|
24
23
|
import {
|
|
25
24
|
type Fail,
|
|
26
25
|
hasModifier,
|
|
27
|
-
|
|
28
|
-
numericLiteralType,
|
|
26
|
+
inferredStorageType,
|
|
29
27
|
type ResolvedType,
|
|
30
28
|
SemanticError,
|
|
29
|
+
type ServiceRecord,
|
|
31
30
|
TypeResolver,
|
|
32
31
|
} from "./types";
|
|
33
32
|
import type { FrontendOptions } from "./typescript";
|
|
@@ -37,7 +36,7 @@ interface StorageFacts {
|
|
|
37
36
|
instance: string | undefined;
|
|
38
37
|
table: ResolvedType | undefined;
|
|
39
38
|
immutable: boolean;
|
|
40
|
-
|
|
39
|
+
initializer: ts.Expression | undefined;
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
export const suppressionDiagnostics = (
|
|
@@ -83,7 +82,6 @@ export const suppressionDiagnostics = (
|
|
|
83
82
|
|
|
84
83
|
export class Analyzer {
|
|
85
84
|
private readonly checker: ts.TypeChecker;
|
|
86
|
-
private readonly variables = new Map<ts.Symbol, Variable>();
|
|
87
85
|
private readonly resolver: TypeResolver;
|
|
88
86
|
private readonly routines: RoutineTable;
|
|
89
87
|
private readonly blocks: BlockResolver;
|
|
@@ -100,7 +98,7 @@ export class Analyzer {
|
|
|
100
98
|
private readonly sdk: string,
|
|
101
99
|
private readonly diagnostics: Diagnostic[],
|
|
102
100
|
private readonly positions: Positions,
|
|
103
|
-
serviceRecord
|
|
101
|
+
serviceRecord: ServiceRecord | null,
|
|
104
102
|
) {
|
|
105
103
|
this.checker = program.getTypeChecker();
|
|
106
104
|
this.resolver = new TypeResolver(
|
|
@@ -116,11 +114,15 @@ export class Analyzer {
|
|
|
116
114
|
positions,
|
|
117
115
|
this.fail,
|
|
118
116
|
);
|
|
117
|
+
const sdkSource = program.getSourceFile(sdk);
|
|
118
|
+
if (!sdkSource) {
|
|
119
|
+
throw new Error(`The program does not include the SDK ${sdk}.`);
|
|
120
|
+
}
|
|
119
121
|
this.blocks = new BlockResolver(
|
|
120
122
|
this.resolver,
|
|
121
123
|
positions.node,
|
|
122
124
|
this.fail,
|
|
123
|
-
positions.node(
|
|
125
|
+
positions.node(sdkSource),
|
|
124
126
|
);
|
|
125
127
|
this.context = {
|
|
126
128
|
checker: this.checker,
|
|
@@ -134,7 +136,7 @@ export class Analyzer {
|
|
|
134
136
|
fn: undefined,
|
|
135
137
|
block: undefined,
|
|
136
138
|
environment: new Map(),
|
|
137
|
-
variables:
|
|
139
|
+
variables: new Map(),
|
|
138
140
|
});
|
|
139
141
|
const roots = new Set(program.getRootFileNames());
|
|
140
142
|
this.sources = runtimeSources(program).filter(
|
|
@@ -146,14 +148,11 @@ export class Analyzer {
|
|
|
146
148
|
);
|
|
147
149
|
}
|
|
148
150
|
|
|
149
|
-
private type(node: ts.TypeNode): ResolvedType {
|
|
150
|
-
return this.resolver.resolve(node);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
151
|
private readonly fail: Fail = (node, code, message) => {
|
|
154
152
|
throw new SemanticError(error(code, message, this.positions.node(node)));
|
|
155
153
|
};
|
|
156
154
|
|
|
155
|
+
/** Runs `action`, reporting the diagnostic it fails with unless an earlier action reported it. */
|
|
157
156
|
private guard(action: () => void): void {
|
|
158
157
|
try {
|
|
159
158
|
action();
|
|
@@ -161,7 +160,9 @@ export class Analyzer {
|
|
|
161
160
|
if (!(cause instanceof SemanticError)) {
|
|
162
161
|
throw cause;
|
|
163
162
|
}
|
|
164
|
-
this.diagnostics.
|
|
163
|
+
if (!this.diagnostics.includes(cause.diagnostic)) {
|
|
164
|
+
this.diagnostics.push(cause.diagnostic);
|
|
165
|
+
}
|
|
165
166
|
}
|
|
166
167
|
}
|
|
167
168
|
|
|
@@ -193,14 +194,13 @@ export class Analyzer {
|
|
|
193
194
|
}
|
|
194
195
|
for (const source of this.blocks.sources.values()) {
|
|
195
196
|
for (const method of source.methods) {
|
|
196
|
-
this.guard(() =>
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
access: methodAccess(method),
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
});
|
|
197
|
+
this.guard(() =>
|
|
198
|
+
this.routines.declareMethod(
|
|
199
|
+
this.resolver.symbol(method.name),
|
|
200
|
+
method,
|
|
201
|
+
{ block: source.block.id, access: methodAccess(method) },
|
|
202
|
+
),
|
|
203
|
+
);
|
|
204
204
|
}
|
|
205
205
|
}
|
|
206
206
|
for (const source of this.sources) {
|
|
@@ -224,9 +224,9 @@ export class Analyzer {
|
|
|
224
224
|
"Persistent PLC state requires a constant initializer.",
|
|
225
225
|
);
|
|
226
226
|
}
|
|
227
|
-
const variable = this.
|
|
228
|
-
|
|
229
|
-
|
|
227
|
+
const variable = this.moduleScope
|
|
228
|
+
.bySymbol()
|
|
229
|
+
.get(this.resolver.symbol(declaration.name));
|
|
230
230
|
if (!variable || variable.storage === "instance") {
|
|
231
231
|
continue;
|
|
232
232
|
}
|
|
@@ -248,11 +248,14 @@ export class Analyzer {
|
|
|
248
248
|
) {
|
|
249
249
|
variable.storage = "module";
|
|
250
250
|
}
|
|
251
|
-
if (
|
|
251
|
+
if (
|
|
252
|
+
variable.retention !== "none" &&
|
|
253
|
+
variable.storage === "constant"
|
|
254
|
+
) {
|
|
252
255
|
this.fail(
|
|
253
256
|
declaration,
|
|
254
257
|
"PLC3004",
|
|
255
|
-
|
|
258
|
+
`${variable.retention} requires mutable persistent storage or a static block instance.`,
|
|
256
259
|
);
|
|
257
260
|
}
|
|
258
261
|
const value = this.moduleScope.constant(
|
|
@@ -301,7 +304,7 @@ export class Analyzer {
|
|
|
301
304
|
...(block.result && { result: block.result }),
|
|
302
305
|
},
|
|
303
306
|
source.fieldBindings,
|
|
304
|
-
source.
|
|
307
|
+
source.body,
|
|
305
308
|
{ block: source, environment: new Map() },
|
|
306
309
|
);
|
|
307
310
|
block.locals = routine.locals;
|
|
@@ -320,52 +323,31 @@ export class Analyzer {
|
|
|
320
323
|
(source) => source.block.id === instance.fn.owner?.block,
|
|
321
324
|
)
|
|
322
325
|
: undefined;
|
|
323
|
-
// Declaration admission proved the parameter list and body before worklist analysis.
|
|
324
326
|
const fn = this.routineBody(
|
|
325
327
|
instance.fn,
|
|
326
|
-
[
|
|
327
|
-
|
|
328
|
-
...instance.node.parameters.map(
|
|
329
|
-
(parameter, index) =>
|
|
330
|
-
[
|
|
331
|
-
this.resolver.symbol(parameter.name),
|
|
332
|
-
instance.fn.parameters[index]!,
|
|
333
|
-
] as const,
|
|
334
|
-
),
|
|
335
|
-
],
|
|
336
|
-
instance.node.body!,
|
|
328
|
+
[...(block?.fieldBindings ?? []), ...instance.parameters],
|
|
329
|
+
instance.body,
|
|
337
330
|
{ block, environment: instance.environment },
|
|
338
331
|
);
|
|
339
|
-
this.routines.
|
|
340
|
-
if (
|
|
341
|
-
ts.isFunctionDeclaration(instance.node) &&
|
|
342
|
-
!instance.node.typeParameters?.length
|
|
343
|
-
) {
|
|
344
|
-
this.routines.functions.set(
|
|
345
|
-
this.resolver.symbol(instance.node.name!),
|
|
346
|
-
fn,
|
|
347
|
-
);
|
|
348
|
-
}
|
|
332
|
+
this.routines.complete(instance, fn);
|
|
349
333
|
});
|
|
350
334
|
}
|
|
351
335
|
}
|
|
352
336
|
|
|
353
|
-
// Lowers one routine body with its bindings layered over module storage.
|
|
354
337
|
private routineBody(
|
|
355
338
|
fn: PlcFunction,
|
|
356
339
|
bindings: Iterable<readonly [ts.Symbol, Variable]>,
|
|
357
340
|
body: ts.Block,
|
|
358
341
|
scope: Pick<LoweringScope, "block" | "environment">,
|
|
359
342
|
): PlcFunction {
|
|
360
|
-
const variables = new Map(this.variables);
|
|
361
|
-
for (const [symbol, variable] of bindings) {
|
|
362
|
-
variables.set(symbol, variable);
|
|
363
|
-
}
|
|
364
343
|
const expressions = new ExpressionLowering(this.context, {
|
|
365
344
|
...scope,
|
|
366
345
|
fn,
|
|
367
|
-
variables,
|
|
346
|
+
variables: this.moduleScope.bySymbol(),
|
|
368
347
|
});
|
|
348
|
+
for (const [symbol, variable] of bindings) {
|
|
349
|
+
expressions.bind(symbol, variable);
|
|
350
|
+
}
|
|
369
351
|
const statements = new StatementLowering(this.context, expressions, fn);
|
|
370
352
|
return { ...fn, ...statements.lowerRoutine(body) };
|
|
371
353
|
}
|
|
@@ -432,31 +414,10 @@ export class Analyzer {
|
|
|
432
414
|
"This dependency could not be resolved to PLC source.",
|
|
433
415
|
);
|
|
434
416
|
}
|
|
435
|
-
|
|
436
|
-
const typeOnly = ts.isImportDeclaration(node)
|
|
437
|
-
? node.importClause?.isTypeOnly
|
|
438
|
-
: node.isTypeOnly;
|
|
439
|
-
if (typeOnly) {
|
|
440
|
-
return;
|
|
441
|
-
}
|
|
442
|
-
const bindings = ts.isImportDeclaration(node)
|
|
443
|
-
? node.importClause?.namedBindings
|
|
444
|
-
: node.exportClause;
|
|
445
|
-
const defaultName = ts.isImportDeclaration(node)
|
|
446
|
-
? node.importClause?.name
|
|
447
|
-
: undefined;
|
|
448
|
-
const namedOnly =
|
|
449
|
-
bindings &&
|
|
450
|
-
(ts.isNamedImports(bindings) || ts.isNamedExports(bindings)) &&
|
|
451
|
-
bindings.elements.length > 0 &&
|
|
452
|
-
bindings.elements.every(
|
|
453
|
-
(binding) =>
|
|
454
|
-
binding.isTypeOnly ||
|
|
455
|
-
!(this.resolver.symbol(binding.name).flags & ts.SymbolFlags.Value),
|
|
456
|
-
);
|
|
457
|
-
if (namedOnly && !defaultName) {
|
|
417
|
+
if (!runtimeImport(node, this.checker)) {
|
|
458
418
|
return;
|
|
459
419
|
}
|
|
420
|
+
const source = this.program.getSourceFile(resolved.resolvedFileName);
|
|
460
421
|
if (source && !source.isDeclarationFile) {
|
|
461
422
|
return;
|
|
462
423
|
}
|
|
@@ -474,7 +435,7 @@ export class Analyzer {
|
|
|
474
435
|
(ts.isVariableStatement(statement) &&
|
|
475
436
|
statement.declarationList.declarations.every(
|
|
476
437
|
(declaration) =>
|
|
477
|
-
declaration.type && this.
|
|
438
|
+
declaration.type && this.resolver.resolve(declaration.type).io,
|
|
478
439
|
)),
|
|
479
440
|
);
|
|
480
441
|
if (authoredIo) {
|
|
@@ -533,14 +494,10 @@ export class Analyzer {
|
|
|
533
494
|
"Generators are not supported in PLC scan code.",
|
|
534
495
|
);
|
|
535
496
|
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
symbol,
|
|
541
|
-
this.routines.instantiate(statement, [], statement, new Map()),
|
|
542
|
-
);
|
|
543
|
-
}
|
|
497
|
+
this.routines.declareFunction(
|
|
498
|
+
this.resolver.symbol(statement.name),
|
|
499
|
+
statement,
|
|
500
|
+
);
|
|
544
501
|
return;
|
|
545
502
|
}
|
|
546
503
|
this.fail(
|
|
@@ -578,7 +535,6 @@ export class Analyzer {
|
|
|
578
535
|
const instance =
|
|
579
536
|
initializer &&
|
|
580
537
|
this.allocatedBlock(declaration, initializer.value, table);
|
|
581
|
-
const literal = initializer && numericLiteral(initializer.value);
|
|
582
538
|
if (table && !immutable) {
|
|
583
539
|
this.fail(
|
|
584
540
|
declaration,
|
|
@@ -590,19 +546,8 @@ export class Analyzer {
|
|
|
590
546
|
instance,
|
|
591
547
|
table,
|
|
592
548
|
immutable,
|
|
593
|
-
|
|
549
|
+
initializer: initializer?.value,
|
|
594
550
|
});
|
|
595
|
-
if (
|
|
596
|
-
!instance &&
|
|
597
|
-
!declaration.type &&
|
|
598
|
-
!immutable &&
|
|
599
|
-
!literal &&
|
|
600
|
-
declaration.initializer &&
|
|
601
|
-
initializer?.value.kind !== ts.SyntaxKind.TrueKeyword &&
|
|
602
|
-
initializer?.value.kind !== ts.SyntaxKind.FalseKeyword
|
|
603
|
-
) {
|
|
604
|
-
this.fail(declaration, "PLC2001", "Annotate PLC storage explicitly.");
|
|
605
|
-
}
|
|
606
551
|
const ambient = declaration.getSourceFile().isDeclarationFile;
|
|
607
552
|
if (type.mode || this.resolver.hasReferences(type.type)) {
|
|
608
553
|
this.fail(
|
|
@@ -621,7 +566,8 @@ export class Analyzer {
|
|
|
621
566
|
if (
|
|
622
567
|
instance &&
|
|
623
568
|
(!immutable ||
|
|
624
|
-
(declaration.type &&
|
|
569
|
+
(declaration.type &&
|
|
570
|
+
this.resolver.resolve(declaration.type).type !== instance))
|
|
625
571
|
) {
|
|
626
572
|
this.fail(
|
|
627
573
|
declaration,
|
|
@@ -629,8 +575,9 @@ export class Analyzer {
|
|
|
629
575
|
"Static block instances require const bindings and matching annotations.",
|
|
630
576
|
);
|
|
631
577
|
}
|
|
578
|
+
const retention = initializer?.retention ?? "none";
|
|
632
579
|
if (
|
|
633
|
-
|
|
580
|
+
retention !== "none" &&
|
|
634
581
|
(ambient ||
|
|
635
582
|
(immutable &&
|
|
636
583
|
type.type !== "inferred" &&
|
|
@@ -640,7 +587,7 @@ export class Analyzer {
|
|
|
640
587
|
this.fail(
|
|
641
588
|
declaration,
|
|
642
589
|
"PLC3004",
|
|
643
|
-
|
|
590
|
+
`${retention} requires mutable persistent storage or a static block instance.`,
|
|
644
591
|
);
|
|
645
592
|
}
|
|
646
593
|
if (ambient && !type.io) {
|
|
@@ -669,13 +616,13 @@ export class Analyzer {
|
|
|
669
616
|
type: type.type,
|
|
670
617
|
storage: this.storageClass(type, { instance, table, immutable }),
|
|
671
618
|
mutable: !immutable,
|
|
672
|
-
|
|
619
|
+
retention,
|
|
673
620
|
...(hasModifier(statement, ts.SyntaxKind.ExportKeyword) && {
|
|
674
621
|
exported: true as const,
|
|
675
622
|
}),
|
|
676
623
|
span: this.positions.node(declaration),
|
|
677
624
|
};
|
|
678
|
-
this.
|
|
625
|
+
this.moduleScope.bind(this.resolver.symbol(declaration.name), variable);
|
|
679
626
|
this.globalVariables.push(variable);
|
|
680
627
|
}
|
|
681
628
|
}
|
|
@@ -697,7 +644,7 @@ export class Analyzer {
|
|
|
697
644
|
/** An unannotated const takes its initializer's type once initializers resolve. */
|
|
698
645
|
private storageType(
|
|
699
646
|
declaration: ts.VariableDeclaration,
|
|
700
|
-
{ instance, table, immutable,
|
|
647
|
+
{ instance, table, immutable, initializer }: StorageFacts,
|
|
701
648
|
): ResolvedType {
|
|
702
649
|
if (instance) {
|
|
703
650
|
return { type: instance };
|
|
@@ -706,18 +653,26 @@ export class Analyzer {
|
|
|
706
653
|
return table;
|
|
707
654
|
}
|
|
708
655
|
if (declaration.type) {
|
|
709
|
-
return this.
|
|
656
|
+
return this.resolver.resolve(declaration.type);
|
|
710
657
|
}
|
|
711
658
|
if (immutable) {
|
|
712
659
|
return { type: "inferred" };
|
|
713
660
|
}
|
|
714
|
-
|
|
661
|
+
// Without an initializer, initializing storage reports the missing one.
|
|
662
|
+
if (!initializer) {
|
|
663
|
+
return { type: "BOOL" };
|
|
664
|
+
}
|
|
665
|
+
return {
|
|
666
|
+
type:
|
|
667
|
+
inferredStorageType(initializer) ??
|
|
668
|
+
this.fail(declaration, "PLC2001", "Annotate PLC storage explicitly."),
|
|
669
|
+
};
|
|
715
670
|
}
|
|
716
671
|
|
|
717
672
|
/** A const record or array keeps mutable fields, so only scalars and readonly tables are constants. */
|
|
718
673
|
private storageClass(
|
|
719
674
|
type: ResolvedType,
|
|
720
|
-
{ instance, table, immutable }: Omit<StorageFacts, "
|
|
675
|
+
{ instance, table, immutable }: Omit<StorageFacts, "initializer">,
|
|
721
676
|
): Variable["storage"] {
|
|
722
677
|
if (instance) {
|
|
723
678
|
return "instance";
|
|
@@ -761,7 +716,7 @@ export class Analyzer {
|
|
|
761
716
|
}
|
|
762
717
|
return this.resolver.fixedArray(
|
|
763
718
|
annotation,
|
|
764
|
-
this.
|
|
719
|
+
this.resolver.resolve(element),
|
|
765
720
|
{ kind: "integer", value: literal.elements.length },
|
|
766
721
|
{ kind: "integer", value: 0 },
|
|
767
722
|
);
|