circuitscript 0.1.15 → 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 (49) hide show
  1. package/dist/cjs/BaseVisitor.js +98 -35
  2. package/dist/cjs/antlr/CircuitScriptLexer.js +3 -3
  3. package/dist/cjs/antlr/CircuitScriptParser.js +868 -757
  4. package/dist/cjs/builtinMethods.js +11 -1
  5. package/dist/cjs/draw_symbols.js +18 -17
  6. package/dist/cjs/execute.js +58 -31
  7. package/dist/cjs/globals.js +4 -1
  8. package/dist/cjs/graph.js +372 -0
  9. package/dist/cjs/helpers.js +6 -2
  10. package/dist/cjs/layout.js +18 -259
  11. package/dist/cjs/objects/ClassComponent.js +27 -20
  12. package/dist/cjs/objects/ExecutionScope.js +7 -2
  13. package/dist/cjs/objects/Net.js +1 -1
  14. package/dist/cjs/objects/PinDefinition.js +55 -3
  15. package/dist/cjs/objects/types.js +42 -6
  16. package/dist/cjs/visitor.js +88 -48
  17. package/dist/esm/BaseVisitor.js +98 -35
  18. package/dist/esm/antlr/CircuitScriptLexer.js +3 -3
  19. package/dist/esm/antlr/CircuitScriptParser.js +864 -755
  20. package/dist/esm/antlr/CircuitScriptVisitor.js +2 -0
  21. package/dist/esm/builtinMethods.js +11 -1
  22. package/dist/esm/draw_symbols.js +18 -17
  23. package/dist/esm/execute.js +60 -33
  24. package/dist/esm/globals.js +3 -0
  25. package/dist/esm/graph.js +344 -0
  26. package/dist/esm/helpers.js +6 -2
  27. package/dist/esm/layout.js +14 -235
  28. package/dist/esm/objects/ClassComponent.js +28 -21
  29. package/dist/esm/objects/ExecutionScope.js +7 -2
  30. package/dist/esm/objects/Net.js +1 -1
  31. package/dist/esm/objects/PinDefinition.js +53 -2
  32. package/dist/esm/objects/types.js +42 -6
  33. package/dist/esm/visitor.js +90 -50
  34. package/dist/libs/std.cst +3 -2
  35. package/dist/types/BaseVisitor.d.ts +5 -2
  36. package/dist/types/antlr/CircuitScriptParser.d.ts +42 -26
  37. package/dist/types/antlr/CircuitScriptVisitor.d.ts +4 -0
  38. package/dist/types/draw_symbols.d.ts +13 -7
  39. package/dist/types/execute.d.ts +12 -12
  40. package/dist/types/globals.d.ts +4 -1
  41. package/dist/types/graph.d.ts +29 -0
  42. package/dist/types/layout.d.ts +4 -9
  43. package/dist/types/objects/ClassComponent.d.ts +8 -8
  44. package/dist/types/objects/ExecutionScope.d.ts +8 -7
  45. package/dist/types/objects/Net.d.ts +2 -2
  46. package/dist/types/objects/PinDefinition.d.ts +17 -2
  47. package/dist/types/objects/types.d.ts +31 -7
  48. package/libs/std.cst +3 -2
  49. package/package.json +2 -1
@@ -1,46 +1,26 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
4
  };
25
5
  Object.defineProperty(exports, "__esModule", { value: true });
26
6
  exports.ExtractDrawingRects = exports.CalculatePinPositions = exports.RenderJunction = exports.RenderFrameType = exports.RenderFrame = exports.RenderText = exports.RenderComponent = exports.RenderWire = exports.RenderObject = exports.getBounds = exports.applyComponentParamsToSymbol = exports.LayoutEngine = void 0;
27
- const graphlib_1 = __importStar(require("@dagrejs/graphlib"));
7
+ const graphlib_1 = __importDefault(require("@dagrejs/graphlib"));
28
8
  const { alg } = graphlib_1.default;
29
9
  const draw_symbols_js_1 = require("./draw_symbols.js");
