@tsplc/compiler 0.5.5 → 0.5.7
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 +152 -31
- package/dist/bun-runtime.js.map +10 -9
- package/dist/cli.js +8 -5
- package/dist/cli.js.map +3 -3
- package/dist/codesys.js +260 -85
- package/dist/codesys.js.map +9 -9
- package/dist/collections.js +395 -0
- package/dist/collections.js.map +10 -0
- package/dist/elaborate-capture.js +62 -4
- package/dist/elaborate-capture.js.map +4 -4
- package/dist/index.js +5322 -1058
- package/dist/index.js.map +30 -23
- package/dist/ir.js +122 -1
- package/dist/ir.js.map +6 -6
- package/dist/project.js +8 -5
- package/dist/project.js.map +3 -3
- package/package.json +14 -9
- package/src/codesys/emit.ts +8 -2
- package/src/codesys/http.ts +114 -72
- package/src/codesys/instrumentation.ts +30 -6
- package/src/codesys/numeric.ts +61 -0
- package/src/codesys/routines.ts +39 -9
- package/src/codesys/st-files.ts +73 -6
- package/src/codesys/telemetry.ts +70 -35
- package/src/frontend/control-flow.ts +752 -0
- package/src/frontend/coroutines.ts +171 -7
- package/src/frontend/elaborate/array-searches.ts +216 -0
- package/src/frontend/elaborate/assignments.ts +352 -0
- package/src/frontend/elaborate/calls.ts +467 -42
- package/src/frontend/elaborate/capture-protocol.ts +19 -0
- package/src/frontend/elaborate/capture.ts +80 -2
- package/src/frontend/elaborate/dialect.ts +116 -2
- package/src/frontend/elaborate/expressions.ts +927 -80
- package/src/frontend/elaborate/filtered-arrays.ts +607 -0
- package/src/frontend/elaborate/frame.ts +44 -1
- package/src/frontend/elaborate/generics.ts +137 -0
- package/src/frontend/elaborate/graph.ts +91 -0
- package/src/frontend/elaborate/index.ts +30 -5
- package/src/frontend/elaborate/initializers.ts +15 -1
- package/src/frontend/elaborate/iterators.ts +1677 -0
- package/src/frontend/elaborate/layouts.ts +41 -19
- package/src/frontend/elaborate/model.ts +64 -8
- package/src/frontend/elaborate/references.ts +749 -0
- package/src/frontend/elaborate/specialize.ts +459 -29
- package/src/frontend/elaborate/statements.ts +552 -133
- package/src/frontend/elaborate/storage.ts +151 -10
- package/src/frontend/elaborate/values.ts +72 -0
- package/src/frontend/elaborate/writes.ts +302 -1
- package/src/frontend/intrinsics.ts +32 -0
- package/src/frontend/module-graph.ts +2 -1
- package/src/frontend/positions.ts +12 -5
- package/src/frontend/typescript.ts +5 -1
- package/src/ir/core-model.ts +2 -6
- package/src/ir/fold.ts +30 -1
- package/src/ir/index.ts +5 -0
- package/src/ir/model.ts +53 -2
- package/src/ir/scalars.ts +126 -0
- package/src/runtime/.runtime-VaUSOu/server/router.ts +17 -0
- package/src/runtime/.runtime-VaUSOu/src/cell.ts +45 -0
- package/src/runtime/.runtime-VaUSOu/src/controller.ts +58 -0
- package/src/runtime/.runtime-VaUSOu/src/lane.ts +6 -0
- package/src/runtime/.runtime-VaUSOu/src/main.ts +11 -0
- package/src/runtime/.runtime-VaUSOu/src/services.ts +8 -0
- package/src/runtime/.runtime-VaUSOu/tsconfig.json +13 -0
- package/src/runtime/.runtime-VaUSOu/tsplc.config.ts +31 -0
- package/src/runtime/.runtime-ybIxYh/server/router.ts +17 -0
- package/src/runtime/.runtime-ybIxYh/src/cell.ts +45 -0
- package/src/runtime/.runtime-ybIxYh/src/controller.ts +58 -0
- package/src/runtime/.runtime-ybIxYh/src/lane.ts +6 -0
- package/src/runtime/.runtime-ybIxYh/src/main.ts +11 -0
- package/src/runtime/.runtime-ybIxYh/src/services.ts +8 -0
- package/src/runtime/.runtime-ybIxYh/tsconfig.json +13 -0
- package/src/runtime/.runtime-ybIxYh/tsplc.config.ts +31 -0
- package/src/runtime/async.ts +15 -12
- package/src/runtime/launch.ts +11 -4
- package/src/runtime/runtime.ts +26 -23
- package/src/runtime/telemetry.ts +14 -6
- package/src/runtime/transport.ts +172 -0
- package/stdlib/collections.ts +514 -0
- package/types/index.d.ts +18 -0
package/dist/codesys.js
CHANGED
|
@@ -330,11 +330,24 @@ import {
|
|
|
330
330
|
floatMaximum,
|
|
331
331
|
integerRange,
|
|
332
332
|
integerType,
|
|
333
|
+
isElementary,
|
|
333
334
|
nestedBodies,
|
|
334
335
|
pathIndexes,
|
|
335
336
|
statementExpressions,
|
|
336
337
|
subexpressions
|
|
337
338
|
} from "@tsplc/compiler/ir";
|
|
339
|
+
var elementaryNames = {
|
|
340
|
+
sqrt: "SQRT",
|
|
341
|
+
ln: "LN",
|
|
342
|
+
log10: "LOG",
|
|
343
|
+
exp: "EXP",
|
|
344
|
+
sin: "SIN",
|
|
345
|
+
cos: "COS",
|
|
346
|
+
tan: "TAN",
|
|
347
|
+
asin: "ASIN",
|
|
348
|
+
acos: "ACOS",
|
|
349
|
+
atan: "ATAN"
|
|
350
|
+
};
|
|
338
351
|
var operatorTokens = {
|
|
339
352
|
add: "+",
|
|
340
353
|
subtract: "-",
|
|
@@ -384,6 +397,9 @@ class NumericLowering {
|
|
|
384
397
|
if (value.kind === "convert" && value.policy === "saturate") {
|
|
385
398
|
this.saturation(value.operand.type, value.type);
|
|
386
399
|
}
|
|
400
|
+
if (value.kind === "unary" && value.operator === "truncate") {
|
|
401
|
+
this.truncation(value.type);
|
|
402
|
+
}
|
|
387
403
|
}
|
|
388
404
|
prepareStatements(items) {
|
|
389
405
|
for (const item of items) {
|
|
@@ -407,6 +423,12 @@ class NumericLowering {
|
|
|
407
423
|
if (value.operator === "clock") {
|
|
408
424
|
return "TO_DINT(TIME_TO_UDINT(TIME()))";
|
|
409
425
|
}
|
|
426
|
+
if (isElementary(value.operator)) {
|
|
427
|
+
return `${elementaryNames[value.operator]}(${operands[0]})`;
|
|
428
|
+
}
|
|
429
|
+
if (value.operator === "truncate") {
|
|
430
|
+
return `${this.truncation(value.type)}(${operands[0]})`;
|
|
431
|
+
}
|
|
410
432
|
return value.operator === "not" ? `(NOT ${operands[0]})` : `TO_${value.type}(${value.operator === "negate" ? "-" : "NOT "}${operands[0]})`;
|
|
411
433
|
}
|
|
412
434
|
if (value.kind !== "binary") {
|
|
@@ -415,6 +437,9 @@ class NumericLowering {
|
|
|
415
437
|
if (value.policy) {
|
|
416
438
|
return `${this.arithmetic(value.type, value.operator, value.policy)}(${operands.join(", ")})`;
|
|
417
439
|
}
|
|
440
|
+
if (value.operator === "power") {
|
|
441
|
+
return `EXPT(${operands.join(", ")})`;
|
|
442
|
+
}
|
|
418
443
|
if (value.operator === "shiftLeft" || value.operator === "shiftRight") {
|
|
419
444
|
const shift = value.operator === "shiftLeft" ? "SHL" : "SHR";
|
|
420
445
|
return `TO_${value.type}(${shift}(${operands.join(", ")}))`;
|
|
@@ -578,6 +603,25 @@ END_IF;
|
|
|
578
603
|
`;
|
|
579
604
|
});
|
|
580
605
|
}
|
|
606
|
+
truncation(typeId) {
|
|
607
|
+
const type = this.types.get(typeId);
|
|
608
|
+
if (type?.kind !== "float") {
|
|
609
|
+
throw new Error("Expected verified float truncation");
|
|
610
|
+
}
|
|
611
|
+
const whole = scalarLiteral({ kind: "float", value: 2 ** (type.bits === 32 ? 23 : 52) }, typeId);
|
|
612
|
+
return this.helper(`truncate_${typeId}`, typeId, [["value", typeId]], (name) => `IF ABS(value) >= ${whole} THEN
|
|
613
|
+
${name} := value;
|
|
614
|
+
RETURN;
|
|
615
|
+
END_IF;
|
|
616
|
+
nearest := TO_LINT(value);
|
|
617
|
+
IF value >= 0 AND TO_${typeId}(nearest) > value THEN
|
|
618
|
+
nearest := nearest - 1;
|
|
619
|
+
ELSIF value < 0 AND TO_${typeId}(nearest) < value THEN
|
|
620
|
+
nearest := nearest + 1;
|
|
621
|
+
END_IF;
|
|
622
|
+
${name} := TO_${typeId}(nearest);
|
|
623
|
+
`, " nearest : LINT;");
|
|
624
|
+
}
|
|
581
625
|
saturation(sourceId, targetId) {
|
|
582
626
|
const source = this.types.get(sourceId);
|
|
583
627
|
const target = this.types.get(targetId);
|
|
@@ -1608,15 +1652,51 @@ SkipWhitespace();
|
|
|
1608
1652
|
IF malformed OR cursor<>TO_UINT(ByteLength(payload))+1 OR seen<>DWORD#${2 ** responseLayout.fields.length - 1} THEN ${port("error")}:=${jobError.malformedResponse};END_IF;`;
|
|
1609
1653
|
return { port, requestCode, decodeResponse, inputs, outputs };
|
|
1610
1654
|
};
|
|
1611
|
-
var
|
|
1655
|
+
var rpcSlots = (symbols, id, owner, path) => {
|
|
1656
|
+
const name = symbols.names.allocateObject("GVL", `TsplcRpc_${owner}`);
|
|
1657
|
+
return {
|
|
1658
|
+
list: {
|
|
1659
|
+
id: `${id}:rpc`,
|
|
1660
|
+
kind: "globalList",
|
|
1661
|
+
name,
|
|
1662
|
+
declaration: `{attribute 'qualified_only'}
|
|
1663
|
+
VAR_GLOBAL
|
|
1664
|
+
{attribute 'symbol' := 'read'} requests:ARRAY[1..${opcuaServiceCapacity}] OF STRING(${plcBufferBytes});
|
|
1665
|
+
{attribute 'symbol' := 'read'} requestIds:ARRAY[1..${opcuaServiceCapacity}] OF STRING(64);
|
|
1666
|
+
{attribute 'symbol' := 'readwrite'} replyIds:ARRAY[1..${opcuaServiceCapacity}] OF STRING(64);
|
|
1667
|
+
{attribute 'symbol' := 'readwrite'} replies:ARRAY[1..${opcuaServiceCapacity}] OF STRING(${plcBufferBytes});
|
|
1668
|
+
{attribute 'symbol' := 'readwrite'} epochs:ARRAY[1..${opcuaServiceCapacity}] OF STRING(32);
|
|
1669
|
+
inUse:ARRAY[1..${opcuaServiceCapacity}] OF __XWORD;
|
|
1670
|
+
sequence:ARRAY[1..${opcuaServiceCapacity}] OF UDINT;
|
|
1671
|
+
END_VAR`
|
|
1672
|
+
},
|
|
1673
|
+
channels: Array.from({ length: opcuaServiceCapacity }, (_, index) => ({
|
|
1674
|
+
path,
|
|
1675
|
+
request: `${name}.requests[${index + 1}]`,
|
|
1676
|
+
reply: `${name}.replies[${index + 1}]`,
|
|
1677
|
+
requestId: `${name}.requestIds[${index + 1}]`,
|
|
1678
|
+
replyId: `${name}.replyIds[${index + 1}]`,
|
|
1679
|
+
epoch: `${name}.epochs[${index + 1}]`
|
|
1680
|
+
}))
|
|
1681
|
+
};
|
|
1682
|
+
};
|
|
1683
|
+
var opcuaClient = ({
|
|
1684
|
+
id,
|
|
1685
|
+
name,
|
|
1686
|
+
ports,
|
|
1687
|
+
port,
|
|
1688
|
+
timeoutMs,
|
|
1689
|
+
rpcGlobal,
|
|
1690
|
+
body,
|
|
1691
|
+
decode
|
|
1692
|
+
}) => {
|
|
1612
1693
|
const channel = (field, index = "slotIndex") => `${rpcGlobal}.${field}[${index}]`;
|
|
1613
1694
|
return {
|
|
1614
|
-
id
|
|
1695
|
+
id,
|
|
1615
1696
|
kind: "functionBlock",
|
|
1616
1697
|
name,
|
|
1617
1698
|
declaration: `FUNCTION_BLOCK ${name}
|
|
1618
|
-
|
|
1619
|
-
VAR_OUTPUT ${outputs} END_VAR
|
|
1699
|
+
${ports}
|
|
1620
1700
|
VAR
|
|
1621
1701
|
timeout:TON;stage:UINT;slotIndex:UINT;candidate:UINT;
|
|
1622
1702
|
identity:STRING(64);epoch:STRING(32);prefix:STRING(80);
|
|
@@ -1642,7 +1722,7 @@ IF stage=0 THEN
|
|
|
1642
1722
|
ELSE
|
|
1643
1723
|
epoch:=${channel("epochs")};identity:=CONCAT(CONCAT(epoch,':'),UDINT_TO_STRING(${channel("sequence")}));
|
|
1644
1724
|
prefix:=CONCAT(identity,'|');payload:='';malformed:=FALSE;
|
|
1645
|
-
|
|
1725
|
+
${body}
|
|
1646
1726
|
IF malformed THEN ${port("error")}:=${jobError.tooLarge};stage:=90;
|
|
1647
1727
|
ELSIF ByteLength(payload)+LEN(prefix)>${plcBufferBytes} THEN ${port("error")}:=${jobError.tooLarge};stage:=90;
|
|
1648
1728
|
ELSE
|
|
@@ -1653,18 +1733,20 @@ IF stage=0 THEN
|
|
|
1653
1733
|
END_IF;
|
|
1654
1734
|
END_IF;
|
|
1655
1735
|
END_IF;
|
|
1656
|
-
timeout(IN:=stage<90,PT:=T#${
|
|
1736
|
+
timeout(IN:=stage<90,PT:=T#${timeoutMs}ms);
|
|
1657
1737
|
IF timeout.Q THEN ${port("error")}:=${jobError.timeout};stage:=90;END_IF;
|
|
1658
1738
|
IF stage=1 THEN
|
|
1659
1739
|
IF ${channel("epochs")}<>epoch THEN ${port("error")}:=${jobError.network};stage:=90;
|
|
1660
1740
|
ELSIF ${channel("replyIds")}=identity AND_THEN LEFT(${channel("replies")},LEN(prefix))=prefix THEN
|
|
1661
1741
|
payload:='';cursor:=LEN(prefix);
|
|
1662
1742
|
IF ByteLength(${channel("replies")})<cursor+4 THEN ${port("error")}:=${jobError.malformedResponse};
|
|
1663
|
-
ELSIF ${channel("replies")}[cursor
|
|
1743
|
+
ELSIF ${channel("replies")}[cursor+1]<>124 THEN ${port("error")}:=${jobError.network};
|
|
1744
|
+
ELSIF ${channel("replies")}[cursor]=52 THEN ${port("error")}:=${httpErrors.base + 400};
|
|
1745
|
+
ELSIF ${channel("replies")}[cursor]<>48 THEN ${port("error")}:=${jobError.network};
|
|
1664
1746
|
ELSE
|
|
1665
1747
|
FOR candidate:=cursor+2 TO ByteLength(${channel("replies")})-1 DO payload[candidate-cursor-2]:=${channel("replies")}[candidate];END_FOR;
|
|
1666
1748
|
payload[ByteLength(${channel("replies")})-cursor-2]:=0;
|
|
1667
|
-
${
|
|
1749
|
+
${decode}
|
|
1668
1750
|
END_IF;
|
|
1669
1751
|
stage:=90;
|
|
1670
1752
|
END_IF;
|
|
@@ -2021,43 +2103,42 @@ IF digits=0 THEN malformed:=TRUE;END_IF;IF negative THEN numberValue:=-numberVal
|
|
|
2021
2103
|
].filter((item) => transport === "http" || !["AppendWire", "FindHeaders", "ReadHeaders"].includes(item.name));
|
|
2022
2104
|
};
|
|
2023
2105
|
function emitServiceBlock({ plan, symbols, instrumentation }, networkName, fn) {
|
|
2024
|
-
const objects = [];
|
|
2025
|
-
const rpcChannels = [];
|
|
2026
2106
|
const endpoint = required2(plan.http[fn.id]);
|
|
2027
|
-
const rpcGlobal = endpoint.transport === "opcua" ? symbols.names.allocateObject("GVL", `TsplcRpc_${required2(symbols.blockNames.get(fn.id))}`) : undefined;
|
|
2028
|
-
if (rpcGlobal) {
|
|
2029
|
-
objects.push({
|
|
2030
|
-
id: `${fn.id}:rpc`,
|
|
2031
|
-
kind: "globalList",
|
|
2032
|
-
name: rpcGlobal,
|
|
2033
|
-
declaration: `{attribute 'qualified_only'}
|
|
2034
|
-
VAR_GLOBAL
|
|
2035
|
-
{attribute 'symbol' := 'read'} requests:ARRAY[1..${opcuaServiceCapacity}] OF STRING(${plcBufferBytes});
|
|
2036
|
-
{attribute 'symbol' := 'read'} requestIds:ARRAY[1..${opcuaServiceCapacity}] OF STRING(64);
|
|
2037
|
-
{attribute 'symbol' := 'readwrite'} replyIds:ARRAY[1..${opcuaServiceCapacity}] OF STRING(64);
|
|
2038
|
-
{attribute 'symbol' := 'readwrite'} replies:ARRAY[1..${opcuaServiceCapacity}] OF STRING(${plcBufferBytes});
|
|
2039
|
-
{attribute 'symbol' := 'readwrite'} epochs:ARRAY[1..${opcuaServiceCapacity}] OF STRING(32);
|
|
2040
|
-
inUse:ARRAY[1..${opcuaServiceCapacity}] OF __XWORD;
|
|
2041
|
-
sequence:ARRAY[1..${opcuaServiceCapacity}] OF UDINT;
|
|
2042
|
-
END_VAR`
|
|
2043
|
-
});
|
|
2044
|
-
for (let slot = 1;slot <= opcuaServiceCapacity; slot++) {
|
|
2045
|
-
rpcChannels.push({
|
|
2046
|
-
path: endpoint.path,
|
|
2047
|
-
request: `${rpcGlobal}.requests[${slot}]`,
|
|
2048
|
-
reply: `${rpcGlobal}.replies[${slot}]`,
|
|
2049
|
-
requestId: `${rpcGlobal}.requestIds[${slot}]`,
|
|
2050
|
-
replyId: `${rpcGlobal}.replyIds[${slot}]`,
|
|
2051
|
-
epoch: `${rpcGlobal}.epochs[${slot}]`
|
|
2052
|
-
});
|
|
2053
|
-
}
|
|
2054
|
-
}
|
|
2055
2107
|
const name = required2(symbols.blockNames.get(fn.id));
|
|
2056
2108
|
const codecs = serviceCodecs(fn, required2(symbols.blockFields.get(fn.id)), symbols.typeMap, symbols.targetTypes);
|
|
2109
|
+
const methods = [
|
|
2110
|
+
...httpMethods(fn.id, endpoint.transport),
|
|
2111
|
+
...httpCertificateVerifier(fn.id, name, endpoint)
|
|
2112
|
+
];
|
|
2113
|
+
if (endpoint.transport === "opcua") {
|
|
2114
|
+
const slots = rpcSlots(symbols, fn.id, name, endpoint.path);
|
|
2115
|
+
return {
|
|
2116
|
+
objects: [
|
|
2117
|
+
slots.list,
|
|
2118
|
+
opcuaClient({
|
|
2119
|
+
id: fn.id,
|
|
2120
|
+
name,
|
|
2121
|
+
ports: `VAR_INPUT ${codecs.inputs} END_VAR
|
|
2122
|
+
VAR_OUTPUT ${codecs.outputs} END_VAR`,
|
|
2123
|
+
port: codecs.port,
|
|
2124
|
+
timeoutMs: endpoint.timeoutMs,
|
|
2125
|
+
rpcGlobal: slots.list.name,
|
|
2126
|
+
body: `Append('{');${codecs.requestCode}Append('}');`,
|
|
2127
|
+
decode: codecs.decodeResponse
|
|
2128
|
+
}),
|
|
2129
|
+
...methods
|
|
2130
|
+
],
|
|
2131
|
+
rpcChannels: slots.channels
|
|
2132
|
+
};
|
|
2133
|
+
}
|
|
2057
2134
|
const requestFields = instrumentation.fields.get(fn.id);
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2135
|
+
return {
|
|
2136
|
+
objects: [
|
|
2137
|
+
...httpServiceBlock(fn, name, codecs, endpoint, `${required2(networkName)}.network`, requestFields?.job && requestFields.sequence ? { job: requestFields.job, sequence: requestFields.sequence } : undefined),
|
|
2138
|
+
...methods
|
|
2139
|
+
],
|
|
2140
|
+
rpcChannels: []
|
|
2141
|
+
};
|
|
2061
2142
|
}
|
|
2062
2143
|
function httpNetwork(plan, symbols) {
|
|
2063
2144
|
if (!Object.values(plan.http).some((endpoint) => endpoint.transport !== "opcua")) {
|
|
@@ -2595,7 +2676,7 @@ import {
|
|
|
2595
2676
|
} from "@tsplc/compiler/ir";
|
|
2596
2677
|
import { serviceOfPath } from "@tsplc/server";
|
|
2597
2678
|
// packages/compiler/package.json
|
|
2598
|
-
var version = "0.5.
|
|
2679
|
+
var version = "0.5.7";
|
|
2599
2680
|
|
|
2600
2681
|
// packages/compiler/src/codesys/sources.ts
|
|
2601
2682
|
import { existsSync, readFileSync } from "node:fs";
|
|
@@ -2873,9 +2954,27 @@ function planTelemetry(core, deployment, options, project, report) {
|
|
|
2873
2954
|
}
|
|
2874
2955
|
const server = project.server;
|
|
2875
2956
|
const base = server?.baseUrlEnv && project.environment[server.baseUrlEnv];
|
|
2957
|
+
const plan = {
|
|
2958
|
+
...settings,
|
|
2959
|
+
capacity: Math.max(settings.capacity, project.trace ? project.trace.capacity : 0),
|
|
2960
|
+
calls,
|
|
2961
|
+
failures,
|
|
2962
|
+
...project.trace && { traceOperands: project.trace.operands }
|
|
2963
|
+
};
|
|
2876
2964
|
if (server?.transport === "opcua") {
|
|
2877
|
-
|
|
2878
|
-
|
|
2965
|
+
return {
|
|
2966
|
+
telemetry: plan,
|
|
2967
|
+
endpoint: {
|
|
2968
|
+
transport: "opcua",
|
|
2969
|
+
host: "",
|
|
2970
|
+
port: 0,
|
|
2971
|
+
authority: "",
|
|
2972
|
+
path: telemetryPath,
|
|
2973
|
+
token: "",
|
|
2974
|
+
timeoutMs: options.http.timeoutMs,
|
|
2975
|
+
tls: false
|
|
2976
|
+
}
|
|
2977
|
+
};
|
|
2879
2978
|
}
|
|
2880
2979
|
if (!base) {
|
|
2881
2980
|
report(`Telemetry posts to the app server: set server.baseUrlEnv and that environment variable to its base URL.`);
|
|
@@ -2883,13 +2982,7 @@ function planTelemetry(core, deployment, options, project, report) {
|
|
|
2883
2982
|
}
|
|
2884
2983
|
try {
|
|
2885
2984
|
return {
|
|
2886
|
-
telemetry:
|
|
2887
|
-
...settings,
|
|
2888
|
-
capacity: Math.max(settings.capacity, project.trace ? project.trace.capacity : 0),
|
|
2889
|
-
calls,
|
|
2890
|
-
failures,
|
|
2891
|
-
...project.trace && { traceOperands: project.trace.operands }
|
|
2892
|
-
},
|
|
2985
|
+
telemetry: plan,
|
|
2893
2986
|
endpoint: resolveHttpEndpoint(`${base.replace(/\/+$/, "")}${telemetryPath}`, options.http, project.environment)
|
|
2894
2987
|
};
|
|
2895
2988
|
} catch (cause) {
|
|
@@ -2932,8 +3025,7 @@ function telemetryObjects({
|
|
|
2932
3025
|
plan,
|
|
2933
3026
|
names,
|
|
2934
3027
|
target,
|
|
2935
|
-
|
|
2936
|
-
network,
|
|
3028
|
+
transport,
|
|
2937
3029
|
build,
|
|
2938
3030
|
types
|
|
2939
3031
|
}) {
|
|
@@ -3047,10 +3139,7 @@ ${instances.length ? ` instance : STRING(${maximum(instances)});
|
|
|
3047
3139
|
];
|
|
3048
3140
|
const { start, rest } = header(build);
|
|
3049
3141
|
const helpers = httpMethods(writer).filter((item) => ["ByteLength", "Append", "WriteString"].includes(item.name));
|
|
3050
|
-
const
|
|
3051
|
-
id: telemetryClient,
|
|
3052
|
-
name: names.client,
|
|
3053
|
-
ports: `VAR_INPUT
|
|
3142
|
+
const clientPorts = `VAR_INPUT
|
|
3054
3143
|
start : BOOL;
|
|
3055
3144
|
cancel : BOOL;
|
|
3056
3145
|
END_VAR
|
|
@@ -3061,15 +3150,35 @@ VAR_OUTPUT
|
|
|
3061
3150
|
busy : BOOL;
|
|
3062
3151
|
done : BOOL;
|
|
3063
3152
|
error : UDINT;
|
|
3064
|
-
END_VAR
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3153
|
+
END_VAR`;
|
|
3154
|
+
const clientObjects = transport.kind === "opcua" ? [
|
|
3155
|
+
opcuaClient({
|
|
3156
|
+
id: telemetryClient,
|
|
3157
|
+
name: names.client,
|
|
3158
|
+
ports: clientPorts,
|
|
3159
|
+
port: (label) => label,
|
|
3160
|
+
timeoutMs: transport.timeoutMs,
|
|
3161
|
+
rpcGlobal: transport.rpcGlobal,
|
|
3162
|
+
body: "Append(body);",
|
|
3163
|
+
decode: ""
|
|
3164
|
+
}),
|
|
3165
|
+
...httpMethods(telemetryClient, "opcua")
|
|
3166
|
+
] : [
|
|
3167
|
+
...nativeHttp({
|
|
3168
|
+
id: telemetryClient,
|
|
3169
|
+
name: names.client,
|
|
3170
|
+
ports: clientPorts,
|
|
3171
|
+
port: (label) => label,
|
|
3172
|
+
endpoint: transport.endpoint,
|
|
3173
|
+
network: transport.network,
|
|
3174
|
+
method: "POST",
|
|
3175
|
+
json: true,
|
|
3176
|
+
body: "Append(body);",
|
|
3177
|
+
decode: ""
|
|
3178
|
+
}),
|
|
3179
|
+
...httpMethods(telemetryClient),
|
|
3180
|
+
...httpCertificateVerifier(telemetryClient, names.client, transport.endpoint)
|
|
3181
|
+
];
|
|
3073
3182
|
return [
|
|
3074
3183
|
{
|
|
3075
3184
|
id: "tsplc:telemetryRecord",
|
|
@@ -3207,10 +3316,7 @@ WriteString(text);
|
|
|
3207
3316
|
...calls,
|
|
3208
3317
|
...failures,
|
|
3209
3318
|
...trace,
|
|
3210
|
-
|
|
3211
|
-
...clientLifecycle,
|
|
3212
|
-
...httpMethods(telemetryClient),
|
|
3213
|
-
...httpCertificateVerifier(telemetryClient, names.client, endpoint)
|
|
3319
|
+
...clientObjects
|
|
3214
3320
|
];
|
|
3215
3321
|
}
|
|
3216
3322
|
|
|
@@ -3703,7 +3809,7 @@ function planInstrumentation(plan, symbols) {
|
|
|
3703
3809
|
const telemetryNames = rings.size ? {
|
|
3704
3810
|
writer: symbols.names.allocateObject("FB", "TsplcTelemetry"),
|
|
3705
3811
|
record: symbols.names.allocateObject("ST", "TsplcRecord"),
|
|
3706
|
-
client: symbols.names.allocateObject("FB", "TsplcTelemetryHttp")
|
|
3812
|
+
client: symbols.names.allocateObject("FB", plan.http[telemetryClient]?.transport === "opcua" ? "TsplcTelemetryOpcUa" : "TsplcTelemetryHttp")
|
|
3707
3813
|
} : undefined;
|
|
3708
3814
|
const jobs = core.blocks.filter((block) => block.job).flatMap((block) => analysis.instances.get(block.id).map((path) => ({ block, path })));
|
|
3709
3815
|
const jobIds = new Map;
|
|
@@ -3743,17 +3849,27 @@ function emitTelemetry(plan, symbols, instrumentation, networkName) {
|
|
|
3743
3849
|
const { telemetry } = plan;
|
|
3744
3850
|
const names = instrumentation.telemetryNames;
|
|
3745
3851
|
if (!telemetry || !names) {
|
|
3746
|
-
return [];
|
|
3852
|
+
return { objects: [], rpcChannels: [] };
|
|
3747
3853
|
}
|
|
3748
|
-
|
|
3854
|
+
const endpoint = required2(plan.http[telemetryClient]);
|
|
3855
|
+
const slots = endpoint.transport === "opcua" ? rpcSlots(symbols, telemetryClient, names.client, endpoint.path) : undefined;
|
|
3856
|
+
const objects = telemetryObjects({
|
|
3749
3857
|
plan: telemetry,
|
|
3750
3858
|
names,
|
|
3751
3859
|
target: symbols.targetTypes,
|
|
3752
|
-
|
|
3753
|
-
|
|
3860
|
+
transport: slots ? {
|
|
3861
|
+
kind: "opcua",
|
|
3862
|
+
timeoutMs: endpoint.timeoutMs,
|
|
3863
|
+
rpcGlobal: slots.list.name
|
|
3864
|
+
} : {
|
|
3865
|
+
kind: "http",
|
|
3866
|
+
endpoint,
|
|
3867
|
+
network: `${required2(networkName)}.network`
|
|
3868
|
+
},
|
|
3754
3869
|
build: buildPlaceholder,
|
|
3755
3870
|
types: symbols.typeMap
|
|
3756
3871
|
});
|
|
3872
|
+
return slots ? { objects: [slots.list, ...objects], rpcChannels: slots.channels } : { objects, rpcChannels: [] };
|
|
3757
3873
|
}
|
|
3758
3874
|
function emitDebugGlobal(plan, instrumentation, objects, manifest) {
|
|
3759
3875
|
const hash = createHash("sha256");
|
|
@@ -4565,6 +4681,13 @@ function emitRoutine(context, fn) {
|
|
|
4565
4681
|
write(`${destination} := ${targetTypes.literal(value, id)};`, depth, span);
|
|
4566
4682
|
}
|
|
4567
4683
|
};
|
|
4684
|
+
const assignResult = (destination, value, depth, span) => {
|
|
4685
|
+
if (value.kind === "constant") {
|
|
4686
|
+
assignConstant(destination, value.value, value.type, depth, span);
|
|
4687
|
+
} else {
|
|
4688
|
+
write(`${destination} := ${expressionText(storage, value)};`, depth, span);
|
|
4689
|
+
}
|
|
4690
|
+
};
|
|
4568
4691
|
const tracked = block && instrumentation.fields.get(block.id);
|
|
4569
4692
|
const body = (items, depth) => {
|
|
4570
4693
|
for (const item of items) {
|
|
@@ -4700,18 +4823,27 @@ function emitRoutine(context, fn) {
|
|
|
4700
4823
|
case "return":
|
|
4701
4824
|
writeProbes(probes, write, item, depth);
|
|
4702
4825
|
if (block) {
|
|
4703
|
-
|
|
4704
|
-
|
|
4826
|
+
const { value } = item;
|
|
4827
|
+
if (value?.kind === "constant" && value.value.kind === "record") {
|
|
4828
|
+
for (const output of block.outputs) {
|
|
4829
|
+
assignConstant(storageName(storage, output.id), required2(value.value.fields[output.name]), output.type, depth, item.span);
|
|
4830
|
+
}
|
|
4831
|
+
} else if (value) {
|
|
4832
|
+
const returned = expressionText(storage, value);
|
|
4705
4833
|
for (const output of block.outputs) {
|
|
4706
4834
|
write(`${storageName(storage, output.id)} := ${returned}.${targetTypes.field(required2(block.result), output.name)};`, depth, item.span);
|
|
4707
4835
|
}
|
|
4708
4836
|
}
|
|
4709
4837
|
} else if (program) {
|
|
4710
4838
|
if (item.value) {
|
|
4711
|
-
|
|
4839
|
+
assignResult(required2(symbols.programResults.get(fn.id)), item.value, depth, item.span);
|
|
4712
4840
|
}
|
|
4713
4841
|
} else if (!method || fn.result) {
|
|
4714
|
-
|
|
4842
|
+
if (item.value) {
|
|
4843
|
+
assignResult(name, item.value, depth, item.span);
|
|
4844
|
+
} else {
|
|
4845
|
+
write(`${name} := TRUE;`, depth, item.span);
|
|
4846
|
+
}
|
|
4715
4847
|
}
|
|
4716
4848
|
if (mutex) {
|
|
4717
4849
|
release(mutex, depth, item.span);
|
|
@@ -4928,15 +5060,57 @@ function objectPaths(plan, symbols, objects) {
|
|
|
4928
5060
|
const owner = required2(block === undefined ? undefined : byId.get(block)?.item);
|
|
4929
5061
|
return `${objectPath(owner)}/methods/${object.name}`;
|
|
4930
5062
|
}
|
|
5063
|
+
const folders = required2(placed.get(object));
|
|
5064
|
+
return [folderPath(folders), object.name].filter(Boolean).join("/");
|
|
5065
|
+
};
|
|
5066
|
+
const placedFolders = (object) => {
|
|
4931
5067
|
const folders = sourceFolders(plan.project.root, sourceModule(object));
|
|
4932
5068
|
if (!folders) {
|
|
4933
|
-
return
|
|
5069
|
+
return [generatedFolder(object)];
|
|
4934
5070
|
}
|
|
4935
|
-
|
|
4936
|
-
return [...kept, object.name].join("/");
|
|
5071
|
+
return object.kind !== "dataType" && folders.at(-1) === object.name ? folders.slice(0, -1) : folders;
|
|
4937
5072
|
};
|
|
5073
|
+
const placed = new Map(objects.filter((object) => object.kind !== "method").map((object) => [object, placedFolders(object)]));
|
|
5074
|
+
const folderPath = separatedFolders([...placed].map(([object, folders]) => ({ folders, name: object.name })));
|
|
4938
5075
|
return objectPath;
|
|
4939
5076
|
}
|
|
5077
|
+
function separatedFolders(objects) {
|
|
5078
|
+
const childrenOf = (entries) => {
|
|
5079
|
+
const children = new Map;
|
|
5080
|
+
for (const [parent, name] of entries) {
|
|
5081
|
+
const names = children.get(parent) ?? new Set;
|
|
5082
|
+
names.add(name.toLowerCase());
|
|
5083
|
+
children.set(parent, names);
|
|
5084
|
+
}
|
|
5085
|
+
return (parent) => children.get(parent) ?? new Set;
|
|
5086
|
+
};
|
|
5087
|
+
const objectsIn = childrenOf(objects.map(({ folders, name }) => [folders.join("/"), name]));
|
|
5088
|
+
const foldersIn = childrenOf(objects.flatMap(({ folders }) => folders.map((name, depth) => [folders.slice(0, depth).join("/"), name])));
|
|
5089
|
+
const renamed = new Map;
|
|
5090
|
+
const given = new Map;
|
|
5091
|
+
const folderPath = (folders) => {
|
|
5092
|
+
const key = folders.join("/");
|
|
5093
|
+
const known = renamed.get(key);
|
|
5094
|
+
if (known !== undefined) {
|
|
5095
|
+
return known;
|
|
5096
|
+
}
|
|
5097
|
+
if (folders.length === 0) {
|
|
5098
|
+
return "";
|
|
5099
|
+
}
|
|
5100
|
+
const parentKey = folders.slice(0, -1).join("/");
|
|
5101
|
+
const name = required2(folders.at(-1));
|
|
5102
|
+
const taken = given.get(parentKey) ?? new Set;
|
|
5103
|
+
given.set(parentKey, taken);
|
|
5104
|
+
const blocked = (candidate) => objectsIn(parentKey).has(candidate.toLowerCase()) || taken.has(candidate.toLowerCase()) || candidate !== name && foldersIn(parentKey).has(candidate.toLowerCase());
|
|
5105
|
+
const free = (count) => blocked(`${name}_${count}`) ? free(count + 1) : `${name}_${count}`;
|
|
5106
|
+
const chosen = blocked(name) ? free(2) : name;
|
|
5107
|
+
taken.add(chosen.toLowerCase());
|
|
5108
|
+
const path = [folderPath(folders.slice(0, -1)), chosen].filter(Boolean).join("/");
|
|
5109
|
+
renamed.set(key, path);
|
|
5110
|
+
return path;
|
|
5111
|
+
};
|
|
5112
|
+
return folderPath;
|
|
5113
|
+
}
|
|
4940
5114
|
|
|
4941
5115
|
// packages/compiler/src/codesys/emit.ts
|
|
4942
5116
|
function emitCodesys(plan) {
|
|
@@ -4977,7 +5151,8 @@ function emitCodesys(plan) {
|
|
|
4977
5151
|
}
|
|
4978
5152
|
objects.push(...symbols.numeric.objects);
|
|
4979
5153
|
allocateBlockFields(symbols, instrumentation, plan, objects);
|
|
4980
|
-
|
|
5154
|
+
const telemetry = emitTelemetry(plan, symbols, instrumentation, network?.name);
|
|
5155
|
+
objects.push(...telemetry.objects);
|
|
4981
5156
|
const routines = [
|
|
4982
5157
|
...core.functions,
|
|
4983
5158
|
...core.blocks.filter((block) => !block.standard)
|
|
@@ -4985,7 +5160,7 @@ function emitCodesys(plan) {
|
|
|
4985
5160
|
for (const fn of routines) {
|
|
4986
5161
|
allocateRoutineScope(symbols, instrumentation, objects, fn);
|
|
4987
5162
|
}
|
|
4988
|
-
const rpcChannels = [];
|
|
5163
|
+
const rpcChannels = [...telemetry.rpcChannels];
|
|
4989
5164
|
for (const fn of routines) {
|
|
4990
5165
|
if ("inputs" in fn && (fn.runtime?.kind === "http" || fn.runtime?.kind === "rpc")) {
|
|
4991
5166
|
const service = emitServiceBlock(context, network?.name, fn);
|
|
@@ -5106,5 +5281,5 @@ export {
|
|
|
5106
5281
|
publicationSelectors
|
|
5107
5282
|
};
|
|
5108
5283
|
|
|
5109
|
-
//# debugId=
|
|
5284
|
+
//# debugId=9F4012D381E173F564756E2164756E21
|
|
5110
5285
|
//# sourceMappingURL=codesys.js.map
|