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.
Files changed (38) hide show
  1. package/dist/cjs/BaseVisitor.js +2 -1
  2. package/dist/cjs/draw_symbols.js +18 -17
  3. package/dist/cjs/execute.js +40 -20
  4. package/dist/cjs/globals.js +1 -0
  5. package/dist/cjs/graph.js +101 -27
  6. package/dist/cjs/layout.js +6 -1
  7. package/dist/cjs/objects/ClassComponent.js +27 -20
  8. package/dist/cjs/objects/ExecutionScope.js +7 -2
  9. package/dist/cjs/objects/Net.js +1 -1
  10. package/dist/cjs/objects/PinDefinition.js +55 -3
  11. package/dist/cjs/objects/types.js +16 -1
  12. package/dist/cjs/visitor.js +56 -18
  13. package/dist/esm/BaseVisitor.js +2 -1
  14. package/dist/esm/draw_symbols.js +18 -17
  15. package/dist/esm/execute.js +41 -21
  16. package/dist/esm/globals.js +1 -0
  17. package/dist/esm/graph.js +79 -28
  18. package/dist/esm/layout.js +6 -1
  19. package/dist/esm/objects/ClassComponent.js +28 -21
  20. package/dist/esm/objects/ExecutionScope.js +7 -2
  21. package/dist/esm/objects/Net.js +1 -1
  22. package/dist/esm/objects/PinDefinition.js +53 -2
  23. package/dist/esm/objects/types.js +15 -0
  24. package/dist/esm/visitor.js +58 -20
  25. package/dist/libs/std.cst +3 -2
  26. package/dist/types/BaseVisitor.d.ts +2 -1
  27. package/dist/types/draw_symbols.d.ts +13 -7
  28. package/dist/types/execute.d.ts +7 -7
  29. package/dist/types/globals.d.ts +1 -0
  30. package/dist/types/graph.d.ts +2 -1
  31. package/dist/types/layout.d.ts +2 -1
  32. package/dist/types/objects/ClassComponent.d.ts +8 -8
  33. package/dist/types/objects/ExecutionScope.d.ts +5 -4
  34. package/dist/types/objects/Net.d.ts +2 -2
  35. package/dist/types/objects/PinDefinition.d.ts +17 -2
  36. package/dist/types/objects/types.d.ts +15 -1
  37. package/libs/std.cst +3 -2
  38. package/package.json +2 -1
@@ -1,13 +1,55 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PortSide = exports.PinIdType = exports.PinDefinition = void 0;
3
+ exports.getPinDefinition = exports.isPinId = exports.PortSide = exports.PinIdType = exports.PinDefinition = exports.PinId = void 0;
4
+ const utils_js_1 = require("../utils.js");
5
+ const ParamDefinition_js_1 = require("./ParamDefinition.js");
4
6
  const PinTypes_js_1 = require("./PinTypes.js");
7
+ class PinId {
8
+ constructor(value) {
9
+ if (typeof value !== 'string' && typeof value !== 'number') {
10
+ throw new utils_js_1.RuntimeExecutionError("Invalid value for PinId: " + value);
11
+ }
12
+ this.value = value;
13
+ this.type = typeof value === 'number' ? PinIdType.Int : PinIdType.Str;
14
+ }
15
+ getValue() {
16
+ return this.value;
17
+ }
18
+ getType() {
19
+ return this.type;
20
+ }
21
+ isNumeric() {
22
+ return this.type === PinIdType.Int;
23
+ }
24
+ isString() {
25
+ return this.type === PinIdType.Str;
26
+ }
27
+ toString() {
28
+ return this.value.toString();
29
+ }
30
+ equals(other) {
31
+ if (other instanceof PinId) {
32
+ return this.value === other.value;
33
+ }
34
+ return this.value === other;
35
+ }
36
+ static from(value) {
37
+ if (value instanceof ParamDefinition_js_1.NumericValue) {
38
+ return new PinId(value.toNumber());
39
+ }
40
+ return new PinId(value);
41
+ }
42
+ static isPinIdType(value) {
43
+ return (typeof value === 'number' || typeof value === 'string');
44
+ }
45
+ }
46
+ exports.PinId = PinId;
5
47
  class PinDefinition {
6
48
  constructor(id, idType, name, pinType = PinTypes_js_1.PinTypes.Any, altNames = []) {
7
49
  this.side = PortSide.EAST;
8
50
  this.position = -1;
9
- this.id = id;
10
- this.idType = idType;
51
+ this.id = id instanceof PinId ? id : new PinId(id);
52
+ this.idType = this.id.getType();
11
53
  this.pinType = pinType;
12
54
  this.name = name;
13
55
  this.altNames = altNames;
@@ -26,3 +68,13 @@ var PortSide;
26
68
  PortSide["SOUTH"] = "SOUTH";
27
69
  PortSide["NORTH"] = "NORTH";
28
70
  })(PortSide || (exports.PortSide = PortSide = {}));
