@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,12 +1,11 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
import { type Mapped, mapped, type Part } from "../positions";
|
|
3
|
-
import
|
|
3
|
+
import { unparenthesized } from "../types";
|
|
4
|
+
import { storeStatement } from "./assignments";
|
|
4
5
|
import type { ExpressionSpecializer, SpecializeContext } from "./expressions";
|
|
5
6
|
import type { Frame } from "./frame";
|
|
6
|
-
import type { Initializers } from "./initializers";
|
|
7
7
|
import { isAbsent } from "./layouts";
|
|
8
|
-
import
|
|
9
|
-
import type { Storage } from "./storage";
|
|
8
|
+
import { type ModelNode, unionMembers } from "./model";
|
|
10
9
|
import { constant, SpecializeError, type Value } from "./values";
|
|
11
10
|
|
|
12
11
|
type Choice = Extract<Value, { kind: "choice" }>;
|
|
@@ -18,18 +17,25 @@ interface PlaceInEach {
|
|
|
18
17
|
place: (option: ModelNode) => Value;
|
|
19
18
|
}
|
|
20
19
|
|
|
21
|
-
/** The PLC type of a reference: the id of the object it refers to, or
|
|
20
|
+
/** The PLC type of a reference: the id of the object it refers to, or `noReference` for undefined. */
|
|
22
21
|
export const referenceLayout = "number";
|
|
23
22
|
|
|
23
|
+
/** What a reference holds when it is undefined. */
|
|
24
|
+
export const noReference = "-1";
|
|
25
|
+
|
|
26
|
+
/** Code for whether a reference holds an object. */
|
|
27
|
+
export const present = (index: string | Mapped): Mapped =>
|
|
28
|
+
mapped`${index} >= 0`;
|
|
29
|
+
|
|
30
|
+
/** Code for whether a reference is undefined. */
|
|
31
|
+
export const absent = (index: string | Mapped): Mapped => mapped`${index} < 0`;
|
|
32
|
+
|
|
24
33
|
/** Whether a type's values are class instances, or undefined: what scan code holds by reference rather than as a copy. */
|
|
25
34
|
export const referenceType = (type: ts.Type): boolean => {
|
|
26
|
-
const defined =
|
|
35
|
+
const defined = unionMembers(type).filter((part) => !isAbsent(part));
|
|
27
36
|
return defined.length > 0 && defined.every(isInstanceType);
|
|
28
37
|
};
|
|
29
38
|
|
|
30
|
-
const parts = (type: ts.Type): readonly ts.Type[] =>
|
|
31
|
-
type.isUnion() ? type.types : [type];
|
|
32
|
-
|
|
33
39
|
/** A class's instances, not the class itself, which its constructor's type shares a symbol with. */
|
|
34
40
|
const isInstanceType = (type: ts.Type): boolean =>
|
|
35
41
|
Boolean(type.flags & ts.TypeFlags.Object) &&
|
|
@@ -58,7 +64,7 @@ export const referenceIndex = (value: Value): string | Mapped | undefined => {
|
|
|
58
64
|
return String(value.node.reference);
|
|
59
65
|
}
|
|
60
66
|
if (value.kind === "const" && value.value === undefined) {
|
|
61
|
-
return
|
|
67
|
+
return noReference;
|
|
62
68
|
}
|
|
63
69
|
return undefined;
|
|
64
70
|
};
|
|
@@ -75,34 +81,30 @@ const optionsOf = (value: Value): readonly ModelNode[] => {
|
|
|
75
81
|
const absentOf = (value: Value): boolean =>
|
|
76
82
|
value.kind === "choice" ? value.optional : value.kind === "const";
|
|
77
83
|
|
|
84
|
+
/**
|
|
85
|
+
* The objects references among the values can be, and whether one can be undefined; undefined
|
|
86
|
+
* when none of the values is an object setup built.
|
|
87
|
+
*/
|
|
88
|
+
export const references = (
|
|
89
|
+
values: readonly Value[],
|
|
90
|
+
): { options: readonly ModelNode[]; optional: boolean } | undefined => {
|
|
91
|
+
const options = values.flatMap(optionsOf);
|
|
92
|
+
if (!options.length) {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
// In the order setup built them, so the code over them is the same every build.
|
|
97
|
+
options: [...new Set(options)].sort((left, right) => left.id - right.id),
|
|
98
|
+
optional: values.some(absentOf),
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
|
|
78
102
|
/** Objects without repeats, in the order of their reference ids, so the code over them is the same every build. */
|
|
79
103
|
export const union = (nodes: readonly ModelNode[]): ModelNode[] =>
|
|
80
104
|
[...new Set(nodes)].sort((left, right) => left.reference - right.reference);
|
|
81
105
|
|
|
82
|
-
const maybeAbsent = (type: ts.Type): boolean =>
|
|
83
|
-
|
|
84
|
-
const unparenthesized = (node: ts.Expression): ts.Expression =>
|
|
85
|
-
ts.isParenthesizedExpression(node) || ts.isNonNullExpression(node)
|
|
86
|
-
? unparenthesized(node.expression)
|
|
87
|
-
: node;
|
|
88
|
-
|
|
89
|
-
/** An if…else if chain, one arm for each test. */
|
|
90
|
-
export const chain = (
|
|
91
|
-
frame: Frame,
|
|
92
|
-
arms: readonly { test: Part; body: VoidFunction }[],
|
|
93
|
-
): void => {
|
|
94
|
-
arms.forEach((arm, index) => {
|
|
95
|
-
if (index === 0) {
|
|
96
|
-
frame.emitter.open(mapped`if (${arm.test}) {`);
|
|
97
|
-
} else {
|
|
98
|
-
frame.emitter.reopen(mapped`} else if (${arm.test}) {`);
|
|
99
|
-
}
|
|
100
|
-
arm.body();
|
|
101
|
-
});
|
|
102
|
-
if (arms.length > 0) {
|
|
103
|
-
frame.emitter.close();
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
+
const maybeAbsent = (type: ts.Type): boolean =>
|
|
107
|
+
unionMembers(type).some(isAbsent);
|
|
106
108
|
|
|
107
109
|
/** A reference that can only be one object is that object, and one that can be none is undefined. */
|
|
108
110
|
export const settled = (choice: Choice): Value => {
|
|
@@ -121,27 +123,24 @@ export const settled = (choice: Choice): Value => {
|
|
|
121
123
|
* filter decided at run time is its candidates with a flag each.
|
|
122
124
|
*/
|
|
123
125
|
export class References {
|
|
124
|
-
private readonly model: Model;
|
|
125
|
-
private readonly checker: ts.TypeChecker;
|
|
126
|
-
private readonly dialect: DialectText;
|
|
127
|
-
private readonly storage: Storage;
|
|
128
|
-
private readonly initializers: Initializers;
|
|
129
126
|
private readonly instances = new Map<string, ModelNode[]>();
|
|
130
127
|
|
|
131
128
|
constructor(
|
|
132
|
-
context: SpecializeContext,
|
|
129
|
+
private readonly context: SpecializeContext,
|
|
133
130
|
private readonly expressions: ExpressionSpecializer,
|
|
134
|
-
) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
this.
|
|
138
|
-
|
|
139
|
-
|
|
131
|
+
) {}
|
|
132
|
+
|
|
133
|
+
private get model() {
|
|
134
|
+
return this.context.model;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
private get checker() {
|
|
138
|
+
return this.context.checker;
|
|
140
139
|
}
|
|
141
140
|
|
|
142
141
|
/** Every instance setup built of the classes a type names, or of their subclasses: what a reference of that type can hold. */
|
|
143
142
|
candidates(type: ts.Type): ModelNode[] {
|
|
144
|
-
const classes =
|
|
143
|
+
const classes = unionMembers(type).flatMap(classesOf);
|
|
145
144
|
const key = classes
|
|
146
145
|
.map((owner) => `${owner.getSourceFile().fileName}:${owner.pos}`)
|
|
147
146
|
.join("|");
|
|
@@ -164,7 +163,10 @@ export class References {
|
|
|
164
163
|
|
|
165
164
|
/** A field read from an instance: one that stores a reference reads as the choice it holds. */
|
|
166
165
|
field(read: Value, holder: ModelNode, name: string): Value {
|
|
167
|
-
if (
|
|
166
|
+
if (
|
|
167
|
+
read.kind !== "code" ||
|
|
168
|
+
!this.context.storage.referenceField(holder, name)
|
|
169
|
+
) {
|
|
168
170
|
return read;
|
|
169
171
|
}
|
|
170
172
|
const declared = read.declared;
|
|
@@ -174,7 +176,6 @@ export class References {
|
|
|
174
176
|
index: read.text,
|
|
175
177
|
optional: declared ? maybeAbsent(declared) : true,
|
|
176
178
|
place: true,
|
|
177
|
-
...(read.setter && { setter: read.setter }),
|
|
178
179
|
};
|
|
179
180
|
}
|
|
180
181
|
|
|
@@ -183,7 +184,7 @@ export class References {
|
|
|
183
184
|
return choice.optional
|
|
184
185
|
? {
|
|
185
186
|
kind: "code",
|
|
186
|
-
text: mapped`(${choice.index}
|
|
187
|
+
text: mapped`(${present(choice.index)})`,
|
|
187
188
|
declared: this.checker.getBooleanType(),
|
|
188
189
|
}
|
|
189
190
|
: constant(true);
|
|
@@ -220,11 +221,11 @@ export class References {
|
|
|
220
221
|
return mapped`(${choice.index} === ${other.index})`;
|
|
221
222
|
case "static":
|
|
222
223
|
return choice.options.includes(other.node)
|
|
223
|
-
? mapped`(${choice
|
|
224
|
+
? mapped`(${holds(choice, other.node)})`
|
|
224
225
|
: false;
|
|
225
226
|
case "const":
|
|
226
227
|
return other.value === undefined && choice.optional
|
|
227
|
-
? mapped`(${choice.index}
|
|
228
|
+
? mapped`(${absent(choice.index)})`
|
|
228
229
|
: false;
|
|
229
230
|
case "code":
|
|
230
231
|
return undefined;
|
|
@@ -334,18 +335,14 @@ export class References {
|
|
|
334
335
|
"Assign an object setup built that this reference can hold, or undefined.",
|
|
335
336
|
);
|
|
336
337
|
}
|
|
337
|
-
frame.emitter.line(
|
|
338
|
-
target.setter
|
|
339
|
-
? mapped`${target.setter}(${index});`
|
|
340
|
-
: mapped`${target.index} = ${index};`,
|
|
341
|
-
);
|
|
338
|
+
frame.emitter.line(storeStatement(target.index, index));
|
|
342
339
|
};
|
|
343
340
|
if (operator === ts.SyntaxKind.EqualsToken) {
|
|
344
341
|
store();
|
|
345
342
|
return target;
|
|
346
343
|
}
|
|
347
344
|
if (operator === ts.SyntaxKind.QuestionQuestionEqualsToken) {
|
|
348
|
-
frame.emitter.open(mapped`if (${target.index}
|
|
345
|
+
frame.emitter.open(mapped`if (${absent(target.index)}) {`);
|
|
349
346
|
store();
|
|
350
347
|
frame.emitter.close();
|
|
351
348
|
return target;
|
|
@@ -361,7 +358,7 @@ export class References {
|
|
|
361
358
|
* is a different place in each object the reference can be, so the caller writes each.
|
|
362
359
|
*/
|
|
363
360
|
target(node: ts.Expression, frame: Frame): Value | PlaceInEach {
|
|
364
|
-
const place = unparenthesized(node);
|
|
361
|
+
const place = unparenthesized(node, { nonNull: true });
|
|
365
362
|
// Only an object of a class is reached by reference; `this` is the instance being specialized.
|
|
366
363
|
if (
|
|
367
364
|
!ts.isPropertyAccessExpression(place) ||
|
|
@@ -389,19 +386,14 @@ export class References {
|
|
|
389
386
|
|
|
390
387
|
/** Runs `write` on the object a reference holds: a branch for each object it can be. */
|
|
391
388
|
each(choice: Choice, frame: Frame, write: (option: ModelNode) => void): void {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
lines: frame.emitter.detached({ nested: true }, () => write(option))
|
|
395
|
-
.lines,
|
|
396
|
-
}));
|
|
397
|
-
chain(
|
|
389
|
+
branches(
|
|
390
|
+
choice,
|
|
398
391
|
frame,
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
.
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
})),
|
|
392
|
+
choice.options.map((option) => ({
|
|
393
|
+
option,
|
|
394
|
+
lines: frame.emitter.detached({ nested: true }, () => write(option))
|
|
395
|
+
.lines,
|
|
396
|
+
})),
|
|
405
397
|
);
|
|
406
398
|
}
|
|
407
399
|
|
|
@@ -438,13 +430,11 @@ export class References {
|
|
|
438
430
|
/** The declared type of a member every object of a reference has, from one of them. */
|
|
439
431
|
private memberType(option: ModelNode, name: string): ts.Type | undefined {
|
|
440
432
|
if (option.captured.kind === "instance") {
|
|
441
|
-
const accessor = this.model
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
member.name.getText() === name,
|
|
447
|
-
);
|
|
433
|
+
const accessor = this.model.memberNamed(
|
|
434
|
+
this.model.classOf(option),
|
|
435
|
+
name,
|
|
436
|
+
ts.isGetAccessorDeclaration,
|
|
437
|
+
);
|
|
448
438
|
const signature =
|
|
449
439
|
accessor && this.checker.getSignatureFromDeclaration(accessor);
|
|
450
440
|
if (signature) {
|
|
@@ -478,8 +468,6 @@ export class References {
|
|
|
478
468
|
if (!first) {
|
|
479
469
|
return constant(undefined);
|
|
480
470
|
}
|
|
481
|
-
const test = (option: ModelNode): Mapped =>
|
|
482
|
-
mapped`${choice.index} === ${option.reference}`;
|
|
483
471
|
const known = first.value;
|
|
484
472
|
if (
|
|
485
473
|
known.kind === "const" &&
|
|
@@ -487,29 +475,27 @@ export class References {
|
|
|
487
475
|
(arm) => arm.value.kind === "const" && arm.value.value === known.value,
|
|
488
476
|
)
|
|
489
477
|
) {
|
|
490
|
-
|
|
491
|
-
frame,
|
|
492
|
-
arms
|
|
493
|
-
.filter((arm) => arm.lines.length > 0)
|
|
494
|
-
.map((arm) => ({
|
|
495
|
-
test: test(arm.option),
|
|
496
|
-
body: () => frame.emitter.append(arm.lines),
|
|
497
|
-
})),
|
|
498
|
-
);
|
|
478
|
+
branches(choice, frame, arms);
|
|
499
479
|
return known;
|
|
500
480
|
}
|
|
501
481
|
const result = frame.emitter.temporary();
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
482
|
+
const referred = arms.map((arm) => ({
|
|
483
|
+
...arm,
|
|
484
|
+
index: referenceIndex(arm.value),
|
|
485
|
+
}));
|
|
486
|
+
if (
|
|
487
|
+
referred.every(
|
|
488
|
+
(arm): arm is (typeof referred)[number] & { index: string | Mapped } =>
|
|
489
|
+
arm.index !== undefined,
|
|
490
|
+
)
|
|
491
|
+
) {
|
|
492
|
+
frame.emitter.line(`let ${result}: ${referenceLayout} = ${noReference};`);
|
|
493
|
+
frame.emitter.chain(
|
|
494
|
+
referred.map((arm) => ({
|
|
495
|
+
test: holds(choice, arm.option),
|
|
508
496
|
body: () => {
|
|
509
497
|
frame.emitter.append(arm.lines);
|
|
510
|
-
frame.emitter.line(
|
|
511
|
-
mapped`${result} = ${referenceIndex(arm.value) ?? "-1"};`,
|
|
512
|
-
);
|
|
498
|
+
frame.emitter.line(mapped`${result} = ${arm.index};`);
|
|
513
499
|
},
|
|
514
500
|
})),
|
|
515
501
|
);
|
|
@@ -540,18 +526,17 @@ export class References {
|
|
|
540
526
|
}
|
|
541
527
|
const iec = sample?.kind === "code" ? sample.iec : undefined;
|
|
542
528
|
const layout = sample?.kind === "code" ? sample.layout : undefined;
|
|
543
|
-
const text = iec ?? layout ?? this.expressions.localType(declared);
|
|
529
|
+
const text = iec ?? layout?.text ?? this.expressions.localType(declared);
|
|
544
530
|
frame.emitter.line(
|
|
545
|
-
`let ${result}: ${text} = ${iec || layout ? `defaultValue<${text}>()` : this.initializers.defaultOf(declared)};`,
|
|
531
|
+
`let ${result}: ${text} = ${iec || layout ? `defaultValue<${text}>()` : this.context.initializers.defaultOf(declared)};`,
|
|
546
532
|
);
|
|
547
|
-
chain(
|
|
548
|
-
frame,
|
|
533
|
+
frame.emitter.chain(
|
|
549
534
|
arms.map((arm) => ({
|
|
550
|
-
test:
|
|
535
|
+
test: holds(choice, arm.option),
|
|
551
536
|
body: () => {
|
|
552
537
|
frame.emitter.append(arm.lines);
|
|
553
538
|
frame.emitter.line(
|
|
554
|
-
mapped`${result} = ${this.dialect.assignmentText(arm.value, declared, iec)};`,
|
|
539
|
+
mapped`${result} = ${this.context.dialect.assignmentText(arm.value, declared, iec)};`,
|
|
555
540
|
);
|
|
556
541
|
},
|
|
557
542
|
})),
|
|
@@ -615,7 +600,7 @@ export class References {
|
|
|
615
600
|
frame: Frame,
|
|
616
601
|
): Value {
|
|
617
602
|
const result = frame.emitter.temporary();
|
|
618
|
-
frame.emitter.line(`let ${result}: ${referenceLayout} =
|
|
603
|
+
frame.emitter.line(`let ${result}: ${referenceLayout} = ${noReference};`);
|
|
619
604
|
const store = (side: () => Value): Value => {
|
|
620
605
|
const value = side();
|
|
621
606
|
frame.emitter.line(mapped`${result} = ${this.index(value, at)};`);
|
|
@@ -643,7 +628,7 @@ export class References {
|
|
|
643
628
|
frame.emitter.line(
|
|
644
629
|
mapped`let ${result}: ${referenceLayout} = ${left.index};`,
|
|
645
630
|
);
|
|
646
|
-
frame.emitter.open(`if (${result}
|
|
631
|
+
frame.emitter.open(mapped`if (${absent(result)}) {`);
|
|
647
632
|
const value = right();
|
|
648
633
|
frame.emitter.line(mapped`${result} = ${this.index(value, at)};`);
|
|
649
634
|
frame.emitter.close();
|
|
@@ -666,32 +651,8 @@ export class References {
|
|
|
666
651
|
return index;
|
|
667
652
|
}
|
|
668
653
|
|
|
669
|
-
/**
|
|
670
|
-
* A call on a reference chosen at run time, or on an array whose elements scan code picks from:
|
|
671
|
-
* a method call through the reference, or an array method that picks an object or keeps some.
|
|
672
|
-
* Undefined for a call setup decides, which unrolls as any other.
|
|
673
|
-
*/
|
|
674
|
-
call(
|
|
675
|
-
name: string,
|
|
676
|
-
receiver: Value,
|
|
677
|
-
items: readonly Value[] | undefined,
|
|
678
|
-
node: ts.CallExpression,
|
|
679
|
-
frame: Frame,
|
|
680
|
-
expected: ts.Type | undefined,
|
|
681
|
-
): Value | undefined {
|
|
682
|
-
return receiver.kind === "choice"
|
|
683
|
-
? this.method(receiver, name, node, frame, expected)
|
|
684
|
-
: this.expressions.filteredArrays.call(
|
|
685
|
-
name,
|
|
686
|
-
receiver,
|
|
687
|
-
items,
|
|
688
|
-
node,
|
|
689
|
-
frame,
|
|
690
|
-
);
|
|
691
|
-
}
|
|
692
|
-
|
|
693
654
|
/** A method call through a reference: the method of whichever object it holds, the arguments worked out once. */
|
|
694
|
-
|
|
655
|
+
call(
|
|
695
656
|
choice: Choice,
|
|
696
657
|
name: string,
|
|
697
658
|
node: ts.CallExpression,
|
|
@@ -701,13 +662,11 @@ export class References {
|
|
|
701
662
|
const [sample] = choice.options;
|
|
702
663
|
const declaration =
|
|
703
664
|
sample?.captured.kind === "instance"
|
|
704
|
-
? this.model
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
member.name.getText() === name,
|
|
710
|
-
)
|
|
665
|
+
? this.model.memberNamed(
|
|
666
|
+
this.model.classOf(sample),
|
|
667
|
+
name,
|
|
668
|
+
ts.isMethodDeclaration,
|
|
669
|
+
)
|
|
711
670
|
: undefined;
|
|
712
671
|
const args = this.expressions.inOrder(
|
|
713
672
|
node.arguments,
|
|
@@ -747,3 +706,22 @@ export class References {
|
|
|
747
706
|
});
|
|
748
707
|
}
|
|
749
708
|
}
|
|
709
|
+
|
|
710
|
+
/** Code for whether a reference holds `option`. */
|
|
711
|
+
export const holds = (choice: Choice, option: ModelNode): Mapped =>
|
|
712
|
+
mapped`${choice.index} === ${option.reference}`;
|
|
713
|
+
|
|
714
|
+
/** A branch for each object a reference can be that wrote lines, which run when it holds that object. */
|
|
715
|
+
const branches = (
|
|
716
|
+
choice: Choice,
|
|
717
|
+
frame: Frame,
|
|
718
|
+
arms: readonly { option: ModelNode; lines: readonly Mapped[] }[],
|
|
719
|
+
): void =>
|
|
720
|
+
frame.emitter.chain(
|
|
721
|
+
arms
|
|
722
|
+
.filter((arm) => arm.lines.length > 0)
|
|
723
|
+
.map((arm) => ({
|
|
724
|
+
test: holds(choice, arm.option),
|
|
725
|
+
body: () => frame.emitter.append(arm.lines),
|
|
726
|
+
})),
|
|
727
|
+
);
|