@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.
Files changed (115) hide show
  1. package/README.md +1 -1
  2. package/dist/cli.js +280 -223
  3. package/dist/cli.js.map +12 -12
  4. package/dist/codesys.js +452 -330
  5. package/dist/codesys.js.map +24 -24
  6. package/dist/elaborate-capture.js +112 -7
  7. package/dist/elaborate-capture.js.map +5 -4
  8. package/dist/index.js +5682 -5407
  9. package/dist/index.js.map +39 -37
  10. package/dist/ir.js +1154 -327
  11. package/dist/ir.js.map +23 -20
  12. package/dist/project.js +68 -29
  13. package/dist/project.js.map +4 -4
  14. package/dist/retain.js +8 -0
  15. package/dist/retain.js.map +10 -0
  16. package/dist/server-check.js +59 -0
  17. package/dist/server-check.js.map +11 -0
  18. package/dist/telemetry.js +19 -10
  19. package/dist/telemetry.js.map +3 -3
  20. package/package.json +33 -12
  21. package/src/codesys/config.ts +1 -1
  22. package/src/codesys/debug.ts +7 -21
  23. package/src/codesys/engineering.ts +8 -12
  24. package/src/codesys/global-lists.ts +19 -17
  25. package/src/codesys/global-names.ts +3 -3
  26. package/src/codesys/http.ts +37 -34
  27. package/src/codesys/index.ts +5 -22
  28. package/src/codesys/instrumentation.ts +3 -1
  29. package/src/codesys/io-paths.ts +2 -1
  30. package/src/codesys/manifest.ts +35 -18
  31. package/src/codesys/numeric.ts +2 -4
  32. package/src/codesys/plan.ts +94 -26
  33. package/src/codesys/publication.ts +4 -3
  34. package/src/codesys/routines.ts +2 -2
  35. package/src/codesys/sources.ts +1 -0
  36. package/src/codesys/st-files.ts +86 -50
  37. package/src/codesys/storage.ts +44 -9
  38. package/src/codesys/task-access.ts +32 -10
  39. package/src/codesys/telemetry.ts +93 -46
  40. package/src/codesys/types.ts +81 -3
  41. package/src/codesys/vendor.ts +1 -1
  42. package/src/frontend/analyzer.ts +15 -14
  43. package/src/frontend/async.ts +23 -21
  44. package/src/frontend/blocks.ts +7 -6
  45. package/src/frontend/configuration.ts +8 -6
  46. package/src/frontend/const-functions.ts +5 -5
  47. package/src/frontend/cooperative.ts +2 -1
  48. package/src/frontend/coroutines.ts +24 -21
  49. package/src/frontend/elaborate/calls.ts +12 -7
  50. package/src/frontend/elaborate/capture-protocol.ts +103 -0
  51. package/src/frontend/elaborate/capture.ts +48 -19
  52. package/src/frontend/elaborate/dialect.ts +2 -2
  53. package/src/frontend/elaborate/expressions.ts +9 -6
  54. package/src/frontend/elaborate/frame.ts +1 -1
  55. package/src/frontend/elaborate/graph.ts +27 -43
  56. package/src/frontend/elaborate/index.ts +52 -17
  57. package/src/frontend/elaborate/initializers.ts +3 -2
  58. package/src/frontend/elaborate/layouts.ts +2 -2
  59. package/src/frontend/elaborate/model.ts +34 -21
  60. package/src/frontend/elaborate/retention.ts +206 -0
  61. package/src/frontend/elaborate/specialize.ts +7 -6
  62. package/src/frontend/elaborate/statements.ts +47 -38
  63. package/src/frontend/elaborate/storage.ts +26 -6
  64. package/src/frontend/exposure.ts +6 -6
  65. package/src/frontend/expressions.ts +26 -25
  66. package/src/frontend/intrinsics.ts +3 -3
  67. package/src/frontend/module-graph.ts +1 -1
  68. package/src/frontend/positions.ts +2 -1
  69. package/src/frontend/promise-chains.ts +1 -0
  70. package/src/frontend/promises.ts +8 -7
  71. package/src/frontend/routines.ts +3 -2
  72. package/src/frontend/sdk.ts +2 -2
  73. package/src/frontend/services.ts +23 -20
  74. package/src/frontend/statements.ts +8 -6
  75. package/src/frontend/tasks.ts +11 -6
  76. package/src/frontend/telemetry.ts +1 -1
  77. package/src/frontend/types.ts +11 -9
  78. package/src/frontend/typescript.ts +92 -42
  79. package/src/index.ts +2 -1
  80. package/src/ir/aggregates.ts +4 -3
  81. package/src/ir/allocation.ts +2 -1
  82. package/src/ir/core-model.ts +38 -8
  83. package/src/ir/declarations.ts +12 -12
  84. package/src/ir/domains.ts +8 -8
  85. package/src/ir/fold.ts +2 -2
  86. package/src/ir/index.ts +53 -40
  87. package/src/ir/job-errors.ts +22 -11
  88. package/src/ir/layouts.ts +3 -2
  89. package/src/ir/link.ts +6 -24
  90. package/src/ir/model.ts +3 -2
  91. package/src/ir/normalization-error.ts +1 -1
  92. package/src/ir/normalize.ts +19 -12
  93. package/src/ir/numeric.ts +1 -0
  94. package/src/{codesys → ir}/operands.ts +2 -6
  95. package/src/ir/ranges.ts +2 -2
  96. package/src/ir/routine.ts +35 -20
  97. package/src/ir/scalars.ts +3 -3
  98. package/src/ir/share.ts +862 -0
  99. package/src/ir/temporaries.ts +236 -0
  100. package/src/ir/types.ts +1 -1
  101. package/src/project/artifacts.ts +12 -2
  102. package/src/project/cli.ts +42 -44
  103. package/src/project/debugger.ts +15 -9
  104. package/src/project/index.ts +1 -1
  105. package/src/project/plant.ts +34 -23
  106. package/src/project/project-commands.ts +92 -73
  107. package/src/project/project.ts +91 -42
  108. package/src/project/release.ts +50 -57
  109. package/src/project/server-check.ts +54 -0
  110. package/src/project/server.ts +60 -41
  111. package/src/project/terminal.ts +3 -1
  112. package/stdlib/retain.ts +2 -0
  113. package/types/globals.d.ts +1 -0
  114. package/types/retain.d.ts +6 -0
  115. package/types/telemetry.d.ts +2 -2
