circuitscript 0.1.15 → 0.1.16
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 +96 -34
- package/dist/cjs/antlr/CircuitScriptLexer.js +3 -3
- package/dist/cjs/antlr/CircuitScriptParser.js +868 -757
- package/dist/cjs/builtinMethods.js +11 -1
- package/dist/cjs/execute.js +18 -11
- package/dist/cjs/globals.js +3 -1
- package/dist/cjs/graph.js +298 -0
- package/dist/cjs/helpers.js +6 -2
- package/dist/cjs/layout.js +12 -258
- package/dist/cjs/objects/types.js +27 -6
- package/dist/cjs/visitor.js +32 -30
- package/dist/esm/BaseVisitor.js +96 -34
- package/dist/esm/antlr/CircuitScriptLexer.js +3 -3
- package/dist/esm/antlr/CircuitScriptParser.js +864 -755
- package/dist/esm/antlr/CircuitScriptVisitor.js +2 -0
- package/dist/esm/builtinMethods.js +11 -1
- package/dist/esm/execute.js +19 -12
- package/dist/esm/globals.js +2 -0
- package/dist/esm/graph.js +293 -0
- package/dist/esm/helpers.js +6 -2
- package/dist/esm/layout.js +8 -234
- package/dist/esm/objects/types.js +27 -6
- package/dist/esm/visitor.js +33 -31
- package/dist/types/BaseVisitor.d.ts +3 -1
- package/dist/types/antlr/CircuitScriptParser.d.ts +42 -26
- package/dist/types/antlr/CircuitScriptVisitor.d.ts +4 -0
- package/dist/types/execute.d.ts +5 -5
- package/dist/types/globals.d.ts +3 -1
- package/dist/types/graph.d.ts +28 -0
- package/dist/types/layout.d.ts +2 -8
- package/dist/types/objects/ExecutionScope.d.ts +3 -3
- package/dist/types/objects/types.d.ts +16 -6
- package/package.json +1 -1
package/dist/cjs/layout.js
CHANGED
|
@@ -1,46 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
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 =
|
|
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");
|
|
37
15
|
const helpers_js_1 = require("./helpers.js");
|
|
38
16
|
const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
|
|
17
|
+
const graph_js_1 = require("./graph.js");
|
|
39
18
|
class LayoutEngine {
|
|
40
|
-
constructor(options = { showBaseFrame: false }) {
|
|
19
|
+
constructor(logger, options = { showBaseFrame: false }) {
|
|
41
20
|
this.layoutWarnings = [];
|
|
42
21
|
this.showBaseFrame = false;
|
|
43
|
-
this.logger =
|
|
22
|
+
this.logger = logger;
|
|
44
23
|
const { showBaseFrame = false } = options ?? {};
|
|
45
24
|
this.showBaseFrame = showBaseFrame;
|
|
46
25
|
}
|
|
@@ -54,30 +33,8 @@ class LayoutEngine {
|
|
|
54
33
|
const padding = ''.padStart(value * 4, ' ');
|
|
55
34
|
return "[" + value + "]" + padding;
|
|
56
35
|
}
|
|
57
|
-
runLayout(
|
|
58
|
-
const logNodesAndEdges = true;
|
|
36
|
+
runLayout(graph, containerFrames, nets) {
|
|
59
37
|
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
38
|
const subgraphInfo = this.sizeSubGraphs(graph);
|
|
82
39
|
const dumpSubgraphInfo = true;
|
|
83
40
|
if (dumpSubgraphInfo) {
|
|
@@ -584,7 +541,7 @@ class LayoutEngine {
|
|
|
584
541
|
return item.component.instanceName;
|
|
585
542
|
}
|
|
586
543
|
else if (item instanceof RenderWire) {
|
|
587
|
-
return getWireName(item.id);
|
|
544
|
+
return (0, graph_js_1.getWireName)(item.id);
|
|
588
545
|
}
|
|
589
546
|
return null;
|
|
590
547
|
}));
|
|
@@ -668,158 +625,6 @@ class LayoutEngine {
|
|
|
668
625
|
}
|
|
669
626
|
}
|
|
670
627
|
}
|
|
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
628
|
sizeSubGraphs(graph) {
|
|
824
629
|
const subGraphs = alg.components(graph);
|
|
825
630
|
const subGraphsStarts = [];
|
|
@@ -847,10 +652,10 @@ class LayoutEngine {
|
|
|
847
652
|
const wires = [];
|
|
848
653
|
innerGraph.forEach(nodeId => {
|
|
849
654
|
const [nodeType, item,] = graph.node(nodeId);
|
|
850
|
-
if (nodeType === RenderItemType.Component) {
|
|
655
|
+
if (nodeType === graph_js_1.RenderItemType.Component) {
|
|
851
656
|
renderItems.push(item);
|
|
852
657
|
}
|
|
853
|
-
else if (nodeType === RenderItemType.Wire) {
|
|
658
|
+
else if (nodeType === graph_js_1.RenderItemType.Wire) {
|
|
854
659
|
wires.push(item);
|
|
855
660
|
}
|
|
856
661
|
});
|
|
@@ -1118,52 +923,6 @@ function getNeighbours(graph, nodeIds) {
|
|
|
1118
923
|
return accum;
|
|
1119
924
|
}, []);
|
|
1120
925
|
}
|
|
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
926
|
function applyComponentParamsToSymbol(component, symbol) {
|
|
1168
927
|
const { widthProp = null, heightProp = null } = component;
|
|
1169
928
|
const newMap = new Map(component.parameters);
|
|
@@ -1413,7 +1172,7 @@ class RenderWire extends RenderObject {
|
|
|
1413
1172
|
this.refreshPoints();
|
|
1414
1173
|
}
|
|
1415
1174
|
toString() {
|
|
1416
|
-
return getWireName(this.id);
|
|
1175
|
+
return (0, graph_js_1.getWireName)(this.id);
|
|
1417
1176
|
}
|
|
1418
1177
|
}
|
|
1419
1178
|
exports.RenderWire = RenderWire;
|
|
@@ -1512,7 +1271,7 @@ function CalculatePinPositions(component) {
|
|
|
1512
1271
|
tmpSymbol = new draw_symbols_js_1.SymbolPlaceholder(component.displayProp);
|
|
1513
1272
|
}
|
|
1514
1273
|
else {
|
|
1515
|
-
const symbolPinDefinitions = generateLayoutPinDefinition(component);
|
|
1274
|
+
const symbolPinDefinitions = (0, graph_js_1.generateLayoutPinDefinition)(component);
|
|
1516
1275
|
tmpSymbol = new draw_symbols_js_1.SymbolCustom(symbolPinDefinitions, component.pinsMaxPositions);
|
|
1517
1276
|
}
|
|
1518
1277
|
applyComponentParamsToSymbol(component, tmpSymbol);
|
|
@@ -1548,8 +1307,3 @@ exports.ExtractDrawingRects = ExtractDrawingRects;
|
|
|
1548
1307
|
function isPointOverlap(x, y, other) {
|
|
1549
1308
|
return (x >= other.x && y >= other.y && x <= (other.x + other.width) && y <= (other.y + other.height));
|
|
1550
1309
|
}
|
|
1551
|
-
var RenderItemType;
|
|
1552
|
-
(function (RenderItemType) {
|
|
1553
|
-
RenderItemType["Wire"] = "wire";
|
|
1554
|
-
RenderItemType["Component"] = "component";
|
|
1555
|
-
})(RenderItemType || (RenderItemType = {}));
|
|
@@ -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.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
|
-
|
|
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
|
-
|
|
43
|
-
|
|
62
|
+
constructor() {
|
|
63
|
+
super(...arguments);
|
|
64
|
+
this.referenceName = 'DeclaredReference';
|
|
44
65
|
}
|
|
45
66
|
toDisplayString() {
|
|
46
67
|
let returnValue = undefined;
|
package/dist/cjs/visitor.js
CHANGED
|
@@ -381,7 +381,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
381
381
|
if (ctxNestedProperties) {
|
|
382
382
|
const nestedKeyValues = this.visitResult(ctxNestedProperties);
|
|
383
383
|
nestedKeyValues.forEach((value, key) => {
|
|
384
|
-
parameters.push(['keyword', key, value]);
|
|
384
|
+
parameters.push(['keyword', key, (0, utils_js_1.unwrapValue)(value)]);
|
|
385
385
|
});
|
|
386
386
|
}
|
|
387
387
|
else {
|
|
@@ -539,36 +539,36 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
539
539
|
this.setResult(ctx, result);
|
|
540
540
|
};
|
|
541
541
|
this.visitData_expr_with_assignment = (ctx) => {
|
|
542
|
-
let
|
|
543
|
-
let componentCtx
|
|
542
|
+
let dataResult = null;
|
|
543
|
+
let componentCtx;
|
|
544
544
|
const ctxDataExpr = ctx.data_expr();
|
|
545
545
|
const ctxAssignmentExpr = ctx.assignment_expr();
|
|
546
546
|
if (ctxDataExpr) {
|
|
547
|
-
|
|
548
|
-
component = (0, utils_js_1.unwrapValue)(component);
|
|
547
|
+
dataResult = this.visitResult(ctxDataExpr);
|
|
549
548
|
componentCtx = ctxDataExpr;
|
|
550
|
-
if (component === null || component === undefined) {
|
|
551
|
-
this.throwWithContext(ctxDataExpr, "Could not find component: " + ctxDataExpr.getText());
|
|
552
|
-
}
|
|
553
549
|
}
|
|
554
550
|
else if (ctxAssignmentExpr) {
|
|
555
|
-
|
|
551
|
+
dataResult = this.visitResult(ctxAssignmentExpr);
|
|
556
552
|
componentCtx = ctxAssignmentExpr;
|
|
557
553
|
}
|
|
558
|
-
if (
|
|
559
|
-
|
|
560
|
-
component = this.getExecutor().copyComponent(component);
|
|
561
|
-
}
|
|
562
|
-
if (component instanceof types_js_1.UndeclaredReference) {
|
|
563
|
-
const { reference: { trailers = [], parentValue = null } } = component;
|
|
554
|
+
if (dataResult instanceof types_js_1.AnyReference) {
|
|
555
|
+
const { trailers = [], parentValue = null } = dataResult;
|
|
564
556
|
if (parentValue instanceof ClassComponent_js_1.ClassComponent
|
|
565
557
|
&& trailers.length > 0
|
|
566
558
|
&& trailers[0] === globals_js_1.ModuleContainsKeyword) {
|
|
567
|
-
|
|
568
|
-
this.placeModuleContains(
|
|
559
|
+
dataResult = parentValue;
|
|
560
|
+
this.placeModuleContains(dataResult);
|
|
569
561
|
}
|
|
570
562
|
}
|
|
571
|
-
|
|
563
|
+
dataResult = (0, utils_js_1.unwrapValue)(dataResult);
|
|
564
|
+
if (dataResult === null || dataResult === undefined) {
|
|
565
|
+
this.throwWithContext(componentCtx, "Could not find component: " + componentCtx.getText());
|
|
566
|
+
}
|
|
567
|
+
if (dataResult instanceof ClassComponent_js_1.ClassComponent
|
|
568
|
+
&& dataResult.copyProp) {
|
|
569
|
+
dataResult = this.getExecutor().copyComponent(dataResult);
|
|
570
|
+
}
|
|
571
|
+
if (dataResult && dataResult instanceof ClassComponent_js_1.ClassComponent) {
|
|
572
572
|
const modifiers = ctx.component_modifier_expr();
|
|
573
573
|
modifiers.forEach(modifier => {
|
|
574
574
|
const modifierText = modifier.ID(0).getText();
|
|
@@ -585,23 +585,23 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
585
585
|
if (modifierText === globals_js_1.ParamKeys.flip) {
|
|
586
586
|
const flipValue = result;
|
|
587
587
|
if (flipValue.indexOf('x') !== -1) {
|
|
588
|
-
|
|
588
|
+
dataResult.setParam(globals_js_1.ParamKeys.flipX, 1);
|
|
589
589
|
shouldIgnoreWireOrientation = true;
|
|
590
590
|
}
|
|
591
591
|
if (flipValue.indexOf('y') !== -1) {
|
|
592
|
-
|
|
592
|
+
dataResult.setParam(globals_js_1.ParamKeys.flipY, 1);
|
|
593
593
|
shouldIgnoreWireOrientation = true;
|
|
594
594
|
}
|
|
595
595
|
}
|
|
596
596
|
else if (modifierText === globals_js_1.ParamKeys.angle) {
|
|
597
|
-
|
|
597
|
+
dataResult.setParam(globals_js_1.ParamKeys.angle, result);
|
|
598
598
|
shouldIgnoreWireOrientation = true;
|
|
599
599
|
}
|
|
600
600
|
else if (modifierText === 'anchor') {
|
|
601
|
-
|
|
601
|
+
dataResult.setParam('anchor', result);
|
|
602
602
|
}
|
|
603
603
|
if (shouldIgnoreWireOrientation) {
|
|
604
|
-
|
|
604
|
+
dataResult.useWireOrientationAngle = false;
|
|
605
605
|
}
|
|
606
606
|
});
|
|
607
607
|
}
|
|
@@ -611,15 +611,15 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
611
611
|
pinValue = this.visitResult(ctxPinSelectExpr);
|
|
612
612
|
}
|
|
613
613
|
else {
|
|
614
|
-
if (
|
|
615
|
-
pinValue =
|
|
614
|
+
if (dataResult instanceof ClassComponent_js_1.ClassComponent) {
|
|
615
|
+
pinValue = dataResult.getDefaultPin();
|
|
616
616
|
}
|
|
617
617
|
else {
|
|
618
|
-
const undeclaredRef =
|
|
618
|
+
const undeclaredRef = dataResult;
|
|
619
619
|
this.throwWithContext(componentCtx, 'Invalid component: ' + undeclaredRef.reference.name);
|
|
620
620
|
}
|
|
621
621
|
}
|
|
622
|
-
this.setResult(ctx, [
|
|
622
|
+
this.setResult(ctx, [dataResult, pinValue]);
|
|
623
623
|
};
|
|
624
624
|
this.visitUnaryOperatorExpr = (ctx) => {
|
|
625
625
|
let value = this.visitResult(ctx.data_expr());
|
|
@@ -749,8 +749,8 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
749
749
|
this.setResult(ctx, result);
|
|
750
750
|
};
|
|
751
751
|
this.visitAdditionExpr = (ctx) => {
|
|
752
|
-
const value1 = this.resolveDataExpr(ctx.data_expr(0));
|
|
753
|
-
const value2 = this.resolveDataExpr(ctx.data_expr(1));
|
|
752
|
+
const value1 = (0, utils_js_1.unwrapValue)(this.resolveDataExpr(ctx.data_expr(0)));
|
|
753
|
+
const value2 = (0, utils_js_1.unwrapValue)(this.resolveDataExpr(ctx.data_expr(1)));
|
|
754
754
|
if (ctx.Addition() && (typeof value1 === 'string' || typeof value2 === 'string')) {
|
|
755
755
|
let tmpValue1 = value1;
|
|
756
756
|
if (value1 instanceof ParamDefinition_js_1.NumericValue) {
|
|
@@ -779,6 +779,8 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
779
779
|
};
|
|
780
780
|
this.visitFunction_def_expr = (ctx) => {
|
|
781
781
|
const functionName = ctx.ID().getText();
|
|
782
|
+
const uniqueFunctionID = '__._' + ctx.start.line + '_'
|
|
783
|
+
+ ctx.start.column + '_' + functionName + '_' + ctx.getText();
|
|
782
784
|
let funcDefinedParameters = [];
|
|
783
785
|
const ctxFunctionArgsExpr = ctx.function_args_expr();
|
|
784
786
|
if (ctxFunctionArgsExpr) {
|
|
@@ -800,7 +802,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
800
802
|
nextLastExecution.mergeScope(lastExecution.scope, executionContextName);
|
|
801
803
|
return [lastExecution, returnValue];
|
|
802
804
|
};
|
|
803
|
-
this.getExecutor().createFunction(functionName, __runFunc);
|
|
805
|
+
this.getExecutor().createFunction(functionName, __runFunc, ctx, uniqueFunctionID);
|
|
804
806
|
};
|
|
805
807
|
this.visitPin_select_expr2 = (ctx) => {
|
|
806
808
|
const ctxStringValue = ctx.STRING_VALUE();
|