@tsplc/compiler 0.2.0 → 0.2.2
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/index.js +18 -11
- package/dist/index.js.map +3 -3
- package/package.json +6 -6
- package/src/frontend/elaborate/specialize.ts +28 -15
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"url": "git+https://github.com/livingforjesus/tsplc.git",
|
|
18
18
|
"directory": "packages/compiler"
|
|
19
19
|
},
|
|
20
|
-
"version": "0.2.
|
|
20
|
+
"version": "0.2.2",
|
|
21
21
|
"type": "module",
|
|
22
22
|
"exports": {
|
|
23
23
|
".": {
|
|
@@ -90,14 +90,14 @@
|
|
|
90
90
|
"bun": ">=1.4.3"
|
|
91
91
|
},
|
|
92
92
|
"dependencies": {
|
|
93
|
-
"@tsplc/agent": "0.2.
|
|
94
|
-
"@tsplc/build": "0.2.
|
|
95
|
-
"@tsplc/config": "0.2.
|
|
96
|
-
"@tsplc/typegen": "0.2.
|
|
93
|
+
"@tsplc/agent": "0.2.2",
|
|
94
|
+
"@tsplc/build": "0.2.2",
|
|
95
|
+
"@tsplc/config": "0.2.2",
|
|
96
|
+
"@tsplc/typegen": "0.2.2",
|
|
97
97
|
"typescript": "6.0.3",
|
|
98
98
|
"zod": "4.3.6",
|
|
99
99
|
"@types/bun": "1.4.2",
|
|
100
|
-
"@tsplc/server": "0.2.
|
|
100
|
+
"@tsplc/server": "0.2.2"
|
|
101
101
|
},
|
|
102
102
|
"bin": {
|
|
103
103
|
"tsplc": "./dist/cli.js"
|
|
@@ -27,6 +27,8 @@ export type Value =
|
|
|
27
27
|
declared?: ts.Type;
|
|
28
28
|
place?: boolean;
|
|
29
29
|
iec?: string;
|
|
30
|
+
/** For an array place, the IEC width its declaration gives its elements, as `Array<BYTE>` does. */
|
|
31
|
+
elementIec?: string;
|
|
30
32
|
/** A module global another module stores into through its setter; an import is read-only. */
|
|
31
33
|
setter?: string;
|
|
32
34
|
};
|
|
@@ -1309,24 +1311,20 @@ export class Specializer {
|
|
|
1309
1311
|
return this.capturedConstant(value, holder.type?.symbol?.valueDeclaration ?? this.sources[0]!);
|
|
1310
1312
|
}
|
|
1311
1313
|
|
|
1314
|
+
/** A captured field's declaration: a class member or a record's property. */
|
|
1315
|
+
private fieldDeclaration(holder: ModelNode, name: string): ts.Node | undefined {
|
|
1316
|
+
return holder.captured.kind === "instance"
|
|
1317
|
+
? this.model.member(this.model.classOf(holder), name)
|
|
1318
|
+
: this.fieldSymbol(holder, name)?.valueDeclaration;
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1312
1321
|
/** The IEC width a captured field's declaration names. */
|
|
1313
1322
|
private fieldIec(holder: ModelNode, name: string): string | undefined {
|
|
1314
|
-
|
|
1315
|
-
return this.layouts.iecName(this.model.member(this.model.classOf(holder), name));
|
|
1316
|
-
return this.layouts.iecName(this.fieldSymbol(holder, name)?.valueDeclaration);
|
|
1323
|
+
return this.layouts.iecName(this.fieldDeclaration(holder, name));
|
|
1317
1324
|
}
|
|
1318
1325
|
|
|
1319
|
-
/** The IEC width
|
|
1320
|
-
private elementIec(
|
|
1321
|
-
const owner = array.owner;
|
|
1322
|
-
const last = owner?.steps.at(-1);
|
|
1323
|
-
if (!owner || last?.kind !== "field") return undefined;
|
|
1324
|
-
const holder = this.at(owner.root, owner.steps.slice(0, -1));
|
|
1325
|
-
const declaration =
|
|
1326
|
-
holder &&
|
|
1327
|
-
(holder.captured.kind === "instance"
|
|
1328
|
-
? this.model.member(this.model.classOf(holder), last.name)
|
|
1329
|
-
: this.fieldSymbol(holder, last.name)?.valueDeclaration);
|
|
1326
|
+
/** The IEC width an array declaration gives its elements, as `data: Array<BYTE>` does. */
|
|
1327
|
+
private elementIec(declaration: ts.Node | undefined): string | undefined {
|
|
1330
1328
|
const node = declaration && (declaration as { type?: ts.TypeNode }).type;
|
|
1331
1329
|
const element =
|
|
1332
1330
|
node && ts.isArrayTypeNode(node)
|
|
@@ -1337,6 +1335,15 @@ export class Specializer {
|
|
|
1337
1335
|
return element ? this.layouts.iecName({ type: element } as unknown as ts.Node) : undefined;
|
|
1338
1336
|
}
|
|
1339
1337
|
|
|
1338
|
+
/** The IEC width of an array's elements, from the declaration holding the array. */
|
|
1339
|
+
private arrayElementIec(array: ModelNode): string | undefined {
|
|
1340
|
+
const owner = array.owner;
|
|
1341
|
+
const last = owner?.steps.at(-1);
|
|
1342
|
+
if (!owner || last?.kind !== "field") return undefined;
|
|
1343
|
+
const holder = this.at(owner.root, owner.steps.slice(0, -1));
|
|
1344
|
+
return holder && this.elementIec(this.fieldDeclaration(holder, last.name));
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1340
1347
|
private storedField(holder: ModelNode, step: Step): Value {
|
|
1341
1348
|
const declared =
|
|
1342
1349
|
step.kind === "index"
|
|
@@ -1356,7 +1363,12 @@ export class Specializer {
|
|
|
1356
1363
|
text: `${this.pathText(holder)}${step.kind === "index" ? `[${step.index}]` : `.${step.name}`}`,
|
|
1357
1364
|
declared,
|
|
1358
1365
|
place: true,
|
|
1359
|
-
|
|
1366
|
+
...(step.kind === "field"
|
|
1367
|
+
? {
|
|
1368
|
+
iec: this.fieldIec(holder, step.name),
|
|
1369
|
+
elementIec: this.elementIec(this.fieldDeclaration(holder, step.name)),
|
|
1370
|
+
}
|
|
1371
|
+
: { iec: this.arrayElementIec(holder) }),
|
|
1360
1372
|
...(global && { setter: `${this.pathText(holder)}.${setterName(step.name)}` }),
|
|
1361
1373
|
};
|
|
1362
1374
|
}
|
|
@@ -1509,6 +1521,7 @@ export class Specializer {
|
|
|
1509
1521
|
text: `${object.text}[${this.code(index, undefined, frame)}]`,
|
|
1510
1522
|
declared,
|
|
1511
1523
|
place: object.place,
|
|
1524
|
+
iec: object.elementIec,
|
|
1512
1525
|
};
|
|
1513
1526
|
}
|
|
1514
1527
|
if (object.kind === "virtual" && object.items) {
|