@tsplc/compiler 0.2.13 → 0.2.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/backends/codesys/debug.ts +509 -0
- package/backends/codesys/emit.ts +701 -9
- package/backends/codesys/http.ts +110 -34
- package/backends/codesys/index.ts +2 -1
- package/backends/codesys/io-paths.ts +3 -1
- package/backends/codesys/manifest.ts +312 -0
- package/backends/codesys/plan.ts +39 -9
- package/backends/codesys/publication.ts +2 -2
- package/backends/codesys/storage.ts +10 -3
- package/backends/codesys/task-access.ts +51 -1
- package/backends/codesys/telemetry.ts +593 -0
- package/backends/codesys/types.ts +2 -1
- package/dist/cli.js +205 -36
- package/dist/cli.js.map +6 -6
- package/dist/codesys.js +2148 -432
- package/dist/codesys.js.map +14 -11
- package/dist/elaborate-capture.js +7 -1
- package/dist/elaborate-capture.js.map +3 -3
- package/dist/index.js +877 -459
- package/dist/index.js.map +16 -15
- package/dist/ir.js +87 -23
- package/dist/ir.js.map +10 -9
- package/dist/project.js +42 -9
- package/dist/project.js.map +3 -3
- package/dist/telemetry.js +83 -0
- package/dist/telemetry.js.map +12 -0
- package/ir/core-model.ts +13 -0
- package/ir/core.ts +1 -0
- package/ir/errors.ts +20 -0
- package/ir/index.ts +1 -0
- package/ir/link.ts +17 -8
- package/ir/model.ts +39 -0
- package/ir/routine.ts +62 -29
- package/ir/types.ts +7 -1
- package/package.json +12 -6
- package/project/cli.ts +96 -6
- package/project/plant.ts +74 -15
- package/project/project.ts +56 -10
- package/src/frontend/async.ts +284 -195
- package/src/frontend/configuration.ts +7 -21
- package/src/frontend/const-functions.ts +44 -38
- package/src/frontend/elaborate/capture.ts +7 -0
- package/src/frontend/elaborate/index.ts +135 -61
- package/src/frontend/elaborate/layouts.ts +8 -0
- package/src/frontend/elaborate/model.ts +13 -0
- package/src/frontend/elaborate/specialize.ts +302 -111
- package/src/frontend/exposure.ts +28 -26
- package/src/frontend/positions.ts +272 -0
- package/src/frontend/promises.ts +52 -47
- package/src/frontend/services.ts +16 -26
- package/src/frontend/types.ts +14 -0
- package/src/frontend/typescript.ts +185 -65
- package/stdlib/telemetry.ts +72 -0
- package/types/telemetry.d.ts +44 -0
package/dist/ir.js
CHANGED
|
@@ -66,6 +66,10 @@ var comparisonOperators = new Set([
|
|
|
66
66
|
"greater",
|
|
67
67
|
"greaterEqual"
|
|
68
68
|
]);
|
|
69
|
+
var telemetryOperands = ({ record, properties }) => [
|
|
70
|
+
...record.kind === "exception" ? [record.code] : [],
|
|
71
|
+
...properties.flatMap(({ value, length }) => length ? [value, length] : [value])
|
|
72
|
+
];
|
|
69
73
|
var timer = (input, output) => ({
|
|
70
74
|
inputs: [
|
|
71
75
|
[input, "IN", "BOOL"],
|
|
@@ -140,6 +144,15 @@ var standardBlocks = {
|
|
|
140
144
|
}
|
|
141
145
|
};
|
|
142
146
|
// packages/compiler/ir/core-model.ts
|
|
147
|
+
var nestedBodies = (item) => {
|
|
148
|
+
if (item.kind === "if")
|
|
149
|
+
return [item.then, item.else];
|
|
150
|
+
if (item.kind === "switch")
|
|
151
|
+
return [...item.cases.map((branch) => branch.body), item.fallback];
|
|
152
|
+
if (item.kind === "for")
|
|
153
|
+
return [item.body];
|
|
154
|
+
return [];
|
|
155
|
+
};
|
|
143
156
|
var verified = Symbol("verified core");
|
|
144
157
|
|
|
145
158
|
// packages/compiler/ir/scalars.ts
|
|
@@ -1121,6 +1134,7 @@ class RoutineNormalizer {
|
|
|
1121
1134
|
id: routine.id,
|
|
1122
1135
|
name: routine.name,
|
|
1123
1136
|
..."owner" in routine && routine.owner && { owner: routine.owner },
|
|
1137
|
+
..."origin" in routine && routine.origin && { origin: routine.origin },
|
|
1124
1138
|
parameters,
|
|
1125
1139
|
locals: routine.locals,
|
|
1126
1140
|
body: routine.body,
|
|
@@ -1474,18 +1488,7 @@ class RoutineNormalizer {
|
|
|
1474
1488
|
span: value.span
|
|
1475
1489
|
});
|
|
1476
1490
|
} else if (input.mode === "inOut" && value.kind === "borrow") {
|
|
1477
|
-
|
|
1478
|
-
if (!root || checked.issue || checked.type !== value.type || !block && !this.declarations.isValueType(value.type) || this.counters.has(root.id) || root.storage === "local" && !initialized.has(root.id))
|
|
1479
|
-
reject(checked.issue ?? "Borrow requires initialized mutable value storage of the exact type.", value.span);
|
|
1480
|
-
arguments_.push({
|
|
1481
|
-
kind: "borrow",
|
|
1482
|
-
type: value.type,
|
|
1483
|
-
place: {
|
|
1484
|
-
root: value.place.root,
|
|
1485
|
-
path: this.normalizePath(value.place, initialized, output)
|
|
1486
|
-
},
|
|
1487
|
-
span: value.span
|
|
1488
|
-
});
|
|
1491
|
+
arguments_.push(this.borrow(value, initialized, output));
|
|
1489
1492
|
} else {
|
|
1490
1493
|
if (value.kind === "borrow")
|
|
1491
1494
|
reject("Readonly value inputs cannot receive borrowed references.", value.span);
|
|
@@ -1494,6 +1497,21 @@ class RoutineNormalizer {
|
|
|
1494
1497
|
}
|
|
1495
1498
|
return arguments_;
|
|
1496
1499
|
}
|
|
1500
|
+
borrow(value, initialized, output) {
|
|
1501
|
+
const block = this.declarations.types.get(value.type)?.kind === "block";
|
|
1502
|
+
const root = this.sourceScope.get(value.place.root), checked = placeType(value.place, this.declarations.types, this.sourceScope, this.ranges, !block);
|
|
1503
|
+
if (!root || checked.issue || checked.type !== value.type || !block && !this.declarations.isValueType(value.type) || this.counters.has(root.id) || root.storage === "local" && !initialized.has(root.id))
|
|
1504
|
+
reject(checked.issue ?? "Borrow requires initialized mutable value storage of the exact type.", value.span);
|
|
1505
|
+
return {
|
|
1506
|
+
kind: "borrow",
|
|
1507
|
+
type: value.type,
|
|
1508
|
+
place: {
|
|
1509
|
+
root: value.place.root,
|
|
1510
|
+
path: this.normalizePath(value.place, initialized, output)
|
|
1511
|
+
},
|
|
1512
|
+
span: value.span
|
|
1513
|
+
};
|
|
1514
|
+
}
|
|
1497
1515
|
body(statements, initialized, inLoop = false) {
|
|
1498
1516
|
const output = [];
|
|
1499
1517
|
let flow = "fallthrough";
|
|
@@ -1661,6 +1679,27 @@ class RoutineNormalizer {
|
|
|
1661
1679
|
flow = "return";
|
|
1662
1680
|
break;
|
|
1663
1681
|
}
|
|
1682
|
+
case "telemetry": {
|
|
1683
|
+
const evaluate = (value) => this.expression(value, initialized, output);
|
|
1684
|
+
const { record } = item;
|
|
1685
|
+
output.push({
|
|
1686
|
+
kind: "telemetry",
|
|
1687
|
+
record: record.kind === "exception" ? { kind: "exception", code: evaluate(record.code) } : record,
|
|
1688
|
+
properties: item.properties.map(({ name, value, length }) => {
|
|
1689
|
+
if (!length)
|
|
1690
|
+
return { name, value: evaluate(value) };
|
|
1691
|
+
if (value.kind !== "borrow")
|
|
1692
|
+
reject("Telemetry text reads a byte array in place.", value.span);
|
|
1693
|
+
return {
|
|
1694
|
+
name,
|
|
1695
|
+
value: this.borrow(value, initialized, output),
|
|
1696
|
+
length: evaluate(length)
|
|
1697
|
+
};
|
|
1698
|
+
}),
|
|
1699
|
+
span: item.span
|
|
1700
|
+
});
|
|
1701
|
+
break;
|
|
1702
|
+
}
|
|
1664
1703
|
case "break":
|
|
1665
1704
|
case "continue":
|
|
1666
1705
|
if (!inLoop)
|
|
@@ -1728,15 +1767,6 @@ function linkModule(module, declarations, functions, normalizedBlocks, edges) {
|
|
|
1728
1767
|
const variable = variables.get(item.instance);
|
|
1729
1768
|
return variable && instancedBlock(variable.type, types)?.block;
|
|
1730
1769
|
};
|
|
1731
|
-
const nestedBodies = (item) => {
|
|
1732
|
-
if (item.kind === "for")
|
|
1733
|
-
return [item.body];
|
|
1734
|
-
if (item.kind === "if")
|
|
1735
|
-
return [item.then, item.else];
|
|
1736
|
-
if (item.kind === "switch")
|
|
1737
|
-
return [...item.cases.map((branch) => branch.body), item.fallback];
|
|
1738
|
-
return [];
|
|
1739
|
-
};
|
|
1740
1770
|
const writes = new Map;
|
|
1741
1771
|
const routineWrites = (id) => {
|
|
1742
1772
|
const cached = writes.get(id);
|
|
@@ -1849,12 +1879,24 @@ function linkModule(module, declarations, functions, normalizedBlocks, edges) {
|
|
|
1849
1879
|
useType(variable.type);
|
|
1850
1880
|
}
|
|
1851
1881
|
}
|
|
1882
|
+
const useTelemetryTypes = (body) => {
|
|
1883
|
+
for (const item of body) {
|
|
1884
|
+
if (item.kind === "telemetry")
|
|
1885
|
+
for (const operand of telemetryOperands(item))
|
|
1886
|
+
useType(operand.type);
|
|
1887
|
+
for (const nested of nestedBodies(item))
|
|
1888
|
+
useTelemetryTypes(nested);
|
|
1889
|
+
}
|
|
1890
|
+
};
|
|
1891
|
+
for (const routine of [...linkedFunctions, ...linkedBlocks])
|
|
1892
|
+
useTelemetryTypes(routine.body);
|
|
1852
1893
|
return {
|
|
1853
1894
|
types: module.types.filter((type) => usedTypes.has(type.id)),
|
|
1854
1895
|
variables: module.variables,
|
|
1855
1896
|
functions: linkedFunctions,
|
|
1856
1897
|
blocks: linkedBlocks,
|
|
1857
|
-
programs: module.programs
|
|
1898
|
+
programs: module.programs,
|
|
1899
|
+
...module.folded && { folded: module.folded }
|
|
1858
1900
|
};
|
|
1859
1901
|
}
|
|
1860
1902
|
|
|
@@ -1895,6 +1937,23 @@ function normalizeModule(module) {
|
|
|
1895
1937
|
throw cause;
|
|
1896
1938
|
}
|
|
1897
1939
|
}
|
|
1940
|
+
// packages/compiler/ir/errors.ts
|
|
1941
|
+
var jobErrors = {
|
|
1942
|
+
"1": "cancelled",
|
|
1943
|
+
"2": "timeout",
|
|
1944
|
+
"3": "request or response too large to encode",
|
|
1945
|
+
"4": "malformed response",
|
|
1946
|
+
"5": "network error or server restarted",
|
|
1947
|
+
"6": "TLS error",
|
|
1948
|
+
"7": "no free request slot",
|
|
1949
|
+
"10000": "HTTP status: 10000 + status code"
|
|
1950
|
+
};
|
|
1951
|
+
var httpErrors = { base: 1e4, last: 10999 };
|
|
1952
|
+
var errorName = (code) => {
|
|
1953
|
+
if (code > httpErrors.base && code <= httpErrors.last)
|
|
1954
|
+
return `HTTP ${code - httpErrors.base}`;
|
|
1955
|
+
return code < httpErrors.base ? jobErrors[code] : undefined;
|
|
1956
|
+
};
|
|
1898
1957
|
export {
|
|
1899
1958
|
aggregate,
|
|
1900
1959
|
aggregateIssue,
|
|
@@ -1908,20 +1967,24 @@ export {
|
|
|
1908
1967
|
domainIssue,
|
|
1909
1968
|
durationLiteral,
|
|
1910
1969
|
error,
|
|
1970
|
+
errorName,
|
|
1911
1971
|
expressionIssue,
|
|
1912
1972
|
floatMaximum,
|
|
1913
1973
|
fold,
|
|
1914
1974
|
formatDiagnostic,
|
|
1915
1975
|
hasErrors,
|
|
1976
|
+
httpErrors,
|
|
1916
1977
|
instancedBlock,
|
|
1917
1978
|
integerRange,
|
|
1918
1979
|
integerType,
|
|
1919
1980
|
interval,
|
|
1920
1981
|
isVerifiedCore,
|
|
1982
|
+
jobErrors,
|
|
1921
1983
|
layoutIssue,
|
|
1922
1984
|
loopBounds,
|
|
1923
1985
|
loopIterations,
|
|
1924
1986
|
narrowRanges,
|
|
1987
|
+
nestedBodies,
|
|
1925
1988
|
normalizeModule,
|
|
1926
1989
|
parseInteger,
|
|
1927
1990
|
placeType,
|
|
@@ -1929,10 +1992,11 @@ export {
|
|
|
1929
1992
|
saturateFloat,
|
|
1930
1993
|
scalarIssue,
|
|
1931
1994
|
standardBlocks,
|
|
1995
|
+
telemetryOperands,
|
|
1932
1996
|
valueFits,
|
|
1933
1997
|
valueRange,
|
|
1934
1998
|
wrapsNatively
|
|
1935
1999
|
};
|
|
1936
2000
|
|
|
1937
|
-
//# debugId=
|
|
2001
|
+
//# debugId=43D0B7CC8A03DD5164756E2164756E21
|
|
1938
2002
|
//# sourceMappingURL=ir.js.map
|