circuitscript 0.1.0 → 0.1.3

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 (61) hide show
  1. package/dist/cjs/BaseVisitor.js +13 -8
  2. package/dist/cjs/antlr/CircuitScriptLexer.js +80 -80
  3. package/dist/cjs/antlr/CircuitScriptParser.js +599 -657
  4. package/dist/cjs/builtinMethods.js +27 -8
  5. package/dist/cjs/draw_symbols.js +320 -197
  6. package/dist/cjs/execute.js +114 -116
  7. package/dist/cjs/export.js +2 -4
  8. package/dist/cjs/geometry.js +52 -19
  9. package/dist/cjs/globals.js +17 -12
  10. package/dist/cjs/helpers.js +16 -3
  11. package/dist/cjs/layout.js +473 -354
  12. package/dist/cjs/logger.js +8 -1
  13. package/dist/cjs/objects/ClassComponent.js +22 -22
  14. package/dist/cjs/objects/ExecutionScope.js +10 -4
  15. package/dist/cjs/objects/Frame.js +11 -2
  16. package/dist/cjs/objects/ParamDefinition.js +123 -4
  17. package/dist/cjs/objects/PinDefinition.js +1 -4
  18. package/dist/cjs/render.js +76 -138
  19. package/dist/cjs/sizing.js +33 -7
  20. package/dist/cjs/utils.js +86 -2
  21. package/dist/cjs/visitor.js +224 -255
  22. package/dist/esm/BaseVisitor.mjs +15 -10
  23. package/dist/esm/antlr/CircuitScriptLexer.mjs +80 -80
  24. package/dist/esm/antlr/CircuitScriptParser.mjs +599 -657
  25. package/dist/esm/builtinMethods.mjs +24 -8
  26. package/dist/esm/draw_symbols.mjs +322 -200
  27. package/dist/esm/execute.mjs +116 -118
  28. package/dist/esm/export.mjs +2 -4
  29. package/dist/esm/geometry.mjs +52 -19
  30. package/dist/esm/globals.mjs +17 -12
  31. package/dist/esm/helpers.mjs +17 -4
  32. package/dist/esm/layout.mjs +479 -360
  33. package/dist/esm/logger.mjs +8 -1
  34. package/dist/esm/objects/ClassComponent.mjs +21 -26
  35. package/dist/esm/objects/ExecutionScope.mjs +10 -4
  36. package/dist/esm/objects/Frame.mjs +10 -1
  37. package/dist/esm/objects/ParamDefinition.mjs +122 -3
  38. package/dist/esm/objects/PinDefinition.mjs +0 -2
  39. package/dist/esm/render.mjs +79 -141
  40. package/dist/esm/sizing.mjs +34 -8
  41. package/dist/esm/utils.mjs +80 -1
  42. package/dist/esm/visitor.mjs +226 -257
  43. package/dist/types/BaseVisitor.d.ts +1 -1
  44. package/dist/types/antlr/CircuitScriptParser.d.ts +2 -3
  45. package/dist/types/draw_symbols.d.ts +72 -45
  46. package/dist/types/execute.d.ts +15 -10
  47. package/dist/types/geometry.d.ts +31 -19
  48. package/dist/types/globals.d.ts +15 -11
  49. package/dist/types/helpers.d.ts +2 -1
  50. package/dist/types/layout.d.ts +35 -54
  51. package/dist/types/logger.d.ts +1 -1
  52. package/dist/types/objects/ClassComponent.d.ts +19 -16
  53. package/dist/types/objects/ExecutionScope.d.ts +3 -2
  54. package/dist/types/objects/Frame.d.ts +9 -2
  55. package/dist/types/objects/ParamDefinition.d.ts +32 -2
  56. package/dist/types/objects/PinDefinition.d.ts +0 -2
  57. package/dist/types/render.d.ts +2 -1
  58. package/dist/types/utils.d.ts +14 -1
  59. package/dist/types/visitor.d.ts +4 -5
  60. package/libs/lib.cst +25 -8
  61. package/package.json +7 -3
