@tsplc/compiler 0.5.6 → 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 +139 -30
- package/dist/bun-runtime.js.map +8 -7
- package/dist/cli.js +8 -5
- package/dist/cli.js.map +3 -3
- package/dist/codesys.js +216 -85
- package/dist/codesys.js.map +8 -8
- package/dist/project.js +8 -5
- package/dist/project.js.map +3 -3
- package/package.json +9 -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/routines.ts +39 -9
- package/src/codesys/st-files.ts +73 -6
- package/src/codesys/telemetry.ts +70 -35
- 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/dist/codesys.js
CHANGED
|
@@ -1652,15 +1652,51 @@ SkipWhitespace();
|
|
|
1652
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;`;
|
|
1653
1653
|
return { port, requestCode, decodeResponse, inputs, outputs };
|
|
1654
1654
|
};
|
|
1655
|
-
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
|
+
}) => {
|
|
1656
1693
|
const channel = (field, index = "slotIndex") => `${rpcGlobal}.${field}[${index}]`;
|
|
1657
1694
|
return {
|
|
1658
|
-
id
|
|
1695
|
+
id,
|
|
1659
1696
|
kind: "functionBlock",
|
|
1660
1697
|
name,
|
|
1661
1698
|
declaration: `FUNCTION_BLOCK ${name}
|
|
1662
|
-
|
|
1663
|
-
VAR_OUTPUT ${outputs} END_VAR
|
|
1699
|
+
${ports}
|
|
1664
1700
|
VAR
|
|
1665
1701
|
timeout:TON;stage:UINT;slotIndex:UINT;candidate:UINT;
|
|
1666
1702
|
identity:STRING(64);epoch:STRING(32);prefix:STRING(80);
|
|
@@ -1686,7 +1722,7 @@ IF stage=0 THEN
|
|
|
1686
1722
|
ELSE
|
|
1687
1723
|
epoch:=${channel("epochs")};identity:=CONCAT(CONCAT(epoch,':'),UDINT_TO_STRING(${channel("sequence")}));
|
|
1688
1724
|
prefix:=CONCAT(identity,'|');payload:='';malformed:=FALSE;
|
|
1689
|
-
|
|
1725
|
+
${body}
|
|
1690
1726
|
IF malformed THEN ${port("error")}:=${jobError.tooLarge};stage:=90;
|
|
1691
1727
|
ELSIF ByteLength(payload)+LEN(prefix)>${plcBufferBytes} THEN ${port("error")}:=${jobError.tooLarge};stage:=90;
|
|
1692
1728
|
ELSE
|
|
@@ -1697,18 +1733,20 @@ IF stage=0 THEN
|
|
|
1697
1733
|
END_IF;
|
|
1698
1734
|
END_IF;
|
|
1699
1735
|
END_IF;
|
|
1700
|
-
timeout(IN:=stage<90,PT:=T#${
|
|
1736
|
+
timeout(IN:=stage<90,PT:=T#${timeoutMs}ms);
|
|
1701
1737
|
IF timeout.Q THEN ${port("error")}:=${jobError.timeout};stage:=90;END_IF;
|
|
1702
1738
|
IF stage=1 THEN
|
|
1703
1739
|
IF ${channel("epochs")}<>epoch THEN ${port("error")}:=${jobError.network};stage:=90;
|
|
1704
1740
|
ELSIF ${channel("replyIds")}=identity AND_THEN LEFT(${channel("replies")},LEN(prefix))=prefix THEN
|
|
1705
1741
|
payload:='';cursor:=LEN(prefix);
|
|
1706
1742
|
IF ByteLength(${channel("replies")})<cursor+4 THEN ${port("error")}:=${jobError.malformedResponse};
|
|
1707
|
-
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};
|
|
1708
1746
|
ELSE
|
|
1709
1747
|
FOR candidate:=cursor+2 TO ByteLength(${channel("replies")})-1 DO payload[candidate-cursor-2]:=${channel("replies")}[candidate];END_FOR;
|
|
1710
1748
|
payload[ByteLength(${channel("replies")})-cursor-2]:=0;
|
|
1711
|
-
${
|
|
1749
|
+
${decode}
|
|
1712
1750
|
END_IF;
|
|
1713
1751
|
stage:=90;
|
|
1714
1752
|
END_IF;
|
|
@@ -2065,43 +2103,42 @@ IF digits=0 THEN malformed:=TRUE;END_IF;IF negative THEN numberValue:=-numberVal
|
|
|
2065
2103
|
].filter((item) => transport === "http" || !["AppendWire", "FindHeaders", "ReadHeaders"].includes(item.name));
|
|
2066
2104
|
};
|
|
2067
2105
|
function emitServiceBlock({ plan, symbols, instrumentation }, networkName, fn) {
|
|
2068
|
-
const objects = [];
|
|
2069
|
-
const rpcChannels = [];
|
|
2070
2106
|
const endpoint = required2(plan.http[fn.id]);
|
|
2071
|
-
const rpcGlobal = endpoint.transport === "opcua" ? symbols.names.allocateObject("GVL", `TsplcRpc_${required2(symbols.blockNames.get(fn.id))}`) : undefined;
|
|
2072
|
-
if (rpcGlobal) {
|
|
2073
|
-
objects.push({
|
|
2074
|
-
id: `${fn.id}:rpc`,
|
|
2075
|
-
kind: "globalList",
|
|
2076
|
-
name: rpcGlobal,
|
|
2077
|
-
declaration: `{attribute 'qualified_only'}
|
|
2078
|
-
VAR_GLOBAL
|
|
2079
|
-
{attribute 'symbol' := 'read'} requests:ARRAY[1..${opcuaServiceCapacity}] OF STRING(${plcBufferBytes});
|
|
2080
|
-
{attribute 'symbol' := 'read'} requestIds:ARRAY[1..${opcuaServiceCapacity}] OF STRING(64);
|
|
2081
|
-
{attribute 'symbol' := 'readwrite'} replyIds:ARRAY[1..${opcuaServiceCapacity}] OF STRING(64);
|
|
2082
|
-
{attribute 'symbol' := 'readwrite'} replies:ARRAY[1..${opcuaServiceCapacity}] OF STRING(${plcBufferBytes});
|
|
2083
|
-
{attribute 'symbol' := 'readwrite'} epochs:ARRAY[1..${opcuaServiceCapacity}] OF STRING(32);
|
|
2084
|
-
inUse:ARRAY[1..${opcuaServiceCapacity}] OF __XWORD;
|
|
2085
|
-
sequence:ARRAY[1..${opcuaServiceCapacity}] OF UDINT;
|
|
2086
|
-
END_VAR`
|
|
2087
|
-
});
|
|
2088
|
-
for (let slot = 1;slot <= opcuaServiceCapacity; slot++) {
|
|
2089
|
-
rpcChannels.push({
|
|
2090
|
-
path: endpoint.path,
|
|
2091
|
-
request: `${rpcGlobal}.requests[${slot}]`,
|
|
2092
|
-
reply: `${rpcGlobal}.replies[${slot}]`,
|
|
2093
|
-
requestId: `${rpcGlobal}.requestIds[${slot}]`,
|
|
2094
|
-
replyId: `${rpcGlobal}.replyIds[${slot}]`,
|
|
2095
|
-
epoch: `${rpcGlobal}.epochs[${slot}]`
|
|
2096
|
-
});
|
|
2097
|
-
}
|
|
2098
|
-
}
|
|
2099
2107
|
const name = required2(symbols.blockNames.get(fn.id));
|
|
2100
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
|
+
}
|
|
2101
2134
|
const requestFields = instrumentation.fields.get(fn.id);
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
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
|
+
};
|
|
2105
2142
|
}
|
|
2106
2143
|
function httpNetwork(plan, symbols) {
|
|
2107
2144
|
if (!Object.values(plan.http).some((endpoint) => endpoint.transport !== "opcua")) {
|
|
@@ -2639,7 +2676,7 @@ import {
|
|
|
2639
2676
|
} from "@tsplc/compiler/ir";
|
|
2640
2677
|
import { serviceOfPath } from "@tsplc/server";
|
|
2641
2678
|
// packages/compiler/package.json
|
|
2642
|
-
var version = "0.5.
|
|
2679
|
+
var version = "0.5.7";
|
|
2643
2680
|
|
|
2644
2681
|
// packages/compiler/src/codesys/sources.ts
|
|
2645
2682
|
import { existsSync, readFileSync } from "node:fs";
|
|
@@ -2917,9 +2954,27 @@ function planTelemetry(core, deployment, options, project, report) {
|
|
|
2917
2954
|
}
|
|
2918
2955
|
const server = project.server;
|
|
2919
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
|
+
};
|
|
2920
2964
|
if (server?.transport === "opcua") {
|
|
2921
|
-
|
|
2922
|
-
|
|
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
|
+
};
|
|
2923
2978
|
}
|
|
2924
2979
|
if (!base) {
|
|
2925
2980
|
report(`Telemetry posts to the app server: set server.baseUrlEnv and that environment variable to its base URL.`);
|
|
@@ -2927,13 +2982,7 @@ function planTelemetry(core, deployment, options, project, report) {
|
|
|
2927
2982
|
}
|
|
2928
2983
|
try {
|
|
2929
2984
|
return {
|
|
2930
|
-
telemetry:
|
|
2931
|
-
...settings,
|
|
2932
|
-
capacity: Math.max(settings.capacity, project.trace ? project.trace.capacity : 0),
|
|
2933
|
-
calls,
|
|
2934
|
-
failures,
|
|
2935
|
-
...project.trace && { traceOperands: project.trace.operands }
|
|
2936
|
-
},
|
|
2985
|
+
telemetry: plan,
|
|
2937
2986
|
endpoint: resolveHttpEndpoint(`${base.replace(/\/+$/, "")}${telemetryPath}`, options.http, project.environment)
|
|
2938
2987
|
};
|
|
2939
2988
|
} catch (cause) {
|
|
@@ -2976,8 +3025,7 @@ function telemetryObjects({
|
|
|
2976
3025
|
plan,
|
|
2977
3026
|
names,
|
|
2978
3027
|
target,
|
|
2979
|
-
|
|
2980
|
-
network,
|
|
3028
|
+
transport,
|
|
2981
3029
|
build,
|
|
2982
3030
|
types
|
|
2983
3031
|
}) {
|
|
@@ -3091,10 +3139,7 @@ ${instances.length ? ` instance : STRING(${maximum(instances)});
|
|
|
3091
3139
|
];
|
|
3092
3140
|
const { start, rest } = header(build);
|
|
3093
3141
|
const helpers = httpMethods(writer).filter((item) => ["ByteLength", "Append", "WriteString"].includes(item.name));
|
|
3094
|
-
const
|
|
3095
|
-
id: telemetryClient,
|
|
3096
|
-
name: names.client,
|
|
3097
|
-
ports: `VAR_INPUT
|
|
3142
|
+
const clientPorts = `VAR_INPUT
|
|
3098
3143
|
start : BOOL;
|
|
3099
3144
|
cancel : BOOL;
|
|
3100
3145
|
END_VAR
|
|
@@ -3105,15 +3150,35 @@ VAR_OUTPUT
|
|
|
3105
3150
|
busy : BOOL;
|
|
3106
3151
|
done : BOOL;
|
|
3107
3152
|
error : UDINT;
|
|
3108
|
-
END_VAR
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
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
|
+
];
|
|
3117
3182
|
return [
|
|
3118
3183
|
{
|
|
3119
3184
|
id: "tsplc:telemetryRecord",
|
|
@@ -3251,10 +3316,7 @@ WriteString(text);
|
|
|
3251
3316
|
...calls,
|
|
3252
3317
|
...failures,
|
|
3253
3318
|
...trace,
|
|
3254
|
-
|
|
3255
|
-
...clientLifecycle,
|
|
3256
|
-
...httpMethods(telemetryClient),
|
|
3257
|
-
...httpCertificateVerifier(telemetryClient, names.client, endpoint)
|
|
3319
|
+
...clientObjects
|
|
3258
3320
|
];
|
|
3259
3321
|
}
|
|
3260
3322
|
|
|
@@ -3747,7 +3809,7 @@ function planInstrumentation(plan, symbols) {
|
|
|
3747
3809
|
const telemetryNames = rings.size ? {
|
|
3748
3810
|
writer: symbols.names.allocateObject("FB", "TsplcTelemetry"),
|
|
3749
3811
|
record: symbols.names.allocateObject("ST", "TsplcRecord"),
|
|
3750
|
-
client: symbols.names.allocateObject("FB", "TsplcTelemetryHttp")
|
|
3812
|
+
client: symbols.names.allocateObject("FB", plan.http[telemetryClient]?.transport === "opcua" ? "TsplcTelemetryOpcUa" : "TsplcTelemetryHttp")
|
|
3751
3813
|
} : undefined;
|
|
3752
3814
|
const jobs = core.blocks.filter((block) => block.job).flatMap((block) => analysis.instances.get(block.id).map((path) => ({ block, path })));
|
|
3753
3815
|
const jobIds = new Map;
|
|
@@ -3787,17 +3849,27 @@ function emitTelemetry(plan, symbols, instrumentation, networkName) {
|
|
|
3787
3849
|
const { telemetry } = plan;
|
|
3788
3850
|
const names = instrumentation.telemetryNames;
|
|
3789
3851
|
if (!telemetry || !names) {
|
|
3790
|
-
return [];
|
|
3852
|
+
return { objects: [], rpcChannels: [] };
|
|
3791
3853
|
}
|
|
3792
|
-
|
|
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({
|
|
3793
3857
|
plan: telemetry,
|
|
3794
3858
|
names,
|
|
3795
3859
|
target: symbols.targetTypes,
|
|
3796
|
-
|
|
3797
|
-
|
|
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
|
+
},
|
|
3798
3869
|
build: buildPlaceholder,
|
|
3799
3870
|
types: symbols.typeMap
|
|
3800
3871
|
});
|
|
3872
|
+
return slots ? { objects: [slots.list, ...objects], rpcChannels: slots.channels } : { objects, rpcChannels: [] };
|
|
3801
3873
|
}
|
|
3802
3874
|
function emitDebugGlobal(plan, instrumentation, objects, manifest) {
|
|
3803
3875
|
const hash = createHash("sha256");
|
|
@@ -4609,6 +4681,13 @@ function emitRoutine(context, fn) {
|
|
|
4609
4681
|
write(`${destination} := ${targetTypes.literal(value, id)};`, depth, span);
|
|
4610
4682
|
}
|
|
4611
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
|
+
};
|
|
4612
4691
|
const tracked = block && instrumentation.fields.get(block.id);
|
|
4613
4692
|
const body = (items, depth) => {
|
|
4614
4693
|
for (const item of items) {
|
|
@@ -4744,18 +4823,27 @@ function emitRoutine(context, fn) {
|
|
|
4744
4823
|
case "return":
|
|
4745
4824
|
writeProbes(probes, write, item, depth);
|
|
4746
4825
|
if (block) {
|
|
4747
|
-
|
|
4748
|
-
|
|
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);
|
|
4749
4833
|
for (const output of block.outputs) {
|
|
4750
4834
|
write(`${storageName(storage, output.id)} := ${returned}.${targetTypes.field(required2(block.result), output.name)};`, depth, item.span);
|
|
4751
4835
|
}
|
|
4752
4836
|
}
|
|
4753
4837
|
} else if (program) {
|
|
4754
4838
|
if (item.value) {
|
|
4755
|
-
|
|
4839
|
+
assignResult(required2(symbols.programResults.get(fn.id)), item.value, depth, item.span);
|
|
4756
4840
|
}
|
|
4757
4841
|
} else if (!method || fn.result) {
|
|
4758
|
-
|
|
4842
|
+
if (item.value) {
|
|
4843
|
+
assignResult(name, item.value, depth, item.span);
|
|
4844
|
+
} else {
|
|
4845
|
+
write(`${name} := TRUE;`, depth, item.span);
|
|
4846
|
+
}
|
|
4759
4847
|
}
|
|
4760
4848
|
if (mutex) {
|
|
4761
4849
|
release(mutex, depth, item.span);
|
|
@@ -4972,15 +5060,57 @@ function objectPaths(plan, symbols, objects) {
|
|
|
4972
5060
|
const owner = required2(block === undefined ? undefined : byId.get(block)?.item);
|
|
4973
5061
|
return `${objectPath(owner)}/methods/${object.name}`;
|
|
4974
5062
|
}
|
|
5063
|
+
const folders = required2(placed.get(object));
|
|
5064
|
+
return [folderPath(folders), object.name].filter(Boolean).join("/");
|
|
5065
|
+
};
|
|
5066
|
+
const placedFolders = (object) => {
|
|
4975
5067
|
const folders = sourceFolders(plan.project.root, sourceModule(object));
|
|
4976
5068
|
if (!folders) {
|
|
4977
|
-
return
|
|
5069
|
+
return [generatedFolder(object)];
|
|
4978
5070
|
}
|
|
4979
|
-
|
|
4980
|
-
return [...kept, object.name].join("/");
|
|
5071
|
+
return object.kind !== "dataType" && folders.at(-1) === object.name ? folders.slice(0, -1) : folders;
|
|
4981
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 })));
|
|
4982
5075
|
return objectPath;
|
|
4983
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
|
+
}
|
|
4984
5114
|
|
|
4985
5115
|
// packages/compiler/src/codesys/emit.ts
|
|
4986
5116
|
function emitCodesys(plan) {
|
|
@@ -5021,7 +5151,8 @@ function emitCodesys(plan) {
|
|
|
5021
5151
|
}
|
|
5022
5152
|
objects.push(...symbols.numeric.objects);
|
|
5023
5153
|
allocateBlockFields(symbols, instrumentation, plan, objects);
|
|
5024
|
-
|
|
5154
|
+
const telemetry = emitTelemetry(plan, symbols, instrumentation, network?.name);
|
|
5155
|
+
objects.push(...telemetry.objects);
|
|
5025
5156
|
const routines = [
|
|
5026
5157
|
...core.functions,
|
|
5027
5158
|
...core.blocks.filter((block) => !block.standard)
|
|
@@ -5029,7 +5160,7 @@ function emitCodesys(plan) {
|
|
|
5029
5160
|
for (const fn of routines) {
|
|
5030
5161
|
allocateRoutineScope(symbols, instrumentation, objects, fn);
|
|
5031
5162
|
}
|
|
5032
|
-
const rpcChannels = [];
|
|
5163
|
+
const rpcChannels = [...telemetry.rpcChannels];
|
|
5033
5164
|
for (const fn of routines) {
|
|
5034
5165
|
if ("inputs" in fn && (fn.runtime?.kind === "http" || fn.runtime?.kind === "rpc")) {
|
|
5035
5166
|
const service = emitServiceBlock(context, network?.name, fn);
|
|
@@ -5150,5 +5281,5 @@ export {
|
|
|
5150
5281
|
publicationSelectors
|
|
5151
5282
|
};
|
|
5152
5283
|
|
|
5153
|
-
//# debugId=
|
|
5284
|
+
//# debugId=9F4012D381E173F564756E2164756E21
|
|
5154
5285
|
//# sourceMappingURL=codesys.js.map
|