@tsplc/compiler 0.5.14 → 0.5.16
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/stdlib/math.ts +0 -23
- package/types/plc.d.ts +0 -4
|
@@ -1,76 +1,20 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
|
-
import {
|
|
3
|
-
existsSync,
|
|
4
|
-
mkdtempSync,
|
|
5
|
-
readFileSync,
|
|
6
|
-
rmSync,
|
|
7
|
-
writeFileSync,
|
|
8
|
-
} from "node:fs";
|
|
2
|
+
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
9
3
|
import { tmpdir } from "node:os";
|
|
10
4
|
import { join } from "node:path";
|
|
11
5
|
import { fileURLToPath } from "node:url";
|
|
12
6
|
import ts from "typescript";
|
|
13
7
|
import { z } from "zod";
|
|
8
|
+
import { valueSymbol } from "../sdk";
|
|
9
|
+
import { isPropertyName } from "../types";
|
|
14
10
|
import {
|
|
11
|
+
bindingNames,
|
|
15
12
|
type CapturedGraph,
|
|
16
13
|
type CaptureRequest,
|
|
17
14
|
type ClosureSite,
|
|
18
15
|
capturedGraphSchema,
|
|
19
16
|
} from "./capture-protocol";
|
|
20
|
-
|
|
21
|
-
/** The top-level bindings a module declares: values, classes and functions, arrow functions among them. */
|
|
22
|
-
export const bindingNames = (source: ts.SourceFile) => {
|
|
23
|
-
const found: CaptureRequest["bindings"][string] = {
|
|
24
|
-
values: [],
|
|
25
|
-
classes: [],
|
|
26
|
-
functions: [],
|
|
27
|
-
};
|
|
28
|
-
const bind = (name: ts.BindingName): void => {
|
|
29
|
-
if (ts.isIdentifier(name)) {
|
|
30
|
-
found.values.push(name.text);
|
|
31
|
-
} else {
|
|
32
|
-
for (const element of name.elements) {
|
|
33
|
-
if (!ts.isOmittedExpression(element)) {
|
|
34
|
-
bind(element.name);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
for (const statement of source.statements) {
|
|
40
|
-
if (ts.isVariableStatement(statement)) {
|
|
41
|
-
for (const declaration of statement.declarationList.declarations) {
|
|
42
|
-
bind(declaration.name);
|
|
43
|
-
}
|
|
44
|
-
} else if (ts.isClassDeclaration(statement) && statement.name) {
|
|
45
|
-
found.classes.push(statement.name.text);
|
|
46
|
-
} else if (
|
|
47
|
-
ts.isFunctionDeclaration(statement) &&
|
|
48
|
-
statement.name &&
|
|
49
|
-
statement.body
|
|
50
|
-
) {
|
|
51
|
-
found.functions.push(statement.name.text);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
// Arrow functions bound to consts are functions too: a stored callback names its binding.
|
|
55
|
-
for (const statement of source.statements) {
|
|
56
|
-
if (ts.isVariableStatement(statement)) {
|
|
57
|
-
for (const declaration of statement.declarationList.declarations) {
|
|
58
|
-
if (
|
|
59
|
-
ts.isIdentifier(declaration.name) &&
|
|
60
|
-
declaration.initializer &&
|
|
61
|
-
(ts.isArrowFunction(declaration.initializer) ||
|
|
62
|
-
ts.isFunctionExpression(declaration.initializer))
|
|
63
|
-
) {
|
|
64
|
-
found.values = found.values.filter(
|
|
65
|
-
(name) => name !== declaration.name.getText(),
|
|
66
|
-
);
|
|
67
|
-
found.functions.push(declaration.name.text);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return found;
|
|
73
|
-
};
|
|
17
|
+
import { within } from "./writes";
|
|
74
18
|
|
|
75
19
|
/**
|
|
76
20
|
* Every arrow and function expression not bound at module level, which setup may store, with the
|
|
@@ -115,11 +59,7 @@ const captures = (
|
|
|
115
59
|
names.add("this");
|
|
116
60
|
}
|
|
117
61
|
if (ts.isIdentifier(node) && !isPropertyName(node)) {
|
|
118
|
-
|
|
119
|
-
const symbol = ts.isShorthandPropertyAssignment(node.parent)
|
|
120
|
-
? checker.getShorthandAssignmentValueSymbol(node.parent)
|
|
121
|
-
: checker.getSymbolAtLocation(node);
|
|
122
|
-
const declaration = symbol?.valueDeclaration;
|
|
62
|
+
const declaration = valueSymbol(checker, node)?.valueDeclaration;
|
|
123
63
|
if (
|
|
124
64
|
declaration &&
|
|
125
65
|
!within(declaration, closure) &&
|
|
@@ -151,43 +91,29 @@ const moduleFunction = (
|
|
|
151
91
|
);
|
|
152
92
|
};
|
|
153
93
|
|
|
154
|
-
|
|
155
|
-
node.pos >= container.pos && node.end <= container.end;
|
|
156
|
-
|
|
157
|
-
const isPropertyName = (node: ts.Identifier): boolean =>
|
|
158
|
-
(ts.isPropertyAccessExpression(node.parent) && node.parent.name === node) ||
|
|
159
|
-
(ts.isPropertyAssignment(node.parent) && node.parent.name === node);
|
|
160
|
-
|
|
161
|
-
/** Runs the program's setup in a Bun subprocess and returns the object graph it built. */
|
|
94
|
+
/** Runs the setup of the program's runtime `sources` in a Bun subprocess and returns the object graph it built. */
|
|
162
95
|
export const captureGraph = (
|
|
163
96
|
entry: string,
|
|
164
97
|
sources: readonly ts.SourceFile[],
|
|
165
98
|
checker: ts.TypeChecker,
|
|
99
|
+
configuration: Readonly<Record<string, string>>,
|
|
166
100
|
): CapturedGraph => {
|
|
167
|
-
const files = sources.filter((source) => !source.isDeclarationFile);
|
|
168
101
|
const request: CaptureRequest = {
|
|
169
102
|
entry,
|
|
170
|
-
|
|
103
|
+
configuration,
|
|
104
|
+
files: sources.map((source) => source.fileName),
|
|
171
105
|
closures: Object.fromEntries(
|
|
172
|
-
|
|
106
|
+
sources.map((source) => [source.fileName, closureSites(source, checker)]),
|
|
173
107
|
),
|
|
174
108
|
bindings: Object.fromEntries(
|
|
175
|
-
|
|
109
|
+
sources.map((source) => [source.fileName, bindingNames(source)]),
|
|
176
110
|
),
|
|
177
111
|
};
|
|
178
112
|
const directory = mkdtempSync(join(tmpdir(), "tsplc-capture-"));
|
|
179
113
|
try {
|
|
180
114
|
const file = join(directory, "request.json");
|
|
181
115
|
writeFileSync(file, JSON.stringify(request));
|
|
182
|
-
|
|
183
|
-
const script = ["./capture.ts", "./elaborate-capture.js"]
|
|
184
|
-
.map((path) => fileURLToPath(new URL(path, import.meta.url)))
|
|
185
|
-
.find((path) => existsSync(path));
|
|
186
|
-
if (!script) {
|
|
187
|
-
throw new Error(
|
|
188
|
-
"The elaboration capture script is missing from this build.",
|
|
189
|
-
);
|
|
190
|
-
}
|
|
116
|
+
const script = fileURLToPath(import.meta.resolve("#elaborate-capture"));
|
|
191
117
|
// The graph has its own file, so setup code is free to write to standard output.
|
|
192
118
|
const output = join(directory, "graph.json");
|
|
193
119
|
const result = spawnSync(process.execPath, [script, file, output], {
|
|
@@ -40,8 +40,6 @@ export class EntryImports {
|
|
|
40
40
|
readonly kept = new ModuleImports();
|
|
41
41
|
/** SDK functions by the module that declares them, such as `@tsplc/compiler/clock`. */
|
|
42
42
|
private readonly sdk = new Map<string, Set<string>>();
|
|
43
|
-
/** Whether scan code calls `telemetry`. */
|
|
44
|
-
telemetry = false;
|
|
45
43
|
|
|
46
44
|
/** Records a call of `name`, which `module` of the SDK declares. */
|
|
47
45
|
addSdk(module: string, name: string): void {
|
|
@@ -61,9 +59,6 @@ export class EntryImports {
|
|
|
61
59
|
([module, names]) =>
|
|
62
60
|
`import { ${[...names].join(", ")} } from "${module}";`,
|
|
63
61
|
),
|
|
64
|
-
...(this.telemetry
|
|
65
|
-
? [`import { telemetry } from "@tsplc/compiler/telemetry";`]
|
|
66
|
-
: []),
|
|
67
62
|
];
|
|
68
63
|
}
|
|
69
64
|
}
|