@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/symbols.ts
CHANGED
|
@@ -1,37 +1,43 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type CoreFunction,
|
|
3
3
|
type CoreFunctionBlock,
|
|
4
|
+
coreTables,
|
|
4
5
|
type GeneratedObject,
|
|
6
|
+
instanceFields,
|
|
7
|
+
isBlockRoutine,
|
|
5
8
|
standardBlocks,
|
|
6
9
|
} from "@tsplc/compiler/ir";
|
|
7
10
|
import { planGlobalNames } from "./global-names";
|
|
8
|
-
import type { Instrumentation } from "./instrumentation";
|
|
11
|
+
import type { BlockInstrumentation, Instrumentation } from "./instrumentation";
|
|
9
12
|
import { Names } from "./names";
|
|
10
13
|
import { NumericLowering } from "./numeric";
|
|
11
14
|
import type { CodesysPlan } from "./plan";
|
|
15
|
+
import { required } from "./required";
|
|
12
16
|
import { accessedStorage } from "./task-access";
|
|
13
17
|
|
|
14
|
-
// All symbol relationships were checked by normalization and planning. Failure
|
|
15
|
-
// here is an emitter invariant violation, rather than a recoverable source error.
|
|
16
|
-
export function required<T>(value: T | undefined): T {
|
|
17
|
-
if (value === undefined) {
|
|
18
|
-
throw new Error("Missing verified CODESYS symbol.");
|
|
19
|
-
}
|
|
20
|
-
return value;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
18
|
/** The names a routine's ST gives its parameters, locals and the block state it reaches. */
|
|
24
|
-
interface RoutineScope {
|
|
19
|
+
export interface RoutineScope {
|
|
25
20
|
names: Names;
|
|
26
|
-
references:
|
|
21
|
+
references: ReadonlyMap<string, string>;
|
|
27
22
|
}
|
|
28
23
|
|
|
24
|
+
/** The names fixed before emission: objects of types, blocks, storage lists and routines that hold state. */
|
|
25
|
+
export type GlobalSymbols = ReturnType<typeof globalSymbols>;
|
|
26
|
+
|
|
29
27
|
/**
|
|
30
|
-
* The target names of a program: its objects, storage, routines and block fields.
|
|
31
|
-
*
|
|
32
|
-
* complete before any routine body is written.
|
|
28
|
+
* The target names of a program: its objects, storage, routines and block fields. `emitCodesys`
|
|
29
|
+
* allocates them in emission order, each scope reserving the objects emitted before it, and they
|
|
30
|
+
* are complete before any routine body is written.
|
|
33
31
|
*/
|
|
34
|
-
export type CodesysSymbols =
|
|
32
|
+
export type CodesysSymbols = GlobalSymbols & {
|
|
33
|
+
/** The global symbol of each module variable and logical IO. */
|
|
34
|
+
references: ReadonlyMap<string, string>;
|
|
35
|
+
functionNames: ReadonlyMap<string, string>;
|
|
36
|
+
programResults: ReadonlyMap<string, string>;
|
|
37
|
+
mailboxLocks: ReadonlyMap<string, string>;
|
|
38
|
+
blockFields: ReadonlyMap<string, ReadonlyMap<string, string>>;
|
|
39
|
+
routineScopes: ReadonlyMap<string, RoutineScope>;
|
|
40
|
+
};
|
|
35
41
|
|
|
36
42
|
/** A plan with the target names and instrumentation allocated for it: what each emitter reads. */
|
|
37
43
|
export interface EmissionContext {
|
|
@@ -40,108 +46,112 @@ export interface EmissionContext {
|
|
|
40
46
|
instrumentation: Instrumentation;
|
|
41
47
|
}
|
|
42
48
|
|
|
43
|
-
export function
|
|
49
|
+
export function globalSymbols(plan: CodesysPlan) {
|
|
50
|
+
const { core } = plan;
|
|
44
51
|
const persistent = new Set(
|
|
45
52
|
core.variables
|
|
46
53
|
.filter((item) => item.storage !== "constant")
|
|
47
54
|
.map((item) => item.id),
|
|
48
55
|
);
|
|
49
|
-
const programRoutines = new Set
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const globalNames = planGlobalNames(core,
|
|
56
|
+
const programRoutines: ReadonlySet<string> = new Set(
|
|
57
|
+
core.functions
|
|
58
|
+
.filter(
|
|
59
|
+
(fn) =>
|
|
60
|
+
!fn.owner &&
|
|
61
|
+
[...accessedStorage(fn, core)].some((id) => persistent.has(id)),
|
|
62
|
+
)
|
|
63
|
+
.map((fn) => fn.id),
|
|
64
|
+
);
|
|
65
|
+
const globalNames = planGlobalNames(core, plan.programNames);
|
|
59
66
|
return {
|
|
60
67
|
...globalNames,
|
|
61
|
-
blocks:
|
|
68
|
+
blocks: coreTables(core).blocks,
|
|
62
69
|
numeric: new NumericLowering(globalNames.typeMap, (label) =>
|
|
63
70
|
globalNames.names.allocate(label),
|
|
64
71
|
),
|
|
65
72
|
programRoutines,
|
|
66
|
-
/** The global symbol of each module variable and logical IO. */
|
|
67
|
-
references: new Map<string, string>(),
|
|
68
|
-
functionNames: new Map<string, string>(),
|
|
69
|
-
programResults: new Map<string, string>(),
|
|
70
|
-
mailboxLocks: new Map<string, string>(),
|
|
71
|
-
blockFields: new Map<string, Map<string, string>>(),
|
|
72
|
-
routineScopes: new Map<string, RoutineScope>(),
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
/** The object name of each function that is not a method. */
|
|
76
77
|
export function allocateFunctionNames(
|
|
77
|
-
symbols: CodesysSymbols,
|
|
78
78
|
{ core }: CodesysPlan,
|
|
79
|
-
|
|
79
|
+
symbols: GlobalSymbols,
|
|
80
|
+
): Map<string, string> {
|
|
80
81
|
const entries = new Set(core.programs.map((program) => program.entry));
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
82
|
+
return new Map(
|
|
83
|
+
core.functions
|
|
84
|
+
.filter((fn) => !fn.owner)
|
|
85
|
+
.map((fn) => {
|
|
86
|
+
const program = symbols.programRoutines.has(fn.id);
|
|
87
|
+
const label =
|
|
88
|
+
program && entries.has(fn.id) ? `${fn.name}_body` : fn.name;
|
|
89
|
+
return [
|
|
90
|
+
fn.id,
|
|
91
|
+
symbols.names.allocateObject(program ? "PRG" : "F", label),
|
|
92
|
+
];
|
|
93
|
+
}),
|
|
94
|
+
);
|
|
89
95
|
}
|
|
90
96
|
|
|
91
|
-
/**
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
/**
|
|
98
|
+
* The names a routine's or block's own scope must not shadow: the objects emitted so far, the
|
|
99
|
+
* debug global, and every routine and block named so far.
|
|
100
|
+
*/
|
|
101
|
+
const scopeNames = (
|
|
102
|
+
symbols: Pick<CodesysSymbols, "functionNames" | "blockNames">,
|
|
103
|
+
objects: readonly GeneratedObject[],
|
|
104
|
+
global: string,
|
|
105
|
+
): Names =>
|
|
106
|
+
new Names([
|
|
107
|
+
...objects.map((object) => object.name),
|
|
108
|
+
global,
|
|
109
|
+
...symbols.functionNames.values(),
|
|
110
|
+
...symbols.blockNames.values(),
|
|
111
|
+
]);
|
|
99
112
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
113
|
+
/**
|
|
114
|
+
* Each block's field names, its methods' names and its mailbox lock, and the instrumentation fields
|
|
115
|
+
* of the blocks that have any. A block's scope reserves the names of the functions that are not
|
|
116
|
+
* methods.
|
|
117
|
+
*/
|
|
118
|
+
export function allocateBlockMembers(
|
|
103
119
|
plan: CodesysPlan,
|
|
120
|
+
symbols: GlobalSymbols & Pick<CodesysSymbols, "functionNames">,
|
|
121
|
+
instrumentation: Pick<Instrumentation, "global" | "analysis">,
|
|
104
122
|
objects: readonly GeneratedObject[],
|
|
105
|
-
)
|
|
123
|
+
) {
|
|
106
124
|
const { core } = plan;
|
|
107
|
-
const
|
|
125
|
+
const fields = new Map<string, ReadonlyMap<string, string>>();
|
|
126
|
+
const methods = new Map<string, string>();
|
|
127
|
+
const mailboxLocks = new Map<string, string>();
|
|
128
|
+
const instrumented = new Map<string, BlockInstrumentation>();
|
|
108
129
|
for (const block of core.blocks) {
|
|
109
|
-
const
|
|
110
|
-
const mapped = new Map<string, string>();
|
|
111
|
-
for (const object of objects) {
|
|
112
|
-
fields.reserve(object.name);
|
|
113
|
-
}
|
|
114
|
-
fields.reserve(instrumentation.global);
|
|
115
|
-
for (const objectName of [
|
|
116
|
-
...core.functions
|
|
117
|
-
.filter((fn) => !fn.owner)
|
|
118
|
-
.map((fn) => required(functionNames.get(fn.id))),
|
|
119
|
-
...blockNames.values(),
|
|
120
|
-
]) {
|
|
121
|
-
fields.reserve(objectName);
|
|
122
|
-
}
|
|
130
|
+
const names = scopeNames(symbols, objects, instrumentation.global);
|
|
123
131
|
for (const method of core.functions.filter(
|
|
124
132
|
(fn) => fn.owner?.block === block.id,
|
|
125
133
|
)) {
|
|
126
|
-
|
|
134
|
+
methods.set(method.id, names.allocate(method.name));
|
|
127
135
|
}
|
|
128
136
|
const native = block.standard && standardBlocks[block.standard];
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
137
|
+
fields.set(
|
|
138
|
+
block.id,
|
|
139
|
+
new Map(
|
|
140
|
+
instanceFields(block).map((item) => [
|
|
141
|
+
item.id,
|
|
142
|
+
native
|
|
143
|
+
? required(
|
|
144
|
+
[...native.inputs, ...native.outputs].find(
|
|
145
|
+
([name]) => name === item.name,
|
|
146
|
+
),
|
|
147
|
+
)[1]
|
|
148
|
+
: names.allocate(item.name),
|
|
149
|
+
]),
|
|
150
|
+
),
|
|
151
|
+
);
|
|
141
152
|
if (block.runtime?.kind === "mailbox") {
|
|
142
|
-
|
|
153
|
+
mailboxLocks.set(block.id, names.allocate("plc_mailbox_lock"));
|
|
143
154
|
}
|
|
144
|
-
blockFields.set(block.id, mapped);
|
|
145
155
|
|
|
146
156
|
const settings = plan.project.debug;
|
|
147
157
|
// Trace sites and an unhandled failure need the step a job finished at.
|
|
@@ -152,51 +162,41 @@ export function allocateBlockFields(
|
|
|
152
162
|
const carries =
|
|
153
163
|
settings?.jobs && instrumentation.analysis.carriers.has(block.id);
|
|
154
164
|
if (tracked || carries) {
|
|
155
|
-
|
|
165
|
+
instrumented.set(block.id, {
|
|
156
166
|
...(tracked && {
|
|
157
|
-
busy:
|
|
158
|
-
track:
|
|
167
|
+
busy: names.allocate("tsplcBusy"),
|
|
168
|
+
track: names.allocate("TsplcTrack"),
|
|
159
169
|
}),
|
|
160
170
|
...(tracked &&
|
|
161
|
-
settings?.jobs && { startedAt:
|
|
162
|
-
...(stepped && { step:
|
|
163
|
-
...(carries && { job:
|
|
171
|
+
settings?.jobs && { startedAt: names.allocate("startedAt") }),
|
|
172
|
+
...(stepped && { step: names.allocate("tsplcStep") }),
|
|
173
|
+
...(carries && { job: names.allocate("requestJob") }),
|
|
164
174
|
...(carries &&
|
|
165
175
|
block.runtime?.kind === "http" && {
|
|
166
|
-
sequence:
|
|
176
|
+
sequence: names.allocate("sequence"),
|
|
167
177
|
}),
|
|
168
178
|
});
|
|
169
179
|
}
|
|
170
180
|
}
|
|
181
|
+
return { fields, methods, mailboxLocks, instrumented };
|
|
171
182
|
}
|
|
172
183
|
|
|
184
|
+
/** The names a routine's ST gives its parameters, locals and block state, and a stateful program's result. */
|
|
173
185
|
export function allocateRoutineScope(
|
|
174
|
-
symbols:
|
|
175
|
-
|
|
186
|
+
symbols: GlobalSymbols &
|
|
187
|
+
Pick<CodesysSymbols, "functionNames" | "blockFields">,
|
|
176
188
|
objects: readonly GeneratedObject[],
|
|
189
|
+
global: string,
|
|
177
190
|
fn: CoreFunction | CoreFunctionBlock,
|
|
178
|
-
):
|
|
179
|
-
const block =
|
|
180
|
-
const owner =
|
|
181
|
-
|
|
182
|
-
("owner" in fn && fn.owner
|
|
183
|
-
? symbols.blocks.get(fn.owner.block)
|
|
184
|
-
: undefined);
|
|
185
|
-
const names = new Names();
|
|
191
|
+
): { scope: RoutineScope; result?: string } {
|
|
192
|
+
const block = isBlockRoutine(fn) ? fn : undefined;
|
|
193
|
+
const owner = owningBlock(symbols, fn);
|
|
194
|
+
const names = scopeNames(symbols, objects, global);
|
|
186
195
|
const references = new Map<string, string>();
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
for (const name of [
|
|
192
|
-
...symbols.functionNames.values(),
|
|
193
|
-
...symbols.blockNames.values(),
|
|
194
|
-
]) {
|
|
195
|
-
names.reserve(name);
|
|
196
|
-
}
|
|
197
|
-
if (symbols.programRoutines.has(fn.id) && "parameters" in fn && fn.result) {
|
|
198
|
-
symbols.programResults.set(fn.id, names.allocate("plc_result"));
|
|
199
|
-
}
|
|
196
|
+
const result =
|
|
197
|
+
!block && symbols.programRoutines.has(fn.id) && fn.result
|
|
198
|
+
? names.allocate("plc_result")
|
|
199
|
+
: undefined;
|
|
200
200
|
if (owner) {
|
|
201
201
|
for (const item of [...owner.outputs, ...owner.state]) {
|
|
202
202
|
const name = required(
|
|
@@ -206,7 +206,7 @@ export function allocateRoutineScope(
|
|
|
206
206
|
references.set(item.id, name);
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
|
-
for (const item of
|
|
209
|
+
for (const item of isBlockRoutine(fn) ? fn.inputs : fn.parameters) {
|
|
210
210
|
const name = block
|
|
211
211
|
? required(required(symbols.blockFields.get(block.id)).get(item.id))
|
|
212
212
|
: names.allocate(item.name);
|
|
@@ -216,5 +216,16 @@ export function allocateRoutineScope(
|
|
|
216
216
|
for (const item of fn.locals) {
|
|
217
217
|
references.set(item.id, names.allocate(item.name));
|
|
218
218
|
}
|
|
219
|
-
|
|
219
|
+
return { scope: { names, references }, ...(result && { result }) };
|
|
220
220
|
}
|
|
221
|
+
|
|
222
|
+
/** The block whose state a routine reaches: the block itself, or a method's block. */
|
|
223
|
+
export const owningBlock = (
|
|
224
|
+
symbols: GlobalSymbols,
|
|
225
|
+
fn: CoreFunction | CoreFunctionBlock,
|
|
226
|
+
): CoreFunctionBlock | undefined => {
|
|
227
|
+
if (isBlockRoutine(fn)) {
|
|
228
|
+
return fn;
|
|
229
|
+
}
|
|
230
|
+
return fn.owner && required(symbols.blocks.get(fn.owner.block));
|
|
231
|
+
};
|