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.
@@ -15,6 +15,7 @@ const types_1 = require("./objects/types");
15
15
  const globals_1 = require("./globals");
16
16
  const builtinMethods_1 = require("./builtinMethods");
17
17
  const utils_1 = require("./utils");
18
+ const ExecutionScope_1 = require("./objects/ExecutionScope");
18
19
  class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
19
20
  constructor(silent = false, onErrorHandler = null, currentDirectory, defaultLibsPath) {
20
21
  super();
@@ -51,12 +52,9 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
51
52
  const trailers = reference.trailers ?? [];
52
53
  if (trailers.length === 0) {
53
54
  if (value instanceof ClassComponent_1.ClassComponent) {
54
- const instances = this.getExecutor().scope.instances;
55
- const tmpComponent = value;
56
- const oldName = tmpComponent.instanceName;
57
- tmpComponent.instanceName = reference.name;
58
- instances.delete(oldName);
59
- instances.set(reference.name, tmpComponent);
55
+ const variables = this.getExecutor().scope.variables;
56
+ variables.set(reference.name, value);
57
+ this.getExecutor().scope.sequence.push([ExecutionScope_1.SequenceAction.Assign, reference.name, value]);
60
58
  this.log2(`assigned '${reference.name}' to ClassComponent`);
61
59
  }
62
60
  else {
@@ -162,7 +160,6 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
162
160
  executor.scope.setNet(tmpComponent, pinId, net);
163
161
  }
164
162
  }
165
- this.log2(`atomId: ${atomId} ${currentReference}`);
166
163
  if (ctx.parent instanceof CircuitScriptParser_1.ExpressionContext && !currentReference.found) {
167
164
  this.throwWithContext(ctx, "Unknown symbol: " + atomId);
168
165
  }
@@ -378,12 +375,18 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
378
375
  };
379
376
  this.logger = new logger_1.Logger();
380
377
  this.onErrorCallbackHandler = onErrorHandler;
381
- this.startingContext = new execute_1.ExecutionContext('__', '__.', '/', 0, 0, silent, this.logger, null);
382
- this.startingContext.scope.variables.set(globals_1.GlobalDocumentName, {});
383
- this.setupPrintFunction(this.startingContext);
378
+ this.startingContext = new execute_1.ExecutionContext(globals_1.DoubleDelimiter1, `${globals_1.DoubleDelimiter1}.`, '/', 0, 0, silent, this.logger, null);
379
+ const scope = this.startingContext.scope;
380
+ scope.sequence.push([
381
+ ExecutionScope_1.SequenceAction.At, scope.componentRoot, scope.currentPin
382
+ ]);
383
+ scope.variables.set(globals_1.GlobalDocumentName, {});
384
+ this.setupBuiltInFunctions(this.startingContext);
384
385
  this.executionStack = [this.startingContext];
385
386
  this.startingContext.resolveNet =
386
387
  this.createNetResolver(this.executionStack);
388
+ this.startingContext.resolveComponentPinNet =
389
+ this.createComponentPinNetResolver(this.executionStack);
387
390
  this.silent = silent;
388
391
  this.currentDirectory = currentDirectory;
389
392
  this.defaultLibsPath = defaultLibsPath;
@@ -391,7 +394,7 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
391
394
  getExecutor() {
392
395
  return this.executionStack[this.executionStack.length - 1];
393
396
  }
394
- setupPrintFunction(context) {
397
+ setupBuiltInFunctions(context) {
395
398
  (0, builtinMethods_1.linkBuiltInMethods)(context, this);
396
399
  }
397
400
  createNetResolver(executionStack) {
@@ -414,6 +417,19 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
414
417
  };
415
418
  return resolveNet;
416
419
  }