30
- const ExecutionScope_js_1 = require("./objects/ExecutionScope.js");
31
10
  const globals_js_1 = require("./globals.js");
32
11
  const geometry_js_1 = require("./geometry.js");
33
- const logger_js_1 = require("./logger.js");
34
12
  const Frame_js_1 = require("./objects/Frame.js");
35
13
  const utils_js_1 = require("./utils.js");
36
14
  const types_js_1 = require("./objects/types.js");
15
+ const PinDefinition_js_1 = require("./objects/PinDefinition.js");
37
16
  const helpers_js_1 = require("./helpers.js");
38
17
  const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
18
+ const graph_js_1 = require("./graph.js");
39
19
  class LayoutEngine {
40
- constructor(options = { showBaseFrame: false }) {
20
+ constructor(logger, options = { showBaseFrame: false }) {
41
21
  this.layoutWarnings = [];
42
22
  this.showBaseFrame = false;
43
- this.logger = new logger_js_1.Logger();
23
+ this.logger = logger;
44
24
  const { showBaseFrame = false } = options ?? {};
45
25
  this.showBaseFrame = showBaseFrame;
46
26
  }
@@ -54,30 +34,8 @@ class LayoutEngine {
54
34
  const padding = ''.padStart(value * 4, ' ');
55
35
  return "[" + value + "]" + padding;
56
36
  }
57
- runLayout(sequence, nets) {
58
- const logNodesAndEdges = true;
37
+ runLayout(graph, containerFrames, nets) {
59
38
  const renderNets = this.collectRenderNets(nets);
60
- this.print('===== creating graph and populating with nodes =====');
61
- const { graph, containerFrames } = this.generateLayoutGraph(sequence, nets);
62
- this.print('===== done populating graph =====');
63
- this.print('');
64
- if (logNodesAndEdges) {
65
- this.print('===== graph edges =====');
66
- const allEdges = graph.edges();
67
- allEdges.forEach(edge => {
68
- const [nodeId1, pin1, nodeId2, pin2] = graph.edge(edge);
69
- this.print(nodeId1, 'pin', pin1, '-----', nodeId2, 'pin', pin2);
70
- });
71
- this.print('===== end edges =====');
72
- this.print();
73
- this.print('===== graph nodes =====');
74
- const nodes = graph.nodes();
75
- nodes.forEach(node => {
76
- this.print(`name:${node}, value:${graph.node(node)}`);
77
- });
78
- this.print('===== end nodes =====');
79
- this.print('');
80
- }
81
39
  const subgraphInfo = this.sizeSubGraphs(graph);
82
40
  const dumpSubgraphInfo = true;
83
41
  if (dumpSubgraphInfo) {
@@ -584,7 +542,7 @@ class LayoutEngine {
584
542
  return item.component.instanceName;
585
543
  }
586
544
  else if (item instanceof RenderWire) {
587
- return getWireName(item.id);
545
+ return (0, graph_js_1.getWireName)(item.id);
588
546
  }
589
547
  return null;
590
548
  }));
@@ -668,158 +626,6 @@ class LayoutEngine {
668
626
  }
669
627
  }
670
628
  }