71
+ function isPinId(item) {
72
+ return item instanceof PinId || (typeof item === 'number' || typeof item === 'string');
73
+ }
74
+ exports.isPinId = isPinId;
75
+ function getPinDefinition(map, id) {
76
+ const keys = Array.from(map.keys());
77
+ const tmpKey = keys.find(item => item.equals(id));
78
+ return map.get(tmpKey);
79
+ }
80
+ exports.getPinDefinition = getPinDefinition;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Direction = exports.ParseSymbolType = exports.DeclaredReference = exports.UndeclaredReference = exports.AnyReference = exports.CFunctionEntry = void 0;
3
+ exports.NetTypes = exports.TypeProps = exports.Direction = exports.ParseSymbolType = exports.DeclaredReference = exports.UndeclaredReference = exports.AnyReference = exports.CFunctionEntry = void 0;
4
4
  const globals_js_1 = require("../globals.js");
5
5
  const utils_js_1 = require("../utils.js");
6
6
  class CFunctionEntry {
@@ -107,3 +107,18 @@ var Direction;
107
107
  Direction["Down"] = "down";
108
108
  Direction["Up"] = "up";
109
109
  })(Direction || (exports.Direction = Direction = {}));
110
+ var TypeProps;
111
+ (function (TypeProps) {
112
+ TypeProps["Net"] = "net";
113
+ TypeProps["Port"] = "port";
114
+ TypeProps["Graphic"] = "graphic";
115
+ TypeProps["Resistor"] = "res";
116
+ TypeProps["Capacitor"] = "cap";
117
+ TypeProps["Inductor"] = "ind";
118
+ TypeProps["Diode"] = "diode";
119
+ })(TypeProps || (exports.TypeProps = TypeProps = {}));
120
+ var NetTypes;
121
+ (function (NetTypes) {
122
+ NetTypes["Any"] = "any";
123
+ NetTypes["Source"] = "source";
124
+ })(NetTypes || (exports.NetTypes = NetTypes = {}));
@@ -22,19 +22,23 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
22
22
  this.setResult(ctx, [id, value]);
23
23
  };
24
24
  this.visitPin_select_expr = (ctx) => {
25
- let value = null;
25
+ let pinId = null;
26
26
  const ctxData = ctx.data_expr();
27
27
  const result = this.visitResult(ctxData);
28
+ let pinValue;
28
29
  if (result instanceof ParamDefinition_js_1.NumericValue) {
29
- value = result.toNumber();
30
+ pinValue = result.toNumber();
30
31
  }
31
32
  else if (typeof result === 'string') {
32
- value = result;
33
+ pinValue = result;
33
34
  }
34
35
  else {
35
- throw new utils_js_2.RuntimeExecutionError("Invalid value for pin", ctx);
36
+ throw new utils_js_2.RuntimeExecutionError("Invalid select pin: " + result, ctx);
36
37
  }
37
- this.setResult(ctx, value);
38
+ if (pinValue !== undefined) {
39
+ pinId = new PinDefinition_js_1.PinId(pinValue);
40
+ }
41
+ this.setResult(ctx, pinId);
38
42
  };
39
43
  this.visitAdd_component_expr = (ctx) => {
40
44
  const [component, pinValue] = this.visitResult(ctx.data_expr_with_assignment());
@@ -221,11 +225,18 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
221
225
  }
222
226
  }