420
+ createComponentPinNetResolver(executionStack) {
421
+ return (component, pin) => {
422
+ const reversed = [...executionStack].reverse();
423
+ for (let i = 0; i < reversed.length; i++) {
424
+ const context = reversed[i];
425
+ const net = context.scope.getNet(component, pin);
426
+ if (net !== null) {
427
+ return net;
428
+ }
429
+ }
430
+ return null;
431
+ };
432
+ }
417
433
  log(...params) {
418
434
  const indentOutput = ''.padStart(this.indentLevel * 4, ' ');
419
435
  const indentLevelText = this.indentLevel.toString().padStart(3, ' ');
@@ -592,7 +608,6 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
592
608
  const executionContextNamespace = currentExecutionContext.namespace
593
609
  + executionContextName + ".";
594
610
  const newExecutor = new execute_1.ExecutionContext(executionContextName, executionContextNamespace, netNamespace, executionLevel + 1, this.getExecutor().scope.indentLevel + 1, currentExecutionContext.silent, currentExecutionContext.logger, parentContext);
595
- this.setupPrintFunction(newExecutor);
596
611
  executionStack.push(newExecutor);
597
612
  this.setupDefinedParameters(funcDefinedParameters, passedInParameters, newExecutor);
598
613
  return newExecutor;
@@ -23,6 +23,8 @@ function linkBuiltInMethods(context, visitor) {
23
23
  ['toMils', toMils],
24
24
  ['range', range],
25
25
  ['len', objectLength],
26
+ ['arrayPush', arrayPush],
27
+ ['arrayGet', arrayGet],
26
28
  ];
27
29
  builtIns.forEach(([functionName, functionImpl]) => {
28
30
  context.createFunction(functionName, params => {
@@ -87,6 +89,26 @@ function objectLength(obj) {
87
89
  }
88
90
  }
89
91
  }
92
+ function arrayPush(arrayObject, valueToPush) {
93
+ if (!Array.isArray(arrayObject)) {
94
+ throw "Invalid array object to push";
95
+ }
96
+ arrayObject.push(valueToPush);
97
+ return arrayObject;
98
+ }
99
+ function arrayGet(arrayObject, index) {
100
+ if (!Array.isArray(arrayObject)) {
101
+ throw "Invalid array object to get";
102
+ }
103
+ let useValue;
104
+ if (index instanceof ParamDefinition_1.NumericValue) {
105
+ useValue = index.toNumber();
106
+ }
107
+ else {
108
+ useValue = index;
109
+ }
110
+ return arrayObject[useValue];
111
+ }
90
112
  function getPositionParams(params) {
91
113
  return params.map(([, , value]) => value);
92
114
  }
@@ -792,7 +792,10 @@ class SymbolCustom extends SymbolGraphic {
792
792
  calculateSize() {
793
793
  const tmpPinSpacing = this.pinSpacing.toNumber();
794
794
  const tmpPinLength = this.pinLength.toNumber();
795
- const { [globals_js_1.SymbolPinSide.Top]: maxTopPins, [globals_js_1.SymbolPinSide.Bottom]: maxBottomPins, [globals_js_1.SymbolPinSide.Left]: maxLeftPins, [globals_js_1.SymbolPinSide.Right]: maxRightPins } = this.pinMaxPositions;
795
+ const maxTopPins = this.pinMaxPositions.get(globals_js_1.SymbolPinSide.Top);
796
+ const maxBottomPins = this.pinMaxPositions.get(globals_js_1.SymbolPinSide.Bottom);
797
+ const maxLeftPins = this.pinMaxPositions.get(globals_js_1.SymbolPinSide.Left);
798
+ const maxRightPins = this.pinMaxPositions.get(globals_js_1.SymbolPinSide.Right);
796
799
  const bodyWidthFromPins = (0, ParamDefinition_js_1.numeric)((1 + Math.max(maxTopPins, maxBottomPins)) * tmpPinSpacing);
797
800
  const bodyWidth = Math.max(bodyWidthFromPins.toNumber(), this.bodyWidth.toNumber());
798
801
  let tmpBodyHeight = 0;
@@ -13,6 +13,7 @@ const Frame_js_1 = require("./objects/Frame.js");
13
13
  const layout_js_1 = require("./layout.js");
14
14
  const helpers_js_1 = require("./helpers.js");
15
15
  const draw_symbols_js_1 = require("./draw_symbols.js");
16
+ const utils_js_1 = require("./utils.js");
16
17
  class ExecutionContext {
17
18
  constructor(name, namespace, netNamespace, executionLevel = 0, indentLevel = 0, silent = false, logger, parent) {
18
19
  this.tmpPointId = 0;
@@ -30,13 +31,6 @@ class ExecutionContext {
30
31
  this.scope = ExecutionScope_js_1.ExecutionScope.create();
31
32
  this.scope.indentLevel = indentLevel;
32
33
  this.setupRoot();
33
- if (name === '__') {
34
- this.scope.sequence.push([
35
- ExecutionScope_js_1.SequenceAction.At,
36
- this.scope.componentRoot,
37
- this.scope.currentPin
38
- ]);
39
- }
40
34
  this.silent = silent;
41
35
  this.log('create new execution context', this.namespace, this.name, this.scope.indentLevel);
42
36
  this.parentContext = parent;
@@ -62,12 +56,12 @@ class ExecutionContext {
62
56
  this.scope.componentRoot = componentRoot;
63
57
  }
64
58
  getUniqueInstanceName() {
65
- const tmpName = 'COMP_' + this.scope.unnamedCounter;
59
+ const tmpName = `COMP${globals_js_1.Delimiter1}${this.scope.unnamedCounter}`;
66
60
  this.scope.unnamedCounter += 1;
67
61
  return tmpName;
68
62
  }
69
63
  getUniqueNetName() {
70
- const tmpName = 'NET_' + this.scope.netCounter;
64
+ const tmpName = `NET${globals_js_1.Delimiter1}${this.scope.netCounter}`;
71
65
  this.scope.netCounter++;
72
66
  return tmpName;
73
67
  }
@@ -77,7 +71,7 @@ class ExecutionContext {
77
71
  linkComponentPinNet(component1, component1Pin, component2, component2Pin) {
78
72
  const net1 = this.scope.getNet(component1, component1Pin);
79
73
  const net2 = this.scope.getNet(component2, component2Pin);
80
- this.log('link nets', component1, component1Pin, net1, 'to', component2, component2Pin, net2);
74
+ this.log('link nets', component1, component1Pin, net1, 'priority:' + net1?.priority, 'to', component2, component2Pin, net2, 'priority:' + net2?.priority);
81
75
  let returnNet;
82
76
  if (net1 === null && net2 === null) {
83
77
  const tmpNet = new Net_js_1.Net(this.netNamespace, this.getUniqueNetName());
@@ -101,7 +95,7 @@ class ExecutionContext {
101
95
  returnNet = net1;
102
96
  }
103
97
  }
104
- this.log('final net after link: ', returnNet);
98
+ this.log('final net after link: ', returnNet, returnNet.priority);
105
99
  return returnNet;
106
100
  }
107
101
  mergeNets(net1, net2) {
@@ -162,8 +156,9 @@ class ExecutionContext {
162
156
  tmpNet = new Net_js_1.Net(this.netNamespace, netName, priority);
163
157
  this.log('net not found, added net instance', tmpNet.namespace, tmpNet.name);
164
158
  }
165
- this.scope.setNet(component, 1, tmpNet);
166
- this.log('set net', netName, 'component', component);
159
+ const defaultPin = 1;
160
+ this.scope.setNet(component, defaultPin, tmpNet);
161
+ this.log('set net', netName, 'component', component, defaultPin);
167
162
  }
168
163
  const { pins: pinSides, maxPositions } = getPortSide(component.pins, component.arrangeProps);
169
164
  component.pinsMaxPositions = maxPositions;
@@ -205,7 +200,6 @@ class ExecutionContext {
205
200
  this.atComponent(component, nextPin, {
206
201
  addSequence: true
207
202
  });
208
- this.printPoint();
209
203
  return this.getCurrentPoint();
210
204
  }
211
205
  toComponent(component, pinId, options) {
@@ -279,6 +273,7 @@ class ExecutionContext {
279
273
  return this.getCurrentPoint();
280
274
  }
281
275
  copyComponent(component) {
276
+ this.log('create clone of net component:', component);
282
277
  let componentCopy = null;
283
278
  if (!this.scope.copyIDs.has(component.instanceName)) {
284
279
  this.scope.copyIDs.set(component.instanceName, 0);
@@ -291,14 +286,24 @@ class ExecutionContext {
291
286
  const cloneInstanceName = component.instanceName + ':' + idNum;
292
287
  this.scope.instances.set(cloneInstanceName, componentCopy);
293
288
  componentCopy.instanceName = cloneInstanceName;
294
- this.linkComponentPinNet(component, 1, componentCopy, 1);
289
+ const defaultPin = 1;
290
+ if (this.scope.getNet(component, defaultPin) === null) {
291
+ const foundNet = this.resolveComponentPinNet(component, defaultPin);
292
+ if (foundNet !== null) {
293
+ this.log('found net in upper scopes', foundNet);
294
+ this.scope.setNet(component, defaultPin, foundNet);
295
+ }
296
+ }
297
+ this.linkComponentPinNet(component, defaultPin, componentCopy, defaultPin);
295
298
  this.log('created clone of net component:', cloneInstanceName);
296
299
  return componentCopy;
297
300
  }
298
301
  enterBlocks(blockType) {
299
- if (blockType === globals_js_1.BlockTypes.Point || blockType === globals_js_1.BlockTypes.Parallel) {
300
- const key = blockType === globals_js_1.BlockTypes.Point ? 'point' : 'parallel';
301
- this.addPoint(`_${key}.${this.name}.${this.tmpPointId}`, false);
302
+ if (blockType === globals_js_1.BlockTypes.Point
303
+ || blockType === globals_js_1.BlockTypes.Parallel
304
+ || blockType === globals_js_1.BlockTypes.Branch) {
305
+ const key = (0, utils_js_1.getBlockTypeString)(blockType);
306
+ this.addPoint(`${globals_js_1.Delimiter1}${key}.${this.name}.${this.tmpPointId}`, false);
302
307
  this.tmpPointId += 1;
303
308
  }
304
309
  this.scope.blockStack.set(this.scope.indentLevel, {
@@ -373,7 +378,7 @@ class ExecutionContext {
373
378
  }
374
379
  else if (blockType === globals_js_1.BlockTypes.Join || blockType === globals_js_1.BlockTypes.Parallel) {
375
380
  if (blockIndex === 0) {
376
- const pointIdName = (blockType === globals_js_1.BlockTypes.Join) ? '_join' : '_parallel';
381
+ const pointIdName = `${globals_js_1.Delimiter1}${(0, utils_js_1.getBlockTypeString)(blockType)}`;
377
382
  this.addPoint(`${pointIdName}.${this.name}.${this.tmpPointId}`, false);
378
383
  this.tmpPointId += 1;
379
384
  stackRef['final_point'] = [
@@ -407,7 +412,7 @@ class ExecutionContext {
407
412
  const stackRef = this.scope.blockStack.get(this.scope.indentLevel - 1 - i);
408
413
  const { entered_at } = stackRef;
409
414
  const component = entered_at[0];
410
- if (component.instanceName.startsWith('_point.')) {
415
+ if (component.instanceName.startsWith(`${globals_js_1.Delimiter1}point.`)) {
411
416
  return entered_at;
412
417
  }
413
418
  }
@@ -522,14 +527,12 @@ class ExecutionContext {
522
527
  const currentComponent = this.scope.currentComponent;
523
528
  const currentPin = this.scope.currentPin;
524
529
  const currentWireId = this.scope.currentWireId;
525
- const gndCopyIdOffset = 0;
526
530
  const tmpInstances = childScope.instances;
527
531
  const tmpNets = childScope.getNets();
528
532
  for (const [instanceName, component] of tmpInstances) {
529
533
  const newInstanceName = `${namespace}.${instanceName}`;
530
534
  component.instanceName = newInstanceName;
531
- if (component === childScope.componentGnd ||
532
- component === childScope.componentRoot) {
535
+ if (component === childScope.componentRoot) {
533
536
  continue;
534
537
  }
535
538
  if (!this.scope.instances.has(newInstanceName)) {
@@ -539,6 +542,16 @@ class ExecutionContext {
539
542
  throw "Invalid instance name to merge into parent scope!";
540
543
  }
541
544
  }
545
+ const childScopeUniqueNets = new Set(tmpNets.map(([, , net]) => net));
546
+ childScopeUniqueNets.forEach(net => {
547
+ if (net.priority === 0
548
+ && this.scope.getNetWithNamespacePath(net.namespace, net.name) !== null) {
549
+ this.log('net namespace and name already used in parent scope', net);
550
+ const newNetName = this.getUniqueNetName();
551
+ net.name = newNetName;
552
+ this.log('assigned new name: ', net);
553
+ }
554
+ });
542
555
  tmpNets.forEach(([component, pin, net]) => {
543
556
  this.scope.setNet(component, pin, net);
544
557
  });
@@ -553,7 +566,6 @@ class ExecutionContext {
553
566
  this.scope.setNet(currentComponent, currentPin, netConnectedToRoot);
554
567
  currentNet = tmpNet;
555
568
  }
556
- netConnectedToRoot.priority = currentNet.priority - 1;
557
569
  this.toComponent(tmpRoot, 1);
558
570
  }
559
571
  }
@@ -642,7 +654,7 @@ class ExecutionContext {
642
654
  this.log('Warning: ' + pointId + ' is being redefined');
643
655
  }
644
656
  const useName = userDefined ? 'point.' + pointId : pointId;
645
- const componentPoint = ClassComponent_js_1.ClassComponent.simple(useName, 1, "point");
657
+ const componentPoint = ClassComponent_js_1.ClassComponent.simple(useName, 1);
646
658
  componentPoint.displayProp = this.getPointSymbol();
647
659
  componentPoint.typeProp = globals_js_1.ComponentTypes.net;
648
660
  this.scope.instances.set(pointId, componentPoint);
@@ -797,12 +809,11 @@ function isWireSegmentsEndAuto(segments) {
797
809
  }
798
810
  function getPortSide(pins, arrangeProps) {
799
811
  const result = [];
800
- const maxPositions = {
801
- [globals_js_1.SymbolPinSide.Left]: 0,
802
- [globals_js_1.SymbolPinSide.Right]: 0,
803
- [globals_js_1.SymbolPinSide.Top]: 0,
804
- [globals_js_1.SymbolPinSide.Bottom]: 0,
805
- };
812
+ const maxPositions = new Map();
813
+ maxPositions.set(globals_js_1.SymbolPinSide.Left, 0);
814
+ maxPositions.set(globals_js_1.SymbolPinSide.Right, 0);
815
+ maxPositions.set(globals_js_1.SymbolPinSide.Top, 0);
816
+ maxPositions.set(globals_js_1.SymbolPinSide.Bottom, 0);
806
817
  if (arrangeProps === null) {
807
818
  let counter = 0;
808
819
  for (const [pinId] of pins) {
@@ -820,8 +831,8 @@ function getPortSide(pins, arrangeProps) {
820
831
  const rightSideItems = result.filter(item => {
821
832
  return item.side === PinDefinition_js_1.PortSide.EAST;
822
833
  });
823
- maxPositions[globals_js_1.SymbolPinSide.Left] = leftSideItems.length;
824
- maxPositions[globals_js_1.SymbolPinSide.Right] = rightSideItems.length;
834
+ maxPositions.set(globals_js_1.SymbolPinSide.Left, leftSideItems.length);
835
+ maxPositions.set(globals_js_1.SymbolPinSide.Right, rightSideItems.length);
825
836
  }
826
837
  else {
827
838
  let counter = pins.size;
@@ -868,7 +879,7 @@ function getPortSide(pins, arrangeProps) {
868
879
  }
869
880
  }
870
881
  });
871
- maxPositions[key] = position;
882
+ maxPositions.set(key, position);
872
883
  }
873
884
  }
874
885
  return {
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RenderFlags = exports.GlobalDocumentName = exports.ModuleContainsKeyword = exports.FrameType = exports.BlockTypes = exports.ReferenceTypes = exports.ComponentTypes = exports.ColorScheme = exports.PortPaddingVertical = exports.PortPaddingHorizontal = exports.PortArrowSize = exports.junctionSize = exports.defaultFontSize = exports.defaultFontBold = exports.defaultFont = exports.displayUnits = exports.defaultFrameTitleTextSize = exports.CustomSymbolParamTextSize = exports.CustomSymbolRefDesSize = exports.CustomSymbolPinIdSize = exports.CustomSymbolPinTextSize = exports.defaultPageSpacingMM = exports.defaultPageMarginMM = exports.defaultPinIdTextSize = exports.defaultPinNameTextSize = exports.defaultWireLineWidth = exports.defaultSymbolLineWidth = exports.fontDisplayScale = exports.defaultZoomScale = exports.defaultGridSizeUnits = exports.portHeight = exports.portWidth = exports.PxToMM = exports.MMToPt = exports.MMToPx = exports.MilsToMM = exports.WireAutoDirection = exports.LengthUnit = exports.SymbolPinSide = exports.LayoutDirection = exports.ParamKeys = exports.NoNetText = exports.GlobalNames = void 0;
3
+ exports.RenderFlags = exports.GlobalDocumentName = exports.ModuleContainsKeyword = exports.FrameType = exports.BlockTypes = exports.ReferenceTypes = exports.ComponentTypes = exports.ColorScheme = exports.PortPaddingVertical = exports.PortPaddingHorizontal = exports.PortArrowSize = exports.junctionSize = exports.defaultFontSize = exports.defaultFontBold = exports.defaultFont = exports.displayUnits = exports.defaultFrameTitleTextSize = exports.CustomSymbolParamTextSize = exports.CustomSymbolRefDesSize = exports.CustomSymbolPinIdSize = exports.CustomSymbolPinTextSize = exports.defaultPageSpacingMM = exports.defaultPageMarginMM = exports.defaultPinIdTextSize = exports.defaultPinNameTextSize = exports.defaultWireLineWidth = exports.defaultSymbolLineWidth = exports.fontDisplayScale = exports.defaultZoomScale = exports.defaultGridSizeUnits = exports.portHeight = exports.portWidth = exports.PxToMM = exports.MMToPt = exports.MMToPx = exports.MilsToMM = exports.WireAutoDirection = exports.LengthUnit = exports.SymbolPinSide = exports.LayoutDirection = exports.ParamKeys = exports.NoNetText = exports.GlobalNames = exports.DoubleDelimiter1 = exports.Delimiter1 = void 0;
4
4
  const ParamDefinition_1 = require("./objects/ParamDefinition");
5
+ exports.Delimiter1 = '-';
6
+ exports.DoubleDelimiter1 = `${exports.Delimiter1}${exports.Delimiter1}`;
5
7
  var GlobalNames;
6
8
  (function (GlobalNames) {
7
- GlobalNames["__root"] = "__root";
9
+ GlobalNames["__root"] = "--root";
8
10
  GlobalNames["symbol"] = "symbol";
9
11
  })(GlobalNames || (exports.GlobalNames = GlobalNames = {}));
10
12
  exports.NoNetText = 'NO_NET';
@@ -9,7 +9,6 @@ const path_1 = __importDefault(require("path"));
9
9
  const pdfkit_1 = __importDefault(require("pdfkit"));
10
10
  const export_js_1 = require("./export.js");
11
11
  const layout_js_1 = require("./layout.js");
12
- const ExecutionScope_js_1 = require("./objects/ExecutionScope.js");
13
12
  const parser_js_1 = require("./parser.js");
14
13
  const render_js_1 = require("./render.js");
15
14
  const utils_js_1 = require("./utils.js");
@@ -181,10 +180,16 @@ function renderScript(scriptData, outputPath, options) {
181
180
  showStats && console.log('Parsing took:', parserTimeTaken);
182
181
  if (dumpNets) {
183
182
  const nets = visitor.dumpNets();
184
- console.log(nets);
183
+ nets.forEach(item => console.log(item.join(" | ")));
185
184
  }
186
- dumpData && (0, fs_1.writeFileSync)('dump/tree.lisp', tree.toStringTree(null, parser));
187
- dumpData && (0, fs_1.writeFileSync)('dump/raw-parser.txt', visitor.logger.dump());
185
+ const dumpDirectory = currentDirectory + '/dump/';
186
+ if (dumpData) {
187
+ if (!(0, fs_1.existsSync)(dumpDirectory)) {
188
+ (0, fs_1.mkdirSync)(dumpDirectory);
189
+ }
190
+ }
191
+ dumpData && (0, fs_1.writeFileSync)(dumpDirectory + 'tree.lisp', tree.toStringTree(null, parser));
192
+ dumpData && (0, fs_1.writeFileSync)(dumpDirectory + 'raw-parser.txt', visitor.logger.dump());
188
193
  if (hasError || hasParseError) {
189
194
  console.log('Error while parsing');
190
195
  return null;
@@ -197,29 +202,8 @@ function renderScript(scriptData, outputPath, options) {
197
202
  console.log('Error during annotation: ', err);
198
203
  }
199
204
  const { sequence, nets } = visitor.getGraph();
200
- const tmpSequence = sequence.map(item => {
201
- const tmp = [...item];
202
- const action = tmp[0];
203
- if (action === ExecutionScope_js_1.SequenceAction.Wire) {
204
- tmp[2] = tmp[2].map(item2 => {
205
- const lengthValue = item2.value;
206
- const useValue = [item2.direction];
207
- if (lengthValue !== null) {
208
- useValue.push(lengthValue.value);
209
- useValue.push(lengthValue.type);
210
- }
211
- return useValue.join(",");
212
- }).join(" ");
213
- }
214
- else if (action === ExecutionScope_js_1.SequenceAction.Frame) {
215
- tmp[1] = item[1].frameId;
216
- }
217
- else if (action !== ExecutionScope_js_1.SequenceAction.WireJump) {
218
- tmp[1] = item[1].instanceName;
219
- }
220
- return tmp.join(" | ");
221
- });
222
- dumpData && (0, fs_1.writeFileSync)('dump/raw-sequence.txt', tmpSequence.join('\n'));
205
+ const tmpSequence = (0, utils_js_1.generateDebugSequenceAction)(sequence).map(item => (0, utils_js_1.sequenceActionString)(item));
206
+ dumpData && (0, fs_1.writeFileSync)(dumpDirectory + 'raw-sequence.txt', tmpSequence.join('\n'));
223
207
  let svgOutput = "";
224
208
  try {
225
209
  let fileExtension = null;
@@ -244,12 +228,12 @@ function renderScript(scriptData, outputPath, options) {
244
228
  const sheetFrames = layoutEngine.runLayout(sequence, nets);
245
229
  layoutEngine.printWarnings();
246
230
  showStats && console.log('Layout took:', layoutTimer.lap());
247
- dumpData && (0, fs_1.writeFileSync)('dump/raw-layout.txt', layoutEngine.logger.dump());
231
+ dumpData && (0, fs_1.writeFileSync)(dumpDirectory + 'raw-layout.txt', layoutEngine.logger.dump());
248
232
  const generateSvgTimer = new utils_js_1.SimpleStopwatch();
249
233
  const renderLogger = new logger_js_1.Logger();
250
234
  const svgCanvas = (0, render_js_1.renderSheetsToSVG)(sheetFrames, renderLogger);
251
235
  showStats && console.log('Render took:', generateSvgTimer.lap());
252
- dumpData && (0, fs_1.writeFileSync)('dump/raw-render.txt', renderLogger.dump());
236
+ dumpData && (0, fs_1.writeFileSync)(dumpDirectory + 'raw-render.txt', renderLogger.dump());
253
237
  svgOutput = (0, render_js_1.generateSvgOutput)(svgCanvas, outputDefaultZoom);
254
238
  if (outputPath) {
255
239
  if (fileExtension === 'svg') {
@@ -348,7 +348,7 @@ class LayoutEngine {
348
348
  const frameArea = [tmpX1, tmpY1, tmpX2, tmpY2];
349
349
  const overlaps = avoidAreas.filter(area => (0, utils_js_1.areasOverlap)(frameArea, area));
350
350
  const doesOverlapAreasToAvoid = overlaps.length > 0;
351
- if (doesExceedFrameHeight || doesOverlapAreasToAvoid) {
351
+ if (boundPoints.length > 0 && (doesExceedFrameHeight || doesOverlapAreasToAvoid)) {
352
352
  innerFrameY = offsetY;
353
353
  const nextX = (0, ParamDefinition_js_1.numeric)(xmax).sub(offsetX).add(frame.gap);
354
354
  innerFrameX = offsetX.add(nextX);
@@ -378,7 +378,7 @@ class LayoutEngine {
378
378
  const frameArea = [tmpX1, tmpY1, tmpX2, tmpY2];
379
379
  const overlaps = avoidAreas.filter(area => (0, utils_js_1.areasOverlap)(frameArea, area));
380
380
  const doesOverlapAreasToAvoid = overlaps.length > 0;
381
- if (doesExceedFrameWidth || doesOverlapAreasToAvoid) {
381
+ if (boundPoints.length > 0 && (doesExceedFrameWidth || doesOverlapAreasToAvoid)) {
382
382
  innerFrameX = offsetX.add(centeredOffsetX);
383
383
  const { ymax } = getBoundsFromPoints(boundPoints);
384
384
  const nextY = (0, ParamDefinition_js_1.numeric)(ymax).sub(offsetY).add(frame.gap);
@@ -1396,7 +1396,7 @@ class RenderFrame extends RenderObject {
1396
1396
  this.padding = (0, helpers_js_1.milsToMM)(100);
1397
1397
  this.gap = (0, helpers_js_1.milsToMM)(100);
1398
1398
  this.borderWidth = (0, ParamDefinition_js_1.numeric)(5);
1399
- this.direction = Frame_js_1.FramePlotDirection.Column;
1399
+ this.direction = Frame_js_1.FramePlotDirection.Row;
1400
1400
  this.width = null;
1401
1401
  this.height = null;
1402
1402
  this.subgraphId = "";
package/dist/cjs/main.js CHANGED
@@ -24,7 +24,8 @@ async function main() {
24
24
  .option('-w, --watch', 'Watch for file changes')
25
25
  .option('-n, --dump-nets', 'Dump out net information')
26
26
  .option('-d, --dump-data', 'Dump data during parsing')
27
- .option('-s, --stats', 'Show stats during generation');
27
+ .option('-s, --stats', 'Show stats during generation')
28
+ .option('-x, --skip-output', 'Skip output generation');
28
29
  commander_1.program.addHelpText('before', figlet_1.default.textSync('circuitscript', {
29
30
  font: 'Small Slant'
30
31
  }));
@@ -80,7 +81,7 @@ async function main() {
80
81
  outputPath = args[1];
81
82
  }
82
83
  const output = (0, helpers_js_1.renderScript)(scriptData, outputPath, scriptOptions);
83
- if (outputPath === null && output) {
84
+ if (outputPath === null && output && (options.skipOutput === undefined)) {
84
85
  console.log(output);
85
86
  }
86
87
  if (watchFileChanges) {
@@ -11,7 +11,7 @@ class ClassComponent {
11
11
  this.pins = new Map();
12
12
  this.pinNets = new Map();
13
13
  this.pinWires = new Map();
14
- this.pinsMaxPositions = {};
14
+ this.pinsMaxPositions = new Map();
15
15
  this._copyID = null;
16
16
  this._copyFrom = null;
17
17
  this.arrangeProps = null;
@@ -144,6 +144,9 @@ class ClassComponent {
144
144
  for (const [key, value] of this.pins) {
145
145
  component.pins.set(key, value);
146
146
  }
147
+ for (const [key, value] of this.pinsMaxPositions) {
148
+ component.pinsMaxPositions.set(key, value);
149
+ }
147
150
  component.refreshCache();
148
151
  return component;
149
152
  }
@@ -19,8 +19,6 @@ class ExecutionScope {
19
19
  this.currentPin = null;
20
20
  this.currentWireId = -1;
21
21
  this.currentFrameId = -1;
22
- this.netGnd = null;
23
- this.componentGnd = null;
24
22
  this.componentRoot = null;
25
23
  this.copyIDs = new Map();
26
24
  this.sequence = [];
@@ -42,6 +40,12 @@ class ExecutionScope {
42
40
  });
43
41
  return found ? found[2] : null;
44
42
  }
43
+ getNetWithNamespacePath(namespace, name) {
44
+ const found = this.nets.find(([, , net]) => {
45
+ return net.namespace === namespace && net.name === name;
46
+ });
47
+ return found ? found[2] : null;
48
+ }
45
49
  hasNet(component, pin) {
46
50
  return this.findNet(component, pin) !== undefined;
47
51
  }
@@ -129,6 +133,7 @@ var SequenceAction;
129
133
  SequenceAction["Wire"] = "wire";
130
134
  SequenceAction["WireJump"] = "wire-jump";
131
135
  SequenceAction["Frame"] = "frame";
136
+ SequenceAction["Assign"] = "assign";
132
137
  })(SequenceAction || (exports.SequenceAction = SequenceAction = {}));
133
138
  var FrameAction;
134
139
  (function (FrameAction) {
@@ -25,6 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.measureTextSize2 = exports.applyFontsToSVG = exports.getCreateSVGWindow = exports.prepareSVGEnvironment = void 0;
27
27
  const svg_js_1 = require("@svgdotjs/svg.js");
28
+ const big_js_1 = require("big.js");
28
29
  const geometry_js_1 = require("./geometry.js");
29
30
  const globals_js_1 = require("./globals.js");
30
31
  const helpers_js_1 = require("./helpers.js");
@@ -116,9 +117,11 @@ function measureTextSize2(text, fontFamily, fontSize, fontWeight = 'regular', an
116
117
  }
117
118
  const { width, height } = textbox;
118
119
  tmpTextElement.remove();
120
+ const finalWidth = new big_js_1.Big(width).round(4).toNumber();
121
+ const finalHeight = new big_js_1.Big(height).round(4).toNumber();
119
122
  measureTextSizeCache[key] = {
120
- width: Math.round(width * 100) / 100,
121
- height: Math.round(height * 100) / 100,
123
+ width: finalWidth,
124
+ height: finalHeight,
122
125
  box: textbox,
123
126
  };
124
127
  measureTextSizeCacheHits[key] = 0;
package/dist/cjs/utils.js CHANGED
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.areasOverlap = exports.isPointWithinArea = exports.resolveToNumericValue = exports.getNumberExponentialText = exports.getNumberExponential = exports.combineMaps = exports.throwWithContext = exports.roundValue = exports.getPortType = exports.getBoundsSize = exports.toNearestGrid = exports.resizeToNearestGrid = exports.printBounds = exports.resizeBounds = exports.SimpleStopwatch = void 0;
3
+ exports.getBlockTypeString = exports.generateDebugSequenceAction = exports.sequenceActionString = exports.areasOverlap = exports.isPointWithinArea = exports.resolveToNumericValue = exports.getNumberExponentialText = exports.getNumberExponential = exports.combineMaps = exports.throwWithContext = exports.roundValue = exports.getPortType = exports.getBoundsSize = exports.toNearestGrid = exports.resizeToNearestGrid = exports.printBounds = exports.resizeBounds = exports.SimpleStopwatch = void 0;
4
4
  const big_js_1 = require("big.js");
5
+ const ClassComponent_1 = require("./objects/ClassComponent");
5
6
  const ParamDefinition_1 = require("./objects/ParamDefinition");
7
+ const ExecutionScope_1 = require("./objects/ExecutionScope");
8
+ const globals_1 = require("./globals");
6
9
  class SimpleStopwatch {
7
10
  constructor() {
8
11
  this.startTime = new Date();
@@ -184,3 +187,76 @@ function areasOverlap(area1, area2) {
184
187
  || isPointWithinArea(pt4, area2);
185
188
  }
186
189
  exports.areasOverlap = areasOverlap;
190
+ function sequenceActionString(sequenceAction) {
191
+ const tmp = [...sequenceAction];
192
+ const action = tmp[0];
193
+ if (action === ExecutionScope_1.SequenceAction.Wire) {
194
+ tmp[2] = tmp[2].map(item2 => {
195
+ const lengthValue = item2.value;
196
+ const useValue = [item2.direction];
197
+ if (lengthValue !== null) {
198
+ useValue.push(lengthValue.value);
199
+ useValue.push(lengthValue.type);
200
+ }
201
+ return useValue.join(",");
202
+ }).join(" ");
203
+ }
204
+ else if (action === ExecutionScope_1.SequenceAction.Frame) {
205
+ tmp[1] = sequenceAction[1].frameId;
206
+ }
207
+ else if (action !== ExecutionScope_1.SequenceAction.WireJump) {
208
+ const [, component] = sequenceAction;
209
+ if (component instanceof ClassComponent_1.ClassComponent) {
210
+ tmp[1] = sequenceAction[1].instanceName;
211
+ }
212
+ }
213
+ return tmp.join(" | ");
214
+ }
215
+ exports.sequenceActionString = sequenceActionString;
216
+ function generateDebugSequenceAction(sequence) {
217
+ const variableMapping = new Map();
218
+ return sequence.map(item => {
219
+ const returnResult = [...item];
220
+ const [action,] = item;
221
+ if (action === ExecutionScope_1.SequenceAction.Assign) {
222
+ const [, name, component] = item;
223
+ variableMapping.set(name, component);
224
+ }
225
+ else {
226
+ if (action === ExecutionScope_1.SequenceAction.At || action === ExecutionScope_1.SequenceAction.To) {
227
+ const [, component,] = item;
228
+ const foundIndex = Array.from(variableMapping.values()).findIndex(item2 => {
229
+ if (component._copyFrom !== null) {
230
+ return component._copyFrom === item2;
231
+ }
232
+ return component === item2;
233
+ });
234
+ if (foundIndex !== -1) {
235
+ const name = Array.from(variableMapping.keys())[foundIndex];
236
+ returnResult[1] = name + ':' + component._copyID;
237
+ }
238
+ }
239
+ }
240
+ return returnResult;
241
+ });
242
+ }
243
+ exports.generateDebugSequenceAction = generateDebugSequenceAction;
244
+ function getBlockTypeString(type) {
245
+ let returnValue = 'branch';
246
+ switch (type) {
247
+ case globals_1.BlockTypes.Branch:
248
+ returnValue = 'branch';
249
+ break;
250
+ case globals_1.BlockTypes.Join:
251
+ returnValue = 'join';
252
+ break;
253
+ case globals_1.BlockTypes.Parallel:
254
+ returnValue = 'parallel';
255
+ break;
256
+ case globals_1.BlockTypes.Point:
257
+ returnValue = 'point';
258
+ break;
259
+ }
260
+ return returnValue;
261
+ }
262
+ exports.getBlockTypeString = getBlockTypeString;