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/esm/layout.js
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
import graphlib
|
|
1
|
+
import graphlib from '@dagrejs/graphlib';
|
|
2
2
|
const { alg } = graphlib;
|
|
3
|
-
import { SymbolCustom, SymbolDrawing,
|
|
4
|
-
import {
|
|
5
|
-
import { ComponentTypes, defaultFrameTitleTextSize, defaultGridSizeUnits, FrameType, NetGraphicsParams, ParamKeys, WireAutoDirection } from './globals.js';
|
|
3
|
+
import { SymbolCustom, SymbolDrawing, SymbolPlaceholder, SymbolText, PlaceHolderCommands } from "./draw_symbols.js";
|
|
4
|
+
import { defaultFrameTitleTextSize, defaultGridSizeUnits, FrameType, NetGraphicsParams, ParamKeys, WireAutoDirection } from './globals.js';
|
|
6
5
|
import { Geometry, HorizontalAlign, VerticalAlign } from './geometry.js';
|
|
7
|
-
import { Logger } from './logger.js';
|
|
8
6
|
import { FixedFrameIds, Frame, FrameParamKeys, FramePlotDirection } from './objects/Frame.js';
|
|
9
7
|
import { areasOverlap, combineMaps, getBoundsSize, printBounds, resizeBounds, resizeToNearestGrid, roundValue, toNearestGrid } from './utils.js';
|
|
10
8
|
import { Direction } from './objects/types.js';
|
|
11
9
|
import { milsToMM, UnitDimension } from './helpers.js';
|
|
12
|
-
import { numeric
|
|
10
|
+
import { numeric } from './objects/ParamDefinition.js';
|
|
11
|
+
import { generateLayoutPinDefinition, getWireName, RenderItemType } from './graph.js';
|
|
13
12
|
export class LayoutEngine {
|
|
14
13
|
logger;
|
|
15
14
|
layoutWarnings = [];
|
|
16
15
|
showBaseFrame = false;
|
|
17
|
-
constructor(options = { showBaseFrame: false }) {
|
|
18
|
-
this.logger =
|
|
16
|
+
constructor(logger, options = { showBaseFrame: false }) {
|
|
17
|
+
this.logger = logger;
|
|
19
18
|
const { showBaseFrame = false } = options ?? {};
|
|
20
19
|
this.showBaseFrame = showBaseFrame;
|
|
21
20
|
}
|
|
@@ -29,30 +28,8 @@ export class LayoutEngine {
|
|
|
29
28
|
const padding = ''.padStart(value * 4, ' ');
|
|
30
29
|
return "[" + value + "]" + padding;
|
|
31
30
|
}
|
|
32
|
-
runLayout(
|
|
33
|
-
const logNodesAndEdges = true;
|
|
31
|
+
runLayout(graph, containerFrames, nets) {
|
|
34
32
|
const renderNets = this.collectRenderNets(nets);
|
|
35
|
-
this.print('===== creating graph and populating with nodes =====');
|
|
36
|
-
const { graph, containerFrames } = this.generateLayoutGraph(sequence, nets);
|
|
37
|
-
this.print('===== done populating graph =====');
|
|
38
|
-
this.print('');
|
|
39
|
-
if (logNodesAndEdges) {
|
|
40
|
-
this.print('===== graph edges =====');
|
|
41
|
-
const allEdges = graph.edges();
|
|
42
|
-
allEdges.forEach(edge => {
|
|
43
|
-
const [nodeId1, pin1, nodeId2, pin2] = graph.edge(edge);
|
|
44
|
-
this.print(nodeId1, 'pin', pin1, '-----', nodeId2, 'pin', pin2);
|
|
45
|
-
});
|
|
46
|
-
this.print('===== end edges =====');
|
|
47
|
-
this.print();
|
|
48
|
-
this.print('===== graph nodes =====');
|
|
49
|
-
const nodes = graph.nodes();
|
|
50
|
-
nodes.forEach(node => {
|
|
51
|
-
this.print(`name:${node}, value:${graph.node(node)}`);
|
|
52
|
-
});
|
|
53
|
-
this.print('===== end nodes =====');
|
|
54
|
-
this.print('');
|
|
55
|
-
}
|
|
56
33
|
const subgraphInfo = this.sizeSubGraphs(graph);
|
|
57
34
|
const dumpSubgraphInfo = true;
|
|
58
35
|
if (dumpSubgraphInfo) {
|
|
@@ -643,158 +620,6 @@ export class LayoutEngine {
|
|
|
643
620
|
}
|
|
644
621
|
}
|
|
645
622
|
}
|
|
646
|
-
generateLayoutGraph(sequence, nets) {
|
|
647
|
-
let previousNode = null;
|
|
648
|
-
let previousPin = null;
|
|
649
|
-
const graph = new Graph({
|
|
650
|
-
directed: true,
|
|
651
|
-
compound: true,
|
|
652
|
-
});
|
|
653
|
-
this.print('sequence length:', sequence.length);
|
|
654
|
-
const baseFrame = new RenderFrame(new Frame(FixedFrameIds.BaseFrame));
|
|
655
|
-
const frameStack = [baseFrame];
|
|
656
|
-
const containerFrames = [baseFrame];
|
|
657
|
-
sequence.forEach((sequenceStep, index) => {
|
|
658
|
-
const action = sequenceStep[0];
|
|
659
|
-
let tmpComponent;
|
|
660
|
-
switch (action) {
|
|
661
|
-
case SequenceAction.To:
|
|
662
|
-
case SequenceAction.At: {
|
|
663
|
-
this.print(...sequenceStep);
|
|
664
|
-
const [, component, pin] = sequenceStep;
|
|
665
|
-
const tmpInstanceName = component.instanceName;
|
|
666
|
-
if (!graph.hasNode(tmpInstanceName)) {
|
|
667
|
-
this.print('create instance', tmpInstanceName);
|
|
668
|
-
const { displayProp = null } = component;
|
|
669
|
-
let tmpSymbol;
|
|
670
|
-
if (displayProp instanceof SymbolDrawing) {
|
|
671
|
-
tmpSymbol = new SymbolPlaceholder(displayProp);
|
|
672
|
-
tmpSymbol.drawing.logger = this.logger;
|
|
673
|
-
}
|
|
674
|
-
else {
|
|
675
|
-
const symbolPinDefinitions = generateLayoutPinDefinition(component);
|
|
676
|
-
if (component.typeProp === ComponentTypes.module) {
|
|
677
|
-
tmpSymbol = new SymbolCustomModule(symbolPinDefinitions, component.pinsMaxPositions);
|
|
678
|
-
}
|
|
679
|
-
else {
|
|
680
|
-
tmpSymbol = new SymbolCustom(symbolPinDefinitions, component.pinsMaxPositions);
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
applyComponentParamsToSymbol(component, tmpSymbol);
|
|
684
|
-
tmpSymbol.refreshDrawing();
|
|
685
|
-
const { width: useWidth, height: useHeight } = tmpSymbol.size();
|
|
686
|
-
tmpComponent = new RenderComponent(component, useWidth, useHeight);
|
|
687
|
-
tmpComponent.symbol = tmpSymbol;
|
|
688
|
-
graph.setNode(tmpInstanceName, [RenderItemType.Component, tmpComponent, index]);
|
|
689
|
-
const currentFrame = frameStack[frameStack.length - 1];
|
|
690
|
-
currentFrame && currentFrame.innerItems.push(tmpComponent);
|
|
691
|
-
}
|
|
692
|
-
if (action === SequenceAction.To && previousNode && previousPin) {
|
|
693
|
-
this.setGraphEdge(graph, previousNode, tmpInstanceName, makeEdgeValue(previousNode, previousPin, tmpInstanceName, pin, index));
|
|
694
|
-
}
|
|
695
|
-
previousNode = tmpInstanceName;
|
|
696
|
-
previousPin = pin;
|
|
697
|
-
break;
|
|
698
|
-
}
|
|
699
|
-
case SequenceAction.Wire: {
|
|
700
|
-
const [, wireId, wireSegments] = sequenceStep;
|
|
701
|
-
let useNet;
|
|
702
|
-
if (previousNode !== null) {
|
|
703
|
-
const [prevNodeType, prevNodeItem] = graph.node(previousNode);
|
|
704
|
-
if (prevNodeType === RenderItemType.Component) {
|
|
705
|
-
const matchingItem = nets.find(([comp, pin]) => {
|
|
706
|
-
return comp.instanceName === previousNode
|
|
707
|
-
&& pin === previousPin;
|
|
708
|
-
});
|
|
709
|
-
if (matchingItem !== undefined) {
|
|
710
|
-
useNet = matchingItem[2];
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
else if (prevNodeType === RenderItemType.Wire) {
|
|
714
|
-
useNet = prevNodeItem.net;
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
const wire = new RenderWire(useNet, numeric(0), numeric(0), wireSegments);
|
|
718
|
-
wire.id = wireId;
|
|
719
|
-
wire.netName = useNet.toString();
|
|
720
|
-
const wireName = getWireName(wire.id);
|
|
721
|
-
graph.setNode(wireName, [RenderItemType.Wire, wire, index]);
|
|
722
|
-
this.setGraphEdge(graph, previousNode, wireName, makeEdgeValue(previousNode, previousPin, wireName, 0, index));
|
|
723
|
-
previousNode = wireName;
|
|
724
|
-
previousPin = 1;
|
|
725
|
-
const wireSegmentsInfo = wireSegments.map(item => {
|
|
726
|
-
const tmp = {
|
|
727
|
-
direction: item.direction,
|
|
728
|
-
value: item.value,
|
|
729
|
-
};
|
|
730
|
-
if (item.valueXY) {
|
|
731
|
-
tmp.valueXY = item.valueXY;
|
|
732
|
-
}
|
|
733
|
-
if (item.until) {
|
|
734
|
-
tmp.until = [item.until[0].toString(), item.until[1]];
|
|
735
|
-
}
|
|
736
|
-
return tmp;
|
|
737
|
-
});
|
|
738
|
-
this.print(SequenceAction.Wire, wireId, JSON.stringify(wireSegmentsInfo));
|
|
739
|
-
break;
|
|
740
|
-
}
|
|
741
|
-
case SequenceAction.WireJump: {
|
|
742
|
-
this.print(...sequenceStep);
|
|
743
|
-
const wireId = sequenceStep[1];
|
|
744
|
-
const wireName = getWireName(wireId);
|
|
745
|
-
let wirePin = 1;
|
|
746
|
-
if (sequenceStep.length === 3) {
|
|
747
|
-
wirePin = sequenceStep[2];
|
|
748
|
-
}
|
|
749
|
-
previousNode = wireName;
|
|
750
|
-
previousPin = wirePin;
|
|
751
|
-
break;
|
|
752
|
-
}
|
|
753
|
-
case SequenceAction.Frame: {
|
|
754
|
-
const [, frameObject, frameAction] = sequenceStep;
|
|
755
|
-
if (frameAction === FrameAction.Enter) {
|
|
756
|
-
const prevFrame = frameStack[frameStack.length - 1];
|
|
757
|
-
const newFrame = new RenderFrame(frameObject);
|
|
758
|
-
if (frameObject.parameters.has(FrameParamKeys.Direction)) {
|
|
759
|
-
newFrame.direction =
|
|
760
|
-
frameObject.parameters.get(FrameParamKeys.Direction);
|
|
761
|
-
}
|
|
762
|
-
if (frameObject.parameters.has(FrameParamKeys.Padding)) {
|
|
763
|
-
newFrame.padding = milsToMM(frameObject.parameters.get(FrameParamKeys.Padding));
|
|
764
|
-
}
|
|
765
|
-
if (frameObject.parameters.has(FrameParamKeys.Border)) {
|
|
766
|
-
newFrame.borderWidth =
|
|
767
|
-
frameObject.parameters.get(FrameParamKeys.Border);
|
|
768
|
-
}
|
|
769
|
-
if (frameObject.parameters.has(FrameParamKeys.Width)) {
|
|
770
|
-
newFrame.width = milsToMM(frameObject.parameters.get(FrameParamKeys.Width));
|
|
771
|
-
}
|
|
772
|
-
if (frameObject.parameters.has(FrameParamKeys.Height)) {
|
|
773
|
-
newFrame.height = milsToMM(frameObject.parameters.get(FrameParamKeys.Height));
|
|
774
|
-
}
|
|
775
|
-
containerFrames.push(newFrame);
|
|
776
|
-
frameStack.push(newFrame);
|
|
777
|
-
prevFrame && prevFrame.innerItems.push(newFrame);
|
|
778
|
-
}
|
|
779
|
-
else if (frameAction === FrameAction.Exit) {
|
|
780
|
-
frameStack.pop();
|
|
781
|
-
}
|
|
782
|
-
break;
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
});
|
|
786
|
-
return {
|
|
787
|
-
graph,
|
|
788
|
-
containerFrames,
|
|
789
|
-
};
|
|
790
|
-
}
|
|
791
|
-
setGraphEdge(graph, node1, node2, edgeValue) {
|
|
792
|
-
if (!graph.isDirected && graph.hasEdge(node1, node2)) {
|
|
793
|
-
this.print(`Warning: edge already exists ${node1} ${node2}`);
|
|
794
|
-
}
|
|
795
|
-
graph.setEdge(node1, node2, edgeValue);
|
|
796
|
-
this.print(`created edge: node1:${node1} node2:${node2} edgeValue:${edgeValue}`);
|
|
797
|
-
}
|
|
798
623
|
sizeSubGraphs(graph) {
|
|
799
624
|
const subGraphs = alg.components(graph);
|
|
800
625
|
const subGraphsStarts = [];
|
|
@@ -1092,52 +917,6 @@ function getNeighbours(graph, nodeIds) {
|
|
|
1092
917
|
return accum;
|
|
1093
918
|
}, []);
|
|
1094
919
|
}
|
|
1095
|
-
function makeEdgeValue(instanceName1, instancePin1, instanceName2, instancePin2, priority) {
|
|
1096
|
-
return [instanceName1, instancePin1, instanceName2, instancePin2, priority];
|
|
1097
|
-
}
|
|
1098
|
-
function getWireName(wireId) {
|
|
1099
|
-
return 'wire:' + wireId;
|
|
1100
|
-
}
|
|
1101
|
-
function generateLayoutPinDefinition(component) {
|
|
1102
|
-
const pins = component.pins;
|
|
1103
|
-
const symbolPinDefinitions = [];
|
|
1104
|
-
const existingPinIds = Array.from(pins.keys());
|
|
1105
|
-
const arrangeProps = component.arrangeProps ?? [];
|
|
1106
|
-
const addedPins = [];
|
|
1107
|
-
for (const [key, items] of arrangeProps) {
|
|
1108
|
-
let useItems;
|
|
1109
|
-
if (!Array.isArray(items)) {
|
|
1110
|
-
useItems = [items];
|
|
1111
|
-
}
|
|
1112
|
-
else {
|
|
1113
|
-
useItems = [...items];
|
|
1114
|
-
}
|
|
1115
|
-
useItems.forEach(pinId => {
|
|
1116
|
-
if (pinId instanceof NumericValue) {
|
|
1117
|
-
const pinIdValue = pinId.toNumber();
|
|
1118
|
-
if (existingPinIds.indexOf(pinIdValue) !== -1) {
|
|
1119
|
-
const pin = pins.get(pinIdValue);
|
|
1120
|
-
symbolPinDefinitions.push({
|
|
1121
|
-
side: key,
|
|
1122
|
-
pinId: pinIdValue,
|
|
1123
|
-
text: pin.name,
|
|
1124
|
-
position: pin.position,
|
|
1125
|
-
pinType: pin.pinType,
|
|
1126
|
-
});
|
|
1127
|
-
addedPins.push(pinIdValue);
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
1130
|
-
});
|
|
1131
|
-
}
|
|
1132
|
-
const unplacedPins = existingPinIds.filter(pinId => {
|
|
1133
|
-
return addedPins.indexOf(pinId) === -1;
|
|
1134
|
-
});
|
|
1135
|
-
if (unplacedPins.length > 0) {
|
|
1136
|
-
component._unplacedPins = unplacedPins;
|
|
1137
|
-
console.warn("Warning: There are unplaced pins: " + unplacedPins);
|
|
1138
|
-
}
|
|
1139
|
-
return symbolPinDefinitions;
|
|
1140
|
-
}
|
|
1141
920
|
export function applyComponentParamsToSymbol(component, symbol) {
|
|
1142
921
|
const { widthProp = null, heightProp = null } = component;
|
|
1143
922
|
const newMap = new Map(component.parameters);
|
|
@@ -1523,8 +1302,3 @@ export function ExtractDrawingRects(drawing) {
|
|
|
1523
1302
|
function isPointOverlap(x, y, other) {
|
|
1524
1303
|
return (x >= other.x && y >= other.y && x <= (other.x + other.width) && y <= (other.y + other.height));
|
|
1525
1304
|
}
|
|
1526
|
-
var RenderItemType;
|
|
1527
|
-
(function (RenderItemType) {
|
|
1528
|
-
RenderItemType["Wire"] = "wire";
|
|
1529
|
-
RenderItemType["Component"] = "component";
|
|
1530
|
-
})(RenderItemType || (RenderItemType = {}));
|
|
@@ -1,4 +1,21 @@
|
|
|
1
|
+
import { ReferenceTypes } from '../globals.js';
|
|
1
2
|
import { RuntimeExecutionError } from '../utils.js';
|
|
3
|
+
export class CFunctionEntry {
|
|
4
|
+
name;
|
|
5
|
+
execute;
|
|
6
|
+
uniqueId;
|
|
7
|
+
source;
|
|
8
|
+
constructor(name, execute, source, uniqueId) {
|
|
9
|
+
this.name = name;
|
|
10
|
+
this.execute = execute;
|
|
11
|
+
this.uniqueId = uniqueId;
|
|
12
|
+
this.source = source;
|
|
13
|
+
}
|
|
14
|
+
toString() {
|
|
15
|
+
return `[Function: ${this.name}]`;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
;
|
|
2
19
|
export class AnyReference {
|
|
3
20
|
found = false;
|
|
4
21
|
name;
|
|
@@ -6,21 +23,27 @@ export class AnyReference {
|
|
|
6
23
|
type;
|
|
7
24
|
value;
|
|
8
25
|
parentValue;
|
|
26
|
+
referenceName = 'AnyReference';
|
|
9
27
|
constructor(refType) {
|
|
10
|
-
if (refType.value instanceof AnyReference
|
|
28
|
+
if (refType.value instanceof AnyReference
|
|
29
|
+
&& refType.value.type !== ReferenceTypes.function) {
|
|
11
30
|
throw new RuntimeExecutionError("Nested reference types!");
|
|
12
31
|
}
|
|
13
32
|
this.found = refType.found;
|
|
14
33
|
this.name = refType.name;
|
|
15
34
|
this.trailers = refType.trailers;
|
|
16
|
-
this.type = refType.type;
|
|
35
|
+
this.type = refType.type ?? ReferenceTypes.unknown;
|
|
17
36
|
this.value = refType.value;
|
|
18
37
|
this.parentValue = refType.parentValue;
|
|
19
38
|
}
|
|
39
|
+
toString() {
|
|
40
|
+
return `[${this.referenceName} name: ${this.name} trailers:${this.trailers} found: ${this.found}]`;
|
|
41
|
+
}
|
|
20
42
|
}
|
|
21
|
-
export class UndeclaredReference {
|
|
43
|
+
export class UndeclaredReference extends AnyReference {
|
|
22
44
|
reference;
|
|
23
45
|
constructor(reference) {
|
|
46
|
+
super(reference);
|
|
24
47
|
this.reference = reference;
|
|
25
48
|
}
|
|
26
49
|
throwMessage() {
|
|
@@ -39,9 +62,7 @@ export class UndeclaredReference {
|
|
|
39
62
|
}
|
|
40
63
|
}
|
|
41
64
|
export class DeclaredReference extends AnyReference {
|
|
42
|
-
|
|
43
|
-
return `[DeclaredReference name: ${this.name} trailers:${this.trailers} found: ${this.found}]`;
|
|
44
|
-
}
|
|
65
|
+
referenceName = 'DeclaredReference';
|
|
45
66
|
toDisplayString() {
|
|
46
67
|
let returnValue = undefined;
|
|
47
68
|
if (this.parentValue) {
|
package/dist/esm/visitor.js
CHANGED
|
@@ -2,7 +2,7 @@ import { ClassComponent } from './objects/ClassComponent.js';
|
|
|
2
2
|
import { NumberOperator, numeric, NumericValue, ParamDefinition } from './objects/ParamDefinition.js';
|
|
3
3
|
import { PinDefinition, PinIdType } from './objects/PinDefinition.js';
|
|
4
4
|
import { PinTypes } from './objects/PinTypes.js';
|
|
5
|
-
import { DeclaredReference, UndeclaredReference } from './objects/types.js';
|
|
5
|
+
import { AnyReference, DeclaredReference, UndeclaredReference } from './objects/types.js';
|
|
6
6
|
import { BlockTypes, ComponentTypes, Delimiter1, FrameType, GlobalDocumentName, ModuleContainsKeyword, NoNetText, ParamKeys, ReferenceTypes, SymbolPinSide, ValidPinSides, WireAutoDirection } from './globals.js';
|
|
7
7
|
import { unwrapValue } from "./utils.js";
|
|
8
8
|
import { PlaceHolderCommands, SymbolDrawingCommands } from './draw_symbols.js';
|
|
@@ -376,7 +376,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
376
376
|
if (ctxNestedProperties) {
|
|
377
377
|
const nestedKeyValues = this.visitResult(ctxNestedProperties);
|
|
378
378
|
nestedKeyValues.forEach((value, key) => {
|
|
379
|
-
parameters.push(['keyword', key, value]);
|
|
379
|
+
parameters.push(['keyword', key, unwrapValue(value)]);
|
|
380
380
|
});
|
|
381
381
|
}
|
|
382
382
|
else {
|
|
@@ -534,36 +534,36 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
534
534
|
this.setResult(ctx, result);
|
|
535
535
|
};
|
|
536
536
|
visitData_expr_with_assignment = (ctx) => {
|
|
537
|
-
let
|
|
538
|
-
let componentCtx
|
|
537
|
+
let dataResult = null;
|
|
538
|
+
let componentCtx;
|
|
539
539
|
const ctxDataExpr = ctx.data_expr();
|
|
540
540
|
const ctxAssignmentExpr = ctx.assignment_expr();
|
|
541
541
|
if (ctxDataExpr) {
|
|
542
|
-
|
|
543
|
-
component = unwrapValue(component);
|
|
542
|
+
dataResult = this.visitResult(ctxDataExpr);
|
|
544
543
|
componentCtx = ctxDataExpr;
|
|
545
|
-
if (component === null || component === undefined) {
|
|
546
|
-
this.throwWithContext(ctxDataExpr, "Could not find component: " + ctxDataExpr.getText());
|
|
547
|
-
}
|
|
548
544
|
}
|
|
549
545
|
else if (ctxAssignmentExpr) {
|
|
550
|
-
|
|
546
|
+
dataResult = this.visitResult(ctxAssignmentExpr);
|
|
551
547
|
componentCtx = ctxAssignmentExpr;
|
|
552
548
|
}
|
|
553
|
-
if (
|
|
554
|
-
|
|
555
|
-
component = this.getExecutor().copyComponent(component);
|
|
556
|
-
}
|
|
557
|
-
if (component instanceof UndeclaredReference) {
|
|
558
|
-
const { reference: { trailers = [], parentValue = null } } = component;
|
|
549
|
+
if (dataResult instanceof AnyReference) {
|
|
550
|
+
const { trailers = [], parentValue = null } = dataResult;
|
|
559
551
|
if (parentValue instanceof ClassComponent
|
|
560
552
|
&& trailers.length > 0
|
|
561
553
|
&& trailers[0] === ModuleContainsKeyword) {
|
|
562
|
-
|
|
563
|
-
this.placeModuleContains(
|
|
554
|
+
dataResult = parentValue;
|
|
555
|
+
this.placeModuleContains(dataResult);
|
|
564
556
|
}
|
|
565
557
|
}
|
|
566
|
-
|
|
558
|
+
dataResult = unwrapValue(dataResult);
|
|
559
|
+
if (dataResult === null || dataResult === undefined) {
|
|
560
|
+
this.throwWithContext(componentCtx, "Could not find component: " + componentCtx.getText());
|
|
561
|
+
}
|
|
562
|
+
if (dataResult instanceof ClassComponent
|
|
563
|
+
&& dataResult.copyProp) {
|
|
564
|
+
dataResult = this.getExecutor().copyComponent(dataResult);
|
|
565
|
+
}
|
|
566
|
+
if (dataResult && dataResult instanceof ClassComponent) {
|
|
567
567
|
const modifiers = ctx.component_modifier_expr();
|
|
568
568
|
modifiers.forEach(modifier => {
|
|
569
569
|
const modifierText = modifier.ID(0).getText();
|
|
@@ -580,23 +580,23 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
580
580
|
if (modifierText === ParamKeys.flip) {
|
|
581
581
|
const flipValue = result;
|
|
582
582
|
if (flipValue.indexOf('x') !== -1) {
|
|
583
|
-
|
|
583
|
+
dataResult.setParam(ParamKeys.flipX, 1);
|
|
584
584
|
shouldIgnoreWireOrientation = true;
|
|
585
585
|
}
|
|
586
586
|
if (flipValue.indexOf('y') !== -1) {
|
|
587
|
-
|
|
587
|
+
dataResult.setParam(ParamKeys.flipY, 1);
|
|
588
588
|
shouldIgnoreWireOrientation = true;
|
|
589
589
|
}
|
|
590
590
|
}
|
|
591
591
|
else if (modifierText === ParamKeys.angle) {
|
|
592
|
-
|
|
592
|
+
dataResult.setParam(ParamKeys.angle, result);
|
|
593
593
|
shouldIgnoreWireOrientation = true;
|
|
594
594
|
}
|
|
595
595
|
else if (modifierText === 'anchor') {
|
|
596
|
-
|
|
596
|
+
dataResult.setParam('anchor', result);
|
|
597
597
|
}
|
|
598
598
|
if (shouldIgnoreWireOrientation) {
|
|
599
|
-
|
|
599
|
+
dataResult.useWireOrientationAngle = false;
|
|
600
600
|
}
|
|
601
601
|
});
|
|
602
602
|
}
|
|
@@ -606,15 +606,15 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
606
606
|
pinValue = this.visitResult(ctxPinSelectExpr);
|
|
607
607
|
}
|
|
608
608
|
else {
|
|
609
|
-
if (
|
|
610
|
-
pinValue =
|
|
609
|
+
if (dataResult instanceof ClassComponent) {
|
|
610
|
+
pinValue = dataResult.getDefaultPin();
|
|
611
611
|
}
|
|
612
612
|
else {
|
|
613
|
-
const undeclaredRef =
|
|
613
|
+
const undeclaredRef = dataResult;
|
|
614
614
|
this.throwWithContext(componentCtx, 'Invalid component: ' + undeclaredRef.reference.name);
|
|
615
615
|
}
|
|
616
616
|
}
|
|
617
|
-
this.setResult(ctx, [
|
|
617
|
+
this.setResult(ctx, [dataResult, pinValue]);
|
|
618
618
|
};
|
|
619
619
|
expandModuleContains(component, netNamespace) {
|
|
620
620
|
this.getExecutor().log('expanding module `contains`');
|
|
@@ -794,8 +794,8 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
794
794
|
this.setResult(ctx, result);
|
|
795
795
|
};
|
|
796
796
|
visitAdditionExpr = (ctx) => {
|
|
797
|
-
const value1 = this.resolveDataExpr(ctx.data_expr(0));
|
|
798
|
-
const value2 = this.resolveDataExpr(ctx.data_expr(1));
|
|
797
|
+
const value1 = unwrapValue(this.resolveDataExpr(ctx.data_expr(0)));
|
|
798
|
+
const value2 = unwrapValue(this.resolveDataExpr(ctx.data_expr(1)));
|
|
799
799
|
if (ctx.Addition() && (typeof value1 === 'string' || typeof value2 === 'string')) {
|
|
800
800
|
let tmpValue1 = value1;
|
|
801
801
|
if (value1 instanceof NumericValue) {
|
|
@@ -824,6 +824,8 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
824
824
|
};
|
|
825
825
|
visitFunction_def_expr = (ctx) => {
|
|
826
826
|
const functionName = ctx.ID().getText();
|
|
827
|
+
const uniqueFunctionID = '__._' + ctx.start.line + '_'
|
|
828
|
+
+ ctx.start.column + '_' + functionName + '_' + ctx.getText();
|
|
827
829
|
let funcDefinedParameters = [];
|
|
828
830
|
const ctxFunctionArgsExpr = ctx.function_args_expr();
|
|
829
831
|
if (ctxFunctionArgsExpr) {
|
|
@@ -845,7 +847,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
845
847
|
nextLastExecution.mergeScope(lastExecution.scope, executionContextName);
|
|
846
848
|
return [lastExecution, returnValue];
|
|
847
849
|
};
|
|
848
|
-
this.getExecutor().createFunction(functionName, __runFunc);
|
|
850
|
+
this.getExecutor().createFunction(functionName, __runFunc, ctx, uniqueFunctionID);
|
|
849
851
|
};
|
|
850
852
|
visitPin_select_expr2 = (ctx) => {
|
|
851
853
|
const ctxStringValue = ctx.STRING_VALUE();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Array_exprContext, ArrayExprContext, Assignment_exprContext, Atom_exprContext, ExpressionContext, Flow_expressionsContext, Function_args_exprContext, Function_call_exprContext, Function_exprContext, Function_return_exprContext, FunctionCallExprContext, Import_exprContext, Operator_assignment_exprContext, ParametersContext, RoundedBracketsExprContext, ScriptContext, Value_exprContext, ValueAtomExprContext } from "./antlr/CircuitScriptParser.js";
|
|
1
|
+
import { Array_exprContext, ArrayExprContext, ArrayIndexExprContext, Assignment_exprContext, Atom_exprContext, ExpressionContext, Flow_expressionsContext, Function_args_exprContext, Function_call_exprContext, Function_exprContext, Function_return_exprContext, FunctionCallExprContext, Import_exprContext, Operator_assignment_exprContext, ParametersContext, RoundedBracketsExprContext, ScriptContext, Trailer_expr2Context, Value_exprContext, ValueAtomExprContext } from "./antlr/CircuitScriptParser.js";
|
|
2
2
|
import { CircuitScriptVisitor } from "./antlr/CircuitScriptVisitor.js";
|
|
3
3
|
import { ExecutionContext } from "./execute.js";
|
|
4
4
|
import { Logger } from "./logger.js";
|
|
@@ -46,6 +46,7 @@ export declare class BaseVisitor extends CircuitScriptVisitor<ComplexType | AnyR
|
|
|
46
46
|
visitAssignment_expr: (ctx: Assignment_exprContext) => void;
|
|
47
47
|
visitOperator_assignment_expr: (ctx: Operator_assignment_exprContext) => void;
|
|
48
48
|
private getReference;
|
|
49
|
+
visitTrailer_expr2: (ctx: Trailer_expr2Context) => void;
|
|
49
50
|
visitAtom_expr: (ctx: Atom_exprContext) => void;
|
|
50
51
|
visitFunctionCallExpr: (ctx: FunctionCallExprContext) => void;
|
|
51
52
|
visitFunction_call_expr: (ctx: Function_call_exprContext) => void;
|
|
@@ -59,6 +60,7 @@ export declare class BaseVisitor extends CircuitScriptVisitor<ComplexType | AnyR
|
|
|
59
60
|
visitFlow_expressions: (ctx: Flow_expressionsContext) => void;
|
|
60
61
|
visitArray_expr: (ctx: Array_exprContext) => void;
|
|
61
62
|
visitArrayExpr: (ctx: ArrayExprContext) => void;
|
|
63
|
+
visitArrayIndexExpr: (ctx: ArrayIndexExprContext) => void;
|
|
62
64
|
protected setResult(ctx: ParserRuleContext, value: any): void;
|
|
63
65
|
protected getResult(ctx: ParserRuleContext): any;
|
|
64
66
|
visitResult(ctx: ParserRuleContext): any;
|
|
@@ -109,30 +109,31 @@ export declare class CircuitScriptParser extends antlr.Parser {
|
|
|
109
109
|
static readonly RULE_function_args_expr = 37;
|
|
110
110
|
static readonly RULE_atom_expr = 38;
|
|
111
111
|
static readonly RULE_trailer_expr = 39;
|
|
112
|
-
static readonly
|
|
113
|
-
static readonly
|
|
114
|
-
static readonly
|
|
115
|
-
static readonly
|
|
116
|
-
static readonly
|
|
117
|
-
static readonly
|
|
118
|
-
static readonly
|
|
119
|
-
static readonly
|
|
120
|
-
static readonly
|
|
121
|
-
static readonly
|
|
122
|
-
static readonly
|
|
123
|
-
static readonly
|
|
124
|
-
static readonly
|
|
125
|
-
static readonly
|
|
126
|
-
static readonly
|
|
127
|
-
static readonly
|
|
128
|
-
static readonly
|
|
129
|
-
static readonly
|
|
130
|
-
static readonly
|
|
131
|
-
static readonly
|
|
132
|
-
static readonly
|
|
133
|
-
static readonly
|
|
134
|
-
static readonly
|
|
135
|
-
static readonly
|
|
112
|
+
static readonly RULE_trailer_expr2 = 40;
|
|
113
|
+
static readonly RULE_function_call_expr = 41;
|
|
114
|
+
static readonly RULE_net_namespace_expr = 42;
|
|
115
|
+
static readonly RULE_function_return_expr = 43;
|
|
116
|
+
static readonly RULE_property_block_expr = 44;
|
|
117
|
+
static readonly RULE_create_component_expr = 45;
|
|
118
|
+
static readonly RULE_graphic_expressions_block = 46;
|
|
119
|
+
static readonly RULE_create_graphic_expr = 47;
|
|
120
|
+
static readonly RULE_create_module_expr = 48;
|
|
121
|
+
static readonly RULE_nested_properties_inner = 49;
|
|
122
|
+
static readonly RULE_graphic_expr = 50;
|
|
123
|
+
static readonly RULE_property_expr = 51;
|
|
124
|
+
static readonly RULE_property_key_expr = 52;
|
|
125
|
+
static readonly RULE_property_value_expr = 53;
|
|
126
|
+
static readonly RULE_wire_atom_expr = 54;
|
|
127
|
+
static readonly RULE_wire_expr = 55;
|
|
128
|
+
static readonly RULE_array_expr = 56;
|
|
129
|
+
static readonly RULE_point_expr = 57;
|
|
130
|
+
static readonly RULE_import_expr = 58;
|
|
131
|
+
static readonly RULE_frame_expr = 59;
|
|
132
|
+
static readonly RULE_if_expr = 60;
|
|
133
|
+
static readonly RULE_if_inner_expr = 61;
|
|
134
|
+
static readonly RULE_else_expr = 62;
|
|
135
|
+
static readonly RULE_while_expr = 63;
|
|
136
|
+
static readonly RULE_for_expr = 64;
|
|
136
137
|
static readonly literalNames: (string | null)[];
|
|
137
138
|
static readonly symbolicNames: (string | null)[];
|
|
138
139
|
static readonly ruleNames: string[];
|
|
@@ -184,6 +185,7 @@ export declare class CircuitScriptParser extends antlr.Parser {
|
|
|
184
185
|
function_args_expr(): Function_args_exprContext;
|
|
185
186
|
atom_expr(): Atom_exprContext;
|
|
186
187
|
trailer_expr(): Trailer_exprContext;
|
|
188
|
+
trailer_expr2(): Trailer_expr2Context;
|
|
187
189
|
function_call_expr(): Function_call_exprContext;
|
|
188
190
|
net_namespace_expr(): Net_namespace_exprContext;
|
|
189
191
|
function_return_expr(): Function_return_exprContext;
|
|
@@ -507,6 +509,12 @@ export declare class ArrayExprContext extends Data_exprContext {
|
|
|
507
509
|
array_expr(): Array_exprContext;
|
|
508
510
|
accept<Result>(visitor: CircuitScriptVisitor<Result>): Result | null;
|
|
509
511
|
}
|
|
512
|
+
export declare class ArrayIndexExprContext extends Data_exprContext {
|
|
513
|
+
constructor(ctx: Data_exprContext);
|
|
514
|
+
data_expr(): Data_exprContext[];
|
|
515
|
+
data_expr(i: number): Data_exprContext | null;
|
|
516
|
+
accept<Result>(visitor: CircuitScriptVisitor<Result>): Result | null;
|
|
517
|
+
}
|
|
510
518
|
export declare class FunctionCallExprContext extends Data_exprContext {
|
|
511
519
|
constructor(ctx: Data_exprContext);
|
|
512
520
|
function_call_expr(): Function_call_exprContext;
|
|
@@ -634,8 +642,9 @@ export declare class Function_args_exprContext extends antlr.ParserRuleContext {
|
|
|
634
642
|
}
|
|
635
643
|
export declare class Atom_exprContext extends antlr.ParserRuleContext {
|
|
636
644
|
constructor(parent: antlr.ParserRuleContext | null, invokingState: number);
|
|
637
|
-
ID(): antlr.TerminalNode
|
|
638
|
-
|
|
645
|
+
ID(): antlr.TerminalNode;
|
|
646
|
+
trailer_expr2(): Trailer_expr2Context[];
|
|
647
|
+
trailer_expr2(i: number): Trailer_expr2Context | null;
|
|
639
648
|
get ruleIndex(): number;
|
|
640
649
|
accept<Result>(visitor: CircuitScriptVisitor<Result>): Result | null;
|
|
641
650
|
}
|
|
@@ -644,7 +653,14 @@ export declare class Trailer_exprContext extends antlr.ParserRuleContext {
|
|
|
644
653
|
OPEN_PAREN(): antlr.TerminalNode | null;
|
|
645
654
|
CLOSE_PAREN(): antlr.TerminalNode | null;
|
|
646
655
|
parameters(): ParametersContext | null;
|
|
656
|
+
trailer_expr2(): Trailer_expr2Context | null;
|
|
657
|
+
get ruleIndex(): number;
|
|
658
|
+
accept<Result>(visitor: CircuitScriptVisitor<Result>): Result | null;
|
|
659
|
+
}
|
|
660
|
+
export declare class Trailer_expr2Context extends antlr.ParserRuleContext {
|
|
661
|
+
constructor(parent: antlr.ParserRuleContext | null, invokingState: number);
|
|
647
662
|
ID(): antlr.TerminalNode | null;
|
|
663
|
+
data_expr(): Data_exprContext | null;
|
|
648
664
|
get ruleIndex(): number;
|
|
649
665
|
accept<Result>(visitor: CircuitScriptVisitor<Result>): Result | null;
|
|
650
666
|
}
|
|
@@ -31,6 +31,7 @@ import { ParametersContext } from "./CircuitScriptParser.js";
|
|
|
31
31
|
import { Property_set_exprContext } from "./CircuitScriptParser.js";
|
|
32
32
|
import { Double_dot_property_set_exprContext } from "./CircuitScriptParser.js";
|
|
33
33
|
import { ArrayExprContext } from "./CircuitScriptParser.js";
|
|
34
|
+
import { ArrayIndexExprContext } from "./CircuitScriptParser.js";
|
|
34
35
|
import { FunctionCallExprContext } from "./CircuitScriptParser.js";
|
|
35
36
|
import { AdditionExprContext } from "./CircuitScriptParser.js";
|
|
36
37
|
import { MultiplyExprContext } from "./CircuitScriptParser.js";
|
|
@@ -48,6 +49,7 @@ import { Function_exprContext } from "./CircuitScriptParser.js";
|
|
|
48
49
|
import { Function_args_exprContext } from "./CircuitScriptParser.js";
|
|
49
50
|
import { Atom_exprContext } from "./CircuitScriptParser.js";
|
|
50
51
|
import { Trailer_exprContext } from "./CircuitScriptParser.js";
|
|
52
|
+
import { Trailer_expr2Context } from "./CircuitScriptParser.js";
|
|
51
53
|
import { Function_call_exprContext } from "./CircuitScriptParser.js";
|
|
52
54
|
import { Net_namespace_exprContext } from "./CircuitScriptParser.js";
|
|
53
55
|
import { Function_return_exprContext } from "./CircuitScriptParser.js";
|
|
@@ -108,6 +110,7 @@ export declare class CircuitScriptVisitor<Result> extends AbstractParseTreeVisit
|
|
|
108
110
|
visitProperty_set_expr?: (ctx: Property_set_exprContext) => Result;
|
|
109
111
|
visitDouble_dot_property_set_expr?: (ctx: Double_dot_property_set_exprContext) => Result;
|
|
110
112
|
visitArrayExpr?: (ctx: ArrayExprContext) => Result;
|
|
113
|
+
visitArrayIndexExpr?: (ctx: ArrayIndexExprContext) => Result;
|
|
111
114
|
visitFunctionCallExpr?: (ctx: FunctionCallExprContext) => Result;
|
|
112
115
|
visitAdditionExpr?: (ctx: AdditionExprContext) => Result;
|
|
113
116
|
visitMultiplyExpr?: (ctx: MultiplyExprContext) => Result;
|
|
@@ -125,6 +128,7 @@ export declare class CircuitScriptVisitor<Result> extends AbstractParseTreeVisit
|
|
|
125
128
|
visitFunction_args_expr?: (ctx: Function_args_exprContext) => Result;
|
|
126
129
|
visitAtom_expr?: (ctx: Atom_exprContext) => Result;
|
|
127
130
|
visitTrailer_expr?: (ctx: Trailer_exprContext) => Result;
|
|
131
|
+
visitTrailer_expr2?: (ctx: Trailer_expr2Context) => Result;
|
|
128
132
|
visitFunction_call_expr?: (ctx: Function_call_exprContext) => Result;
|
|
129
133
|
visitNet_namespace_expr?: (ctx: Net_namespace_exprContext) => Result;
|
|
130
134
|
visitFunction_return_expr?: (ctx: Function_return_exprContext) => Result;
|