223
227
  else {
224
- if (!(value instanceof ParamDefinition_js_1.NumericValue)) {
228
+ if (!(value instanceof ParamDefinition_js_1.NumericValue) && !(typeof value === 'string')) {
225
229
  throw new utils_js_2.RuntimeExecutionError(`Invalid numeric value for arrange.${sideKeyName}`, ctx);
226
230
  }
227
231
  else {
228
- checkPinExistsAndNotDuplicated(value.toNumber(), ctx);
232
+ let useValue;
233
+ if (value instanceof ParamDefinition_js_1.NumericValue) {
234
+ useValue = value.toNumber();
235
+ }
236
+ else if (typeof value === 'string') {
237
+ useValue = value;
238
+ }
239
+ value && checkPinExistsAndNotDuplicated(useValue, ctx);
229
240
  }
230
241
  }
231
242
  }
@@ -265,7 +276,6 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
265
276
  scope.exitContext();
266
277
  scope.popOnPropertyHandler();
267
278
  const properties = this.getPropertyExprList(ctx.property_expr());
268
- const pins = this.parseCreateComponentPins(properties.get('pins'));
269
279
  let instanceName = this.getExecutor().getUniqueInstanceName();
270
280
  const propParams = properties.get('params');
271
281
  const params = this.parseCreateComponentParams(propParams);
@@ -278,11 +288,11 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
278
288
  }
279
289
  instanceName += `${globals_js_1.Delimiter1}${appendValue}`;
280
290
  }
281
- const arrange = properties.has('arrange') ?
291
+ const arrangeProp = properties.has('arrange') ?
282
292
  properties.get('arrange') : null;
283
- const display = properties.has('display') ?
293
+ const displayProp = properties.has('display') ?
284
294
  properties.get('display') : null;
285
- const type = properties.has('type') ?
295
+ const typeProp = properties.has('type') ?
286
296
  properties.get('type') : null;
287
297
  const copy = properties.has('copy') ?
288
298
  properties.get('copy') : false;
@@ -294,8 +304,29 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
294
304
  properties.get(globals_js_1.ParamKeys.angle) : null;
295
305
  const followWireOrientation = properties.has('followWireOrientation') ?
296
306
  properties.get('followWireOrientation') : true;
307
+ let pins = [];
308
+ if (displayProp !== null && arrangeProp === null
309
+ && typeProp !== types_js_1.TypeProps.Graphic) {
310
+ const drawCommands = displayProp.getCommands();
311
+ drawCommands.forEach(command => {
312
+ const [commandValue,] = command;
313
+ if (commandValue === draw_symbols_js_1.PlaceHolderCommands.vpin
314
+ || commandValue === draw_symbols_js_1.PlaceHolderCommands.hpin
315
+ || commandValue === draw_symbols_js_1.PlaceHolderCommands.pin) {
316
+ const id = PinDefinition_js_1.PinId.from(command[1][0]);
317
+ const pinType = id.getType();
318
+ const pinName = id.toString();
319
+ pins.push(new PinDefinition_js_1.PinDefinition(id, pinType, pinName, PinTypes_js_1.PinTypes.Any));
320
+ }
321
+ });
322
+ }
323
+ else {
324
+ pins = this.parseCreateComponentPins(properties.get('pins'));
325
+ }
297
326
  const props = {
298
- arrange, display, type, width, height, copy,
327
+ arrange: arrangeProp,
328
+ display: displayProp,
329
+ type: typeProp, width, height, copy,
299
330
  angle, followWireOrientation
300
331
  };
301
332
  try {
@@ -807,14 +838,21 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
807
838
  this.visitPin_select_expr2 = (ctx) => {
808
839
  const ctxStringValue = ctx.STRING_VALUE();
809
840
  const ctxIntegerValue = ctx.INTEGER_VALUE();
810
- let result = null;
841
+ let pinIdValue;
842
+ let pinId = null;
811
843
  if (ctxStringValue) {
812
- result = this.prepareStringValue(ctxStringValue.getText());
844
+ pinIdValue = this.prepareStringValue(ctxStringValue.getText());
813
845
  }
814
846
  else if (ctxIntegerValue) {
815
- result = Number(ctxIntegerValue.getText());
847
+ pinIdValue = Number(ctxIntegerValue.getText());
816
848
  }
817
- this.setResult(ctx, result);
849
+ if (pinIdValue !== undefined) {
850
+ pinId = new PinDefinition_js_1.PinId(pinIdValue);
851
+ }
852
+ else {
853
+ throw new utils_js_2.RuntimeExecutionError("Invalid select pin", ctx);
854
+ }
855
+ this.setResult(ctx, pinId);
818
856
  };
819
857
  this.visitAt_block_pin_expr = (ctx) => {
820
858
  const executor = this.getExecutor();
@@ -1206,7 +1244,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
1206
1244
  return item;
1207
1245
  }
1208
1246
  else {
1209
- return (0, ParamDefinition_js_1.numeric)(nameToPinId.get(item));
1247
+ return new PinDefinition_js_1.PinId(nameToPinId.get(item));
1210
1248
  }
1211
1249
  });
