@tsplc/compiler 0.5.3 → 0.5.5
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/dist/bun-runtime.js.map +7 -7
- package/dist/cli.js.map +8 -8
- package/dist/codesys.js +2 -2
- package/dist/codesys.js.map +23 -23
- package/dist/elaborate-capture.js +3 -2
- package/dist/elaborate-capture.js.map +3 -3
- package/dist/index.js +26 -19
- package/dist/index.js.map +38 -38
- package/dist/ir.js.map +19 -19
- package/dist/project.js.map +1 -1
- package/dist/server-check.js.map +1 -1
- package/dist/telemetry.js.map +1 -1
- package/package.json +9 -9
- package/src/codesys/config.ts +2 -2
- package/src/codesys/debug.ts +2 -2
- package/src/codesys/emit.ts +10 -10
- package/src/codesys/engineering.ts +1 -1
- package/src/codesys/expressions.ts +1 -1
- package/src/codesys/global-lists.ts +6 -6
- package/src/codesys/global-names.ts +3 -3
- package/src/codesys/http.ts +3 -3
- package/src/codesys/index.ts +8 -8
- package/src/codesys/instrumentation.ts +9 -13
- package/src/codesys/io-paths.ts +1 -1
- package/src/codesys/manifest.ts +5 -5
- package/src/codesys/plan.ts +9 -9
- package/src/codesys/programs.ts +3 -3
- package/src/codesys/publication.ts +4 -4
- package/src/codesys/routines.ts +5 -5
- package/src/codesys/st-files.ts +4 -4
- package/src/codesys/symbols.ts +6 -6
- package/src/codesys/telemetry.ts +6 -6
- package/src/codesys/types.ts +2 -2
- package/src/codesys/vendor.ts +2 -2
- package/src/frontend/analyzer.ts +9 -9
- package/src/frontend/async.ts +6 -6
- package/src/frontend/blocks.ts +1 -1
- package/src/frontend/configuration.ts +4 -4
- package/src/frontend/const-functions.ts +2 -2
- package/src/frontend/cooperative.ts +1 -1
- package/src/frontend/coroutines.ts +6 -6
- package/src/frontend/elaborate/calls.ts +29 -18
- package/src/frontend/elaborate/capture.ts +3 -2
- package/src/frontend/elaborate/dialect.ts +9 -9
- package/src/frontend/elaborate/expressions.ts +12 -12
- package/src/frontend/elaborate/frame.ts +4 -4
- package/src/frontend/elaborate/graph.ts +1 -1
- package/src/frontend/elaborate/imports.ts +14 -15
- package/src/frontend/elaborate/index.ts +12 -12
- package/src/frontend/elaborate/initializers.ts +4 -4
- package/src/frontend/elaborate/layouts.ts +3 -3
- package/src/frontend/elaborate/model.ts +1 -1
- package/src/frontend/elaborate/retention.ts +5 -5
- package/src/frontend/elaborate/specialize.ts +11 -11
- package/src/frontend/elaborate/statements.ts +8 -11
- package/src/frontend/elaborate/storage.ts +6 -11
- package/src/frontend/elaborate/values.ts +2 -2
- package/src/frontend/exposure.ts +3 -3
- package/src/frontend/expressions.ts +5 -5
- package/src/frontend/intrinsics.ts +2 -2
- package/src/frontend/module-graph.ts +1 -1
- package/src/frontend/promise-chains.ts +2 -2
- package/src/frontend/promises.ts +5 -5
- package/src/frontend/routines.ts +2 -2
- package/src/frontend/sdk.ts +7 -1
- package/src/frontend/services.ts +3 -3
- package/src/frontend/statements.ts +4 -4
- package/src/frontend/tasks.ts +5 -10
- package/src/frontend/telemetry.ts +2 -2
- package/src/frontend/types.ts +1 -1
- package/src/frontend/typescript.ts +11 -15
- package/src/index.ts +1 -1
- package/src/ir/aggregates.ts +6 -6
- package/src/ir/allocation.ts +5 -5
- package/src/ir/core-model.ts +3 -3
- package/src/ir/declarations.ts +6 -6
- package/src/ir/domains.ts +3 -7
- package/src/ir/fold.ts +4 -9
- package/src/ir/index.ts +16 -16
- package/src/ir/layouts.ts +3 -3
- package/src/ir/link.ts +5 -5
- package/src/ir/model.ts +2 -2
- package/src/ir/normalization-error.ts +1 -1
- package/src/ir/normalize.ts +8 -8
- package/src/ir/numeric.ts +2 -2
- package/src/ir/operands.ts +2 -2
- package/src/ir/ranges.ts +4 -9
- package/src/ir/routine.ts +10 -15
- package/src/ir/scalars.ts +5 -5
- package/src/ir/share.ts +4 -4
- package/src/ir/temporaries.ts +4 -4
- package/src/project/cli.ts +3 -3
- package/src/project/debugger.ts +1 -1
- package/src/project/index.ts +1 -1
- package/src/project/plant.ts +2 -2
- package/src/project/project-commands.ts +3 -3
- package/src/project/project.ts +2 -2
- package/src/project/release.ts +2 -2
- package/src/project/server-check.ts +1 -1
- package/src/runtime/main.ts +2 -2
- package/src/runtime/process.ts +1 -1
- package/src/runtime/program.ts +2 -2
- package/src/runtime/retain.ts +1 -1
- package/src/runtime/runtime.ts +11 -16
- package/stdlib/telemetry.ts +2 -2
package/src/codesys/vendor.ts
CHANGED
|
@@ -4,8 +4,8 @@ import type {
|
|
|
4
4
|
EmitResult,
|
|
5
5
|
GeneratedObject,
|
|
6
6
|
} from "@tsplc/compiler/ir";
|
|
7
|
-
import type { SourceMapping } from "./emit
|
|
8
|
-
import { declarationFile } from "./st-files
|
|
7
|
+
import type { SourceMapping } from "./emit";
|
|
8
|
+
import { declarationFile } from "./st-files";
|
|
9
9
|
|
|
10
10
|
type MappedBundle = Pick<EmitResult, "objects"> & {
|
|
11
11
|
mappings: readonly SourceMapping[];
|
package/src/frontend/analyzer.ts
CHANGED
|
@@ -10,17 +10,17 @@ import {
|
|
|
10
10
|
type Variable,
|
|
11
11
|
} from "@tsplc/compiler/ir";
|
|
12
12
|
import ts from "typescript";
|
|
13
|
-
import { BlockResolver, storageInitializer } from "./blocks
|
|
13
|
+
import { BlockResolver, storageInitializer } from "./blocks";
|
|
14
14
|
import {
|
|
15
15
|
type AnalysisContext,
|
|
16
16
|
ExpressionLowering,
|
|
17
17
|
type LoweringScope,
|
|
18
|
-
} from "./expressions
|
|
19
|
-
import { runtimeSources } from "./module-graph
|
|
20
|
-
import type { Positions } from "./positions
|
|
21
|
-
import { methodAccess, RoutineTable } from "./routines
|
|
22
|
-
import { inSdk, unaliased } from "./sdk
|
|
23
|
-
import { StatementLowering } from "./statements
|
|
18
|
+
} from "./expressions";
|
|
19
|
+
import { runtimeSources } from "./module-graph";
|
|
20
|
+
import type { Positions } from "./positions";
|
|
21
|
+
import { methodAccess, RoutineTable } from "./routines";
|
|
22
|
+
import { inSdk, unaliased } from "./sdk";
|
|
23
|
+
import { StatementLowering } from "./statements";
|
|
24
24
|
import {
|
|
25
25
|
type Fail,
|
|
26
26
|
hasModifier,
|
|
@@ -29,8 +29,8 @@ import {
|
|
|
29
29
|
type ResolvedType,
|
|
30
30
|
SemanticError,
|
|
31
31
|
TypeResolver,
|
|
32
|
-
} from "./types
|
|
33
|
-
import type { FrontendOptions } from "./typescript
|
|
32
|
+
} from "./types";
|
|
33
|
+
import type { FrontendOptions } from "./typescript";
|
|
34
34
|
|
|
35
35
|
/** What a module variable's initializer and keyword establish about its storage. */
|
|
36
36
|
interface StorageFacts {
|
package/src/frontend/async.ts
CHANGED
|
@@ -7,8 +7,8 @@ import {
|
|
|
7
7
|
type PlcProgram,
|
|
8
8
|
} from "@tsplc/compiler/ir";
|
|
9
9
|
import ts from "typescript";
|
|
10
|
-
import { lowerCoroutine } from "./coroutines
|
|
11
|
-
import { runtimeSources } from "./module-graph
|
|
10
|
+
import { lowerCoroutine } from "./coroutines";
|
|
11
|
+
import { runtimeSources } from "./module-graph";
|
|
12
12
|
import {
|
|
13
13
|
type Edit,
|
|
14
14
|
edited,
|
|
@@ -18,10 +18,10 @@ import {
|
|
|
18
18
|
mapped,
|
|
19
19
|
type Positions,
|
|
20
20
|
slice,
|
|
21
|
-
} from "./positions
|
|
22
|
-
import { namesSdk, symbolAt } from "./sdk
|
|
23
|
-
import { lowerTaskDefinitions } from "./tasks
|
|
24
|
-
import { hasModifier, SemanticError } from "./types
|
|
21
|
+
} from "./positions";
|
|
22
|
+
import { namesSdk, symbolAt } from "./sdk";
|
|
23
|
+
import { lowerTaskDefinitions } from "./tasks";
|
|
24
|
+
import { hasModifier, SemanticError } from "./types";
|
|
25
25
|
|
|
26
26
|
export type Job = NonNullable<FunctionBlock["job"]>;
|
|
27
27
|
/** A named async function or method. */
|
package/src/frontend/blocks.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type Diagnostic, error } from "@tsplc/compiler/ir";
|
|
2
2
|
import ts from "typescript";
|
|
3
|
-
import { runtimeSources } from "./module-graph
|
|
4
|
-
import { type Edit, edited, type Mapped, type Positions } from "./positions
|
|
5
|
-
import { namesSdk, symbolAt } from "./sdk
|
|
6
|
-
import type { CompileEnvironment } from "./typescript
|
|
3
|
+
import { runtimeSources } from "./module-graph";
|
|
4
|
+
import { type Edit, edited, type Mapped, type Positions } from "./positions";
|
|
5
|
+
import { namesSdk, symbolAt } from "./sdk";
|
|
6
|
+
import type { CompileEnvironment } from "./typescript";
|
|
7
7
|
|
|
8
8
|
export const lowerEnvironment = (
|
|
9
9
|
program: ts.Program,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Diagnostic, error } from "@tsplc/compiler/ir";
|
|
2
2
|
import ts from "typescript";
|
|
3
|
-
import { runtimeSources } from "./module-graph
|
|
3
|
+
import { runtimeSources } from "./module-graph";
|
|
4
4
|
import {
|
|
5
5
|
copied,
|
|
6
6
|
type Edit,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
mapped,
|
|
12
12
|
type Part,
|
|
13
13
|
type Positions,
|
|
14
|
-
} from "./positions
|
|
14
|
+
} from "./positions";
|
|
15
15
|
|
|
16
16
|
/** An arrow body as a function body: a block as written, or its expression returned (or, for void, evaluated). */
|
|
17
17
|
const functionBody = (
|
|
@@ -7,10 +7,10 @@ import type {
|
|
|
7
7
|
MethodMembers,
|
|
8
8
|
Routine,
|
|
9
9
|
SourceRewrite,
|
|
10
|
-
} from "./async
|
|
11
|
-
import { staticString } from "./configuration
|
|
12
|
-
import { copyValue } from "./cooperative
|
|
13
|
-
import { importSpecifier } from "./module-graph
|
|
10
|
+
} from "./async";
|
|
11
|
+
import { staticString } from "./configuration";
|
|
12
|
+
import { copyValue } from "./cooperative";
|
|
13
|
+
import { importSpecifier } from "./module-graph";
|
|
14
14
|
import {
|
|
15
15
|
copied,
|
|
16
16
|
type Edit,
|
|
@@ -20,8 +20,8 @@ import {
|
|
|
20
20
|
type Mapped,
|
|
21
21
|
mapped,
|
|
22
22
|
type Part,
|
|
23
|
-
} from "./positions
|
|
24
|
-
import { hasModifier } from "./types
|
|
23
|
+
} from "./positions";
|
|
24
|
+
import { hasModifier } from "./types";
|
|
25
25
|
|
|
26
26
|
type Step = Job["steps"][number];
|
|
27
27
|
/** What a step does when the operation it waits on fails; `cancellable` failures may be a cancel. */
|
|
@@ -7,24 +7,21 @@ import {
|
|
|
7
7
|
type Mapped,
|
|
8
8
|
mapped,
|
|
9
9
|
type Part,
|
|
10
|
-
} from "../positions
|
|
11
|
-
import { declaredBySdk, inSdk, symbolAt } from "../sdk
|
|
12
|
-
import type { DialectText } from "./dialect
|
|
13
|
-
import type {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} from "./
|
|
17
|
-
import type {
|
|
18
|
-
import type { EntryImports } from "./imports.ts";
|
|
19
|
-
import type { Model } from "./model.ts";
|
|
20
|
-
import type { Storage } from "./storage.ts";
|
|
10
|
+
} from "../positions";
|
|
11
|
+
import { declaredBySdk, inSdk, sdkModule, symbolAt } from "../sdk";
|
|
12
|
+
import type { DialectText } from "./dialect";
|
|
13
|
+
import type { ExpressionSpecializer, SpecializeContext } from "./expressions";
|
|
14
|
+
import type { Frame } from "./frame";
|
|
15
|
+
import type { EntryImports } from "./imports";
|
|
16
|
+
import type { Model } from "./model";
|
|
17
|
+
import type { Storage } from "./storage";
|
|
21
18
|
import {
|
|
22
19
|
constant,
|
|
23
20
|
type FunctionLike,
|
|
24
21
|
repeatable,
|
|
25
22
|
SpecializeError,
|
|
26
23
|
type Value,
|
|
27
|
-
} from "./values
|
|
24
|
+
} from "./values";
|
|
28
25
|
|
|
29
26
|
/** Specializes calls: to what the language and SDK provide, to the service client, and to functions. */
|
|
30
27
|
export class CallSpecializer {
|
|
@@ -149,8 +146,9 @@ export class CallSpecializer {
|
|
|
149
146
|
expected,
|
|
150
147
|
);
|
|
151
148
|
}
|
|
152
|
-
|
|
153
|
-
|
|
149
|
+
const sdkFile = ts.isIdentifier(callee) && this.sdkDeclaration(callee);
|
|
150
|
+
if (ts.isIdentifier(callee) && sdkFile) {
|
|
151
|
+
return this.sdk(callee.text, sdkModule(sdkFile), node, frame);
|
|
154
152
|
}
|
|
155
153
|
return this.expressions.invoke(
|
|
156
154
|
target,
|
|
@@ -208,9 +206,17 @@ export class CallSpecializer {
|
|
|
208
206
|
}
|
|
209
207
|
|
|
210
208
|
/** SDK functions scan code calls, such as the PLC clock. */
|
|
211
|
-
|
|
209
|
+
/** The SDK declaration file of the function `callee` names, or null when the SDK doesn't declare it. */
|
|
210
|
+
private sdkDeclaration(callee: ts.Identifier): string | null {
|
|
212
211
|
const symbol = symbolAt(this.checker, callee);
|
|
213
|
-
|
|
212
|
+
if (symbol === undefined || !declaredBySdk(this.sdkFile, symbol)) {
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
return (
|
|
216
|
+
symbol.declarations
|
|
217
|
+
?.map((declaration) => declaration.getSourceFile().fileName)
|
|
218
|
+
.find((file) => inSdk(this.sdkFile, file)) ?? null
|
|
219
|
+
);
|
|
214
220
|
}
|
|
215
221
|
|
|
216
222
|
/** A method of `@tsplc/compiler/telemetry`'s `telemetry`. */
|
|
@@ -272,14 +278,19 @@ export class CallSpecializer {
|
|
|
272
278
|
);
|
|
273
279
|
}
|
|
274
280
|
|
|
275
|
-
private sdk(
|
|
281
|
+
private sdk(
|
|
282
|
+
name: string,
|
|
283
|
+
module: string,
|
|
284
|
+
node: ts.CallExpression,
|
|
285
|
+
frame: Frame,
|
|
286
|
+
): Value {
|
|
276
287
|
const args = node.arguments.map((argument) =>
|
|
277
288
|
this.dialect.code(
|
|
278
289
|
this.expressions.expression(argument, frame),
|
|
279
290
|
undefined,
|
|
280
291
|
),
|
|
281
292
|
);
|
|
282
|
-
this.imports.
|
|
293
|
+
this.imports.addSdk(module, name);
|
|
283
294
|
return {
|
|
284
295
|
kind: "code",
|
|
285
296
|
text: mapped`${name}(${joined(args, ", ")})`,
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
type CaptureRequest,
|
|
17
17
|
captureRequestSchema,
|
|
18
18
|
withBindingRegistry,
|
|
19
|
-
} from "./capture-protocol
|
|
19
|
+
} from "./capture-protocol";
|
|
20
20
|
|
|
21
21
|
const request: CaptureRequest = captureRequestSchema.parse(
|
|
22
22
|
JSON.parse(readFileSync(process.argv[2]!, "utf8")),
|
|
@@ -76,7 +76,8 @@ plugin({
|
|
|
76
76
|
build.module("@tsplc/compiler/async", () => ({
|
|
77
77
|
contents: `export const createServiceClient = () => globalThis.__tsplcService([]);
|
|
78
78
|
const unsupported = (name) => () => { throw new Error(name + " cannot run during PLC setup."); };
|
|
79
|
-
export const sleep = unsupported("sleep"), fetch = unsupported("fetch"), cancelAsync = unsupported("cancelAsync")
|
|
79
|
+
export const sleep = unsupported("sleep"), fetch = unsupported("fetch"), cancelAsync = unsupported("cancelAsync");
|
|
80
|
+
export const errorCode = unsupported("errorCode"), asyncDiagnostics = unsupported("asyncDiagnostics"), opcuaCall = unsupported("opcuaCall");`,
|
|
80
81
|
loader: "js",
|
|
81
82
|
}));
|
|
82
83
|
},
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { canAssign, integerType, primitiveTypes } from "@tsplc/compiler/ir";
|
|
2
2
|
import ts from "typescript";
|
|
3
|
-
import { joined, type Mapped, mapped } from "../positions
|
|
4
|
-
import type { EntryImports } from "./imports
|
|
5
|
-
import type { Initializers } from "./initializers
|
|
6
|
-
import type { Layouts } from "./layouts
|
|
7
|
-
import type { Model } from "./model
|
|
8
|
-
import type { Storage } from "./storage
|
|
9
|
-
import type { Value } from "./values
|
|
3
|
+
import { joined, type Mapped, mapped } from "../positions";
|
|
4
|
+
import type { EntryImports } from "./imports";
|
|
5
|
+
import type { Initializers } from "./initializers";
|
|
6
|
+
import type { Layouts } from "./layouts";
|
|
7
|
+
import type { Model } from "./model";
|
|
8
|
+
import type { Storage } from "./storage";
|
|
9
|
+
import type { Value } from "./values";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Specialized values as dialect text, in a place of a declared type: literals as enum members,
|
|
@@ -152,7 +152,7 @@ export class DialectText {
|
|
|
152
152
|
needsConversion(value.iec ?? "DINT", target)
|
|
153
153
|
) {
|
|
154
154
|
// A TypeScript number holds any of these; in the PLC a value converts as an IEC assignment does.
|
|
155
|
-
this.imports.
|
|
155
|
+
this.imports.addSdk("@tsplc/compiler/types", "wrap");
|
|
156
156
|
return mapped`wrap<${target}>(${this.code(value, undefined)})`;
|
|
157
157
|
}
|
|
158
158
|
if (declared && this.layouts.isOptionalRecord(declared)) {
|
|
@@ -237,7 +237,7 @@ export class DialectText {
|
|
|
237
237
|
if (!needsConversion(from, to) || !needsConversion(to, from)) {
|
|
238
238
|
return [leftText, rightText];
|
|
239
239
|
}
|
|
240
|
-
this.imports.
|
|
240
|
+
this.imports.addSdk("@tsplc/compiler/types", "wrap");
|
|
241
241
|
return [mapped`wrap<LINT>(${leftText})`, mapped`wrap<LINT>(${rightText})`];
|
|
242
242
|
}
|
|
243
243
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// biome-ignore-all lint/style/noNonNullAssertion: Retain existing non-null assertions during the tooling migration; changing their contracts requires a separate review.
|
|
2
2
|
import ts from "typescript";
|
|
3
|
-
import { from, joined, type Mapped, mapped } from "../positions
|
|
4
|
-
import { unaliased } from "../sdk
|
|
5
|
-
import { CallSpecializer } from "./calls
|
|
6
|
-
import type { DialectText } from "./dialect
|
|
7
|
-
import type { Frame } from "./frame
|
|
8
|
-
import type { EntryImports } from "./imports
|
|
9
|
-
import type { Initializers } from "./initializers
|
|
10
|
-
import { type Layouts, recordTypes } from "./layouts
|
|
11
|
-
import type { Model, ModelNode } from "./model
|
|
12
|
-
import type { Storage } from "./storage
|
|
3
|
+
import { from, joined, type Mapped, mapped } from "../positions";
|
|
4
|
+
import { unaliased } from "../sdk";
|
|
5
|
+
import { CallSpecializer } from "./calls";
|
|
6
|
+
import type { DialectText } from "./dialect";
|
|
7
|
+
import type { Frame } from "./frame";
|
|
8
|
+
import type { EntryImports } from "./imports";
|
|
9
|
+
import type { Initializers } from "./initializers";
|
|
10
|
+
import { type Layouts, recordTypes } from "./layouts";
|
|
11
|
+
import type { Model, ModelNode } from "./model";
|
|
12
|
+
import type { Storage } from "./storage";
|
|
13
13
|
import {
|
|
14
14
|
constant,
|
|
15
15
|
type Env,
|
|
@@ -17,8 +17,8 @@ import {
|
|
|
17
17
|
repeatable,
|
|
18
18
|
SpecializeError,
|
|
19
19
|
type Value,
|
|
20
|
-
} from "./values
|
|
21
|
-
import { isAssignment } from "./writes
|
|
20
|
+
} from "./values";
|
|
21
|
+
import { isAssignment } from "./writes";
|
|
22
22
|
|
|
23
23
|
/** What every part of scan-code specialization shares. */
|
|
24
24
|
export interface SpecializeContext {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type ts from "typescript";
|
|
2
|
-
import { from, type Mapped, mapped, type Part } from "../positions
|
|
3
|
-
import { unusedName } from "./layouts
|
|
4
|
-
import type { ModelNode } from "./model
|
|
5
|
-
import type { Env } from "./values
|
|
2
|
+
import { from, type Mapped, mapped, type Part } from "../positions";
|
|
3
|
+
import { unusedName } from "./layouts";
|
|
4
|
+
import type { ModelNode } from "./model";
|
|
5
|
+
import type { Env } from "./values";
|
|
6
6
|
|
|
7
7
|
/** Indented lines of one generated routine, with the local names it has used. */
|
|
8
8
|
export class Emitter {
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
type CapturedGraph,
|
|
16
16
|
type CaptureRequest,
|
|
17
17
|
capturedGraphSchema,
|
|
18
|
-
} from "./capture-protocol
|
|
18
|
+
} from "./capture-protocol";
|
|
19
19
|
|
|
20
20
|
/** The top-level bindings a module declares: values, classes and functions, arrow functions among them. */
|
|
21
21
|
export const bindingNames = (source: ts.SourceFile) => {
|
|
@@ -31,20 +31,25 @@ export class ModuleImports {
|
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* What the generated entry module imports besides the generated types: the storage modules,
|
|
34
|
-
* kept modules' bindings and the SDK functions scan code
|
|
34
|
+
* kept modules' bindings, and the SDK functions scan code and generated conversions call.
|
|
35
35
|
*/
|
|
36
36
|
export class EntryImports {
|
|
37
37
|
/** Storage modules generated code reads through a namespace import, by import name. */
|
|
38
38
|
readonly namespaces = new Map<string, string>();
|
|
39
39
|
/** Bindings of kept modules, read by their own names. */
|
|
40
40
|
readonly kept = new ModuleImports();
|
|
41
|
-
/** `@tsplc/compiler/clock
|
|
42
|
-
readonly
|
|
43
|
-
/** Conversions generated code calls from `@tsplc/compiler/types`. */
|
|
44
|
-
readonly conversions = new Set<string>();
|
|
41
|
+
/** SDK functions by the module that declares them, such as `@tsplc/compiler/clock`. */
|
|
42
|
+
private readonly sdk = new Map<string, Set<string>>();
|
|
45
43
|
/** Whether scan code calls `telemetry`. */
|
|
46
44
|
telemetry = false;
|
|
47
45
|
|
|
46
|
+
/** Records a call of `name`, which `module` of the SDK declares. */
|
|
47
|
+
addSdk(module: string, name: string): void {
|
|
48
|
+
const names = this.sdk.get(module) ?? new Set<string>();
|
|
49
|
+
names.add(name);
|
|
50
|
+
this.sdk.set(module, names);
|
|
51
|
+
}
|
|
52
|
+
|
|
48
53
|
lines(entryFile: string): string[] {
|
|
49
54
|
return [
|
|
50
55
|
...[...this.namespaces].map(
|
|
@@ -52,19 +57,13 @@ export class EntryImports {
|
|
|
52
57
|
`import * as ${name} from "${importPath(entryFile, file)}";`,
|
|
53
58
|
),
|
|
54
59
|
...this.kept.lines(entryFile, "import"),
|
|
55
|
-
...
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
: []),
|
|
60
|
+
...[...this.sdk].map(
|
|
61
|
+
([module, names]) =>
|
|
62
|
+
`import { ${[...names].join(", ")} } from "${module}";`,
|
|
63
|
+
),
|
|
60
64
|
...(this.telemetry
|
|
61
65
|
? [`import { telemetry } from "@tsplc/compiler/telemetry";`]
|
|
62
66
|
: []),
|
|
63
|
-
...(this.conversions.size
|
|
64
|
-
? [
|
|
65
|
-
`import { ${[...this.conversions].join(", ")} } from "@tsplc/compiler/types";`,
|
|
66
|
-
]
|
|
67
|
-
: []),
|
|
68
67
|
];
|
|
69
68
|
}
|
|
70
69
|
}
|
|
@@ -8,24 +8,24 @@ import {
|
|
|
8
8
|
} from "@tsplc/compiler/ir";
|
|
9
9
|
import { generatedDirectory } from "@tsplc/config/project-files";
|
|
10
10
|
import ts from "typescript";
|
|
11
|
-
import { runtimeSources } from "../module-graph
|
|
11
|
+
import { runtimeSources } from "../module-graph";
|
|
12
12
|
import {
|
|
13
13
|
copied,
|
|
14
14
|
from,
|
|
15
15
|
joined,
|
|
16
16
|
type Mapped,
|
|
17
17
|
type Positions,
|
|
18
|
-
} from "../positions
|
|
19
|
-
import { inSdk, namesSdk } from "../sdk
|
|
20
|
-
import type { CompileDebug } from "../typescript
|
|
21
|
-
import type { CapturedValue } from "./capture-protocol
|
|
22
|
-
import { captureGraph } from "./graph
|
|
23
|
-
import { importPath } from "./imports
|
|
24
|
-
import { Model, type Root } from "./model
|
|
25
|
-
import { Retention, retainedDeclarations } from "./retention
|
|
26
|
-
import { closingBrace, Specializer } from "./specialize
|
|
27
|
-
import { setterName } from "./storage
|
|
28
|
-
import { SpecializeError } from "./values
|
|
18
|
+
} from "../positions";
|
|
19
|
+
import { inSdk, namesSdk } from "../sdk";
|
|
20
|
+
import type { CompileDebug } from "../typescript";
|
|
21
|
+
import type { CapturedValue } from "./capture-protocol";
|
|
22
|
+
import { captureGraph } from "./graph";
|
|
23
|
+
import { importPath } from "./imports";
|
|
24
|
+
import { Model, type Root } from "./model";
|
|
25
|
+
import { Retention, retainedDeclarations } from "./retention";
|
|
26
|
+
import { closingBrace, Specializer } from "./specialize";
|
|
27
|
+
import { setterName } from "./storage";
|
|
28
|
+
import { SpecializeError } from "./values";
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* A module the compiled program keeps as written: only types, enums, constants and the service
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// biome-ignore-all lint/style/noNonNullAssertion: Retain existing non-null assertions during the tooling migration; changing their contracts requires a separate review.
|
|
2
2
|
import ts from "typescript";
|
|
3
|
-
import type { CapturedValue } from "./capture-protocol
|
|
4
|
-
import { type Layouts, recordTypes } from "./layouts
|
|
5
|
-
import type { Model, ModelNode } from "./model
|
|
6
|
-
import type { Storage } from "./storage
|
|
3
|
+
import type { CapturedValue } from "./capture-protocol";
|
|
4
|
+
import { type Layouts, recordTypes } from "./layouts";
|
|
5
|
+
import type { Model, ModelNode } from "./model";
|
|
6
|
+
import type { Storage } from "./storage";
|
|
7
7
|
|
|
8
8
|
/** Values setup captured as dialect text: storage initializers, and fixed data scan code reads. */
|
|
9
9
|
export class Initializers {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { primitiveTypes } from "@tsplc/compiler/ir";
|
|
2
2
|
import ts from "typescript";
|
|
3
|
-
import type { CapturedValue } from "./capture-protocol
|
|
4
|
-
import { ModuleImports } from "./imports
|
|
5
|
-
import type { Model } from "./model
|
|
3
|
+
import type { CapturedValue } from "./capture-protocol";
|
|
4
|
+
import { ModuleImports } from "./imports";
|
|
5
|
+
import type { Model } from "./model";
|
|
6
6
|
|
|
7
7
|
/** IEC names a program can write as types; they keep their width rather than becoming DINT. */
|
|
8
8
|
const iecNames = new Set(primitiveTypes.map((type) => type.id));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
|
-
import { namesSdk } from "../sdk
|
|
3
|
-
import type { CapturedValue } from "./capture-protocol
|
|
2
|
+
import { namesSdk } from "../sdk";
|
|
3
|
+
import type { CapturedValue } from "./capture-protocol";
|
|
4
4
|
import {
|
|
5
5
|
children,
|
|
6
6
|
type Model,
|
|
@@ -8,9 +8,9 @@ import {
|
|
|
8
8
|
type Owner,
|
|
9
9
|
type Root,
|
|
10
10
|
tsPath,
|
|
11
|
-
} from "./model
|
|
12
|
-
import type { Storage } from "./storage
|
|
13
|
-
import { SpecializeError } from "./values
|
|
11
|
+
} from "./model";
|
|
12
|
+
import type { Storage } from "./storage";
|
|
13
|
+
import { SpecializeError } from "./values";
|
|
14
14
|
|
|
15
15
|
/** A declaration whose initializer retains a primitive: a module binding or a class field. */
|
|
16
16
|
type RetainedDeclaration = ts.VariableDeclaration | ts.PropertyDeclaration;
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
// biome-ignore-all lint/style/noNonNullAssertion: Retain existing non-null assertions during the tooling migration; changing their contracts requires a separate review.
|
|
2
2
|
import ts from "typescript";
|
|
3
|
-
import { from, joined, type Mapped, mapped } from "../positions
|
|
4
|
-
import { DialectText } from "./dialect
|
|
3
|
+
import { from, joined, type Mapped, mapped } from "../positions";
|
|
4
|
+
import { DialectText } from "./dialect";
|
|
5
5
|
import {
|
|
6
6
|
ExpressionSpecializer,
|
|
7
7
|
type RoutineCall,
|
|
8
8
|
type RoutineTable,
|
|
9
9
|
type SpecializeContext,
|
|
10
|
-
} from "./expressions
|
|
11
|
-
import { Emitter, type Frame } from "./frame
|
|
12
|
-
import { EntryImports } from "./imports
|
|
13
|
-
import { Initializers } from "./initializers
|
|
14
|
-
import { Layouts, unusedName } from "./layouts
|
|
15
|
-
import { type Model, type ModelNode, type Root, tsPath } from "./model
|
|
16
|
-
import { StatementSpecializer } from "./statements
|
|
17
|
-
import { Storage } from "./storage
|
|
10
|
+
} from "./expressions";
|
|
11
|
+
import { Emitter, type Frame } from "./frame";
|
|
12
|
+
import { EntryImports } from "./imports";
|
|
13
|
+
import { Initializers } from "./initializers";
|
|
14
|
+
import { Layouts, unusedName } from "./layouts";
|
|
15
|
+
import { type Model, type ModelNode, type Root, tsPath } from "./model";
|
|
16
|
+
import { StatementSpecializer } from "./statements";
|
|
17
|
+
import { Storage } from "./storage";
|
|
18
18
|
import {
|
|
19
19
|
constant,
|
|
20
20
|
type Env,
|
|
21
21
|
type FunctionLike,
|
|
22
22
|
SpecializeError,
|
|
23
23
|
type Value,
|
|
24
|
-
} from "./values
|
|
24
|
+
} from "./values";
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Evaluates the program's scan code against the setup graph. Everything setup decided (which
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
// biome-ignore-all lint/style/noNonNullAssertion: Retain existing non-null assertions during the tooling migration; changing their contracts requires a separate review.
|
|
2
2
|
import ts from "typescript";
|
|
3
|
-
import { copied, type Mapped, mapped, type Part } from "../positions
|
|
4
|
-
import type { DialectText } from "./dialect
|
|
5
|
-
import type {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from "./
|
|
9
|
-
import type
|
|
10
|
-
import
|
|
11
|
-
import type { Layouts } from "./layouts.ts";
|
|
12
|
-
import { SpecializeError, type Value } from "./values.ts";
|
|
13
|
-
import { isAssignment, isUpdate } from "./writes.ts";
|
|
3
|
+
import { copied, type Mapped, mapped, type Part } from "../positions";
|
|
4
|
+
import type { DialectText } from "./dialect";
|
|
5
|
+
import type { ExpressionSpecializer, SpecializeContext } from "./expressions";
|
|
6
|
+
import type { Frame } from "./frame";
|
|
7
|
+
import type { Initializers } from "./initializers";
|
|
8
|
+
import type { Layouts } from "./layouts";
|
|
9
|
+
import { SpecializeError, type Value } from "./values";
|
|
10
|
+
import { isAssignment, isUpdate } from "./writes";
|
|
14
11
|
|
|
15
12
|
/** Specializes one routine's statements; expressions in them go through its ExpressionSpecializer. */
|
|
16
13
|
export class StatementSpecializer {
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
// biome-ignore-all lint/style/noNonNullAssertion: Retain existing non-null assertions during the tooling migration; changing their contracts requires a separate review.
|
|
2
2
|
import ts from "typescript";
|
|
3
|
-
import type { CapturedPrimitive, CapturedValue } from "./capture-protocol
|
|
4
|
-
import type { EntryImports } from "./imports
|
|
5
|
-
import {
|
|
6
|
-
type Layouts,
|
|
7
|
-
pascalCase,
|
|
8
|
-
recordTypes,
|
|
9
|
-
unusedName,
|
|
10
|
-
} from "./layouts.ts";
|
|
3
|
+
import type { CapturedPrimitive, CapturedValue } from "./capture-protocol";
|
|
4
|
+
import type { EntryImports } from "./imports";
|
|
5
|
+
import { type Layouts, pascalCase, recordTypes, unusedName } from "./layouts";
|
|
11
6
|
import {
|
|
12
7
|
children,
|
|
13
8
|
type Model,
|
|
@@ -16,9 +11,9 @@ import {
|
|
|
16
11
|
type Root,
|
|
17
12
|
type Step,
|
|
18
13
|
tsPath,
|
|
19
|
-
} from "./model
|
|
20
|
-
import { constant, type Value } from "./values
|
|
21
|
-
import { ScanWrites } from "./writes
|
|
14
|
+
} from "./model";
|
|
15
|
+
import { constant, type Value } from "./values";
|
|
16
|
+
import { ScanWrites } from "./writes";
|
|
22
17
|
|
|
23
18
|
/** A primitive scan code read from setup and folded, at its TypeScript path. */
|
|
24
19
|
interface FoldedField {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type ts from "typescript";
|
|
2
|
-
import type { Mapped } from "../positions
|
|
3
|
-
import type { ModelNode } from "./model
|
|
2
|
+
import type { Mapped } from "../positions";
|
|
3
|
+
import type { ModelNode } from "./model";
|
|
4
4
|
|
|
5
5
|
export type FunctionLike =
|
|
6
6
|
| ts.FunctionDeclaration
|
package/src/frontend/exposure.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import { type Diagnostic, error } from "@tsplc/compiler/ir";
|
|
3
3
|
import { elementaryType, isIntegerValued } from "@tsplc/iec";
|
|
4
4
|
import ts from "typescript";
|
|
5
|
-
import { runtimeSources } from "./module-graph
|
|
5
|
+
import { runtimeSources } from "./module-graph";
|
|
6
6
|
import {
|
|
7
7
|
copied,
|
|
8
8
|
type Edit,
|
|
@@ -12,8 +12,8 @@ import {
|
|
|
12
12
|
type Mapped,
|
|
13
13
|
mapped,
|
|
14
14
|
type Positions,
|
|
15
|
-
} from "./positions
|
|
16
|
-
import { namesSdk, symbolAt } from "./sdk
|
|
15
|
+
} from "./positions";
|
|
16
|
+
import { namesSdk, symbolAt } from "./sdk";
|
|
17
17
|
|
|
18
18
|
/** Telemetry carries a BOOL, an integer or bit string of up to 32 bits, or a bounded STRING. */
|
|
19
19
|
const telemetryType = (annotation: string): boolean => {
|