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,15 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
1
|
+
import { AbstractParseTreeVisitor } from "antlr4ng";
|
|
2
|
+
export class CircuitScriptVisitor extends AbstractParseTreeVisitor {
|
|
3
3
|
visitScript;
|
|
4
4
|
visitExpression;
|
|
5
5
|
visitPath_blocks;
|
|
6
6
|
visitPath_block_inner;
|
|
7
7
|
visitProperty_set_expr2;
|
|
8
8
|
visitAssignment_expr2;
|
|
9
|
+
visitPin_select_expr;
|
|
10
|
+
visitComponent_modifier_expr;
|
|
9
11
|
visitData_expr_with_assignment;
|
|
10
12
|
visitAdd_component_expr;
|
|
11
13
|
visitComponent_select_expr;
|
|
12
|
-
visitPin_select_expr;
|
|
13
14
|
visitPin_select_expr2;
|
|
14
15
|
visitAt_component_expr;
|
|
15
16
|
visitTo_component_expr;
|
|
@@ -27,8 +28,10 @@ export default class CircuitScriptVisitor extends ParseTreeVisitor {
|
|
|
27
28
|
visitParameters;
|
|
28
29
|
visitProperty_set_expr;
|
|
29
30
|
visitDouble_dot_property_set_expr;
|
|
31
|
+
visitFunctionCallExpr;
|
|
30
32
|
visitAdditionExpr;
|
|
31
33
|
visitMultiplyExpr;
|
|
34
|
+
visitLogicalOperatorExpr;
|
|
32
35
|
visitDataExpr;
|
|
33
36
|
visitUnaryOperatorExpr;
|
|
34
37
|
visitValueAtomExpr;
|
|
@@ -42,18 +45,24 @@ export default class CircuitScriptVisitor extends ParseTreeVisitor {
|
|
|
42
45
|
visitFunction_args_expr;
|
|
43
46
|
visitAtom_expr;
|
|
44
47
|
visitTrailer_expr;
|
|
48
|
+
visitFunction_call_expr;
|
|
45
49
|
visitNet_namespace_expr;
|
|
46
50
|
visitFunction_return_expr;
|
|
47
51
|
visitCreate_component_expr;
|
|
48
52
|
visitCreate_graphic_expr;
|
|
49
|
-
|
|
53
|
+
visitGraphic_expr;
|
|
50
54
|
visitProperty_expr;
|
|
51
55
|
visitProperty_key_expr;
|
|
52
56
|
visitNested_properties;
|
|
53
57
|
visitSingle_line_property;
|
|
54
58
|
visitBlank_expr;
|
|
59
|
+
visitWire_expr_direction_value;
|
|
60
|
+
visitWire_expr_direction_only;
|
|
55
61
|
visitWire_expr;
|
|
56
62
|
visitPoint_expr;
|
|
57
63
|
visitImport_expr;
|
|
58
64
|
visitFrame_expr;
|
|
65
|
+
visitIf_expr;
|
|
66
|
+
visitIf_inner_expr;
|
|
67
|
+
visitElse_expr;
|
|
59
68
|
}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { SymbolPinSide, defaultFont } from "./globals.mjs";
|
|
1
|
+
import { ReferenceTypes, SymbolPinSide, defaultFont } from "./globals.mjs";
|
|
2
2
|
import { Geometry, GeometryProp, HorizontalAlign, Label, VerticalAlign } from "./geometry.mjs";
|
|
3
|
+
import { PinTypes } from "./objects/PinTypes.mjs";
|
|
3
4
|
const defaultSymbolLineWidth = 2;
|
|
4
5
|
export class SymbolGraphic {
|
|
5
6
|
drawPortsName = true;
|
|
6
7
|
displayBounds = true;
|
|
7
8
|
drawing;
|
|
8
9
|
_angle = 0;
|
|
10
|
+
_flipX = 0;
|
|
11
|
+
_flipY = 0;
|
|
9
12
|
width;
|
|
10
13
|
height;
|
|
11
14
|
labelTexts = new Map();
|
|
@@ -15,6 +18,18 @@ export class SymbolGraphic {
|
|
|
15
18
|
set angle(value) {
|
|
16
19
|
this._angle = value;
|
|
17
20
|
}
|
|
21
|
+
get flipX() {
|
|
22
|
+
return this._flipX;
|
|
23
|
+
}
|
|
24
|
+
set flipX(value) {
|
|
25
|
+
this._flipX = value;
|
|
26
|
+
}
|
|
27
|
+
get flipY() {
|
|
28
|
+
return this._flipY;
|
|
29
|
+
}
|
|
30
|
+
set flipY(value) {
|
|
31
|
+
this._flipY = value;
|
|
32
|
+
}
|
|
18
33
|
refreshDrawing(calculateSize = true) {
|
|
19
34
|
this.generateDrawing();
|
|
20
35
|
calculateSize && this.calculateSize();
|
|
@@ -40,10 +55,11 @@ export class SymbolGraphic {
|
|
|
40
55
|
drawPlaceRemove(group, extra) {
|
|
41
56
|
if (extra && extra.place === false) {
|
|
42
57
|
const { start, end } = this.drawing.getBoundingBox(true);
|
|
43
|
-
|
|
58
|
+
const path = Geometry.roundPathValues([
|
|
44
59
|
"M", start[0], start[1], "L", end[0], end[1],
|
|
45
60
|
"M", end[0], start[1], "L", start[0], end[1]
|
|
46
|
-
]
|
|
61
|
+
]);
|
|
62
|
+
group.path(path)
|
|
47
63
|
.stroke({
|
|
48
64
|
width: defaultSymbolLineWidth,
|
|
49
65
|
color: 'red'
|
|
@@ -110,27 +126,33 @@ export class SymbolGraphic {
|
|
|
110
126
|
}
|
|
111
127
|
switch (useAnchor) {
|
|
112
128
|
case HorizontalAlign.Left:
|
|
113
|
-
anchorStyle = 'start';
|
|
129
|
+
anchorStyle = (this.flipX === 0) ? 'start' : 'end';
|
|
114
130
|
break;
|
|
115
131
|
case HorizontalAlign.Middle:
|
|
116
132
|
anchorStyle = 'middle';
|
|
117
133
|
break;
|
|
118
134
|
case HorizontalAlign.Right:
|
|
119
|
-
anchorStyle = 'end';
|
|
135
|
+
anchorStyle = (this.flipX === 0) ? 'end' : 'start';
|
|
120
136
|
break;
|
|
121
137
|
}
|
|
122
138
|
switch (useDominantBaseline) {
|
|
123
139
|
case VerticalAlign.Top:
|
|
124
|
-
dominantBaseline = 'hanging';
|
|
140
|
+
dominantBaseline = (this.flipY === 0) ? 'hanging' : 'text-top';
|
|
125
141
|
break;
|
|
126
142
|
case VerticalAlign.Middle:
|
|
127
143
|
dominantBaseline = 'middle';
|
|
128
144
|
break;
|
|
129
145
|
case VerticalAlign.Bottom:
|
|
130
|
-
dominantBaseline = 'text-top';
|
|
146
|
+
dominantBaseline = (this.flipY === 0) ? 'text-top' : 'hanging';
|
|
131
147
|
break;
|
|
132
148
|
}
|
|
133
149
|
const position = tmpLabel.getLabelPosition();
|
|
150
|
+
if (this.flipX !== 0) {
|
|
151
|
+
position[0] *= -1;
|
|
152
|
+
}
|
|
153
|
+
if (this.flipY !== 0) {
|
|
154
|
+
position[1] *= -1;
|
|
155
|
+
}
|
|
134
156
|
const useFont = defaultFont;
|
|
135
157
|
const textContainer = group.group();
|
|
136
158
|
const text = textContainer.text(tmpLabel.text)
|
|
@@ -154,11 +176,26 @@ export class SymbolGraphic {
|
|
|
154
176
|
translateY = position[1];
|
|
155
177
|
useRotateAngle = this.angle;
|
|
156
178
|
}
|
|
179
|
+
translateX = this.roundValues(translateX);
|
|
180
|
+
translateY = this.roundValues(translateY);
|
|
157
181
|
text.rotate(labelAngle);
|
|
158
182
|
textContainer.translate(translateX, translateY)
|
|
159
183
|
.rotate(useRotateAngle, -translateX, -translateY);
|
|
184
|
+
const { a, b, c, d, e, f } = textContainer.matrix();
|
|
185
|
+
const newMatrix = {
|
|
186
|
+
a: this.roundValues(a),
|
|
187
|
+
b: this.roundValues(b),
|
|
188
|
+
c: this.roundValues(c),
|
|
189
|
+
d: this.roundValues(d),
|
|
190
|
+
e: this.roundValues(e),
|
|
191
|
+
f: this.roundValues(f),
|
|
192
|
+
};
|
|
193
|
+
textContainer.transform(newMatrix);
|
|
160
194
|
});
|
|
161
195
|
}
|
|
196
|
+
roundValues(value) {
|
|
197
|
+
return +value.toFixed(7);
|
|
198
|
+
}
|
|
162
199
|
flipTextAnchor(value) {
|
|
163
200
|
if (value === HorizontalAlign.Left) {
|
|
164
201
|
return HorizontalAlign.Right;
|
|
@@ -229,6 +266,8 @@ export class SymbolPlaceholder extends SymbolGraphic {
|
|
|
229
266
|
drawing.log("=== start generate drawing ===");
|
|
230
267
|
drawing.clear();
|
|
231
268
|
drawing.angle = this._angle;
|
|
269
|
+
drawing.flipX = this._flipX;
|
|
270
|
+
drawing.flipY = this._flipY;
|
|
232
271
|
const commands = drawing.getCommands();
|
|
233
272
|
drawing.log('id: ', drawing.id, 'angle: ', this._angle, "commands:", commands.length);
|
|
234
273
|
commands.forEach(([commandName, positionParams, keywordParams]) => {
|
|
@@ -305,12 +344,16 @@ export class SymbolPlaceholder extends SymbolGraphic {
|
|
|
305
344
|
drawing.log('add pin', ...positionParams);
|
|
306
345
|
const keywordDisplayPinId = 'display_pin_id';
|
|
307
346
|
let displayPinId = true;
|
|
308
|
-
if (keywordParams.has(keywordDisplayPinId)
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
}
|
|
347
|
+
if (keywordParams.has(keywordDisplayPinId)
|
|
348
|
+
&& keywordParams.get(keywordDisplayPinId) === 0) {
|
|
349
|
+
displayPinId = false;
|
|
312
350
|
}
|
|
313
351
|
let pinNameParam = null;
|
|
352
|
+
let pinType = PinTypes.Any;
|
|
353
|
+
if (positionParams[1].type && positionParams[1].type === ReferenceTypes.pinType) {
|
|
354
|
+
pinType = positionParams[1].value;
|
|
355
|
+
positionParams = [positionParams[0], ...positionParams.slice(2)];
|
|
356
|
+
}
|
|
314
357
|
if (typeof positionParams[1] === 'string') {
|
|
315
358
|
pinNameParam = positionParams[1];
|
|
316
359
|
positionParams = [positionParams[0], ...positionParams.slice(2)];
|
|
@@ -338,8 +381,8 @@ export class SymbolPlaceholder extends SymbolGraphic {
|
|
|
338
381
|
];
|
|
339
382
|
}
|
|
340
383
|
drawing.addPin(...positionParams);
|
|
341
|
-
const
|
|
342
|
-
const [pinId, , angle] =
|
|
384
|
+
const lastAddedPin = this.drawing.pins[this.drawing.pins.length - 1];
|
|
385
|
+
const [pinId, , angle] = lastAddedPin;
|
|
343
386
|
const [, , , endX, endY] = positionParams;
|
|
344
387
|
let pinNameAlignment = HorizontalAlign.Left;
|
|
345
388
|
let pinNameOffsetX = 4;
|
|
@@ -433,6 +476,8 @@ export class SymbolCustom extends SymbolGraphic {
|
|
|
433
476
|
const maxRightPins = Math.max(...rightPins.map(item => item.position)) + 1;
|
|
434
477
|
const drawing = new SymbolDrawing();
|
|
435
478
|
drawing.angle = this._angle;
|
|
479
|
+
drawing.flipX = this._flipX;
|
|
480
|
+
drawing.flipY = this._flipY;
|
|
436
481
|
const bodyWidth = this.bodyWidth;
|
|
437
482
|
const bodyHeight = (1 + Math.max(maxLeftPins, maxRightPins)) * this.pinSpacing;
|
|
438
483
|
drawing.addRect(0, 0, bodyWidth, bodyHeight);
|
|
@@ -498,6 +543,8 @@ export class SymbolDrawing {
|
|
|
498
543
|
items = [];
|
|
499
544
|
pins = [];
|
|
500
545
|
angle = 0;
|
|
546
|
+
flipX = 0;
|
|
547
|
+
flipY = 0;
|
|
501
548
|
mainOrigin = [0, 0];
|
|
502
549
|
logger = null;
|
|
503
550
|
clear() {
|
|
@@ -676,8 +723,9 @@ export class SymbolDrawing {
|
|
|
676
723
|
}
|
|
677
724
|
}
|
|
678
725
|
else {
|
|
679
|
-
|
|
680
|
-
|
|
726
|
+
let tmpResult = Geometry.groupFlip([item], this.flipX, this.flipY);
|
|
727
|
+
tmpResult = Geometry.groupRotate(tmpResult, this.angle, this.mainOrigin);
|
|
728
|
+
const { path, isClosedPolygon } = this.featuresToPath(tmpResult);
|
|
681
729
|
pathItems.push({
|
|
682
730
|
path: path,
|
|
683
731
|
lineWidth: currentLineWidth,
|
|
@@ -690,9 +738,10 @@ export class SymbolDrawing {
|
|
|
690
738
|
return pathItems;
|
|
691
739
|
}
|
|
692
740
|
getPinsPath() {
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
741
|
+
let features = this.pins.map(item => item[1]);
|
|
742
|
+
features = Geometry.groupFlip(features, this.flipX, this.flipY);
|
|
743
|
+
features = Geometry.groupRotate(features, this.angle, this.mainOrigin);
|
|
744
|
+
const { path } = this.featuresToPath(features);
|
|
696
745
|
return path;
|
|
697
746
|
}
|
|
698
747
|
getLabels() {
|
|
@@ -713,9 +762,10 @@ export class SymbolDrawing {
|
|
|
713
762
|
}
|
|
714
763
|
return accum;
|
|
715
764
|
}, []);
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
765
|
+
let features = [...drawingFeatures, ...pinFeatures];
|
|
766
|
+
features = Geometry.groupFlip(features, this.flipX, this.flipY);
|
|
767
|
+
features = Geometry.groupRotate(features, this.angle, this.mainOrigin);
|
|
768
|
+
return Geometry.groupBounds(features);
|
|
719
769
|
}
|
|
720
770
|
getPinPosition(pinId) {
|
|
721
771
|
const pin = this.pins.find(item => {
|
|
@@ -723,8 +773,9 @@ export class SymbolDrawing {
|
|
|
723
773
|
});
|
|
724
774
|
if (pin) {
|
|
725
775
|
const [, feature, angle] = pin;
|
|
726
|
-
|
|
727
|
-
|
|
776
|
+
let tmpFeature = Geometry.flip(feature, this.flipX, this.flipY);
|
|
777
|
+
tmpFeature = Geometry.rotateDegs(tmpFeature, this.angle, this.mainOrigin);
|
|
778
|
+
const coords = Geometry.getCoords(tmpFeature);
|
|
728
779
|
return {
|
|
729
780
|
start: coords[0],
|
|
730
781
|
end: coords[1],
|
package/dist/esm/execute.mjs
CHANGED
|
@@ -18,7 +18,8 @@ export class ExecutionContext {
|
|
|
18
18
|
silent = false;
|
|
19
19
|
logger;
|
|
20
20
|
__functionCache = {};
|
|
21
|
-
|
|
21
|
+
parentContext;
|
|
22
|
+
constructor(name, namespace, netNamespace, executionLevel = 0, indentLevel = 0, silent = false, logger, parent) {
|
|
22
23
|
this.name = name;
|
|
23
24
|
this.namespace = namespace;
|
|
24
25
|
this.netNamespace = netNamespace;
|
|
@@ -27,10 +28,18 @@ export class ExecutionContext {
|
|
|
27
28
|
this.scope = ExecutionScope.create();
|
|
28
29
|
this.scope.indentLevel = indentLevel;
|
|
29
30
|
this.setupRoot();
|
|
31
|
+
if (name === '__') {
|
|
32
|
+
this.scope.sequence.push([
|
|
33
|
+
SequenceAction.At,
|
|
34
|
+
this.scope.componentRoot,
|
|
35
|
+
this.scope.currentPin
|
|
36
|
+
]);
|
|
37
|
+
}
|
|
30
38
|
this.silent = silent;
|
|
31
|
-
this.
|
|
39
|
+
this.log('create new execution context', this.namespace, this.name, this.scope.indentLevel);
|
|
40
|
+
this.parentContext = parent;
|
|
32
41
|
}
|
|
33
|
-
|
|
42
|
+
log(...params) {
|
|
34
43
|
const indentOutput = ''.padStart(this.scope.indentLevel * 4, ' ');
|
|
35
44
|
const indentLevelText = this.scope.indentLevel
|
|
36
45
|
.toString()
|
|
@@ -44,18 +53,13 @@ export class ExecutionContext {
|
|
|
44
53
|
}
|
|
45
54
|
setupRoot() {
|
|
46
55
|
const componentRoot = ClassComponent.simple(GlobalNames.__root, 1, '__root');
|
|
47
|
-
componentRoot.typeProp = ComponentTypes.
|
|
56
|
+
componentRoot.typeProp = ComponentTypes.point;
|
|
57
|
+
componentRoot.displayProp = 'point';
|
|
48
58
|
this.scope.instances.set(GlobalNames.__root, componentRoot);
|
|
49
59
|
this.scope.currentComponent = componentRoot;
|
|
50
60
|
this.scope.currentPin = componentRoot.getDefaultPin();
|
|
51
61
|
this.scope.componentRoot = componentRoot;
|
|
52
62
|
}
|
|
53
|
-
instanceExists(instanceName) {
|
|
54
|
-
return this.scope.instances.has(instanceName);
|
|
55
|
-
}
|
|
56
|
-
getComponent(instanceName) {
|
|
57
|
-
return this.scope.instances.get(instanceName);
|
|
58
|
-
}
|
|
59
63
|
getUniqueInstanceName(className) {
|
|
60
64
|
let extraPrefix = '';
|
|
61
65
|
switch (className) {
|
|
@@ -90,7 +94,7 @@ export class ExecutionContext {
|
|
|
90
94
|
const net2 = net2_exists
|
|
91
95
|
? this.scope.getNet(component2, component2Pin)
|
|
92
96
|
: null;
|
|
93
|
-
this.
|
|
97
|
+
this.log('link nets', component1, component1Pin, net1, 'to', component2, component2Pin, net2);
|
|
94
98
|
let returnNet;
|
|
95
99
|
if (net1 === null && net2 === null) {
|
|
96
100
|
const tmpNet = new Net(this.netNamespace, this.getUniqueNetName());
|
|
@@ -140,33 +144,34 @@ export class ExecutionContext {
|
|
|
140
144
|
pins.forEach((pin) => {
|
|
141
145
|
component.pins.set(pin.id, pin);
|
|
142
146
|
});
|
|
147
|
+
component.arrangeProps = props.arrange ?? null;
|
|
148
|
+
component.displayProp = props.display ?? null;
|
|
149
|
+
component.widthProp = props.width ?? null;
|
|
150
|
+
component.typeProp = props.type ?? null;
|
|
151
|
+
component.copyProp = props.copy ?? false;
|
|
143
152
|
const paramsMap = new Map();
|
|
144
153
|
params.forEach((param) => {
|
|
145
154
|
component.parameters.set(param.paramName, param.paramValue);
|
|
146
155
|
paramsMap.set(param.paramName, param.paramValue);
|
|
147
156
|
});
|
|
148
|
-
if (
|
|
157
|
+
if (component.typeProp === ComponentTypes.net
|
|
158
|
+
|| component.typeProp === ComponentTypes.label) {
|
|
149
159
|
const netName = paramsMap.get(ParamKeys.net_name);
|
|
150
160
|
const priority = paramsMap.get(ParamKeys.priority);
|
|
151
161
|
const result = this.resolveNet(netName, this.netNamespace);
|
|
152
162
|
let tmpNet;
|
|
153
163
|
if (result.found) {
|
|
154
164
|
tmpNet = result.net;
|
|
155
|
-
this.
|
|
165
|
+
this.log('net found', tmpNet.namespace, tmpNet.name);
|
|
156
166
|
}
|
|
157
167
|
else {
|
|
158
168
|
tmpNet = new Net(this.netNamespace, netName, priority);
|
|
159
|
-
this.
|
|
169
|
+
this.log('net not found, added net instance', tmpNet.namespace, tmpNet.name);
|
|
160
170
|
}
|
|
161
171
|
this.scope.setNet(component, 1, tmpNet);
|
|
162
|
-
this.
|
|
172
|
+
this.log('set net', netName, 'component', component);
|
|
163
173
|
}
|
|
164
|
-
const
|
|
165
|
-
component.arrangeProps = arrange;
|
|
166
|
-
component.displayProp = props.display ?? null;
|
|
167
|
-
component.widthProp = props.width ?? null;
|
|
168
|
-
component.typeProp = props.type ?? null;
|
|
169
|
-
const portSides = getPortSide(component.pins, arrange);
|
|
174
|
+
const portSides = getPortSide(component.pins, component.arrangeProps);
|
|
170
175
|
portSides.forEach(({ pinId, side, position }) => {
|
|
171
176
|
if (component.pins.has(pinId)) {
|
|
172
177
|
const tmpPin = component.pins.get(pinId);
|
|
@@ -178,17 +183,21 @@ export class ExecutionContext {
|
|
|
178
183
|
const pinsOutput = pins.map((pin) => {
|
|
179
184
|
return pin.id + ':' + pin.name;
|
|
180
185
|
});
|
|
181
|
-
this.
|
|
186
|
+
this.log('add symbol', instanceName, '[' + pinsOutput.join(', ') + ']');
|
|
182
187
|
return component;
|
|
183
188
|
}
|
|
184
189
|
printPoint(extra = '') {
|
|
185
190
|
let netName = NoNetText;
|
|
191
|
+
if (this.scope.currentComponent === null || this.scope.currentPin === null) {
|
|
192
|
+
this.log((extra !== '' ? (extra + ' ') : '') + 'point is null');
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
186
195
|
if (this.scope.hasNet(this.scope.currentComponent, this.scope.currentPin)) {
|
|
187
196
|
netName = this.scope
|
|
188
197
|
.getNet(this.scope.currentComponent, this.scope.currentPin)
|
|
189
198
|
.toString();
|
|
190
199
|
}
|
|
191
|
-
this.
|
|
200
|
+
this.log((extra !== '' ? (extra + ' ') : '') + 'point: ' +
|
|
192
201
|
this.scope.currentComponent.instanceName +
|
|
193
202
|
' ' +
|
|
194
203
|
this.scope.currentPin + ' ' + netName);
|
|
@@ -197,7 +206,7 @@ export class ExecutionContext {
|
|
|
197
206
|
const startPin = pin;
|
|
198
207
|
const nextPin = component.getNextPinAfter(startPin);
|
|
199
208
|
this.toComponent(component, startPin, { addSequence: true });
|
|
200
|
-
this.
|
|
209
|
+
this.log('move to next pin: ' + nextPin);
|
|
201
210
|
this.atComponent(component, nextPin, {
|
|
202
211
|
addSequence: true
|
|
203
212
|
});
|
|
@@ -205,11 +214,8 @@ export class ExecutionContext {
|
|
|
205
214
|
return this.getCurrentPoint();
|
|
206
215
|
}
|
|
207
216
|
toComponent(component, pinId, options) {
|
|
208
|
-
this.
|
|
209
|
-
const { addSequence = false
|
|
210
|
-
if (cloneNetComponent && this.isNetOnlyComponent(component)) {
|
|
211
|
-
component = this.cloneComponent(component);
|
|
212
|
-
}
|
|
217
|
+
this.log('to component');
|
|
218
|
+
const { addSequence = false } = options ?? {};
|
|
213
219
|
if (!(component instanceof ClassComponent)) {
|
|
214
220
|
throw "Not a valid component!";
|
|
215
221
|
}
|
|
@@ -229,7 +235,7 @@ export class ExecutionContext {
|
|
|
229
235
|
}
|
|
230
236
|
}
|
|
231
237
|
if (this.scope.hasNet(this.scope.currentComponent, this.scope.currentPin)) {
|
|
232
|
-
this.
|
|
238
|
+
this.log('net: ', this.scope
|
|
233
239
|
.getNet(this.scope.currentComponent, this.scope.currentPin)
|
|
234
240
|
.toString());
|
|
235
241
|
}
|
|
@@ -256,11 +262,8 @@ export class ExecutionContext {
|
|
|
256
262
|
return this.getCurrentPoint();
|
|
257
263
|
}
|
|
258
264
|
atComponent(component, pinId, options) {
|
|
259
|
-
this.
|
|
260
|
-
const { addSequence = false
|
|
261
|
-
if (cloneNetComponent && this.isNetOnlyComponent(component)) {
|
|
262
|
-
component = this.cloneComponent(component);
|
|
263
|
-
}
|
|
265
|
+
this.log('at component');
|
|
266
|
+
const { addSequence = false } = options ?? {};
|
|
264
267
|
this.scope.currentComponent = component;
|
|
265
268
|
let usePinId;
|
|
266
269
|
if (pinId === null) {
|
|
@@ -285,25 +288,22 @@ export class ExecutionContext {
|
|
|
285
288
|
this.printPoint();
|
|
286
289
|
return this.getCurrentPoint();
|
|
287
290
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
}
|
|
291
|
-
cloneComponent(component) {
|
|
292
|
-
let clonedComponent = null;
|
|
291
|
+
copyComponent(component) {
|
|
292
|
+
let componentCopy = null;
|
|
293
293
|
if (!this.scope.copyIDs.has(component.instanceName)) {
|
|
294
294
|
this.scope.copyIDs.set(component.instanceName, 0);
|
|
295
295
|
}
|
|
296
296
|
const idNum = this.scope.copyIDs.get(component.instanceName);
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
297
|
+
componentCopy = component.clone();
|
|
298
|
+
componentCopy._copyID = idNum;
|
|
299
|
+
componentCopy._copyFrom = component;
|
|
300
300
|
this.scope.copyIDs.set(component.instanceName, idNum + 1);
|
|
301
301
|
const cloneInstanceName = component.instanceName + ':' + idNum;
|
|
302
|
-
this.scope.instances.set(cloneInstanceName,
|
|
303
|
-
|
|
304
|
-
this.linkComponentPinNet(component, 1,
|
|
305
|
-
this.
|
|
306
|
-
return
|
|
302
|
+
this.scope.instances.set(cloneInstanceName, componentCopy);
|
|
303
|
+
componentCopy.instanceName = cloneInstanceName;
|
|
304
|
+
this.linkComponentPinNet(component, 1, componentCopy, 1);
|
|
305
|
+
this.log('created clone of net component:', cloneInstanceName);
|
|
306
|
+
return componentCopy;
|
|
307
307
|
}
|
|
308
308
|
enterBlocks(blockType) {
|
|
309
309
|
if (blockType === BlockTypes.Point) {
|
|
@@ -324,7 +324,7 @@ export class ExecutionContext {
|
|
|
324
324
|
current_index: null,
|
|
325
325
|
type: blockType,
|
|
326
326
|
});
|
|
327
|
-
this.
|
|
327
|
+
this.log('enter blocks');
|
|
328
328
|
}
|
|
329
329
|
exitBlocks() {
|
|
330
330
|
const stackRef = this.scope.blockStack.get(this.scope.indentLevel);
|
|
@@ -345,7 +345,7 @@ export class ExecutionContext {
|
|
|
345
345
|
const { entered_at: [component, pin,] } = stackRef;
|
|
346
346
|
this.atComponent(component, pin, { addSequence: true });
|
|
347
347
|
}
|
|
348
|
-
this.
|
|
348
|
+
this.log('exit blocks');
|
|
349
349
|
}
|
|
350
350
|
enterBlock(blockIndex) {
|
|
351
351
|
const stackRef = this.scope.blockStack.get(this.scope.indentLevel);
|
|
@@ -364,7 +364,7 @@ export class ExecutionContext {
|
|
|
364
364
|
const { entered_at: [component, pin,] } = stackRef;
|
|
365
365
|
this.atComponent(component, pin, { addSequence: true });
|
|
366
366
|
}
|
|
367
|
-
this.
|
|
367
|
+
this.log(`enter inner block of type (${blockType}) >>>`);
|
|
368
368
|
this.scope.indentLevel += 1;
|
|
369
369
|
}
|
|
370
370
|
exitBlock(blockIndex) {
|
|
@@ -378,7 +378,7 @@ export class ExecutionContext {
|
|
|
378
378
|
];
|
|
379
379
|
stackRef['block_index'] = null;
|
|
380
380
|
this.scope.indentLevel -= 1;
|
|
381
|
-
this.
|
|
381
|
+
this.log('exit inner block <<<');
|
|
382
382
|
if (blockType === BlockTypes.Branch) {
|
|
383
383
|
const { entered_at: [component, pin, wireId] } = stackRef;
|
|
384
384
|
this.atComponent(component, pin, { addSequence: true });
|
|
@@ -417,7 +417,7 @@ export class ExecutionContext {
|
|
|
417
417
|
});
|
|
418
418
|
}
|
|
419
419
|
getPointBlockLocation() {
|
|
420
|
-
this.
|
|
420
|
+
this.log('get block point');
|
|
421
421
|
for (let i = 0; i < this.scope.indentLevel; i++) {
|
|
422
422
|
const stackRef = this.scope.blockStack.get(this.scope.indentLevel - 1 - i);
|
|
423
423
|
const { entered_at } = stackRef;
|
|
@@ -426,11 +426,11 @@ export class ExecutionContext {
|
|
|
426
426
|
return entered_at;
|
|
427
427
|
}
|
|
428
428
|
}
|
|
429
|
-
this.
|
|
429
|
+
this.log('did not find block point');
|
|
430
430
|
return null;
|
|
431
431
|
}
|
|
432
432
|
breakBranch() {
|
|
433
|
-
this.
|
|
433
|
+
this.log('break branch');
|
|
434
434
|
const branchesInfo = this.scope.blockStack.get(this.scope.indentLevel - 1);
|
|
435
435
|
const branchIndex = branchesInfo['block_index'];
|
|
436
436
|
const branchIndexRef = branchesInfo['inner_blocks'].get(branchIndex);
|
|
@@ -439,7 +439,7 @@ export class ExecutionContext {
|
|
|
439
439
|
createFunction(functionName, __runFunc) {
|
|
440
440
|
this.scope.functions.set(functionName, __runFunc);
|
|
441
441
|
this.__functionCache[functionName] = __runFunc;
|
|
442
|
-
this.
|
|
442
|
+
this.log(`defined new function '${functionName}'`);
|
|
443
443
|
}
|
|
444
444
|
hasFunction(functionName) {
|
|
445
445
|
return this.scope.functions.has(functionName);
|
|
@@ -488,7 +488,7 @@ export class ExecutionContext {
|
|
|
488
488
|
__runFunc = this.getFunction(functionName);
|
|
489
489
|
}
|
|
490
490
|
if (__runFunc === null) {
|
|
491
|
-
this.
|
|
491
|
+
this.log(`searching for function ${functionName} in upper context`);
|
|
492
492
|
const tmpResolveResult = this.resolveVariable(executionStack, functionName);
|
|
493
493
|
if (tmpResolveResult.found) {
|
|
494
494
|
__runFunc = tmpResolveResult.value;
|
|
@@ -497,17 +497,17 @@ export class ExecutionContext {
|
|
|
497
497
|
throw `Invalid function ${functionName}`;
|
|
498
498
|
}
|
|
499
499
|
}
|
|
500
|
-
this.
|
|
500
|
+
this.log('save function to cache:', functionName);
|
|
501
501
|
this.__functionCache[functionName] = __runFunc;
|
|
502
502
|
}
|
|
503
503
|
else {
|
|
504
|
-
this.
|
|
504
|
+
this.log('found function in cache:', functionName);
|
|
505
505
|
__runFunc = this.__functionCache[functionName];
|
|
506
506
|
}
|
|
507
507
|
if (__runFunc !== null) {
|
|
508
|
-
this.
|
|
508
|
+
this.log(`call function '${functionName}'`);
|
|
509
509
|
const functionResult = __runFunc(functionParams, { netNamespace });
|
|
510
|
-
this.
|
|
510
|
+
this.log(`done call function '${functionName}'`);
|
|
511
511
|
return functionResult;
|
|
512
512
|
}
|
|
513
513
|
else {
|
|
@@ -515,7 +515,7 @@ export class ExecutionContext {
|
|
|
515
515
|
}
|
|
516
516
|
}
|
|
517
517
|
mergeScope(childScope, namespace) {
|
|
518
|
-
this.
|
|
518
|
+
this.log('-- merging scope to parent --');
|
|
519
519
|
const currentComponent = this.scope.currentComponent;
|
|
520
520
|
const currentPin = this.scope.currentPin;
|
|
521
521
|
const currentWireId = this.scope.currentWireId;
|
|
@@ -570,7 +570,8 @@ export class ExecutionContext {
|
|
|
570
570
|
}
|
|
571
571
|
else if (action === SequenceAction.At || action === SequenceAction.To) {
|
|
572
572
|
const tmpComponent = sequenceAction[1];
|
|
573
|
-
if (
|
|
573
|
+
if (tmpComponent.typeProp === ComponentTypes.net
|
|
574
|
+
&& tmpComponent.parameters.get(ParamKeys.net_name) === 'gnd') {
|
|
574
575
|
tmpComponent._copyID = gndCopyIdOffset + incrementGndLinkId;
|
|
575
576
|
incrementGndLinkId += 1;
|
|
576
577
|
}
|
|
@@ -605,16 +606,16 @@ export class ExecutionContext {
|
|
|
605
606
|
this.scope.currentWireId = childScope.currentWireId + wireIdOffset;
|
|
606
607
|
}
|
|
607
608
|
this.printPoint('resume at');
|
|
608
|
-
this.
|
|
609
|
+
this.log('-- nets --');
|
|
609
610
|
const currentNets = this.scope.getNets();
|
|
610
611
|
currentNets.reduce((accum, [, , net]) => {
|
|
611
612
|
if (accum.indexOf(net) === -1) {
|
|
612
613
|
accum.push(net);
|
|
613
|
-
this.
|
|
614
|
+
this.log(`${net.namespace}${net.name} ${net.priority}`);
|
|
614
615
|
}
|
|
615
616
|
return accum;
|
|
616
617
|
}, []);
|
|
617
|
-
this.
|
|
618
|
+
this.log('-- done merging scope --');
|
|
618
619
|
}
|
|
619
620
|
addWire(segments) {
|
|
620
621
|
if (this.scope.currentComponent === null) {
|
|
@@ -633,14 +634,14 @@ export class ExecutionContext {
|
|
|
633
634
|
segments.forEach(item => {
|
|
634
635
|
output.push(item.join(","));
|
|
635
636
|
});
|
|
636
|
-
this.
|
|
637
|
+
this.log('add wire: ', output.join("|"));
|
|
637
638
|
this.scope.setActive(ActiveObject.Wire, wireId);
|
|
638
639
|
this.scope.sequence.push([SequenceAction.Wire, wireId, tmp]);
|
|
639
640
|
this.scope.currentComponent.pinWires.set(this.scope.currentPin, tmp);
|
|
640
641
|
}
|
|
641
642
|
addPoint(pointId, userDefined = true) {
|
|
642
643
|
if (this.scope.instances.has(pointId)) {
|
|
643
|
-
this.
|
|
644
|
+
this.log('Warning: ' + pointId + ' is being redefined');
|
|
644
645
|
}
|
|
645
646
|
const useName = userDefined ? 'point.' + pointId : pointId;
|
|
646
647
|
const componentPoint = ClassComponent.simple(useName, 1, "point");
|
|
@@ -651,7 +652,7 @@ export class ExecutionContext {
|
|
|
651
652
|
return this.getCurrentPoint();
|
|
652
653
|
}
|
|
653
654
|
setProperty(nameWithProp, value) {
|
|
654
|
-
this.
|
|
655
|
+
this.log('set property', nameWithProp, 'value', value);
|
|
655
656
|
let idName;
|
|
656
657
|
let paramName;
|
|
657
658
|
let useActive = false;
|
|
@@ -711,12 +712,6 @@ function isWireSegmentsEndAuto(segments) {
|
|
|
711
712
|
}
|
|
712
713
|
return false;
|
|
713
714
|
}
|
|
714
|
-
export function isNetComponent(component) {
|
|
715
|
-
return component.parameters.has(ParamKeys.__is_net);
|
|
716
|
-
}
|
|
717
|
-
export function isLabelComponent(component) {
|
|
718
|
-
return component.parameters.has(ParamKeys.__is_label);
|
|
719
|
-
}
|
|
720
715
|
export function getPortSide(pins, arrangeProps) {
|
|
721
716
|
const result = [];
|
|
722
717
|
if (arrangeProps === null) {
|