circuitscript 0.1.14 → 0.1.16

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 (39) hide show
  1. package/dist/cjs/BaseVisitor.js +96 -34
  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/execute.js +18 -11
  6. package/dist/cjs/geometry.js +19 -0
  7. package/dist/cjs/globals.js +6 -2
  8. package/dist/cjs/graph.js +298 -0
  9. package/dist/cjs/helpers.js +6 -2
  10. package/dist/cjs/layout.js +27 -261
  11. package/dist/cjs/objects/types.js +27 -6
  12. package/dist/cjs/render.js +20 -14
  13. package/dist/cjs/visitor.js +32 -30
  14. package/dist/esm/BaseVisitor.js +96 -34
  15. package/dist/esm/antlr/CircuitScriptLexer.js +3 -3
  16. package/dist/esm/antlr/CircuitScriptParser.js +864 -755
  17. package/dist/esm/antlr/CircuitScriptVisitor.js +2 -0
  18. package/dist/esm/builtinMethods.js +11 -1
  19. package/dist/esm/execute.js +19 -12
  20. package/dist/esm/geometry.js +19 -0
  21. package/dist/esm/globals.js +5 -1
  22. package/dist/esm/graph.js +293 -0
  23. package/dist/esm/helpers.js +6 -2
  24. package/dist/esm/layout.js +23 -237
  25. package/dist/esm/objects/types.js +27 -6
  26. package/dist/esm/render.js +20 -14
  27. package/dist/esm/visitor.js +33 -31
  28. package/dist/types/BaseVisitor.d.ts +3 -1
  29. package/dist/types/antlr/CircuitScriptParser.d.ts +42 -26
  30. package/dist/types/antlr/CircuitScriptVisitor.d.ts +4 -0
  31. package/dist/types/draw_symbols.d.ts +1 -1
  32. package/dist/types/execute.d.ts +5 -5
  33. package/dist/types/geometry.d.ts +3 -1
  34. package/dist/types/globals.d.ts +7 -3
  35. package/dist/types/graph.d.ts +28 -0
  36. package/dist/types/layout.d.ts +6 -10
  37. package/dist/types/objects/ExecutionScope.d.ts +3 -3
  38. package/dist/types/objects/types.d.ts +16 -6
  39. package/package.json +1 -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;
@@ -200,7 +200,7 @@ export declare class SymbolDrawingCommands extends SymbolDrawing {
200
200
  clone(): SymbolDrawingCommands;
201
201
  eq(other: SymbolDrawingCommands): boolean;
202
202
  }
203
- type SimplePoint = [x: number, y: number];
203
+ export type SimplePoint = [x: number, y: number];
204
204
  type SymbolPinLayout = {
205
205
  pinId: number;
206
206
  angle: number;
@@ -5,7 +5,7 @@ import { ExecutionScope } from './objects/ExecutionScope.js';
5
5
  import { Net } from './objects/Net.js';
6
6
  import { NumericValue, ParamDefinition } from './objects/ParamDefinition.js';
7
7
  import { PinDefinition } from './objects/PinDefinition.js';
8
- import { AnyReference, CFunction, CFunctionResult, CallableParameter, ComponentPin, DeclaredReference } from './objects/types.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';
@@ -26,7 +26,7 @@ export declare class ExecutionContext {
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[];
@@ -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;
@@ -2,6 +2,7 @@ import Flatten from '@flatten-js/core';
2
2
  import { Box } from '@svgdotjs/svg.js';
3
3
  import { NumericValue } from './objects/ParamDefinition.js';
4
4
  import { PinTypes } from './objects/PinTypes.js';
5
+ import { SimplePoint } from './draw_symbols.js';
5
6
  export type Segment = Flatten.Segment;
6
7
  export type Polygon = Flatten.Polygon;
7
8
  export type Multiline = Flatten.Multiline;
@@ -76,7 +77,8 @@ export declare class Geometry {
76
77
  y: NumericValue;
77
78
  }[][]): {
78
79
  intersectPoints: WirePointCount[];
79
- segments: [x: number, y: number][][];
80
+ segments: SimplePoint[][];
81
+ lines: SimplePoint[][];
80
82
  };
81
83
  }