@@ -1,10 +1,11 @@
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 ts from "typescript";
2
- import { copied, mapped, type Mapped, type Part } from "../positions.ts";
3
+ import { copied, type Mapped, mapped, type Part } from "../positions.ts";
4
+ import type { DialectText } from "./dialect.ts";
3
5
  import type {
4
6
  ExpressionSpecializer,
5
7
  SpecializeContext,
6
8
  } from "./expressions.ts";
7
- import type { DialectText } from "./dialect.ts";
8
9
  import type { Frame } from "./frame.ts";
9
10
  import type { Initializers } from "./initializers.ts";
10
11
  import type { Layouts } from "./layouts.ts";
@@ -30,9 +31,7 @@ export class StatementSpecializer {
30
31
 
31
32
  body(node: ts.ConciseBody, frame: Frame): void {
32
33
  if (ts.isBlock(node)) {
33
- for (const statement of node.statements) {
34
- this.statement(statement, frame);
35
- }
34
+ this.statements(node.statements, frame);
36
35
  } else {
37
36
  frame.emitter.origin = node;
38
37
  frame.emitter.line(
@@ -41,53 +40,65 @@ export class StatementSpecializer {
41
40
  }
42
41
  }
43
42
 
44
- private statement(node: ts.Statement, frame: Frame): void {
43
+ /** Statements after one that always returns are unreachable, and may read what setup left undefined on that path. */
44
+ private statements(
45
+ nodes: ReadonlyArray<ts.Statement>,
46
+ frame: Frame,
47
+ ): boolean {
48
+ for (const statement of nodes) {
49
+ if (this.statement(statement, frame)) {
50
+ return true;
51
+ }
52
+ }
53
+ return false;
54
+ }
55
+
56
+ /** True when control never continues past the statement: it returns on every path. */
57
+ private statement(node: ts.Statement, frame: Frame): boolean {
45
58
  const enclosing = frame.emitter.origin;
46
59
  frame.emitter.origin = node;
47
- this.specializeStatement(node, frame);
60
+ const returns = this.specializeStatement(node, frame);
48
61
  frame.emitter.origin = enclosing;
62
+ return returns;
49
63
  }
50
64
 
51
- private specializeStatement(node: ts.Statement, frame: Frame): void {
65
+ private specializeStatement(node: ts.Statement, frame: Frame): boolean {
52
66
  const { emitter } = frame;
53
67
  if (ts.isBlock(node)) {
54
68
  emitter.open("{");
55
- for (const statement of node.statements) {
56
- this.statement(statement, frame);
57
- }
69
+ const returns = this.statements(node.statements, frame);
58
70
  emitter.close();
59
- return;
71
+ return returns;
60
72
  }
61
73
  if (ts.isVariableStatement(node)) {
62
74
  const mutable = !(node.declarationList.flags & ts.NodeFlags.Const);
63
75
  for (const declaration of node.declarationList.declarations) {
64
76
  this.declare(declaration, mutable, frame);
65
77
  }
66
- return;
78
+ return false;
67
79
  }
68
80
  if (ts.isExpressionStatement(node)) {
69
81
  this.effect(node.expression, frame);
70
- return;
82
+ return false;
71
83
  }
72
84
  if (ts.isIfStatement(node)) {
73
- this.ifStatement(node, frame);
74
- return;
85
+ return this.ifStatement(node, frame);
75
86
  }
76
87
  if (ts.isReturnStatement(node)) {
77
88
  this.returnStatement(node, frame);
78
- return;
89
+ return true;
79
90
  }
80
91
  if (ts.isForOfStatement(node)) {
81
92
  this.forOf(node, frame);
82
- return;
93
+ return false;
83
94
  }
84
95
  if (ts.isSwitchStatement(node)) {
85
96
  this.switch(node, frame);
86
- return;
97
+ return false;
87
98
  }
88
99
  if (ts.isForStatement(node)) {
89
100
  this.forLoop(node, frame);
90
- return;
101
+ return false;
91
102
  }
92
103
  if (ts.isWhileStatement(node)) {
93
104
  throw new SpecializeError(
@@ -97,14 +108,14 @@ export class StatementSpecializer {
97
108
  }
98
109
  if (ts.isTryStatement(node)) {
99
110
  this.tryStatement(node, frame);
100
- return;
111
+ return false;
101
112
  }
102
113
  if (ts.isBreakStatement(node) || ts.isContinueStatement(node)) {
103
114
  emitter.line(copied(node));
104
- return;
115
+ return false;
105
116
  }
106
117
  if (ts.isEmptyStatement(node)) {
107
- return;
118
+ return false;
108
119
  }
109
120
  throw new SpecializeError(
110
121
  node,
@@ -113,7 +124,7 @@ export class StatementSpecializer {
113
124
  }
114
125
 
115
126
  /** An if on a value setup fixed keeps only the branch it takes. */
116
- private ifStatement(node: ts.IfStatement, frame: Frame): void {
127
+ private ifStatement(node: ts.IfStatement, frame: Frame): boolean {
117
128
  const condition = this.expressions.expression(node.expression, frame);
118
129
  if (
119
130
  condition.kind === "const" ||
@@ -123,21 +134,23 @@ export class StatementSpecializer {
123
134
  const truthy =
124
135
  condition.kind === "const" ? Boolean(condition.value) : true;
125
136
  if (truthy) {
126
- this.statement(node.thenStatement, frame);
127
- } else if (node.elseStatement) {
128
- this.statement(node.elseStatement, frame);
137
+ return this.statement(node.thenStatement, frame);
129
138
  }
130
- return;
139
+ return node.elseStatement !== undefined
140
+ ? this.statement(node.elseStatement, frame)
141
+ : false;
131
142
  }
132
143
  frame.emitter.open(
133
144
  mapped`if (${this.dialect.condition(condition, node.expression)}) {`,
134
145
  );
135
- this.inner(node.thenStatement, frame);
146
+ const thenReturns = this.inner(node.thenStatement, frame);
147
+ let elseReturns = false;
136
148
  if (node.elseStatement) {
137
149
  frame.emitter.reopen("} else {");
138
- this.inner(node.elseStatement, frame);
150
+ elseReturns = this.inner(node.elseStatement, frame);
139
151
  }
140
152
  frame.emitter.close();
153
+ return thenReturns && elseReturns;
141
154
  }
142
155
 
143
156
  /** `return x satisfies never` marks an unreachable end, which returns the result type's default. */
@@ -193,14 +206,10 @@ export class StatementSpecializer {
193
206
  }
194
207
 
195
208
  /** A branch body: blocks keep their statements without another brace level. */
196
- private inner(node: ts.Statement, frame: Frame): void {
197
- if (ts.isBlock(node)) {
198
- for (const statement of node.statements) {
199
- this.statement(statement, frame);
200
- }
201
- } else {
202
- this.statement(node, frame);
203
- }
209
+ private inner(node: ts.Statement, frame: Frame): boolean {
210
+ return ts.isBlock(node)
211
+ ? this.statements(node.statements, frame)
212
+ : this.statement(node, frame);
204
213
  }
205
214
 
206
215
  private isNever(type: ts.TypeNode): boolean {
@@ -1,20 +1,21 @@
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 ts from "typescript";
2
- import type { CapturedPrimitive, CapturedValue } from "./graph.ts";
3
+ import type { CapturedPrimitive, CapturedValue } from "./capture-protocol.ts";
3
4
  import type { EntryImports } from "./imports.ts";
4
5
  import {
6
+ type Layouts,
5
7
  pascalCase,
6
8
  recordTypes,
7
9
  unusedName,
8
- type Layouts,
9
10
  } from "./layouts.ts";
10
11
  import {
11
12
  children,
12
- tsPath,
13
13
  type Model,
14
14
  type ModelNode,
15
15
  type Owner,
16
16
  type Root,
17
17
  type Step,
18
+ tsPath,
18
19
  } from "./model.ts";
19
20
  import { constant, type Value } from "./values.ts";
20
21
  import { ScanWrites } from "./writes.ts";
@@ -168,7 +169,7 @@ export class Storage {
168
169
  }
169
170
 
170
171
  /** Whether anything inside a node is state the PLC stores. */
171
- private hasState(node: ModelNode): boolean {
172
+ hasState(node: ModelNode): boolean {
172
173
  const captured = node.captured;
173
174
  if (node.owner?.root.exported) {
174
175
  return true;
@@ -348,7 +349,11 @@ export class Storage {
348
349
  step.kind === "field" &&
349
350
  this.written(holder, step.name)
350
351
  ) {
351
- return this.storedField(holder, step);
352
+ return this.storedField(
353
+ holder,
354
+ step,
355
+ node.captured.kind === "array" ? value : undefined,
356
+ );
352
357
  }
353
358
  return { kind: "static", node };
354
359
  }
@@ -468,7 +473,12 @@ export class Storage {
468
473
  return found;
469
474
  }
470
475
 
471
- private storedField(holder: ModelNode, step: Step): Value {
476
+ /** `array` is the array setup put in the field, whose length an array parameter takes when the field is passed to one. */
477
+ private storedField(
478
+ holder: ModelNode,
479
+ step: Step,
480
+ array?: CapturedValue,
481
+ ): Value {
472
482
  const declared =
473
483
  step.kind === "index"
474
484
  ? holder.type && this.model.elementType(holder.type)
@@ -493,6 +503,16 @@ export class Storage {
493
503
  ...(global && {
494
504
  setter: `${this.pathText(holder)}.${setterName(step.name)}`,
495
505
  }),
506
+ ...(array &&
507
+ declared &&
508
+ this.checker.isArrayType(declared) &&
509
+ step.kind === "field" && {
510
+ layout: this.layouts.declaredText(
511
+ this.fieldDeclaration(holder, step.name),
512
+ declared,
513
+ array,
514
+ ),
515
+ }),
496
516
  };
497
517
  }
498
518
 
@@ -1,19 +1,19 @@
1
- import { runtimeSources } from "./module-graph.ts";
2
- import { namesSdk, symbolAt } from "./sdk.ts";
3
- import ts from "typescript";
4
1
  import { createHash } from "node:crypto";
2
+ import { type Diagnostic, error } from "@tsplc/compiler/ir";
5
3
  import { elementaryType, isIntegerValued } from "@tsplc/iec";
6
- import { error, type Diagnostic } from "@tsplc/compiler/ir";
4
+ import ts from "typescript";
5
+ import { runtimeSources } from "./module-graph.ts";
7
6
  import {
8
7
  copied,
8
+ type Edit,
9
9
  edited,
10
10
  from,
11
11
  joined,
12
- mapped,
13
- type Edit,
14
12
  type Mapped,
13
+ mapped,
15
14
  type Positions,
16
15
  } from "./positions.ts";
16
+ import { namesSdk, symbolAt } from "./sdk.ts";
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 => {
@@ -1,45 +1,46 @@
1
- import ts from "typescript";
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 {
3
- instancedBlock,
4
- error,
5
- parseInteger,
6
- roundFloat,
7
- fold,
8
- canAssign,
9
3
  aggregate,
10
- expressionIssue,
11
- defaultValue,
12
- placeType,
13
- narrowRanges,
14
- interval,
15
- valueRange,
16
- comparisonOperators,
17
4
  type BinaryOperator,
18
- type IntegerInterval,
19
5
  type Constant,
6
+ canAssign,
7
+ comparisonOperators,
8
+ defaultValue,
20
9
  type Expression,
10
+ error,
11
+ expressionIssue,
12
+ fold,
13
+ type IntegerInterval,
14
+ instancedBlock,
15
+ interval,
16
+ narrowRanges,
17
+ type Place,
21
18
  type PlcFunction,
22
19
  type PlcType,
20
+ parseInteger,
21
+ placeType,
22
+ roundFloat,
23
23
  type SourceSpan,
24
24
  type Statement,
25
25
  type Variable,
26
- type Place,
26
+ valueRange,
27
27
  } from "@tsplc/compiler/ir";
28
- import type { Positions } from "./positions.ts";
29
- import { intrinsicExpression } from "./intrinsics.ts";
28
+ import ts from "typescript";
30
29
  import type { BlockResolver, BlockSource } from "./blocks.ts";
30
+ import { intrinsicExpression } from "./intrinsics.ts";
31
+ import type { Positions } from "./positions.ts";
31
32
  import type { RoutineTable } from "./routines.ts";
32
33
  import {
33
- SemanticError,
34
- numericLiteral,
35
34
  calleeName,
35
+ type Fail,
36
36
  namedProperty,
37
+ numericLiteral,
37
38
  numericLiteralType,
38
- unparenthesized,
39
- type Fail,
39
+ type ResolvedType,
40
+ SemanticError,
40
41
  type TypeEnvironment,
41
42
  type TypeResolver,
42
- type ResolvedType,
43
+ unparenthesized,
43
44
  } from "./types.ts";
44
45
 
45
46
  type UnaryOperator = Extract<Expression, { kind: "unary" }>["operator"];
@@ -1230,8 +1231,8 @@ export class ExpressionLowering {
1230
1231
  this.loopCounters.has(value.place.root) ||
1231
1232
  Boolean(
1232
1233
  root &&
1233
- !root.mutable &&
1234
- ["parameter", "local", "constant"].includes(root.storage),
1234
+ !root.mutable &&
1235
+ ["parameter", "local", "constant"].includes(root.storage),
1235
1236
  )
1236
1237
  );
1237
1238
  }
@@ -1,12 +1,12 @@
1
- import ts from "typescript";
2
1
  import {
2
+ type Constant,
3
3
  calendarLiteral,
4
4
  defaultValue,
5
5
  durationLiteral,
6
- parseInteger,
7
- type Constant,
8
6
  type Expression,
7
+ parseInteger,
9
8
  } from "@tsplc/compiler/ir";
9
+ import ts from "typescript";
10
10
  import type { ExpressionLowering } from "./expressions.ts";
11
11
  import { numericLiteral } from "./types.ts";
12
12
 
@@ -1,5 +1,5 @@
1
- import ts from "typescript";
2
1
  import { dirname, relative } from "node:path";
2
+ import ts from "typescript";
3
3
  import { symbolAt } from "./sdk.ts";
4
4
 
5
5
  /** The quoted specifier an import generated into `importer` uses to reach `target`. */
@@ -1,5 +1,6 @@
1
- import ts from "typescript";
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 type { SourceSpan } from "@tsplc/compiler/ir";
3
+ import type ts from "typescript";
3
4
 
4
5
  /**
5
6
  * Where a run of lowered text, `start`..`end`, came from. Copied text maps offset for offset
@@ -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 ts from "typescript";
2
3
  import type { PromiseContext, Routine } from "./promises.ts";
3
4
  import { hasModifier } from "./types.ts";
@@ -1,18 +1,19 @@
1
- import { importSpecifier, runtimeSources } from "./module-graph.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 { type Diagnostic, error } from "@tsplc/compiler/ir";
2
3
  import ts from "typescript";
3
- import { namesSdk, symbolAt } from "./sdk.ts";
4
- import { error, type Diagnostic } from "@tsplc/compiler/ir";
5
- import { chainOf, lowerChain } from "./promise-chains.ts";
6
- import { SemanticError, hasModifier } from "./types.ts";
4
+ import { importSpecifier, runtimeSources } from "./module-graph.ts";
7
5
  import {
6
+ type Edit,
8
7
  edited,
9
8
  from,
10
9
  joined,
11
- mapped,
12
- type Edit,
13
10
  type Mapped,
11
+ mapped,
14
12
  type Positions,
15
13
  } from "./positions.ts";
14
+ import { chainOf, lowerChain } from "./promise-chains.ts";
15
+ import { namesSdk, symbolAt } from "./sdk.ts";
16
+ import { hasModifier, SemanticError } from "./types.ts";
16
17
 
17
18
  export type Routine = ts.FunctionDeclaration | ts.MethodDeclaration;
18
19
 
@@ -1,13 +1,14 @@
1
- import ts from "typescript";
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 {
3
3
  aggregate,
4
4
  type MethodOwner,
5
5
  type PlcFunction,
6
6
  } from "@tsplc/compiler/ir";
7
+ import ts from "typescript";
7
8
  import type { Positions } from "./positions.ts";
8
9
  import {
9
- hasModifier,
10
10
  type Fail,
11
+ hasModifier,
11
12
  type TypeEnvironment,
12
13
  type TypeResolver,
13
14
  } from "./types.ts";
@@ -1,7 +1,7 @@
1
- import ts from "typescript";
2
- import { createRequire } from "node:module";
3
1
  import { realpathSync } from "node:fs";
2
+ import { createRequire } from "node:module";
4
3
  import { dirname } from "node:path";
4
+ import ts from "typescript";
5
5
 
6
6
  /** The `@tsplc/compiler/globals` declaration file a project compiles against. */
7
7
  export const sdkFor = (
@@ -1,26 +1,27 @@
1
- import { runtimeSources } from "./module-graph.ts";
2
- import { namesSdk, symbolAt } from "./sdk.ts";
3
- import ts from "typescript";
1
+ // biome-ignore-all lint/style/noNonNullAssertion: Retain existing non-null assertions during the tooling migration; changing their contracts requires a separate review.
4
2
  import { dirname, join, relative } from "node:path";
5
- import { error, type Diagnostic } from "@tsplc/compiler/ir";
6
- import {
7
- edited,
8
- from,
9
- mapped,
10
- type Edit,
11
- type Mapped,
12
- type Positions,
13
- } from "./positions.ts";
3
+ import { type Diagnostic, error } from "@tsplc/compiler/ir";
14
4
  import {
15
5
  isIntegerType,
6
+ type ServiceContract,
16
7
  serviceContract,
17
8
  servicePath,
18
- wireLayout,
19
- wireRecord,
20
- type ServiceContract,
21
9
  type WireField,
22
10
  type WireScalar,
11
+ wireLayout,
12
+ wireRecord,
23
13
  } from "@tsplc/server";
14
+ import ts from "typescript";
15
+ import { runtimeSources } from "./module-graph.ts";
16
+ import {
17
+ type Edit,
18
+ edited,
19
+ from,
20
+ type Mapped,
21
+ mapped,
22
+ type Positions,
23
+ } from "./positions.ts";
24
+ import { namesSdk, symbolAt } from "./sdk.ts";
24
25
 
25
26
  /** The server section's transport; each client's type argument names its router. */
26
27
  export interface ServiceOptions {
@@ -523,11 +524,13 @@ const serviceModule = (
523
524
  options.transport === "http"
524
525
  ? `const tsplcServiceBaseUrl:STRING<512>=tsplcServiceEnv<STRING<512>>(${JSON.stringify(options.baseUrlEnv)});`
525
526
  : "";
526
- return (
527
- [transport, ...enumImports, baseUrl, ...interfaces, ...functions].join(
528
- "\n",
529
- ) + "\n"
530
- );
527
+ return `${[
528
+ transport,
529
+ ...enumImports,
530
+ baseUrl,
531
+ ...interfaces,
532
+ ...functions,
533
+ ].join("\n")}\n`;
531
534
  };
532
535
 
533
536
  /** Lowers a type that names a called procedure's record, such as `inferRouterOutputs<AppRouter>["a"]["b"]`. */
@@ -1,22 +1,23 @@
1
- import ts from "typescript";
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 {
3
3
  aggregate,
4
+ type Constant,
5
+ type Expression,
6
+ type IntegerInterval,
4
7
  integerRange,
5
8
  loopBounds,
6
9
  loopIterations,
7
10
  maxLoopIterations,
8
- type Constant,
9
- type Expression,
10
- type IntegerInterval,
11
11
  type PlcFunction,
12
12
  type PlcType,
13
13
  type Statement,
14
14
  type Variable,
15
15
  } from "@tsplc/compiler/ir";
16
- import type { Positions } from "./positions.ts";
16
+ import ts from "typescript";
17
17
  import type { AnalysisContext, ExpressionLowering } from "./expressions.ts";
18
+ import type { Positions } from "./positions.ts";
18
19
  import { telemetryStatement } from "./telemetry.ts";
19
- import { numericLiteral, type Fail, type TypeResolver } from "./types.ts";
20
+ import { type Fail, numericLiteral, type TypeResolver } from "./types.ts";
20
21
 
21
22
  type IterationForm = "elements" | "entries" | "recordValues" | "recordEntries";
22
23
 
@@ -83,6 +84,7 @@ export class StatementLowering {
83
84
  ...origin,
84
85
  kind: "if",
85
86
  condition,
87
+ // biome-ignore lint/suspicious/noThenProperty: This is the IR branch field, not a Promise method.
86
88
  then: branch(node.thenStatement, true),
87
89
  else: branch(node.elseStatement, false),
88
90
  },
@@ -1,16 +1,21 @@
1
- import ts from "typescript";
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 { resolve } from "node:path";
3
- import { durationLiteral, nanosecondsPerMillisecond } from "@tsplc/compiler/ir";
3
+ import {
4
+ durationLiteral,
5
+ jobError,
6
+ nanosecondsPerMillisecond,
7
+ } from "@tsplc/compiler/ir";
8
+ import ts from "typescript";
9
+ import type { AsyncContext, Routine, SourceRewrite } from "./async.ts";
4
10
  import {
5
11
  cooperativeSite,
6
12
  copyValue,
7
- taskSite,
8
13
  type Site,
14
+ taskSite,
9
15
  } from "./cooperative.ts";
10
16
  import { aliasPrefix } from "./coroutines.ts";
11
17
  import { importSpecifier } from "./module-graph.ts";
12
18
  import { from } from "./positions.ts";
13
- import type { AsyncContext, Routine, SourceRewrite } from "./async.ts";
14
19
 
15
20
  /** A `<tasks>.define(...)` initializer, the declaration holding it, and that declaration's block. */
16
21
  interface TaskDefinition {
@@ -289,9 +294,9 @@ private pending:BOOL=false;private active:BOOL=false;private completed:BOOL=fals
289
294
  ${params.map((p) => `private ${p.field}:${p.type}=defaultValue<${p.type}>();`).join("\n")}
290
295
  start(${params.map((p) => `${p.name}:${p.type}`).join(",")}):BOOL {if(this.pending || this.active || this.completed)return false;${params.map((p) => `this.${p.field}=${copyValue(p.name, p.aggregate)};`).join("")}this.pending=true;return true;}
291
296
  take():${requestType} {const ready:BOOL=this.pending; if(ready){this.pending=false;this.active=true;}return {ready,${params.map((p) => `${p.field}:${copyValue(`this.${p.field}`, p.aggregate)}`).join(",")}};}
292
- publish(value:${valueType},error:UDINT):BOOL {if(!this.active)return false;if(this.cancelRequested){this.value=defaultValue<${valueType}>();this.failure=1;}else{this.value=${copyValue("value", valueAggregate)};this.failure=error;}this.active=false;this.completed=true;this.cancelRequested=false;return true;}
297
+ publish(value:${valueType},error:UDINT):BOOL {if(!this.active)return false;if(this.cancelRequested){this.value=defaultValue<${valueType}>();this.failure=${jobError.cancelled};}else{this.value=${copyValue("value", valueAggregate)};this.failure=error;}this.active=false;this.completed=true;this.cancelRequested=false;return true;}
293
298
  snapshot():${snapshotType} {return ${emptySnapshot};}
294
- cancel():BOOL {if(this.pending){this.pending=false;this.completed=true;this.failure=1;return true;}if(this.active){this.cancelRequested=true;return true;}return false;}
299
+ cancel():BOOL {if(this.pending){this.pending=false;this.completed=true;this.failure=${jobError.cancelled};return true;}if(this.active){this.cancelRequested=true;return true;}return false;}
295
300
  reset():BOOL {if(this.pending || this.active)return false;this.completed=false;this.failure=0;this.cancelRequested=false;this.value=defaultValue<${valueType}>();return true;}
296
301
  protected execute(input:{}):void {}
297
302
  }
@@ -1,5 +1,5 @@
1
- import ts from "typescript";
2
1
  import type { Statement } from "@tsplc/compiler/ir";
2
+ import ts from "typescript";
3
3
  import type { ExpressionLowering } from "./expressions.ts";
4
4
  import { namedProperty, type TelemetryMethod } from "./types.ts";
5
5
 
@@ -1,18 +1,19 @@
1
- import ts from "typescript";
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 { dirname, relative, resolve } from "node:path";
3
- import { elementaryType, integerRange } from "@tsplc/iec";
4
- import { declaredBySdk, unaliased } from "./sdk.ts";
5
3
  import {
4
+ type Diagnostic,
5
+ type Field,
6
6
  instancedBlock,
7
+ type MathHelper,
7
8
  maxNestingDepth,
8
9
  maxScalarElements,
9
- type Diagnostic,
10
- primitiveTypes,
11
- parseInteger,
12
10
  type PlcType,
13
- type Field,
14
- type MathHelper,
11
+ parseInteger,
12
+ primitiveTypes,
15
13
  } from "@tsplc/compiler/ir";
14
+ import { elementaryType, integerRange } from "@tsplc/iec";
15
+ import ts from "typescript";
16
+ import { declaredBySdk, unaliased } from "./sdk.ts";
16
17
 
17
18
  export interface ResolvedType {
18
19
  type: string;
@@ -20,7 +21,8 @@ export interface ResolvedType {
20
21
  mode?: "inOut";
21
22
  }
22
23
  export type TypeArgument =
23
- { kind: "type"; value: ResolvedType } | { kind: "integer"; value: number };
24
+ | { kind: "type"; value: ResolvedType }
25
+ | { kind: "integer"; value: number };
24
26
  export type TypeEnvironment = ReadonlyMap<ts.Symbol, TypeArgument>;
25
27
  export type Fail = (node: ts.Node, code: string, message: string) => never;
26
28