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/esm/errors.js
CHANGED
|
@@ -111,9 +111,12 @@ export function collectErrorChain(error) {
|
|
|
111
111
|
return items;
|
|
112
112
|
}
|
|
113
113
|
export function printErrorChain(error) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
114
|
+
let useErrors = collectErrorChain(error);
|
|
115
|
+
if (useErrors.length === 0) {
|
|
116
|
+
useErrors = [error];
|
|
117
|
+
}
|
|
118
|
+
useErrors.reverse();
|
|
119
|
+
for (const err of useErrors) {
|
|
117
120
|
console.log(" " + err.toString());
|
|
118
121
|
}
|
|
119
122
|
}
|
package/dist/esm/execute.js
CHANGED
|
@@ -1028,7 +1028,8 @@ export class ExecutionContext {
|
|
|
1028
1028
|
});
|
|
1029
1029
|
}
|
|
1030
1030
|
applyComponentAngleFromWire(component, pin, opposite = false) {
|
|
1031
|
-
const
|
|
1031
|
+
const usePin = component.getPin(pin);
|
|
1032
|
+
const targetUnit = component.getUnitForPin(usePin);
|
|
1032
1033
|
if (this.componentAngleFollowsWire
|
|
1033
1034
|
&& targetUnit.followWireOrientationProp
|
|
1034
1035
|
&& targetUnit.useWireOrientationAngle
|
|
@@ -1040,8 +1041,8 @@ export class ExecutionContext {
|
|
|
1040
1041
|
useSegment = currentWire.path[0];
|
|
1041
1042
|
}
|
|
1042
1043
|
const pinPositions = CalculatePinPositions(targetUnit);
|
|
1043
|
-
if (pinPositions.has(
|
|
1044
|
-
const connectedPinPos = pinPositions.get(
|
|
1044
|
+
if (pinPositions.has(usePin)) {
|
|
1045
|
+
const connectedPinPos = pinPositions.get(usePin);
|
|
1045
1046
|
let targetAngle = null;
|
|
1046
1047
|
let useDirection = useSegment.direction;
|
|
1047
1048
|
if (opposite) {
|
|
@@ -196,10 +196,10 @@ export class ClassComponent {
|
|
|
196
196
|
}
|
|
197
197
|
throw new RuntimeExecutionError(`Could not find pin '${pinId}' on component '${this.instanceName}'`);
|
|
198
198
|
}
|
|
199
|
-
getNextPinAfter(
|
|
199
|
+
getNextPinAfter(pinId) {
|
|
200
200
|
const pins = Array.from(this.pins.keys());
|
|
201
|
-
|
|
202
|
-
const index = pins.findIndex(tmp => tmp.equals(
|
|
201
|
+
const foundPin = this.getPin(pinId);
|
|
202
|
+
const index = pins.findIndex(tmp => tmp.equals(foundPin));
|
|
203
203
|
if (index + 1 < pins.length) {
|
|
204
204
|
return pins[index + 1];
|
|
205
205
|
}
|
|
@@ -22,13 +22,16 @@ async function regenerateTests(extra = "", fileList = []) {
|
|
|
22
22
|
const outputPath = mainDir + 'svgs/' + file + extra + '.svg';
|
|
23
23
|
env.setModuleDirectory(mainDir);
|
|
24
24
|
env.setDefaultLibsPath(mainDir + '../../../libs/');
|
|
25
|
-
await renderScript(scriptData, outputPath, {
|
|
25
|
+
const { errors } = await renderScript(scriptData, outputPath, {
|
|
26
26
|
inputPath,
|
|
27
27
|
dumpNets: false,
|
|
28
28
|
dumpData: false,
|
|
29
29
|
showStats: false,
|
|
30
30
|
environment: env,
|
|
31
31
|
});
|
|
32
|
+
if (errors.length > 0) {
|
|
33
|
+
console.log(errors);
|
|
34
|
+
}
|
|
32
35
|
}
|
|
33
36
|
return cstFiles;
|
|
34
37
|
}
|
|
@@ -455,6 +455,9 @@ export class SymbolPlaceholder extends SymbolGraphic {
|
|
|
455
455
|
case PlaceHolderCommands.triangle:
|
|
456
456
|
drawing.addTriangle(...positionParams);
|
|
457
457
|
break;
|
|
458
|
+
case PlaceHolderCommands.arrow:
|
|
459
|
+
drawing.addArrow(...positionParams);
|
|
460
|
+
break;
|
|
458
461
|
case PlaceHolderCommands.pin:
|
|
459
462
|
case PlaceHolderCommands.hpin:
|
|
460
463
|
case PlaceHolderCommands.vpin:
|
|
@@ -681,6 +684,7 @@ export var PlaceHolderCommands;
|
|
|
681
684
|
PlaceHolderCommands["rect"] = "rect";
|
|
682
685
|
PlaceHolderCommands["crect"] = "crect";
|
|
683
686
|
PlaceHolderCommands["triangle"] = "triangle";
|
|
687
|
+
PlaceHolderCommands["arrow"] = "arrow";
|
|
684
688
|
PlaceHolderCommands["pin"] = "pin";
|
|
685
689
|
PlaceHolderCommands["hpin"] = "hpin";
|
|
686
690
|
PlaceHolderCommands["vpin"] = "vpin";
|
|
@@ -1048,6 +1052,35 @@ export class SymbolDrawing {
|
|
|
1048
1052
|
]));
|
|
1049
1053
|
return this;
|
|
1050
1054
|
}
|
|
1055
|
+
addArrow(startX, startY, endX, endY, arrowLength = numeric(25), arrowWidth = numeric(25)) {
|
|
1056
|
+
startX = milsToMM(startX);
|
|
1057
|
+
startY = milsToMM(startY);
|
|
1058
|
+
endX = milsToMM(endX);
|
|
1059
|
+
endY = milsToMM(endY);
|
|
1060
|
+
arrowLength = milsToMM(arrowLength);
|
|
1061
|
+
arrowWidth = milsToMM(arrowWidth);
|
|
1062
|
+
const dxNum = endX.sub(startX).toNumber();
|
|
1063
|
+
const dyNum = endY.sub(startY).toNumber();
|
|
1064
|
+
const len = Math.sqrt(dxNum * dxNum + dyNum * dyNum);
|
|
1065
|
+
const unitDx = numeric(dxNum / len);
|
|
1066
|
+
const unitDy = numeric(dyNum / len);
|
|
1067
|
+
const arrowBaseX = endX.sub(unitDx.mul(arrowLength));
|
|
1068
|
+
const arrowBaseY = endY.sub(unitDy.mul(arrowLength));
|
|
1069
|
+
this.items.push(Geometry.segment([startX, startY], [arrowBaseX, arrowBaseY]));
|
|
1070
|
+
const perpX = numeric(-unitDy.toNumber());
|
|
1071
|
+
const perpY = numeric(unitDx.toNumber());
|
|
1072
|
+
const dx1 = perpX.mul(arrowWidth).half();
|
|
1073
|
+
const dy1 = perpY.mul(arrowWidth).half();
|
|
1074
|
+
const dx2 = perpX.mul(arrowWidth.neg()).half();
|
|
1075
|
+
const dy2 = perpY.mul(arrowWidth.neg()).half();
|
|
1076
|
+
this.items.push(Geometry.polygon([
|
|
1077
|
+
[dx1.add(arrowBaseX), dy1.add(arrowBaseY)],
|
|
1078
|
+
[dx2.add(arrowBaseX), dy2.add(arrowBaseY)],
|
|
1079
|
+
[endX, endY],
|
|
1080
|
+
[dx1.add(arrowBaseX), dy1.add(arrowBaseY)],
|
|
1081
|
+
]));
|
|
1082
|
+
return this;
|
|
1083
|
+
}
|
|
1051
1084
|
addLabel(x, y, textValue, style) {
|
|
1052
1085
|
this.items.push(Geometry.label(null, x, y, textValue, style));
|
|
1053
1086
|
return this;
|
package/dist/esm/visitor.js
CHANGED
|
@@ -4,7 +4,7 @@ import { ParamDefinition } from "./objects/ParamDefinition.js";
|
|
|
4
4
|
import { numeric } from "./objects/NumericValue.js";
|
|
5
5
|
import { PinDefinition, PinId, PinIdType } from './objects/PinDefinition.js';
|
|
6
6
|
import { PinTypes } from './objects/PinTypes.js';
|
|
7
|
-
import { AnyReference, DeclaredReference, UndeclaredReference } from './objects/types.js';
|
|
7
|
+
import { AnyReference, DeclaredReference, Direction, UndeclaredReference } from './objects/types.js';
|
|
8
8
|
import { ComponentTypes, Delimiter1, FrameType, GlobalDocumentName, ModuleContainsKeyword, NoNetText, ParamKeys, RefdesFileSuffix, ReferenceTypes, SymbolPinSide, ValidPinSides, WireAutoDirection } from './globals.js';
|
|
9
9
|
import { BlockTypes } from "./objects/BlockTypes.js";
|
|
10
10
|
import { unwrapValue } from "./utils.js";
|
|
@@ -237,6 +237,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
237
237
|
const suffix = properties.get('suffix') ?? null;
|
|
238
238
|
let pins = [];
|
|
239
239
|
if (display !== null && arrange === null && typeProp !== ComponentTypes.graphic) {
|
|
240
|
+
display.variables = properties.get('params') ?? new Map();
|
|
240
241
|
const drawCommands = display.getCommands();
|
|
241
242
|
drawCommands.forEach(command => {
|
|
242
243
|
const [commandValue,] = command;
|
|
@@ -244,9 +245,11 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
244
245
|
|| commandValue === PlaceHolderCommands.hpin
|
|
245
246
|
|| commandValue === PlaceHolderCommands.pin) {
|
|
246
247
|
const id = PinId.from(command[1][0]);
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
248
|
+
let pinName = id.toString();
|
|
249
|
+
if (typeof command[1][1] === 'string') {
|
|
250
|
+
pinName = command[1][1];
|
|
251
|
+
}
|
|
252
|
+
pins.push(new PinDefinition(id, id.getType(), pinName, PinTypes.Any));
|
|
250
253
|
}
|
|
251
254
|
});
|
|
252
255
|
}
|
|
@@ -700,14 +703,17 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
700
703
|
let shouldIgnoreWireOrientation = false;
|
|
701
704
|
if (modifierText === ParamKeys.flip) {
|
|
702
705
|
const flipValue = result.name;
|
|
706
|
+
let didSetX = false;
|
|
707
|
+
let didSetY = false;
|
|
703
708
|
if (flipValue.indexOf('x') !== -1) {
|
|
704
709
|
defaultUnit.setParam(ParamKeys.flipX, numeric(1));
|
|
705
|
-
|
|
710
|
+
didSetX = true;
|
|
706
711
|
}
|
|
707
712
|
if (flipValue.indexOf('y') !== -1) {
|
|
708
713
|
defaultUnit.setParam(ParamKeys.flipY, numeric(1));
|
|
709
|
-
|
|
714
|
+
didSetY = true;
|
|
710
715
|
}
|
|
716
|
+
shouldIgnoreWireOrientation = didSetX && didSetY;
|
|
711
717
|
}
|
|
712
718
|
else if (modifierText === ParamKeys.angle) {
|
|
713
719
|
defaultUnit.setParam(ParamKeys.angle, result);
|
|
@@ -716,6 +722,9 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
716
722
|
else if (modifierText === 'anchor') {
|
|
717
723
|
dataResult.setParam('anchor', result.name);
|
|
718
724
|
}
|
|
725
|
+
else {
|
|
726
|
+
dataResult.setParam(modifierText, result);
|
|
727
|
+
}
|
|
719
728
|
if (shouldIgnoreWireOrientation) {
|
|
720
729
|
defaultUnit.useWireOrientationAngle = false;
|
|
721
730
|
}
|
|
@@ -1069,18 +1078,36 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
1069
1078
|
visitWire_expr = (ctx) => {
|
|
1070
1079
|
const segments = [];
|
|
1071
1080
|
ctx.ID().forEach((ctxId, index) => {
|
|
1072
|
-
const
|
|
1081
|
+
const valueText = ctxId.getText();
|
|
1073
1082
|
const ctxDataExpr = ctx.data_expr(index);
|
|
1074
|
-
|
|
1075
|
-
|
|
1083
|
+
let value = null;
|
|
1084
|
+
switch (valueText) {
|
|
1085
|
+
case 'right':
|
|
1086
|
+
case 'rg':
|
|
1087
|
+
case 'r':
|
|
1088
|
+
value = Direction.Right;
|
|
1089
|
+
break;
|
|
1090
|
+
case 'left':
|
|
1091
|
+
case 'lf':
|
|
1092
|
+
case 'l':
|
|
1093
|
+
value = Direction.Left;
|
|
1094
|
+
break;
|
|
1095
|
+
case 'up':
|
|
1096
|
+
case 'u':
|
|
1097
|
+
value = Direction.Up;
|
|
1098
|
+
break;
|
|
1099
|
+
case 'down':
|
|
1100
|
+
case 'dw':
|
|
1101
|
+
case 'd':
|
|
1102
|
+
value = Direction.Down;
|
|
1103
|
+
break;
|
|
1104
|
+
}
|
|
1105
|
+
if ((valueText === WireAutoDirection.Auto || valueText === WireAutoDirection.Auto_) && ctxDataExpr === null) {
|
|
1106
|
+
segments.push([valueText]);
|
|
1076
1107
|
}
|
|
1077
1108
|
else if (this.acceptedDirections.indexOf(value) !== -1 && ctxDataExpr) {
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
if (useValue instanceof NumericValue) {
|
|
1081
|
-
useValue = useValue.toNumber();
|
|
1082
|
-
}
|
|
1083
|
-
segments.push([value, new UnitDimension(useValue)]);
|
|
1109
|
+
const useValue = this.visitResult(ctxDataExpr);
|
|
1110
|
+
segments.push([value, new UnitDimension(useValue.toNumber())]);
|
|
1084
1111
|
}
|
|
1085
1112
|
else {
|
|
1086
1113
|
this.throwWithContext(ctx, "Invalid wire expression");
|