circuitscript 0.1.11 → 0.1.13
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 +147 -115
- package/dist/cjs/antlr/CircuitScriptParser.js +949 -932
- package/dist/cjs/builtinMethods.js +7 -1
- package/dist/cjs/execute.js +67 -35
- package/dist/cjs/globals.js +7 -1
- package/dist/cjs/helpers.js +11 -8
- package/dist/cjs/layout.js +50 -16
- package/dist/cjs/objects/ExecutionScope.js +3 -0
- package/dist/cjs/objects/Net.js +1 -0
- package/dist/cjs/objects/ParamDefinition.js +3 -0
- package/dist/cjs/objects/types.js +19 -10
- package/dist/cjs/parser.js +3 -1
- package/dist/cjs/render.js +48 -6
- package/dist/cjs/utils.js +16 -1
- package/dist/cjs/visitor.js +69 -52
- package/dist/esm/BaseVisitor.js +113 -81
- package/dist/esm/antlr/CircuitScriptParser.js +943 -926
- package/dist/esm/antlr/CircuitScriptVisitor.js +4 -4
- package/dist/esm/builtinMethods.js +8 -2
- package/dist/esm/execute.js +68 -36
- package/dist/esm/globals.js +6 -0
- package/dist/esm/helpers.js +11 -8
- package/dist/esm/layout.js +53 -17
- package/dist/esm/objects/ExecutionScope.js +3 -0
- package/dist/esm/objects/Net.js +1 -0
- package/dist/esm/objects/ParamDefinition.js +4 -1
- package/dist/esm/objects/types.js +21 -15
- package/dist/esm/parser.js +3 -1
- package/dist/esm/render.js +49 -7
- package/dist/esm/utils.js +13 -0
- package/dist/esm/visitor.js +57 -40
- package/dist/types/BaseVisitor.d.ts +5 -6
- package/dist/types/antlr/CircuitScriptParser.d.ts +58 -58
- package/dist/types/antlr/CircuitScriptVisitor.d.ts +8 -8
- package/dist/types/execute.d.ts +4 -2
- package/dist/types/globals.d.ts +5 -0
- package/dist/types/layout.d.ts +16 -3
- package/dist/types/objects/ExecutionScope.d.ts +15 -3
- package/dist/types/objects/Net.d.ts +1 -0
- package/dist/types/objects/types.d.ts +25 -18
- package/dist/types/parser.d.ts +1 -0
- package/dist/types/utils.d.ts +3 -1
- package/dist/types/visitor.d.ts +3 -2
- package/package.json +1 -1
- /package/dist/libs/{lib.cst → std.cst} +0 -0
- /package/libs/{lib.cst → std.cst} +0 -0
|
@@ -2,9 +2,11 @@ import { AbstractParseTreeVisitor } from "antlr4ng";
|
|
|
2
2
|
export class CircuitScriptVisitor extends AbstractParseTreeVisitor {
|
|
3
3
|
visitScript;
|
|
4
4
|
visitExpression;
|
|
5
|
+
visitFlow_expressions;
|
|
6
|
+
visitGraph_expressions;
|
|
7
|
+
visitGraph_linear_expression;
|
|
5
8
|
visitExpressions_block;
|
|
6
|
-
|
|
7
|
-
visitPath_block_inner;
|
|
9
|
+
visitPath_block;
|
|
8
10
|
visitProperty_set_expr2;
|
|
9
11
|
visitAssignment_expr2;
|
|
10
12
|
visitPin_select_expr;
|
|
@@ -23,8 +25,6 @@ export class CircuitScriptVisitor extends AbstractParseTreeVisitor {
|
|
|
23
25
|
visitAt_block_pin_expr;
|
|
24
26
|
visitAt_block_pin_expression_simple;
|
|
25
27
|
visitAt_block_pin_expression_complex;
|
|
26
|
-
visitBreak_keyword;
|
|
27
|
-
visitContinue_keyword;
|
|
28
28
|
visitAssignment_expr;
|
|
29
29
|
visitOperator_assignment_expr;
|
|
30
30
|
visitKeyword_assignment_expr;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Big from "big.js";
|
|
2
2
|
import { numeric, NumericValue } from "./objects/ParamDefinition.js";
|
|
3
|
-
import { resolveToNumericValue } from "./utils.js";
|
|
3
|
+
import { unwrapValue, resolveToNumericValue, RuntimeExecutionError } from "./utils.js";
|
|
4
4
|
const builtInMethods = [
|
|
5
5
|
['enumerate', enumerate],
|
|
6
6
|
['toMils', toMils],
|
|
@@ -15,7 +15,9 @@ export const buildInMethodNamesList = builtInMethods.map(item => item[0]);
|
|
|
15
15
|
export function linkBuiltInMethods(context, visitor) {
|
|
16
16
|
context.createFunction('print', (params) => {
|
|
17
17
|
const args = getPositionParams(params);
|
|
18
|
-
const items = args.map(item =>
|
|
18
|
+
const items = args.map(item => {
|
|
19
|
+
return toString(unwrapValue(item));
|
|
20
|
+
});
|
|
19
21
|
if (visitor.printToConsole) {
|
|
20
22
|
console.log('::', ...items);
|
|
21
23
|
}
|
|
@@ -75,6 +77,7 @@ function toMils(value) {
|
|
|
75
77
|
return resolveToNumericValue(bigValue);
|
|
76
78
|
}
|
|
77
79
|
function objectLength(obj) {
|
|
80
|
+
obj = unwrapValue(obj);
|
|
78
81
|
if (Array.isArray(obj)) {
|
|
79
82
|
return numeric(obj.length);
|
|
80
83
|
}
|
|
@@ -105,6 +108,9 @@ function arrayGet(arrayObject, index) {
|
|
|
105
108
|
else {
|
|
106
109
|
useValue = index;
|
|
107
110
|
}
|
|
111
|
+
if (isNaN(useValue)) {
|
|
112
|
+
throw new RuntimeExecutionError("Invalid index for arrayGet");
|
|
113
|
+
}
|
|
108
114
|
return arrayObject[useValue];
|
|
109
115
|
}
|
|
110
116
|
function arraySet(arrayObject, index, setValue) {
|
package/dist/esm/execute.js
CHANGED
|
@@ -4,7 +4,7 @@ import { ActiveObject, ExecutionScope, FrameAction, SequenceAction } from './obj
|
|
|
4
4
|
import { Net } from './objects/Net.js';
|
|
5
5
|
import { numeric, NumericValue } from './objects/ParamDefinition.js';
|
|
6
6
|
import { PortSide } from './objects/PinDefinition.js';
|
|
7
|
-
import { DeclaredReference, Direction } from './objects/types.js';
|
|
7
|
+
import { AnyReference, DeclaredReference, Direction } from './objects/types.js';
|
|
8
8
|
import { Wire } from './objects/Wire.js';
|
|
9
9
|
import { Frame } from './objects/Frame.js';
|
|
10
10
|
import { CalculatePinPositions } from './layout.js';
|
|
@@ -357,6 +357,10 @@ export class ExecutionContext {
|
|
|
357
357
|
}
|
|
358
358
|
}
|
|
359
359
|
this.scope.setCurrent(component, usePinId);
|
|
360
|
+
if (!this.scope.hasNet(component, pinId)) {
|
|
361
|
+
const tmpNet = new Net(this.netNamespace, this.getUniqueNetName());
|
|
362
|
+
this.scope.setNet(component, pinId, tmpNet);
|
|
363
|
+
}
|
|
360
364
|
this.scope.clearActive();
|
|
361
365
|
if (addSequence) {
|
|
362
366
|
this.scope.sequence.push([SequenceAction.At,
|
|
@@ -400,13 +404,14 @@ export class ExecutionContext {
|
|
|
400
404
|
this.tmpPointId += 1;
|
|
401
405
|
}
|
|
402
406
|
this.scope.blockStack.set(this.scope.indentLevel, {
|
|
403
|
-
|
|
407
|
+
start_point: [
|
|
404
408
|
this.scope.currentComponent,
|
|
405
409
|
this.scope.currentPin,
|
|
406
410
|
this.scope.currentWireId
|
|
407
411
|
],
|
|
412
|
+
end_point: null,
|
|
408
413
|
inner_blocks: new Map(),
|
|
409
|
-
current_index:
|
|
414
|
+
current_index: 0,
|
|
410
415
|
type: blockType,
|
|
411
416
|
});
|
|
412
417
|
this.log('enter blocks');
|
|
@@ -415,7 +420,7 @@ export class ExecutionContext {
|
|
|
415
420
|
const stackRef = this.scope.blockStack.get(this.scope.indentLevel);
|
|
416
421
|
const { type: blockType } = stackRef;
|
|
417
422
|
if (blockType === BlockTypes.Join || blockType === BlockTypes.Parallel) {
|
|
418
|
-
const {
|
|
423
|
+
const { end_point: finalPoint } = stackRef;
|
|
419
424
|
const [component, pin, wireId] = finalPoint;
|
|
420
425
|
this.scope.setCurrent(component, pin);
|
|
421
426
|
this.scope.currentWireId = wireId;
|
|
@@ -426,17 +431,22 @@ export class ExecutionContext {
|
|
|
426
431
|
}
|
|
427
432
|
}
|
|
428
433
|
else if (blockType === BlockTypes.Point) {
|
|
429
|
-
const {
|
|
434
|
+
const { start_point: [component, pin,] } = stackRef;
|
|
430
435
|
this.atComponent(component, pin, { addSequence: true });
|
|
431
436
|
}
|
|
437
|
+
this.scope.blockStack.delete(this.scope.indentLevel);
|
|
432
438
|
this.log('exit blocks');
|
|
433
439
|
}
|
|
440
|
+
closeAllBlocks() {
|
|
441
|
+
if (this.scope.blockStack.has(this.scope.indentLevel)) {
|
|
442
|
+
this.exitBlocks();
|
|
443
|
+
}
|
|
444
|
+
}
|
|
434
445
|
enterBlock(blockIndex) {
|
|
435
446
|
const stackRef = this.scope.blockStack.get(this.scope.indentLevel);
|
|
436
|
-
stackRef['block_index'] = blockIndex;
|
|
437
447
|
const { type: blockType } = stackRef;
|
|
438
448
|
const blockTypeName = getBlockTypeString(blockType);
|
|
439
|
-
stackRef
|
|
449
|
+
stackRef.inner_blocks.set(blockIndex, {
|
|
440
450
|
last_net: null,
|
|
441
451
|
ignore_last_net: false,
|
|
442
452
|
});
|
|
@@ -445,7 +455,7 @@ export class ExecutionContext {
|
|
|
445
455
|
this.scope.currentWireId = -1;
|
|
446
456
|
}
|
|
447
457
|
else if (blockType === BlockTypes.Parallel) {
|
|
448
|
-
const {
|
|
458
|
+
const { start_point: [component, pin,] } = stackRef;
|
|
449
459
|
this.atComponent(component, pin, { addSequence: true });
|
|
450
460
|
}
|
|
451
461
|
this.log(`enter inner block of type (${blockTypeName}) >>>`);
|
|
@@ -454,17 +464,16 @@ export class ExecutionContext {
|
|
|
454
464
|
exitBlock(blockIndex) {
|
|
455
465
|
const stackRef = this.scope.blockStack.get(this.scope.indentLevel - 1);
|
|
456
466
|
const { type: blockType } = stackRef;
|
|
457
|
-
const blockIndexRef = stackRef
|
|
458
|
-
blockIndexRef
|
|
467
|
+
const blockIndexRef = stackRef.inner_blocks.get(blockIndex);
|
|
468
|
+
blockIndexRef.last_net = [
|
|
459
469
|
this.scope.currentComponent,
|
|
460
470
|
this.scope.currentPin,
|
|
461
471
|
this.scope.currentWireId
|
|
462
472
|
];
|
|
463
|
-
stackRef['block_index'] = null;
|
|
464
473
|
this.scope.indentLevel -= 1;
|
|
465
474
|
this.log('exit inner block <<<');
|
|
466
475
|
if (blockType === BlockTypes.Branch) {
|
|
467
|
-
const {
|
|
476
|
+
const { start_point: [component, pin, wireId] } = stackRef;
|
|
468
477
|
this.atComponent(component, pin, { addSequence: true });
|
|
469
478
|
if (wireId !== -1) {
|
|
470
479
|
this.scope.sequence.push([SequenceAction.WireJump, wireId, 1]);
|
|
@@ -475,14 +484,14 @@ export class ExecutionContext {
|
|
|
475
484
|
const pointIdName = `${Delimiter1}${getBlockTypeString(blockType)}`;
|
|
476
485
|
this.addPoint(`${pointIdName}.${this.name}.${this.tmpPointId}`, false);
|
|
477
486
|
this.tmpPointId += 1;
|
|
478
|
-
stackRef
|
|
487
|
+
stackRef.end_point = [
|
|
479
488
|
this.scope.currentComponent,
|
|
480
489
|
this.scope.currentPin,
|
|
481
490
|
this.scope.currentWireId
|
|
482
491
|
];
|
|
483
492
|
}
|
|
484
493
|
else {
|
|
485
|
-
const {
|
|
494
|
+
const { end_point: finalPoint } = stackRef;
|
|
486
495
|
const [component, pin,] = finalPoint;
|
|
487
496
|
this.toComponent(component, pin, { addSequence: true });
|
|
488
497
|
}
|
|
@@ -504,10 +513,10 @@ export class ExecutionContext {
|
|
|
504
513
|
this.log('get block point');
|
|
505
514
|
for (let i = 0; i < this.scope.indentLevel; i++) {
|
|
506
515
|
const stackRef = this.scope.blockStack.get(this.scope.indentLevel - 1 - i);
|
|
507
|
-
const {
|
|
508
|
-
const component =
|
|
516
|
+
const { start_point } = stackRef;
|
|
517
|
+
const component = start_point[0];
|
|
509
518
|
if (component.instanceName.startsWith(`${Delimiter1}point.`)) {
|
|
510
|
-
return
|
|
519
|
+
return start_point;
|
|
511
520
|
}
|
|
512
521
|
}
|
|
513
522
|
this.log('did not find block point');
|
|
@@ -548,29 +557,23 @@ export class ExecutionContext {
|
|
|
548
557
|
});
|
|
549
558
|
}
|
|
550
559
|
else {
|
|
551
|
-
|
|
552
|
-
|
|
560
|
+
let isVariable = context.scope.variables.has(idName);
|
|
561
|
+
let isComponentInstance = context.scope.instances.has(idName);
|
|
553
562
|
if (isVariable || isComponentInstance) {
|
|
554
563
|
const scopeList = isVariable ? context.scope.variables
|
|
555
564
|
: context.scope.instances;
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
const trailersPath = trailers.join(".");
|
|
561
|
-
if (isVariable) {
|
|
562
|
-
useValue = parentValue[trailersPath];
|
|
563
|
-
}
|
|
564
|
-
else if (isComponentInstance) {
|
|
565
|
-
useValue = parentValue.parameters.get(trailersPath);
|
|
566
|
-
}
|
|
565
|
+
const useValue = scopeList.get(idName);
|
|
566
|
+
if (!isComponentInstance && (useValue instanceof ClassComponent)) {
|
|
567
|
+
isComponentInstance = true;
|
|
568
|
+
isVariable = false;
|
|
567
569
|
}
|
|
570
|
+
const tmpReference = this.resolveTrailers(isVariable ? ReferenceTypes.variable : ReferenceTypes.instance, useValue, trailers);
|
|
568
571
|
return new DeclaredReference({
|
|
569
572
|
type: isVariable ? ReferenceTypes.variable
|
|
570
573
|
: ReferenceTypes.instance,
|
|
571
|
-
found: (
|
|
572
|
-
parentValue,
|
|
573
|
-
value:
|
|
574
|
+
found: (tmpReference.value !== undefined),
|
|
575
|
+
parentValue: tmpReference.parentValue,
|
|
576
|
+
value: tmpReference.value,
|
|
574
577
|
name: idName,
|
|
575
578
|
trailers,
|
|
576
579
|
});
|
|
@@ -582,6 +585,37 @@ export class ExecutionContext {
|
|
|
582
585
|
name: idName,
|
|
583
586
|
});
|
|
584
587
|
}
|
|
588
|
+
resolveTrailers(type, item, trailers = []) {
|
|
589
|
+
let parentValue;
|
|
590
|
+
let useValue = item;
|
|
591
|
+
if (trailers.length > 0) {
|
|
592
|
+
parentValue = useValue;
|
|
593
|
+
const trailersPath = trailers.join(".");
|
|
594
|
+
if (type === ReferenceTypes.variable) {
|
|
595
|
+
useValue = parentValue[trailersPath];
|
|
596
|
+
}
|
|
597
|
+
else if (type === ReferenceTypes.instance) {
|
|
598
|
+
const tmpComponent = parentValue;
|
|
599
|
+
if (tmpComponent.typeProp === ComponentTypes.net) {
|
|
600
|
+
const usedNet = this.scope.getNet(tmpComponent, 1);
|
|
601
|
+
if (usedNet) {
|
|
602
|
+
const trailerValue = trailers.join(".");
|
|
603
|
+
useValue = usedNet.params.get(trailerValue) ?? null;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
else {
|
|
607
|
+
useValue = parentValue.parameters.get(trailersPath);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
return new AnyReference({
|
|
612
|
+
found: true,
|
|
613
|
+
type: type,
|
|
614
|
+
parentValue,
|
|
615
|
+
trailers,
|
|
616
|
+
value: useValue,
|
|
617
|
+
});
|
|
618
|
+
}
|
|
585
619
|
callFunction(functionName, functionParams, executionStack, netNamespace) {
|
|
586
620
|
let __runFunc = null;
|
|
587
621
|
if (this.__functionCache[functionName] === undefined) {
|
|
@@ -618,9 +652,7 @@ export class ExecutionContext {
|
|
|
618
652
|
}
|
|
619
653
|
mergeScope(childScope, namespace) {
|
|
620
654
|
this.log('-- merging scope to parent --');
|
|
621
|
-
const currentComponent = this.scope
|
|
622
|
-
const currentPin = this.scope.currentPin;
|
|
623
|
-
const currentWireId = this.scope.currentWireId;
|
|
655
|
+
const { currentComponent, currentPin, currentWireId } = this.scope;
|
|
624
656
|
const tmpInstances = childScope.instances;
|
|
625
657
|
const tmpNets = childScope.getNets();
|
|
626
658
|
for (const [instanceName, component] of tmpInstances) {
|
package/dist/esm/globals.js
CHANGED
|
@@ -100,6 +100,12 @@ export var BlockTypes;
|
|
|
100
100
|
BlockTypes[BlockTypes["Parallel"] = 3] = "Parallel";
|
|
101
101
|
BlockTypes[BlockTypes["Point"] = 4] = "Point";
|
|
102
102
|
})(BlockTypes || (BlockTypes = {}));
|
|
103
|
+
export var NetGraphicsParams;
|
|
104
|
+
(function (NetGraphicsParams) {
|
|
105
|
+
NetGraphicsParams["Color"] = "color";
|
|
106
|
+
NetGraphicsParams["Highight"] = "highlight";
|
|
107
|
+
NetGraphicsParams["LineWidth"] = "lineWidth";
|
|
108
|
+
})(NetGraphicsParams || (NetGraphicsParams = {}));
|
|
103
109
|
export var FrameType;
|
|
104
110
|
(function (FrameType) {
|
|
105
111
|
FrameType[FrameType["Frame"] = 1] = "Frame";
|
package/dist/esm/helpers.js
CHANGED
|
@@ -184,14 +184,6 @@ export async function renderScript(scriptData, outputPath, options) {
|
|
|
184
184
|
};
|
|
185
185
|
visitor.log('reading file');
|
|
186
186
|
visitor.log('done reading file');
|
|
187
|
-
const { tree, parser, parserTimeTaken, lexerTimeTaken } = await parseFileWithVisitor(visitor, scriptData);
|
|
188
|
-
printWarnings(visitor.getWarnings());
|
|
189
|
-
showStats && console.log('Lexing took:', lexerTimeTaken);
|
|
190
|
-
showStats && console.log('Parsing took:', parserTimeTaken);
|
|
191
|
-
if (dumpNets) {
|
|
192
|
-
const nets = visitor.dumpNets();
|
|
193
|
-
nets.forEach(item => console.log(item.join(" | ")));
|
|
194
|
-
}
|
|
195
187
|
const dumpDirectory = environment.getRelativeToModule('/dump/');
|
|
196
188
|
if (dumpData) {
|
|
197
189
|
console.log('Dump data to:', dumpDirectory);
|
|
@@ -199,8 +191,19 @@ export async function renderScript(scriptData, outputPath, options) {
|
|
|
199
191
|
mkdirSync(dumpDirectory);
|
|
200
192
|
}
|
|
201
193
|
}
|
|
194
|
+
const { tree, parser, parserTimeTaken, lexerTimeTaken, throwError } = await parseFileWithVisitor(visitor, scriptData);
|
|
195
|
+
printWarnings(visitor.getWarnings());
|
|
196
|
+
showStats && console.log('Lexing took:', lexerTimeTaken);
|
|
197
|
+
showStats && console.log('Parsing took:', parserTimeTaken);
|
|
198
|
+
if (dumpNets) {
|
|
199
|
+
const nets = visitor.dumpNets();
|
|
200
|
+
nets.forEach(item => console.log(item.join(" | ")));
|
|
201
|
+
}
|
|
202
202
|
dumpData && writeFileSync(dumpDirectory + 'tree.lisp', tree.toStringTree(null, parser));
|
|
203
203
|
dumpData && writeFileSync(dumpDirectory + 'raw-parser.txt', visitor.logger.dump());
|
|
204
|
+
if (throwError) {
|
|
205
|
+
throw throwError;
|
|
206
|
+
}
|
|
204
207
|
let svgOutput = "";
|
|
205
208
|
if (errors.length === 0) {
|
|
206
209
|
const { frameComponent } = visitor.applySheetFrameComponent();
|
package/dist/esm/layout.js
CHANGED
|
@@ -2,7 +2,7 @@ import graphlib, { Graph } from '@dagrejs/graphlib';
|
|
|
2
2
|
const { alg } = graphlib;
|
|
3
3
|
import { SymbolCustom, SymbolDrawing, SymbolCustomModule, SymbolPlaceholder, SymbolText, PlaceHolderCommands } from "./draw_symbols.js";
|
|
4
4
|
import { FrameAction, SequenceAction } from "./objects/ExecutionScope.js";
|
|
5
|
-
import { ComponentTypes, defaultFrameTitleTextSize, defaultGridSizeUnits, FrameType, ParamKeys, WireAutoDirection } from './globals.js';
|
|
5
|
+
import { ComponentTypes, defaultFrameTitleTextSize, defaultGridSizeUnits, FrameType, NetGraphicsParams, ParamKeys, WireAutoDirection } from './globals.js';
|
|
6
6
|
import { Geometry, HorizontalAlign, VerticalAlign } from './geometry.js';
|
|
7
7
|
import { Logger } from './logger.js';
|
|
8
8
|
import { FixedFrameIds, Frame, FrameParamKeys, FramePlotDirection } from './objects/Frame.js';
|
|
@@ -31,6 +31,7 @@ export class LayoutEngine {
|
|
|
31
31
|
}
|
|
32
32
|
runLayout(sequence, nets) {
|
|
33
33
|
const logNodesAndEdges = true;
|
|
34
|
+
const renderNets = this.collectRenderNets(nets);
|
|
34
35
|
this.print('===== creating graph and populating with nodes =====');
|
|
35
36
|
const { graph, containerFrames } = this.generateLayoutGraph(sequence, nets);
|
|
36
37
|
this.print('===== done populating graph =====');
|
|
@@ -83,7 +84,7 @@ export class LayoutEngine {
|
|
|
83
84
|
}
|
|
84
85
|
wireGroups.get(netName).push(wire);
|
|
85
86
|
});
|
|
86
|
-
const { junctions, mergedWires } = this.findJunctions(wireGroups);
|
|
87
|
+
const { junctions, mergedWires } = this.findJunctions(wireGroups, renderNets);
|
|
87
88
|
return {
|
|
88
89
|
frame: sheet,
|
|
89
90
|
frames,
|
|
@@ -91,11 +92,33 @@ export class LayoutEngine {
|
|
|
91
92
|
wires,
|
|
92
93
|
textObjects,
|
|
93
94
|
junctions,
|
|
94
|
-
mergedWires
|
|
95
|
+
mergedWires
|
|
95
96
|
};
|
|
96
97
|
});
|
|
97
98
|
return sheetFrameObjects;
|
|
98
99
|
}
|
|
100
|
+
collectRenderNets(nets) {
|
|
101
|
+
const renderNets = new Map();
|
|
102
|
+
const uniqueNets = new Set(nets.map(([, , net]) => net));
|
|
103
|
+
uniqueNets.forEach(net => {
|
|
104
|
+
const renderNet = {
|
|
105
|
+
netName: net.toString(),
|
|
106
|
+
net,
|
|
107
|
+
};
|
|
108
|
+
if (net.params.has(NetGraphicsParams.Color)) {
|
|
109
|
+
renderNet.color = net.params.get(NetGraphicsParams.Color);
|
|
110
|
+
}
|
|
111
|
+
if (net.params.has(NetGraphicsParams.LineWidth)) {
|
|
112
|
+
const value = net.params.get(NetGraphicsParams.LineWidth);
|
|
113
|
+
renderNet.lineWidth = milsToMM(value).toNumber();
|
|
114
|
+
}
|
|
115
|
+
if (net.params.has(NetGraphicsParams.Highight)) {
|
|
116
|
+
renderNet.highlight = net.params.get(NetGraphicsParams.Highight);
|
|
117
|
+
}
|
|
118
|
+
renderNets.set(net.toString(), renderNet);
|
|
119
|
+
});
|
|
120
|
+
return renderNets;
|
|
121
|
+
}
|
|
99
122
|
flattenFrameItems(frame) {
|
|
100
123
|
const items = [];
|
|
101
124
|
frame.innerItems.forEach(item => {
|
|
@@ -107,11 +130,11 @@ export class LayoutEngine {
|
|
|
107
130
|
});
|
|
108
131
|
return items;
|
|
109
132
|
}
|
|
110
|
-
findJunctions(wireGroups) {
|
|
133
|
+
findJunctions(wireGroups, nets) {
|
|
111
134
|
const junctions = [];
|
|
112
135
|
const mergedWires = [];
|
|
113
136
|
const debugSegments = false;
|
|
114
|
-
for (const [
|
|
137
|
+
for (const [netName, wires] of wireGroups) {
|
|
115
138
|
const allLines = wires.map(wire => {
|
|
116
139
|
return wire.points.map(pt => {
|
|
117
140
|
return {
|
|
@@ -120,6 +143,10 @@ export class LayoutEngine {
|
|
|
120
143
|
};
|
|
121
144
|
});
|
|
122
145
|
});
|
|
146
|
+
let renderNet = null;
|
|
147
|
+
if (nets.has(netName)) {
|
|
148
|
+
renderNet = nets.get(netName);
|
|
149
|
+
}
|
|
123
150
|
if (debugSegments) {
|
|
124
151
|
const tmpSegments = [];
|
|
125
152
|
allLines.forEach(wire => {
|
|
@@ -133,20 +160,22 @@ export class LayoutEngine {
|
|
|
133
160
|
}
|
|
134
161
|
});
|
|
135
162
|
mergedWires.push({
|
|
136
|
-
netName:
|
|
163
|
+
netName: netName,
|
|
137
164
|
segments: tmpSegments,
|
|
138
165
|
intersectPoints: [],
|
|
166
|
+
net: renderNet,
|
|
139
167
|
});
|
|
140
168
|
}
|
|
141
169
|
else {
|
|
142
170
|
const { intersectPoints, segments } = Geometry.mergeWires(allLines);
|
|
143
171
|
mergedWires.push({
|
|
144
|
-
netName:
|
|
172
|
+
netName: netName,
|
|
145
173
|
segments,
|
|
146
174
|
intersectPoints,
|
|
175
|
+
net: renderNet,
|
|
147
176
|
});
|
|
148
177
|
intersectPoints.forEach(([x, y]) => {
|
|
149
|
-
junctions.push(new RenderJunction(numeric(x), numeric(y)));
|
|
178
|
+
junctions.push(new RenderJunction(numeric(x), numeric(y), renderNet));
|
|
150
179
|
});
|
|
151
180
|
}
|
|
152
181
|
}
|
|
@@ -657,22 +686,25 @@ export class LayoutEngine {
|
|
|
657
686
|
}
|
|
658
687
|
case SequenceAction.Wire: {
|
|
659
688
|
const [, wireId, wireSegments] = sequenceStep;
|
|
660
|
-
|
|
661
|
-
wire.id = wireId;
|
|
662
|
-
let useNetName = null;
|
|
689
|
+
let useNet;
|
|
663
690
|
if (previousNode !== null) {
|
|
664
691
|
const [prevNodeType, prevNodeItem] = graph.node(previousNode);
|
|
665
692
|
if (prevNodeType === RenderItemType.Component) {
|
|
666
693
|
const matchingItem = nets.find(([comp, pin]) => {
|
|
667
|
-
return comp.instanceName === previousNode
|
|
694
|
+
return comp.instanceName === previousNode
|
|
695
|
+
&& pin === previousPin;
|
|
668
696
|
});
|
|
669
|
-
|
|
697
|
+
if (matchingItem !== undefined) {
|
|
698
|
+
useNet = matchingItem[2];
|
|
699
|
+
}
|
|
670
700
|
}
|
|
671
701
|
else if (prevNodeType === RenderItemType.Wire) {
|
|
672
|
-
|
|
702
|
+
useNet = prevNodeItem.net;
|
|
673
703
|
}
|
|
674
704
|
}
|
|
675
|
-
wire
|
|
705
|
+
const wire = new RenderWire(useNet, numeric(0), numeric(0), wireSegments);
|
|
706
|
+
wire.id = wireId;
|
|
707
|
+
wire.netName = useNet.toString();
|
|
676
708
|
const wireName = getWireName(wire.id);
|
|
677
709
|
graph.setNode(wireName, [RenderItemType.Wire, wire, index]);
|
|
678
710
|
this.setGraphEdge(graph, previousNode, wireName, makeEdgeValue(previousNode, previousPin, wireName, 0, index));
|
|
@@ -1188,8 +1220,10 @@ export class RenderWire extends RenderObject {
|
|
|
1188
1220
|
segments = [];
|
|
1189
1221
|
points = [];
|
|
1190
1222
|
netName;
|
|
1191
|
-
|
|
1223
|
+
net;
|
|
1224
|
+
constructor(net, x, y, segments) {
|
|
1192
1225
|
super();
|
|
1226
|
+
this.net = net;
|
|
1193
1227
|
this.x = x;
|
|
1194
1228
|
this.y = y;
|
|
1195
1229
|
this.segments = segments;
|
|
@@ -1428,9 +1462,11 @@ export var RenderFrameType;
|
|
|
1428
1462
|
export class RenderJunction {
|
|
1429
1463
|
x;
|
|
1430
1464
|
y;
|
|
1431
|
-
|
|
1465
|
+
net;
|
|
1466
|
+
constructor(x, y, net) {
|
|
1432
1467
|
this.x = x;
|
|
1433
1468
|
this.y = y;
|
|
1469
|
+
this.net = net;
|
|
1434
1470
|
}
|
|
1435
1471
|
}
|
|
1436
1472
|
export function CalculatePinPositions(component) {
|
|
@@ -103,6 +103,9 @@ export class ExecutionScope {
|
|
|
103
103
|
console.log(netName.padEnd(10), '=>', instanceName, pin);
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
|
+
setVariable(name, value) {
|
|
107
|
+
this.variables.set(name, value);
|
|
108
|
+
}
|
|
106
109
|
setActive(type, item) {
|
|
107
110
|
this.clearActive();
|
|
108
111
|
if (type === ActiveObject.Wire) {
|
package/dist/esm/objects/Net.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getNumberExponential, getNumberExponentialText, resolveToNumericValue } from "../utils.js";
|
|
1
|
+
import { getNumberExponential, getNumberExponentialText, isReference, resolveToNumericValue } from "../utils.js";
|
|
2
2
|
import { Big } from 'big.js';
|
|
3
3
|
export class ParamDefinition {
|
|
4
4
|
paramName;
|
|
@@ -121,6 +121,9 @@ export class NumberOperator {
|
|
|
121
121
|
if (typeof value === 'number') {
|
|
122
122
|
return new WrappedNumber(value);
|
|
123
123
|
}
|
|
124
|
+
else if (isReference(value)) {
|
|
125
|
+
return value.value;
|
|
126
|
+
}
|
|
124
127
|
else {
|
|
125
128
|
return value;
|
|
126
129
|
}
|
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
import { RuntimeExecutionError } from '../utils.js';
|
|
2
|
+
export class AnyReference {
|
|
3
|
+
found = false;
|
|
4
|
+
name;
|
|
5
|
+
trailers = [];
|
|
6
|
+
type;
|
|
7
|
+
value;
|
|
8
|
+
parentValue;
|
|
9
|
+
constructor(refType) {
|
|
10
|
+
if (refType.value instanceof AnyReference) {
|
|
11
|
+
throw new RuntimeExecutionError("Nested reference types!");
|
|
12
|
+
}
|
|
13
|
+
this.found = refType.found;
|
|
14
|
+
this.name = refType.name;
|
|
15
|
+
this.trailers = refType.trailers;
|
|
16
|
+
this.type = refType.type;
|
|
17
|
+
this.value = refType.value;
|
|
18
|
+
this.parentValue = refType.parentValue;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
1
21
|
export class UndeclaredReference {
|
|
2
22
|
reference;
|
|
3
23
|
constructor(reference) {
|
|
@@ -18,21 +38,7 @@ export class UndeclaredReference {
|
|
|
18
38
|
return name + extra;
|
|
19
39
|
}
|
|
20
40
|
}
|
|
21
|
-
export class DeclaredReference {
|
|
22
|
-
found;
|
|
23
|
-
name;
|
|
24
|
-
trailers;
|
|
25
|
-
type;
|
|
26
|
-
value;
|
|
27
|
-
parentValue;
|
|
28
|
-
constructor(refType) {
|
|
29
|
-
this.found = refType.found;
|
|
30
|
-
this.name = refType.name;
|
|
31
|
-
this.trailers = refType.trailers;
|
|
32
|
-
this.type = refType.type;
|
|
33
|
-
this.value = refType.value;
|
|
34
|
-
this.parentValue = refType.parentValue;
|
|
35
|
-
}
|
|
41
|
+
export class DeclaredReference extends AnyReference {
|
|
36
42
|
toString() {
|
|
37
43
|
return `[DeclaredReference name: ${this.name} trailers:${this.trailers} found: ${this.found}]`;
|
|
38
44
|
}
|
package/dist/esm/parser.js
CHANGED
|
@@ -18,6 +18,7 @@ export async function parseFileWithVisitor(visitor, data) {
|
|
|
18
18
|
parser.removeErrorListeners();
|
|
19
19
|
parser.addErrorListener(parserErrorListener);
|
|
20
20
|
const tree = parser.script();
|
|
21
|
+
let throwError;
|
|
21
22
|
try {
|
|
22
23
|
await visitor.visitAsync(tree);
|
|
23
24
|
}
|
|
@@ -27,7 +28,7 @@ export async function parseFileWithVisitor(visitor, data) {
|
|
|
27
28
|
visitor.onErrorHandler(error.message, null, error);
|
|
28
29
|
}
|
|
29
30
|
else {
|
|
30
|
-
|
|
31
|
+
throwError = error;
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
}
|
|
@@ -38,6 +39,7 @@ export async function parseFileWithVisitor(visitor, data) {
|
|
|
38
39
|
hasError: false,
|
|
39
40
|
parserTimeTaken,
|
|
40
41
|
lexerTimeTaken,
|
|
42
|
+
throwError
|
|
41
43
|
};
|
|
42
44
|
}
|
|
43
45
|
export class CircuitscriptParserErrorListener {
|