@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
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Diagnostic } from "@tsplc/compiler/ir";
|
|
2
1
|
import ts from "typescript";
|
|
3
|
-
import {
|
|
2
|
+
import { copiedWhole } from "./coroutines";
|
|
3
|
+
import { plcSources } from "./module-graph";
|
|
4
4
|
import {
|
|
5
5
|
copied,
|
|
6
6
|
copiedRange,
|
|
@@ -12,6 +12,9 @@ import {
|
|
|
12
12
|
mapped,
|
|
13
13
|
type Part,
|
|
14
14
|
} from "./positions";
|
|
15
|
+
import { promiseCallback } from "./promise-chains";
|
|
16
|
+
import { sdkModules } from "./sdk";
|
|
17
|
+
import { hasModifier, promisedType } from "./types";
|
|
15
18
|
|
|
16
19
|
/**
|
|
17
20
|
* Structured Text exits a loop with EXIT and leaves a CASE at its end only, and has no labels and no
|
|
@@ -25,6 +28,11 @@ type JumpKind = "break" | "continue" | "return";
|
|
|
25
28
|
interface Target {
|
|
26
29
|
kind: "loop" | "switch" | "labelled" | "finally";
|
|
27
30
|
labels: readonly string[];
|
|
31
|
+
/**
|
|
32
|
+
* The coroutine runs it inside one step of an async routine, so a jump from it to the steps around
|
|
33
|
+
* it, written as is, would leave the step without moving the job on.
|
|
34
|
+
*/
|
|
35
|
+
withinStep: boolean;
|
|
28
36
|
breakFlag?: string;
|
|
29
37
|
continueFlag?: string;
|
|
30
38
|
/** Of a try with finally: which of its blocks the statements being lowered sit in. */
|
|
@@ -38,14 +46,17 @@ interface Pending {
|
|
|
38
46
|
target: Target | undefined;
|
|
39
47
|
}
|
|
40
48
|
|
|
49
|
+
/** A statement as lowered; `changed` when its text differs from the source's. */
|
|
41
50
|
interface Lowered {
|
|
42
51
|
text: Part;
|
|
43
52
|
pending: readonly Pending[];
|
|
53
|
+
changed: boolean;
|
|
44
54
|
}
|
|
45
55
|
|
|
46
56
|
interface List {
|
|
47
57
|
parts: readonly Part[];
|
|
48
58
|
pending: readonly Pending[];
|
|
59
|
+
changed: boolean;
|
|
49
60
|
}
|
|
50
61
|
|
|
51
62
|
/** One statement of a list, lowered when its turn comes, so guards can wrap the statements after it. */
|
|
@@ -54,14 +65,13 @@ interface Item {
|
|
|
54
65
|
lower: () => Lowered;
|
|
55
66
|
}
|
|
56
67
|
|
|
57
|
-
interface
|
|
68
|
+
interface RoutineScope {
|
|
58
69
|
source: ts.SourceFile;
|
|
59
70
|
async: boolean;
|
|
60
71
|
stack: Target[];
|
|
61
72
|
/** The routine's result type as written, or undefined when it returns nothing. */
|
|
62
73
|
resultType: string | undefined;
|
|
63
74
|
result?: { flag: string; value: string | undefined };
|
|
64
|
-
changes: number;
|
|
65
75
|
name: (base: string) => string;
|
|
66
76
|
/** The SDK functions the lowered routine calls, which its module imports. */
|
|
67
77
|
uses: Set<keyof typeof sdkNames>;
|
|
@@ -112,6 +122,9 @@ const isNative = (
|
|
|
112
122
|
) {
|
|
113
123
|
return false;
|
|
114
124
|
}
|
|
125
|
+
if (!target?.withinStep && crossing.some((item) => item.withinStep)) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
115
128
|
if (kind === "return" || !target) {
|
|
116
129
|
return true;
|
|
117
130
|
}
|
|
@@ -137,33 +150,30 @@ const targetIndex = (
|
|
|
137
150
|
if (kind === "return") {
|
|
138
151
|
return -1;
|
|
139
152
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
continue;
|
|
150
|
-
}
|
|
151
|
-
if (item.kind === "loop" || (kind === "break" && item.kind === "switch")) {
|
|
152
|
-
return index;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return undefined;
|
|
153
|
+
const found = [...stack.entries()]
|
|
154
|
+
.reverse()
|
|
155
|
+
.find(([, item]) =>
|
|
156
|
+
label === undefined
|
|
157
|
+
? item.kind === "loop" || (kind === "break" && item.kind === "switch")
|
|
158
|
+
: item.labels.includes(label),
|
|
159
|
+
);
|
|
160
|
+
return found?.[0];
|
|
156
161
|
};
|
|
157
162
|
|
|
158
163
|
const lowerItems = (items: readonly Item[], loop: Target | undefined): List => {
|
|
159
164
|
const [first, ...others] = items;
|
|
160
165
|
if (!first) {
|
|
161
|
-
return { parts: [], pending: [] };
|
|
166
|
+
return { parts: [], pending: [], changed: false };
|
|
162
167
|
}
|
|
163
168
|
const head = first.lower();
|
|
164
169
|
const tail = lowerItems(others, loop);
|
|
170
|
+
const changed = head.changed || tail.changed;
|
|
165
171
|
if (!head.pending.length) {
|
|
166
|
-
return {
|
|
172
|
+
return {
|
|
173
|
+
parts: [head.text, ...tail.parts],
|
|
174
|
+
pending: tail.pending,
|
|
175
|
+
changed,
|
|
176
|
+
};
|
|
167
177
|
}
|
|
168
178
|
// Directly in a loop's body, a jump past the loop leaves it with EXIT; one continuing it skips the rest.
|
|
169
179
|
const continuing = loop
|
|
@@ -190,12 +200,16 @@ const lowerItems = (items: readonly Item[], loop: Target | undefined): List => {
|
|
|
190
200
|
: joined(tail.parts, " "),
|
|
191
201
|
);
|
|
192
202
|
}
|
|
193
|
-
return {
|
|
203
|
+
return {
|
|
204
|
+
parts,
|
|
205
|
+
pending: unique([...head.pending, ...tail.pending]),
|
|
206
|
+
changed,
|
|
207
|
+
};
|
|
194
208
|
};
|
|
195
209
|
|
|
196
210
|
const statementItems = (
|
|
197
211
|
statements: readonly ts.Statement[],
|
|
198
|
-
routine:
|
|
212
|
+
routine: RoutineScope,
|
|
199
213
|
): Item[] =>
|
|
200
214
|
statements.map((statement) => ({
|
|
201
215
|
origin: statement,
|
|
@@ -205,7 +219,7 @@ const statementItems = (
|
|
|
205
219
|
const lowerList = (
|
|
206
220
|
statements: readonly ts.Statement[],
|
|
207
221
|
loop: Target | undefined,
|
|
208
|
-
routine:
|
|
222
|
+
routine: RoutineScope,
|
|
209
223
|
): List => lowerItems(statementItems(statements, routine), loop);
|
|
210
224
|
|
|
211
225
|
const settled = (pending: readonly Pending[], target: Target): Pending[] =>
|
|
@@ -225,16 +239,23 @@ const declared = (target: Target, node: ts.Node, text: Part): Part => {
|
|
|
225
239
|
);
|
|
226
240
|
};
|
|
227
241
|
|
|
228
|
-
const
|
|
229
|
-
|
|
242
|
+
const withinStep = (node: ts.Statement, routine: RoutineScope): boolean =>
|
|
243
|
+
routine.async &&
|
|
244
|
+
(routine.stack.some((item) => item.withinStep) ||
|
|
245
|
+
copiedWhole(node, routine.source));
|
|
246
|
+
|
|
247
|
+
const unchanged = (node: ts.Node): Lowered => ({
|
|
248
|
+
text: copied(node),
|
|
249
|
+
pending: [],
|
|
250
|
+
changed: false,
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
const lower = (node: ts.Statement, routine: RoutineScope): Lowered => {
|
|
230
254
|
const lowered = lowerStatement(node, routine);
|
|
231
|
-
|
|
232
|
-
return { text: copied(node), pending: [] };
|
|
233
|
-
}
|
|
234
|
-
return lowered;
|
|
255
|
+
return lowered.changed ? lowered : unchanged(node);
|
|
235
256
|
};
|
|
236
257
|
|
|
237
|
-
const lowerStatement = (node: ts.Statement, routine:
|
|
258
|
+
const lowerStatement = (node: ts.Statement, routine: RoutineScope): Lowered => {
|
|
238
259
|
if (ts.isLabeledStatement(node)) {
|
|
239
260
|
return labelled(node, routine);
|
|
240
261
|
}
|
|
@@ -249,6 +270,7 @@ const lowerStatement = (node: ts.Statement, routine: Routine): Lowered => {
|
|
|
249
270
|
return {
|
|
250
271
|
text: from(node, mapped`{ ${joined(list.parts, " ")} }`),
|
|
251
272
|
pending: list.pending,
|
|
273
|
+
changed: list.changed,
|
|
252
274
|
};
|
|
253
275
|
}
|
|
254
276
|
if (ts.isIfStatement(node)) {
|
|
@@ -266,25 +288,33 @@ const lowerStatement = (node: ts.Statement, routine: Routine): Lowered => {
|
|
|
266
288
|
) {
|
|
267
289
|
return jump(node, routine);
|
|
268
290
|
}
|
|
269
|
-
return
|
|
291
|
+
return unchanged(node);
|
|
270
292
|
};
|
|
271
293
|
|
|
272
|
-
|
|
273
|
-
|
|
294
|
+
/** Structured Text has no labels, so a labelled statement always changes. */
|
|
295
|
+
const labelled = (
|
|
296
|
+
node: ts.LabeledStatement,
|
|
297
|
+
routine: RoutineScope,
|
|
298
|
+
): Lowered => {
|
|
274
299
|
const { labels, inner } = unlabelled(node);
|
|
275
300
|
if (ts.isIterationStatement(inner, false)) {
|
|
276
|
-
return loop(inner, labels, routine);
|
|
301
|
+
return { ...loop(inner, labels, routine), changed: true };
|
|
277
302
|
}
|
|
278
303
|
if (ts.isSwitchStatement(inner)) {
|
|
279
|
-
return switchStatement(inner, labels, routine);
|
|
304
|
+
return { ...switchStatement(inner, labels, routine), changed: true };
|
|
280
305
|
}
|
|
281
|
-
const target: Target = {
|
|
306
|
+
const target: Target = {
|
|
307
|
+
kind: "labelled",
|
|
308
|
+
labels,
|
|
309
|
+
withinStep: withinStep(inner, routine),
|
|
310
|
+
};
|
|
282
311
|
routine.stack.push(target);
|
|
283
312
|
const body = lower(inner, routine);
|
|
284
313
|
routine.stack.pop();
|
|
285
314
|
return {
|
|
286
315
|
text: declared(target, node, body.text),
|
|
287
316
|
pending: settled(body.pending, target),
|
|
317
|
+
changed: true,
|
|
288
318
|
};
|
|
289
319
|
};
|
|
290
320
|
|
|
@@ -302,10 +332,13 @@ const unlabelled = (
|
|
|
302
332
|
const loop = (
|
|
303
333
|
node: ts.IterationStatement,
|
|
304
334
|
labels: readonly string[],
|
|
305
|
-
routine:
|
|
335
|
+
routine: RoutineScope,
|
|
306
336
|
): Lowered => {
|
|
307
|
-
const
|
|
308
|
-
|
|
337
|
+
const target: Target = {
|
|
338
|
+
kind: "loop",
|
|
339
|
+
labels,
|
|
340
|
+
withinStep: withinStep(node, routine),
|
|
341
|
+
};
|
|
309
342
|
routine.stack.push(target);
|
|
310
343
|
const body = node.statement;
|
|
311
344
|
const list = lowerList(
|
|
@@ -314,8 +347,8 @@ const loop = (
|
|
|
314
347
|
routine,
|
|
315
348
|
);
|
|
316
349
|
routine.stack.pop();
|
|
317
|
-
if (
|
|
318
|
-
return
|
|
350
|
+
if (!list.changed) {
|
|
351
|
+
return unchanged(node);
|
|
319
352
|
}
|
|
320
353
|
const { source } = routine;
|
|
321
354
|
const reset = target.continueFlag ? `${target.continueFlag} = false; ` : "";
|
|
@@ -323,19 +356,15 @@ const loop = (
|
|
|
323
356
|
return {
|
|
324
357
|
text: declared(target, node, text),
|
|
325
358
|
pending: settled(list.pending, target),
|
|
359
|
+
changed: true,
|
|
326
360
|
};
|
|
327
361
|
};
|
|
328
362
|
|
|
329
|
-
const ifStatement = (node: ts.IfStatement, routine:
|
|
330
|
-
const before = routine.changes;
|
|
363
|
+
const ifStatement = (node: ts.IfStatement, routine: RoutineScope): Lowered => {
|
|
331
364
|
const yes = lower(node.thenStatement, routine);
|
|
332
365
|
const no = node.elseStatement && lower(node.elseStatement, routine);
|
|
333
|
-
if (
|
|
334
|
-
|
|
335
|
-
!yes.pending.length &&
|
|
336
|
-
!no?.pending.length
|
|
337
|
-
) {
|
|
338
|
-
return { text: copied(node), pending: [] };
|
|
366
|
+
if (!yes.changed && !no?.changed) {
|
|
367
|
+
return unchanged(node);
|
|
339
368
|
}
|
|
340
369
|
const { source } = routine;
|
|
341
370
|
const head = copiedRange(
|
|
@@ -350,6 +379,7 @@ const ifStatement = (node: ts.IfStatement, routine: Routine): Lowered => {
|
|
|
350
379
|
return {
|
|
351
380
|
text: mapped`${head}${yes.text}${otherwise}`,
|
|
352
381
|
pending: unique([...yes.pending, ...(no?.pending ?? [])]),
|
|
382
|
+
changed: true,
|
|
353
383
|
};
|
|
354
384
|
};
|
|
355
385
|
|
|
@@ -360,22 +390,24 @@ const ifStatement = (node: ts.IfStatement, routine: Routine): Lowered => {
|
|
|
360
390
|
const switchStatement = (
|
|
361
391
|
node: ts.SwitchStatement,
|
|
362
392
|
labels: readonly string[],
|
|
363
|
-
routine:
|
|
393
|
+
routine: RoutineScope,
|
|
364
394
|
): Lowered => {
|
|
365
|
-
const
|
|
366
|
-
|
|
395
|
+
const target: Target = {
|
|
396
|
+
kind: "switch",
|
|
397
|
+
labels,
|
|
398
|
+
withinStep: withinStep(node, routine),
|
|
399
|
+
};
|
|
367
400
|
routine.stack.push(target);
|
|
368
401
|
const { source } = routine;
|
|
369
402
|
const bodies = node.caseBlock.clauses.map((clause) =>
|
|
370
403
|
unbraced(clause.statements),
|
|
371
404
|
);
|
|
372
|
-
const
|
|
373
|
-
const clauses = node.caseBlock.clauses.map((clause, index) => {
|
|
405
|
+
const clauses = node.caseBlock.clauses.map((clause, index): Lowered => {
|
|
374
406
|
const label = ts.isCaseClause(clause)
|
|
375
407
|
? mapped`case ${copied(clause.expression)}:`
|
|
376
408
|
: "default:";
|
|
377
409
|
if (!bodies[index]?.length) {
|
|
378
|
-
return from(clause, label);
|
|
410
|
+
return { text: from(clause, label), pending: [], changed: false };
|
|
379
411
|
}
|
|
380
412
|
const chain: (readonly ts.Statement[])[] = [];
|
|
381
413
|
for (const body of bodies.slice(index)) {
|
|
@@ -387,9 +419,6 @@ const switchStatement = (
|
|
|
387
419
|
break;
|
|
388
420
|
}
|
|
389
421
|
}
|
|
390
|
-
if (chain.length > 1) {
|
|
391
|
-
routine.changes++;
|
|
392
|
-
}
|
|
393
422
|
const last = chain.at(-1) ?? [];
|
|
394
423
|
const end = last.at(-1);
|
|
395
424
|
const ending =
|
|
@@ -405,45 +434,54 @@ const switchStatement = (
|
|
|
405
434
|
return {
|
|
406
435
|
text: from(clause, mapped`{ ${joined(list.parts, " ")} }`),
|
|
407
436
|
pending: list.pending,
|
|
437
|
+
changed: list.changed,
|
|
408
438
|
};
|
|
409
439
|
},
|
|
410
440
|
}));
|
|
411
441
|
const list = lowerItems(items, undefined);
|
|
412
|
-
pending.push(...list.pending);
|
|
413
442
|
const returns =
|
|
414
443
|
end !== undefined &&
|
|
415
444
|
(ts.isReturnStatement(end) || ts.isThrowStatement(end)) &&
|
|
416
445
|
!list.pending.length;
|
|
417
446
|
const body = joined(list.parts, " ");
|
|
418
|
-
return
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
447
|
+
return {
|
|
448
|
+
text: from(
|
|
449
|
+
clause,
|
|
450
|
+
returns
|
|
451
|
+
? mapped`${label} { ${body} }`
|
|
452
|
+
: mapped`${label} { ${body} } break;`,
|
|
453
|
+
),
|
|
454
|
+
pending: list.pending,
|
|
455
|
+
// A case that runs on into the next one is a change in itself.
|
|
456
|
+
changed: chain.length > 1 || list.changed,
|
|
457
|
+
};
|
|
424
458
|
});
|
|
425
459
|
routine.stack.pop();
|
|
426
|
-
if (
|
|
427
|
-
return
|
|
460
|
+
if (!clauses.some((clause) => clause.changed)) {
|
|
461
|
+
return unchanged(node);
|
|
428
462
|
}
|
|
429
|
-
|
|
430
|
-
|
|
463
|
+
const text = mapped`${copiedRange(source, node.getStart(source), node.caseBlock.getStart(source))}{ ${joined(
|
|
464
|
+
clauses.map((clause) => clause.text),
|
|
465
|
+
" ",
|
|
466
|
+
)} }`;
|
|
431
467
|
return {
|
|
432
468
|
text: declared(target, node, text),
|
|
433
|
-
pending: settled(
|
|
469
|
+
pending: settled(
|
|
470
|
+
unique(clauses.flatMap((clause) => clause.pending)),
|
|
471
|
+
target,
|
|
472
|
+
),
|
|
473
|
+
changed: true,
|
|
434
474
|
};
|
|
435
475
|
};
|
|
436
476
|
|
|
437
|
-
const tryStatement = (
|
|
438
|
-
|
|
477
|
+
const tryStatement = (
|
|
478
|
+
node: ts.TryStatement,
|
|
479
|
+
routine: RoutineScope,
|
|
480
|
+
): Lowered => {
|
|
439
481
|
const attempt = lower(node.tryBlock, routine);
|
|
440
482
|
const caught = node.catchClause && lower(node.catchClause.block, routine);
|
|
441
|
-
if (
|
|
442
|
-
|
|
443
|
-
!attempt.pending.length &&
|
|
444
|
-
!caught?.pending.length
|
|
445
|
-
) {
|
|
446
|
-
return { text: copied(node), pending: [] };
|
|
483
|
+
if (!attempt.changed && !caught?.changed) {
|
|
484
|
+
return unchanged(node);
|
|
447
485
|
}
|
|
448
486
|
const { source } = routine;
|
|
449
487
|
const recovery =
|
|
@@ -453,6 +491,7 @@ const tryStatement = (node: ts.TryStatement, routine: Routine): Lowered => {
|
|
|
453
491
|
return {
|
|
454
492
|
text: mapped`${copiedRange(source, node.getStart(source), node.tryBlock.getStart(source))}${attempt.text}${recovery}`,
|
|
455
493
|
pending: unique([...attempt.pending, ...(caught?.pending ?? [])]),
|
|
494
|
+
changed: true,
|
|
456
495
|
};
|
|
457
496
|
};
|
|
458
497
|
|
|
@@ -463,10 +502,14 @@ const tryStatement = (node: ts.TryStatement, routine: Routine): Lowered => {
|
|
|
463
502
|
const finallyStatement = (
|
|
464
503
|
node: ts.TryStatement,
|
|
465
504
|
finallyBlock: ts.Block,
|
|
466
|
-
routine:
|
|
505
|
+
routine: RoutineScope,
|
|
467
506
|
): Lowered => {
|
|
468
|
-
|
|
469
|
-
|
|
507
|
+
const target: Target = {
|
|
508
|
+
kind: "finally",
|
|
509
|
+
labels: [],
|
|
510
|
+
withinStep: withinStep(node, routine),
|
|
511
|
+
region: "try",
|
|
512
|
+
};
|
|
470
513
|
routine.stack.push(target);
|
|
471
514
|
const attempt = lowerList(node.tryBlock.statements, undefined, routine);
|
|
472
515
|
target.region = "catch";
|
|
@@ -488,7 +531,6 @@ const finallyStatement = (
|
|
|
488
531
|
const parts: Part[] = [...guarded.parts];
|
|
489
532
|
parts.push(mapped`{ ${joined(final.parts, " ")} }`);
|
|
490
533
|
|
|
491
|
-
// Held jumps Structured Text can now make go straight on; the rest stay held for the statements around.
|
|
492
534
|
const resumed: string[] = guarded.rethrow ? [guarded.rethrow] : [];
|
|
493
535
|
const still: Pending[] = [];
|
|
494
536
|
for (const item of held) {
|
|
@@ -515,6 +557,7 @@ const finallyStatement = (
|
|
|
515
557
|
return {
|
|
516
558
|
text: from(node, mapped`{ ${joined(parts, " ")} }`),
|
|
517
559
|
pending: unique([...still, ...final.pending]),
|
|
560
|
+
changed: true,
|
|
518
561
|
};
|
|
519
562
|
};
|
|
520
563
|
|
|
@@ -523,7 +566,7 @@ const caughtAttempt = (
|
|
|
523
566
|
node: ts.TryStatement,
|
|
524
567
|
attempt: List,
|
|
525
568
|
caught: List | undefined,
|
|
526
|
-
routine:
|
|
569
|
+
routine: RoutineScope,
|
|
527
570
|
): { parts: Part[]; rethrow: string } => {
|
|
528
571
|
const throwing = routine.name("tsplcThrowing");
|
|
529
572
|
const error = routine.name("tsplcError");
|
|
@@ -557,31 +600,21 @@ const caughtAttempt = (
|
|
|
557
600
|
|
|
558
601
|
const jump = (
|
|
559
602
|
node: ts.BreakStatement | ts.ContinueStatement | ts.ReturnStatement,
|
|
560
|
-
routine:
|
|
603
|
+
routine: RoutineScope,
|
|
561
604
|
): Lowered => {
|
|
562
|
-
const kind
|
|
563
|
-
? "break"
|
|
564
|
-
: ts.isContinueStatement(node)
|
|
565
|
-
? "continue"
|
|
566
|
-
: "return";
|
|
567
|
-
const label =
|
|
568
|
-
ts.isBreakStatement(node) || ts.isContinueStatement(node)
|
|
569
|
-
? node.label?.text
|
|
570
|
-
: undefined;
|
|
605
|
+
const { kind, label } = jumpOf(node);
|
|
571
606
|
const index = targetIndex(kind, label, routine.stack);
|
|
572
607
|
if (index === undefined) {
|
|
573
|
-
return
|
|
608
|
+
return unchanged(node);
|
|
574
609
|
}
|
|
575
610
|
const target = index >= 0 ? routine.stack[index] : undefined;
|
|
576
611
|
const crossing = routine.stack.slice(index + 1);
|
|
577
612
|
if (isNative(kind, target, crossing) && label === undefined) {
|
|
578
|
-
return
|
|
613
|
+
return unchanged(node);
|
|
579
614
|
}
|
|
580
615
|
if (isNative(kind, target, crossing)) {
|
|
581
|
-
|
|
582
|
-
return { text: from(node, `${kind};`), pending: [] };
|
|
616
|
+
return { text: from(node, `${kind};`), pending: [], changed: true };
|
|
583
617
|
}
|
|
584
|
-
routine.changes++;
|
|
585
618
|
const flag = flagFor(kind, target, routine);
|
|
586
619
|
const value =
|
|
587
620
|
ts.isReturnStatement(node) && node.expression && routine.result?.value
|
|
@@ -591,13 +624,26 @@ const jump = (
|
|
|
591
624
|
return {
|
|
592
625
|
text: from(node, mapped`{ ${flag} = true; ${value}${exit} }`),
|
|
593
626
|
pending: [{ kind, flag, target }],
|
|
627
|
+
changed: true,
|
|
594
628
|
};
|
|
595
629
|
};
|
|
596
630
|
|
|
631
|
+
const jumpOf = (
|
|
632
|
+
node: ts.BreakStatement | ts.ContinueStatement | ts.ReturnStatement,
|
|
633
|
+
): { kind: JumpKind; label: string | undefined } => {
|
|
634
|
+
if (ts.isBreakStatement(node)) {
|
|
635
|
+
return { kind: "break", label: node.label?.text };
|
|
636
|
+
}
|
|
637
|
+
if (ts.isContinueStatement(node)) {
|
|
638
|
+
return { kind: "continue", label: node.label?.text };
|
|
639
|
+
}
|
|
640
|
+
return { kind: "return", label: undefined };
|
|
641
|
+
};
|
|
642
|
+
|
|
597
643
|
const flagFor = (
|
|
598
644
|
kind: JumpKind,
|
|
599
645
|
target: Target | undefined,
|
|
600
|
-
routine:
|
|
646
|
+
routine: RoutineScope,
|
|
601
647
|
): string => {
|
|
602
648
|
if (!target) {
|
|
603
649
|
routine.result ??= {
|
|
@@ -641,16 +687,9 @@ const resultType = (
|
|
|
641
687
|
return undefined;
|
|
642
688
|
}
|
|
643
689
|
const annotation = node.type;
|
|
644
|
-
const isAsync = node.
|
|
645
|
-
(modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword,
|
|
646
|
-
);
|
|
690
|
+
const isAsync = hasModifier(node, ts.SyntaxKind.AsyncKeyword);
|
|
647
691
|
if (annotation) {
|
|
648
|
-
const inner =
|
|
649
|
-
isAsync &&
|
|
650
|
-
ts.isTypeReferenceNode(annotation) &&
|
|
651
|
-
annotation.typeName.getText() === "Promise"
|
|
652
|
-
? annotation.typeArguments?.[0]
|
|
653
|
-
: annotation;
|
|
692
|
+
const inner = isAsync ? promisedType(annotation) : annotation;
|
|
654
693
|
if (!inner || inner.kind === ts.SyntaxKind.VoidKeyword) {
|
|
655
694
|
return undefined;
|
|
656
695
|
}
|
|
@@ -674,20 +713,16 @@ const sdkNames = {
|
|
|
674
713
|
errorCode: "tsplcHeldErrorCode",
|
|
675
714
|
} as const;
|
|
676
715
|
|
|
677
|
-
const
|
|
678
|
-
defaultValue:
|
|
679
|
-
errorCode:
|
|
716
|
+
const sdkNameModules: Record<keyof typeof sdkNames, string> = {
|
|
717
|
+
defaultValue: sdkModules.types,
|
|
718
|
+
errorCode: sdkModules.async,
|
|
680
719
|
};
|
|
681
720
|
|
|
682
721
|
/** Lowers the jumps, labels, fallthrough and finally blocks Structured Text can't express in every routine. */
|
|
683
722
|
export const lowerControlFlow = (program: ts.Program) => {
|
|
684
723
|
const checker = program.getTypeChecker();
|
|
685
724
|
const sources = new Map<string, Mapped>();
|
|
686
|
-
const
|
|
687
|
-
for (const source of runtimeSources(program)) {
|
|
688
|
-
if (source.isDeclarationFile) {
|
|
689
|
-
continue;
|
|
690
|
-
}
|
|
725
|
+
for (const source of plcSources(program)) {
|
|
691
726
|
const edits: Edit[] = [];
|
|
692
727
|
let counter = 0;
|
|
693
728
|
const uses = new Set<keyof typeof sdkNames>();
|
|
@@ -698,21 +733,18 @@ export const lowerControlFlow = (program: ts.Program) => {
|
|
|
698
733
|
return;
|
|
699
734
|
}
|
|
700
735
|
const body = node.body;
|
|
701
|
-
const routine:
|
|
736
|
+
const routine: RoutineScope = {
|
|
702
737
|
source,
|
|
703
|
-
async:
|
|
704
|
-
node.
|
|
705
|
-
|
|
706
|
-
),
|
|
707
|
-
),
|
|
738
|
+
async:
|
|
739
|
+
hasModifier(node, ts.SyntaxKind.AsyncKeyword) ||
|
|
740
|
+
promiseCallback(node),
|
|
708
741
|
stack: [],
|
|
709
742
|
resultType: resultType(node, checker),
|
|
710
|
-
changes: 0,
|
|
711
743
|
name,
|
|
712
744
|
uses,
|
|
713
745
|
};
|
|
714
746
|
const list = lowerList(body.statements, undefined, routine);
|
|
715
|
-
if (!
|
|
747
|
+
if (!list.changed) {
|
|
716
748
|
ts.forEachChild(node, visit);
|
|
717
749
|
return;
|
|
718
750
|
}
|
|
@@ -726,12 +758,15 @@ export const lowerControlFlow = (program: ts.Program) => {
|
|
|
726
758
|
);
|
|
727
759
|
}
|
|
728
760
|
}
|
|
761
|
+
// Only a return can still be held here, and every other path through the routine returns.
|
|
762
|
+
const value = list.pending.length ? routine.result?.value : undefined;
|
|
763
|
+
const resumed = value ? [`return ${value};`] : [];
|
|
729
764
|
edits.push({
|
|
730
765
|
start: body.getStart(source),
|
|
731
766
|
end: body.end,
|
|
732
767
|
text: from(
|
|
733
768
|
body,
|
|
734
|
-
mapped`{ ${declarations.join(" ")} ${joined(list.parts, "\n")} }`,
|
|
769
|
+
mapped`{ ${declarations.join(" ")} ${joined([...list.parts, ...resumed], "\n")} }`,
|
|
735
770
|
),
|
|
736
771
|
});
|
|
737
772
|
};
|
|
@@ -743,10 +778,10 @@ export const lowerControlFlow = (program: ts.Program) => {
|
|
|
743
778
|
edits.push({
|
|
744
779
|
start: 0,
|
|
745
780
|
end: 0,
|
|
746
|
-
text: `import { ${used} as ${sdkNames[used]} } from "${
|
|
781
|
+
text: `import { ${used} as ${sdkNames[used]} } from "${sdkNameModules[used]}";\n`,
|
|
747
782
|
});
|
|
748
783
|
}
|
|
749
784
|
sources.set(source.fileName, edited(source, edits));
|
|
750
785
|
}
|
|
751
|
-
return { sources, diagnostics };
|
|
786
|
+
return { sources, diagnostics: [] };
|
|
752
787
|
};
|
|
@@ -20,6 +20,15 @@ interface Worker {
|
|
|
20
20
|
declaration: string;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
/** The shared diagnostics instance that the promise pass declares and detached chains report failures to. */
|
|
24
|
+
export const diagnosticsInstance = "tsplcPromiseDiagnostics";
|
|
25
|
+
/** The SDK's `wrapAdd` as the promise pass imports it into generated code. */
|
|
26
|
+
export const asyncWrapAdd = "tsplcAsyncWrapAdd";
|
|
27
|
+
/** The SDK's `cooperativeTasks` as the promise pass imports it into generated code. */
|
|
28
|
+
export const cooperativeTasksAlias = "tsplcCooperative";
|
|
29
|
+
/** The SDK's `errorCode` as the promise pass imports it into generated code. */
|
|
30
|
+
export const errorCodeAlias = "tsplcErrorCode";
|
|
31
|
+
|
|
23
32
|
/** A value as generated code stores it: records and arrays are copied, as TypeScript would share them. */
|
|
24
33
|
export const copyValue = (value: Part, aggregate: boolean) =>
|
|
25
34
|
aggregate ? mapped`copy(${value})` : value;
|
|
@@ -36,9 +45,7 @@ export const cooperativeSite = (
|
|
|
36
45
|
const member = (label: string) => `this.${field(label)}`;
|
|
37
46
|
const method = (label: string) => (inline ? `${name}_${label}` : label);
|
|
38
47
|
const invoke = (label: string, args = "") => `this.${method(label)}(${args})`;
|
|
39
|
-
const
|
|
40
|
-
aggregate ? `copy(${value})` : value;
|
|
41
|
-
const faults = `${member("faults")}=tsplcAsyncWrapAdd<UDINT>(${member("faults")},1);${member("lastError")}=7;`;
|
|
48
|
+
const faults = `${member("faults")}=${asyncWrapAdd}<UDINT>(${member("faults")},1);${member("lastError")}=${jobError.noRequestSlot};`;
|
|
42
49
|
const signature = parameters
|
|
43
50
|
.map((parameter) => `${parameter.name}:${parameter.type}`)
|
|
44
51
|
.join(",");
|
|
@@ -51,14 +58,14 @@ ${parameters.map((parameter) => `private ${field(`queued_${parameter.name}`)}:${
|
|
|
51
58
|
${worker.declaration}`;
|
|
52
59
|
const body = `${fields}
|
|
53
60
|
public ${method("begin")}(${signature}):void{const accepted:BOOL=${worker.start}(${args});if(!accepted){${faults}return;}${member("active")}=true;${member("fresh")}=true;${member("cancelled")}=false;${worker.advance}({cancel:false});}
|
|
54
|
-
public ${method("start")}(${signature}):void{if(${member("active")}){if(${member("cancelled")}&&!${member("queued")}){${parameters.map((parameter) => `${member(`queued_${parameter.name}`)}=${
|
|
61
|
+
public ${method("start")}(${signature}):void{if(${member("active")}){if(${member("cancelled")}&&!${member("queued")}){${parameters.map((parameter) => `${member(`queued_${parameter.name}`)}=${copyValue(parameter.name, parameter.aggregate)};`).join("")}${member("queued")}=true;}else{${faults}}return;}${invoke("begin", args)};}
|
|
55
62
|
public ${method("cancel")}():void{${member("cancelled")}=true;${member("queued")}=false;}
|
|
56
63
|
public ${method("poll")}():void{
|
|
57
|
-
if(${member("faults")}>0
|
|
64
|
+
if(${member("faults")}>0&&${diagnosticsInstance}.report(${member("lastError")},${member("faults")}))${member("faults")}=0;
|
|
58
65
|
if(!${member("active")})return;
|
|
59
66
|
if(${member("fresh")}&&!${member("cancelled")}){${member("fresh")}=false;return;}
|
|
60
67
|
${worker.advance}({cancel:${member("cancelled")}});const state=${worker.snapshot}();if(!state.done)return;
|
|
61
|
-
if(!${member("cancelled")}&&state.error!==0&&state.error
|
|
68
|
+
if(!${member("cancelled")}&&state.error!==0&&state.error!==${jobError.cancelled}){${member("faults")}=${asyncWrapAdd}<UDINT>(${member("faults")},1);${member("lastError")}=state.error;}
|
|
62
69
|
${worker.reset}();${member("active")}=false;
|
|
63
70
|
if(${member("queued")}){${member("queued")}=false;${invoke("begin", queued)};}
|
|
64
71
|
}`;
|
|
@@ -80,13 +87,14 @@ export const taskSite = (
|
|
|
80
87
|
value: { type: string; aggregate: boolean },
|
|
81
88
|
): Site => {
|
|
82
89
|
const method = (label: string) => (inline ? `${name}_${label}` : label);
|
|
83
|
-
const
|
|
90
|
+
const cancelledField = inline ? `${name}_cancelled` : "cancelled";
|
|
91
|
+
const cancelled = `this.${cancelledField}`;
|
|
84
92
|
const signature = parameters
|
|
85
93
|
.map((parameter) => `${parameter.name}:${parameter.type}`)
|
|
86
94
|
.join(",");
|
|
87
95
|
const args = parameters.map((parameter) => parameter.name).join(",");
|
|
88
|
-
const result =
|
|
89
|
-
const body = `private ${
|
|
96
|
+
const result = copyValue("state.result", value.aggregate);
|
|
97
|
+
const body = `private ${cancelledField}:BOOL=false;
|
|
90
98
|
${worker.declaration}
|
|
91
99
|
public ${method("start")}(${signature}):BOOL{const accepted:BOOL=${worker.start}(${args});if(accepted){${cancelled}=false;${worker.advance}({cancel:false});}return accepted;}
|
|
92
100
|
public ${method("cancel")}():BOOL{const state=${worker.snapshot}();if(!state.busy&&!state.done)return false;${cancelled}=true;return true;}
|