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.
- package/LICENSE +1 -1
- package/dist/cjs/BaseVisitor.js +485 -0
- package/dist/cjs/SemanticTokenVisitor.js +218 -0
- package/dist/cjs/SymbolValidatorVisitor.js +233 -0
- package/dist/cjs/antlr/CircuitScriptLexer.js +256 -219
- package/dist/cjs/antlr/CircuitScriptParser.js +2891 -2151
- package/dist/cjs/antlr/CircuitScriptVisitor.js +4 -3
- package/dist/cjs/draw_symbols.js +73 -22
- package/dist/cjs/execute.js +70 -78
- package/dist/cjs/export.js +91 -5
- package/dist/cjs/geometry.js +28 -8
- package/dist/cjs/globals.js +1 -2
- package/dist/cjs/helpers.js +180 -7
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/layout.js +8 -0
- package/dist/cjs/lexer.js +19 -22
- package/dist/cjs/main.js +27 -20
- package/dist/cjs/objects/ClassComponent.js +4 -0
- package/dist/cjs/objects/ExecutionScope.js +1 -0
- package/dist/cjs/objects/types.js +7 -1
- package/dist/cjs/parser.js +29 -258
- package/dist/cjs/render.js +1 -1
- package/dist/cjs/validate.js +81 -0
- package/dist/cjs/visitor.js +601 -823
- package/dist/esm/BaseVisitor.mjs +486 -0
- package/dist/esm/SemanticTokenVisitor.mjs +215 -0
- package/dist/esm/SymbolValidatorVisitor.mjs +222 -0
- package/dist/esm/antlr/CircuitScriptLexer.mjs +231 -218
- package/dist/esm/antlr/CircuitScriptParser.mjs +2852 -2144
- package/dist/esm/antlr/CircuitScriptVisitor.mjs +13 -4
- package/dist/esm/draw_symbols.mjs +74 -23
- package/dist/esm/execute.mjs +70 -75
- package/dist/esm/export.mjs +89 -6
- package/dist/esm/geometry.mjs +28 -8
- package/dist/esm/globals.mjs +1 -2
- package/dist/esm/helpers.mjs +171 -9
- package/dist/esm/index.mjs +2 -0
- package/dist/esm/layout.mjs +8 -0
- package/dist/esm/lexer.mjs +10 -10
- package/dist/esm/main.mjs +28 -21
- package/dist/esm/objects/ClassComponent.mjs +4 -0
- package/dist/esm/objects/ExecutionScope.mjs +1 -0
- package/dist/esm/objects/types.mjs +6 -0
- package/dist/esm/parser.mjs +25 -230
- package/dist/esm/render.mjs +2 -2
- package/dist/esm/validate.mjs +74 -0
- package/dist/esm/visitor.mjs +415 -643
- package/dist/types/BaseVisitor.d.ts +66 -0
- package/dist/types/SemanticTokenVisitor.d.ts +36 -0
- package/dist/types/SymbolValidatorVisitor.d.ts +61 -0
- package/dist/types/antlr/CircuitScriptLexer.d.ts +37 -29
- package/dist/types/antlr/CircuitScriptParser.d.ts +606 -494
- package/dist/types/antlr/CircuitScriptVisitor.d.ts +78 -60
- package/dist/types/draw_symbols.d.ts +12 -3
- package/dist/types/execute.d.ts +5 -10
- package/dist/types/export.d.ts +27 -1
- package/dist/types/geometry.d.ts +4 -0
- package/dist/types/globals.d.ts +2 -3
- package/dist/types/helpers.d.ts +32 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/lexer.d.ts +2 -2
- package/dist/types/objects/ClassComponent.d.ts +1 -0
- package/dist/types/objects/ExecutionScope.d.ts +4 -1
- package/dist/types/objects/types.d.ts +5 -0
- package/dist/types/parser.d.ts +15 -28
- package/dist/types/validate.d.ts +2 -0
- package/dist/types/visitor.d.ts +43 -95
- package/fonts/Inter-Bold.ttf +0 -0
- package/fonts/Inter-Regular.ttf +0 -0
- package/fonts/OpenSans-Regular.ttf +0 -0
- package/fonts/Roboto-Regular.ttf +0 -0
- package/libs/lib.cst +184 -0
- package/package.json +11 -6
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
exports.CircuitScriptVisitor = void 0;
|
|
4
|
+
const antlr4ng_1 = require("antlr4ng");
|
|
5
|
+
class CircuitScriptVisitor extends antlr4ng_1.AbstractParseTreeVisitor {
|
|
5
6
|
}
|
|
6
|
-
exports.
|
|
7
|
+
exports.CircuitScriptVisitor = CircuitScriptVisitor;
|
package/dist/cjs/draw_symbols.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
]
|
|
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
|
-
|
|
315
|
-
|
|
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
|
|
347
|
-
const [pinId, , angle] =
|
|
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
|
-
|
|
687
|
-
|
|
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
|
-
|
|
701
|
-
|
|
702
|
-
|
|
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
|
-
|
|
724
|
-
|
|
725
|
-
|
|
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
|
-
|
|
734
|
-
|
|
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],
|
package/dist/cjs/execute.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPortSide = exports.
|
|
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.
|
|
35
|
+
this.log('create new execution context', this.namespace, this.name, this.scope.indentLevel);
|
|
36
|
+
this.parentContext = parent;
|
|
29
37
|
}
|
|
30
|
-
|
|
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.
|
|
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.
|
|
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 (
|
|
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.
|
|
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.
|
|
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.
|
|
168
|
+
this.log('set net', netName, 'component', component);
|
|
160
169
|
}
|
|
161
|
-
const
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
206
|
-
const { addSequence = false
|
|
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.
|
|
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.
|
|
257
|
-
const { addSequence = false
|
|
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
|
-
|
|
286
|
-
|
|
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
|
-
|
|
295
|
-
|
|
296
|
-
|
|
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,
|
|
300
|
-
|
|
301
|
-
this.linkComponentPinNet(component, 1,
|
|
302
|
-
this.
|
|
303
|
-
return
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
425
|
+
this.log('did not find block point');
|
|
427
426
|
return null;
|
|
428
427
|
}
|
|
429
428
|
breakBranch() {
|
|
430
|
-
this.
|
|
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.
|
|
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.
|
|
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.
|
|
496
|
+
this.log('save function to cache:', functionName);
|
|
498
497
|
this.__functionCache[functionName] = __runFunc;
|
|
499
498
|
}
|
|
500
499
|
else {
|
|
501
|
-
this.
|
|
500
|
+
this.log('found function in cache:', functionName);
|
|
502
501
|
__runFunc = this.__functionCache[functionName];
|
|
503
502
|
}
|
|
504
503
|
if (__runFunc !== null) {
|
|
505
|
-
this.
|
|
504
|
+
this.log(`call function '${functionName}'`);
|
|
506
505
|
const functionResult = __runFunc(functionParams, { netNamespace });
|
|
507
|
-
this.
|
|
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.
|
|
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 (
|
|
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.
|
|
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.
|
|
610
|
+
this.log(`${net.namespace}${net.name} ${net.priority}`);
|
|
611
611
|
}
|
|
612
612
|
return accum;
|
|
613
613
|
}, []);
|
|
614
|
-
this.
|
|
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.
|
|
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.
|
|
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.
|
|
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) {
|