82
84
  type WirePointCount = [x: number, y: number, count: number];
@@ -80,7 +80,8 @@ export declare enum ReferenceTypes {
80
80
  value = "value",
81
81
  variable = "variable",
82
82
  instance = "instance",
83
- pinType = "pinType"
83
+ pinType = "pinType",
84
+ unknown = "unknown"
84
85
  }
85
86
  export declare enum BlockTypes {
86
87
  Branch = 1,
@@ -90,8 +91,10 @@ export declare enum BlockTypes {
90
91
  }
91
92
  export declare enum NetGraphicsParams {
92
93
  Color = "color",
93
- Highight = "highlight",
94
- LineWidth = "lineWidth"
94
+ LineWidth = "lineWidth",
95
+ Highlight = "highlight",
96
+ HighlightWidth = "highlightWidth",
97
+ HighlightOpacity = "highlightOpacity"
95
98
  }
96
99
  export declare enum FrameType {
97
100
  Frame = 1,
@@ -107,3 +110,4 @@ export declare const RenderFlags: {
107
110
  ShowLabelOrigin: boolean;
108
111
  };
109
112
  export declare const SymbolValidatorContext = "_sym";
113
+ export declare const TrailerArrayIndex = "index";
@@ -0,0 +1,28 @@
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
+ export declare class NetGraph {
10
+ logger: Logger;
11
+ constructor(logger: Logger);
12
+ generateLayoutGraph(sequence: SequenceItem[], nets: [ClassComponent, pin: number, net: Net][]): {
13
+ graph: Graph;
14
+ containerFrames: RenderFrame[];
15
+ };
16
+ private setGraphEdge;
17
+ protected print(...params: any[]): void;
18
+ generateNetGraph(nets: ComponentPinNetPair[]): void;
19
+ findNodePaths(graph: Graph, startNode: string, endNode: string, seenNodes?: string[]): string[][];
20
+ private getNetNodeName;
21
+ private getComponentName;
22
+ }
23
+ export declare function getWireName(wireId: number): string;
24
+ export declare function generateLayoutPinDefinition(component: ClassComponent): SymbolPinDefintion[];
25
+ export declare enum RenderItemType {
26
+ Wire = "wire",
27
+ Component = "component"
28
+ }
@@ -1,7 +1,6 @@
1
1
  import { Graph } from '@dagrejs/graphlib';
2
- import { SymbolGraphic, SymbolText, SymbolDrawingCommands } from "./draw_symbols.js";
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';
@@ -14,13 +13,13 @@ export declare class LayoutEngine {
14
13
  logger: Logger;
15
14
  layoutWarnings: string[];
16
15
  showBaseFrame: boolean;
17
- constructor(options?: {
16
+ constructor(logger: Logger, options?: {
18
17
  showBaseFrame: boolean;
19
18
  });
20
19
  protected print(...params: any[]): void;
21
20
  protected printLevel(level: number, ...params: any[]): void;
22
21
  protected padLevel(value: number): string;
23
- runLayout(sequence: SequenceItem[], nets: ComponentPinNetPair[]): SheetFrame[];
22
+ runLayout(graph: Graph, containerFrames: RenderFrame[], nets: ComponentPinNetPair[]): SheetFrame[];
24
23
  private collectRenderNets;
25
24
  private flattenFrameItems;
26
25
  private findJunctions;
@@ -31,11 +30,6 @@ export declare class LayoutEngine {
31
30
  dumpFrame(frame: RenderFrame, level?: number): void;
32
31
  private prepareFrames;
33
32
  private checkAddFrameTitle;
34
- generateLayoutGraph(sequence: SequenceItem[], nets: [ClassComponent, pin: number, net: Net][]): {
35
- graph: Graph;
36
- containerFrames: RenderFrame[];
37
- };
38
- private setGraphEdge;
39
33
  private sizeSubGraphs;
40
34
  private walkAndPlaceGraph;
41
35
  private placeSubgraphV2;
@@ -61,6 +55,7 @@ export type RenderNet = {
61
55
  lineWidth?: number;
62
56
  highlight?: string;
63
57
  highlightOpacity?: number;
58
+ highlightWidth?: number;
64
59
  };
65
60
  export declare class RenderWire extends RenderObject {
66
61
  id: number;
@@ -85,9 +80,10 @@ export declare class RenderWire extends RenderObject {
85
80
  }
86
81
  export type MergedWire = {
87
82
  netName: string;
88
- segments: [x: number, y: number][][];
83
+ segments: SimplePoint[][];
89
84
  intersectPoints: [x: number, y: number, count: number][];
90
85
  net: RenderNet;
86
+ lines?: SimplePoint[][];
91
87
  };
92
88
  export declare class RenderComponent extends RenderObject {
93
89
  component: ClassComponent;
@@ -1,6 +1,6 @@
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';
@@ -12,7 +12,7 @@ export declare class ExecutionScope {
12
12
  scopeId: number;
13
13
  private nets;
14
14
  instances: Map<string, ClassComponent>;
15
- functions: Map<string, CFunction>;
15
+ functions: Map<string, CFunctionEntry>;
16
16
  variables: Map<string, ValueType | ClassComponent>;
17
17
  symbols: Map<string, {
18
18
  type: ParseSymbolType;
@@ -33,7 +33,7 @@ export declare class ExecutionScope {
33
33
  componentRoot: ClassComponent | null;
34
34
  copyIDs: Map<string, number>;
35
35
  sequence: SequenceItem[];
36
- constructor(scopeId: number);
36
+ private constructor();
37
37
  static scopeId: number;
38
38
  static create(): ExecutionScope;
39
39
  private findNet;
@@ -1,10 +1,18 @@
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
7
  export type CFunction = (args: CallableParameter[], options?: CFunctionOptions) => CFunctionResult;
8
+ export declare class CFunctionEntry {
9
+ name: string;
10
+ execute: CFunction;
11
+ uniqueId?: string;
12
+ source?: ParserRuleContext;
13
+ constructor(name: string, execute: CFunction, source?: ParserRuleContext, uniqueId?: string);
14
+ toString(): string;
15
+ }
8
16
  export type CFunctionOptions = {
9
17
  netNamespace?: string;
10
18
  };
@@ -50,20 +58,22 @@ export type FunctionDefinedParameter = [
50
58
  export declare class AnyReference {
51
59
  found: boolean;
52
60
  name?: string;
53
- trailers: string[];
54
- type?: ReferenceTypes;
61
+ trailers: (string | ['index', number])[];
62
+ type: ReferenceTypes;
55
63
  value?: any;
56
64
  parentValue?: any;
65
+ referenceName: string;
57
66
  constructor(refType: {
58
67
  found: boolean;
59
68
  name?: string;
60
- trailers?: string[];
69
+ trailers?: (string | ['index', number])[];
61
70
  type?: ReferenceTypes;
62
71
  value?: any;
63
72
  parentValue?: any;
64
73
  });
74
+ toString(): string;
65
75
  }
66
- export declare class UndeclaredReference {
76
+ export declare class UndeclaredReference extends AnyReference {
67
77
  reference: AnyReference;
68
78
  constructor(reference: AnyReference);
69
79
  throwMessage(): string;
@@ -71,7 +81,7 @@ export declare class UndeclaredReference {
71
81
  nameString(): string;
72
82
  }
73
83
  export declare class DeclaredReference extends AnyReference {
74
- toString(): string;
84
+ referenceName: string;
75
85
  toDisplayString(): string;
76
86
  }
77
87
  export declare enum ParseSymbolType {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "circuitscript",
3
- "version": "0.1.14",
3
+ "version": "0.1.16",
4
4
  "description": "Interpreter for the circuitscript language",
5
5
  "homepage": "https://circuitscript.net",
6
6
  "engines": {