@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
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type CoreExpression,
|
|
3
|
+
type CorePath,
|
|
4
|
+
type CoreStatement,
|
|
5
|
+
type CoreTables,
|
|
6
|
+
isBlockRoutine,
|
|
7
|
+
isTemporary,
|
|
8
|
+
projectReconstruction,
|
|
9
|
+
type ReconstructedSegment,
|
|
10
|
+
type StatementConditions,
|
|
11
|
+
standardBlocks,
|
|
12
|
+
staticNames,
|
|
13
|
+
} from "@tsplc/compiler/ir";
|
|
14
|
+
import type {
|
|
15
|
+
ExplainAssignment,
|
|
16
|
+
ExplainCall,
|
|
17
|
+
ExplainFile,
|
|
18
|
+
} from "@tsplc/debug/explain-file";
|
|
19
|
+
import { required } from "../required";
|
|
20
|
+
import type { ExplainEncoder, Spelled } from "./expressions";
|
|
21
|
+
import { parameterIndex, parameterKey } from "./parameters";
|
|
22
|
+
import { calleeRows, type Row } from "./rows";
|
|
23
|
+
import type { ExplainTables } from "./tables";
|
|
24
|
+
|
|
25
|
+
type Invoke = Extract<CoreStatement, { kind: "invoke" }>;
|
|
26
|
+
|
|
27
|
+
/** What every record of a statement starts with. */
|
|
28
|
+
type StatementRecord = Pick<
|
|
29
|
+
ExplainAssignment,
|
|
30
|
+
"routine" | "position" | "conditions" | "site"
|
|
31
|
+
>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Writes through by-reference parameters are followed this many calls deep: each level fans out
|
|
35
|
+
* to every instance the call can run on.
|
|
36
|
+
*/
|
|
37
|
+
const maxParameterDepth = 16;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Every row's loops, calls, returns and the writes of stored state its statements make, the
|
|
41
|
+
* writes through by-reference parameters included, as `explain.json` holds them.
|
|
42
|
+
*/
|
|
43
|
+
export function explainWrites({
|
|
44
|
+
rows,
|
|
45
|
+
core,
|
|
46
|
+
tables,
|
|
47
|
+
encoder,
|
|
48
|
+
writesThrough,
|
|
49
|
+
}: {
|
|
50
|
+
rows: readonly Row[];
|
|
51
|
+
core: CoreTables;
|
|
52
|
+
tables: ExplainTables;
|
|
53
|
+
encoder: ExplainEncoder;
|
|
54
|
+
/** The parameters each routine writes through, by `parameterKey`. */
|
|
55
|
+
writesThrough: ReadonlySet<string>;
|
|
56
|
+
}) {
|
|
57
|
+
const { expression, condition, spell, extend, local, placeRef, isAggregate } =
|
|
58
|
+
encoder;
|
|
59
|
+
const loops: ExplainFile["loops"] = [];
|
|
60
|
+
const assignments: ExplainAssignment[] = [];
|
|
61
|
+
const returns: ExplainFile["returns"] = [];
|
|
62
|
+
const callRecords = new Map<number, ExplainCall>();
|
|
63
|
+
/** The assignments each statement makes itself, in every instance that runs it. */
|
|
64
|
+
const recorded = new Map<CoreStatement, number[]>();
|
|
65
|
+
|
|
66
|
+
const segments = (
|
|
67
|
+
row: Row,
|
|
68
|
+
path: CorePath,
|
|
69
|
+
at: number,
|
|
70
|
+
): ReconstructedSegment[] =>
|
|
71
|
+
path.map((segment) =>
|
|
72
|
+
segment.kind === "field"
|
|
73
|
+
? segment
|
|
74
|
+
: {
|
|
75
|
+
kind: "index",
|
|
76
|
+
value: row.conditions.reconstruct(segment.value, at),
|
|
77
|
+
},
|
|
78
|
+
);
|
|
79
|
+
const loopOf = (row: Row, loop: number | null): number | null =>
|
|
80
|
+
loop === null ? null : row.firstLoop + loop;
|
|
81
|
+
const statementRecord = (
|
|
82
|
+
row: Row,
|
|
83
|
+
item: CoreStatement,
|
|
84
|
+
flow: StatementConditions,
|
|
85
|
+
): StatementRecord => ({
|
|
86
|
+
routine: row.index,
|
|
87
|
+
position: flow.position,
|
|
88
|
+
conditions: tables.conditionsIndex(
|
|
89
|
+
flow.conditions.map((part) => condition(row, part)),
|
|
90
|
+
),
|
|
91
|
+
site: tables.site(item.span),
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
/** A block instance a call runs on, at the element it indexes. */
|
|
95
|
+
const spellInstance = (
|
|
96
|
+
row: Row,
|
|
97
|
+
instance: string,
|
|
98
|
+
index: CoreExpression | undefined,
|
|
99
|
+
at: number,
|
|
100
|
+
) =>
|
|
101
|
+
spell(
|
|
102
|
+
row,
|
|
103
|
+
instance,
|
|
104
|
+
index
|
|
105
|
+
? [{ kind: "index", value: row.conditions.reconstruct(index, at) }]
|
|
106
|
+
: [],
|
|
107
|
+
);
|
|
108
|
+
/** The receiver of a call in a row: a block instance's path, or none for a function. */
|
|
109
|
+
const receiver = (
|
|
110
|
+
row: Row,
|
|
111
|
+
item: Invoke,
|
|
112
|
+
at: number,
|
|
113
|
+
): ExplainCall["receiver"] => {
|
|
114
|
+
if (item.instance === undefined) {
|
|
115
|
+
return core.functions.get(item.function)?.owner && row.instance !== null
|
|
116
|
+
? { kind: "path", path: tables.paths.add(row.instance) }
|
|
117
|
+
: { kind: "none" };
|
|
118
|
+
}
|
|
119
|
+
const spelled = spellInstance(row, item.instance, item.index, at);
|
|
120
|
+
return spelled ? placeRef(spelled) : { kind: "none" };
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
for (const row of rows) {
|
|
124
|
+
const { routine, conditions } = row;
|
|
125
|
+
conditions.loops.forEach((loop, index) => {
|
|
126
|
+
const counter = core.variableOf(loop.counter);
|
|
127
|
+
loops.push({
|
|
128
|
+
routine: row.index,
|
|
129
|
+
position: loop.position,
|
|
130
|
+
counter: expression(
|
|
131
|
+
row,
|
|
132
|
+
conditions.reconstruct(
|
|
133
|
+
{
|
|
134
|
+
kind: "load",
|
|
135
|
+
root: loop.counter,
|
|
136
|
+
type: counter.type,
|
|
137
|
+
span: loop.statement.span,
|
|
138
|
+
},
|
|
139
|
+
loop.position,
|
|
140
|
+
),
|
|
141
|
+
),
|
|
142
|
+
first: expression(row, loop.first),
|
|
143
|
+
limit: expression(row, loop.limit),
|
|
144
|
+
exclusive: loop.exclusive,
|
|
145
|
+
step: tables.expressions.add({
|
|
146
|
+
kind: "constant",
|
|
147
|
+
value: Number(loop.step),
|
|
148
|
+
type: counter.type,
|
|
149
|
+
}),
|
|
150
|
+
maxIterations: loop.maxIterations,
|
|
151
|
+
breaks: loop.breaks.map((all) =>
|
|
152
|
+
all.map((part) => condition(row, part)),
|
|
153
|
+
),
|
|
154
|
+
parent: loopOf(row, loop.parent),
|
|
155
|
+
site: required(row.loopSites[index]),
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
const block = isBlockRoutine(routine) ? routine : undefined;
|
|
159
|
+
for (const [item, flow] of conditions.statements) {
|
|
160
|
+
const first = assignments.length;
|
|
161
|
+
const at = flow.position;
|
|
162
|
+
const record = statementRecord(row, item, flow);
|
|
163
|
+
const loop = loopOf(row, flow.loop);
|
|
164
|
+
const reconstruct = (value: CoreExpression) =>
|
|
165
|
+
expression(row, conditions.reconstruct(value, at));
|
|
166
|
+
/** A write of `value` to `root`: stored, a local's definition, or nothing for a temporary. */
|
|
167
|
+
const write = (
|
|
168
|
+
root: string,
|
|
169
|
+
path: CorePath,
|
|
170
|
+
kind: "assign" | "call" | "counter",
|
|
171
|
+
value: number | null,
|
|
172
|
+
): void => {
|
|
173
|
+
const variable = core.variableOf(root);
|
|
174
|
+
const parameter = parameterIndex(routine, root);
|
|
175
|
+
const isLocal =
|
|
176
|
+
variable.storage === "local" &&
|
|
177
|
+
routine.locals.some((candidate) => candidate.id === root);
|
|
178
|
+
if (isLocal && isTemporary(routine.id, variable)) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (isLocal || parameter >= 0) {
|
|
182
|
+
const names = staticNames(segments(row, path, at));
|
|
183
|
+
local(row, root).definitions.push({
|
|
184
|
+
...record,
|
|
185
|
+
kind: kind === "counter" ? "counter" : "assign",
|
|
186
|
+
path: names ?? [],
|
|
187
|
+
value: names ? value : null,
|
|
188
|
+
call: null,
|
|
189
|
+
loop,
|
|
190
|
+
});
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
const spelled = spell(row, root, segments(row, path, at));
|
|
194
|
+
if (!spelled) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
assignments.push({
|
|
198
|
+
...record,
|
|
199
|
+
kind,
|
|
200
|
+
writes: placeRef(spelled),
|
|
201
|
+
whole: isAggregate(spelled),
|
|
202
|
+
value,
|
|
203
|
+
block: null,
|
|
204
|
+
via: [],
|
|
205
|
+
loop,
|
|
206
|
+
});
|
|
207
|
+
};
|
|
208
|
+
/** A local or parameter a call borrows, which the callee writes through. */
|
|
209
|
+
const borrowed = (
|
|
210
|
+
call: number,
|
|
211
|
+
argument: CoreExpression,
|
|
212
|
+
index: number,
|
|
213
|
+
callee: string,
|
|
214
|
+
) => {
|
|
215
|
+
if (
|
|
216
|
+
argument.kind !== "borrow" ||
|
|
217
|
+
!writesThrough.has(parameterKey(callee, index))
|
|
218
|
+
) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
const root = argument.place.root;
|
|
222
|
+
const isLocal =
|
|
223
|
+
routine.locals.some((candidate) => candidate.id === root) &&
|
|
224
|
+
!isTemporary(routine.id, core.variableOf(root));
|
|
225
|
+
if (!isLocal && parameterIndex(routine, root) < 0) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const names = staticNames(segments(row, argument.place.path, at));
|
|
229
|
+
local(row, root).definitions.push({
|
|
230
|
+
...record,
|
|
231
|
+
kind: "borrowed",
|
|
232
|
+
path: names ?? [],
|
|
233
|
+
value: null,
|
|
234
|
+
call,
|
|
235
|
+
loop,
|
|
236
|
+
});
|
|
237
|
+
};
|
|
238
|
+
switch (item.kind) {
|
|
239
|
+
case "assign":
|
|
240
|
+
write(item.root, item.path ?? [], "assign", reconstruct(item.value));
|
|
241
|
+
break;
|
|
242
|
+
case "invoke": {
|
|
243
|
+
const call = required(row.calls.get(item));
|
|
244
|
+
callRecords.set(call, {
|
|
245
|
+
...record,
|
|
246
|
+
callee: item.function,
|
|
247
|
+
receiver: receiver(row, item, at),
|
|
248
|
+
arguments: item.arguments.map((argument) => reconstruct(argument)),
|
|
249
|
+
loop,
|
|
250
|
+
});
|
|
251
|
+
item.arguments.forEach((argument, index) => {
|
|
252
|
+
borrowed(call, argument, index, item.function);
|
|
253
|
+
});
|
|
254
|
+
if (item.destination) {
|
|
255
|
+
write(
|
|
256
|
+
item.destination,
|
|
257
|
+
[],
|
|
258
|
+
"call",
|
|
259
|
+
tables.expressions.add({
|
|
260
|
+
kind: "call",
|
|
261
|
+
call,
|
|
262
|
+
path: [],
|
|
263
|
+
type: required(core.functionOf(item.function).result),
|
|
264
|
+
}),
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
case "blockUpdate": {
|
|
270
|
+
const call = required(row.calls.get(item));
|
|
271
|
+
const called = core.updatedBlock(item);
|
|
272
|
+
const spelled = spellInstance(row, item.instance, item.index, at);
|
|
273
|
+
callRecords.set(call, {
|
|
274
|
+
...record,
|
|
275
|
+
callee: called.id,
|
|
276
|
+
receiver: spelled ? placeRef(spelled) : { kind: "none" },
|
|
277
|
+
arguments: called.inputs.flatMap((input) => {
|
|
278
|
+
const value = item.inputs[input.name];
|
|
279
|
+
return value ? [reconstruct(value)] : [];
|
|
280
|
+
}),
|
|
281
|
+
loop,
|
|
282
|
+
});
|
|
283
|
+
if (!spelled) {
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
if (called.standard) {
|
|
287
|
+
const native = standardBlocks[called.standard];
|
|
288
|
+
const elapsed = native.outputs.some(([name]) => name === "elapsed")
|
|
289
|
+
? extend(row, spelled, [{ kind: "field", name: "elapsed" }])
|
|
290
|
+
: undefined;
|
|
291
|
+
assignments.push({
|
|
292
|
+
...record,
|
|
293
|
+
kind: "block",
|
|
294
|
+
writes: placeRef(spelled),
|
|
295
|
+
whole: true,
|
|
296
|
+
value: null,
|
|
297
|
+
block: {
|
|
298
|
+
kind: called.standard,
|
|
299
|
+
inputs: Object.fromEntries(
|
|
300
|
+
Object.entries(item.inputs).map(([name, value]) => [
|
|
301
|
+
name,
|
|
302
|
+
reconstruct(value),
|
|
303
|
+
]),
|
|
304
|
+
),
|
|
305
|
+
elapsed: elapsed
|
|
306
|
+
? encoder.storedRead(row, elapsed, {
|
|
307
|
+
capturedAt: at,
|
|
308
|
+
type: "TIME",
|
|
309
|
+
})
|
|
310
|
+
: null,
|
|
311
|
+
},
|
|
312
|
+
via: [],
|
|
313
|
+
loop,
|
|
314
|
+
});
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
called.inputs.forEach((input) => {
|
|
318
|
+
const value = item.inputs[input.name];
|
|
319
|
+
if (!value || value.kind === "borrow") {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
const field = extend(row, spelled, [
|
|
323
|
+
{ kind: "field", name: input.name },
|
|
324
|
+
]);
|
|
325
|
+
assignments.push({
|
|
326
|
+
...record,
|
|
327
|
+
kind: "input",
|
|
328
|
+
writes: placeRef(field),
|
|
329
|
+
whole: isAggregate(field),
|
|
330
|
+
value: reconstruct(value),
|
|
331
|
+
block: null,
|
|
332
|
+
via: [],
|
|
333
|
+
loop,
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
break;
|
|
337
|
+
}
|
|
338
|
+
case "for":
|
|
339
|
+
write(item.counter, [], "counter", null);
|
|
340
|
+
break;
|
|
341
|
+
case "return": {
|
|
342
|
+
returns.push({
|
|
343
|
+
...record,
|
|
344
|
+
value: item.value ? reconstruct(item.value) : null,
|
|
345
|
+
});
|
|
346
|
+
const value = item.value;
|
|
347
|
+
if (!block || !value || row.instance === null) {
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
350
|
+
const returned = conditions.reconstruct(value, at);
|
|
351
|
+
for (const output of block.outputs) {
|
|
352
|
+
const field = spell(row, output.id, []);
|
|
353
|
+
if (!field) {
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
assignments.push({
|
|
357
|
+
...record,
|
|
358
|
+
kind: "return",
|
|
359
|
+
writes: placeRef(field),
|
|
360
|
+
whole: isAggregate(field),
|
|
361
|
+
value: expression(
|
|
362
|
+
row,
|
|
363
|
+
projectReconstruction(
|
|
364
|
+
returned,
|
|
365
|
+
[{ kind: "field", name: output.name }],
|
|
366
|
+
output.type,
|
|
367
|
+
),
|
|
368
|
+
),
|
|
369
|
+
block: null,
|
|
370
|
+
via: [],
|
|
371
|
+
loop,
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
default:
|
|
377
|
+
break;
|
|
378
|
+
}
|
|
379
|
+
if (assignments.length > first) {
|
|
380
|
+
recorded.set(item, [
|
|
381
|
+
...(recorded.get(item) ?? []),
|
|
382
|
+
...Array.from(
|
|
383
|
+
{ length: assignments.length - first },
|
|
384
|
+
(_, offset) => first + offset,
|
|
385
|
+
),
|
|
386
|
+
]);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
const calls = Array.from({ length: callRecords.size }, (_, index) =>
|
|
391
|
+
required(callRecords.get(index)),
|
|
392
|
+
);
|
|
393
|
+
|
|
394
|
+
// Writes through a by-reference parameter land in the storage each call site passes.
|
|
395
|
+
const throughParameter = (
|
|
396
|
+
target: Spelled,
|
|
397
|
+
callee: Row,
|
|
398
|
+
parameter: number,
|
|
399
|
+
via: readonly number[],
|
|
400
|
+
depth: number,
|
|
401
|
+
): void => {
|
|
402
|
+
const root = isBlockRoutine(callee.routine)
|
|
403
|
+
? undefined
|
|
404
|
+
: callee.routine.parameters[parameter]?.id;
|
|
405
|
+
if (root === undefined || depth > maxParameterDepth) {
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
for (const [item, flow] of callee.conditions.statements) {
|
|
409
|
+
const at = flow.position;
|
|
410
|
+
const record = statementRecord(callee, item, flow);
|
|
411
|
+
// A written place's runtime indexes are evaluated where the place is named, in the
|
|
412
|
+
// outermost caller; one the callee computes itself isn't followed.
|
|
413
|
+
const fixed = (path: CorePath) =>
|
|
414
|
+
path.every(
|
|
415
|
+
(segment) =>
|
|
416
|
+
segment.kind === "field" || segment.value.kind === "constant",
|
|
417
|
+
);
|
|
418
|
+
if (
|
|
419
|
+
item.kind === "assign" &&
|
|
420
|
+
item.root === root &&
|
|
421
|
+
fixed(item.path ?? [])
|
|
422
|
+
) {
|
|
423
|
+
const spelled = extend(
|
|
424
|
+
callee,
|
|
425
|
+
target,
|
|
426
|
+
segments(callee, item.path ?? [], at),
|
|
427
|
+
);
|
|
428
|
+
assignments.push({
|
|
429
|
+
...record,
|
|
430
|
+
kind: "assign",
|
|
431
|
+
writes: placeRef(spelled),
|
|
432
|
+
whole: isAggregate(spelled),
|
|
433
|
+
value: expression(
|
|
434
|
+
callee,
|
|
435
|
+
callee.conditions.reconstruct(item.value, at),
|
|
436
|
+
),
|
|
437
|
+
block: null,
|
|
438
|
+
via: [...via],
|
|
439
|
+
loop: loopOf(callee, flow.loop),
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
const call = callee.calls.get(item);
|
|
443
|
+
if (item.kind !== "invoke" || call === undefined) {
|
|
444
|
+
continue;
|
|
445
|
+
}
|
|
446
|
+
const nested = required(calls[call]);
|
|
447
|
+
item.arguments.forEach((argument, index) => {
|
|
448
|
+
if (
|
|
449
|
+
argument.kind !== "borrow" ||
|
|
450
|
+
argument.place.root !== root ||
|
|
451
|
+
!fixed(argument.place.path) ||
|
|
452
|
+
!writesThrough.has(parameterKey(item.function, index))
|
|
453
|
+
) {
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
const inner = extend(
|
|
457
|
+
callee,
|
|
458
|
+
target,
|
|
459
|
+
segments(callee, argument.place.path, at),
|
|
460
|
+
);
|
|
461
|
+
for (const next of calleeRows(rows, tables, core, nested, callee)) {
|
|
462
|
+
throughParameter(inner, next, index, [call, ...via], depth + 1);
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
for (const row of rows) {
|
|
468
|
+
for (const [item, call] of row.calls) {
|
|
469
|
+
if (item.kind !== "invoke") {
|
|
470
|
+
continue;
|
|
471
|
+
}
|
|
472
|
+
const record = required(calls[call]);
|
|
473
|
+
const at = required(row.conditions.statements.get(item)).position;
|
|
474
|
+
item.arguments.forEach((argument, index) => {
|
|
475
|
+
if (
|
|
476
|
+
argument.kind !== "borrow" ||
|
|
477
|
+
!writesThrough.has(parameterKey(item.function, index))
|
|
478
|
+
) {
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
const target = spell(
|
|
482
|
+
row,
|
|
483
|
+
argument.place.root,
|
|
484
|
+
segments(row, argument.place.path, at),
|
|
485
|
+
);
|
|
486
|
+
if (!target) {
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
for (const callee of calleeRows(rows, tables, core, record, row)) {
|
|
490
|
+
throughParameter(target, callee, index, [call], 0);
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
return { loops, calls, assignments, returns, recorded };
|
|
497
|
+
}
|