circuitscript 0.1.15 → 0.1.17

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 (49) hide show
  1. package/dist/cjs/BaseVisitor.js +98 -35
  2. package/dist/cjs/antlr/CircuitScriptLexer.js +3 -3
  3. package/dist/cjs/antlr/CircuitScriptParser.js +868 -757
  4. package/dist/cjs/builtinMethods.js +11 -1
  5. package/dist/cjs/draw_symbols.js +18 -17
  6. package/dist/cjs/execute.js +58 -31
  7. package/dist/cjs/globals.js +4 -1
  8. package/dist/cjs/graph.js +372 -0
  9. package/dist/cjs/helpers.js +6 -2
  10. package/dist/cjs/layout.js +18 -259
  11. package/dist/cjs/objects/ClassComponent.js +27 -20
  12. package/dist/cjs/objects/ExecutionScope.js +7 -2
  13. package/dist/cjs/objects/Net.js +1 -1
  14. package/dist/cjs/objects/PinDefinition.js +55 -3
  15. package/dist/cjs/objects/types.js +42 -6
  16. package/dist/cjs/visitor.js +88 -48
  17. package/dist/esm/BaseVisitor.js +98 -35
  18. package/dist/esm/antlr/CircuitScriptLexer.js +3 -3
  19. package/dist/esm/antlr/CircuitScriptParser.js +864 -755
  20. package/dist/esm/antlr/CircuitScriptVisitor.js +2 -0
  21. package/dist/esm/builtinMethods.js +11 -1
  22. package/dist/esm/draw_symbols.js +18 -17
  23. package/dist/esm/execute.js +60 -33
  24. package/dist/esm/globals.js +3 -0
  25. package/dist/esm/graph.js +344 -0
  26. package/dist/esm/helpers.js +6 -2
  27. package/dist/esm/layout.js +14 -235
  28. package/dist/esm/objects/ClassComponent.js +28 -21
  29. package/dist/esm/objects/ExecutionScope.js +7 -2
  30. package/dist/esm/objects/Net.js +1 -1
  31. package/dist/esm/objects/PinDefinition.js +53 -2
  32. package/dist/esm/objects/types.js +42 -6
  33. package/dist/esm/visitor.js +90 -50
  34. package/dist/libs/std.cst +3 -2
  35. package/dist/types/BaseVisitor.d.ts +5 -2
  36. package/dist/types/antlr/CircuitScriptParser.d.ts +42 -26
  37. package/dist/types/antlr/CircuitScriptVisitor.d.ts +4 -0
  38. package/dist/types/draw_symbols.d.ts +13 -7
  39. package/dist/types/execute.d.ts +12 -12
  40. package/dist/types/globals.d.ts +4 -1
  41. package/dist/types/graph.d.ts +29 -0
  42. package/dist/types/layout.d.ts +4 -9
  43. package/dist/types/objects/ClassComponent.d.ts +8 -8
  44. package/dist/types/objects/ExecutionScope.d.ts +8 -7
  45. package/dist/types/objects/Net.d.ts +2 -2
  46. package/dist/types/objects/PinDefinition.d.ts +17 -2
  47. package/dist/types/objects/types.d.ts +31 -7
  48. package/libs/std.cst +3 -2
  49. package/package.json +2 -1
