circuitscript 0.1.10 → 0.1.12

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 (52) hide show
  1. package/dist/cjs/BaseVisitor.js +78 -51
  2. package/dist/cjs/SemanticTokenVisitor.js +6 -1
  3. package/dist/cjs/antlr/CircuitScriptParser.js +1062 -963
  4. package/dist/cjs/builtinMethods.js +5 -1
  5. package/dist/cjs/draw_symbols.js +2 -1
  6. package/dist/cjs/execute.js +43 -22
  7. package/dist/cjs/geometry.js +3 -9
  8. package/dist/cjs/globals.js +7 -1
  9. package/dist/cjs/layout.js +50 -16
  10. package/dist/cjs/objects/ExecutionScope.js +3 -0
  11. package/dist/cjs/objects/Net.js +1 -0
  12. package/dist/cjs/objects/ParamDefinition.js +3 -0
  13. package/dist/cjs/objects/types.js +19 -10
  14. package/dist/cjs/render.js +48 -6
  15. package/dist/cjs/utils.js +16 -1
  16. package/dist/cjs/validate/SymbolValidatorVisitor.js +5 -0
  17. package/dist/cjs/visitor.js +77 -57
  18. package/dist/esm/BaseVisitor.js +72 -45
  19. package/dist/esm/SemanticTokenVisitor.js +6 -1
  20. package/dist/esm/antlr/CircuitScriptParser.js +1055 -958
  21. package/dist/esm/antlr/CircuitScriptVisitor.js +4 -2
  22. package/dist/esm/builtinMethods.js +6 -2
  23. package/dist/esm/draw_symbols.js +2 -1
  24. package/dist/esm/execute.js +43 -22
  25. package/dist/esm/geometry.js +3 -9
  26. package/dist/esm/globals.js +6 -0
  27. package/dist/esm/layout.js +53 -17
  28. package/dist/esm/objects/ExecutionScope.js +3 -0
  29. package/dist/esm/objects/Net.js +1 -0
  30. package/dist/esm/objects/ParamDefinition.js +4 -1
  31. package/dist/esm/objects/types.js +21 -15
  32. package/dist/esm/render.js +49 -7
  33. package/dist/esm/utils.js +13 -0
  34. package/dist/esm/validate/SymbolValidatorVisitor.js +5 -0
  35. package/dist/esm/visitor.js +66 -46
  36. package/dist/types/BaseVisitor.d.ts +2 -2
  37. package/dist/types/SemanticTokenVisitor.d.ts +2 -1
  38. package/dist/types/antlr/CircuitScriptParser.d.ts +100 -85
  39. package/dist/types/antlr/CircuitScriptVisitor.d.ts +8 -4
  40. package/dist/types/execute.d.ts +1 -0
  41. package/dist/types/geometry.d.ts +0 -1
  42. package/dist/types/globals.d.ts +5 -0
  43. package/dist/types/layout.d.ts +16 -3
  44. package/dist/types/objects/ExecutionScope.d.ts +15 -3
  45. package/dist/types/objects/Net.d.ts +1 -0
  46. package/dist/types/objects/types.d.ts +25 -18
  47. package/dist/types/utils.d.ts +3 -1
  48. package/dist/types/validate/SymbolValidatorVisitor.d.ts +2 -1
  49. package/dist/types/visitor.d.ts +3 -2
  50. package/package.json +3 -2
  51. /package/dist/libs/{lib.cst → std.cst} +0 -0
  52. /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
- visitPath_blocks;
7
- visitPath_block_inner;
9
+ visitPath_block;
8
10
  visitProperty_set_expr2;
9
11
  visitAssignment_expr2;
10
12
  visitPin_select_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 { prepareValue, resolveToNumericValue } from "./utils.js";
4
4
  const builtInMethods = [
5
5
  ['enumerate', enumerate],
6
6
  ['toMils', toMils],
@@ -15,7 +15,10 @@ 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 => toString(item));
18
+ const items = args.map(item => {
19
+ const value = prepareValue(item);
20
+ return toString(value);
21
+ });
19
22
  if (visitor.printToConsole) {
20
23
  console.log('::', ...items);
21
24
  }
@@ -75,6 +78,7 @@ function toMils(value) {
75
78
  return resolveToNumericValue(bigValue);
76
79
  }
