@tsplc/compiler 0.2.21 → 0.4.0
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 +1 -1
- package/dist/cli.js +280 -223
- package/dist/cli.js.map +12 -12
- package/dist/codesys.js +452 -330
- package/dist/codesys.js.map +24 -24
- package/dist/elaborate-capture.js +112 -7
- package/dist/elaborate-capture.js.map +5 -4
- package/dist/index.js +5682 -5407
- package/dist/index.js.map +39 -37
- package/dist/ir.js +1154 -327
- package/dist/ir.js.map +23 -20
- package/dist/project.js +68 -29
- package/dist/project.js.map +4 -4
- package/dist/retain.js +8 -0
- package/dist/retain.js.map +10 -0
- package/dist/server-check.js +59 -0
- package/dist/server-check.js.map +11 -0
- package/dist/telemetry.js +19 -10
- package/dist/telemetry.js.map +3 -3
- package/package.json +33 -12
- package/src/codesys/config.ts +1 -1
- package/src/codesys/debug.ts +7 -21
- package/src/codesys/engineering.ts +8 -12
- package/src/codesys/global-lists.ts +19 -17
- package/src/codesys/global-names.ts +3 -3
- package/src/codesys/http.ts +37 -34
- package/src/codesys/index.ts +5 -22
- package/src/codesys/instrumentation.ts +3 -1
- package/src/codesys/io-paths.ts +2 -1
- package/src/codesys/manifest.ts +35 -18
- package/src/codesys/numeric.ts +2 -4
- package/src/codesys/plan.ts +94 -26
- package/src/codesys/publication.ts +4 -3
- package/src/codesys/routines.ts +2 -2
- package/src/codesys/sources.ts +1 -0
- package/src/codesys/st-files.ts +86 -50
- package/src/codesys/storage.ts +44 -9
- package/src/codesys/task-access.ts +32 -10
- package/src/codesys/telemetry.ts +93 -46
- package/src/codesys/types.ts +81 -3
- package/src/codesys/vendor.ts +1 -1
- package/src/frontend/analyzer.ts +15 -14
- package/src/frontend/async.ts +23 -21
- package/src/frontend/blocks.ts +7 -6
- package/src/frontend/configuration.ts +8 -6
- package/src/frontend/const-functions.ts +5 -5
- package/src/frontend/cooperative.ts +2 -1
- package/src/frontend/coroutines.ts +24 -21
- package/src/frontend/elaborate/calls.ts +12 -7
- package/src/frontend/elaborate/capture-protocol.ts +103 -0
- package/src/frontend/elaborate/capture.ts +48 -19
- package/src/frontend/elaborate/dialect.ts +2 -2
- package/src/frontend/elaborate/expressions.ts +9 -6
- package/src/frontend/elaborate/frame.ts +1 -1
- package/src/frontend/elaborate/graph.ts +27 -43
- package/src/frontend/elaborate/index.ts +52 -17
- package/src/frontend/elaborate/initializers.ts +3 -2
- package/src/frontend/elaborate/layouts.ts +2 -2
- package/src/frontend/elaborate/model.ts +34 -21
- package/src/frontend/elaborate/retention.ts +206 -0
- package/src/frontend/elaborate/specialize.ts +7 -6
- package/src/frontend/elaborate/statements.ts +47 -38
- package/src/frontend/elaborate/storage.ts +26 -6
- package/src/frontend/exposure.ts +6 -6
- package/src/frontend/expressions.ts +26 -25
- package/src/frontend/intrinsics.ts +3 -3
- package/src/frontend/module-graph.ts +1 -1
- package/src/frontend/positions.ts +2 -1
- package/src/frontend/promise-chains.ts +1 -0
- package/src/frontend/promises.ts +8 -7
- package/src/frontend/routines.ts +3 -2
- package/src/frontend/sdk.ts +2 -2
- package/src/frontend/services.ts +23 -20
- package/src/frontend/statements.ts +8 -6
- package/src/frontend/tasks.ts +11 -6
- package/src/frontend/telemetry.ts +1 -1
- package/src/frontend/types.ts +11 -9
- package/src/frontend/typescript.ts +92 -42
- package/src/index.ts +2 -1
- package/src/ir/aggregates.ts +4 -3
- package/src/ir/allocation.ts +2 -1
- package/src/ir/core-model.ts +38 -8
- package/src/ir/declarations.ts +12 -12
- package/src/ir/domains.ts +8 -8
- package/src/ir/fold.ts +2 -2
- package/src/ir/index.ts +53 -40
- package/src/ir/job-errors.ts +22 -11
- package/src/ir/layouts.ts +3 -2
- package/src/ir/link.ts +6 -24
- package/src/ir/model.ts +3 -2
- package/src/ir/normalization-error.ts +1 -1
- package/src/ir/normalize.ts +19 -12
- package/src/ir/numeric.ts +1 -0
- package/src/{codesys → ir}/operands.ts +2 -6
- package/src/ir/ranges.ts +2 -2
- package/src/ir/routine.ts +35 -20
- package/src/ir/scalars.ts +3 -3
- package/src/ir/share.ts +862 -0
- package/src/ir/temporaries.ts +236 -0
- package/src/ir/types.ts +1 -1
- package/src/project/artifacts.ts +12 -2
- package/src/project/cli.ts +42 -44
- package/src/project/debugger.ts +15 -9
- package/src/project/index.ts +1 -1
- package/src/project/plant.ts +34 -23
- package/src/project/project-commands.ts +92 -73
- package/src/project/project.ts +91 -42
- package/src/project/release.ts +50 -57
- package/src/project/server-check.ts +54 -0
- package/src/project/server.ts +60 -41
- package/src/project/terminal.ts +3 -1
- package/stdlib/retain.ts +2 -0
- package/types/globals.d.ts +1 -0
- package/types/retain.d.ts +6 -0
- package/types/telemetry.d.ts +2 -2
package/src/ir/normalize.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { PlcModule } from "./model.ts";
|
|
1
|
+
import { checkStaticAllocation } from "./allocation.ts";
|
|
3
2
|
import {
|
|
4
|
-
verified,
|
|
5
|
-
type VerifiedCoreModule,
|
|
6
3
|
type CoreFunction,
|
|
7
4
|
type CoreFunctionBlock,
|
|
5
|
+
type VerifiedCoreModule,
|
|
6
|
+
verified,
|
|
8
7
|
} from "./core-model.ts";
|
|
9
8
|
import { ModuleDeclarations } from "./declarations.ts";
|
|
10
|
-
import {
|
|
11
|
-
import { RoutineNormalizer } from "./routine.ts";
|
|
9
|
+
import type { Diagnostic } from "./diagnostics.ts";
|
|
12
10
|
import { linkModule } from "./link.ts";
|
|
11
|
+
import type { PlcModule } from "./model.ts";
|
|
13
12
|
import { InvalidCore } from "./normalization-error.ts";
|
|
13
|
+
import { RoutineNormalizer } from "./routine.ts";
|
|
14
14
|
|
|
15
15
|
const verifiedModules = new WeakSet<object>();
|
|
16
16
|
export function isVerifiedCore(value: unknown): value is VerifiedCoreModule {
|
|
@@ -28,6 +28,16 @@ function freeze(value: unknown): void {
|
|
|
28
28
|
}
|
|
29
29
|
Object.freeze(value);
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Admits a module across the trust boundary. Only normalization, and transformations of an
|
|
33
|
+
* admitted module that keep what it verified, call this.
|
|
34
|
+
*/
|
|
35
|
+
export function admitCore(core: VerifiedCoreModule): VerifiedCoreModule {
|
|
36
|
+
freeze(core);
|
|
37
|
+
verifiedModules.add(core);
|
|
38
|
+
return core;
|
|
39
|
+
}
|
|
40
|
+
|
|
31
41
|
// The module crosses the trust boundary only after admission, lowering and linking.
|
|
32
42
|
export function normalizeModule(module: PlcModule): {
|
|
33
43
|
core?: VerifiedCoreModule;
|
|
@@ -54,13 +64,10 @@ export function normalizeModule(module: PlcModule): {
|
|
|
54
64
|
}
|
|
55
65
|
|
|
56
66
|
const linked = linkModule(module, declarations, functions, blocks, edges);
|
|
57
|
-
|
|
58
|
-
...structuredClone(linked),
|
|
59
|
-
[
|
|
67
|
+
return {
|
|
68
|
+
core: admitCore({ ...structuredClone(linked), [verified]: true }),
|
|
69
|
+
diagnostics: [],
|
|
60
70
|
};
|
|
61
|
-
freeze(core);
|
|
62
|
-
verifiedModules.add(core);
|
|
63
|
-
return { core, diagnostics: [] };
|
|
64
71
|
} catch (cause) {
|
|
65
72
|
if (cause instanceof InvalidCore) {
|
|
66
73
|
return { diagnostics: [cause.diagnostic] };
|
package/src/ir/numeric.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// biome-ignore-all lint/style/noNonNullAssertion: Retain existing non-null assertions during the tooling migration; changing their contracts requires a separate review.
|
|
1
2
|
import type { Constant } from "./model.ts";
|
|
2
3
|
import { integerRange, type PlcType } from "./types.ts";
|
|
3
4
|
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
type CorePath,
|
|
4
|
-
type CoreStatement,
|
|
5
|
-
telemetryOperands,
|
|
6
|
-
} from "@tsplc/compiler/ir";
|
|
1
|
+
import type { CoreExpression, CorePath, CoreStatement } from "./core-model.ts";
|
|
2
|
+
import { telemetryOperands } from "./model.ts";
|
|
7
3
|
|
|
8
4
|
/** The index expressions along a place's path. */
|
|
9
5
|
export const pathIndexes = (path: CorePath = []): CoreExpression[] =>
|
package/src/ir/ranges.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
+
import { fold } from "./fold.ts";
|
|
1
2
|
import type {
|
|
2
3
|
BinaryOperator,
|
|
3
4
|
Expression,
|
|
4
5
|
MathHelper,
|
|
5
6
|
Variable,
|
|
6
7
|
} from "./model.ts";
|
|
7
|
-
import { fold } from "./fold.ts";
|
|
8
8
|
import {
|
|
9
9
|
admits,
|
|
10
10
|
highest,
|
|
11
|
+
type IntegerInterval,
|
|
11
12
|
integerType,
|
|
12
13
|
lowest,
|
|
13
14
|
within,
|
|
14
|
-
type IntegerInterval,
|
|
15
15
|
} from "./numeric.ts";
|
|
16
16
|
import { integerRange, type PlcType } from "./types.ts";
|
|
17
17
|
|
package/src/ir/routine.ts
CHANGED
|
@@ -1,20 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
FunctionBlock,
|
|
9
|
-
} from "./model.ts";
|
|
1
|
+
// biome-ignore-all lint/style/noNonNullAssertion: Retain existing non-null assertions during the tooling migration; changing their contracts requires a separate review.
|
|
2
|
+
import {
|
|
3
|
+
aggregate,
|
|
4
|
+
expressionIssue,
|
|
5
|
+
placeType,
|
|
6
|
+
valueFits,
|
|
7
|
+
} from "./aggregates.ts";
|
|
10
8
|
import type {
|
|
11
9
|
CoreExpression,
|
|
12
|
-
CoreStatement,
|
|
13
|
-
CorePath,
|
|
14
10
|
CoreFunction,
|
|
15
11
|
CoreFunctionBlock,
|
|
12
|
+
CorePath,
|
|
13
|
+
CoreStatement,
|
|
16
14
|
} from "./core-model.ts";
|
|
15
|
+
import type { ModuleDeclarations } from "./declarations.ts";
|
|
16
|
+
import type { SourceSpan } from "./diagnostics.ts";
|
|
17
17
|
import { fold } from "./fold.ts";
|
|
18
|
+
import type {
|
|
19
|
+
Expression,
|
|
20
|
+
FunctionBlock,
|
|
21
|
+
Place,
|
|
22
|
+
PlcFunction,
|
|
23
|
+
Statement,
|
|
24
|
+
Variable,
|
|
25
|
+
} from "./model.ts";
|
|
26
|
+
import { reject } from "./normalization-error.ts";
|
|
18
27
|
import { admits, canonicalInteger, type IntegerInterval } from "./numeric.ts";
|
|
19
28
|
import {
|
|
20
29
|
interval,
|
|
@@ -24,14 +33,6 @@ import {
|
|
|
24
33
|
valueRange,
|
|
25
34
|
} from "./ranges.ts";
|
|
26
35
|
import { instancedBlock, integerRange } from "./types.ts";
|
|
27
|
-
import {
|
|
28
|
-
aggregate,
|
|
29
|
-
expressionIssue,
|
|
30
|
-
placeType,
|
|
31
|
-
valueFits,
|
|
32
|
-
} from "./aggregates.ts";
|
|
33
|
-
import { reject } from "./normalization-error.ts";
|
|
34
|
-
import type { ModuleDeclarations } from "./declarations.ts";
|
|
35
36
|
|
|
36
37
|
type Flow = "fallthrough" | "return" | "loop" | "mixed";
|
|
37
38
|
interface FlowState {
|
|
@@ -71,6 +72,20 @@ const join = (
|
|
|
71
72
|
|
|
72
73
|
// All mutable lowering state belongs to one invocation of one authored routine.
|
|
73
74
|
// sourceScope admits authored places; scope additionally contains captured temps.
|
|
75
|
+
const temporaryPrefix = (routine: string) => `${routine}:temporary:`;
|
|
76
|
+
const temporaryId = (routine: string, index: number) =>
|
|
77
|
+
`${temporaryPrefix(routine)}${index}`;
|
|
78
|
+
|
|
79
|
+
/** Whether a local is a temporary the normalizer made for `routine`, rather than one its source declares. */
|
|
80
|
+
export function isTemporary(routine: string, variable: Variable): boolean {
|
|
81
|
+
const prefix = temporaryPrefix(routine);
|
|
82
|
+
return (
|
|
83
|
+
variable.storage === "local" &&
|
|
84
|
+
variable.id.startsWith(prefix) &&
|
|
85
|
+
/^\d+$/.test(variable.id.slice(prefix.length))
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
74
89
|
export class RoutineNormalizer {
|
|
75
90
|
private readonly fn: PlcFunction;
|
|
76
91
|
|
|
@@ -149,7 +164,7 @@ export class RoutineNormalizer {
|
|
|
149
164
|
private temporary(type: string, span: SourceSpan): Variable {
|
|
150
165
|
let id: string;
|
|
151
166
|
do {
|
|
152
|
-
id =
|
|
167
|
+
id = temporaryId(this.fn.id, this.temporaryCount++);
|
|
153
168
|
} while (this.declarations.hasId(id));
|
|
154
169
|
this.declarations.claimId(id);
|
|
155
170
|
const item: Variable = {
|
package/src/ir/scalars.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
+
import { fold } from "./fold.ts";
|
|
1
2
|
import {
|
|
2
|
-
comparisonOperators,
|
|
3
3
|
type Constant,
|
|
4
|
+
comparisonOperators,
|
|
4
5
|
type Expression,
|
|
5
6
|
type Variable,
|
|
6
7
|
} from "./model.ts";
|
|
7
|
-
import { fold } from "./fold.ts";
|
|
8
8
|
import {
|
|
9
9
|
admits,
|
|
10
10
|
canAssign,
|
|
11
11
|
constantFits,
|
|
12
12
|
exactIntegerLimit,
|
|
13
13
|
floatMaximum,
|
|
14
|
+
type IntegerInterval,
|
|
14
15
|
integerType,
|
|
15
16
|
roundFloat,
|
|
16
17
|
within,
|
|
17
18
|
wrapsNatively,
|
|
18
|
-
type IntegerInterval,
|
|
19
19
|
} from "./numeric.ts";
|
|
20
20
|
import { interval } from "./ranges.ts";
|
|
21
21
|
import { integerRange, type PlcType } from "./types.ts";
|