circuitscript 0.1.3 → 0.1.5
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 +27 -12
- package/dist/cjs/builtinMethods.js +22 -0
- package/dist/cjs/draw_symbols.js +4 -1
- package/dist/cjs/execute.js +45 -34
- package/dist/cjs/globals.js +4 -2
- package/dist/cjs/helpers.js +13 -29
- package/dist/cjs/layout.js +3 -3
- package/dist/cjs/main.js +3 -2
- package/dist/cjs/objects/ClassComponent.js +4 -1
- package/dist/cjs/objects/ExecutionScope.js +7 -2
- package/dist/cjs/sizing.js +5 -2
- package/dist/cjs/utils.js +77 -1
- package/dist/cjs/visitor.js +9 -7
- package/dist/esm/BaseVisitor.mjs +28 -13
- package/dist/esm/builtinMethods.mjs +22 -0
- package/dist/esm/draw_symbols.mjs +4 -1
- package/dist/esm/execute.mjs +47 -35
- package/dist/esm/globals.mjs +3 -1
- package/dist/esm/helpers.mjs +15 -31
- package/dist/esm/layout.mjs +3 -3
- package/dist/esm/main.mjs +3 -2
- package/dist/esm/objects/ClassComponent.mjs +4 -1
- package/dist/esm/objects/ExecutionScope.mjs +7 -2
- package/dist/esm/sizing.mjs +5 -2
- package/dist/esm/utils.mjs +73 -0
- package/dist/esm/visitor.mjs +10 -8
- package/dist/types/BaseVisitor.d.ts +2 -1
- package/dist/types/draw_symbols.d.ts +2 -6
- package/dist/types/execute.d.ts +2 -3
- package/dist/types/globals.d.ts +3 -1
- package/dist/types/objects/ClassComponent.d.ts +1 -3
- package/dist/types/objects/ExecutionScope.d.ts +9 -6
- package/dist/types/utils.d.ts +5 -0
- package/libs/lib.cst +12 -22
- package/package.json +2 -2
package/dist/esm/utils.mjs
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { Big } from 'big.js';
|
|
2
|
+
import { ClassComponent } from "./objects/ClassComponent";
|
|
2
3
|
import { NumericValue } from "./objects/ParamDefinition";
|
|
4
|
+
import { SequenceAction } from './objects/ExecutionScope';
|
|
5
|
+
import { BlockTypes } from './globals';
|
|
3
6
|
export class SimpleStopwatch {
|
|
4
7
|
startTime;
|
|
5
8
|
constructor() {
|
|
@@ -167,3 +170,73 @@ export function areasOverlap(area1, area2) {
|
|
|
167
170
|
|| isPointWithinArea(pt3, area2)
|
|
168
171
|
|| isPointWithinArea(pt4, area2);
|
|
169
172
|
}
|
|
173
|
+
export function sequenceActionString(sequenceAction) {
|
|
174
|
+
const tmp = [...sequenceAction];
|
|
175
|
+
const action = tmp[0];
|
|
176
|
+
if (action === SequenceAction.Wire) {
|
|
177
|
+
tmp[2] = tmp[2].map(item2 => {
|
|
178
|
+
const lengthValue = item2.value;
|
|
179
|
+
const useValue = [item2.direction];
|
|
180
|
+
if (lengthValue !== null) {
|
|
181
|
+
useValue.push(lengthValue.value);
|
|
182
|
+
useValue.push(lengthValue.type);
|
|
183
|
+
}
|
|
184
|
+
return useValue.join(",");
|
|
185
|
+
}).join(" ");
|
|
186
|
+
}
|
|
187
|
+
else if (action === SequenceAction.Frame) {
|
|
188
|
+
tmp[1] = sequenceAction[1].frameId;
|
|
189
|
+
}
|
|
190
|
+
else if (action !== SequenceAction.WireJump) {
|
|
191
|
+
const [, component] = sequenceAction;
|
|
192
|
+
if (component instanceof ClassComponent) {
|
|
193
|
+
tmp[1] = sequenceAction[1].instanceName;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return tmp.join(" | ");
|
|
197
|
+
}
|
|
198
|
+
export function generateDebugSequenceAction(sequence) {
|
|
199
|
+
const variableMapping = new Map();
|
|
200
|
+
return sequence.map(item => {
|
|
201
|
+
const returnResult = [...item];
|
|
202
|
+
const [action,] = item;
|
|
203
|
+
if (action === SequenceAction.Assign) {
|
|
204
|
+
const [, name, component] = item;
|
|
205
|
+
variableMapping.set(name, component);
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
if (action === SequenceAction.At || action === SequenceAction.To) {
|
|
209
|
+
const [, component,] = item;
|
|
210
|
+
const foundIndex = Array.from(variableMapping.values()).findIndex(item2 => {
|
|
211
|
+
if (component._copyFrom !== null) {
|
|
212
|
+
return component._copyFrom === item2;
|
|
213
|
+
}
|
|
214
|
+
return component === item2;
|
|
215
|
+
});
|
|
216
|
+
if (foundIndex !== -1) {
|
|
217
|
+
const name = Array.from(variableMapping.keys())[foundIndex];
|
|
218
|
+
returnResult[1] = name + ':' + component._copyID;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return returnResult;
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
export function getBlockTypeString(type) {
|
|
226
|
+
let returnValue = 'branch';
|
|
227
|
+
switch (type) {
|
|
228
|
+
case BlockTypes.Branch:
|
|
229
|
+
returnValue = 'branch';
|
|
230
|
+
break;
|
|
231
|
+
case BlockTypes.Join:
|
|
232
|
+
returnValue = 'join';
|
|
233
|
+
break;
|
|
234
|
+
case BlockTypes.Parallel:
|
|
235
|
+
returnValue = 'parallel';
|
|
236
|
+
break;
|
|
237
|
+
case BlockTypes.Point:
|
|
238
|
+
returnValue = 'point';
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
return returnValue;
|
|
242
|
+
}
|
package/dist/esm/visitor.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { NumberOperator, numeric, NumericValue, ParamDefinition } from './object
|
|
|
3
3
|
import { PinDefinition, PinIdType } from './objects/PinDefinition.mjs';
|
|
4
4
|
import { PinTypes } from './objects/PinTypes.mjs';
|
|
5
5
|
import { DeclaredReference, UndeclaredReference } from './objects/types.mjs';
|
|
6
|
-
import { BlockTypes, ComponentTypes, FrameType, GlobalDocumentName, ModuleContainsKeyword, NoNetText, ParamKeys, ReferenceTypes, SymbolPinSide, WireAutoDirection } from './globals.mjs';
|
|
6
|
+
import { BlockTypes, ComponentTypes, Delimiter1, FrameType, GlobalDocumentName, ModuleContainsKeyword, NoNetText, ParamKeys, ReferenceTypes, SymbolPinSide, WireAutoDirection } from './globals.mjs';
|
|
7
7
|
import { PlaceHolderCommands, SymbolDrawingCommands } from './draw_symbols.mjs';
|
|
8
8
|
import { BaseVisitor } from './BaseVisitor.mjs';
|
|
9
9
|
import { getPortType } from './utils.mjs';
|
|
@@ -118,7 +118,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
118
118
|
if (paramValue instanceof NumericValue) {
|
|
119
119
|
appendValue = paramValue.value;
|
|
120
120
|
}
|
|
121
|
-
instanceName +=
|
|
121
|
+
instanceName += `${Delimiter1}${appendValue}`;
|
|
122
122
|
}
|
|
123
123
|
const arrange = properties.has('arrange') ?
|
|
124
124
|
properties.get('arrange') : null;
|
|
@@ -446,15 +446,15 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
446
446
|
expandModuleContains(component, netNamespace) {
|
|
447
447
|
this.getExecutor().log('expanding module `contains`');
|
|
448
448
|
const executionStack = this.executionStack;
|
|
449
|
-
const resolveNet = this.createNetResolver(executionStack);
|
|
450
449
|
const executor = this.getExecutor();
|
|
451
|
-
const executionContextName = executor.namespace +
|
|
450
|
+
const executionContextName = executor.namespace + Delimiter1
|
|
452
451
|
+ component.instanceName
|
|
453
|
-
+
|
|
454
|
-
const tmpNamespace = this.getNetNamespace(netNamespace, "+/" + component.instanceName +
|
|
452
|
+
+ Delimiter1 + component.moduleCounter;
|
|
453
|
+
const tmpNamespace = this.getNetNamespace(netNamespace, "+/" + component.instanceName + Delimiter1 + component.moduleCounter);
|
|
455
454
|
const newExecutor = this.enterNewChildContext(executionStack, executor, executionContextName, { netNamespace: tmpNamespace }, [], []);
|
|
456
455
|
component.moduleCounter += 1;
|
|
457
|
-
newExecutor.resolveNet =
|
|
456
|
+
newExecutor.resolveNet = this.createNetResolver(executionStack);
|
|
457
|
+
newExecutor.resolveComponentPinNet = this.createComponentPinNetResolver(executionStack);
|
|
458
458
|
this.visit(component.moduleContainsExpressions);
|
|
459
459
|
const executionContext = executionStack.pop();
|
|
460
460
|
component.moduleExecutionContext = executionContext;
|
|
@@ -659,11 +659,13 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
659
659
|
const executionStack = this.executionStack;
|
|
660
660
|
const functionCounter = { counter: 0 };
|
|
661
661
|
const resolveNet = this.createNetResolver(this.executionStack);
|
|
662
|
+
const resolveComponentPinNet = this.createComponentPinNetResolver(this.executionStack);
|
|
662
663
|
const __runFunc = (passedInParameters, options) => {
|
|
663
|
-
const executionContextName = functionName
|
|
664
|
+
const executionContextName = `${functionName}-${functionCounter['counter']}`;
|
|
664
665
|
const newExecutor = this.enterNewChildContext(executionStack, this.getExecutor(), executionContextName, options, funcDefinedParameters, passedInParameters);
|
|
665
666
|
functionCounter['counter'] += 1;
|
|
666
667
|
newExecutor.resolveNet = resolveNet;
|
|
668
|
+
newExecutor.resolveComponentPinNet = resolveComponentPinNet;
|
|
667
669
|
const returnValue = this.runExpressions(newExecutor, ctx.function_expr());
|
|
668
670
|
const lastExecution = executionStack.pop();
|
|
669
671
|
const nextLastExecution = executionStack[executionStack.length - 1];
|
|
@@ -27,11 +27,12 @@ export declare class BaseVisitor extends CircuitScriptVisitor<ComplexType | Refe
|
|
|
27
27
|
};
|
|
28
28
|
constructor(silent: boolean | undefined, onErrorHandler: OnErrorCallback | null | undefined, currentDirectory: string | null, defaultLibsPath: string);
|
|
29
29
|
getExecutor(): ExecutionContext;
|
|
30
|
-
protected
|
|
30
|
+
protected setupBuiltInFunctions(context: ExecutionContext): void;
|
|
31
31
|
createNetResolver(executionStack: ExecutionContext[]): (netName: string, netNamespace: string) => {
|
|
32
32
|
found: boolean;
|
|
33
33
|
net?: Net;
|
|
34
34
|
};
|
|
35
|
+
createComponentPinNetResolver(executionStack: ExecutionContext[]): (component: ClassComponent, pin: number) => Net | null;
|
|
35
36
|
log(...params: any[]): void;
|
|
36
37
|
log2(message: string): void;
|
|
37
38
|
visitScript: (ctx: ScriptContext) => void;
|
|
@@ -101,12 +101,8 @@ export declare class SymbolCustom extends SymbolGraphic {
|
|
|
101
101
|
_cacheRightPins: SymbolPinDefintion[];
|
|
102
102
|
_cacheTopPins: SymbolPinDefintion[];
|
|
103
103
|
_cacheBottomPins: SymbolPinDefintion[];
|
|
104
|
-
pinMaxPositions:
|
|
105
|
-
|
|
106
|
-
};
|
|
107
|
-
constructor(pinDefinition: SymbolPinDefintion[], pinMaxPositions: {
|
|
108
|
-
[key: string]: number;
|
|
109
|
-
});
|
|
104
|
+
pinMaxPositions: Map<string, number>;
|
|
105
|
+
constructor(pinDefinition: SymbolPinDefintion[], pinMaxPositions: Map<string, number>);
|
|
110
106
|
generateDrawing(): void;
|
|
111
107
|
private getPins;
|
|
112
108
|
generateDrawingPins(drawing: SymbolDrawing, bodyWidthMM: NumericValue, bodyHeightMM: NumericValue, pins: {
|
package/dist/types/execute.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export declare class ExecutionContext {
|
|
|
20
20
|
found: boolean;
|
|
21
21
|
net?: Net;
|
|
22
22
|
});
|
|
23
|
+
resolveComponentPinNet: (component: ClassComponent, pin: number) => Net | null;
|
|
23
24
|
stopFurtherExpressions: boolean;
|
|
24
25
|
returnValue: null;
|
|
25
26
|
silent: boolean;
|
|
@@ -80,9 +81,7 @@ export declare class ExecutionContext {
|
|
|
80
81
|
}
|
|
81
82
|
export declare function getPortSide(pins: Map<number, PinDefinition>, arrangeProps: null | Map<string, number[]>): {
|
|
82
83
|
pins: PortSideItem[];
|
|
83
|
-
maxPositions:
|
|
84
|
-
[key: string]: number;
|
|
85
|
-
};
|
|
84
|
+
maxPositions: Map<string, number>;
|
|
86
85
|
};
|
|
87
86
|
type PortSideItem = {
|
|
88
87
|
pinId: number;
|
package/dist/types/globals.d.ts
CHANGED
|
@@ -12,9 +12,7 @@ export declare class ClassComponent {
|
|
|
12
12
|
pins: Map<number, PinDefinition>;
|
|
13
13
|
pinNets: Map<number, Net>;
|
|
14
14
|
pinWires: Map<number, WireSegment[]>;
|
|
15
|
-
pinsMaxPositions:
|
|
16
|
-
[key: string]: number;
|
|
17
|
-
};
|
|
15
|
+
pinsMaxPositions: Map<string, number>;
|
|
18
16
|
_cachedPins: string;
|
|
19
17
|
_cachedParams: string;
|
|
20
18
|
_copyID?: number;
|
|
@@ -25,8 +25,6 @@ export declare class ExecutionScope {
|
|
|
25
25
|
currentPin: number | null;
|
|
26
26
|
currentWireId: number;
|
|
27
27
|
currentFrameId: number;
|
|
28
|
-
netGnd: Net | null;
|
|
29
|
-
componentGnd: ClassComponent | null;
|
|
30
28
|
componentRoot: ClassComponent | null;
|
|
31
29
|
copyIDs: Map<string, number>;
|
|
32
30
|
sequence: SequenceItem[];
|
|
@@ -35,6 +33,7 @@ export declare class ExecutionScope {
|
|
|
35
33
|
static create(): ExecutionScope;
|
|
36
34
|
private findNet;
|
|
37
35
|
getNetWithName(name: string): Net;
|
|
36
|
+
getNetWithNamespacePath(namespace: string, name: string): Net | null;
|
|
38
37
|
hasNet(component: ClassComponent, pin: number): boolean;
|
|
39
38
|
getNet(component: ClassComponent, pin: number): Net | null;
|
|
40
39
|
setNet(component: ClassComponent, pin: number, net: Net): void;
|
|
@@ -51,7 +50,8 @@ export declare enum SequenceAction {
|
|
|
51
50
|
At = "at",
|
|
52
51
|
Wire = "wire",
|
|
53
52
|
WireJump = "wire-jump",
|
|
54
|
-
Frame = "frame"
|
|
53
|
+
Frame = "frame",
|
|
54
|
+
Assign = "assign"
|
|
55
55
|
}
|
|
56
56
|
export declare enum FrameAction {
|
|
57
57
|
Enter = "enter",
|
|
@@ -61,10 +61,13 @@ export declare enum ActiveObject {
|
|
|
61
61
|
Frame = "frame",
|
|
62
62
|
Wire = "wire"
|
|
63
63
|
}
|
|
64
|
-
export type
|
|
64
|
+
export type SequenceActionAtTo = [
|
|
65
65
|
SequenceAction.To | SequenceAction.At,
|
|
66
66
|
ClassComponent,
|
|
67
|
-
number,
|
|
67
|
+
pinId: number,
|
|
68
68
|
LayoutDirection?,
|
|
69
69
|
string?
|
|
70
|
-
]
|
|
70
|
+
];
|
|
71
|
+
export type SequenceActionWire = [SequenceAction.Wire, wireId: number, WireSegment[]];
|
|
72
|
+
export type SequenceActionAssign = [SequenceAction.Assign, variable: string, ClassComponent];
|
|
73
|
+
export type SequenceItem = SequenceActionAtTo | SequenceActionWire | [SequenceAction.WireJump, wireId: number, pinId: number] | [SequenceAction.Frame, Frame, "enter" | "exit"] | SequenceActionAssign;
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { Big } from 'big.js';
|
|
|
2
2
|
import { ParserRuleContext } from "antlr4ng";
|
|
3
3
|
import { ClassComponent } from "./objects/ClassComponent";
|
|
4
4
|
import { NumericValue } from "./objects/ParamDefinition";
|
|
5
|
+
import { SequenceAction, SequenceItem } from './objects/ExecutionScope';
|
|
6
|
+
import { BlockTypes } from './globals';
|
|
5
7
|
export declare class SimpleStopwatch {
|
|
6
8
|
startTime: Date;
|
|
7
9
|
constructor();
|
|
@@ -36,3 +38,6 @@ export declare function getNumberExponentialText(value: number): string;
|
|
|
36
38
|
export declare function resolveToNumericValue(value: Big): NumericValue;
|
|
37
39
|
export declare function isPointWithinArea(point: [x: number, y: number], bounds: BoundBox2): boolean;
|
|
38
40
|
export declare function areasOverlap(area1: BoundBox2, area2: BoundBox2): boolean;
|
|
41
|
+
export declare function sequenceActionString(sequenceAction: SequenceAction): string;
|
|
42
|
+
export declare function generateDebugSequenceAction(sequence: SequenceItem[]): string[];
|
|
43
|
+
export declare function getBlockTypeString(type: BlockTypes): string;
|
package/libs/lib.cst
CHANGED
|
@@ -15,18 +15,8 @@ def net(net_name):
|
|
|
15
15
|
priority: 10
|
|
16
16
|
|
|
17
17
|
def supply(net_name):
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
copy: true
|
|
21
|
-
angle: -90
|
|
22
|
-
display: create graphic (params):
|
|
23
|
-
hline: -50, 0, 100
|
|
24
|
-
vpin: 1, 0, 50, -50, display_pin_id=false
|
|
25
|
-
label: params.net_name, 0, -15, fontSize=50, anchor="middle"
|
|
26
|
-
type: "net"
|
|
27
|
-
params:
|
|
28
|
-
net_name: net_name
|
|
29
|
-
priority: 20
|
|
18
|
+
net_obj = net(net_name)
|
|
19
|
+
return net_obj
|
|
30
20
|
|
|
31
21
|
def label(value, anchor="left"):
|
|
32
22
|
return create component:
|
|
@@ -97,21 +87,21 @@ def cap(value):
|
|
|
97
87
|
footprint: "Capacitor_SMD:C_0402_1005Metric"
|
|
98
88
|
|
|
99
89
|
def ind(value):
|
|
100
|
-
width =
|
|
101
|
-
height =
|
|
90
|
+
width = 200
|
|
91
|
+
height = 100
|
|
102
92
|
|
|
103
93
|
return create component:
|
|
104
94
|
pins: 2
|
|
105
95
|
type: "ind"
|
|
106
96
|
display: create graphic (params):
|
|
107
|
-
arc: -
|
|
108
|
-
arc: -
|
|
109
|
-
arc:
|
|
110
|
-
arc:
|
|
111
|
-
hpin: 1, -width/2 -
|
|
112
|
-
hpin: 2, width/2 +
|
|
113
|
-
label: (params.refdes, -width/2, -height/2 -
|
|
114
|
-
label: (params.value, 0,
|
|
97
|
+
arc: -75, 0, 25, 180, 360
|
|
98
|
+
arc: -25, 0, 25, 180, 360
|
|
99
|
+
arc: 25, 0, 25, 180, 360
|
|
100
|
+
arc: 75, 0, 25, 180, 360
|
|
101
|
+
hpin: 1, -width/2 - 100, 0, 100
|
|
102
|
+
hpin: 2, width/2 + 100, 0, -100
|
|
103
|
+
label: (params.refdes, -width/2, -height/2 - 25 , fontSize=50, anchor="left")
|
|
104
|
+
label: (params.value, 0, 50, fontSize=50, anchor="middle", vanchor="middle")
|
|
115
105
|
params:
|
|
116
106
|
value: value
|
|
117
107
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "circuitscript",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Interpreter for the circuitscript language",
|
|
5
5
|
"homepage": "https://circuitscript.net",
|
|
6
6
|
"engines": {
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"lodash": "^4.17.21",
|
|
89
89
|
"pdfkit": "^0.15.1",
|
|
90
90
|
"svg-to-pdfkit": "^0.1.8",
|
|
91
|
-
"svgdom": "
|
|
91
|
+
"svgdom": "0.1.14",
|
|
92
92
|
"this-file": "^2.0.3",
|
|
93
93
|
"tslib": "~2.5",
|
|
94
94
|
"ws": "^8.14.2"
|