77
80
  function objectLength(obj) {
81
+ obj = prepareValue(obj);
78
82
  if (Array.isArray(obj)) {
79
83
  return numeric(obj.length);
80
84
  }
@@ -424,7 +424,8 @@ export class SymbolPlaceholder extends SymbolGraphic {
424
424
  drawing.addArc(...positionParams);
425
425
  break;
426
426
  case PlaceHolderCommands.circle:
427
- drawing.addArc(...positionParams, numeric(0), numeric(360));
427
+ drawing.addArc(...positionParams, numeric(0), numeric(180));
428
+ drawing.addArc(...positionParams, numeric(180), numeric(360));
428
429
  break;
429
430
  case PlaceHolderCommands.triangle:
430
431
  drawing.addTriangle(...positionParams);
@@ -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
- entered_at: [
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: null,
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 { final_point: finalPoint } = stackRef;
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 { entered_at: [component, pin,] } = stackRef;
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['inner_blocks'].set(blockIndex, {
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 { entered_at: [component, pin,] } = stackRef;
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['inner_blocks'].get(blockIndex);
458
- blockIndexRef['last_net'] = [
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 { entered_at: [component, pin, wireId] } = stackRef;
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['final_point'] = [
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 { final_point: finalPoint } = stackRef;
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 { entered_at } = stackRef;
508
- const component = entered_at[0];
516
+ const { start_point } = stackRef;
517
+ const component = start_point[0];
509
518
  if (component.instanceName.startsWith(`${Delimiter1}point.`)) {
510
- return entered_at;
519
+ return start_point;
511
520
  }
512
521
  }
513
522
  this.log('did not find block point');
@@ -548,8 +557,8 @@ export class ExecutionContext {
548
557
  });
549
558
  }
550
559
  else {
551
- const isVariable = context.scope.variables.has(idName);
552
- const isComponentInstance = context.scope.instances.has(idName);
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;
@@ -558,11 +567,25 @@ export class ExecutionContext {
558
567
  if (trailers.length > 0) {
559
568
  parentValue = useValue;
560
569
  const trailersPath = trailers.join(".");
570
+ if (!isComponentInstance && (parentValue instanceof ClassComponent)) {
571
+ isComponentInstance = true;
572
+ isVariable = false;
573
+ }
561
574
  if (isVariable) {
562
575
  useValue = parentValue[trailersPath];
563
576
  }
564
577
  else if (isComponentInstance) {
565
- useValue = parentValue.parameters.get(trailersPath);
578
+ const tmpComponent = parentValue;
579
+ if (tmpComponent.typeProp === ComponentTypes.net) {
580
+ const usedNet = this.scope.getNet(tmpComponent, 1);
581
+ if (usedNet) {
582
+ const trailerValue = trailers.join(".");
583
+ useValue = usedNet.params.get(trailerValue) ?? null;
584
+ }
585
+ }
586
+ else {
587
+ useValue = parentValue.parameters.get(trailersPath);
588
+ }
566
589
  }
567
590
  }
568
591
  return new DeclaredReference({
@@ -618,9 +641,7 @@ export class ExecutionContext {
618
641
  }
619
642
  mergeScope(childScope, namespace) {
620
643
  this.log('-- merging scope to parent --');
621
- const currentComponent = this.scope.currentComponent;
622
- const currentPin = this.scope.currentPin;
623
- const currentWireId = this.scope.currentWireId;
644
+ const { currentComponent, currentPin, currentWireId } = this.scope;
624
645
  const tmpInstances = childScope.instances;
625
646
  const tmpNets = childScope.getNets();
626
647
  for (const [instanceName, component] of tmpInstances) {
@@ -254,7 +254,6 @@ export class Geometry {
254
254
  height: maxY - minY,
255
255
  };
256
256
  }
257
- static FullCircleRadians = 2 * Math.PI;
258
257
  static featuresToPath(items, flipX, flipY) {
259
258
  const paths = [];
260
259
  let isClosedPolygon = false;
@@ -267,17 +266,12 @@ export class Geometry {
267
266
  const x = item.center.x;
268
267
  const y = item.center.y;
269
268
  const radius = item.r;
270
- let useEndAngle = item.endAngle;
271
269
  let extraEnd = '';
272
- if (item.startAngle === 0 && item.endAngle === Geometry.FullCircleRadians) {
273
- useEndAngle = 359.9999 * Math.PI / 180;
274
- isClosedPolygon = true;
275
- extraEnd = ' Z';
276
- }
277
- const startPoint = getArcPointRadians(x, y, radius, item.startAngle);
270
+ const { startAngle: useStartAngle, endAngle: useEndAngle } = item;
271
+ const startPoint = getArcPointRadians(x, y, radius, useStartAngle);
278
272
  const endPoint = getArcPointRadians(x, y, radius, useEndAngle);
279
273
  let largeArcSweepFlag = 0;
280
- if (useEndAngle - item.startAngle > Math.PI) {
274
+ if (useEndAngle - useStartAngle > Math.PI) {
281
275
  largeArcSweepFlag = 1;
282
276
  }
283
277
  let sweepFlag = 1;
@@ -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";
@@ -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 [key, wires] of wireGroups) {
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: key,
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: key,
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
- const wire = new RenderWire(numeric(0), numeric(0), wireSegments);
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 && pin === previousPin;
694
+ return comp.instanceName === previousNode
695
+ && pin === previousPin;
668
696
  });
669
- useNetName = matchingItem !== undefined ? matchingItem[2].name : null;
697
+ if (matchingItem !== undefined) {
698
+ useNet = matchingItem[2];
699
+ }
670
700
  }
671
701
  else if (prevNodeType === RenderItemType.Wire) {
672
- useNetName = prevNodeItem.netName;
702
+ useNet = prevNodeItem.net;
673
703
  }
674
704
  }
675
- wire.netName = useNetName;
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
- constructor(x, y, segments) {
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
- constructor(x, y) {
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) {
@@ -4,6 +4,7 @@ export class Net {
4
4
  namespace;
5
5
  priority;
6
6
  type;
7
+ params = new Map();
7
8
  constructor(namespace, name, priority = 0, type = null) {
8
9
  if (namespace.indexOf(' ') !== -1) {
9
10
  throw "Invalid net namespace provided";
@@ -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
  }
@@ -1,7 +1,7 @@
1
1
  import { SVG, registerWindow } from '@svgdotjs/svg.js';
2
2
  import { ExtractDrawingRects, RenderFrameType, getBounds } from "./layout.js";
3
3
  import { applyFontsToSVG } from './sizing.js';
4
- import { ColorScheme, ComponentTypes, FrameType, MMToPt, MMToPx, ParamKeys, RenderFlags, defaultGridSizeUnits, defaultPageSpacingMM, defaultWireLineWidth, fontDisplayScale, junctionSize } from './globals.js';
4
+ import { ColorScheme, ComponentTypes, FrameType, MMToPt, MMToPx, MilsToMM, ParamKeys, RenderFlags, defaultGridSizeUnits, defaultPageSpacingMM, defaultWireLineWidth, fontDisplayScale, junctionSize } from './globals.js';
5
5
  import { numeric, NumericValue } from './objects/ParamDefinition.js';
6
6
  import { combineMaps, getBoundsSize } from './utils.js';
7
7
  import { getPaperSize, milsToMM } from './helpers.js';
@@ -169,28 +169,70 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
169
169
  .translate(wire.x.add(5).toNumber(), wire.y.add(5).toNumber());
170
170
  });
171
171
  }
172
+ const mergedWireHighlightGroup = canvas.group();
172
173
  const mergedWireGroup = canvas.group();
173
174
  mergedWires.forEach(tmpItem => {
174
- const { segments, intersectPoints } = tmpItem;
175
+ const { segments, intersectPoints, net = null } = tmpItem;
176
+ let useJunctionColor = ColorScheme.JunctionColor;
177
+ let useColor = ColorScheme.WireColor;
178
+ let useLineWidth = defaultWireLineWidth;
179
+ let displayHighlight = false;
180
+ let displayHighlightColor = null;
181
+ if (net !== null) {
182
+ useColor = net.color ?? ColorScheme.WireColor;
183
+ useJunctionColor = net.color ?? ColorScheme.JunctionColor;
184
+ useLineWidth = net.lineWidth ?? defaultWireLineWidth;
185
+ if (net.highlight !== null) {
186
+ displayHighlight = true;
187
+ displayHighlightColor = net.highlight ?? null;
188
+ }
189
+ }
190
+ const pathItems = [];
191
+ const highlightExtraSize = 5 * MilsToMM;
175
192
  segments.forEach(segment => {
176
193
  const pt1 = segment[0];
177
194
  const pt2 = segment[1];
178
- mergedWireGroup.line([pt1, pt2])
195
+ pathItems.push(...[
196
+ 'M', pt1[0], pt1[1],
197
+ 'L', pt2[0], pt2[1]
198
+ ]);
199
+ });
200
+ if (displayHighlight) {
201
+ mergedWireHighlightGroup.path(pathItems)
179
202
  .stroke({
180
- width: defaultWireLineWidth,
181
- color: ColorScheme.WireColor,
203
+ width: useLineWidth + highlightExtraSize,
204
+ color: displayHighlightColor,
205
+ opacity: 0.3,
182
206
  linecap: 'square'
183
207
  })
184
208
  .fill('none');
185
- });
209
+ }
210
+ mergedWireGroup.path(pathItems)
211
+ .stroke({
212
+ width: useLineWidth,
213
+ color: useColor,
214
+ linecap: 'square'
215
+ })
216
+ .fill('none');
186
217
  const halfJunctionSize = junctionSize.half();
218
+ const highlightJunctionSize = numeric(junctionSize.toNumber() + highlightExtraSize);
219
+ const tmpHighlightExtraSize = highlightJunctionSize.half();
187
220
  intersectPoints.forEach(point => {
188
221
  const [x, y,] = point;
189
222
  const translateX = numeric(x).sub(halfJunctionSize);
190
223
  const translateY = numeric(y).sub(halfJunctionSize);
224
+ if (displayHighlight && displayHighlightColor !== null) {
225
+ const tmpTranslateX = numeric(x).sub(tmpHighlightExtraSize);
226
+ const tmpTranslateY = numeric(y).sub(tmpHighlightExtraSize);
227
+ mergedWireHighlightGroup.circle(highlightJunctionSize.toNumber())
228
+ .translate(tmpTranslateX.toNumber(), tmpTranslateY.toNumber())
229
+ .fill(displayHighlightColor)
230
+ .opacity(0.3)
231
+ .stroke('none');
232
+ }
191
233
  mergedWireGroup.circle(junctionSize.toNumber())
192
234
  .translate(translateX.toNumber(), translateY.toNumber())
193
- .fill(ColorScheme.JunctionColor)
235
+ .fill(useJunctionColor)
194
236
  .stroke('none');
195
237
  });
196
238
  });
package/dist/esm/utils.js CHANGED
@@ -4,6 +4,7 @@ import { ClassComponent } from "./objects/ClassComponent.js";
4
4
  import { NumericValue } from "./objects/ParamDefinition.js";
5
5
  import { SequenceAction } from './objects/ExecutionScope.js';
6
6
  import { BlockTypes } from './globals.js';
7
+ import { DeclaredReference, AnyReference } from './objects/types.js';
7
8
  export class SimpleStopwatch {
8
9
  startTime;
9
10
  constructor() {
@@ -325,3 +326,15 @@ export function printWarnings(warnings) {
325
326
  console.log(`Warning: ${message}`);
326
327
  });
327
328
  }
329
+ export function prepareValue(value) {
330
+ if (isReference(value)) {
331
+ return value.value;
332
+ }
333
+ else {
334
+ return value;
335
+ }
336
+ }
337
+ export function isReference(value) {
338
+ return (value instanceof AnyReference ||
339
+ value instanceof DeclaredReference);
340
+ }
@@ -154,6 +154,11 @@ export class SymbolValidatorVisitor extends BaseVisitor {
154
154
  this.runExpressions(newExecutor, ctx.function_expr());
155
155
  this.executionStack.pop();
156
156
  };
157
+ visitFor_expr = (ctx) => {
158
+ ctx.ID().forEach(item => {
159
+ this.addSymbolVariable(item.getSymbol(), item.getText(), null);
160
+ });
161
+ };
157
162
  getSymbols() {
158
163
  return this.symbolTable;
159
164
  }