circuitscript 0.6.0 → 0.6.1
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/annotate/ComponentAnnotater.js +6 -12
- package/dist/cjs/antlr/CircuitScriptParser.js +372 -342
- package/dist/cjs/errors.js +6 -3
- package/dist/cjs/execute.js +4 -3
- package/dist/cjs/objects/ClassComponent.js +3 -3
- package/dist/cjs/regenerate-tests.js +4 -1
- package/dist/cjs/render/draw_symbols.js +33 -0
- package/dist/cjs/visitor.js +41 -14
- package/dist/esm/annotate/ComponentAnnotater.js +6 -12
- package/dist/esm/antlr/CircuitScriptParser.js +372 -342
- package/dist/esm/errors.js +6 -3
- package/dist/esm/execute.js +4 -3
- package/dist/esm/objects/ClassComponent.js +3 -3
- package/dist/esm/regenerate-tests.js +4 -1
- package/dist/esm/render/draw_symbols.js +33 -0
- package/dist/esm/visitor.js +42 -15
- package/dist/libs/std.cst +515 -14
- package/dist/types/antlr/CircuitScriptParser.d.ts +3 -1
- package/dist/types/execute.d.ts +1 -1
- package/dist/types/objects/ClassComponent.d.ts +1 -1
- package/dist/types/render/draw_symbols.d.ts +2 -0
- package/libs/std.cst +515 -14
- package/package.json +1 -1
package/dist/cjs/errors.js
CHANGED
|
@@ -131,9 +131,12 @@ function collectErrorChain(error) {
|
|
|
131
131
|
}
|
|
132
132
|
exports.collectErrorChain = collectErrorChain;
|
|
133
133
|
function printErrorChain(error) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
134
|
+
let useErrors = collectErrorChain(error);
|
|
135
|
+
if (useErrors.length === 0) {
|
|
136
|
+
useErrors = [error];
|
|
137
|
+
}
|
|
138
|
+
useErrors.reverse();
|
|
139
|
+
for (const err of useErrors) {
|
|
137
140
|
console.log(" " + err.toString());
|
|
138
141
|
}
|
|
139
142
|
}
|
package/dist/cjs/execute.js
CHANGED
|
@@ -1023,7 +1023,8 @@ class ExecutionContext {
|
|
|
1023
1023
|
});
|
|
1024
1024
|
}
|
|
1025
1025
|
applyComponentAngleFromWire(component, pin, opposite = false) {
|
|
1026
|
-
const
|
|
1026
|
+
const usePin = component.getPin(pin);
|
|
1027
|
+
const targetUnit = component.getUnitForPin(usePin);
|
|
1027
1028
|
if (this.componentAngleFollowsWire
|
|
1028
1029
|
&& targetUnit.followWireOrientationProp
|
|
1029
1030
|
&& targetUnit.useWireOrientationAngle
|
|
@@ -1035,8 +1036,8 @@ class ExecutionContext {
|
|
|
1035
1036
|
useSegment = currentWire.path[0];
|
|
1036
1037
|
}
|
|
1037
1038
|
const pinPositions = (0, layout_js_1.CalculatePinPositions)(targetUnit);
|
|
1038
|
-
if (pinPositions.has(
|
|
1039
|
-
const connectedPinPos = pinPositions.get(
|
|
1039
|
+
if (pinPositions.has(usePin)) {
|
|
1040
|
+
const connectedPinPos = pinPositions.get(usePin);
|
|
1040
1041
|
let targetAngle = null;
|
|
1041
1042
|
let useDirection = useSegment.direction;
|
|
1042
1043
|
if (opposite) {
|
|
@@ -192,10 +192,10 @@ class ClassComponent {
|
|
|
192
192
|
}
|
|
193
193
|
throw new errors_js_1.RuntimeExecutionError(`Could not find pin '${pinId}' on component '${this.instanceName}'`);
|
|
194
194
|
}
|
|
195
|
-
getNextPinAfter(
|
|
195
|
+
getNextPinAfter(pinId) {
|
|
196
196
|
const pins = Array.from(this.pins.keys());
|
|
197
|
-
|
|
198
|
-
const index = pins.findIndex(tmp => tmp.equals(
|
|
197
|
+
const foundPin = this.getPin(pinId);
|
|
198
|
+
const index = pins.findIndex(tmp => tmp.equals(foundPin));
|
|
199
199
|
if (index + 1 < pins.length) {
|
|
200
200
|
return pins[index + 1];
|
|
201
201
|
}
|
|
@@ -27,13 +27,16 @@ async function regenerateTests(extra = "", fileList = []) {
|
|
|
27
27
|
const outputPath = mainDir + 'svgs/' + file + extra + '.svg';
|
|
28
28
|
env.setModuleDirectory(mainDir);
|
|
29
29
|
env.setDefaultLibsPath(mainDir + '../../../libs/');
|
|
30
|
-
await (0, pipeline_js_1.renderScript)(scriptData, outputPath, {
|
|
30
|
+
const { errors } = await (0, pipeline_js_1.renderScript)(scriptData, outputPath, {
|
|
31
31
|
inputPath,
|
|
32
32
|
dumpNets: false,
|
|
33
33
|
dumpData: false,
|
|
34
34
|
showStats: false,
|
|
35
35
|
environment: env,
|
|
36
36
|
});
|
|
37
|
+
if (errors.length > 0) {
|
|
38
|
+
console.log(errors);
|
|
39
|
+
}
|
|
37
40
|
}
|
|
38
41
|
return cstFiles;
|
|
39
42
|
}
|
|
@@ -456,6 +456,9 @@ class SymbolPlaceholder extends SymbolGraphic {
|
|
|
456
456
|
case PlaceHolderCommands.triangle:
|
|
457
457
|
drawing.addTriangle(...positionParams);
|
|
458
458
|
break;
|
|
459
|
+
case PlaceHolderCommands.arrow:
|
|
460
|
+
drawing.addArrow(...positionParams);
|
|
461
|
+
break;
|
|
459
462
|
case PlaceHolderCommands.pin:
|
|
460
463
|
case PlaceHolderCommands.hpin:
|
|
461
464
|
case PlaceHolderCommands.vpin:
|
|
@@ -683,6 +686,7 @@ var PlaceHolderCommands;
|
|
|
683
686
|
PlaceHolderCommands["rect"] = "rect";
|
|
684
687
|
PlaceHolderCommands["crect"] = "crect";
|
|
685
688
|
PlaceHolderCommands["triangle"] = "triangle";
|
|
689
|
+
PlaceHolderCommands["arrow"] = "arrow";
|
|
686
690
|
PlaceHolderCommands["pin"] = "pin";
|
|
687
691
|
PlaceHolderCommands["hpin"] = "hpin";
|
|
688
692
|
PlaceHolderCommands["vpin"] = "vpin";
|
|
@@ -1056,6 +1060,35 @@ class SymbolDrawing {
|
|
|
1056
1060
|
]));
|
|
1057
1061
|
return this;
|
|
1058
1062
|
}
|
|
1063
|
+
addArrow(startX, startY, endX, endY, arrowLength = (0, NumericValue_js_1.numeric)(25), arrowWidth = (0, NumericValue_js_1.numeric)(25)) {
|
|
1064
|
+
startX = (0, helpers_js_1.milsToMM)(startX);
|
|
1065
|
+
startY = (0, helpers_js_1.milsToMM)(startY);
|
|
1066
|
+
endX = (0, helpers_js_1.milsToMM)(endX);
|
|
1067
|
+
endY = (0, helpers_js_1.milsToMM)(endY);
|
|
1068
|
+
arrowLength = (0, helpers_js_1.milsToMM)(arrowLength);
|
|
1069
|
+
arrowWidth = (0, helpers_js_1.milsToMM)(arrowWidth);
|
|
1070
|
+
const dxNum = endX.sub(startX).toNumber();
|
|
1071
|
+
const dyNum = endY.sub(startY).toNumber();
|
|
1072
|
+
const len = Math.sqrt(dxNum * dxNum + dyNum * dyNum);
|
|
1073
|
+
const unitDx = (0, NumericValue_js_1.numeric)(dxNum / len);
|
|
1074
|
+
const unitDy = (0, NumericValue_js_1.numeric)(dyNum / len);
|
|
1075
|
+
const arrowBaseX = endX.sub(unitDx.mul(arrowLength));
|
|
1076
|
+
const arrowBaseY = endY.sub(unitDy.mul(arrowLength));
|
|
1077
|
+
this.items.push(geometry_js_1.Geometry.segment([startX, startY], [arrowBaseX, arrowBaseY]));
|
|
1078
|
+
const perpX = (0, NumericValue_js_1.numeric)(-unitDy.toNumber());
|
|
1079
|
+
const perpY = (0, NumericValue_js_1.numeric)(unitDx.toNumber());
|
|
1080
|
+
const dx1 = perpX.mul(arrowWidth).half();
|
|
1081
|
+
const dy1 = perpY.mul(arrowWidth).half();
|
|
1082
|
+
const dx2 = perpX.mul(arrowWidth.neg()).half();
|
|
1083
|
+
const dy2 = perpY.mul(arrowWidth.neg()).half();
|
|
1084
|
+
this.items.push(geometry_js_1.Geometry.polygon([
|
|
1085
|
+
[dx1.add(arrowBaseX), dy1.add(arrowBaseY)],
|
|
1086
|
+
[dx2.add(arrowBaseX), dy2.add(arrowBaseY)],
|
|
1087
|
+
[endX, endY],
|
|
1088
|
+
[dx1.add(arrowBaseX), dy1.add(arrowBaseY)],
|
|
1089
|
+
]));
|
|
1090
|
+
return this;
|
|
1091
|
+
}
|
|
1059
1092
|
addLabel(x, y, textValue, style) {
|
|
1060
1093
|
this.items.push(geometry_js_1.Geometry.label(null, x, y, textValue, style));
|
|
1061
1094
|
return this;
|
package/dist/cjs/visitor.js
CHANGED
|
@@ -509,14 +509,17 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
509
509
|
let shouldIgnoreWireOrientation = false;
|
|
510
510
|
if (modifierText === globals_js_1.ParamKeys.flip) {
|
|
511
511
|
const flipValue = result.name;
|
|
512
|
+
let didSetX = false;
|
|
513
|
+
let didSetY = false;
|
|
512
514
|
if (flipValue.indexOf('x') !== -1) {
|
|
513
515
|
defaultUnit.setParam(globals_js_1.ParamKeys.flipX, (0, NumericValue_js_2.numeric)(1));
|
|
514
|
-
|
|
516
|
+
didSetX = true;
|
|
515
517
|
}
|
|
516
518
|
if (flipValue.indexOf('y') !== -1) {
|
|
517
519
|
defaultUnit.setParam(globals_js_1.ParamKeys.flipY, (0, NumericValue_js_2.numeric)(1));
|
|
518
|
-
|
|
520
|
+
didSetY = true;
|
|
519
521
|
}
|
|
522
|
+
shouldIgnoreWireOrientation = didSetX && didSetY;
|
|
520
523
|
}
|
|
521
524
|
else if (modifierText === globals_js_1.ParamKeys.angle) {
|
|
522
525
|
defaultUnit.setParam(globals_js_1.ParamKeys.angle, result);
|
|
@@ -525,6 +528,9 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
525
528
|
else if (modifierText === 'anchor') {
|
|
526
529
|
dataResult.setParam('anchor', result.name);
|
|
527
530
|
}
|
|
531
|
+
else {
|
|
532
|
+
dataResult.setParam(modifierText, result);
|
|
533
|
+
}
|
|
528
534
|
if (shouldIgnoreWireOrientation) {
|
|
529
535
|
defaultUnit.useWireOrientationAngle = false;
|
|
530
536
|
}
|
|
@@ -830,18 +836,36 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
830
836
|
this.visitWire_expr = (ctx) => {
|
|
831
837
|
const segments = [];
|
|
832
838
|
ctx.ID().forEach((ctxId, index) => {
|
|
833
|
-
const
|
|
839
|
+
const valueText = ctxId.getText();
|
|
834
840
|
const ctxDataExpr = ctx.data_expr(index);
|
|
835
|
-
|
|
836
|
-
|
|
841
|
+
let value = null;
|
|
842
|
+
switch (valueText) {
|
|
843
|
+
case 'right':
|
|
844
|
+
case 'rg':
|
|
845
|
+
case 'r':
|
|
846
|
+
value = types_js_1.Direction.Right;
|
|
847
|
+
break;
|
|
848
|
+
case 'left':
|
|
849
|
+
case 'lf':
|
|
850
|
+
case 'l':
|
|
851
|
+
value = types_js_1.Direction.Left;
|
|
852
|
+
break;
|
|
853
|
+
case 'up':
|
|
854
|
+
case 'u':
|
|
855
|
+
value = types_js_1.Direction.Up;
|
|
856
|
+
break;
|
|
857
|
+
case 'down':
|
|
858
|
+
case 'dw':
|
|
859
|
+
case 'd':
|
|
860
|
+
value = types_js_1.Direction.Down;
|
|
861
|
+
break;
|
|
862
|
+
}
|
|
863
|
+
if ((valueText === globals_js_1.WireAutoDirection.Auto || valueText === globals_js_1.WireAutoDirection.Auto_) && ctxDataExpr === null) {
|
|
864
|
+
segments.push([valueText]);
|
|
837
865
|
}
|
|
838
866
|
else if (this.acceptedDirections.indexOf(value) !== -1 && ctxDataExpr) {
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
if (useValue instanceof NumericValue_js_1.NumericValue) {
|
|
842
|
-
useValue = useValue.toNumber();
|
|
843
|
-
}
|
|
844
|
-
segments.push([value, new helpers_js_1.UnitDimension(useValue)]);
|
|
867
|
+
const useValue = this.visitResult(ctxDataExpr);
|
|
868
|
+
segments.push([value, new helpers_js_1.UnitDimension(useValue.toNumber())]);
|
|
845
869
|
}
|
|
846
870
|
else {
|
|
847
871
|
this.throwWithContext(ctx, "Invalid wire expression");
|
|
@@ -1175,6 +1199,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1175
1199
|
const suffix = properties.get('suffix') ?? null;
|
|
1176
1200
|
let pins = [];
|
|
1177
1201
|
if (display !== null && arrange === null && typeProp !== globals_js_1.ComponentTypes.graphic) {
|
|
1202
|
+
display.variables = properties.get('params') ?? new Map();
|
|
1178
1203
|
const drawCommands = display.getCommands();
|
|
1179
1204
|
drawCommands.forEach(command => {
|
|
1180
1205
|
const [commandValue,] = command;
|
|
@@ -1182,9 +1207,11 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1182
1207
|
|| commandValue === draw_symbols_js_1.PlaceHolderCommands.hpin
|
|
1183
1208
|
|| commandValue === draw_symbols_js_1.PlaceHolderCommands.pin) {
|
|
1184
1209
|
const id = PinDefinition_js_1.PinId.from(command[1][0]);
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1210
|
+
let pinName = id.toString();
|
|
1211
|
+
if (typeof command[1][1] === 'string') {
|
|
1212
|
+
pinName = command[1][1];
|
|
1213
|
+
}
|
|
1214
|
+
pins.push(new PinDefinition_js_1.PinDefinition(id, id.getType(), pinName, PinTypes_js_1.PinTypes.Any));
|
|
1188
1215
|
}
|
|
1189
1216
|
});
|
|
1190
1217
|
}
|
|
@@ -23,21 +23,15 @@ export class ComponentAnnotater {
|
|
|
23
23
|
else {
|
|
24
24
|
const type = instance.typeProp ?? 'conn';
|
|
25
25
|
if (this.counter[type] === undefined && type.length <= 2) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
throw "Refdes prefix is already in use!";
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
if (ComponentRefDesPrefixes[type] === undefined) {
|
|
32
|
-
ComponentRefDesPrefixes[type] = type;
|
|
33
|
-
this.counter[type] = 1;
|
|
34
|
-
}
|
|
26
|
+
ComponentRefDesPrefixes[type] = type;
|
|
27
|
+
this.counter[type] = 1;
|
|
35
28
|
}
|
|
29
|
+
let useType = type;
|
|
36
30
|
if (ComponentRefDesPrefixes[type] === undefined) {
|
|
37
|
-
|
|
31
|
+
useType = 'conn';
|
|
38
32
|
}
|
|
39
|
-
usePrefix = ComponentRefDesPrefixes[
|
|
40
|
-
useCounterKey =
|
|
33
|
+
usePrefix = ComponentRefDesPrefixes[useType];
|
|
34
|
+
useCounterKey = useType;
|
|
41
35
|
}
|
|
42
36
|
let prefix = '';
|
|
43
37
|
let resultRefdes = '';
|