circuitscript 0.0.29 → 0.0.32

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 (64) hide show
  1. package/dist/cjs/BaseVisitor.js +6 -1
  2. package/dist/cjs/antlr/CircuitScriptLexer.js +204 -200
  3. package/dist/cjs/antlr/CircuitScriptParser.js +1066 -1173
  4. package/dist/cjs/draw_symbols.js +330 -87
  5. package/dist/cjs/execute.js +41 -14
  6. package/dist/cjs/geometry.js +79 -18
  7. package/dist/cjs/globals.js +37 -6
  8. package/dist/cjs/helpers.js +75 -5
  9. package/dist/cjs/layout.js +107 -43
  10. package/dist/cjs/main.js +10 -4
  11. package/dist/cjs/objects/ClassComponent.js +2 -0
  12. package/dist/cjs/objects/ExecutionScope.js +1 -1
  13. package/dist/cjs/objects/Frame.js +2 -0
  14. package/dist/cjs/objects/Net.js +3 -2
  15. package/dist/cjs/objects/PinTypes.js +7 -1
  16. package/dist/cjs/objects/types.js +11 -1
  17. package/dist/cjs/regenerate-tests.js +64 -3
  18. package/dist/cjs/render.js +29 -21
  19. package/dist/cjs/sizing.js +4 -6
  20. package/dist/cjs/utils.js +29 -5
  21. package/dist/cjs/visitor.js +176 -10
  22. package/dist/esm/BaseVisitor.mjs +6 -1
  23. package/dist/esm/antlr/CircuitScriptLexer.mjs +204 -200
  24. package/dist/esm/antlr/CircuitScriptParser.mjs +1061 -1171
  25. package/dist/esm/antlr/CircuitScriptVisitor.mjs +3 -0
  26. package/dist/esm/draw_symbols.mjs +324 -85
  27. package/dist/esm/execute.mjs +42 -15
  28. package/dist/esm/geometry.mjs +79 -17
  29. package/dist/esm/globals.mjs +36 -5
  30. package/dist/esm/helpers.mjs +74 -5
  31. package/dist/esm/layout.mjs +110 -46
  32. package/dist/esm/main.mjs +11 -5
  33. package/dist/esm/objects/ClassComponent.mjs +6 -0
  34. package/dist/esm/objects/ExecutionScope.mjs +1 -1
  35. package/dist/esm/objects/Frame.mjs +2 -0
  36. package/dist/esm/objects/Net.mjs +3 -2
  37. package/dist/esm/objects/PinTypes.mjs +6 -0
  38. package/dist/esm/objects/types.mjs +14 -0
  39. package/dist/esm/regenerate-tests.mjs +64 -3
  40. package/dist/esm/render.mjs +30 -22
  41. package/dist/esm/sizing.mjs +3 -4
  42. package/dist/esm/utils.mjs +26 -4
  43. package/dist/esm/visitor.mjs +179 -13
  44. package/dist/types/antlr/CircuitScriptLexer.d.ts +42 -41
  45. package/dist/types/antlr/CircuitScriptParser.d.ts +144 -133
  46. package/dist/types/antlr/CircuitScriptVisitor.d.ts +6 -0
  47. package/dist/types/draw_symbols.d.ts +15 -2
  48. package/dist/types/execute.d.ts +5 -4
  49. package/dist/types/geometry.d.ts +4 -3
  50. package/dist/types/globals.d.ts +32 -3
  51. package/dist/types/helpers.d.ts +12 -0
  52. package/dist/types/layout.d.ts +8 -2
  53. package/dist/types/objects/ClassComponent.d.ts +8 -0
  54. package/dist/types/objects/Frame.d.ts +3 -1
  55. package/dist/types/objects/PinTypes.d.ts +1 -0
  56. package/dist/types/objects/Wire.d.ts +4 -2
  57. package/dist/types/objects/types.d.ts +8 -0
  58. package/dist/types/render.d.ts +5 -1
  59. package/dist/types/sizing.d.ts +0 -4
  60. package/dist/types/utils.d.ts +3 -0
  61. package/dist/types/visitor.d.ts +8 -1
  62. package/fonts/Arial.ttf +0 -0
  63. package/libs/lib.cst +58 -41
  64. package/package.json +5 -1