@@ -1,6 +1,6 @@
1
1
  export declare class Logger {
2
2
  logs: string[];
3
3
  constructor();
4
- add(message: string): void;
4
+ add(...args: (string | number)[]): void;
5
5
  dump(): string;
6
6
  }
@@ -3,22 +3,26 @@ import { SymbolDrawingCommands } from '../draw_symbols.js';
3
3
  import { Net } from './Net.js';
4
4
  import { PinDefinition, PinId } from './PinDefinition.js';
5
5
  import { WireSegment } from './Wire.js';
6
- import { ExecutionContext } from 'src/execute.js';
6
+ import { ExecutionContext } from '../execute.js';
7
+ import { NumericValue } from './ParamDefinition.js';
7
8
  export declare class ClassComponent {
8
9
  instanceName: string;
9
10
  numPins: number;
10
- parameters: Map<string, number | string>;
11
+ parameters: Map<string, number | string | NumericValue>;
11
12
  pins: Map<number, PinDefinition>;
12
13
  pinNets: Map<number, Net>;
13
14
  pinWires: Map<number, WireSegment[]>;
15
+ pinsMaxPositions: {
16
+ [key: string]: number;
17
+ };
14
18
  _cachedPins: string;
15
19
  _cachedParams: string;
16
- className: string;
17
20
  _copyID?: number;
18
21
  _copyFrom?: ClassComponent;
19
- arrangeProps: Map<string, number[]> | null;
20
- displayProp: string | SymbolDrawingCommands | null;
22
+ arrangeProps: Map<string, NumericValue[]> | null;
23
+ displayProp: SymbolDrawingCommands | null;
21
24
  widthProp: number | null;
25
+ heightProp: number | null;
22
26
  typeProp: string | null;
23
27
  copyProp: boolean;
24
28
  angleProp: number;
@@ -26,29 +30,28 @@ export declare class ClassComponent {
26
30
  wireOrientationAngle: number;
27
31
  useWireOrientationAngle: boolean;
28
32
  didSetWireOrientationAngle: boolean;
29
- styles: {
30
- [key: string]: number | string;
31
- };
32
33
  assignedRefDes: string | null;
33
- moduleContainsExpressions?: Expressions_blockContext;
34
- moduleCounter: number;
35
- moduleExecutionContext: ExecutionContext;
36
- moduleExecutionContextName: string;
37
- modulePinIdToPortMap: Map<number, ClassComponent>;
38
- constructor(instanceName: string, numPins: number, className: string);
34
+ constructor(instanceName: string, numPins: number);
39
35
  setupPins(): void;
40
36
  getDefaultPin(): number;
41
37
  hasPin(pinId: number | string): boolean;
42
38
  getPin(pinId: number | string): PinId;
43
39
  getNextPinAfter(pinIndex: number): number;
44
- setParam(key: string, value: number | string): void;
40
+ setParam(key: string, value: number | string | NumericValue): void;
45
41
  hasParam(key: string): boolean;
46
42
  private refreshParamCache;
47
43
  private refreshPinsCache;
48
44
  refreshCache(): void;
49
45
  getParam<T>(key: string): T;
50
46
  toString(): string;
51
- static simple(instanceName: string, numPins: number, className: string): ClassComponent;
47
+ static simple(instanceName: string, numPins: number): ClassComponent;
52
48
  isEqual(other: ClassComponent): boolean;
53
49
  clone(): ClassComponent;
54
50
  }
51
+ export declare class ModuleComponent extends ClassComponent {
52
+ moduleContainsExpressions?: Expressions_blockContext;
53
+ moduleCounter: number;
54
+ moduleExecutionContext?: ExecutionContext;
55
+ moduleExecutionContextName?: string;
56
+ modulePinIdToPortMap?: Map<number, ClassComponent>;
57
+ }
@@ -29,14 +29,14 @@ export declare class ExecutionScope {
29
29
  componentGnd: ClassComponent | null;
30
30
  componentRoot: ClassComponent | null;
31
31
  copyIDs: Map<string, number>;
32
- sequence: any[];
32
+ sequence: SequenceItem[];
33
33
  constructor(scopeId: number);
34
34
  static scopeId: number;
35
35
  static create(): ExecutionScope;
36
36
  private findNet;
37
37
  getNetWithName(name: string): Net;
38
38
  hasNet(component: ClassComponent, pin: number): boolean;
39
- getNet(component: ClassComponent, pin: number): Net;
39
+ getNet(component: ClassComponent, pin: number): Net | null;
40
40
  setNet(component: ClassComponent, pin: number, net: Net): void;
41
41
  removeNet(component: ClassComponent, pin: number): void;
42
42
  getNets(): ComponentPinNetPair[];
@@ -44,6 +44,7 @@ export declare class ExecutionScope {
44
44
  printNets(): void;
45
45
  setActive(type: ActiveObject, item: any): void;
46
46
  clearActive(): void;
47
+ setCurrent(component: ClassComponent | null, pin?: number | null): void;
47
48
  }
48
49
  export declare enum SequenceAction {
49
50
  To = "to",
@@ -1,9 +1,13 @@
1
- import { FrameType } from "src/globals";
1
+ import { FrameType } from "../globals.js";
2
2
  export declare class Frame {
3
3
  parameters: Map<string, any>;
4
4
  frameId: number;
5
5
  frameType: FrameType;
6
- constructor(frameId: number, frameType: FrameType);
6
+ constructor(frameId: number, frameType?: FrameType);
7
+ }
8
+ export declare enum FixedFrameIds {
9
+ BaseFrame = -1,
10
+ FrameIdNotUsed = -2
7
11
  }
8
12
  export declare enum FrameParamKeys {
9
13
  Title = "title",
@@ -14,6 +18,9 @@ export declare enum FrameParamKeys {
14
18
  Height = "height",
15
19
  PaperSize = "paper_size",
16
20
  SheetType = "sheet_type",
21
+ TitleAlign = "title_align",
22
+ HorizontalAlign = "align",
23
+ VerticalAlign = "valign",
17
24
  SheetNumber = "sheet_number",
18
25
  SheetTotal = "sheet_total"
19
26
  }
@@ -1,16 +1,46 @@
1
+ import { Big } from 'big.js';
1
2
  export declare class ParamDefinition {
2
3
  paramName: string;
3
4
  paramValue: string | number | any;
4
5
  constructor(paramName: string, paramValue: any);
5
6
  }
6
7
  export declare class NumericValue {
7
- value: string | number;
8
- constructor(value: string | number);
8
+ value: string | number | Big;
9
+ valuePart: Big;
10
+ prefixPart: number;
11
+ constructor(value: string | number | Big, prefix?: number);
9
12
  toString(): string;
10
13
  toDisplayString(): string;
14
+ toNumber(): number;
15
+ toBigNumber(): Big;
16
+ div(value: NumericValue | number): NumericValue;
17
+ half(): NumericValue;
18
+ mul(value: NumericValue | number): NumericValue;
19
+ add(value: NumericValue | number): NumericValue;
20
+ sub(value: NumericValue | number): NumericValue;
21
+ mod(value: NumericValue | number): NumericValue;
22
+ neg(): NumericValue;
23
+ eq(value: NumericValue): boolean;
11
24
  }
25
+ export declare function numeric(value: number): NumericValue;
12
26
  export declare class PercentageValue {
13
27
  value: string | number;
14
28
  constructor(value: string | number);
15
29
  toString(): string;
30
+ toNumber(): number;
31
+ }
32
+ export declare class WrappedNumber {
33
+ value: number;
34
+ constructor(value: number);
35
+ toString(): string;
36
+ toNumber(): number;
37
+ }
38
+ export type NumberOperatorType = NumericValue | PercentageValue | WrappedNumber;
39
+ export declare class NumberOperator {
40
+ prepare(value: number | NumberOperatorType): NumberOperatorType;
41
+ multiply(value1: NumberOperatorType, value2: NumberOperatorType): NumberOperatorType;
42
+ divide(value1: NumberOperatorType, value2: NumberOperatorType): NumberOperatorType;
43
+ addition(value1: NumberOperatorType, value2: NumberOperatorType): NumberOperatorType;
44
+ subtraction(value1: NumberOperatorType, value2: NumberOperatorType): NumberOperatorType;
45
+ modulus(value1: NumberOperatorType, value2: NumberOperatorType): NumberOperatorType;
16
46
  }
@@ -20,5 +20,3 @@ export declare enum PortSide {
20
20
  SOUTH = "SOUTH",
21
21
  NORTH = "NORTH"
22
22
  }
23
- export declare class PinReference {
24
- }
@@ -1,6 +1,7 @@
1
1
  /// <reference types="pdfkit" />
2
2
  import { Svg } from '@svgdotjs/svg.js';
3
3
  import { SheetFrame } from "./layout.js";
4
- export declare function renderSheetsToSVG(sheetFrames: SheetFrame[]): Svg;
4
+ import { Logger } from './logger.js';
5
+ export declare function renderSheetsToSVG(sheetFrames: SheetFrame[], logger: Logger): Svg;
5
6
  export declare function generateSvgOutput(canvas: Svg, zoomScale?: number): string;
6
7
  export declare function generatePdfOutput(doc: PDFKit.PDFDocument, canvas: Svg, sheetSize: string, sheetSizeDefined: boolean, zoomScale?: number): void;
@@ -1,5 +1,7 @@
1
+ import { Big } from 'big.js';
1
2
  import { ParserRuleContext } from "antlr4ng";
2
3
  import { ClassComponent } from "./objects/ClassComponent";
4
+ import { NumericValue } from "./objects/ParamDefinition";
3
5
  export declare class SimpleStopwatch {
4
6
  startTime: Date;
5
7
  constructor();
@@ -11,6 +13,12 @@ export type BoundBox = {
11
13
  xmax: number;
12
14
  ymax: number;
13
15
  };
16
+ export type BoundBox2 = [
17
+ xmin: number,
18
+ ymin: number,
19
+ xmax: number,
20
+ ymax: number
21
+ ];
14
22
  export declare function resizeBounds(bounds: BoundBox, value: number): BoundBox;
15
23
  export declare function printBounds(bounds: BoundBox): string;
16
24
  export declare function resizeToNearestGrid(bounds: BoundBox, gridSize?: number): BoundBox;
@@ -20,6 +28,11 @@ export declare function getBoundsSize(bounds: BoundBox): {
20
28
  height: number;
21
29
  };
22
30
  export declare function getPortType(component: ClassComponent): string | null;
23
- export declare function roundValue(value: number): number;
31
+ export declare function roundValue(value: NumericValue): NumericValue;
24
32
  export declare function throwWithContext(context: ParserRuleContext, message: string): void;
25
33
  export declare function combineMaps(map1: Map<string, any>, map2: Map<string, any>): Map<string, any>;
34
+ export declare function getNumberExponential(value: string): number;
35
+ export declare function getNumberExponentialText(value: number): string;
36
+ export declare function resolveToNumericValue(value: Big): NumericValue;
37
+ export declare function isPointWithinArea(point: [x: number, y: number], bounds: BoundBox2): boolean;
38
+ export declare function areasOverlap(area1: BoundBox2, area2: BoundBox2): boolean;
@@ -1,7 +1,7 @@
1
1
  import { Add_component_exprContext, AdditionExprContext, At_blockContext, At_block_pin_exprContext, At_block_pin_expression_complexContext, At_block_pin_expression_simpleContext, At_component_exprContext, BinaryOperatorExprContext, Path_blocksContext, Component_select_exprContext, Create_component_exprContext, Create_graphic_exprContext, DataExprContext, Data_expr_with_assignmentContext, Double_dot_property_set_exprContext, Frame_exprContext, Function_def_exprContext, Keyword_assignment_exprContext, MultiplyExprContext, Nested_propertiesContext, Net_namespace_exprContext, Pin_select_expr2Context, Pin_select_exprContext, Point_exprContext, Property_exprContext, Property_key_exprContext, Property_set_exprContext, Single_line_propertyContext, To_component_exprContext, Wire_exprContext, UnaryOperatorExprContext, Wire_expr_direction_onlyContext, Wire_expr_direction_valueContext, If_exprContext, If_inner_exprContext, LogicalOperatorExprContext, Nested_properties_innerContext, Expressions_blockContext, Create_module_exprContext, Property_block_exprContext, While_exprContext, For_exprContext, GraphicCommandExprContext, Graphic_expressions_blockContext, GraphicForExprContext } from './antlr/CircuitScriptParser.js';
2
2
  import { ClassComponent } from './objects/ClassComponent.js';
3
3
  import { PinTypes } from './objects/PinTypes.js';
4
- import { ComponentPin, ComponentPinNet } from './objects/types.js';
4
+ import { ComponentPin, ComponentPinNet, ComponentPinNetPair } from './objects/types.js';
5
5
  import { Net } from './objects/Net.js';
6
6
  import { BaseVisitor } from './BaseVisitor.js';
7
7
  import { ParserRuleContext } from 'antlr4ng';
@@ -59,6 +59,8 @@ export declare class ParserVisitor extends BaseVisitor {
59
59
  pinTypes: PinTypes[];
60
60
  private parseCreateComponentPins;
61
61
  private parseCreateModulePorts;
62
+ private getArrangePropFromModulePorts;
63
+ private getPortItems;
62
64
  private parseCreateComponentParams;
63
65
  printNets(): void;
64
66
  dumpNets(): ComponentPinNet[];
@@ -73,16 +75,13 @@ export declare class ParserVisitor extends BaseVisitor {
73
75
  getNetList(): NetListItem[];
74
76
  getGraph(): {
75
77
  sequence: any[];
76
- nets: import("./objects/types.js").ComponentPinNetPair[];
77
- components: ClassComponent[];
78
+ nets: ComponentPinNetPair[];
78
79
  };
79
80
  annotateComponents(): void;
80
81
  applySheetFrameComponent(): {
81
82
  frameComponent: ClassComponent | null;
82
83
  };
83
84
  private resolveNets;
84
- private setComponentOrientation;
85
- private setComponentFlip;
86
85
  private getPropertyExprList;
87
86
  }
88
87
  export type NetListItem = {
package/libs/lib.cst CHANGED
@@ -37,7 +37,7 @@ def label(value, anchor="left"):
37
37
  textColor: "#222"
38
38
  label: params.value, 0, -10, fontSize=50, anchor=anchor
39
39
  pin: 1, 0, 0, 0, 0, display_pin_id=false
40
- type: "label"
40
+ type: "net"
41
41
  params:
42
42
  net_name: value
43
43
  value: value
@@ -64,11 +64,11 @@ def res(value):
64
64
  return create component:
65
65
  pins: 2
66
66
  display: create graphic (params):
67
- rect: 0, 0, width, height
67
+ crect: 0, 0, width, height
68
68
  hpin: 1, -width/2 - 30, 0, 30
69
69
  hpin: 2, width/2 + 30, 0, -30
70
70
  label: params.refdes, -width/2, -height/2 - 20, fontSize=50, anchor="left"
71
- label: params.value, 0, 4, fontSize=30, anchor="middle", vanchor="middle"
71
+ label: params.value, 0, 0, fontSize=30, anchor="middle", vanchor="middle"
72
72
  type: "res"
73
73
  params:
74
74
  value: value
@@ -195,6 +195,7 @@ def text(value, offsetX = 0, offsetY = 0, fontSize = 50):
195
195
  return create component:
196
196
  pins: 1
197
197
  followWireOrientation: false
198
+ type: "graphic"
198
199
  display: create graphic:
199
200
  pin: 1, 0, 0, 0, 0, display_pin_id=false
200
201
  text:
@@ -222,6 +223,17 @@ def arrow_point():
222
223
  path: ("M", -5, 0, "L", -20, 0)
223
224
  hpin: 1, 0, 0, 0, display_pin_id=false
224
225
 
226
+ def no_connect(size=20):
227
+ return create component:
228
+ pins: 1
229
+ display: create graphic:
230
+ path: "M", -size, -size, "L", size, size
231
+ path: "M", -size, size, "L", size, -size
232
+ pin: 1, 0, 0, 0, 0, display_pin_id=false
233
+
234
+ def dnc(size=20):
235
+ return no_connect(size)
236
+
225
237
  def sheet_generator(paper_size_name, paper_width, paper_height, margin_x, margin_y,
226
238
  col_display_value, row_display_value, inner_frame_margin = 50):
227
239
 
@@ -259,19 +271,21 @@ def sheet_generator(paper_size_name, paper_width, paper_height, margin_x, margin
259
271
  title_block_y2 = title_block_y + title_block_height
260
272
 
261
273
  return create component:
262
- type: "frame"
274
+ type: "graphic"
263
275
  display: create graphic (params):
264
276
  fill: "none"
265
277
 
266
278
  # outer rect
267
279
  lineColor: "#cccccc"
268
- rect: paper_width/2, paper_height/2, paper_width, paper_height
280
+ crect: (paper_width/2, paper_height/2,
281
+ paper_width, paper_height, class="paper-area")
269
282
 
270
283
  # inner rect
271
284
  lineColor: "#111111"
272
- rect: paper_width/2, paper_height/2, inner_width, inner_height
285
+ crect: (paper_width/2, paper_height/2,
286
+ inner_width, inner_height, class="plot-area")
273
287
 
274
- rect: (paper_width/2, paper_height/2,
288
+ crect: (paper_width/2, paper_height/2,
275
289
  paper_width - 2 * margin_x + inner_frame_margin * 2,
276
290
  paper_height - 2 * margin_y + inner_frame_margin * 2)
277
291
 
@@ -346,7 +360,10 @@ def sheet_generator(paper_size_name, paper_width, paper_height, margin_x, margin
346
360
  anchor: "left"
347
361
  vanchor: "bottom"
348
362
 
349
- rect: title_block_x + title_block_width / 2, title_block_y + title_block_height / 2, title_block_width, title_block_height
363
+ crect: (title_block_x + title_block_width / 2,
364
+ title_block_y + title_block_height / 2,
365
+ title_block_width, title_block_height,
366
+ class="keepout-area")
350
367
 
351
368
  params:
352
369
  title: "Sheet title"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "circuitscript",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
4
  "description": "Interpreter for the circuitscript language",
5
5
  "homepage": "https://circuitscript.net",
6
6
  "engines": {
@@ -24,6 +24,7 @@
24
24
  "libs"
25
25
  ],
26
26
  "devDependencies": {
27
+ "@types/big.js": "^6.2.2",
27
28
  "@types/figlet": "^1.5.8",
28
29
  "@types/jest": "~29.5",
29
30
  "@types/node": "~18",
@@ -69,7 +70,9 @@
69
70
  "profile-flame": "node --prof-process --preprocess -j isolate*.log | flamebearer",
70
71
  "server": "node server.js",
71
72
  "pack-local": "npm pack; rm circuitscript-install.tgz; mv `ls | grep circuitscript` circuitscript-install.tgz; cp circuitscript-install.tgz ../circuitscript-vscode/client; cp circuitscript-install.tgz ../circuitscript-vscode/server",
72
- "changelog": "auto-changelog --handlebars-setup ../changelog/helper.js"
73
+ "changelog": "auto-changelog --handlebars-setup ../changelog/helper.js -p",
74
+ "preversion": "npm run test",
75
+ "version": "npm run changelog && git add CHANGELOG.md"
73
76
  },
74
77
  "boilerplate_author": "Jakub Synowiec <jsynowiec@users.noreply.github.com>",
75
78
  "license": "MIT",
@@ -78,13 +81,14 @@
78
81
  "@flatten-js/core": "1.5.5",
79
82
  "@svgdotjs/svg.js": "3.2.0",
80
83
  "antlr4ng": "^3.0.4",
84
+ "big.js": "^6.2.2",
81
85
  "commander": "^11.1.0",
82
86
  "express": "^4.18.2",
83
87
  "figlet": "^1.7.0",
84
88
  "lodash": "^4.17.21",
85
89
  "pdfkit": "^0.15.1",
86
90
  "svg-to-pdfkit": "^0.1.8",
87
- "svgdom": "0.1.14",
91
+ "svgdom": "^0.1.14",
88
92
  "this-file": "^2.0.3",
89
93
  "tslib": "~2.5",
90
94
  "ws": "^8.14.2"