circuitscript 0.1.0 → 0.1.2
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.
- package/dist/cjs/BaseVisitor.js +13 -8
- package/dist/cjs/antlr/CircuitScriptLexer.js +80 -80
- package/dist/cjs/antlr/CircuitScriptParser.js +599 -657
- package/dist/cjs/builtinMethods.js +27 -8
- package/dist/cjs/draw_symbols.js +314 -190
- package/dist/cjs/execute.js +113 -115
- package/dist/cjs/export.js +2 -4
- package/dist/cjs/geometry.js +52 -19
- package/dist/cjs/globals.js +12 -8
- package/dist/cjs/helpers.js +16 -3
- package/dist/cjs/layout.js +129 -125
- package/dist/cjs/logger.js +8 -1
- package/dist/cjs/objects/ClassComponent.js +22 -22
- package/dist/cjs/objects/ExecutionScope.js +10 -4
- package/dist/cjs/objects/Frame.js +2 -1
- package/dist/cjs/objects/ParamDefinition.js +120 -4
- package/dist/cjs/objects/PinDefinition.js +1 -4
- package/dist/cjs/render.js +40 -110
- package/dist/cjs/sizing.js +33 -7
- package/dist/cjs/utils.js +68 -2
- package/dist/cjs/visitor.js +214 -254
- package/dist/esm/BaseVisitor.mjs +15 -10
- package/dist/esm/antlr/CircuitScriptLexer.mjs +80 -80
- package/dist/esm/antlr/CircuitScriptParser.mjs +599 -657
- package/dist/esm/builtinMethods.mjs +24 -8
- package/dist/esm/draw_symbols.mjs +316 -193
- package/dist/esm/execute.mjs +115 -117
- package/dist/esm/export.mjs +2 -4
- package/dist/esm/geometry.mjs +52 -19
- package/dist/esm/globals.mjs +12 -8
- package/dist/esm/helpers.mjs +17 -4
- package/dist/esm/layout.mjs +131 -127
- package/dist/esm/logger.mjs +8 -1
- package/dist/esm/objects/ClassComponent.mjs +21 -26
- package/dist/esm/objects/ExecutionScope.mjs +10 -4
- package/dist/esm/objects/Frame.mjs +2 -1
- package/dist/esm/objects/ParamDefinition.mjs +119 -3
- package/dist/esm/objects/PinDefinition.mjs +0 -2
- package/dist/esm/render.mjs +42 -112
- package/dist/esm/sizing.mjs +34 -8
- package/dist/esm/utils.mjs +64 -1
- package/dist/esm/visitor.mjs +216 -256
- package/dist/types/BaseVisitor.d.ts +1 -1
- package/dist/types/antlr/CircuitScriptParser.d.ts +2 -3
- package/dist/types/draw_symbols.d.ts +71 -45
- package/dist/types/execute.d.ts +15 -10
- package/dist/types/geometry.d.ts +31 -19
- package/dist/types/globals.d.ts +14 -10
- package/dist/types/helpers.d.ts +2 -1
- package/dist/types/layout.d.ts +21 -21
- package/dist/types/logger.d.ts +1 -1
- package/dist/types/objects/ClassComponent.d.ts +19 -16
- package/dist/types/objects/ExecutionScope.d.ts +2 -1
- package/dist/types/objects/Frame.d.ts +2 -2
- package/dist/types/objects/ParamDefinition.d.ts +31 -2
- package/dist/types/objects/PinDefinition.d.ts +0 -2
- package/dist/types/render.d.ts +2 -1
- package/dist/types/utils.d.ts +6 -1
- package/dist/types/visitor.d.ts +4 -5
- package/libs/lib.cst +15 -3
- package/package.json +7 -3
|
@@ -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 '
|
|
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,
|
|
20
|
-
displayProp:
|
|
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
|
-
|
|
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
|
|
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
|
+
}
|
|
@@ -36,7 +36,7 @@ export declare class 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,9 @@
|
|
|
1
|
-
import { FrameType } from "
|
|
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
|
|
6
|
+
constructor(frameId: number, frameType?: FrameType);
|
|
7
7
|
}
|
|
8
8
|
export declare enum FrameParamKeys {
|
|
9
9
|
Title = "title",
|
|
@@ -1,16 +1,45 @@
|
|
|
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
|
-
|
|
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
|
+
mul(value: NumericValue | number): NumericValue;
|
|
18
|
+
add(value: NumericValue | number): NumericValue;
|
|
19
|
+
sub(value: NumericValue | number): NumericValue;
|
|
20
|
+
mod(value: NumericValue | number): NumericValue;
|
|
21
|
+
neg(): NumericValue;
|
|
22
|
+
eq(value: NumericValue): boolean;
|
|
11
23
|
}
|
|
24
|
+
export declare function numeric(value: number): NumericValue;
|
|
12
25
|
export declare class PercentageValue {
|
|
13
26
|
value: string | number;
|
|
14
27
|
constructor(value: string | number);
|
|
15
28
|
toString(): string;
|
|
29
|
+
toNumber(): number;
|
|
30
|
+
}
|
|
31
|
+
export declare class WrappedNumber {
|
|
32
|
+
value: number;
|
|
33
|
+
constructor(value: number);
|
|
34
|
+
toString(): string;
|
|
35
|
+
toNumber(): number;
|
|
36
|
+
}
|
|
37
|
+
export type NumberOperatorType = NumericValue | PercentageValue | WrappedNumber;
|
|
38
|
+
export declare class NumberOperator {
|
|
39
|
+
prepare(value: number | NumberOperatorType): NumberOperatorType;
|
|
40
|
+
multiply(value1: NumberOperatorType, value2: NumberOperatorType): NumberOperatorType;
|
|
41
|
+
divide(value1: NumberOperatorType, value2: NumberOperatorType): NumberOperatorType;
|
|
42
|
+
addition(value1: NumberOperatorType, value2: NumberOperatorType): NumberOperatorType;
|
|
43
|
+
subtraction(value1: NumberOperatorType, value2: NumberOperatorType): NumberOperatorType;
|
|
44
|
+
modulus(value1: NumberOperatorType, value2: NumberOperatorType): NumberOperatorType;
|
|
16
45
|
}
|
package/dist/types/render.d.ts
CHANGED
|
@@ -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
|
-
|
|
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;
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -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();
|
|
@@ -20,6 +22,9 @@ export declare function getBoundsSize(bounds: BoundBox): {
|
|
|
20
22
|
height: number;
|
|
21
23
|
};
|
|
22
24
|
export declare function getPortType(component: ClassComponent): string | null;
|
|
23
|
-
export declare function roundValue(value:
|
|
25
|
+
export declare function roundValue(value: NumericValue): NumericValue;
|
|
24
26
|
export declare function throwWithContext(context: ParserRuleContext, message: string): void;
|
|
25
27
|
export declare function combineMaps(map1: Map<string, any>, map2: Map<string, any>): Map<string, any>;
|
|
28
|
+
export declare function getNumberExponential(value: string): number;
|
|
29
|
+
export declare function getNumberExponentialText(value: number): string;
|
|
30
|
+
export declare function resolveToNumericValue(value: Big): NumericValue;
|
package/dist/types/visitor.d.ts
CHANGED
|
@@ -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:
|
|
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: "
|
|
40
|
+
type: "net"
|
|
41
41
|
params:
|
|
42
42
|
net_name: value
|
|
43
43
|
value: value
|
|
@@ -68,7 +68,7 @@ def res(value):
|
|
|
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,
|
|
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,7 +271,7 @@ 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: "
|
|
274
|
+
type: "graphic"
|
|
263
275
|
display: create graphic (params):
|
|
264
276
|
fill: "none"
|
|
265
277
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "circuitscript",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
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"
|