@@ -1,7 +1,9 @@
1
+ import { Expressions_blockContext } from 'src/antlr/CircuitScriptParser.js';
1
2
  import { SymbolDrawingCommands } from '../draw_symbols.js';
2
3
  import { Net } from './Net.js';
3
4
  import { PinDefinition, PinId } from './PinDefinition.js';
4
5
  import { WireSegment } from './Wire.js';
6
+ import { ExecutionContext } from 'src/execute.js';
5
7
  export declare class ClassComponent {
6
8
  instanceName: string;
7
9
  numPins: number;
@@ -23,10 +25,16 @@ export declare class ClassComponent {
23
25
  followWireOrientationProp: boolean;
24
26
  wireOrientationAngle: number;
25
27
  useWireOrientationAngle: boolean;
28
+ didSetWireOrientationAngle: boolean;
26
29
  styles: {
27
30
  [key: string]: number | string;
28
31
  };
29
32
  assignedRefDes: string | null;
33
+ moduleContainsExpressions?: Expressions_blockContext;
34
+ moduleCounter: number;
35
+ moduleExecutionContext: ExecutionContext;
36
+ moduleExecutionContextName: string;
37
+ modulePinIdToPortMap: Map<number, ClassComponent>;
30
38
  constructor(instanceName: string, numPins: number, className: string);
31
39
  setupPins(): void;
32
40
  getDefaultPin(): number;
@@ -7,7 +7,9 @@ export declare enum FrameParamKeys {
7
7
  Title = "title",
8
8
  Direction = "direction",
9
9
  Padding = "padding",
10
- Border = "border"
10
+ Border = "border",
11
+ Width = "width",
12
+ Height = "height"
11
13
  }
12
14
  export declare enum FramePlotDirection {
13
15
  Row = "row",
@@ -5,3 +5,4 @@ export declare enum PinTypes {
5
5
  IO = "io",
6
6
  Power = "power"
7
7
  }
8
+ export declare const AllPinTypes: PinTypes[];
@@ -1,12 +1,14 @@
1
+ import { UnitDimension } from "src/helpers.js";
1
2
  import { ClassComponent } from "./ClassComponent.js";
2
3
  import { Direction } from "./types.js";
4
+ import { WireAutoDirection } from "src/globals.js";
3
5
  export declare class Wire {
4
6
  path: WireSegment[];
5
7
  constructor(path: WireSegment[]);
6
8
  }
7
9
  export type WireSegment = {
8
- direction: Direction.Up | Direction.Down | Direction.Left | Direction.Right | 'auto' | 'auto_';
9
- value: number;
10
+ direction: Direction.Up | Direction.Down | Direction.Left | Direction.Right | WireAutoDirection;
11
+ value: number | UnitDimension;
10
12
  valueXY?: [x: number, y: number];
11
13
  until?: [instance: ClassComponent, pin: number];
12
14
  };
@@ -40,6 +40,14 @@ export declare class UndeclaredReference {
40
40
  reference: ReferenceType;
41
41
  constructor(reference: ReferenceType);
42
42
  }
43
+ export declare class DeclaredReference {
44
+ found: boolean;
45
+ name?: string;
46
+ trailers?: string[];
47
+ type?: string;
48
+ value?: any;
49
+ constructor(refType: ReferenceType);
50
+ }
43
51
  export type ReferenceType = {
44
52
  found: boolean;
45
53
  name?: string;
@@ -7,4 +7,8 @@ export declare function generateSVG2(graph: {
7
7
  debugRects?: BoundBox[];
8
8
  frameObjects: RenderFrame[];
9
9
  textObjects: RenderText[];
10
- }): string;
10
+ }): {
11
+ svg: string;
12
+ width: number;
13
+ height: number;
14
+ };
@@ -4,10 +4,6 @@ import { SVGWindow } from 'svgdom';
4
4
  export declare function prepareSVGEnvironment(fontsPath: string | null): Promise<void>;
5
5
  export declare function getCreateSVGWindow(): () => SVGWindow;
6
6
  export declare function applyFontsToSVG(canvas: SVGTypeMapping): void;
7
- export declare function measureTextSize(text: string, fontFamily: string, fontSize: number): Promise<{
8
- width: number;
9
- height: number;
10
- }>;
11
7
  export declare function measureTextSize2(text: string, fontFamily: string, fontSize: number, fontWeight?: string, anchor?: HorizontalAlign, vanchor?: VerticalAlign): {
12
8
  width: number;
13
9
  height: number;
@@ -1,3 +1,4 @@
1
+ import { ClassComponent } from "./objects/ClassComponent";
1
2
  export declare class SimpleStopwatch {
2
3
  startTime: Date;
3
4
  constructor();
@@ -17,3 +18,5 @@ export declare function getBoundsSize(bounds: BoundBox): {
17
18
  width: number;
18
19
  height: number;
19
20
  };
21
+ export declare function getPortType(component: ClassComponent): string | null;
22
+ export declare function roundValue(value: number): number;
@@ -1,4 +1,4 @@
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, Graphic_exprContext, If_exprContext, If_inner_exprContext, LogicalOperatorExprContext, Nested_properties_innerContext } from './antlr/CircuitScriptParser.js';
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, Graphic_exprContext, If_exprContext, If_inner_exprContext, LogicalOperatorExprContext, Nested_properties_innerContext, Expressions_blockContext, Create_module_exprContext, Property_block_exprContext } from './antlr/CircuitScriptParser.js';
2
2
  import { ClassComponent } from './objects/ClassComponent.js';
3
3
  import { PinTypes } from './objects/PinTypes.js';
4
4
  import { ComponentPin, ComponentPinNet } from './objects/types.js';
@@ -16,12 +16,17 @@ export declare class ParserVisitor extends BaseVisitor {
16
16
  visitCreate_component_expr: (ctx: Create_component_exprContext) => void;
17
17
  visitCreate_graphic_expr: (ctx: Create_graphic_exprContext) => void;
18
18
  visitGraphic_expr: (ctx: Graphic_exprContext) => void;
19
+ visitCreate_module_expr: (ctx: Create_module_exprContext) => void;
20
+ visitProperty_block_expr: (ctx: Property_block_exprContext) => void;
19
21
  visitProperty_expr: (ctx: Property_exprContext) => void;
20
22
  visitSingle_line_property: (ctx: Single_line_propertyContext) => void;
21
23
  visitNested_properties_inner: (ctx: Nested_properties_innerContext) => void;
22
24
  visitNested_properties: (ctx: Nested_propertiesContext) => void;
23
25
  visitProperty_key_expr: (ctx: Property_key_exprContext) => void;
24
26
  visitData_expr_with_assignment: (ctx: Data_expr_with_assignmentContext) => void;
27
+ private expandModuleContains;
28
+ private linkModuleSymbolWithContains;
29
+ private placeModuleContains;
25
30
  visitUnaryOperatorExpr: (ctx: UnaryOperatorExprContext) => void;
26
31
  visitDataExpr: (ctx: DataExprContext) => void;
27
32
  visitBinaryOperatorExpr: (ctx: BinaryOperatorExprContext) => void;
@@ -40,12 +45,14 @@ export declare class ParserVisitor extends BaseVisitor {
40
45
  visitPoint_expr: (ctx: Point_exprContext) => ComponentPin;
41
46
  visitProperty_set_expr: (ctx: Property_set_exprContext) => void;
42
47
  visitDouble_dot_property_set_expr: (ctx: Double_dot_property_set_exprContext) => void;
48
+ visitExpressions_block: (ctx: Expressions_blockContext) => void;
43
49
  visitFrame_expr: (ctx: Frame_exprContext) => void;
44
50
  visitNet_namespace_expr: (ctx: Net_namespace_exprContext) => void;
45
51
  visitIf_expr: (ctx: If_exprContext) => void;
46
52
  visitIf_inner_expr: (ctx: If_inner_exprContext) => void;
47
53
  pinTypes: PinTypes[];
48
54
  private parseCreateComponentPins;
55
+ private parseCreateModulePorts;
49
56
  private parseCreateComponentParams;
50
57
  printNets(): void;
51
58
  dumpNets(): ComponentPinNet[];
Binary file
package/libs/lib.cst CHANGED
@@ -6,9 +6,9 @@ def net(net_name):
6
6
  copy: true
7
7
  angle: -90
8
8
  display: create graphic:
9
- hline: -15, 0, 30
10
- vpin: 1, 0, 10, -10, display_pin_id=false
11
- label: "net_name", 0, -5, net_name, fontSize=10, anchor="middle"
9
+ hline: -50, 0, 100
10
+ vpin: 1, 0, 50, -50, display_pin_id=false
11
+ label: "net_name", 0, -15, net_name, fontSize=50, anchor="middle"
12
12
  type: "net"
13
13
  params:
14
14
  net_name: net_name
@@ -20,9 +20,9 @@ def supply(net_name):
20
20
  copy: true
21
21
  angle: -90
22
22
  display: create graphic:
23
- hline: -15, 0, 30
24
- vpin: 1, 0, 10, -10, display_pin_id=false
25
- label: "net_name", 0, -5, net_name, fontSize=10, anchor="middle"
23
+ hline: -50, 0, 100
24
+ vpin: 1, 0, 50, -50, display_pin_id=false
25
+ label: "net_name", 0, -15, net_name, fontSize=50, anchor="middle"
26
26
  type: "net"
27
27
  params:
28
28
  net_name: net_name
@@ -35,7 +35,7 @@ def label(value, anchor="left"):
35
35
  followWireOrientation: false
36
36
  display: create graphic:
37
37
  textColor: "#222"
38
- label: "value", 0, -2, "?", fontSize=10, anchor=anchor
38
+ label: "value", 0, -10, "?", fontSize=50, anchor=anchor
39
39
  pin: 1, 0, 0, 0, 0, display_pin_id=false
40
40
  type: "label"
41
41
  params:
@@ -43,18 +43,32 @@ def label(value, anchor="left"):
43
43
  value: value
44
44
  priority: 5
45
45
 
46
+ def port(value, portType="input"):
47
+ return create component:
48
+ pins: 1
49
+ copy: true
50
+ display: create graphic:
51
+ textColor: "#222"
52
+ label: "value", 0, 0, "?", fontSize=40, anchor="left", vanchor="middle", portType=portType
53
+ pin: 1, 0, 0, 0, 0, display_pin_id=false
54
+ type: "port"
55
+ params:
56
+ net_name: value
57
+ value: value
58
+ priority: 5
59
+
46
60
  def res(value):
47
- width = 40
48
- height = 20
61
+ width = 140
62
+ height = 60
49
63
 
50
64
  return create component:
51
65
  pins: 2
52
66
  display: create graphic:
53
67
  rect: 0, 0, width, height
54
- hpin: 1, -width/2 - 20, 0, 20
55
- hpin: 2, width/2 + 20, 0, -20
56
- label: ("value", 0, 1, value, fontSize=10, anchor="middle", vanchor="middle")
57
- label: ("refdes", -width/2, -height/2 -5 , "?", fontSize=10, anchor="left")
68
+ hpin: 1, -width/2 - 30, 0, 30
69
+ hpin: 2, width/2 + 30, 0, -30
70
+ label: "refdes", -width/2, -height/2 - 20 , "?", fontSize=50, anchor="left"
71
+ label: "value", 0, 4, value, fontSize=30, anchor="middle", vanchor="middle"
58
72
  type: "res"
59
73
  params:
60
74
  value: value
@@ -62,19 +76,20 @@ def res(value):
62
76
  footprint: "Resistor_SMD:R_0402_1005Metric"
63
77
 
64
78
  def cap(value):
65
- width = 20
79
+ width = 120
66
80
  height = 40
67
81
 
68
82
  return create component:
69
83
  pins: 2
70
84
  angle: 90
71
85
  display: create graphic:
72
- hline: -width/2, -3, width
73
- hline: -width/2, 3, width
74
- vpin: 1, 0, -height/2, 20-3
75
- vpin: 2, 0, height/2, -20+3
76
- label: "refdes", width/2+2, 0, "?", fontSize = 10, anchor="left"
77
- label: "value", width/2+2, 5, value, fontSize = 10, anchor = "left", vanchor="top"
86
+ lineWidth: 13
87
+ hline: -width/2, 20, width
88
+ hline: -width/2, -20, width
89
+ vpin: 1, 0, -100, 80
90
+ vpin: 2, 0, 100, -80
91
+ label: "refdes", 80, -30, "?", fontSize=50, anchor="left", vanchor="middle"
92
+ label: "value", 80, 30, value, fontSize=50, anchor = "left", vanchor="middle"
78
93
  type: "cap"
79
94
  params:
80
95
  value: value
@@ -95,14 +110,14 @@ def ind(value):
95
110
  arc: 15, 0, 5, 180, 360
96
111
  hpin: 1, -width/2 - 20, 0, 20
97
112
  hpin: 2, width/2 + 20, 0, -20
98
- label: ("value", 0, 10, value, fontSize=10, anchor="middle", vanchor="middle")
99
- label: ("refdes", -width/2, -height/2 -5 , "?", fontSize=10, anchor="left")
113
+ label: ("refdes", -width/2, -height/2 -5 , "?", fontSize=50, anchor="left")
114
+ label: ("value", 0, 10, value, fontSize=50, anchor="middle", vanchor="middle")
100
115
  params:
101
116
  value: value
102
117
 
103
118
  def diode():
104
- width = 20
105
- height = 20
119
+ width = 100
120
+ height = 100
106
121
 
107
122
  # Diode is drawn horizontally
108
123
  # -|>|-
@@ -112,13 +127,13 @@ def diode():
112
127
  display: create graphic:
113
128
  triangle: -width/2, 0, width/2, 0, height
114
129
  vline: width/2, -height/2, height
115
- hpin: 1, -width/2-20, 0, 20 # anode
116
- hpin: 2, width/2 + 20, 0, -20 # cathode
117
- label: "refdes", width/2 + 5, 5, "?", fontSize=10, anchor="left", vanchor="top"
130
+ hpin: 1, -width/2-100, 0, 100 # anode
131
+ hpin: 2, width/2 + 100, 0, -100 # cathode
132
+ label: "refdes", 0, -100, "?", fontSize=50, anchor="middle", vanchor="top"
118
133
 
119
134
  def led(color):
120
- width = 20
121
- height = 20
135
+ width = 100
136
+ height = 100
122
137
 
123
138
  return create component:
124
139
  pins:
@@ -128,12 +143,14 @@ def led(color):
128
143
  display: create graphic:
129
144
  triangle: -width/2, 0, width/2, 0, height
130
145
  vline: width/2, -height/2, height
131
- path: ("M", 0, 8, "L", 5, 18,
132
- "M", 3, 8, "L", 8, 18)
133
- hpin: 1, -width/2-20, 0, 20 # anode
134
- hpin: 2, width/2 + 20, 0, -20 # cathode
135
- label: "refdes", width/2 + 5, 5, "?", fontSize=10, anchor="left", vanchor="top"
136
- label: "color", width/2 + 5, 25, color
146
+ path: ("M", 70, 30, "L", 130, 90,
147
+ "M", 130, 60, "L", 130, 90, "L", 100, 90)
148
+ path: ("M", 120, 30, "L", 180, 90,
149
+ "M", 180, 60, "L", 180, 90, "L", 150, 90)
150
+ hpin: 1, -width/2-100, 0, 100 # anode
151
+ hpin: 2, width/2 + 100, 0, -100 # cathode
152
+ label: "refdes", 0, -100, "?", fontSize=50, anchor="middle", vanchor="top"
153
+ label: "color", 0, 100, color, fontSize=40, anchor="middle", vanchor="bottom"
137
154
  params:
138
155
  size: "0603"
139
156
  footprint: "LED_SMD:LED_0603_1608Metric_Pad1.05x0.95mm_HandSolder"
@@ -150,15 +167,15 @@ def cgnd():
150
167
  hline: -10, 5, 20
151
168
  hline: -5, 10, 10
152
169
  vpin: 1, 0, -10, 10, display_pin_id=false
153
- label: "net_name", 0, 22, net_name, fontSize=10, anchor="middle"
170
+ label: "net_name", 0, 22, net_name, fontSize=50, anchor="middle"
154
171
  type: "net"
155
172
  params:
156
173
  net_name: net_name
157
174
  priority: 100
158
175
 
159
176
  def dgnd(net_name="GND"):
160
- height = 10
161
- width = 20
177
+ height = 50
178
+ width = 100
162
179
 
163
180
  return create component:
164
181
  pins: 1
@@ -166,14 +183,14 @@ def dgnd(net_name="GND"):
166
183
  angle: 90
167
184
  display: create graphic:
168
185
  triangle: 0, 0, 0, height, width
169
- vpin: 1, 0, -10, 10, display_pin_id=false
170
- label: "net_name", 0, height + 10, net_name, fontSize=10, anchor="middle"
186
+ vpin: 1, 0, -50, 50, display_pin_id=false
187
+ label: "net_name", 0, height + 50, net_name, fontSize=50, anchor="middle", vanchor="middle"
171
188
  type: "net"
172
189
  params:
173
190
  net_name: net_name
174
191
  priority: 100
175
192
 
176
- def text(value, offsetX = 0, offsetY = 0, fontSize = 12):
193
+ def text(value, offsetX = 0, offsetY = 0, fontSize = 50):
177
194
  return create component:
178
195
  pins: 1
179
196
  followWireOrientation: false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "circuitscript",
3
- "version": "0.0.29",
3
+ "version": "0.0.32",
4
4
  "description": "Interpreter for the circuitscript language",
5
5
  "homepage": "https://circuitscript.net",
6
6
  "engines": {
@@ -27,6 +27,8 @@
27
27
  "@types/figlet": "^1.5.8",
28
28
  "@types/jest": "~29.5",
29
29
  "@types/node": "~18",
30
+ "@types/pdfkit": "^0.13.6",
31
+ "@types/svg-to-pdfkit": "^0.1.3",
30
32
  "@types/svgdom": "^0.1.2",
31
33
  "@typescript-eslint/eslint-plugin": "~5.59",
32
34
  "@typescript-eslint/parser": "~5.59",
@@ -79,6 +81,8 @@
79
81
  "express": "^4.18.2",
80
82
  "figlet": "^1.7.0",
81
83
  "lodash": "^4.17.21",
84
+ "pdfkit": "^0.15.1",
85
+ "svg-to-pdfkit": "^0.1.8",
82
86
  "svgdom": "0.1.14",
83
87
  "this-file": "^2.0.3",
84
88
  "tslib": "~2.5",