@@ -109,30 +109,31 @@ export declare class CircuitScriptParser extends antlr.Parser {
109
109
  static readonly RULE_function_args_expr = 37;
110
110
  static readonly RULE_atom_expr = 38;
111
111
  static readonly RULE_trailer_expr = 39;
112
- static readonly RULE_function_call_expr = 40;
113
- static readonly RULE_net_namespace_expr = 41;
114
- static readonly RULE_function_return_expr = 42;
115
- static readonly RULE_property_block_expr = 43;
116
- static readonly RULE_create_component_expr = 44;
117
- static readonly RULE_graphic_expressions_block = 45;
118
- static readonly RULE_create_graphic_expr = 46;
119
- static readonly RULE_create_module_expr = 47;
120
- static readonly RULE_nested_properties_inner = 48;
121
- static readonly RULE_graphic_expr = 49;
122
- static readonly RULE_property_expr = 50;
123
- static readonly RULE_property_key_expr = 51;
124
- static readonly RULE_property_value_expr = 52;
125
- static readonly RULE_wire_atom_expr = 53;
126
- static readonly RULE_wire_expr = 54;
127
- static readonly RULE_array_expr = 55;
128
- static readonly RULE_point_expr = 56;
129
- static readonly RULE_import_expr = 57;
130
- static readonly RULE_frame_expr = 58;
131
- static readonly RULE_if_expr = 59;
132
- static readonly RULE_if_inner_expr = 60;
133
- static readonly RULE_else_expr = 61;
134
- static readonly RULE_while_expr = 62;
135
- static readonly RULE_for_expr = 63;
112
+ static readonly RULE_trailer_expr2 = 40;
113
+ static readonly RULE_function_call_expr = 41;
114
+ static readonly RULE_net_namespace_expr = 42;
115
+ static readonly RULE_function_return_expr = 43;
116
+ static readonly RULE_property_block_expr = 44;
117
+ static readonly RULE_create_component_expr = 45;
118
+ static readonly RULE_graphic_expressions_block = 46;
119
+ static readonly RULE_create_graphic_expr = 47;
120
+ static readonly RULE_create_module_expr = 48;
121
+ static readonly RULE_nested_properties_inner = 49;
122
+ static readonly RULE_graphic_expr = 50;
123
+ static readonly RULE_property_expr = 51;
124
+ static readonly RULE_property_key_expr = 52;
125
+ static readonly RULE_property_value_expr = 53;
126
+ static readonly RULE_wire_atom_expr = 54;
127
+ static readonly RULE_wire_expr = 55;
128
+ static readonly RULE_array_expr = 56;
129
+ static readonly RULE_point_expr = 57;
130
+ static readonly RULE_import_expr = 58;
131
+ static readonly RULE_frame_expr = 59;
132
+ static readonly RULE_if_expr = 60;
133
+ static readonly RULE_if_inner_expr = 61;
134
+ static readonly RULE_else_expr = 62;
135
+ static readonly RULE_while_expr = 63;
136
+ static readonly RULE_for_expr = 64;
136
137
  static readonly literalNames: (string | null)[];
137
138
  static readonly symbolicNames: (string | null)[];
138
139
  static readonly ruleNames: string[];
@@ -184,6 +185,7 @@ export declare class CircuitScriptParser extends antlr.Parser {
184
185
  function_args_expr(): Function_args_exprContext;
185
186
  atom_expr(): Atom_exprContext;
186
187
  trailer_expr(): Trailer_exprContext;
188
+ trailer_expr2(): Trailer_expr2Context;
187
189
  function_call_expr(): Function_call_exprContext;
188
190
  net_namespace_expr(): Net_namespace_exprContext;
189
191
  function_return_expr(): Function_return_exprContext;
@@ -507,6 +509,12 @@ export declare class ArrayExprContext extends Data_exprContext {
507
509
  array_expr(): Array_exprContext;
508
510
  accept<Result>(visitor: CircuitScriptVisitor<Result>): Result | null;
509
511
  }
512
+ export declare class ArrayIndexExprContext extends Data_exprContext {
513
+ constructor(ctx: Data_exprContext);
514
+ data_expr(): Data_exprContext[];
515
+ data_expr(i: number): Data_exprContext | null;
516
+ accept<Result>(visitor: CircuitScriptVisitor<Result>): Result | null;
517
+ }
510
518
  export declare class FunctionCallExprContext extends Data_exprContext {
511
519
  constructor(ctx: Data_exprContext);
512
520
  function_call_expr(): Function_call_exprContext;
@@ -634,8 +642,9 @@ export declare class Function_args_exprContext extends antlr.ParserRuleContext {
634
642
  }
635
643
  export declare class Atom_exprContext extends antlr.ParserRuleContext {
636
644
  constructor(parent: antlr.ParserRuleContext | null, invokingState: number);
637
- ID(): antlr.TerminalNode[];
638
- ID(i: number): antlr.TerminalNode | null;
645
+ ID(): antlr.TerminalNode;
646
+ trailer_expr2(): Trailer_expr2Context[];
647
+ trailer_expr2(i: number): Trailer_expr2Context | null;
639
648
  get ruleIndex(): number;
640
649
  accept<Result>(visitor: CircuitScriptVisitor<Result>): Result | null;
641
650
  }
@@ -644,7 +653,14 @@ export declare class Trailer_exprContext extends antlr.ParserRuleContext {
644
653
  OPEN_PAREN(): antlr.TerminalNode | null;
645
654
  CLOSE_PAREN(): antlr.TerminalNode | null;
646
655
  parameters(): ParametersContext | null;
656
+ trailer_expr2(): Trailer_expr2Context | null;
657
+ get ruleIndex(): number;
658
+ accept<Result>(visitor: CircuitScriptVisitor<Result>): Result | null;
659
+ }
660
+ export declare class Trailer_expr2Context extends antlr.ParserRuleContext {
661
+ constructor(parent: antlr.ParserRuleContext | null, invokingState: number);
647
662
  ID(): antlr.TerminalNode | null;
663
+ data_expr(): Data_exprContext | null;
648
664
  get ruleIndex(): number;
649
665
  accept<Result>(visitor: CircuitScriptVisitor<Result>): Result | null;
650
666
  }
@@ -31,6 +31,7 @@ import { ParametersContext } from "./CircuitScriptParser.js";
31
31
  import { Property_set_exprContext } from "./CircuitScriptParser.js";
32
32
  import { Double_dot_property_set_exprContext } from "./CircuitScriptParser.js";
33
33
  import { ArrayExprContext } from "./CircuitScriptParser.js";
34
+ import { ArrayIndexExprContext } from "./CircuitScriptParser.js";
34
35
  import { FunctionCallExprContext } from "./CircuitScriptParser.js";
35
36
  import { AdditionExprContext } from "./CircuitScriptParser.js";
36
37
  import { MultiplyExprContext } from "./CircuitScriptParser.js";
@@ -48,6 +49,7 @@ import { Function_exprContext } from "./CircuitScriptParser.js";
48
49
  import { Function_args_exprContext } from "./CircuitScriptParser.js";
49
50
  import { Atom_exprContext } from "./CircuitScriptParser.js";
50
51
  import { Trailer_exprContext } from "./CircuitScriptParser.js";
52
+ import { Trailer_expr2Context } from "./CircuitScriptParser.js";
51
53
  import { Function_call_exprContext } from "./CircuitScriptParser.js";
52
54
  import { Net_namespace_exprContext } from "./CircuitScriptParser.js";
53
55
  import { Function_return_exprContext } from "./CircuitScriptParser.js";
@@ -108,6 +110,7 @@ export declare class CircuitScriptVisitor<Result> extends AbstractParseTreeVisit
108
110
  visitProperty_set_expr?: (ctx: Property_set_exprContext) => Result;
109
111
  visitDouble_dot_property_set_expr?: (ctx: Double_dot_property_set_exprContext) => Result;
110
112
  visitArrayExpr?: (ctx: ArrayExprContext) => Result;
113
+ visitArrayIndexExpr?: (ctx: ArrayIndexExprContext) => Result;
111
114
  visitFunctionCallExpr?: (ctx: FunctionCallExprContext) => Result;
112
115
  visitAdditionExpr?: (ctx: AdditionExprContext) => Result;
113
116
  visitMultiplyExpr?: (ctx: MultiplyExprContext) => Result;
@@ -125,6 +128,7 @@ export declare class CircuitScriptVisitor<Result> extends AbstractParseTreeVisit
125
128
  visitFunction_args_expr?: (ctx: Function_args_exprContext) => Result;
126
129
  visitAtom_expr?: (ctx: Atom_exprContext) => Result;
127
130
  visitTrailer_expr?: (ctx: Trailer_exprContext) => Result;
131
+ visitTrailer_expr2?: (ctx: Trailer_expr2Context) => Result;
128
132
  visitFunction_call_expr?: (ctx: Function_call_exprContext) => Result;
129
133
  visitNet_namespace_expr?: (ctx: Net_namespace_exprContext) => Result;
130
134
  visitFunction_return_expr?: (ctx: Function_return_exprContext) => Result;
@@ -4,6 +4,7 @@ import { Logger } from "./logger.js";
4
4
  import { PinTypes } from "./objects/PinTypes.js";
5
5
  import { ParserRuleContext } from "antlr4ng";
6
6
  import { NumericValue } from "./objects/ParamDefinition.js";
7
+ import { PinId } from "./objects/PinDefinition.js";
7
8
  export declare abstract class SymbolGraphic {
8
9
  drawPortsName: boolean;
9
10
  displayBounds: boolean;
@@ -37,7 +38,7 @@ export declare abstract class SymbolGraphic {
37
38
  drawPlaceRemove(group: G, extra?: {
38
39
  place?: boolean;
39
40
  }): void;
40
- pinPosition(id: number): {
41
+ pinPosition(id: PinId): {
41
42
  x: NumericValue;
42
43
  y: NumericValue;
43
44
  angle: NumericValue;
@@ -131,7 +132,7 @@ export declare class SymbolCustomModule extends SymbolCustom {
131
132
  }
132
133
  export declare class SymbolDrawing {
133
134
  items: (Feature | GeometryProp)[];
134
- pins: [NumericValue, Feature, angle: NumericValue, lineColor: string][];
135
+ pins: PinRenderInfo[];
135
136
  angle: number;
136
137
  flipX: number;
137
138
  flipY: number;
@@ -141,8 +142,7 @@ export declare class SymbolDrawing {
141
142
  clear(): void;
142
143
  log(...params: any[]): void;
143
144
  addLine(startX: NumericValue, startY: NumericValue, endX: NumericValue, endY: NumericValue): SymbolDrawing;
144
- addPin(pinId: NumericValue, startX: NumericValue, startY: NumericValue, endX: NumericValue, endY: NumericValue, lineColor: string): SymbolDrawing;
145
- addPinMM(pinId: NumericValue, startXMM: NumericValue, startYMM: NumericValue, endXMM: NumericValue, endYMM: NumericValue, lineColor: string): SymbolDrawing;
145
+ addPinMM(pinId: PinId, startXMM: NumericValue, startYMM: NumericValue, endXMM: NumericValue, endYMM: NumericValue, lineColor: string): SymbolDrawing;
146
146
  addVLine(startX: NumericValue, startY: NumericValue, value: NumericValue): SymbolDrawing;
147
147
  addHLine(startX: NumericValue, startY: NumericValue, value: NumericValue): SymbolDrawing;
148
148
  addRect(x: NumericValue, y: NumericValue, width: NumericValue, height: NumericValue): SymbolDrawing;
@@ -177,7 +177,7 @@ export declare class SymbolDrawing {
177
177
  start: SimplePoint;
178
178
  end: SimplePoint;
179
179
  };
180
- getPinPosition(pinId: number): {
180
+ getPinPosition(pinId: PinId): {
181
181
  start: [x: NumericValue, y: NumericValue];
182
182
  end: [x: NumericValue, y: NumericValue];
183
183
  angle: NumericValue;
@@ -191,7 +191,7 @@ export type GraphicExprCommand = [
191
191
  ];
192
192
  export declare class SymbolDrawingCommands extends SymbolDrawing {
193
193
  id: string;
194
- private commands;
194
+ protected commands: GraphicExprCommand[];
195
195
  paramIds: string[];
196
196
  callback: (variables: Map<string, any>) => GraphicExprCommand[];
197
197
  constructor(callback: (variables: Map<string, any>) => GraphicExprCommand[]);
@@ -216,9 +216,15 @@ type SymbolPinLayout = {
216
216
  };
217
217
  export type SymbolPinDefintion = {
218
218
  side: string;
219
- pinId: number;
219
+ pinId: PinId;
220
220
  text: string;
221
221
  position: number;
222
222
  pinType: PinTypes;
223
223
  };
224
+ export type PinRenderInfo = [
225
+ PinId,
226
+ Feature,
227
+ angle: NumericValue,
228
+ lineColor: string
229
+ ];
224
230
  export {};
@@ -4,8 +4,8 @@ import { ClassComponent } from './objects/ClassComponent.js';
4
4
  import { ExecutionScope } from './objects/ExecutionScope.js';
5
5
  import { Net } from './objects/Net.js';
6
6
  import { NumericValue, ParamDefinition } from './objects/ParamDefinition.js';
7
- import { PinDefinition } from './objects/PinDefinition.js';
8
- import { AnyReference, CFunction, CFunctionResult, CallableParameter, ComponentPin, DeclaredReference } from './objects/types.js';
7
+ import { PinDefinition, PinId } from './objects/PinDefinition.js';
8
+ import { AnyReference, CFunction, CFunctionEntry, CFunctionResult, CallableParameter, ComponentPin } from './objects/types.js';
9
9
  import { Logger } from './logger.js';
10
10
  import { UnitDimension } from './helpers.js';
11
11
  import { ParserRuleContext } from 'antlr4ng';
@@ -21,12 +21,12 @@ export declare class ExecutionContext {
21
21
  found: boolean;
22
22
  net?: Net;
23
23
  });
24
- resolveComponentPinNet: (component: ClassComponent, pin: number) => Net | null;
24
+ resolveComponentPinNet: (component: ClassComponent, pin: PinId) => Net | null;
25
25
  stopFurtherExpressions: boolean;
26
26
  returnValue: null;
27
27
  silent: boolean;
28
28
  logger: Logger;
29
- __functionCache: {};
29
+ __functionCache: Map<string, CFunction>;
30
30
  parentContext: ExecutionContext;
31
31
  componentAngleFollowsWire: boolean;
32
32
  warnings: ExecutionWarning[];
@@ -40,7 +40,7 @@ export declare class ExecutionContext {
40
40
  private linkComponentPinNet;
41
41
  private mergeNets;
42
42
  createComponent(instanceName: string, pins: PinDefinition[], params: ParamDefinition[], props: {
43
- arrange?: Map<string, number[]>;
43
+ arrange?: Map<string, PinId[]>;
44
44
  display?: SymbolDrawingCommands;
45
45
  type?: string;
46
46
  width?: number;
@@ -52,11 +52,11 @@ export declare class ExecutionContext {
52
52
  private removeArrangePropDuplicates;
53
53
  private getArrangePropPins;
54
54
  printPoint(extra?: string): void;
55
- addComponentExisting(component: ClassComponent, pin: number): ComponentPin;
55
+ addComponentExisting(component: ClassComponent, pin: PinId): ComponentPin;
56
56
  toComponent(component: ClassComponent, pinId: number | null, options?: {
57
57
  addSequence?: boolean;
58
58
  }): ComponentPin;
59
- atComponent(component: ClassComponent, pinId: number | null, options?: {
59
+ atComponent(component: ClassComponent, pinId: PinId | null, options?: {
60
60
  addSequence?: boolean;
61
61
  }): ComponentPin;
62
62
  copyComponent(component: ClassComponent): ClassComponent;
@@ -71,10 +71,10 @@ export declare class ExecutionContext {
71
71
  addBreakContext(ctx: ParserRuleContext): void;
72
72
  popBreakContext(): ParserRuleContext;
73
73
  getBreakContext(): ParserRuleContext;
74
- createFunction(functionName: string, __runFunc: CFunction): void;
74
+ createFunction(functionName: string, __runFunc: CFunction, source?: ParserRuleContext, uniqueId?: string): void;
75
75
  hasFunction(functionName: string): boolean;
76
- getFunction(functionName: string): CFunction;
77
- resolveVariable(executionStack: ExecutionContext[], idName: string, trailers?: string[]): DeclaredReference;
76
+ getFunction(functionName: string): CFunctionEntry;
77
+ resolveVariable(executionStack: ExecutionContext[], idName: string, trailers?: string[]): AnyReference;
78
78
  resolveTrailers(type: ReferenceTypes, item: any, trailers?: string[]): AnyReference;
79
79
  callFunction(functionName: string, functionParams: CallableParameter[], executionStack: ExecutionContext[], netNamespace: string): CFunctionResult;
80
80
  mergeScope(childScope: ExecutionScope, namespace: string): void;
@@ -86,12 +86,12 @@ export declare class ExecutionContext {
86
86
  enterFrame(frameType: FrameType): number;
87
87
  exitFrame(frameId: number): void;
88
88
  }
89
- export declare function getPortSide(pins: Map<number, PinDefinition>, arrangeProps: null | Map<string, number[]>): {
89
+ export declare function getPortSide(pins: Map<PinId, PinDefinition>, arrangeProps: null | Map<string, number[]>): {
90
90
  pins: PortSideItem[];
91
91
  maxPositions: Map<string, number>;
92
92
  };
93
93
  type PortSideItem = {
94
- pinId: number;
94
+ pinId: PinId;
95
95
  side: string;
96
96
  order: number;
97
97
  position: number;
@@ -9,6 +9,7 @@ export declare const NoNetText = "NO_NET";
9
9
  export declare enum ParamKeys {
10
10
  priority = "priority",
11
11
  net_name = "net_name",
12
+ net_type = "net_type",
12
13
  flip = "flip",
13
14
  flipX = "flipX",
14
15
  flipY = "flipY",
@@ -80,7 +81,8 @@ export declare enum ReferenceTypes {
80
81
  value = "value",
81
82
  variable = "variable",
82
83
  instance = "instance",
83
- pinType = "pinType"
84
+ pinType = "pinType",
85
+ unknown = "unknown"
84
86
  }
85
87
  export declare enum BlockTypes {
86
88
  Branch = 1,
@@ -109,3 +111,4 @@ export declare const RenderFlags: {
109
111
  ShowLabelOrigin: boolean;
110
112
  };
111
113
  export declare const SymbolValidatorContext = "_sym";
114
+ export declare const TrailerArrayIndex = "index";
@@ -0,0 +1,29 @@
1
+ import { Graph } from "@dagrejs/graphlib";
2
+ import { SymbolPinDefintion } from "./draw_symbols.js";
3
+ import { RenderFrame } from "./layout.js";
4
+ import { ClassComponent } from "./objects/ClassComponent.js";
5
+ import { SequenceItem } from "./objects/ExecutionScope.js";
6
+ import { Net } from "./objects/Net.js";
7
+ import { Logger } from "./logger.js";
8
+ import { ComponentPinNetPair } from "./objects/types.js";
9
+ import { PinId } from "./objects/PinDefinition.js";
10
+ export declare class NetGraph {
11
+ logger: Logger;
12
+ constructor(logger: Logger);
13
+ generateLayoutGraph(sequence: SequenceItem[], nets: [ClassComponent, pin: PinId, net: Net][]): {
14
+ graph: Graph;
15
+ containerFrames: RenderFrame[];
16
+ };
17
+ private setGraphEdge;
18
+ protected print(...params: any[]): void;
19
+ generateNetGraph(nets: ComponentPinNetPair[]): void;
20
+ findNodePaths(graph: Graph, startNode: string, endNode: string, seenNodes?: string[]): string[][];
21
+ private getNetNodeName;
22
+ private getComponentName;
23
+ }
24
+ export declare function getWireName(wireId: number): string;
25
+ export declare function generateLayoutPinDefinition(component: ClassComponent): SymbolPinDefintion[];
26
+ export declare enum RenderItemType {
27
+ Wire = "wire",
28
+ Component = "component"
29
+ }
@@ -1,7 +1,6 @@
1
1
  import { Graph } from '@dagrejs/graphlib';
2
2
  import { SymbolGraphic, SymbolText, SymbolDrawingCommands, SimplePoint } from "./draw_symbols.js";
3
3
  import { ClassComponent } from "./objects/ClassComponent.js";
4
- import { SequenceItem } from "./objects/ExecutionScope.js";
5
4
  import { WireAutoDirection } from './globals.js';
6
5
  import { WireSegment } from './objects/Wire.js';
7
6
  import { Net } from './objects/Net.js';
@@ -9,18 +8,19 @@ import { Logger } from './logger.js';
9
8
  import { Frame, FramePlotDirection } from './objects/Frame.js';
10
9
  import { BoundBox } from './utils.js';
11
10
  import { ComponentPinNetPair } from './objects/types.js';
11
+ import { PinId } from './objects/PinDefinition.js';
12
12
  import { NumericValue } from './objects/ParamDefinition.js';
13
13
  export declare class LayoutEngine {
14
14
  logger: Logger;
15
15
  layoutWarnings: string[];
16
16
  showBaseFrame: boolean;
17
- constructor(options?: {
17
+ constructor(logger: Logger, options?: {
18
18
  showBaseFrame: boolean;
19
19
  });
20
20
  protected print(...params: any[]): void;
21
21
  protected printLevel(level: number, ...params: any[]): void;
22
22
  protected padLevel(value: number): string;
23
- runLayout(sequence: SequenceItem[], nets: ComponentPinNetPair[]): SheetFrame[];
23
+ runLayout(graph: Graph, containerFrames: RenderFrame[], nets: ComponentPinNetPair[]): SheetFrame[];
24
24
  private collectRenderNets;
25
25
  private flattenFrameItems;
26
26
  private findJunctions;
@@ -31,17 +31,12 @@ export declare class LayoutEngine {
31
31
  dumpFrame(frame: RenderFrame, level?: number): void;
32
32
  private prepareFrames;
33
33
  private checkAddFrameTitle;
34
- generateLayoutGraph(sequence: SequenceItem[], nets: [ClassComponent, pin: number, net: Net][]): {
35
- graph: Graph;
36
- containerFrames: RenderFrame[];
37
- };
38
- private setGraphEdge;
39
34
  private sizeSubGraphs;
40
35
  private walkAndPlaceGraph;
41
36
  private placeSubgraphV2;
42
37
  mergeOriginNodes(node1: RenderItem, pin1: number, node2: RenderItem, pin2: number, originNode1: string, originNode2: string, originNodes: RenderItem[], originNodeGroups: Map<string, RenderItem[]>): void;
43
38
  translateNodeBy(offsetX: number, offsetY: number, item: RenderItem): void;
44
- placeNodeAtPosition(fromX: NumericValue, fromY: NumericValue, item: RenderItem, pin: number, depth?: number): void;
39
+ placeNodeAtPosition(fromX: NumericValue, fromY: NumericValue, item: RenderItem, pin: PinId, depth?: number): void;
45
40
  placeFloatingItems(graph: Graph, item: RenderItem, depth?: number): void;
46
41
  printWarnings(): void;
47
42
  }
@@ -9,8 +9,8 @@ export declare class ClassComponent {
9
9
  instanceName: string;
10
10
  numPins: number;
11
11
  parameters: Map<string, number | string | NumericValue>;
12
- pins: Map<number, PinDefinition>;
13
- pinNets: Map<number, Net>;
12
+ pins: Map<PinId, PinDefinition>;
13
+ pinNets: Map<PinId, Net>;
14
14
  pinWires: Map<number, WireSegment[]>;
15
15
  pinsMaxPositions: Map<string, number>;
16
16
  _cachedPins: string;
@@ -18,8 +18,8 @@ export declare class ClassComponent {
18
18
  _copyID?: number;
19
19
  _copyFrom?: ClassComponent;
20
20
  _pointLinkComponent?: ClassComponent;
21
- _unplacedPins: number[];
22
- arrangeProps: Map<string, NumericValue[]> | null;
21
+ _unplacedPins: PinId[];
22
+ arrangeProps: Map<string, PinId[]> | null;
23
23
  displayProp: SymbolDrawingCommands | null;
24
24
  widthProp: number | null;
25
25
  heightProp: number | null;
@@ -33,10 +33,10 @@ export declare class ClassComponent {
33
33
  assignedRefDes: string | null;
34
34
  constructor(instanceName: string, numPins: number);
35
35
  setupPins(): void;
36
- getDefaultPin(): number;
37
- hasPin(pinId: number | string): boolean;
38
- getPin(pinId: number | string): PinId;
39
- getNextPinAfter(pinIndex: number): number;
36
+ getDefaultPin(): PinId;
37
+ hasPin(pinId: PinId): boolean;
38
+ getPin(pinId: PinId): PinId;
39
+ getNextPinAfter(pinIndex: PinId): PinId;
40
40
  setParam(key: string, value: number | string | NumericValue): void;
41
41
  hasParam(key: string): boolean;
42
42
  private refreshParamCache;
@@ -1,18 +1,19 @@
1
1
  import { ClassComponent } from './ClassComponent.js';
2
2
  import { Net } from './Net.js';
3
- import { CFunction, ComponentPinNet, ComponentPinNetPair, ComponentPinWireId, ParseSymbolType, ValueType } from './types.js';
3
+ import { CFunctionEntry, ComponentPinNet, ComponentPinNetPair, ComponentPinWireId, ParseSymbolType, ValueType } from './types.js';
4
4
  import { BlockTypes, LayoutDirection } from '../globals.js';
5
5
  import { Wire, WireSegment } from './Wire.js';
6
6
  import { Frame } from './Frame.js';
7
7
  import { ParserRuleContext } from 'antlr4ng';
8
8
  import { BaseVisitor } from 'src/BaseVisitor.js';
9
+ import { PinId } from './PinDefinition.js';
9
10
  type OnPropertyHandler = (path: PropertyTreeKey[], value: any, valueContext: ParserRuleContext) => void;
10
11
  export type PropertyTreeKey = [ctx: ParserRuleContext, value: any] | ['index', number];
11
12
  export declare class ExecutionScope {
12
13
  scopeId: number;
13
14
  private nets;
14
15
  instances: Map<string, ClassComponent>;
15
- functions: Map<string, CFunction>;
16
+ functions: Map<string, CFunctionEntry>;
16
17
  variables: Map<string, ValueType | ClassComponent>;
17
18
  symbols: Map<string, {
18
19
  type: ParseSymbolType;
@@ -33,16 +34,16 @@ export declare class ExecutionScope {
33
34
  componentRoot: ClassComponent | null;
34
35
  copyIDs: Map<string, number>;
35
36
  sequence: SequenceItem[];
36
- constructor(scopeId: number);
37
+ private constructor();
37
38
  static scopeId: number;
38
39
  static create(): ExecutionScope;
39
40
  private findNet;
40
41
  getNetWithName(name: string): Net;
41
42
  getNetWithNamespacePath(namespace: string, name: string): Net | null;
42
- hasNet(component: ClassComponent, pin: number): boolean;
43
- getNet(component: ClassComponent, pin: number): Net | null;
44
- setNet(component: ClassComponent, pin: number, net: Net): void;
45
- removeNet(component: ClassComponent, pin: number): void;
43
+ hasNet(component: ClassComponent, pin: PinId): boolean;
44
+ getNet(component: ClassComponent, pin: PinId): Net | null;
45
+ setNet(component: ClassComponent, pin: PinId, net: Net): void;
46
+ removeNet(component: ClassComponent, pin: PinId): void;
46
47
  getNets(): ComponentPinNetPair[];
47
48
  dumpNets(): ComponentPinNet[];
48
49
  printNets(): void;
@@ -3,9 +3,9 @@ export declare class Net {
3
3
  baseName: string;
4
4
  namespace: string;
5
5
  priority: number;
6
- type: any;
6
+ type: string;
7
7
  params: Map<string, any>;
8
- constructor(namespace: string, name: string, priority?: number, type?: any);
8
+ constructor(namespace: string, name: string, priority?: number, type?: string);
9
9
  toString(): string;
10
10
  static isSame(netA: Net, netB: Net): boolean;
11
11
  }
@@ -1,5 +1,18 @@
1
+ import { NumericValue } from './ParamDefinition.js';
1
2
  import { PinTypes } from './PinTypes.js';
2
- export type PinId = number | string;
3
+ export declare class PinId {
4
+ private value;
5
+ private type;
6
+ constructor(value: number | string);
7
+ getValue(): number | string;
8
+ getType(): PinIdType;
9
+ isNumeric(): boolean;
10
+ isString(): boolean;
11
+ toString(): string;
12
+ equals(other: PinId | number | string): boolean;
13
+ static from(value: number | string | NumericValue): PinId;
14
+ static isPinIdType(value: number | string): boolean;
15
+ }
3
16
  export declare class PinDefinition {
4
17
  id: PinId;
5
18
  idType: PinIdType;
@@ -8,7 +21,7 @@ export declare class PinDefinition {
8
21
  altNames: string[];
9
22
  side: string;
10
23
  position: number;
11
- constructor(id: PinId, idType: PinIdType, name: string, pinType?: PinTypes, altNames?: never[]);
24
+ constructor(id: PinId | number | string, idType: PinIdType, name: string, pinType?: PinTypes, altNames?: never[]);
12
25
  }
13
26
  export declare enum PinIdType {
14
27
  Int = "int",
@@ -20,3 +33,5 @@ export declare enum PortSide {
20
33
  SOUTH = "SOUTH",
21
34
  NORTH = "NORTH"
22
35
  }
36
+ export declare function isPinId(item: any): boolean;
37
+ export declare function getPinDefinition(map: Map<PinId, PinDefinition>, id: PinId): PinDefinition;
@@ -1,10 +1,19 @@
1
- import { Token } from 'antlr4ng';
1
+ import { ParserRuleContext, Token } from 'antlr4ng';
2
2
  import { ExecutionContext } from '../execute.js';
3
3
  import { ClassComponent } from './ClassComponent.js';
4
4
  import { Net } from './Net.js';
5
5
  import { NumericValue, PercentageValue } from './ParamDefinition.js';
6
6
  import { ReferenceTypes } from '../globals.js';
7
+ import { PinId } from './PinDefinition.js';
7
8
  export type CFunction = (args: CallableParameter[], options?: CFunctionOptions) => CFunctionResult;
9
+ export declare class CFunctionEntry {
10
+ name: string;
11
+ execute: CFunction;
12
+ uniqueId?: string;
13
+ source?: ParserRuleContext;
14
+ constructor(name: string, execute: CFunction, source?: ParserRuleContext, uniqueId?: string);
15
+ toString(): string;
16
+ }
8
17
  export type CFunctionOptions = {
9
18
  netNamespace?: string;
10
19
  };
@@ -19,7 +28,7 @@ export type ComponentPinNet = [
19
28
  ];
20
29
  export type ComponentPinNetPair = [
21
30
  component: ClassComponent,
22
- pin: number,
31
+ pin: PinId,
23
32
  net: Net
24
33
  ];
25
34
  export type ComponentPinWireId = [
@@ -50,20 +59,22 @@ export type FunctionDefinedParameter = [
50
59
  export declare class AnyReference {
51
60
  found: boolean;
52
61
  name?: string;
53
- trailers: string[];
54
- type?: ReferenceTypes;
62
+ trailers: (string | ['index', number])[];
63
+ type: ReferenceTypes;
55
64
  value?: any;
56
65
  parentValue?: any;
66
+ referenceName: string;
57
67
  constructor(refType: {
58
68
  found: boolean;
59
69
  name?: string;
60
- trailers?: string[];
70
+ trailers?: (string | ['index', number])[];
61
71
  type?: ReferenceTypes;
62
72
  value?: any;
63
73
  parentValue?: any;
64
74
  });
75
+ toString(): string;
65
76
  }
66
- export declare class UndeclaredReference {
77
+ export declare class UndeclaredReference extends AnyReference {
67
78
  reference: AnyReference;
68
79
  constructor(reference: AnyReference);
69
80
  throwMessage(): string;
@@ -71,7 +82,7 @@ export declare class UndeclaredReference {
71
82
  nameString(): string;
72
83
  }
73
84
  export declare class DeclaredReference extends AnyReference {
74
- toString(): string;
85
+ referenceName: string;
75
86
  toDisplayString(): string;
76
87
  }
77
88
  export declare enum ParseSymbolType {
@@ -85,3 +96,16 @@ export declare enum Direction {
85
96
  Down = "down",
86
97
  Up = "up"
87
98
  }
99
+ export declare enum TypeProps {
100
+ Net = "net",
101
+ Port = "port",
102
+ Graphic = "graphic",
103
+ Resistor = "res",
104
+ Capacitor = "cap",
105
+ Inductor = "ind",
106
+ Diode = "diode"
107
+ }
108
+ export declare enum NetTypes {
109
+ Any = "any",
110
+ Source = "source"
111
+ }
package/libs/std.cst CHANGED
@@ -1,6 +1,6 @@
1
1
  # Circuitscript default lib
2
2
 
3
- def net(net_name):
3
+ def net(net_name, net_type = "any"):
4
4
  return create component:
5
5
  pins: 1
6
6
  copy: true
@@ -13,9 +13,10 @@ def net(net_name):
13
13
  params:
14
14
  net_name: net_name
15
15
  priority: 10
16
+ net_type: net_type
16
17
 
17
18
  def supply(net_name):
18
- net_obj = net(net_name)
19
+ net_obj = net(net_name, "source")
19
20
  return net_obj
20
21
 
21
22
  def label(value, anchor="left"):
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "circuitscript",
3
- "version": "0.1.15",
3
+ "version": "0.1.17",
4
4
  "description": "Interpreter for the circuitscript language",
5
5
  "homepage": "https://circuitscript.net",
6
6
  "engines": {
@@ -88,6 +88,7 @@
88
88
  "express": "^4.18.2",
89
89
  "figlet": "^1.7.0",
90
90
  "lodash": "^4.17.21",
91
+ "ml-matrix": "^6.12.1",
91
92
  "pdfkit": "^0.15.1",
92
93
  "svg-to-pdfkit": "^0.1.8",
93
94
  "svgdom": "^0.1.22",