1212
1250
  if (items.length > 0) {
@@ -1297,7 +1335,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
1297
1335
  getGraph() {
1298
1336
  const executor = this.getExecutor();
1299
1337
  const fullSequence = executor.scope.sequence;
1300
- const tmpNet = executor.scope.getNet(executor.scope.componentRoot, 1);
1338
+ const tmpNet = executor.scope.getNet(executor.scope.componentRoot, new PinDefinition_js_1.PinId(1));
1301
1339
  const sequence = (tmpNet === null)
1302
1340
  ? fullSequence.slice(1) : fullSequence;
1303
1341
  const nets = executor.scope.getNets();
@@ -11,6 +11,7 @@ import { isReference, unwrapValue as unwrapValue } from "./utils.js";
11
11
  import { linkBuiltInMethods } from './builtinMethods.js';
12
12
  import { resolveToNumericValue, RuntimeExecutionError, throwWithContext } from './utils.js';
13
13
  import { SequenceAction } from './objects/ExecutionScope.js';
14
+ import { PinId } from './objects/PinDefinition.js';
14
15
  export class BaseVisitor extends CircuitScriptVisitor {
15
16
  indentLevel = 0;
16
17
  startingContext;
@@ -171,7 +172,7 @@ export class BaseVisitor extends CircuitScriptVisitor {
171
172
  this.log2(`assigned component param ${leftSideReference.parentValue} trailers: ${trailers} value: ${rhsValue}`);
172
173
  sequenceParts.push(...['instance', [leftSideReference.parentValue, trailers], rhsValue]);
173
174
  if (leftSideReference.parentValue.typeProp === ComponentTypes.net) {
174
- const net = this.getScope().getNet(leftSideReference.parentValue, 1);
175
+ const net = this.getScope().getNet(leftSideReference.parentValue, new PinId(1));
175
176
  if (net) {
176
177
  const trailerValue = trailers.join(".");
177
178
  net.params.set(trailerValue, rhsValue);
@@ -5,6 +5,7 @@ import { PinTypes } from "./objects/PinTypes.js";
5
5
  import { roundValue, RuntimeExecutionError, throwWithContext } from "./utils.js";
6
6
  import { DeclaredReference, UndeclaredReference } from "./objects/types.js";
7
7
  import { numeric, NumericValue } from "./objects/ParamDefinition.js";
8
+ import { PinId } from "./objects/PinDefinition.js";
8
9
  export class SymbolGraphic {
9
10
  drawPortsName = true;
10
11
  displayBounds = false;
@@ -560,6 +561,12 @@ export class SymbolPlaceholder extends SymbolGraphic {
560
561
  milsToMM(endY)
561
562
  ];
562
563
  }
564
+ if (positionParams[0] instanceof NumericValue) {
565
+ positionParams[0] = new PinId(positionParams[0].toNumber());
566
+ }
567
+ else if (typeof positionParams[0] === 'number' || typeof positionParams[0] === 'string') {
568
+ positionParams[0] = new PinId(positionParams[0]);
569
+ }
563
570
  drawing.addPinMM(...positionParams, lineColor);
564
571
  const lastAddedPin = this.drawing.pins[this.drawing.pins.length - 1];
565
572
  const [pinId, , angle] = lastAddedPin;
@@ -604,7 +611,8 @@ export class SymbolPlaceholder extends SymbolGraphic {
604
611
  vanchor: VerticalAlign.Middle,
605
612
  textColor: pinNameColor,
606
613
  });
607
- displayPinId && drawing.addLabel(endX.add(pinIdOffsetX), endY.add(pinIdOffsetY), pinId.toDisplayString(), {
614
+ const pinDisplayText = pinId.toString();
615
+ displayPinId && drawing.addLabel(endX.add(pinIdOffsetX), endY.add(pinIdOffsetY), pinDisplayText, {
608
616
  fontSize: numeric(defaultPinIdTextSize),
609
617
  anchor: pinIdAlignment,
610
618
  vanchor: pinIdVAlignment,
@@ -704,7 +712,7 @@ export class SymbolCustom extends SymbolGraphic {
704
712
  leftPins.forEach(pin => {
705
713
  const position = pin.position;
706
714
  const pinY = pinStartY.add((position + 1) * tmpPinSpacing);
707
- drawing.addPinMM(numeric(pin.pinId), leftPinStart.sub(this.pinLength), pinY, leftPinStart, pinY, defaultLineColor);
715
+ drawing.addPinMM(pin.pinId, leftPinStart.sub(this.pinLength), pinY, leftPinStart, pinY, defaultLineColor);
708
716
  drawing.addLabel(leftPinStart.add(milsToMM(20)), pinY, pin.text, {
709
717
  fontSize: numeric(CustomSymbolPinTextSize),
710
718
  anchor: HorizontalAlign.Left,
@@ -721,7 +729,7 @@ export class SymbolCustom extends SymbolGraphic {
721
729
  rightPins.forEach(pin => {
722
730
  const position = pin.position;
723
731
  const pinY = pinStartY.add((position + 1) * tmpPinSpacing);
724
- drawing.addPinMM(numeric(pin.pinId), rightPinStart.add(this.pinLength), pinY, rightPinStart, pinY, defaultLineColor);
732
+ drawing.addPinMM(pin.pinId, rightPinStart.add(this.pinLength), pinY, rightPinStart, pinY, defaultLineColor);
725
733
  drawing.addLabel(rightPinStart.sub(milsToMM(20)), pinY, pin.text, {
726
734
  fontSize: numeric(CustomSymbolPinTextSize),
727
735
  anchor: HorizontalAlign.Right,
@@ -738,7 +746,7 @@ export class SymbolCustom extends SymbolGraphic {
738
746
  topPins.forEach(pin => {
739
747
  const position = pin.position;
740
748
  const pinX = pinStartX.add((position + 1) * tmpPinSpacing);
741
- drawing.addPinMM(numeric(pin.pinId), pinX, topPinStart.sub(this.pinLength), pinX, topPinStart, defaultLineColor);
749
+ drawing.addPinMM(pin.pinId, pinX, topPinStart.sub(this.pinLength), pinX, topPinStart, defaultLineColor);
742
750
  drawing.addLabel(pinX, topPinStart.add(milsToMM(20)), pin.text, {
743
751
  fontSize: numeric(CustomSymbolPinTextSize),
744
752
  anchor: HorizontalAlign.Right,
@@ -757,7 +765,7 @@ export class SymbolCustom extends SymbolGraphic {
757
765
  bottomPins.forEach(pin => {
758
766
  const position = pin.position;
759
767
  const pinX = pinStartX.add((position + 1) * tmpPinSpacing);
760
- drawing.addPinMM(numeric(pin.pinId), pinX, bottomPinStart.add(this.pinLength), pinX, bottomPinStart, defaultLineColor);
768
+ drawing.addPinMM(pin.pinId, pinX, bottomPinStart.add(this.pinLength), pinX, bottomPinStart, defaultLineColor);
761
769
  drawing.addLabel(pinX, bottomPinStart.sub(milsToMM(20)), pin.text, {
762
770
  fontSize: numeric(CustomSymbolPinTextSize),
763
771
  anchor: HorizontalAlign.Left,
@@ -839,7 +847,7 @@ export class SymbolCustomModule extends SymbolCustom {
839
847
  leftPins.forEach(pin => {
840
848
  const position = pin.position;
841
849
  const pinY = pinStartY.add((position + 1) * tmpPinSpacing);
842
- drawing.addPinMM(numeric(pin.pinId), leftPinStart.sub(this.pinLength), pinY, leftPinStart, pinY, defaultLineColor);
850
+ drawing.addPinMM(pin.pinId, leftPinStart.sub(this.pinLength), pinY, leftPinStart, pinY, defaultLineColor);
843
851
  drawing.addModulePort(leftPinStart, pinY, this.portWidth, this.portHeight, pin.pinType);
844
852
  drawing.addLabel(leftPinStart.add(this.portWidth).add(milsToMM(20)), pinY, pin.text, {
845
853
  fontSize: numeric(40),
@@ -851,7 +859,7 @@ export class SymbolCustomModule extends SymbolCustom {
851
859
  rightPins.forEach(pin => {
852
860
  const position = pin.position;
853
861
  const pinY = pinStartY.add((position + 1) * tmpPinSpacing);
854
- drawing.addPinMM(numeric(pin.pinId), rightPinStart.add(this.pinLength), pinY, rightPinStart, pinY, defaultLineColor);
862
+ drawing.addPinMM(pin.pinId, rightPinStart.add(this.pinLength), pinY, rightPinStart, pinY, defaultLineColor);
855
863
  drawing.addModulePort(rightPinStart, pinY, this.portWidth, this.portHeight, pin.pinType, -1);
856
864
  drawing.addLabel(rightPinStart.sub(this.portWidth).sub(milsToMM(20)), pinY, pin.text, {
857
865
  fontSize: numeric(40),
@@ -863,7 +871,7 @@ export class SymbolCustomModule extends SymbolCustom {
863
871
  topPins.forEach(pin => {
864
872
  const position = pin.position;
865
873
  const pinX = pinStartX.add((position + 1) * tmpPinSpacing);
866
- drawing.addPinMM(numeric(pin.pinId), pinX, topPinStart.sub(this.pinLength), pinX, topPinStart, defaultLineColor);
874
+ drawing.addPinMM(pin.pinId, pinX, topPinStart.sub(this.pinLength), pinX, topPinStart, defaultLineColor);
867
875
  drawing.addModulePort(pinX, topPinStart, this.portWidth, this.portHeight, pin.pinType, 1, 90);
868
876
  drawing.addLabel(pinX, topPinStart.add(this.portWidth).add(milsToMM(20)), pin.text, {
869
877
  fontSize: numeric(40),
@@ -876,7 +884,7 @@ export class SymbolCustomModule extends SymbolCustom {
876
884
  bottomPins.forEach(pin => {
877
885
  const position = pin.position;
878
886
  const pinX = pinStartX.add((position + 1) * tmpPinSpacing);
879
- drawing.addPinMM(numeric(pin.pinId), pinX, bottomPinStart, pinX, bottomPinStart.sub(this.pinLength), defaultLineColor);
887
+ drawing.addPinMM(pin.pinId, pinX, bottomPinStart, pinX, bottomPinStart.sub(this.pinLength), defaultLineColor);
880
888
  drawing.addModulePort(pinX, bottomPinStart, this.portWidth, this.portHeight, pin.pinType, 1, -90);
881
889
  drawing.addLabel(pinX, bottomPinStart.sub(this.portWidth).sub(milsToMM(20)), pin.text, {
882
890
  fontSize: numeric(40),
@@ -912,13 +920,6 @@ export class SymbolDrawing {
912
920
  this.items.push(Geometry.segment([startX, startY], [endX, endY]));
913
921
  return this;
914
922
  }
915
- addPin(pinId, startX, startY, endX, endY, lineColor) {
916
- startX = milsToMM(startX);
917
- startY = milsToMM(startY);
918
- endX = milsToMM(endX);
919
- endY = milsToMM(endY);
920
- return this.addPinMM(pinId, startX, startY, endX, endY, lineColor);
921
- }
922
923
  addPinMM(pinId, startXMM, startYMM, endXMM, endYMM, lineColor) {
923
924
  let angle = 0;
924
925
  const tmpStartXMM = startXMM.toNumber();
@@ -1221,7 +1222,7 @@ export class SymbolDrawing {
1221
1222
  }
1222
1223
  getPinPosition(pinId) {
1223
1224
  const pin = this.pins.find(item => {
1224
- return item[0].toNumber() === pinId;
1225
+ return item[0].equals(pinId);
1225
1226
  });
1226
1227
  if (pin) {
1227
1228
  const [, feature, angle] = pin;
@@ -3,7 +3,7 @@ import { ClassComponent, ModuleComponent } from './objects/ClassComponent.js';
3
3
  import { ActiveObject, ExecutionScope, FrameAction, SequenceAction } from './objects/ExecutionScope.js';
4
4
  import { Net } from './objects/Net.js';
5
5
  import { numeric, NumericValue } from './objects/ParamDefinition.js';
6
- import { PortSide } from './objects/PinDefinition.js';
6
+ import { PinId, PortSide } from './objects/PinDefinition.js';
7
7
  import { AnyReference, CFunctionEntry, DeclaredReference, Direction } from './objects/types.js';
8
8
  import { Wire } from './objects/Wire.js';
9
9
  import { Frame } from './objects/Frame.js';
@@ -151,7 +151,7 @@ export class ExecutionContext {
151
151
  const tmpArrangeRight = [];
152
152
  pins.forEach((pin, index) => {
153
153
  const useArray = (index % 2 === 0) ? tmpArrangeLeft : tmpArrangeRight;
154
- useArray.push(numeric(pin.id));
154
+ useArray.push(pin.id);
155
155
  });
156
156
  const arrangeProp = new Map([
157
157
  [SymbolPinSide.Left, tmpArrangeLeft],
@@ -161,11 +161,9 @@ export class ExecutionContext {
161
161
  }
162
162
  if (props.arrange !== null) {
163
163
  component.arrangeProps = this.removeArrangePropDuplicates(props.arrange);
164
- const arrangePropPins = this.getArrangePropPins(component.arrangeProps).map(item => {
165
- return item.toNumber();
166
- });
164
+ const arrangePropPins = this.getArrangePropPins(component.arrangeProps);
167
165
  pins.forEach(pin => {
168
- if (arrangePropPins.indexOf(pin.id) === -1) {
166
+ if (arrangePropPins.find(id => id.equals(pin.id)) === undefined) {
169
167
  this.logWarning(`Pin ${pin.id} is not specified in arrange property`);
170
168
  }
171
169
  });
@@ -182,6 +180,7 @@ export class ExecutionContext {
182
180
  });
183
181
  if (component.typeProp === ComponentTypes.net) {
184
182
  const netName = paramsMap.get(ParamKeys.net_name);
183
+ const netType = paramsMap.get(ParamKeys.net_type);
185
184
  let priority = 0;
186
185
  if (paramsMap.has(ParamKeys.priority)) {
187
186
  priority = paramsMap.get(ParamKeys.priority).toNumber();
@@ -193,21 +192,26 @@ export class ExecutionContext {
193
192
  this.log('net found', tmpNet.namespace, tmpNet.name);
194
193
  }
195
194
  else {
196
- tmpNet = new Net(this.netNamespace, netName, priority);
195
+ tmpNet = new Net(this.netNamespace, netName, priority, netType);
197
196
  this.log('net not found, added net instance', tmpNet.namespace, tmpNet.name);
198
197
  }
199
- const defaultPin = 1;
198
+ const defaultPin = new PinId(1);
200
199
  this.scope.setNet(component, defaultPin, tmpNet);
201
200
  this.log('set net', netName, 'component', component, defaultPin);
202
201
  }
203
202
  const { pins: pinSides, maxPositions } = getPortSide(component.pins, component.arrangeProps);
204
203
  component.pinsMaxPositions = maxPositions;
204
+ const pinIdKeys = Array.from(component.pins.keys());
205
205
  pinSides.forEach(({ pinId, side, position }) => {
206
- if (component.pins.has(pinId)) {
207
- const tmpPin = component.pins.get(pinId);
206
+ const matchedPinId = pinIdKeys.find(id => id.equals(pinId));
207
+ if (matchedPinId) {
208
+ const tmpPin = component.pins.get(matchedPinId);
208
209
  tmpPin.side = side;
209
210
  tmpPin.position = position;
210
211
  }
212
+ else {
213
+ throw 'Not found!';
214
+ }
211
215
  });
212
216
  this.scope.instances.set(instanceName, component);
213
217
  const pinsOutput = pins.map((pin) => {
@@ -230,15 +234,32 @@ export class ExecutionContext {
230
234
  if (!Array.isArray(items)) {
231
235
  items = [items];
232
236
  }
237
+ items = items.map(item => {
238
+ if (item instanceof NumericValue) {
239
+ item = item.toNumber();
240
+ }
241
+ if (item instanceof PinId) {
242
+ return item;
243
+ }
244
+ else if (PinId.isPinIdType(item)) {
245
+ return new PinId(item);
246
+ }
247
+ return item;
248
+ });
249
+ arrangeProp.set(side, items);
250
+ if (!Array.isArray(items)) {
251
+ items = [items];
252
+ }
233
253
  const uniqueItems = [];
234
254
  items.forEach(item => {
235
- if (item instanceof NumericValue) {
236
- if (seenIds.indexOf(item.toNumber()) === -1) {
237
- seenIds.push(item.toNumber());
255
+ if (item instanceof PinId) {
256
+ const found = seenIds.find(id => id.equals(item));
257
+ if (!found) {
258
+ seenIds.push(item);
238
259
  uniqueItems.push(item);
239
260
  }
240
261
  else {
241
- this.logWarning(`Pin ${item.toNumber()} specified more than once in arrange property`);
262
+ this.logWarning(`Pin ${item.toString()} specified more than once in arrange property`);
242
263
  }
243
264
  }
244
265
  else {
@@ -261,7 +282,7 @@ export class ExecutionContext {
261
282
  const items = arrangeProps.get(side);
262
283
  if (items) {
263
284
  items.forEach(item => {
264
- if (item instanceof NumericValue) {
285
+ if (item instanceof PinId) {
265
286
  pins.push(item);
266
287
  }
267
288
  });
@@ -383,7 +404,7 @@ export class ExecutionContext {
383
404
  const cloneInstanceName = component.instanceName + ':' + idNum;
384
405
  this.scope.instances.set(cloneInstanceName, componentCopy);
385
406
  componentCopy.instanceName = cloneInstanceName;
386
- const defaultPin = 1;
407
+ const defaultPin = new PinId(1);
387
408
  if (this.scope.getNet(component, defaultPin) === null) {
388
409
  const foundNet = this.resolveComponentPinNet(component, defaultPin);
389
410
  if (foundNet !== null) {
@@ -602,7 +623,7 @@ export class ExecutionContext {
602
623
  else if (type === ReferenceTypes.instance) {
603
624
  const tmpComponent = parentValue;
604
625
  if (tmpComponent.typeProp === ComponentTypes.net) {
605
- const usedNet = this.scope.getNet(tmpComponent, 1);
626
+ const usedNet = this.scope.getNet(tmpComponent, new PinId(1));
606
627
  if (usedNet) {
607
628
  const trailerValue = trailers.join(".");
608
629
  useValue = usedNet.params.get(trailerValue) ?? null;
@@ -696,7 +717,7 @@ export class ExecutionContext {
696
717
  const linkRootComponent = true;
697
718
  const tmpRoot = childScope.componentRoot;
698
719
  if (linkRootComponent) {
699
- const netConnectedToRoot = childScope.getNet(tmpRoot, 1);
720
+ const netConnectedToRoot = childScope.getNet(tmpRoot, new PinId(1));
700
721
  if (netConnectedToRoot !== null) {
701
722
  let currentNet = this.scope.getNet(currentComponent, currentPin);
702
723
  if (currentNet === null) {
@@ -1043,10 +1064,9 @@ export function getPortSide(pins, arrangeProps) {
1043
1064
  position += item[0].toNumber();
1044
1065
  }
1045
1066
  else {
1046
- const itemValue = item.toNumber();
1047
- if (existingPinIds.indexOf(itemValue) !== -1) {
1067
+ if (existingPinIds.find(id => id.equals(item))) {
1048
1068
  result.push({
1049
- pinId: itemValue,
1069
+ pinId: item,
1050
1070
  side: useSide,
1051
1071
  position,
1052
1072
  order: counter
@@ -12,6 +12,7 @@ export var ParamKeys;
12
12
  (function (ParamKeys) {
13
13
  ParamKeys["priority"] = "priority";
14
14
  ParamKeys["net_name"] = "net_name";
15
+ ParamKeys["net_type"] = "net_type";
15
16
  ParamKeys["flip"] = "flip";
16
17
  ParamKeys["flipX"] = "flipX";
17
18
  ParamKeys["flipY"] = "flipY";