circuitscript 0.1.16 → 0.1.17
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/cjs/BaseVisitor.js +2 -1
- package/dist/cjs/draw_symbols.js +18 -17
- package/dist/cjs/execute.js +40 -20
- package/dist/cjs/globals.js +1 -0
- package/dist/cjs/graph.js +101 -27
- package/dist/cjs/layout.js +6 -1
- package/dist/cjs/objects/ClassComponent.js +27 -20
- package/dist/cjs/objects/ExecutionScope.js +7 -2
- package/dist/cjs/objects/Net.js +1 -1
- package/dist/cjs/objects/PinDefinition.js +55 -3
- package/dist/cjs/objects/types.js +16 -1
- package/dist/cjs/visitor.js +56 -18
- package/dist/esm/BaseVisitor.js +2 -1
- package/dist/esm/draw_symbols.js +18 -17
- package/dist/esm/execute.js +41 -21
- package/dist/esm/globals.js +1 -0
- package/dist/esm/graph.js +79 -28
- package/dist/esm/layout.js +6 -1
- package/dist/esm/objects/ClassComponent.js +28 -21
- package/dist/esm/objects/ExecutionScope.js +7 -2
- package/dist/esm/objects/Net.js +1 -1
- package/dist/esm/objects/PinDefinition.js +53 -2
- package/dist/esm/objects/types.js +15 -0
- package/dist/esm/visitor.js +58 -20
- package/dist/libs/std.cst +3 -2
- package/dist/types/BaseVisitor.d.ts +2 -1
- package/dist/types/draw_symbols.d.ts +13 -7
- package/dist/types/execute.d.ts +7 -7
- package/dist/types/globals.d.ts +1 -0
- package/dist/types/graph.d.ts +2 -1
- package/dist/types/layout.d.ts +2 -1
- package/dist/types/objects/ClassComponent.d.ts +8 -8
- package/dist/types/objects/ExecutionScope.d.ts +5 -4
- package/dist/types/objects/Net.d.ts +2 -2
- package/dist/types/objects/PinDefinition.d.ts +17 -2
- package/dist/types/objects/types.d.ts +15 -1
- package/libs/std.cst +3 -2
- package/package.json +2 -1
package/dist/esm/graph.js
CHANGED
|
@@ -5,7 +5,10 @@ import { milsToMM } from "./helpers.js";
|
|
|
5
5
|
import { RenderFrame, RenderComponent, applyComponentParamsToSymbol, RenderWire } from "./layout.js";
|
|
6
6
|
import { SequenceAction, FrameAction } from "./objects/ExecutionScope.js";
|
|
7
7
|
import { Frame, FixedFrameIds, FrameParamKeys } from "./objects/Frame.js";
|
|
8
|
-
import { numeric
|
|
8
|
+
import { numeric } from "./objects/ParamDefinition.js";
|
|
9
|
+
import { NetTypes, TypeProps } from "./objects/types.js";
|
|
10
|
+
import Matrix, { solve } from "ml-matrix";
|
|
11
|
+
import { getPinDefinition } from "./objects/PinDefinition.js";
|
|
9
12
|
export class NetGraph {
|
|
10
13
|
logger;
|
|
11
14
|
constructor(logger) {
|
|
@@ -73,7 +76,7 @@ export class NetGraph {
|
|
|
73
76
|
if (prevNodeType === RenderItemType.Component) {
|
|
74
77
|
const matchingItem = nets.find(([comp, pin]) => {
|
|
75
78
|
return comp.instanceName === previousNode
|
|
76
|
-
&& pin
|
|
79
|
+
&& pin.equals(previousPin);
|
|
77
80
|
});
|
|
78
81
|
if (matchingItem !== undefined) {
|
|
79
82
|
useNet = matchingItem[2];
|
|
@@ -188,21 +191,71 @@ export class NetGraph {
|
|
|
188
191
|
this.logger.add(params.join(' '));
|
|
189
192
|
}
|
|
190
193
|
generateNetGraph(nets) {
|
|
191
|
-
const
|
|
192
|
-
|
|
194
|
+
const uniqueNets = new Set(nets.map(([, , net]) => net));
|
|
195
|
+
const components = new Set(nets.map(([component, ,]) => component));
|
|
196
|
+
const tmpNets = Array.from(uniqueNets);
|
|
197
|
+
const gndNet = tmpNets.find(item => {
|
|
198
|
+
return item.toString() === '/GND';
|
|
193
199
|
});
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
200
|
+
const otherNets = tmpNets.filter(item => {
|
|
201
|
+
return item !== gndNet;
|
|
202
|
+
});
|
|
203
|
+
const netsIndexed = [];
|
|
204
|
+
if (gndNet) {
|
|
205
|
+
netsIndexed.push(gndNet);
|
|
206
|
+
}
|
|
207
|
+
netsIndexed.push(...otherNets);
|
|
208
|
+
const netsLength = netsIndexed.length;
|
|
209
|
+
const conductanceMatrix = Matrix.zeros(netsLength, netsLength);
|
|
210
|
+
components.forEach(item => {
|
|
211
|
+
if (item.typeProp === TypeProps.Resistor) {
|
|
212
|
+
const net1 = item.pinNets.get(1);
|
|
213
|
+
const net2 = item.pinNets.get(2);
|
|
214
|
+
const net1Index = netsIndexed.indexOf(net1);
|
|
215
|
+
const net2Index = netsIndexed.indexOf(net2);
|
|
216
|
+
const resistance = item.parameters.get('value');
|
|
217
|
+
const resistanceValue = resistance.toNumber();
|
|
218
|
+
const conductanceValue = 1 / resistanceValue;
|
|
219
|
+
const currentValue1 = conductanceMatrix.get(net1Index, net1Index);
|
|
220
|
+
const currentValue2 = conductanceMatrix.get(net2Index, net2Index);
|
|
221
|
+
const currentValue3 = conductanceMatrix.get(net1Index, net2Index);
|
|
222
|
+
const currentValue4 = conductanceMatrix.get(net2Index, net1Index);
|
|
223
|
+
conductanceMatrix.set(net1Index, net1Index, currentValue1 + conductanceValue);
|
|
224
|
+
conductanceMatrix.set(net2Index, net2Index, currentValue2 + conductanceValue);
|
|
225
|
+
conductanceMatrix.set(net1Index, net2Index, currentValue3 - conductanceValue);
|
|
226
|
+
conductanceMatrix.set(net2Index, net1Index, currentValue4 - conductanceValue);
|
|
203
227
|
}
|
|
204
|
-
graph.setEdge(netNodeName, componentNodeName, [component, pin, net]);
|
|
205
228
|
});
|
|
229
|
+
if (gndNet) {
|
|
230
|
+
conductanceMatrix.removeColumn(0);
|
|
231
|
+
conductanceMatrix.removeRow(0);
|
|
232
|
+
}
|
|
233
|
+
const netsWithoutGnd = netsIndexed.filter(net => {
|
|
234
|
+
return (net !== gndNet);
|
|
235
|
+
});
|
|
236
|
+
const netResistances = new Map();
|
|
237
|
+
try {
|
|
238
|
+
netsWithoutGnd.forEach((net, index) => {
|
|
239
|
+
if (net.type === NetTypes.Source) {
|
|
240
|
+
const currentVector = Matrix.zeros(netsWithoutGnd.length, 1);
|
|
241
|
+
currentVector.set(index, 0, 1);
|
|
242
|
+
const solution = solve(conductanceMatrix, currentVector);
|
|
243
|
+
for (let i = 0; i < solution.rows; i++) {
|
|
244
|
+
const resValue = solution.get(i, 0);
|
|
245
|
+
if (resValue > 0) {
|
|
246
|
+
const targetNet = netsIndexed[i];
|
|
247
|
+
netResistances.set(targetNet, resValue);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
catch (err) {
|
|
254
|
+
}
|
|
255
|
+
return {
|
|
256
|
+
nets,
|
|
257
|
+
netResistances,
|
|
258
|
+
};
|
|
206
259
|
}
|
|
207
260
|
findNodePaths(graph, startNode, endNode, seenNodes = []) {
|
|
208
261
|
const edges = graph.nodeEdges(startNode);
|
|
@@ -261,24 +314,22 @@ export function generateLayoutPinDefinition(component) {
|
|
|
261
314
|
useItems = [...items];
|
|
262
315
|
}
|
|
263
316
|
useItems.forEach(pinId => {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
addedPins.push(pinIdValue);
|
|
276
|
-
}
|
|
317
|
+
const existingPin = existingPinIds.find(pin => pin.equals(pinId));
|
|
318
|
+
if (existingPin) {
|
|
319
|
+
const pin = getPinDefinition(pins, existingPin);
|
|
320
|
+
symbolPinDefinitions.push({
|
|
321
|
+
side: key,
|
|
322
|
+
pinId: pinId,
|
|
323
|
+
text: pin.name,
|
|
324
|
+
position: pin.position,
|
|
325
|
+
pinType: pin.pinType,
|
|
326
|
+
});
|
|
327
|
+
addedPins.push(pinId);
|
|
277
328
|
}
|
|
278
329
|
});
|
|
279
330
|
}
|
|
280
331
|
const unplacedPins = existingPinIds.filter(pinId => {
|
|
281
|
-
return addedPins.
|
|
332
|
+
return addedPins.find(id => id.equals(pinId)) === undefined;
|
|
282
333
|
});
|
|
283
334
|
if (unplacedPins.length > 0) {
|
|
284
335
|
component._unplacedPins = unplacedPins;
|
package/dist/esm/layout.js
CHANGED
|
@@ -6,6 +6,7 @@ import { Geometry, HorizontalAlign, VerticalAlign } from './geometry.js';
|
|
|
6
6
|
import { FixedFrameIds, Frame, FrameParamKeys, FramePlotDirection } from './objects/Frame.js';
|
|
7
7
|
import { areasOverlap, combineMaps, getBoundsSize, printBounds, resizeBounds, resizeToNearestGrid, roundValue, toNearestGrid } from './utils.js';
|
|
8
8
|
import { Direction } from './objects/types.js';
|
|
9
|
+
import { PinId } from './objects/PinDefinition.js';
|
|
9
10
|
import { milsToMM, UnitDimension } from './helpers.js';
|
|
10
11
|
import { numeric } from './objects/ParamDefinition.js';
|
|
11
12
|
import { generateLayoutPinDefinition, getWireName, RenderItemType } from './graph.js';
|
|
@@ -689,7 +690,11 @@ export class LayoutEngine {
|
|
|
689
690
|
}
|
|
690
691
|
if (subgraphEdges.length === 0) {
|
|
691
692
|
const [, node1] = graph.node(firstNodeId);
|
|
692
|
-
|
|
693
|
+
let defaultPin = new PinId(1);
|
|
694
|
+
if (node1 instanceof RenderComponent) {
|
|
695
|
+
defaultPin = node1.component.getDefaultPin();
|
|
696
|
+
}
|
|
697
|
+
this.placeNodeAtPosition(numeric(0), numeric(0), node1, defaultPin);
|
|
693
698
|
return;
|
|
694
699
|
}
|
|
695
700
|
let fixedNode;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { SymbolDrawingCommands } from '../draw_symbols.js';
|
|
2
|
-
import { PinDefinition, PinIdType } from './PinDefinition.js';
|
|
2
|
+
import { PinDefinition, PinId, PinIdType } from './PinDefinition.js';
|
|
3
3
|
import { PinTypes } from './PinTypes.js';
|
|
4
4
|
import { ParamKeys } from '../globals.js';
|
|
5
|
+
import { RuntimeExecutionError } from '../utils.js';
|
|
5
6
|
export class ClassComponent {
|
|
6
7
|
instanceName;
|
|
7
8
|
numPins;
|
|
@@ -35,47 +36,53 @@ export class ClassComponent {
|
|
|
35
36
|
setupPins() {
|
|
36
37
|
for (let i = 1; i < this.numPins + 1; i++) {
|
|
37
38
|
const pinIndex = i;
|
|
38
|
-
this.pins.set(pinIndex, new PinDefinition(pinIndex, PinIdType.Int, pinIndex.toString(), PinTypes.Any));
|
|
39
|
+
this.pins.set(new PinId(pinIndex), new PinDefinition(pinIndex, PinIdType.Int, pinIndex.toString(), PinTypes.Any));
|
|
39
40
|
}
|
|
40
41
|
this.refreshPinsCache();
|
|
41
42
|
}
|
|
42
43
|
getDefaultPin() {
|
|
43
|
-
|
|
44
|
+
const pins = Array.from(this.pins.keys());
|
|
45
|
+
pins.sort();
|
|
46
|
+
return pins[0];
|
|
44
47
|
}
|
|
45
48
|
hasPin(pinId) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
49
|
+
for (const [pin, pinDef] of this.pins) {
|
|
50
|
+
if (pin.equals(pinId)) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
if (pinId.getType() === PinIdType.Str && (pinDef.name === pinId.getValue() ||
|
|
54
|
+
pinDef.altNames.indexOf(pinId.getValue()) !== -1)) {
|
|
55
|
+
return true;
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
return false;
|
|
58
59
|
}
|
|
59
60
|
getPin(pinId) {
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
for (const [pin,] of this.pins) {
|
|
62
|
+
if (pin.equals(pinId)) {
|
|
63
|
+
return pin;
|
|
64
|
+
}
|
|
62
65
|
}
|
|
63
|
-
|
|
66
|
+
if (pinId.getType() === PinIdType.Str) {
|
|
67
|
+
const pinIdStringValue = pinId.getValue();
|
|
64
68
|
for (const [pin, pinDef] of this.pins) {
|
|
65
|
-
if (pinDef.name ===
|
|
66
|
-
pinDef.altNames.indexOf(
|
|
69
|
+
if (pinDef.name === pinIdStringValue ||
|
|
70
|
+
pinDef.altNames.indexOf(pinIdStringValue) !== -1) {
|
|
67
71
|
return pin;
|
|
68
72
|
}
|
|
69
73
|
}
|
|
70
|
-
return -1;
|
|
71
74
|
}
|
|
75
|
+
throw new RuntimeExecutionError(`Could not find pin '${pinId}' on component '${this.instanceName}'`);
|
|
72
76
|
}
|
|
73
77
|
getNextPinAfter(pinIndex) {
|
|
74
|
-
|
|
75
|
-
|
|
78
|
+
const pins = Array.from(this.pins.keys());
|
|
79
|
+
pins.sort();
|
|
80
|
+
const index = pins.findIndex(tmp => tmp.equals(pinIndex));
|
|
81
|
+
if (index + 1 < pins.length) {
|
|
82
|
+
return pins[index + 1];
|
|
76
83
|
}
|
|
77
84
|
else {
|
|
78
|
-
return
|
|
85
|
+
return this.getDefaultPin();
|
|
79
86
|
}
|
|
80
87
|
}
|
|
81
88
|
setParam(key, value) {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Property_key_exprContext } from '../antlr/CircuitScriptParser.js';
|
|
2
|
+
import { PinId } from './PinDefinition.js';
|
|
3
|
+
import { RuntimeExecutionError } from '../utils.js';
|
|
2
4
|
export class ExecutionScope {
|
|
3
5
|
scopeId;
|
|
4
6
|
nets = [];
|
|
@@ -32,8 +34,11 @@ export class ExecutionScope {
|
|
|
32
34
|
return scope;
|
|
33
35
|
}
|
|
34
36
|
findNet(component, pin) {
|
|
37
|
+
if (!(pin instanceof PinId)) {
|
|
38
|
+
throw new RuntimeExecutionError('Invalid value for PinId: ' + pin);
|
|
39
|
+
}
|
|
35
40
|
return this.nets.find(([tmpComponent, tmpPin]) => {
|
|
36
|
-
return tmpComponent.isEqual(component) && tmpPin
|
|
41
|
+
return tmpComponent.isEqual(component) && tmpPin.equals(pin);
|
|
37
42
|
});
|
|
38
43
|
}
|
|
39
44
|
getNetWithName(name) {
|
|
@@ -94,7 +99,7 @@ export class ExecutionScope {
|
|
|
94
99
|
}
|
|
95
100
|
});
|
|
96
101
|
return sortedNet.map(([component, pin, net]) => {
|
|
97
|
-
return [net.toString(), component.instanceName, pin];
|
|
102
|
+
return [net.toString(), component.instanceName, pin.value];
|
|
98
103
|
});
|
|
99
104
|
}
|
|
100
105
|
printNets() {
|
package/dist/esm/objects/Net.js
CHANGED
|
@@ -5,7 +5,7 @@ export class Net {
|
|
|
5
5
|
priority;
|
|
6
6
|
type;
|
|
7
7
|
params = new Map();
|
|
8
|
-
constructor(namespace, name, priority = 0, type =
|
|
8
|
+
constructor(namespace, name, priority = 0, type = 'any') {
|
|
9
9
|
if (namespace.indexOf(' ') !== -1) {
|
|
10
10
|
throw "Invalid net namespace provided";
|
|
11
11
|
}
|
|
@@ -1,4 +1,47 @@
|
|
|
1
|
+
import { RuntimeExecutionError } from '../utils.js';
|
|
2
|
+
import { NumericValue } from './ParamDefinition.js';
|
|
1
3
|
import { PinTypes } from './PinTypes.js';
|
|
4
|
+
export class PinId {
|
|
5
|
+
value;
|
|
6
|
+
type;
|
|
7
|
+
constructor(value) {
|
|
8
|
+
if (typeof value !== 'string' && typeof value !== 'number') {
|
|
9
|
+
throw new RuntimeExecutionError("Invalid value for PinId: " + value);
|
|
10
|
+
}
|
|
11
|
+
this.value = value;
|
|
12
|
+
this.type = typeof value === 'number' ? PinIdType.Int : PinIdType.Str;
|
|
13
|
+
}
|
|
14
|
+
getValue() {
|
|
15
|
+
return this.value;
|
|
16
|
+
}
|
|
17
|
+
getType() {
|
|
18
|
+
return this.type;
|
|
19
|
+
}
|
|
20
|
+
isNumeric() {
|
|
21
|
+
return this.type === PinIdType.Int;
|
|
22
|
+
}
|
|
23
|
+
isString() {
|
|
24
|
+
return this.type === PinIdType.Str;
|
|
25
|
+
}
|
|
26
|
+
toString() {
|
|
27
|
+
return this.value.toString();
|
|
28
|
+
}
|
|
29
|
+
equals(other) {
|
|
30
|
+
if (other instanceof PinId) {
|
|
31
|
+
return this.value === other.value;
|
|
32
|
+
}
|
|
33
|
+
return this.value === other;
|
|
34
|
+
}
|
|
35
|
+
static from(value) {
|
|
36
|
+
if (value instanceof NumericValue) {
|
|
37
|
+
return new PinId(value.toNumber());
|
|
38
|
+
}
|
|
39
|
+
return new PinId(value);
|
|
40
|
+
}
|
|
41
|
+
static isPinIdType(value) {
|
|
42
|
+
return (typeof value === 'number' || typeof value === 'string');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
2
45
|
export class PinDefinition {
|
|
3
46
|
id;
|
|
4
47
|
idType;
|
|
@@ -8,8 +51,8 @@ export class PinDefinition {
|
|
|
8
51
|
side = PortSide.EAST;
|
|
9
52
|
position = -1;
|
|
10
53
|
constructor(id, idType, name, pinType = PinTypes.Any, altNames = []) {
|
|
11
|
-
this.id = id;
|
|
12
|
-
this.idType =
|
|
54
|
+
this.id = id instanceof PinId ? id : new PinId(id);
|
|
55
|
+
this.idType = this.id.getType();
|
|
13
56
|
this.pinType = pinType;
|
|
14
57
|
this.name = name;
|
|
15
58
|
this.altNames = altNames;
|
|
@@ -27,3 +70,11 @@ export var PortSide;
|
|
|
27
70
|
PortSide["SOUTH"] = "SOUTH";
|
|
28
71
|
PortSide["NORTH"] = "NORTH";
|
|
29
72
|
})(PortSide || (PortSide = {}));
|
|
73
|
+
export function isPinId(item) {
|
|
74
|
+
return item instanceof PinId || (typeof item === 'number' || typeof item === 'string');
|
|
75
|
+
}
|
|
76
|
+
export function getPinDefinition(map, id) {
|
|
77
|
+
const keys = Array.from(map.keys());
|
|
78
|
+
const tmpKey = keys.find(item => item.equals(id));
|
|
79
|
+
return map.get(tmpKey);
|
|
80
|
+
}
|
|
@@ -106,3 +106,18 @@ export var Direction;
|
|
|
106
106
|
Direction["Down"] = "down";
|
|
107
107
|
Direction["Up"] = "up";
|
|
108
108
|
})(Direction || (Direction = {}));
|
|
109
|
+
export var TypeProps;
|
|
110
|
+
(function (TypeProps) {
|
|
111
|
+
TypeProps["Net"] = "net";
|
|
112
|
+
TypeProps["Port"] = "port";
|
|
113
|
+
TypeProps["Graphic"] = "graphic";
|
|
114
|
+
TypeProps["Resistor"] = "res";
|
|
115
|
+
TypeProps["Capacitor"] = "cap";
|
|
116
|
+
TypeProps["Inductor"] = "ind";
|
|
117
|
+
TypeProps["Diode"] = "diode";
|
|
118
|
+
})(TypeProps || (TypeProps = {}));
|
|
119
|
+
export var NetTypes;
|
|
120
|
+
(function (NetTypes) {
|
|
121
|
+
NetTypes["Any"] = "any";
|
|
122
|
+
NetTypes["Source"] = "source";
|
|
123
|
+
})(NetTypes || (NetTypes = {}));
|
package/dist/esm/visitor.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ClassComponent } from './objects/ClassComponent.js';
|
|
2
2
|
import { NumberOperator, numeric, NumericValue, ParamDefinition } from './objects/ParamDefinition.js';
|
|
3
|
-
import { PinDefinition, PinIdType } from './objects/PinDefinition.js';
|
|
3
|
+
import { PinDefinition, PinId, PinIdType } from './objects/PinDefinition.js';
|
|
4
4
|
import { PinTypes } from './objects/PinTypes.js';
|
|
5
|
-
import { AnyReference, DeclaredReference, UndeclaredReference } from './objects/types.js';
|
|
5
|
+
import { AnyReference, DeclaredReference, TypeProps, UndeclaredReference } from './objects/types.js';
|
|
6
6
|
import { BlockTypes, ComponentTypes, Delimiter1, FrameType, GlobalDocumentName, ModuleContainsKeyword, NoNetText, ParamKeys, ReferenceTypes, SymbolPinSide, ValidPinSides, WireAutoDirection } from './globals.js';
|
|
7
7
|
import { unwrapValue } from "./utils.js";
|
|
8
8
|
import { PlaceHolderCommands, SymbolDrawingCommands } from './draw_symbols.js';
|
|
@@ -17,19 +17,23 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
17
17
|
this.setResult(ctx, [id, value]);
|
|
18
18
|
};
|
|
19
19
|
visitPin_select_expr = (ctx) => {
|
|
20
|
-
let
|
|
20
|
+
let pinId = null;
|
|
21
21
|
const ctxData = ctx.data_expr();
|
|
22
22
|
const result = this.visitResult(ctxData);
|
|
23
|
+
let pinValue;
|
|
23
24
|
if (result instanceof NumericValue) {
|
|
24
|
-
|
|
25
|
+
pinValue = result.toNumber();
|
|
25
26
|
}
|
|
26
27
|
else if (typeof result === 'string') {
|
|
27
|
-
|
|
28
|
+
pinValue = result;
|
|
28
29
|
}
|
|
29
30
|
else {
|
|
30
|
-
throw new RuntimeExecutionError("Invalid
|
|
31
|
+
throw new RuntimeExecutionError("Invalid select pin: " + result, ctx);
|
|
31
32
|
}
|
|
32
|
-
|
|
33
|
+
if (pinValue !== undefined) {
|
|
34
|
+
pinId = new PinId(pinValue);
|
|
35
|
+
}
|
|
36
|
+
this.setResult(ctx, pinId);
|
|
33
37
|
};
|
|
34
38
|
visitAdd_component_expr = (ctx) => {
|
|
35
39
|
const [component, pinValue] = this.visitResult(ctx.data_expr_with_assignment());
|
|
@@ -216,11 +220,18 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
216
220
|
}
|
|
217
221
|
}
|
|
218
222
|
else {
|
|
219
|
-
if (!(value instanceof NumericValue)) {
|
|
223
|
+
if (!(value instanceof NumericValue) && !(typeof value === 'string')) {
|
|
220
224
|
throw new RuntimeExecutionError(`Invalid numeric value for arrange.${sideKeyName}`, ctx);
|
|
221
225
|
}
|
|
222
226
|
else {
|
|
223
|
-
|
|
227
|
+
let useValue;
|
|
228
|
+
if (value instanceof NumericValue) {
|
|
229
|
+
useValue = value.toNumber();
|
|
230
|
+
}
|
|
231
|
+
else if (typeof value === 'string') {
|
|
232
|
+
useValue = value;
|
|
233
|
+
}
|
|
234
|
+
value && checkPinExistsAndNotDuplicated(useValue, ctx);
|
|
224
235
|
}
|
|
225
236
|
}
|
|
226
237
|
}
|
|
@@ -260,7 +271,6 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
260
271
|
scope.exitContext();
|
|
261
272
|
scope.popOnPropertyHandler();
|
|
262
273
|
const properties = this.getPropertyExprList(ctx.property_expr());
|
|
263
|
-
const pins = this.parseCreateComponentPins(properties.get('pins'));
|
|
264
274
|
let instanceName = this.getExecutor().getUniqueInstanceName();
|
|
265
275
|
const propParams = properties.get('params');
|
|
266
276
|
const params = this.parseCreateComponentParams(propParams);
|
|
@@ -273,11 +283,11 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
273
283
|
}
|
|
274
284
|
instanceName += `${Delimiter1}${appendValue}`;
|
|
275
285
|
}
|
|
276
|
-
const
|
|
286
|
+
const arrangeProp = properties.has('arrange') ?
|
|
277
287
|
properties.get('arrange') : null;
|
|
278
|
-
const
|
|
288
|
+
const displayProp = properties.has('display') ?
|
|
279
289
|
properties.get('display') : null;
|
|
280
|
-
const
|
|
290
|
+
const typeProp = properties.has('type') ?
|
|
281
291
|
properties.get('type') : null;
|
|
282
292
|
const copy = properties.has('copy') ?
|
|
283
293
|
properties.get('copy') : false;
|
|
@@ -289,8 +299,29 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
289
299
|
properties.get(ParamKeys.angle) : null;
|
|
290
300
|
const followWireOrientation = properties.has('followWireOrientation') ?
|
|
291
301
|
properties.get('followWireOrientation') : true;
|
|
302
|
+
let pins = [];
|
|
303
|
+
if (displayProp !== null && arrangeProp === null
|
|
304
|
+
&& typeProp !== TypeProps.Graphic) {
|
|
305
|
+
const drawCommands = displayProp.getCommands();
|
|
306
|
+
drawCommands.forEach(command => {
|
|
307
|
+
const [commandValue,] = command;
|
|
308
|
+
if (commandValue === PlaceHolderCommands.vpin
|
|
309
|
+
|| commandValue === PlaceHolderCommands.hpin
|
|
310
|
+
|| commandValue === PlaceHolderCommands.pin) {
|
|
311
|
+
const id = PinId.from(command[1][0]);
|
|
312
|
+
const pinType = id.getType();
|
|
313
|
+
const pinName = id.toString();
|
|
314
|
+
pins.push(new PinDefinition(id, pinType, pinName, PinTypes.Any));
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
pins = this.parseCreateComponentPins(properties.get('pins'));
|
|
320
|
+
}
|
|
292
321
|
const props = {
|
|
293
|
-
arrange
|
|
322
|
+
arrange: arrangeProp,
|
|
323
|
+
display: displayProp,
|
|
324
|
+
type: typeProp, width, height, copy,
|
|
294
325
|
angle, followWireOrientation
|
|
295
326
|
};
|
|
296
327
|
try {
|
|
@@ -852,14 +883,21 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
852
883
|
visitPin_select_expr2 = (ctx) => {
|
|
853
884
|
const ctxStringValue = ctx.STRING_VALUE();
|
|
854
885
|
const ctxIntegerValue = ctx.INTEGER_VALUE();
|
|
855
|
-
let
|
|
886
|
+
let pinIdValue;
|
|
887
|
+
let pinId = null;
|
|
856
888
|
if (ctxStringValue) {
|
|
857
|
-
|
|
889
|
+
pinIdValue = this.prepareStringValue(ctxStringValue.getText());
|
|
858
890
|
}
|
|
859
891
|
else if (ctxIntegerValue) {
|
|
860
|
-
|
|
892
|
+
pinIdValue = Number(ctxIntegerValue.getText());
|
|
861
893
|
}
|
|
862
|
-
|
|
894
|
+
if (pinIdValue !== undefined) {
|
|
895
|
+
pinId = new PinId(pinIdValue);
|
|
896
|
+
}
|
|
897
|
+
else {
|
|
898
|
+
throw new RuntimeExecutionError("Invalid select pin", ctx);
|
|
899
|
+
}
|
|
900
|
+
this.setResult(ctx, pinId);
|
|
863
901
|
};
|
|
864
902
|
visitAt_block_pin_expr = (ctx) => {
|
|
865
903
|
const executor = this.getExecutor();
|
|
@@ -1200,7 +1238,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
1200
1238
|
return item;
|
|
1201
1239
|
}
|
|
1202
1240
|
else {
|
|
1203
|
-
return
|
|
1241
|
+
return new PinId(nameToPinId.get(item));
|
|
1204
1242
|
}
|
|
1205
1243
|
});
|
|
1206
1244
|
if (items.length > 0) {
|
|
@@ -1291,7 +1329,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
1291
1329
|
getGraph() {
|
|
1292
1330
|
const executor = this.getExecutor();
|
|
1293
1331
|
const fullSequence = executor.scope.sequence;
|
|
1294
|
-
const tmpNet = executor.scope.getNet(executor.scope.componentRoot, 1);
|
|
1332
|
+
const tmpNet = executor.scope.getNet(executor.scope.componentRoot, new PinId(1));
|
|
1295
1333
|
const sequence = (tmpNet === null)
|
|
1296
1334
|
? fullSequence.slice(1) : fullSequence;
|
|
1297
1335
|
const nets = executor.scope.getNets();
|
package/dist/libs/std.cst
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Circuitscript default lib
|
|
2
2
|
|
|
3
|
-
def net(net_name):
|
|
3
|
+
def net(net_name, net_type = "any"):
|
|
4
4
|
return create component:
|
|
5
5
|
pins: 1
|
|
6
6
|
copy: true
|
|
@@ -13,9 +13,10 @@ def net(net_name):
|
|
|
13
13
|
params:
|
|
14
14
|
net_name: net_name
|
|
15
15
|
priority: 10
|
|
16
|
+
net_type: net_type
|
|
16
17
|
|
|
17
18
|
def supply(net_name):
|
|
18
|
-
net_obj = net(net_name)
|
|
19
|
+
net_obj = net(net_name, "source")
|
|
19
20
|
return net_obj
|
|
20
21
|
|
|
21
22
|
def label(value, anchor="left"):
|
|
@@ -10,6 +10,7 @@ import { ExecutionWarning } from "./utils.js";
|
|
|
10
10
|
import { BaseError } from './utils.js';
|
|
11
11
|
import { ExecutionScope } from './objects/ExecutionScope.js';
|
|
12
12
|
import { NodeScriptEnvironment } from "./environment.js";
|
|
13
|
+
import { PinId } from './objects/PinDefinition.js';
|
|
13
14
|
export declare class BaseVisitor extends CircuitScriptVisitor<ComplexType | AnyReference | any> {
|
|
14
15
|
indentLevel: number;
|
|
15
16
|
startingContext: ExecutionContext;
|
|
@@ -38,7 +39,7 @@ export declare class BaseVisitor extends CircuitScriptVisitor<ComplexType | AnyR
|
|
|
38
39
|
found: boolean;
|
|
39
40
|
net?: Net;
|
|
40
41
|
};
|
|
41
|
-
createComponentPinNetResolver(executionStack: ExecutionContext[]): (component: ClassComponent, pin:
|
|
42
|
+
createComponentPinNetResolver(executionStack: ExecutionContext[]): (component: ClassComponent, pin: PinId) => Net | null;
|
|
42
43
|
log(...params: any[]): void;
|
|
43
44
|
log2(message: string): void;
|
|
44
45
|
visitAsync(ctx: ParserRuleContext): Promise<void>;
|
|
@@ -4,6 +4,7 @@ import { Logger } from "./logger.js";
|
|
|
4
4
|
import { PinTypes } from "./objects/PinTypes.js";
|
|
5
5
|
import { ParserRuleContext } from "antlr4ng";
|
|
6
6
|
import { NumericValue } from "./objects/ParamDefinition.js";
|
|
7
|
+
import { PinId } from "./objects/PinDefinition.js";
|
|
7
8
|
export declare abstract class SymbolGraphic {
|
|
8
9
|
drawPortsName: boolean;
|
|
9
10
|
displayBounds: boolean;
|
|
@@ -37,7 +38,7 @@ export declare abstract class SymbolGraphic {
|
|
|
37
38
|
drawPlaceRemove(group: G, extra?: {
|
|
38
39
|
place?: boolean;
|
|
39
40
|
}): void;
|
|
40
|
-
pinPosition(id:
|
|
41
|
+
pinPosition(id: PinId): {
|
|
41
42
|
x: NumericValue;
|
|
42
43
|
y: NumericValue;
|
|
43
44
|
angle: NumericValue;
|
|
@@ -131,7 +132,7 @@ export declare class SymbolCustomModule extends SymbolCustom {
|
|
|
131
132
|
}
|
|
132
133
|
export declare class SymbolDrawing {
|
|
133
134
|
items: (Feature | GeometryProp)[];
|
|
134
|
-
pins: [
|
|
135
|
+
pins: PinRenderInfo[];
|
|
135
136
|
angle: number;
|
|
136
137
|
flipX: number;
|
|
137
138
|
flipY: number;
|
|
@@ -141,8 +142,7 @@ export declare class SymbolDrawing {
|
|
|
141
142
|
clear(): void;
|
|
142
143
|
log(...params: any[]): void;
|
|
143
144
|
addLine(startX: NumericValue, startY: NumericValue, endX: NumericValue, endY: NumericValue): SymbolDrawing;
|
|
144
|
-
|
|
145
|
-
addPinMM(pinId: NumericValue, startXMM: NumericValue, startYMM: NumericValue, endXMM: NumericValue, endYMM: NumericValue, lineColor: string): SymbolDrawing;
|
|
145
|
+
addPinMM(pinId: PinId, startXMM: NumericValue, startYMM: NumericValue, endXMM: NumericValue, endYMM: NumericValue, lineColor: string): SymbolDrawing;
|
|
146
146
|
addVLine(startX: NumericValue, startY: NumericValue, value: NumericValue): SymbolDrawing;
|
|
147
147
|
addHLine(startX: NumericValue, startY: NumericValue, value: NumericValue): SymbolDrawing;
|
|
148
148
|
addRect(x: NumericValue, y: NumericValue, width: NumericValue, height: NumericValue): SymbolDrawing;
|
|
@@ -177,7 +177,7 @@ export declare class SymbolDrawing {
|
|
|
177
177
|
start: SimplePoint;
|
|
178
178
|
end: SimplePoint;
|
|
179
179
|
};
|
|
180
|
-
getPinPosition(pinId:
|
|
180
|
+
getPinPosition(pinId: PinId): {
|
|
181
181
|
start: [x: NumericValue, y: NumericValue];
|
|
182
182
|
end: [x: NumericValue, y: NumericValue];
|
|
183
183
|
angle: NumericValue;
|
|
@@ -191,7 +191,7 @@ export type GraphicExprCommand = [
|
|
|
191
191
|
];
|
|
192
192
|
export declare class SymbolDrawingCommands extends SymbolDrawing {
|
|
193
193
|
id: string;
|
|
194
|
-
|
|
194
|
+
protected commands: GraphicExprCommand[];
|
|
195
195
|
paramIds: string[];
|
|
196
196
|
callback: (variables: Map<string, any>) => GraphicExprCommand[];
|
|
197
197
|
constructor(callback: (variables: Map<string, any>) => GraphicExprCommand[]);
|
|
@@ -216,9 +216,15 @@ type SymbolPinLayout = {
|
|
|
216
216
|
};
|
|
217
217
|
export type SymbolPinDefintion = {
|
|
218
218
|
side: string;
|
|
219
|
-
pinId:
|
|
219
|
+
pinId: PinId;
|
|
220
220
|
text: string;
|
|
221
221
|
position: number;
|
|
222
222
|
pinType: PinTypes;
|
|
223
223
|
};
|
|
224
|
+
export type PinRenderInfo = [
|
|
225
|
+
PinId,
|
|
226
|
+
Feature,
|
|
227
|
+
angle: NumericValue,
|
|
228
|
+
lineColor: string
|
|
229
|
+
];
|
|
224
230
|
export {};
|