circuitscript 0.0.24 → 0.0.26

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 (73) hide show
  1. package/LICENSE +1 -1
  2. package/dist/cjs/BaseVisitor.js +485 -0
  3. package/dist/cjs/SemanticTokenVisitor.js +218 -0
  4. package/dist/cjs/SymbolValidatorVisitor.js +233 -0
  5. package/dist/cjs/antlr/CircuitScriptLexer.js +256 -219
  6. package/dist/cjs/antlr/CircuitScriptParser.js +2891 -2151
  7. package/dist/cjs/antlr/CircuitScriptVisitor.js +4 -3
  8. package/dist/cjs/draw_symbols.js +73 -22
  9. package/dist/cjs/execute.js +70 -78
  10. package/dist/cjs/export.js +91 -5
  11. package/dist/cjs/geometry.js +28 -8
  12. package/dist/cjs/globals.js +1 -2
  13. package/dist/cjs/helpers.js +180 -7
  14. package/dist/cjs/index.js +2 -0
  15. package/dist/cjs/layout.js +8 -0
  16. package/dist/cjs/lexer.js +19 -22
  17. package/dist/cjs/main.js +27 -20
  18. package/dist/cjs/objects/ClassComponent.js +4 -0
  19. package/dist/cjs/objects/ExecutionScope.js +1 -0
  20. package/dist/cjs/objects/types.js +7 -1
  21. package/dist/cjs/parser.js +29 -258
  22. package/dist/cjs/render.js +1 -1
  23. package/dist/cjs/validate.js +81 -0
  24. package/dist/cjs/visitor.js +601 -823
  25. package/dist/esm/BaseVisitor.mjs +486 -0
  26. package/dist/esm/SemanticTokenVisitor.mjs +215 -0
  27. package/dist/esm/SymbolValidatorVisitor.mjs +222 -0
  28. package/dist/esm/antlr/CircuitScriptLexer.mjs +231 -218
  29. package/dist/esm/antlr/CircuitScriptParser.mjs +2852 -2144
  30. package/dist/esm/antlr/CircuitScriptVisitor.mjs +13 -4
  31. package/dist/esm/draw_symbols.mjs +74 -23
  32. package/dist/esm/execute.mjs +70 -75
  33. package/dist/esm/export.mjs +89 -6
  34. package/dist/esm/geometry.mjs +28 -8
  35. package/dist/esm/globals.mjs +1 -2
  36. package/dist/esm/helpers.mjs +171 -9
  37. package/dist/esm/index.mjs +2 -0
  38. package/dist/esm/layout.mjs +8 -0
  39. package/dist/esm/lexer.mjs +10 -10
  40. package/dist/esm/main.mjs +28 -21
  41. package/dist/esm/objects/ClassComponent.mjs +4 -0
  42. package/dist/esm/objects/ExecutionScope.mjs +1 -0
  43. package/dist/esm/objects/types.mjs +6 -0
  44. package/dist/esm/parser.mjs +25 -230
  45. package/dist/esm/render.mjs +2 -2
  46. package/dist/esm/validate.mjs +74 -0
  47. package/dist/esm/visitor.mjs +415 -643
  48. package/dist/types/BaseVisitor.d.ts +66 -0
  49. package/dist/types/SemanticTokenVisitor.d.ts +36 -0
  50. package/dist/types/SymbolValidatorVisitor.d.ts +61 -0
  51. package/dist/types/antlr/CircuitScriptLexer.d.ts +37 -29
  52. package/dist/types/antlr/CircuitScriptParser.d.ts +606 -494
  53. package/dist/types/antlr/CircuitScriptVisitor.d.ts +78 -60
  54. package/dist/types/draw_symbols.d.ts +12 -3
  55. package/dist/types/execute.d.ts +5 -10
  56. package/dist/types/export.d.ts +27 -1
  57. package/dist/types/geometry.d.ts +4 -0
  58. package/dist/types/globals.d.ts +2 -3
  59. package/dist/types/helpers.d.ts +32 -1
  60. package/dist/types/index.d.ts +2 -0
  61. package/dist/types/lexer.d.ts +2 -2
  62. package/dist/types/objects/ClassComponent.d.ts +1 -0
  63. package/dist/types/objects/ExecutionScope.d.ts +4 -1
  64. package/dist/types/objects/types.d.ts +5 -0
  65. package/dist/types/parser.d.ts +15 -28
  66. package/dist/types/validate.d.ts +2 -0
  67. package/dist/types/visitor.d.ts +43 -95
  68. package/fonts/Inter-Bold.ttf +0 -0
  69. package/fonts/Inter-Regular.ttf +0 -0
  70. package/fonts/OpenSans-Regular.ttf +0 -0
  71. package/fonts/Roboto-Regular.ttf +0 -0
  72. package/libs/lib.cst +184 -0
  73. package/package.json +11 -6
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const antlr4_1 = require("antlr4");
4
- class CircuitScriptVisitor extends antlr4_1.ParseTreeVisitor {
3
+ exports.CircuitScriptVisitor = void 0;
4
+ const antlr4ng_1 = require("antlr4ng");
5
+ class CircuitScriptVisitor extends antlr4ng_1.AbstractParseTreeVisitor {
5
6
  }
6
- exports.default = CircuitScriptVisitor;
7
+ exports.CircuitScriptVisitor = CircuitScriptVisitor;
@@ -3,12 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SymbolDrawingCommands = exports.SymbolDrawing = exports.SymbolCustom = exports.PlaceHolderCommands = exports.SymbolPlaceholder = exports.SymbolText = exports.SymbolPointHidden = exports.SymbolFactory = exports.SymbolGraphic = void 0;
4
4
  const globals_js_1 = require("./globals.js");
5
5
  const geometry_js_1 = require("./geometry.js");
6
+ const PinTypes_js_1 = require("./objects/PinTypes.js");
6
7
  const defaultSymbolLineWidth = 2;
7
8
  class SymbolGraphic {
8
9
  constructor() {
9
10
  this.drawPortsName = true;
10
11
  this.displayBounds = true;
11
12
  this._angle = 0;
13
+ this._flipX = 0;
14
+ this._flipY = 0;
12
15
  this.labelTexts = new Map();
13
16
  }
14
17
  get angle() {
@@ -17,6 +20,18 @@ class SymbolGraphic {
17
20
  set angle(value) {
18
21
  this._angle = value;
19
22
  }
23
+ get flipX() {
24
+ return this._flipX;
25
+ }
26
+ set flipX(value) {
27
+ this._flipX = value;
28
+ }
29
+ get flipY() {
30
+ return this._flipY;
31
+ }
32
+ set flipY(value) {
33
+ this._flipY = value;
34
+ }
20
35
  refreshDrawing(calculateSize = true) {
21
36
  this.generateDrawing();
22
37
  calculateSize && this.calculateSize();
@@ -42,10 +57,11 @@ class SymbolGraphic {
42
57
  drawPlaceRemove(group, extra) {
43
58
  if (extra && extra.place === false) {
44
59
  const { start, end } = this.drawing.getBoundingBox(true);
45
- group.path([
60
+ const path = geometry_js_1.Geometry.roundPathValues([
46
61
  "M", start[0], start[1], "L", end[0], end[1],
47
62
  "M", end[0], start[1], "L", start[0], end[1]
48
- ].join(" "))
63
+ ]);
64
+ group.path(path)
49
65
  .stroke({
50
66
  width: defaultSymbolLineWidth,
51
67
  color: 'red'
@@ -112,27 +128,33 @@ class SymbolGraphic {
112
128
  }
113
129
  switch (useAnchor) {
114
130
  case geometry_js_1.HorizontalAlign.Left:
115
- anchorStyle = 'start';
131
+ anchorStyle = (this.flipX === 0) ? 'start' : 'end';
116
132
  break;
117
133
  case geometry_js_1.HorizontalAlign.Middle:
118
134
  anchorStyle = 'middle';
119
135
  break;
120
136
  case geometry_js_1.HorizontalAlign.Right:
121
- anchorStyle = 'end';
137
+ anchorStyle = (this.flipX === 0) ? 'end' : 'start';
122
138
  break;
123
139
  }
124
140
  switch (useDominantBaseline) {
125
141
  case geometry_js_1.VerticalAlign.Top:
126
- dominantBaseline = 'hanging';
142
+ dominantBaseline = (this.flipY === 0) ? 'hanging' : 'text-top';
127
143
  break;
128
144
  case geometry_js_1.VerticalAlign.Middle:
129
145
  dominantBaseline = 'middle';
130
146
  break;
131
147
  case geometry_js_1.VerticalAlign.Bottom:
132
- dominantBaseline = 'text-top';
148
+ dominantBaseline = (this.flipY === 0) ? 'text-top' : 'hanging';
133
149
  break;
134
150
  }
135
151
  const position = tmpLabel.getLabelPosition();
152
+ if (this.flipX !== 0) {
153
+ position[0] *= -1;
154
+ }
155
+ if (this.flipY !== 0) {
156
+ position[1] *= -1;
157
+ }
136
158
  const useFont = globals_js_1.defaultFont;
137
159
  const textContainer = group.group();
138
160
  const text = textContainer.text(tmpLabel.text)
@@ -156,11 +178,26 @@ class SymbolGraphic {
156
178
  translateY = position[1];
157
179
  useRotateAngle = this.angle;
158
180
  }
181
+ translateX = this.roundValues(translateX);
182
+ translateY = this.roundValues(translateY);
159
183
  text.rotate(labelAngle);
160
184
  textContainer.translate(translateX, translateY)
161
185
  .rotate(useRotateAngle, -translateX, -translateY);
186
+ const { a, b, c, d, e, f } = textContainer.matrix();
187
+ const newMatrix = {
188
+ a: this.roundValues(a),
189
+ b: this.roundValues(b),
190
+ c: this.roundValues(c),
191
+ d: this.roundValues(d),
192
+ e: this.roundValues(e),
193
+ f: this.roundValues(f),
194
+ };
195
+ textContainer.transform(newMatrix);
162
196
  });
163
197
  }
198
+ roundValues(value) {
199
+ return +value.toFixed(7);
200
+ }
164
201
  flipTextAnchor(value) {
165
202
  if (value === geometry_js_1.HorizontalAlign.Left) {
166
203
  return geometry_js_1.HorizontalAlign.Right;
@@ -234,6 +271,8 @@ class SymbolPlaceholder extends SymbolGraphic {
234
271
  drawing.log("=== start generate drawing ===");
235
272
  drawing.clear();
236
273
  drawing.angle = this._angle;
274
+ drawing.flipX = this._flipX;
275
+ drawing.flipY = this._flipY;
237
276
  const commands = drawing.getCommands();
238
277
  drawing.log('id: ', drawing.id, 'angle: ', this._angle, "commands:", commands.length);
239
278
  commands.forEach(([commandName, positionParams, keywordParams]) => {
@@ -310,12 +349,16 @@ class SymbolPlaceholder extends SymbolGraphic {
310
349
  drawing.log('add pin', ...positionParams);
311
350
  const keywordDisplayPinId = 'display_pin_id';
312
351
  let displayPinId = true;
313
- if (keywordParams.has(keywordDisplayPinId)) {
314
- if (keywordParams.get(keywordDisplayPinId) === 0) {
315
- displayPinId = false;
316
- }
352
+ if (keywordParams.has(keywordDisplayPinId)
353
+ && keywordParams.get(keywordDisplayPinId) === 0) {
354
+ displayPinId = false;
317
355
  }
318
356
  let pinNameParam = null;
357
+ let pinType = PinTypes_js_1.PinTypes.Any;
358
+ if (positionParams[1].type && positionParams[1].type === globals_js_1.ReferenceTypes.pinType) {
359
+ pinType = positionParams[1].value;
360
+ positionParams = [positionParams[0], ...positionParams.slice(2)];
361
+ }
319
362
  if (typeof positionParams[1] === 'string') {
320
363
  pinNameParam = positionParams[1];
321
364
  positionParams = [positionParams[0], ...positionParams.slice(2)];
@@ -343,8 +386,8 @@ class SymbolPlaceholder extends SymbolGraphic {
343
386
  ];
344
387
  }
345
388
  drawing.addPin(...positionParams);
346
- const latestPin = this.drawing.pins[this.drawing.pins.length - 1];
347
- const [pinId, , angle] = latestPin;
389
+ const lastAddedPin = this.drawing.pins[this.drawing.pins.length - 1];
390
+ const [pinId, , angle] = lastAddedPin;
348
391
  const [, , , endX, endY] = positionParams;
349
392
  let pinNameAlignment = geometry_js_1.HorizontalAlign.Left;
350
393
  let pinNameOffsetX = 4;
@@ -437,6 +480,8 @@ class SymbolCustom extends SymbolGraphic {
437
480
  const maxRightPins = Math.max(...rightPins.map(item => item.position)) + 1;
438
481
  const drawing = new SymbolDrawing();
439
482
  drawing.angle = this._angle;
483
+ drawing.flipX = this._flipX;
484
+ drawing.flipY = this._flipY;
440
485
  const bodyWidth = this.bodyWidth;
441
486
  const bodyHeight = (1 + Math.max(maxLeftPins, maxRightPins)) * this.pinSpacing;
442
487
  drawing.addRect(0, 0, bodyWidth, bodyHeight);
@@ -504,6 +549,8 @@ class SymbolDrawing {
504
549
  this.items = [];
505
550
  this.pins = [];
506
551
  this.angle = 0;
552
+ this.flipX = 0;
553
+ this.flipY = 0;
507
554
  this.mainOrigin = [0, 0];
508
555
  this.logger = null;
509
556
  }
@@ -683,8 +730,9 @@ class SymbolDrawing {
683
730
  }
684
731
  }
685
732
  else {
686
- const rotatedPath = geometry_js_1.Geometry.groupRotate([item], this.angle, this.mainOrigin);
687
- const { path, isClosedPolygon } = this.featuresToPath(rotatedPath);
733
+ let tmpResult = geometry_js_1.Geometry.groupFlip([item], this.flipX, this.flipY);
734
+ tmpResult = geometry_js_1.Geometry.groupRotate(tmpResult, this.angle, this.mainOrigin);
735
+ const { path, isClosedPolygon } = this.featuresToPath(tmpResult);
688
736
  pathItems.push({
689
737
  path: path,
690
738
  lineWidth: currentLineWidth,
@@ -697,9 +745,10 @@ class SymbolDrawing {
697
745
  return pathItems;
698
746
  }
699
747
  getPinsPath() {
700
- const features = this.pins.map(item => item[1]);
701
- const withAngle = geometry_js_1.Geometry.groupRotate(features, this.angle, this.mainOrigin);
702
- const { path } = this.featuresToPath(withAngle);
748
+ let features = this.pins.map(item => item[1]);
749
+ features = geometry_js_1.Geometry.groupFlip(features, this.flipX, this.flipY);
750
+ features = geometry_js_1.Geometry.groupRotate(features, this.angle, this.mainOrigin);
751
+ const { path } = this.featuresToPath(features);
703
752
  return path;
704
753
  }
705
754
  getLabels() {
@@ -720,9 +769,10 @@ class SymbolDrawing {
720
769
  }
721
770
  return accum;
722
771
  }, []);
723
- const measureItems = [...drawingFeatures, ...pinFeatures];
724
- const withAngle = geometry_js_1.Geometry.groupRotate(measureItems, this.angle, this.mainOrigin);
725
- return geometry_js_1.Geometry.groupBounds(withAngle);
772
+ let features = [...drawingFeatures, ...pinFeatures];
773
+ features = geometry_js_1.Geometry.groupFlip(features, this.flipX, this.flipY);
774
+ features = geometry_js_1.Geometry.groupRotate(features, this.angle, this.mainOrigin);
775
+ return geometry_js_1.Geometry.groupBounds(features);
726
776
  }
727
777
  getPinPosition(pinId) {
728
778
  const pin = this.pins.find(item => {
@@ -730,8 +780,9 @@ class SymbolDrawing {
730
780
  });
731
781
  if (pin) {
732
782
  const [, feature, angle] = pin;
733
- const withAngle = geometry_js_1.Geometry.rotateDegs(feature, this.angle, this.mainOrigin);
734
- const coords = geometry_js_1.Geometry.getCoords(withAngle);
783
+ let tmpFeature = geometry_js_1.Geometry.flip(feature, this.flipX, this.flipY);
784
+ tmpFeature = geometry_js_1.Geometry.rotateDegs(tmpFeature, this.angle, this.mainOrigin);
785
+ const coords = geometry_js_1.Geometry.getCoords(tmpFeature);
735
786
  return {
736
787
  start: coords[0],
737
788
  end: coords[1],
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPortSide = exports.isLabelComponent = exports.isNetComponent = exports.ExecutionContext = void 0;
3
+ exports.getPortSide = exports.ExecutionContext = void 0;
4
4
  const globals_js_1 = require("./globals.js");
5
5
  const ClassComponent_js_1 = require("./objects/ClassComponent.js");
6
6
  const ExecutionScope_js_1 = require("./objects/ExecutionScope.js");
@@ -9,7 +9,7 @@ const PinDefinition_js_1 = require("./objects/PinDefinition.js");
9
9
  const Wire_js_1 = require("./objects/Wire.js");
10
10
  const Frame_js_1 = require("./objects/Frame.js");
11
11
  class ExecutionContext {
12
- constructor(name, namespace, netNamespace, executionLevel = 0, indentLevel = 0, silent = false, logger) {
12
+ constructor(name, namespace, netNamespace, executionLevel = 0, indentLevel = 0, silent = false, logger, parent) {
13
13
  this.tmpPointId = 0;
14
14
  this.resolveNet = null;
15
15
  this.stopFurtherExpressions = false;
@@ -24,10 +24,18 @@ class ExecutionContext {
24
24
  this.scope = ExecutionScope_js_1.ExecutionScope.create();
25
25
  this.scope.indentLevel = indentLevel;
26
26
  this.setupRoot();
27
+ if (name === '__') {
28
+ this.scope.sequence.push([
29
+ ExecutionScope_js_1.SequenceAction.At,
30
+ this.scope.componentRoot,
31
+ this.scope.currentPin
32
+ ]);
33
+ }
27
34
  this.silent = silent;
28
- this.print('create new execution context', this.namespace, this.name, this.scope.indentLevel);
35
+ this.log('create new execution context', this.namespace, this.name, this.scope.indentLevel);
36
+ this.parentContext = parent;
29
37
  }
30
- print(...params) {
38
+ log(...params) {
31
39
  const indentOutput = ''.padStart(this.scope.indentLevel * 4, ' ');
32
40
  const indentLevelText = this.scope.indentLevel
33
41
  .toString()
@@ -41,18 +49,13 @@ class ExecutionContext {
41
49
  }
42
50
  setupRoot() {
43
51
  const componentRoot = ClassComponent_js_1.ClassComponent.simple(globals_js_1.GlobalNames.__root, 1, '__root');
44
- componentRoot.typeProp = globals_js_1.ComponentTypes.net;
52
+ componentRoot.typeProp = globals_js_1.ComponentTypes.point;
53
+ componentRoot.displayProp = 'point';
45
54
  this.scope.instances.set(globals_js_1.GlobalNames.__root, componentRoot);
46
55
  this.scope.currentComponent = componentRoot;
47
56
  this.scope.currentPin = componentRoot.getDefaultPin();
48
57
  this.scope.componentRoot = componentRoot;
49
58
  }
50
- instanceExists(instanceName) {
51
- return this.scope.instances.has(instanceName);
52
- }
53
- getComponent(instanceName) {
54
- return this.scope.instances.get(instanceName);
55
- }
56
59
  getUniqueInstanceName(className) {
57
60
  let extraPrefix = '';
58
61
  switch (className) {
@@ -87,7 +90,7 @@ class ExecutionContext {
87
90
  const net2 = net2_exists
88
91
  ? this.scope.getNet(component2, component2Pin)
89
92
  : null;
90
- this.print('link nets', component1, component1Pin, net1, 'to', component2, component2Pin, net2);
93
+ this.log('link nets', component1, component1Pin, net1, 'to', component2, component2Pin, net2);
91
94
  let returnNet;
92
95
  if (net1 === null && net2 === null) {
93
96
  const tmpNet = new Net_js_1.Net(this.netNamespace, this.getUniqueNetName());
@@ -137,33 +140,34 @@ class ExecutionContext {
137
140
  pins.forEach((pin) => {
138
141
  component.pins.set(pin.id, pin);
139
142
  });
143
+ component.arrangeProps = props.arrange ?? null;
144
+ component.displayProp = props.display ?? null;
145
+ component.widthProp = props.width ?? null;
146
+ component.typeProp = props.type ?? null;
147
+ component.copyProp = props.copy ?? false;
140
148
  const paramsMap = new Map();
141
149
  params.forEach((param) => {
142
150
  component.parameters.set(param.paramName, param.paramValue);
143
151
  paramsMap.set(param.paramName, param.paramValue);
144
152
  });
145
- if (paramsMap.has(globals_js_1.ParamKeys.__is_net)) {
153
+ if (component.typeProp === globals_js_1.ComponentTypes.net
154
+ || component.typeProp === globals_js_1.ComponentTypes.label) {
146
155
  const netName = paramsMap.get(globals_js_1.ParamKeys.net_name);
147
156
  const priority = paramsMap.get(globals_js_1.ParamKeys.priority);
148
157
  const result = this.resolveNet(netName, this.netNamespace);
149
158
  let tmpNet;
150
159
  if (result.found) {
151
160
  tmpNet = result.net;
152
- this.print('net found', tmpNet.namespace, tmpNet.name);
161
+ this.log('net found', tmpNet.namespace, tmpNet.name);
153
162
  }
154
163
  else {
155
164
  tmpNet = new Net_js_1.Net(this.netNamespace, netName, priority);
156
- this.print('net not found, added net instance', tmpNet.namespace, tmpNet.name);
165
+ this.log('net not found, added net instance', tmpNet.namespace, tmpNet.name);
157
166
  }
158
167
  this.scope.setNet(component, 1, tmpNet);
159
- this.print('set net', netName, 'component', component);
168
+ this.log('set net', netName, 'component', component);
160
169
  }
161
- const { arrange = null } = props;
162
- component.arrangeProps = arrange;
163
- component.displayProp = props.display ?? null;
164
- component.widthProp = props.width ?? null;
165
- component.typeProp = props.type ?? null;
166
- const portSides = getPortSide(component.pins, arrange);
170
+ const portSides = getPortSide(component.pins, component.arrangeProps);
167
171
  portSides.forEach(({ pinId, side, position }) => {
168
172
  if (component.pins.has(pinId)) {
169
173
  const tmpPin = component.pins.get(pinId);
@@ -175,17 +179,21 @@ class ExecutionContext {
175
179
  const pinsOutput = pins.map((pin) => {
176
180
  return pin.id + ':' + pin.name;
177
181
  });
178
- this.print('add symbol', instanceName, '[' + pinsOutput.join(', ') + ']');
182
+ this.log('add symbol', instanceName, '[' + pinsOutput.join(', ') + ']');
179
183
  return component;
180
184
  }
181
185
  printPoint(extra = '') {
182
186
  let netName = globals_js_1.NoNetText;
187
+ if (this.scope.currentComponent === null || this.scope.currentPin === null) {
188
+ this.log((extra !== '' ? (extra + ' ') : '') + 'point is null');
189
+ return;
190
+ }
183
191
  if (this.scope.hasNet(this.scope.currentComponent, this.scope.currentPin)) {
184
192
  netName = this.scope
185
193
  .getNet(this.scope.currentComponent, this.scope.currentPin)
186
194
  .toString();
187
195
  }
188
- this.print((extra !== '' ? (extra + ' ') : '') + 'point: ' +
196
+ this.log((extra !== '' ? (extra + ' ') : '') + 'point: ' +
189
197
  this.scope.currentComponent.instanceName +
190
198
  ' ' +
191
199
  this.scope.currentPin + ' ' + netName);
@@ -194,7 +202,7 @@ class ExecutionContext {
194
202
  const startPin = pin;
195
203
  const nextPin = component.getNextPinAfter(startPin);
196
204
  this.toComponent(component, startPin, { addSequence: true });
197
- this.print('move to next pin: ' + nextPin);
205
+ this.log('move to next pin: ' + nextPin);
198
206
  this.atComponent(component, nextPin, {
199
207
  addSequence: true
200
208
  });
@@ -202,11 +210,8 @@ class ExecutionContext {
202
210
  return this.getCurrentPoint();
203
211
  }
204
212
  toComponent(component, pinId, options) {
205
- this.print('to component');
206
- const { addSequence = false, cloneNetComponent = false } = options ?? {};
207
- if (cloneNetComponent && this.isNetOnlyComponent(component)) {
208
- component = this.cloneComponent(component);
209
- }
213
+ this.log('to component');
214
+ const { addSequence = false } = options ?? {};
210
215
  if (!(component instanceof ClassComponent_js_1.ClassComponent)) {
211
216
  throw "Not a valid component!";
212
217
  }
@@ -226,7 +231,7 @@ class ExecutionContext {
226
231
  }
227
232
  }
228
233
  if (this.scope.hasNet(this.scope.currentComponent, this.scope.currentPin)) {
229
- this.print('net: ', this.scope
234
+ this.log('net: ', this.scope
230
235
  .getNet(this.scope.currentComponent, this.scope.currentPin)
231
236
  .toString());
232
237
  }
@@ -253,11 +258,8 @@ class ExecutionContext {
253
258
  return this.getCurrentPoint();
254
259
  }
255
260
  atComponent(component, pinId, options) {
256
- this.print('at component');
257
- const { addSequence = false, cloneNetComponent = false } = options ?? {};
258
- if (cloneNetComponent && this.isNetOnlyComponent(component)) {
259
- component = this.cloneComponent(component);
260
- }
261
+ this.log('at component');
262
+ const { addSequence = false } = options ?? {};
261
263
  this.scope.currentComponent = component;
262
264
  let usePinId;
263
265
  if (pinId === null) {
@@ -282,25 +284,22 @@ class ExecutionContext {
282
284
  this.printPoint();
283
285
  return this.getCurrentPoint();
284
286
  }
285
- isNetOnlyComponent(component) {
286
- return isNetComponent(component) && !isLabelComponent(component);
287
- }
288
- cloneComponent(component) {
289
- let clonedComponent = null;
287
+ copyComponent(component) {
288
+ let componentCopy = null;
290
289
  if (!this.scope.copyIDs.has(component.instanceName)) {
291
290
  this.scope.copyIDs.set(component.instanceName, 0);
292
291
  }
293
292
  const idNum = this.scope.copyIDs.get(component.instanceName);
294
- clonedComponent = component.clone();
295
- clonedComponent._copyID = idNum;
296
- clonedComponent._copyFrom = component;
293
+ componentCopy = component.clone();
294
+ componentCopy._copyID = idNum;
295
+ componentCopy._copyFrom = component;
297
296
  this.scope.copyIDs.set(component.instanceName, idNum + 1);
298
297
  const cloneInstanceName = component.instanceName + ':' + idNum;
299
- this.scope.instances.set(cloneInstanceName, clonedComponent);
300
- clonedComponent.instanceName = cloneInstanceName;
301
- this.linkComponentPinNet(component, 1, clonedComponent, 1);
302
- this.print('created clone of net component:', cloneInstanceName);
303
- return clonedComponent;
298
+ this.scope.instances.set(cloneInstanceName, componentCopy);
299
+ componentCopy.instanceName = cloneInstanceName;
300
+ this.linkComponentPinNet(component, 1, componentCopy, 1);
301
+ this.log('created clone of net component:', cloneInstanceName);
302
+ return componentCopy;
304
303
  }
305
304
  enterBlocks(blockType) {
306
305
  if (blockType === globals_js_1.BlockTypes.Point) {
@@ -321,7 +320,7 @@ class ExecutionContext {
321
320
  current_index: null,
322
321
  type: blockType,
323
322
  });
324
- this.print('enter blocks');
323
+ this.log('enter blocks');
325
324
  }
326
325
  exitBlocks() {
327
326
  const stackRef = this.scope.blockStack.get(this.scope.indentLevel);
@@ -342,7 +341,7 @@ class ExecutionContext {
342
341
  const { entered_at: [component, pin,] } = stackRef;
343
342
  this.atComponent(component, pin, { addSequence: true });
344
343
  }
345
- this.print('exit blocks');
344
+ this.log('exit blocks');
346
345
  }
347
346
  enterBlock(blockIndex) {
348
347
  const stackRef = this.scope.blockStack.get(this.scope.indentLevel);
@@ -361,7 +360,7 @@ class ExecutionContext {
361
360
  const { entered_at: [component, pin,] } = stackRef;
362
361
  this.atComponent(component, pin, { addSequence: true });
363
362
  }
364
- this.print(`enter inner block of type (${blockType}) >>>`);
363
+ this.log(`enter inner block of type (${blockType}) >>>`);
365
364
  this.scope.indentLevel += 1;
366
365
  }
367
366
  exitBlock(blockIndex) {
@@ -375,7 +374,7 @@ class ExecutionContext {
375
374
  ];
376
375
  stackRef['block_index'] = null;
377
376
  this.scope.indentLevel -= 1;
378
- this.print('exit inner block <<<');
377
+ this.log('exit inner block <<<');
379
378
  if (blockType === globals_js_1.BlockTypes.Branch) {
380
379
  const { entered_at: [component, pin, wireId] } = stackRef;
381
380
  this.atComponent(component, pin, { addSequence: true });
@@ -414,7 +413,7 @@ class ExecutionContext {
414
413
  });
415
414
  }
416
415
  getPointBlockLocation() {
417
- this.print('get block point');
416
+ this.log('get block point');
418
417
  for (let i = 0; i < this.scope.indentLevel; i++) {
419
418
  const stackRef = this.scope.blockStack.get(this.scope.indentLevel - 1 - i);
420
419
  const { entered_at } = stackRef;
@@ -423,11 +422,11 @@ class ExecutionContext {
423
422
  return entered_at;
424
423
  }
425
424
  }
426
- this.print('did not find block point');
425
+ this.log('did not find block point');
427
426
  return null;
428
427
  }
429
428
  breakBranch() {
430
- this.print('break branch');
429
+ this.log('break branch');
431
430
  const branchesInfo = this.scope.blockStack.get(this.scope.indentLevel - 1);
432
431
  const branchIndex = branchesInfo['block_index'];
433
432
  const branchIndexRef = branchesInfo['inner_blocks'].get(branchIndex);
@@ -436,7 +435,7 @@ class ExecutionContext {
436
435
  createFunction(functionName, __runFunc) {
437
436
  this.scope.functions.set(functionName, __runFunc);
438
437
  this.__functionCache[functionName] = __runFunc;
439
- this.print(`defined new function '${functionName}'`);
438
+ this.log(`defined new function '${functionName}'`);
440
439
  }
441
440
  hasFunction(functionName) {
442
441
  return this.scope.functions.has(functionName);
@@ -485,7 +484,7 @@ class ExecutionContext {
485
484
  __runFunc = this.getFunction(functionName);
486
485
  }
487
486
  if (__runFunc === null) {
488
- this.print(`searching for function ${functionName} in upper context`);
487
+ this.log(`searching for function ${functionName} in upper context`);
489
488
  const tmpResolveResult = this.resolveVariable(executionStack, functionName);
490
489
  if (tmpResolveResult.found) {
491
490
  __runFunc = tmpResolveResult.value;
@@ -494,17 +493,17 @@ class ExecutionContext {
494
493
  throw `Invalid function ${functionName}`;
495
494
  }
496
495
  }
497
- this.print('save function to cache:', functionName);
496
+ this.log('save function to cache:', functionName);
498
497
  this.__functionCache[functionName] = __runFunc;
499
498
  }
500
499
  else {
501
- this.print('found function in cache:', functionName);
500
+ this.log('found function in cache:', functionName);
502
501
  __runFunc = this.__functionCache[functionName];
503
502
  }
504
503
  if (__runFunc !== null) {
505
- this.print(`call function '${functionName}'`);
504
+ this.log(`call function '${functionName}'`);
506
505
  const functionResult = __runFunc(functionParams, { netNamespace });
507
- this.print(`done call function '${functionName}'`);
506
+ this.log(`done call function '${functionName}'`);
508
507
  return functionResult;
509
508
  }
510
509
  else {
@@ -512,7 +511,7 @@ class ExecutionContext {
512
511
  }
513
512
  }
514
513
  mergeScope(childScope, namespace) {
515
- this.print('-- merging scope to parent --');
514
+ this.log('-- merging scope to parent --');
516
515
  const currentComponent = this.scope.currentComponent;
517
516
  const currentPin = this.scope.currentPin;
518
517
  const currentWireId = this.scope.currentWireId;
@@ -567,7 +566,8 @@ class ExecutionContext {
567
566
  }
568
567
  else if (action === ExecutionScope_js_1.SequenceAction.At || action === ExecutionScope_js_1.SequenceAction.To) {
569
568
  const tmpComponent = sequenceAction[1];
570
- if (isNetComponent(tmpComponent) && tmpComponent.parameters.get(globals_js_1.ParamKeys.net_name) === 'gnd') {
569
+ if (tmpComponent.typeProp === globals_js_1.ComponentTypes.net
570
+ && tmpComponent.parameters.get(globals_js_1.ParamKeys.net_name) === 'gnd') {
571
571
  tmpComponent._copyID = gndCopyIdOffset + incrementGndLinkId;
572
572
  incrementGndLinkId += 1;
573
573
  }
@@ -602,16 +602,16 @@ class ExecutionContext {
602
602
  this.scope.currentWireId = childScope.currentWireId + wireIdOffset;
603
603
  }
604
604
  this.printPoint('resume at');
605
- this.print('-- nets --');
605
+ this.log('-- nets --');
606
606
  const currentNets = this.scope.getNets();
607
607
  currentNets.reduce((accum, [, , net]) => {
608
608
  if (accum.indexOf(net) === -1) {
609
609
  accum.push(net);
610
- this.print(`${net.namespace}${net.name} ${net.priority}`);
610
+ this.log(`${net.namespace}${net.name} ${net.priority}`);
611
611
  }
612
612
  return accum;
613
613
  }, []);
614
- this.print('-- done merging scope --');
614
+ this.log('-- done merging scope --');
615
615
  }
616
616
  addWire(segments) {
617
617
  if (this.scope.currentComponent === null) {
@@ -630,14 +630,14 @@ class ExecutionContext {
630
630
  segments.forEach(item => {
631
631
  output.push(item.join(","));
632
632
  });
633
- this.print('add wire: ', output.join("|"));
633
+ this.log('add wire: ', output.join("|"));
634
634
  this.scope.setActive(ExecutionScope_js_1.ActiveObject.Wire, wireId);
635
635
  this.scope.sequence.push([ExecutionScope_js_1.SequenceAction.Wire, wireId, tmp]);
636
636
  this.scope.currentComponent.pinWires.set(this.scope.currentPin, tmp);
637
637
  }
638
638
  addPoint(pointId, userDefined = true) {
639
639
  if (this.scope.instances.has(pointId)) {
640
- this.print('Warning: ' + pointId + ' is being redefined');
640
+ this.log('Warning: ' + pointId + ' is being redefined');
641
641
  }
642
642
  const useName = userDefined ? 'point.' + pointId : pointId;
643
643
  const componentPoint = ClassComponent_js_1.ClassComponent.simple(useName, 1, "point");
@@ -648,7 +648,7 @@ class ExecutionContext {
648
648
  return this.getCurrentPoint();
649
649
  }
650
650
  setProperty(nameWithProp, value) {
651
- this.print('set property', nameWithProp, 'value', value);
651
+ this.log('set property', nameWithProp, 'value', value);
652
652
  let idName;
653
653
  let paramName;
654
654
  let useActive = false;
@@ -709,14 +709,6 @@ function isWireSegmentsEndAuto(segments) {
709
709
  }
710
710
  return false;
711
711
  }
712
- function isNetComponent(component) {
713
- return component.parameters.has(globals_js_1.ParamKeys.__is_net);
714
- }
715
- exports.isNetComponent = isNetComponent;
716
- function isLabelComponent(component) {
717
- return component.parameters.has(globals_js_1.ParamKeys.__is_label);
718
- }
719
- exports.isLabelComponent = isLabelComponent;
720
712
  function getPortSide(pins, arrangeProps) {
721
713
  const result = [];
722
714
  if (arrangeProps === null) {