circuitscript 0.5.4 → 0.5.5

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.
Files changed (58) hide show
  1. package/dist/cjs/BaseVisitor.js +11 -10
  2. package/dist/cjs/builtinMethods.js +6 -5
  3. package/dist/cjs/environment/environment.js +2 -2
  4. package/dist/cjs/errors.js +140 -0
  5. package/dist/cjs/execute.js +12 -5
  6. package/dist/cjs/main.js +3 -2
  7. package/dist/cjs/objects/ClassComponent.js +4 -4
  8. package/dist/cjs/objects/ExecutionScope.js +2 -2
  9. package/dist/cjs/objects/NumericValue.js +15 -0
  10. package/dist/cjs/objects/PinDefinition.js +2 -2
  11. package/dist/cjs/objects/types.js +2 -2
  12. package/dist/cjs/parser.js +3 -2
  13. package/dist/cjs/pipeline.js +21 -14
  14. package/dist/cjs/regenerate-tests.js +6 -6
  15. package/dist/cjs/render/draw_symbols.js +17 -17
  16. package/dist/cjs/render/geometry.js +6 -6
  17. package/dist/cjs/render/layout.js +325 -253
  18. package/dist/cjs/render/render.js +21 -18
  19. package/dist/cjs/semantic-tokens/getSemanticTokens.js +2 -2
  20. package/dist/cjs/sizing.js +2 -2
  21. package/dist/cjs/utils.js +13 -110
  22. package/dist/cjs/validate/validateScript.js +2 -2
  23. package/dist/cjs/visitor.js +14 -12
  24. package/dist/esm/BaseVisitor.js +2 -1
  25. package/dist/esm/builtinMethods.js +6 -5
  26. package/dist/esm/environment/environment.js +1 -1
  27. package/dist/esm/errors.js +119 -0
  28. package/dist/esm/execute.js +10 -3
  29. package/dist/esm/main.js +3 -2
  30. package/dist/esm/objects/ClassComponent.js +1 -1
  31. package/dist/esm/objects/ExecutionScope.js +1 -1
  32. package/dist/esm/objects/NumericValue.js +15 -0
  33. package/dist/esm/objects/PinDefinition.js +1 -1
  34. package/dist/esm/objects/types.js +1 -1
  35. package/dist/esm/parser.js +2 -1
  36. package/dist/esm/pipeline.js +10 -3
  37. package/dist/esm/regenerate-tests.js +6 -6
  38. package/dist/esm/render/draw_symbols.js +15 -15
  39. package/dist/esm/render/geometry.js +6 -6
  40. package/dist/esm/render/layout.js +325 -253
  41. package/dist/esm/render/render.js +22 -19
  42. package/dist/esm/semantic-tokens/getSemanticTokens.js +1 -1
  43. package/dist/esm/sizing.js +2 -2
  44. package/dist/esm/utils.js +10 -95
  45. package/dist/esm/validate/validateScript.js +1 -1
  46. package/dist/esm/visitor.js +4 -2
  47. package/dist/libs/std.cst +31 -31
  48. package/dist/types/BaseVisitor.d.ts +3 -1
  49. package/dist/types/errors.d.ts +37 -0
  50. package/dist/types/execute.d.ts +1 -1
  51. package/dist/types/helpers.d.ts +1 -1
  52. package/dist/types/objects/NumericValue.d.ts +5 -1
  53. package/dist/types/render/geometry.d.ts +4 -4
  54. package/dist/types/render/layout.d.ts +7 -1
  55. package/dist/types/utils.d.ts +2 -27
  56. package/dist/types/visitor.d.ts +1 -1
  57. package/libs/std.cst +31 -31
  58. package/package.json +1 -1