671
- generateLayoutGraph(sequence, nets) {
672
- let previousNode = null;
673
- let previousPin = null;
674
- const graph = new graphlib_1.Graph({
675
- directed: true,
676
- compound: true,
677
- });
678
- this.print('sequence length:', sequence.length);
679
- const baseFrame = new RenderFrame(new Frame_js_1.Frame(Frame_js_1.FixedFrameIds.BaseFrame));
680
- const frameStack = [baseFrame];
681
- const containerFrames = [baseFrame];
682
- sequence.forEach((sequenceStep, index) => {
683
- const action = sequenceStep[0];
684
- let tmpComponent;
685
- switch (action) {
686
- case ExecutionScope_js_1.SequenceAction.To:
687
- case ExecutionScope_js_1.SequenceAction.At: {
688
- this.print(...sequenceStep);
689
- const [, component, pin] = sequenceStep;
690
- const tmpInstanceName = component.instanceName;
691
- if (!graph.hasNode(tmpInstanceName)) {
692
- this.print('create instance', tmpInstanceName);
693
- const { displayProp = null } = component;
694
- let tmpSymbol;
695
- if (displayProp instanceof draw_symbols_js_1.SymbolDrawing) {
696
- tmpSymbol = new draw_symbols_js_1.SymbolPlaceholder(displayProp);
697
- tmpSymbol.drawing.logger = this.logger;
698
- }
699
- else {
700
- const symbolPinDefinitions = generateLayoutPinDefinition(component);
701
- if (component.typeProp === globals_js_1.ComponentTypes.module) {
702
- tmpSymbol = new draw_symbols_js_1.SymbolCustomModule(symbolPinDefinitions, component.pinsMaxPositions);
703
- }
704
- else {
705
- tmpSymbol = new draw_symbols_js_1.SymbolCustom(symbolPinDefinitions, component.pinsMaxPositions);
706
- }
707
- }
708
- applyComponentParamsToSymbol(component, tmpSymbol);
709
- tmpSymbol.refreshDrawing();
710
- const { width: useWidth, height: useHeight } = tmpSymbol.size();
711
- tmpComponent = new RenderComponent(component, useWidth, useHeight);
712
- tmpComponent.symbol = tmpSymbol;
713
- graph.setNode(tmpInstanceName, [RenderItemType.Component, tmpComponent, index]);
714
- const currentFrame = frameStack[frameStack.length - 1];
715
- currentFrame && currentFrame.innerItems.push(tmpComponent);
716
- }
717
- if (action === ExecutionScope_js_1.SequenceAction.To && previousNode && previousPin) {
718
- this.setGraphEdge(graph, previousNode, tmpInstanceName, makeEdgeValue(previousNode, previousPin, tmpInstanceName, pin, index));
719
- }
720
- previousNode = tmpInstanceName;
721
- previousPin = pin;
722
- break;
723
- }
724
- case ExecutionScope_js_1.SequenceAction.Wire: {
725
- const [, wireId, wireSegments] = sequenceStep;
726
- let useNet;
727
- if (previousNode !== null) {
728
- const [prevNodeType, prevNodeItem] = graph.node(previousNode);
729
- if (prevNodeType === RenderItemType.Component) {
730
- const matchingItem = nets.find(([comp, pin]) => {
731
- return comp.instanceName === previousNode
732
- && pin === previousPin;
733
- });
734
- if (matchingItem !== undefined) {
735
- useNet = matchingItem[2];
736
- }
737
- }
738
- else if (prevNodeType === RenderItemType.Wire) {
739
- useNet = prevNodeItem.net;
740
- }
741
- }
742
- const wire = new RenderWire(useNet, (0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0), wireSegments);
743
- wire.id = wireId;
744
- wire.netName = useNet.toString();
745
- const wireName = getWireName(wire.id);
746
- graph.setNode(wireName, [RenderItemType.Wire, wire, index]);
747
- this.setGraphEdge(graph, previousNode, wireName, makeEdgeValue(previousNode, previousPin, wireName, 0, index));
748
- previousNode = wireName;
749
- previousPin = 1;
750
- const wireSegmentsInfo = wireSegments.map(item => {
751
- const tmp = {
752
- direction: item.direction,
753
- value: item.value,
754
- };
755
- if (item.valueXY) {
756
- tmp.valueXY = item.valueXY;
757
- }
758
- if (item.until) {
759
- tmp.until = [item.until[0].toString(), item.until[1]];
760
- }
761
- return tmp;
762
- });
763
- this.print(ExecutionScope_js_1.SequenceAction.Wire, wireId, JSON.stringify(wireSegmentsInfo));
764
- break;
765
- }
766
- case ExecutionScope_js_1.SequenceAction.WireJump: {
767
- this.print(...sequenceStep);
768
- const wireId = sequenceStep[1];
769
- const wireName = getWireName(wireId);
770
- let wirePin = 1;
771
- if (sequenceStep.length === 3) {
772
- wirePin = sequenceStep[2];
773
- }
774
- previousNode = wireName;
775
- previousPin = wirePin;
776
- break;
777
- }
778
- case ExecutionScope_js_1.SequenceAction.Frame: {
779
- const [, frameObject, frameAction] = sequenceStep;
780
- if (frameAction === ExecutionScope_js_1.FrameAction.Enter) {
781
- const prevFrame = frameStack[frameStack.length - 1];
782
- const newFrame = new RenderFrame(frameObject);
783
- if (frameObject.parameters.has(Frame_js_1.FrameParamKeys.Direction)) {
784
- newFrame.direction =
785
- frameObject.parameters.get(Frame_js_1.FrameParamKeys.Direction);
786
- }
787
- if (frameObject.parameters.has(Frame_js_1.FrameParamKeys.Padding)) {
788
- newFrame.padding = (0, helpers_js_1.milsToMM)(frameObject.parameters.get(Frame_js_1.FrameParamKeys.Padding));
789
- }
790
- if (frameObject.parameters.has(Frame_js_1.FrameParamKeys.Border)) {
791
- newFrame.borderWidth =
792
- frameObject.parameters.get(Frame_js_1.FrameParamKeys.Border);
793
- }
794
- if (frameObject.parameters.has(Frame_js_1.FrameParamKeys.Width)) {
795
- newFrame.width = (0, helpers_js_1.milsToMM)(frameObject.parameters.get(Frame_js_1.FrameParamKeys.Width));
796
- }
797
- if (frameObject.parameters.has(Frame_js_1.FrameParamKeys.Height)) {
798
- newFrame.height = (0, helpers_js_1.milsToMM)(frameObject.parameters.get(Frame_js_1.FrameParamKeys.Height));
799
- }
800
- containerFrames.push(newFrame);
801
- frameStack.push(newFrame);
802
- prevFrame && prevFrame.innerItems.push(newFrame);
803
- }
804
- else if (frameAction === ExecutionScope_js_1.FrameAction.Exit) {
805
- frameStack.pop();
806
- }
807
- break;
808
- }
809
- }
810
- });
811
- return {
812
- graph,
813
- containerFrames,
814
- };
815
- }
816
- setGraphEdge(graph, node1, node2, edgeValue) {
817
- if (!graph.isDirected && graph.hasEdge(node1, node2)) {
818
- this.print(`Warning: edge already exists ${node1} ${node2}`);
819
- }
820
- graph.setEdge(node1, node2, edgeValue);
821
- this.print(`created edge: node1:${node1} node2:${node2} edgeValue:${edgeValue}`);
822
- }
823
629
  sizeSubGraphs(graph) {
824
630
  const subGraphs = alg.components(graph);
825
631
  const subGraphsStarts = [];
@@ -847,10 +653,10 @@ class LayoutEngine {
847
653
  const wires = [];
848
654
  innerGraph.forEach(nodeId => {
849
655
  const [nodeType, item,] = graph.node(nodeId);
850
- if (nodeType === RenderItemType.Component) {
656
+ if (nodeType === graph_js_1.RenderItemType.Component) {
851
657
  renderItems.push(item);
852
658
  }
853
- else if (nodeType === RenderItemType.Wire) {
659
+ else if (nodeType === graph_js_1.RenderItemType.Wire) {
854
660
  wires.push(item);
855
661
  }
856
662
  });
@@ -889,7 +695,11 @@ class LayoutEngine {
889
695
  }
890
696
  if (subgraphEdges.length === 0) {
891
697
  const [, node1] = graph.node(firstNodeId);
892
- this.placeNodeAtPosition((0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0), node1, 1);
698
+ let defaultPin = new PinDefinition_js_1.PinId(1);
699
+ if (node1 instanceof RenderComponent) {
700
+ defaultPin = node1.component.getDefaultPin();
701
+ }
702
+ this.placeNodeAtPosition((0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0), node1, defaultPin);
893
703
  return;
894
704
  }
895
705
  let fixedNode;
@@ -1118,52 +928,6 @@ function getNeighbours(graph, nodeIds) {
1118
928
  return accum;
1119
929
  }, []);
1120
930
  }
1121
- function makeEdgeValue(instanceName1, instancePin1, instanceName2, instancePin2, priority) {
1122
- return [instanceName1, instancePin1, instanceName2, instancePin2, priority];
1123
- }
1124
- function getWireName(wireId) {
1125
- return 'wire:' + wireId;
1126
- }
1127
- function generateLayoutPinDefinition(component) {
1128
- const pins = component.pins;
1129
- const symbolPinDefinitions = [];
1130
- const existingPinIds = Array.from(pins.keys());
1131
- const arrangeProps = component.arrangeProps ?? [];
1132
- const addedPins = [];
1133
- for (const [key, items] of arrangeProps) {
1134
- let useItems;
1135
- if (!Array.isArray(items)) {
1136
- useItems = [items];
1137
- }
1138
- else {
1139
- useItems = [...items];
1140
- }
1141
- useItems.forEach(pinId => {
1142
- if (pinId instanceof ParamDefinition_js_1.NumericValue) {
1143
- const pinIdValue = pinId.toNumber();
1144
- if (existingPinIds.indexOf(pinIdValue) !== -1) {
1145
- const pin = pins.get(pinIdValue);
1146
- symbolPinDefinitions.push({
1147
- side: key,
1148
- pinId: pinIdValue,
1149
- text: pin.name,
1150
- position: pin.position,
1151
- pinType: pin.pinType,
1152
- });
1153
- addedPins.push(pinIdValue);
1154
- }
1155
- }
1156
- });
1157
- }
1158
- const unplacedPins = existingPinIds.filter(pinId => {
1159
- return addedPins.indexOf(pinId) === -1;
1160
- });
1161
- if (unplacedPins.length > 0) {
1162
- component._unplacedPins = unplacedPins;
1163
- console.warn("Warning: There are unplaced pins: " + unplacedPins);
1164
- }
1165
- return symbolPinDefinitions;
1166
- }
1167
931
  function applyComponentParamsToSymbol(component, symbol) {
1168
932
  const { widthProp = null, heightProp = null } = component;
1169
933
  const newMap = new Map(component.parameters);
@@ -1413,7 +1177,7 @@ class RenderWire extends RenderObject {
1413
1177
  this.refreshPoints();
1414
1178
  }
1415
1179
  toString() {
1416
- return getWireName(this.id);
1180
+ return (0, graph_js_1.getWireName)(this.id);
1417
1181
  }
1418
1182
  }
1419
1183
  exports.RenderWire = RenderWire;
@@ -1512,7 +1276,7 @@ function CalculatePinPositions(component) {
1512
1276
  tmpSymbol = new draw_symbols_js_1.SymbolPlaceholder(component.displayProp);
1513
1277
  }
1514
1278
  else {
1515
- const symbolPinDefinitions = generateLayoutPinDefinition(component);
1279
+ const symbolPinDefinitions = (0, graph_js_1.generateLayoutPinDefinition)(component);
1516
1280
  tmpSymbol = new draw_symbols_js_1.SymbolCustom(symbolPinDefinitions, component.pinsMaxPositions);
1517
1281
  }
1518
1282
  applyComponentParamsToSymbol(component, tmpSymbol);
@@ -1548,8 +1312,3 @@ exports.ExtractDrawingRects = ExtractDrawingRects;
1548
1312
  function isPointOverlap(x, y, other) {
1549
1313
  return (x >= other.x && y >= other.y && x <= (other.x + other.width) && y <= (other.y + other.height));
1550
1314
  }
1551
- var RenderItemType;
1552
- (function (RenderItemType) {
1553
- RenderItemType["Wire"] = "wire";
1554
- RenderItemType["Component"] = "component";
1555
- })(RenderItemType || (RenderItemType = {}));
@@ -5,6 +5,7 @@ const draw_symbols_js_1 = require("../draw_symbols.js");
5
5
  const PinDefinition_js_1 = require("./PinDefinition.js");
6
6
  const PinTypes_js_1 = require("./PinTypes.js");
7
7
  const globals_js_1 = require("../globals.js");
8
+ const utils_js_1 = require("../utils.js");
8
9
  class ClassComponent {
9
10
  constructor(instanceName, numPins) {
10
11
  this.parameters = new Map();
@@ -33,47 +34,53 @@ class ClassComponent {
33
34
  setupPins() {
34
35
  for (let i = 1; i < this.numPins + 1; i++) {
35
36
  const pinIndex = i;
36
- this.pins.set(pinIndex, new PinDefinition_js_1.PinDefinition(pinIndex, PinDefinition_js_1.PinIdType.Int, pinIndex.toString(), PinTypes_js_1.PinTypes.Any));
37
+ this.pins.set(new PinDefinition_js_1.PinId(pinIndex), new PinDefinition_js_1.PinDefinition(pinIndex, PinDefinition_js_1.PinIdType.Int, pinIndex.toString(), PinTypes_js_1.PinTypes.Any));
37
38
  }
38
39
  this.refreshPinsCache();
39
40
  }
40
41
  getDefaultPin() {
41
- return 1;
42
+ const pins = Array.from(this.pins.keys());
43
+ pins.sort();
44
+ return pins[0];
42
45
  }
43
46
  hasPin(pinId) {
44
- if (typeof pinId === 'number') {
45
- return this.pins.has(pinId);
46
- }
47
- else {
48
- for (const [, pinDef] of this.pins) {
49
- if (pinDef.name === pinId ||
50
- pinDef.altNames.indexOf(pinId) !== -1) {
51
- return true;
52
- }
47
+ for (const [pin, pinDef] of this.pins) {
48
+ if (pin.equals(pinId)) {
49
+ return true;
50
+ }
51
+ if (pinId.getType() === PinDefinition_js_1.PinIdType.Str && (pinDef.name === pinId.getValue() ||
52
+ pinDef.altNames.indexOf(pinId.getValue()) !== -1)) {
53
+ return true;
53
54
  }
54
55
  }
55
56
  return false;
56
57
  }
57
58
  getPin(pinId) {
58
- if (typeof pinId === 'number') {
59
- return pinId;
59
+ for (const [pin,] of this.pins) {
60
+ if (pin.equals(pinId)) {
61
+ return pin;
62
+ }
60
63
  }
61
- else {
64
+ if (pinId.getType() === PinDefinition_js_1.PinIdType.Str) {
65
+ const pinIdStringValue = pinId.getValue();
62
66
  for (const [pin, pinDef] of this.pins) {
63
- if (pinDef.name === pinId ||
64
- pinDef.altNames.indexOf(pinId) !== -1) {
67
+ if (pinDef.name === pinIdStringValue ||
68
+ pinDef.altNames.indexOf(pinIdStringValue) !== -1) {
65
69
  return pin;
66
70
  }
67
71
  }
68
- return -1;
69
72
  }
73
+ throw new utils_js_1.RuntimeExecutionError(`Could not find pin '${pinId}' on component '${this.instanceName}'`);
70
74
  }
71
75
  getNextPinAfter(pinIndex) {
72
- if (pinIndex + 1 <= this.numPins) {
73
- return pinIndex + 1;
76
+ const pins = Array.from(this.pins.keys());
77
+ pins.sort();
78
+ const index = pins.findIndex(tmp => tmp.equals(pinIndex));
79
+ if (index + 1 < pins.length) {
80
+ return pins[index + 1];
74
81
  }
75
82
  else {
76
- return 1;
83
+ return this.getDefaultPin();
77
84
  }
78
85
  }
79
86
  setParam(key, value) {
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ActiveObject = exports.FrameAction = exports.SequenceAction = exports.ExecutionScope = void 0;
4
4
  const CircuitScriptParser_js_1 = require("../antlr/CircuitScriptParser.js");
5
+ const PinDefinition_js_1 = require("./PinDefinition.js");
6
+ const utils_js_1 = require("../utils.js");
5
7
  class ExecutionScope {
6
8
  constructor(scopeId) {
7
9
  this.nets = [];
@@ -33,8 +35,11 @@ class ExecutionScope {
33
35
  return scope;
34
36
  }
35
37
  findNet(component, pin) {
38
+ if (!(pin instanceof PinDefinition_js_1.PinId)) {
39
+ throw new utils_js_1.RuntimeExecutionError('Invalid value for PinId: ' + pin);
40
+ }
36
41
  return this.nets.find(([tmpComponent, tmpPin]) => {
37
- return tmpComponent.isEqual(component) && tmpPin === pin;
42
+ return tmpComponent.isEqual(component) && tmpPin.equals(pin);
38
43
  });
39
44
  }
40
45
  getNetWithName(name) {
@@ -95,7 +100,7 @@ class ExecutionScope {
95
100
  }
96
101
  });
97
102
  return sortedNet.map(([component, pin, net]) => {
98
- return [net.toString(), component.instanceName, pin];
103
+ return [net.toString(), component.instanceName, pin.value];
99
104
  });
100
105
  }
101
106
  printNets() {
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Net = void 0;
4
4
  class Net {
5
- constructor(namespace, name, priority = 0, type = null) {
5
+ constructor(namespace, name, priority = 0, type = 'any') {
6
6
  this.params = new Map();
7
7
  if (namespace.indexOf(' ') !== -1) {
8
8
  throw "Invalid net namespace provided";
@@ -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,25 +1,45 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Direction = exports.ParseSymbolType = exports.DeclaredReference = exports.UndeclaredReference = exports.AnyReference = void 0;
3
+ exports.NetTypes = exports.TypeProps = exports.Direction = exports.ParseSymbolType = exports.DeclaredReference = exports.UndeclaredReference = exports.AnyReference = exports.CFunctionEntry = void 0;
4
+ const globals_js_1 = require("../globals.js");
4
5
  const utils_js_1 = require("../utils.js");
6
+ class CFunctionEntry {
7
+ constructor(name, execute, source, uniqueId) {
8
+ this.name = name;
9
+ this.execute = execute;
10
+ this.uniqueId = uniqueId;
11
+ this.source = source;
12
+ }
13
+ toString() {
14
+ return `[Function: ${this.name}]`;
15
+ }
16
+ }
17
+ exports.CFunctionEntry = CFunctionEntry;
18
+ ;
5
19
  class AnyReference {
6
20
  constructor(refType) {
7
21
  this.found = false;
8
22
  this.trailers = [];
9
- if (refType.value instanceof AnyReference) {
23
+ this.referenceName = 'AnyReference';
24
+ if (refType.value instanceof AnyReference
25
+ && refType.value.type !== globals_js_1.ReferenceTypes.function) {
10
26
  throw new utils_js_1.RuntimeExecutionError("Nested reference types!");
11
27
  }
12
28
  this.found = refType.found;
13
29
  this.name = refType.name;
14
30
  this.trailers = refType.trailers;
15
- this.type = refType.type;
31
+ this.type = refType.type ?? globals_js_1.ReferenceTypes.unknown;
16
32
  this.value = refType.value;
17
33
  this.parentValue = refType.parentValue;
18
34
  }
35
+ toString() {
36
+ return `[${this.referenceName} name: ${this.name} trailers:${this.trailers} found: ${this.found}]`;
37
+ }
19
38
  }
20
39
  exports.AnyReference = AnyReference;
21
- class UndeclaredReference {
40
+ class UndeclaredReference extends AnyReference {
22
41
  constructor(reference) {
42
+ super(reference);
23
43
  this.reference = reference;
24
44
  }
25
45
  throwMessage() {
@@ -39,8 +59,9 @@ class UndeclaredReference {
39
59
  }
40
60
  exports.UndeclaredReference = UndeclaredReference;
41
61
  class DeclaredReference extends AnyReference {
42
- toString() {
43
- return `[DeclaredReference name: ${this.name} trailers:${this.trailers} found: ${this.found}]`;
62
+ constructor() {
63
+ super(...arguments);
64
+ this.referenceName = 'DeclaredReference';
44
65
  }
45
66
  toDisplayString() {
46
67
  let returnValue = undefined;
@@ -86,3 +107,18 @@ var Direction;
86
107
  Direction["Down"] = "down";
87
108
  Direction["Up"] = "up";
88
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 = {}));