@tsplc/compiler 0.3.0 → 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.
- package/dist/codesys.js +48 -26
- package/dist/codesys.js.map +5 -5
- package/dist/elaborate-capture.js +22 -3
- package/dist/elaborate-capture.js.map +4 -4
- package/dist/index.js +489 -355
- package/dist/index.js.map +9 -8
- package/dist/retain.js +8 -0
- package/dist/retain.js.map +10 -0
- package/package.json +14 -9
- package/src/codesys/global-lists.ts +18 -16
- package/src/codesys/global-names.ts +3 -3
- package/src/codesys/storage.ts +44 -9
- package/src/frontend/elaborate/capture-protocol.ts +5 -0
- package/src/frontend/elaborate/capture.ts +22 -1
- package/src/frontend/elaborate/expressions.ts +4 -2
- package/src/frontend/elaborate/index.ts +29 -4
- package/src/frontend/elaborate/retention.ts +206 -0
- package/src/frontend/elaborate/storage.ts +1 -1
- package/stdlib/retain.ts +2 -0
- package/types/retain.d.ts +6 -0
package/dist/codesys.js
CHANGED
|
@@ -155,6 +155,11 @@ import {
|
|
|
155
155
|
} from "@tsplc/compiler/ir";
|
|
156
156
|
var moduleFile = (variable) => variable.id.slice(0, variable.id.indexOf(":"));
|
|
157
157
|
var moduleName = (variable) => basename(moduleFile(variable)).replace(/\.[^.]+$/, "");
|
|
158
|
+
var sectionOrder = [
|
|
159
|
+
"constants",
|
|
160
|
+
"state",
|
|
161
|
+
"retained"
|
|
162
|
+
];
|
|
158
163
|
var globalStorage = (variable, retainedVariables) => {
|
|
159
164
|
if (variable.storage === "constant") {
|
|
160
165
|
return "constants";
|
|
@@ -192,18 +197,33 @@ function storageLayout(core) {
|
|
|
192
197
|
continue;
|
|
193
198
|
}
|
|
194
199
|
const storage = globalStorage(variable, retainedVariables);
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
+
const kind = storage === "constants" ? "constants" : "state";
|
|
201
|
+
const id = `${moduleFile(variable)}:${kind}`;
|
|
202
|
+
const group = groups.get(id) ?? {
|
|
203
|
+
id,
|
|
204
|
+
module: moduleName(variable),
|
|
205
|
+
kind,
|
|
206
|
+
sections: []
|
|
207
|
+
};
|
|
208
|
+
groups.set(id, group);
|
|
209
|
+
const section = group.sections.find((item) => item.storage === storage);
|
|
210
|
+
if (section) {
|
|
211
|
+
section.variables.push(variable);
|
|
212
|
+
} else {
|
|
213
|
+
group.sections.push({ storage, variables: [variable] });
|
|
200
214
|
}
|
|
201
|
-
group.variables.push(variable);
|
|
202
215
|
}
|
|
203
216
|
return {
|
|
204
217
|
retainedBlocks,
|
|
205
218
|
retainedVariables,
|
|
206
|
-
globalLists: [...groups.values()]
|
|
219
|
+
globalLists: [...groups.values()].map((group) => {
|
|
220
|
+
const sections = sectionOrder.flatMap((storage) => group.sections.filter((section) => section.storage === storage));
|
|
221
|
+
return {
|
|
222
|
+
...group,
|
|
223
|
+
sections,
|
|
224
|
+
variables: sections.flatMap((section) => section.variables)
|
|
225
|
+
};
|
|
226
|
+
})
|
|
207
227
|
};
|
|
208
228
|
}
|
|
209
229
|
|
|
@@ -872,8 +892,8 @@ var planGlobalNames = (core, programNames = {}) => {
|
|
|
872
892
|
const { globalLists, retainedVariables } = storageLayout(core);
|
|
873
893
|
const hasExports = (group) => group.variables.some((variable) => variable.exported && !variable.exposure);
|
|
874
894
|
const globals = globalLists.map((group) => {
|
|
875
|
-
const splitByStorage = globalLists.some((other) => other.module === group.module && other.
|
|
876
|
-
const name = hasExports(group) ? names.allocate(pascalCase(splitByStorage ? `${group.module}-${group.
|
|
895
|
+
const splitByStorage = globalLists.some((other) => other.module === group.module && other.kind !== group.kind && hasExports(other));
|
|
896
|
+
const name = hasExports(group) ? names.allocate(pascalCase(splitByStorage ? `${group.module}-${group.kind}` : group.module)) : names.allocateObject("GVL", `${group.module}_${group.kind}`);
|
|
877
897
|
const fields = new Names;
|
|
878
898
|
for (const name of blockNames.values()) {
|
|
879
899
|
fields.reserve(name);
|
|
@@ -1270,24 +1290,26 @@ function emitGlobalLists(plan, symbols) {
|
|
|
1270
1290
|
const publish = group.variables.some((variable) => published.has(variable.id));
|
|
1271
1291
|
const lines = [
|
|
1272
1292
|
...publish ? ["{attribute 'linkalways'}"] : [],
|
|
1273
|
-
"{attribute 'qualified_only'}"
|
|
1274
|
-
globalSections[group.storage]
|
|
1293
|
+
"{attribute 'qualified_only'}"
|
|
1275
1294
|
];
|
|
1276
|
-
for (const
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1295
|
+
for (const section of group.sections) {
|
|
1296
|
+
lines.push(globalSections[section.storage]);
|
|
1297
|
+
for (const item of section.variables) {
|
|
1298
|
+
const field = required2(fields.get(item.id));
|
|
1299
|
+
references.set(item.id, `${name}.${field}`);
|
|
1300
|
+
if (published.has(item.id)) {
|
|
1301
|
+
lines.push(` {attribute 'symbol' := '${item.exposure ? "read" : "readwrite"}'}`);
|
|
1302
|
+
}
|
|
1303
|
+
mappings.push({
|
|
1304
|
+
path: `${name}.st`,
|
|
1305
|
+
line: lines.length + 1,
|
|
1306
|
+
span: item.span
|
|
1307
|
+
});
|
|
1308
|
+
const initial = globalInitializer(symbols, section.storage, item);
|
|
1309
|
+
lines.push(` ${field} : ${targetTypes.name(item.type)}${initial};`);
|
|
1281
1310
|
}
|
|
1282
|
-
|
|
1283
|
-
path: `${name}.st`,
|
|
1284
|
-
line: lines.length + 1,
|
|
1285
|
-
span: item.span
|
|
1286
|
-
});
|
|
1287
|
-
const initial = globalInitializer(symbols, group.storage, item);
|
|
1288
|
-
lines.push(` ${field} : ${targetTypes.name(item.type)}${initial};`);
|
|
1311
|
+
lines.push("END_VAR");
|
|
1289
1312
|
}
|
|
1290
|
-
lines.push("END_VAR");
|
|
1291
1313
|
objects.push({
|
|
1292
1314
|
id: group.id,
|
|
1293
1315
|
kind: "globalList",
|
|
@@ -2503,7 +2525,7 @@ import {
|
|
|
2503
2525
|
} from "@tsplc/compiler/ir";
|
|
2504
2526
|
import { serviceOfPath } from "@tsplc/server";
|
|
2505
2527
|
// packages/compiler/package.json
|
|
2506
|
-
var version = "0.
|
|
2528
|
+
var version = "0.4.0";
|
|
2507
2529
|
|
|
2508
2530
|
// packages/compiler/src/codesys/sources.ts
|
|
2509
2531
|
import { existsSync, readFileSync } from "node:fs";
|
|
@@ -4992,5 +5014,5 @@ export {
|
|
|
4992
5014
|
publicationSelectors
|
|
4993
5015
|
};
|
|
4994
5016
|
|
|
4995
|
-
//# debugId=
|
|
5017
|
+
//# debugId=CDE3110BCF012FF964756E2164756E21
|
|
4996
5018
|
//# sourceMappingURL=codesys.js.map
|