@@ -27,6 +27,9 @@ export class NumericValue {
27
27
  toString() {
28
28
  return 'numeric:' + this.value;
29
29
  }
30
+ copy() {
31
+ return this.add(0);
32
+ }
30
33
  toDisplayString() {
31
34
  if (typeof this.value === 'number') {
32
35
  return this.value.toString();
@@ -81,6 +84,15 @@ export class NumericValue {
81
84
  eq(value) {
82
85
  return this.toBigNumber().eq(value.toBigNumber());
83
86
  }
87
+ floor() {
88
+ return numeric(Math.floor(this.toNumber()));
89
+ }
90
+ ceil() {
91
+ return numeric(Math.ceil(this.toNumber()));
92
+ }
93
+ roundDp() {
94
+ return roundValue(this.toNumber());
95
+ }
84
96
  }
85
97
  export class NumberOperator {
86
98
  prepare(value) {
@@ -185,5 +197,8 @@ export function resolveToNumericValue(value) {
185
197
  return new NumericValue(useValue, prefixPart * 3);
186
198
  }
187
199
  export function roundValue(value) {
200
+ if (typeof value === "number") {
201
+ value = numeric(value);
202
+ }
188
203
  return resolveToNumericValue(new Big(value.toBigNumber().toFixed(7)));
189
204
  }
@@ -1,4 +1,4 @@
1
- import { RuntimeExecutionError } from '../utils.js';
1
+ import { RuntimeExecutionError } from "../errors.js";
2
2
  import { NumericValue } from './NumericValue.js';
3
3
  import { PinTypes } from './PinTypes.js';
4
4
  export class PinId {
@@ -1,5 +1,5 @@
1
1
  import { ReferenceTypes } from '../globals.js';
2
- import { RuntimeExecutionError } from '../utils.js';
2
+ import { RuntimeExecutionError } from "../errors.js";
3
3
  export class CFunctionEntry {
4
4
  name;
5
5
  namespace;
@@ -1,6 +1,7 @@
1
1
  import { CircuitScriptParser } from './antlr/CircuitScriptParser.js';
2
2
  import { MainLexer } from './lexer.js';
3
- import { ParseSyntaxError, RuntimeExecutionError, SimpleStopwatch } from './utils.js';
3
+ import { SimpleStopwatch } from './utils.js';
4
+ import { ParseSyntaxError, RuntimeExecutionError } from "./errors.js";
4
5
  import { CharStream, CommonTokenStream, PredictionMode } from 'antlr4ng';
5
6
  export function parseFileWithVisitor(visitor, data, options) {
6
7
  const lexerErrorListener = new CircuitscriptParserErrorListener(visitor.onErrorHandler);
@@ -12,9 +12,10 @@ import { parseFileWithVisitor } from "./parser.js";
12
12
  import { KiCadNetListOutputHandler } from "./render/KiCadNetListOutputHandler.js";
13
13
  import { renderSheetsToSVG, generateSvgOutput, generatePdfOutput } from "./render/render.js";
14
14
  import { EvaluateERCRules } from "./rules-check/rules.js";
15
- import { RuntimeExecutionError, ParseSyntaxError, ParseError, printWarnings, RenderError, generateDebugSequenceAction, sequenceActionString, SimpleStopwatch } from "./utils.js";
15
+ import { printWarnings, generateDebugSequenceAction, sequenceActionString, SimpleStopwatch } from "./utils.js";
16
16
  import { ParserVisitor } from "./visitor.js";
17
17
  import { getStylesFromDocument } from "./styles.js";
18
+ import { RuntimeExecutionError, ParseSyntaxError, ParseError, RenderError, AutoWireFailedError, AutoWireFailedError_ } from "./errors.js";
18
19
  export async function renderScript(scriptData, outputPath, options) {
19
20
  const parseHandlers = [
20
21
  new KiCadNetListOutputHandler(),
@@ -208,7 +209,13 @@ export async function renderScriptCustom(scriptData, outputPath, options, parseH
208
209
  }
209
210
  }
210
211
  catch (err) {
211
- throw new RenderError(`Error during layout generation: ${err}`, 'layout');
212
+ let useErr = err;
213
+ if (err instanceof AutoWireFailedError_) {
214
+ const errCtx = visitor.wireCtxLinks.get(err.wire);
215
+ useErr = new AutoWireFailedError(err.message, errCtx.start, errCtx.stop);
216
+ }
217
+ dumpData && environment.writeFileSync(dumpDirectory + 'raw-layout.txt', layoutEngine.logger.dump());
218
+ throw new RenderError(`Error during layout generation`, 'layout', { cause: useErr });
212
219
  }
213
220
  layoutEngine.printWarnings();
214
221
  showStats && console.log('Layout took:', layoutTimer.lap());
@@ -270,7 +277,7 @@ export async function renderScriptCustom(scriptData, outputPath, options, parseH
270
277
  }
271
278
  }
272
279
  catch (err) {
273
- throw new RenderError(`Error during rendering: ${err}`, 'output_generation');
280
+ throw new RenderError(`Error during rendering: ${err}`, 'output_generation', { cause: err });
274
281
  }
275
282
  }
276
283
  return {
@@ -40,14 +40,14 @@ async function regenerateTests(extra = "") {
40
40
  cstFiles.forEach(file => {
41
41
  const svg1 = 'svgs/' + file + '.svg';
42
42
  const svg2 = 'svgs/' + file + '.next.svg';
43
- const cleanedName = file.replace('script', '').replace('.cst', '');
44
- allFiles.push([file, svg1, svg2, cleanedName]);
43
+ const cleanedName = file.replace('script', '')
44
+ .replace('.cst', '')
45
+ .replace('.annotated', '');
46
+ allFiles.push([file, svg1, svg2, Number(cleanedName)]);
45
47
  });
46
48
  const sortedFiles = allFiles.sort((a, b) => {
47
- const nameA = a[3];
48
- const nameB = b[3];
49
- const indexA = Number(nameA);
50
- const indexB = Number(nameB);
49
+ const indexA = a[3];
50
+ const indexB = b[3];
51
51
  if (indexA > indexB) {
52
52
  return 1;
53
53
  }
@@ -2,7 +2,7 @@ import { milsToMM } from "../helpers.js";
2
2
  import { ColorScheme, CustomSymbolParamTextSize, CustomSymbolPinIdSize, CustomSymbolPinTextSize, CustomSymbolRefDesSize, Defaults, PinTypesList, PortArrowSize, PortPaddingHorizontal, PortPaddingVertical, ReferenceTypes, RenderFlags, SymbolPinSide, defaultFont, defaultPinIdTextSize, defaultPinNameTextSize, defaultSymbolLineWidth, fontDisplayScale } from "../globals.js";
3
3
  import { Geometry, GeometryProp, HorizontalAlign, HorizontalAlignProp, Textbox, VerticalAlign, VerticalAlignProp } from "./geometry.js";
4
4
  import { PinTypes } from "../objects/PinTypes.js";
5
- import { RuntimeExecutionError, throwWithContext } from "../utils.js";
5
+ import { RuntimeExecutionError, throwWithContext } from "../errors.js";
6
6
  import { DeclaredReference, UndeclaredReference } from "../objects/types.js";
7
7
  import { NumericValue, numeric, roundValue } from "../objects/NumericValue.js";
8
8
  import { PinId } from "../objects/PinDefinition.js";
@@ -153,7 +153,7 @@ export class SymbolGraphic {
153
153
  }
154
154
  const isHorizontalLabel = finalLabelAngle === 0 || finalLabelAngle === 180;
155
155
  const isVerticalLabel = finalLabelAngle === 90 || finalLabelAngle === -90;
156
- if (useAnchor === HorizontalAlign.Middle) {
156
+ if (useAnchor === HorizontalAlign.Center) {
157
157
  anchorStyle = HorizontalAlignProp.Middle;
158
158
  }
159
159
  else if (useAnchor === HorizontalAlign.Left) {
@@ -162,7 +162,7 @@ export class SymbolGraphic {
162
162
  else if (useAnchor === HorizontalAlign.Right) {
163
163
  anchorStyle = HorizontalAlignProp.End;
164
164
  }
165
- if (useDominantBaseline === VerticalAlign.Middle) {
165
+ if (useDominantBaseline === VerticalAlign.Center) {
166
166
  dominantBaseline = VerticalAlignProp.Central;
167
167
  }
168
168
  else if (useDominantBaseline === VerticalAlign.Top) {
@@ -330,7 +330,7 @@ export class SymbolGraphic {
330
330
  return HorizontalAlign.Left;
331
331
  }
332
332
  else {
333
- return HorizontalAlign.Middle;
333
+ return HorizontalAlign.Center;
334
334
  }
335
335
  }
336
336
  flipDominantBaseline(value) {
@@ -341,7 +341,7 @@ export class SymbolGraphic {
341
341
  return VerticalAlign.Top;
342
342
  }
343
343
  else {
344
- return VerticalAlign.Middle;
344
+ return VerticalAlign.Center;
345
345
  }
346
346
  }
347
347
  }
@@ -358,7 +358,7 @@ export class SymbolText extends SymbolGraphic {
358
358
  drawing.clear();
359
359
  drawing.addTextbox(numeric(0), numeric(0), this.text, {
360
360
  fontSize: this.fontSize,
361
- anchor: HorizontalAlign.Middle,
361
+ anchor: HorizontalAlign.Center,
362
362
  fontWeight: this.fontWeight,
363
363
  });
364
364
  this.drawing = drawing;
@@ -646,7 +646,7 @@ export class SymbolPlaceholder extends SymbolGraphic {
646
646
  displayPinName && usePinName !== "" && drawing.addLabel(endX.add(pinNameOffsetX), endY.add(pinNameOffsetY), usePinName, {
647
647
  fontSize: numeric(defaultPinNameTextSize),
648
648
  anchor: pinNameAlignment,
649
- vanchor: VerticalAlign.Middle,
649
+ vanchor: VerticalAlign.Center,
650
650
  textColor: pinNameColor,
651
651
  angle: numeric(usePinIdAngle)
652
652
  });
@@ -759,7 +759,7 @@ export class SymbolCustom extends SymbolGraphic {
759
759
  drawing.addLabel(leftPinStart.add(milsToMM(20)), pinY, pin.text, {
760
760
  fontSize: numeric(CustomSymbolPinTextSize),
761
761
  anchor: HorizontalAlign.Left,
762
- vanchor: VerticalAlign.Middle,
762
+ vanchor: VerticalAlign.Center,
763
763
  textColor: ColorScheme.PinNameColor,
764
764
  });
765
765
  drawing.addLabel(leftPinStart.sub(milsToMM(10)), pinY.sub(milsToMM(10)), pin.pinId.toString(), {
@@ -776,7 +776,7 @@ export class SymbolCustom extends SymbolGraphic {
776
776
  drawing.addLabel(rightPinStart.sub(milsToMM(20)), pinY, pin.text, {
777
777
  fontSize: numeric(CustomSymbolPinTextSize),
778
778
  anchor: HorizontalAlign.Right,
779
- vanchor: VerticalAlign.Middle,
779
+ vanchor: VerticalAlign.Center,
780
780
  textColor: ColorScheme.PinNameColor,
781
781
  });
782
782
  drawing.addLabel(rightPinStart.add(milsToMM(10)), pinY.sub(milsToMM(10)), pin.pinId.toString(), {
@@ -793,7 +793,7 @@ export class SymbolCustom extends SymbolGraphic {
793
793
  drawing.addLabel(pinX, topPinStart.add(milsToMM(20)), pin.text, {
794
794
  fontSize: numeric(CustomSymbolPinTextSize),
795
795
  anchor: HorizontalAlign.Right,
796
- vanchor: VerticalAlign.Middle,
796
+ vanchor: VerticalAlign.Center,
797
797
  textColor: ColorScheme.PinNameColor,
798
798
  angle: numeric(-90),
799
799
  });
@@ -812,7 +812,7 @@ export class SymbolCustom extends SymbolGraphic {
812
812
  drawing.addLabel(pinX, bottomPinStart.sub(milsToMM(20)), pin.text, {
813
813
  fontSize: numeric(CustomSymbolPinTextSize),
814
814
  anchor: HorizontalAlign.Left,
815
- vanchor: VerticalAlign.Middle,
815
+ vanchor: VerticalAlign.Center,
816
816
  textColor: ColorScheme.PinNameColor,
817
817
  angle: numeric(-90),
818
818
  });
@@ -895,7 +895,7 @@ export class SymbolCustomModule extends SymbolCustom {
895
895
  drawing.addLabel(leftPinStart.add(this.portWidth).add(milsToMM(20)), pinY, pin.text, {
896
896
  fontSize: numeric(40),
897
897
  anchor: HorizontalAlign.Left,
898
- vanchor: VerticalAlign.Middle,
898
+ vanchor: VerticalAlign.Center,
899
899
  textColor: ColorScheme.PinNameColor,
900
900
  });
901
901
  });
@@ -907,7 +907,7 @@ export class SymbolCustomModule extends SymbolCustom {
907
907
  drawing.addLabel(rightPinStart.sub(this.portWidth).sub(milsToMM(20)), pinY, pin.text, {
908
908
  fontSize: numeric(40),
909
909
  anchor: HorizontalAlign.Right,
910
- vanchor: VerticalAlign.Middle,
910
+ vanchor: VerticalAlign.Center,
911
911
  textColor: ColorScheme.PinNameColor,
912
912
  });
913
913
  });
@@ -919,7 +919,7 @@ export class SymbolCustomModule extends SymbolCustom {
919
919
  drawing.addLabel(pinX, topPinStart.add(this.portWidth).add(milsToMM(20)), pin.text, {
920
920
  fontSize: numeric(40),
921
921
  anchor: HorizontalAlign.Right,
922
- vanchor: VerticalAlign.Middle,
922
+ vanchor: VerticalAlign.Center,
923
923
  textColor: ColorScheme.PinNameColor,
924
924
  angle: numeric(-90),
925
925
  });
@@ -932,7 +932,7 @@ export class SymbolCustomModule extends SymbolCustom {
932
932
  drawing.addLabel(pinX, bottomPinStart.sub(this.portWidth).sub(milsToMM(20)), pin.text, {
933
933
  fontSize: numeric(40),
934
934
  anchor: HorizontalAlign.Left,
935
- vanchor: VerticalAlign.Middle,
935
+ vanchor: VerticalAlign.Center,
936
936
  textColor: ColorScheme.PinNameColor,
937
937
  angle: numeric(-90),
938
938
  });
@@ -464,7 +464,7 @@ function labelPolygonForAnchors(x, y, width, height, hAnchor, vAnchor) {
464
464
  [1, 1],
465
465
  ];
466
466
  }
467
- else if (vAnchor === VerticalAlign.Middle) {
467
+ else if (vAnchor === VerticalAlign.Center) {
468
468
  coordVectors = [
469
469
  [0, -0.5],
470
470
  [0, 0.5],
@@ -490,7 +490,7 @@ function labelPolygonForAnchors(x, y, width, height, hAnchor, vAnchor) {
490
490
  [0, -1],
491
491
  ];
492
492
  }
493
- else if (vAnchor === VerticalAlign.Middle) {
493
+ else if (vAnchor === VerticalAlign.Center) {
494
494
  coordVectors = [
495
495
  [0, -0.5],
496
496
  [0, 0.5],
@@ -507,7 +507,7 @@ function labelPolygonForAnchors(x, y, width, height, hAnchor, vAnchor) {
507
507
  ];
508
508
  }
509
509
  }
510
- else if (hAnchor === HorizontalAlign.Middle) {
510
+ else if (hAnchor === HorizontalAlign.Center) {
511
511
  if (vAnchor === VerticalAlign.Bottom) {
512
512
  coordVectors = [
513
513
  [-0.5, 0],
@@ -516,7 +516,7 @@ function labelPolygonForAnchors(x, y, width, height, hAnchor, vAnchor) {
516
516
  [0.5, 0]
517
517
  ];
518
518
  }
519
- else if (vAnchor === VerticalAlign.Middle) {
519
+ else if (vAnchor === VerticalAlign.Center) {
520
520
  coordVectors = [
521
521
  [-0.5, 0.5],
522
522
  [-0.5, -0.5],
@@ -543,13 +543,13 @@ function labelPolygonForAnchors(x, y, width, height, hAnchor, vAnchor) {
543
543
  export var HorizontalAlign;
544
544
  (function (HorizontalAlign) {
545
545
  HorizontalAlign["Left"] = "left";
546
- HorizontalAlign["Middle"] = "middle";
546
+ HorizontalAlign["Center"] = "center";
547
547
  HorizontalAlign["Right"] = "right";
548
548
  })(HorizontalAlign || (HorizontalAlign = {}));
549
549
  export var VerticalAlign;
550
550
  (function (VerticalAlign) {
551
551
  VerticalAlign["Top"] = "top";
552
- VerticalAlign["Middle"] = "middle";
552
+ VerticalAlign["Center"] = "center";
553
553
  VerticalAlign["Bottom"] = "bottom";
554
554
  })(VerticalAlign || (VerticalAlign = {}));
555
555
  export var HorizontalAlignProp;