circuitscript 0.0.17 → 0.0.18

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.
@@ -53,10 +53,13 @@ export class SymbolGraphic {
53
53
  }
54
54
  pinPosition(id) {
55
55
  const pin = this.drawing.getPinPosition(id);
56
+ const [x, y] = pin.start;
57
+ const useX = Math.round(x * 10000) / 10000;
58
+ const useY = Math.round(y * 10000 / 10000);
56
59
  if (pin) {
57
60
  return {
58
- x: pin.start[0],
59
- y: pin.start[1],
61
+ x: useX,
62
+ y: useY,
60
63
  angle: pin.angle,
61
64
  };
62
65
  }
@@ -1,4 +1,4 @@
1
- import { ComponentTypes, GlobalNames, ParamKeys, ReferenceTypes } from './globals.js';
1
+ import { BranchType, ComponentTypes, GlobalNames, NoNetText, ParamKeys, ReferenceTypes } from './globals.js';
2
2
  import { ClassComponent } from './objects/ClassComponent.js';
3
3
  import { ActiveObject, ExecutionScope, FrameAction, SequenceAction } from './objects/ExecutionScope.js';
4
4
  import { Net } from './objects/Net.js';
@@ -11,6 +11,7 @@ export class ExecutionContext {
11
11
  netNamespace;
12
12
  executionLevel;
13
13
  scope;
14
+ joinPointId = 0;
14
15
  resolveNet = null;
15
16
  stopFurtherExpressions = false;
16
17
  returnValue = null;
@@ -180,11 +181,17 @@ export class ExecutionContext {
180
181
  this.print('add symbol', instanceName, '[' + pinsOutput.join(', ') + ']');
181
182
  return component;
182
183
  }
183
- printPoint() {
184
- this.print('point: ' +
184
+ printPoint(extra = '') {
185
+ let netName = NoNetText;
186
+ if (this.scope.hasNet(this.scope.currentComponent, this.scope.currentPin)) {
187
+ netName = this.scope
188
+ .getNet(this.scope.currentComponent, this.scope.currentPin)
189
+ .toString();
190
+ }
191
+ this.print((extra !== '' ? (extra + ' ') : '') + 'point: ' +
185
192
  this.scope.currentComponent.instanceName +
186
193
  ' ' +
187
- this.scope.currentPin);
194
+ this.scope.currentPin + ' ' + netName);
188
195
  }
189
196
  addComponentExisting(component, pin) {
190
197
  const startPin = pin;
@@ -298,78 +305,86 @@ export class ExecutionContext {
298
305
  this.print('created clone of net component:', cloneInstanceName);
299
306
  return clonedComponent;
300
307
  }
301
- enterBranches() {
308
+ enterBranches(branchType) {
302
309
  this.scope.branchStack.set(this.scope.indentLevel, {
303
- entered_at: [this.scope.currentComponent, this.scope.currentPin, this.scope.currentWireId],
310
+ entered_at: [
311
+ this.scope.currentComponent,
312
+ this.scope.currentPin,
313
+ this.scope.currentWireId
314
+ ],
304
315
  inner_branches: new Map(),
305
316
  current_index: null,
317
+ type: branchType,
306
318
  });
307
319
  this.print('enter branches');
308
320
  }
309
321
  exitBranches() {
310
- false && this.joinBranches();
311
- this.print('exit branches');
312
- }
313
- joinBranches() {
314
- const innerBranches = this.scope.branchStack.get(this.scope.indentLevel)['inner_branches'];
315
- const lastNets = [];
316
- for (const [key, value] of innerBranches) {
317
- if (value['ignore_last_net'] === false) {
318
- const [component, pin] = value['last_net'];
319
- let netPriority = 0;
320
- if (this.scope.hasNet(component, pin)) {
321
- netPriority = this.scope.getNet(component, pin).priority;
322
- }
323
- lastNets.push([netPriority, value['last_net']]);
322
+ const stackRef = this.scope.branchStack.get(this.scope.indentLevel);
323
+ const { type: branchType } = stackRef;
324
+ if (branchType === BranchType.Join) {
325
+ const { join_final_point: finalPoint } = stackRef;
326
+ const [component, pin, wireId] = finalPoint;
327
+ this.scope.currentComponent = component;
328
+ this.scope.currentPin = pin;
329
+ this.scope.currentWireId = wireId;
330
+ if (wireId !== -1) {
331
+ this.scope.sequence.push([
332
+ SequenceAction.WireJump, wireId, 1
333
+ ]);
324
334
  }
325
335
  }
326
- if (lastNets.length > 0) {
327
- const sortedNets = lastNets.sort((a, b) => {
328
- if (a[0] > b[0]) {
329
- return -1;
330
- }
331
- else if (a[0] < b[0]) {
332
- return 1;
333
- }
334
- else {
335
- return 0;
336
- }
337
- });
338
- const [comp1, pin1] = sortedNets[0][1];
339
- const tmpList = sortedNets.slice(1);
340
- tmpList.forEach((item) => {
341
- const [, [comp2, pin2]] = item;
342
- this.atComponent(comp1, pin1, { addSequence: true });
343
- this.toComponent(comp2, pin2, { addSequence: true });
344
- });
345
- this.scope.currentComponent = comp1;
346
- this.scope.currentPin = pin1;
347
- }
336
+ this.print('exit branches');
348
337
  }
349
338
  enterBranch(branchIndex) {
350
- this.print('enter inner branch >>>');
351
339
  const stackRef = this.scope.branchStack.get(this.scope.indentLevel);
352
340
  stackRef['branch_index'] = branchIndex;
341
+ const { type: branchType } = stackRef;
353
342
  stackRef['inner_branches'].set(branchIndex, {
354
343
  last_net: null,
355
344
  ignore_last_net: false,
356
345
  });
346
+ if (branchType === BranchType.Join) {
347
+ this.scope.currentComponent = null;
348
+ this.scope.currentPin = null;
349
+ this.scope.currentWireId = -1;
350
+ }
351
+ this.print(`enter inner branch of type (${branchType}) >>>`);
357
352
  this.scope.indentLevel += 1;
358
353
  }
359
354
  exitBranch(branchIndex) {
360
355
  const stackRef = this.scope.branchStack.get(this.scope.indentLevel - 1);
356
+ const { type: branchType } = stackRef;
361
357
  const branchIndexRef = stackRef['inner_branches'].get(branchIndex);
362
358
  branchIndexRef['last_net'] = [
363
359
  this.scope.currentComponent,
364
360
  this.scope.currentPin,
361
+ this.scope.currentWireId
365
362
  ];
366
363
  stackRef['branch_index'] = null;
367
364
  const [preBranchComponent, preBranchPin, preBranchWireId] = stackRef['entered_at'];
368
365
  this.scope.indentLevel -= 1;
369
366
  this.print('exit inner branch <<<');
370
- this.atComponent(preBranchComponent, preBranchPin, { addSequence: true });
371
- if (preBranchWireId !== -1) {
372
- this.scope.sequence.push([SequenceAction.WireJump, preBranchWireId]);
367
+ if (branchType === BranchType.Branch) {
368
+ this.atComponent(preBranchComponent, preBranchPin, { addSequence: true });
369
+ if (preBranchWireId !== -1) {
370
+ this.scope.sequence.push([SequenceAction.WireJump, preBranchWireId, 1]);
371
+ }
372
+ }
373
+ else if (branchType === BranchType.Join) {
374
+ if (branchIndex === 0) {
375
+ this.addPoint(`_join.${this.name}.${this.joinPointId}`, false);
376
+ this.joinPointId += 1;
377
+ stackRef['join_final_point'] = [
378
+ this.scope.currentComponent,
379
+ this.scope.currentPin,
380
+ this.scope.currentWireId
381
+ ];
382
+ }
383
+ else {
384
+ const { join_final_point: finalPoint } = stackRef;
385
+ const [joinComponent, joinPin, joinWireId] = finalPoint;
386
+ this.toComponent(joinComponent, joinPin, { addSequence: true });
387
+ }
373
388
  }
374
389
  }
375
390
  breakBranch() {
@@ -508,7 +523,7 @@ export class ExecutionContext {
508
523
  }
509
524
  else if (action === SequenceAction.WireJump) {
510
525
  const jumpWireId = wireIdOffset + sequenceAction[1];
511
- this.scope.sequence.push([SequenceAction.WireJump, jumpWireId]);
526
+ this.scope.sequence.push([SequenceAction.WireJump, jumpWireId, 1]);
512
527
  }
513
528
  else if (action === SequenceAction.At || action === SequenceAction.To) {
514
529
  const tmpComponent = sequenceAction[1];
@@ -536,8 +551,17 @@ export class ExecutionContext {
536
551
  this.scope.sequence.push(sequenceAction);
537
552
  }
538
553
  });
539
- this.scope.currentComponent = currentComponent;
540
- this.scope.currentPin = currentPin;
554
+ if (childScope.currentComponent === childScope.componentRoot) {
555
+ this.scope.currentComponent = currentComponent;
556
+ this.scope.currentPin = currentPin;
557
+ this.scope.currentWireId = currentWireId;
558
+ }
559
+ else {
560
+ this.scope.currentComponent = childScope.currentComponent;
561
+ this.scope.currentPin = childScope.currentPin;
562
+ this.scope.currentWireId = childScope.currentWireId + wireIdOffset;
563
+ }
564
+ this.printPoint('resume at');
541
565
  this.print('-- nets --');
542
566
  const currentNets = this.scope.getNets();
543
567
  currentNets.reduce((accum, [, , net]) => {
@@ -568,11 +592,12 @@ export class ExecutionContext {
568
592
  this.scope.sequence.push([SequenceAction.Wire, wireId, tmp]);
569
593
  this.scope.currentComponent.pinWires.set(this.scope.currentPin, tmp);
570
594
  }
571
- addPoint(pointId) {
595
+ addPoint(pointId, userDefined = true) {
572
596
  if (this.scope.instances.has(pointId)) {
573
597
  this.print('Warning: ' + pointId + ' is being redefined');
574
598
  }
575
- const componentPoint = ClassComponent.simple("point." + pointId, 1, "point");
599
+ const useName = userDefined ? 'point.' + pointId : pointId;
600
+ const componentPoint = ClassComponent.simple(useName, 1, "point");
576
601
  componentPoint.displayProp = "point";
577
602
  componentPoint.typeProp = ComponentTypes.point;
578
603
  this.scope.instances.set(pointId, componentPoint);
@@ -1,4 +1,4 @@
1
- import { ComponentTypes } from "./globals.js";
1
+ import { ComponentTypes, NoNetText } from "./globals.js";
2
2
  import { NumericValue } from "./objects/ParamDefinition.js";
3
3
  export function generateKiCADNetList(netlist) {
4
4
  const componentsList = [];
@@ -28,7 +28,7 @@ export function generateKiCADNetList(netlist) {
28
28
  for (const key in pins) {
29
29
  const netInfo = pins[key];
30
30
  const netName = netInfo.netName;
31
- if (netName === 'NO_NET') {
31
+ if (netName === NoNetText) {
32
32
  continue;
33
33
  }
34
34
  if (nets[netName] === undefined) {
@@ -7,6 +7,7 @@ export var GlobalNames;
7
7
  GlobalNames["DefaultInductor"] = "ind";
8
8
  GlobalNames["symbol"] = "symbol";
9
9
  })(GlobalNames || (GlobalNames = {}));
10
+ export const NoNetText = 'NO_NET';
10
11
  export var ParamKeys;
11
12
  (function (ParamKeys) {
12
13
  ParamKeys["__is_net"] = "__is_net";
@@ -47,3 +48,8 @@ export var ReferenceTypes;
47
48
  ReferenceTypes["variable"] = "variable";
48
49
  ReferenceTypes["instance"] = "instance";
49
50
  })(ReferenceTypes || (ReferenceTypes = {}));
51
+ export var BranchType;
52
+ (function (BranchType) {
53
+ BranchType[BranchType["Branch"] = 1] = "Branch";
54
+ BranchType[BranchType["Join"] = 2] = "Join";
55
+ })(BranchType || (BranchType = {}));
@@ -79,6 +79,17 @@ export class LayoutEngine {
79
79
  }
80
80
  wireGroups.get(netName).push(wire);
81
81
  });
82
+ const { junctions, mergedWires } = this.findJunctions(wireGroups);
83
+ return {
84
+ components: placedComponents,
85
+ wires: placedWires,
86
+ mergedWires,
87
+ junctions,
88
+ frameObjects,
89
+ textObjects,
90
+ };
91
+ }
92
+ findJunctions(wireGroups) {
82
93
  const junctions = [];
83
94
  const mergedWires = [];
84
95
  for (const [key, wires] of wireGroups) {
@@ -101,12 +112,8 @@ export class LayoutEngine {
101
112
  });
102
113
  }
103
114
  return {
104
- components: placedComponents,
105
- wires: placedWires,
106
- mergedWires,
107
115
  junctions,
108
- frameObjects,
109
- textObjects,
116
+ mergedWires
110
117
  };
111
118
  }
112
119
  placeFrames(graph, subgraphInfo, frameObjects) {
@@ -402,7 +409,7 @@ export class LayoutEngine {
402
409
  currentFrame && currentFrame.innerItems.push(tmpComponent);
403
410
  }
404
411
  if (action === SequenceAction.To) {
405
- graph.setEdge(previousNode, tmpInstanceName, makeEdgeValue(previousNode, previousPin, tmpInstanceName, pin, i));
412
+ this.setGraphEdge(graph, previousNode, tmpInstanceName, makeEdgeValue(previousNode, previousPin, tmpInstanceName, pin, i));
406
413
  }
407
414
  previousNode = tmpInstanceName;
408
415
  previousPin = pin;
@@ -427,7 +434,7 @@ export class LayoutEngine {
427
434
  wire.netName = useNetName;
428
435
  const wireName = getWireName(wire.id);
429
436
  graph.setNode(wireName, [RenderItemType.Wire, wire, i]);
430
- graph.setEdge(previousNode, wireName, makeEdgeValue(previousNode, previousPin, wireName, 0, i));
437
+ this.setGraphEdge(graph, previousNode, wireName, makeEdgeValue(previousNode, previousPin, wireName, 0, i));
431
438
  previousNode = wireName;
432
439
  previousPin = 1;
433
440
  const wireSegmentsInfo = wireSegments.map(item => {
@@ -447,9 +454,14 @@ export class LayoutEngine {
447
454
  }
448
455
  else if (action === SequenceAction.WireJump) {
449
456
  this.print(...sequence[i]);
450
- const [, wireId] = sequence[i];
451
- previousNode = getWireName(wireId);
452
- previousPin = 1;
457
+ const wireId = sequence[i][1];
458
+ const wireName = getWireName(wireId);
459
+ let wirePin = 1;
460
+ if (sequence[i].length === 3) {
461
+ wirePin = sequence[i][2];
462
+ }
463
+ previousNode = wireName;
464
+ previousPin = wirePin;
453
465
  }
454
466
  else if (action === SequenceAction.Frame) {
455
467
  const [, frameObject, frameAction] = sequence[i];
@@ -482,6 +494,9 @@ export class LayoutEngine {
482
494
  containerFrames,
483
495
  };
484
496
  }
497
+ setGraphEdge(graph, node1, node2, edgeValue) {
498
+ graph.setEdge(node1, node2, edgeValue);
499
+ }
485
500
  sizeSubGraphs(graph) {
486
501
  const subGraphs = graphlib.alg.components(graph);
487
502
  const subGraphsStarts = [];
@@ -613,9 +628,8 @@ export class LayoutEngine {
613
628
  if (x1 !== x2 && y1 !== y2) {
614
629
  if (node1 instanceof RenderWire &&
615
630
  node2 instanceof RenderComponent) {
616
- this.layoutWarnings.push('component ' +
617
- node2.component.instanceName +
618
- ' may not be placed correctly');
631
+ const refdes = node2.component.assignedRefDes;
632
+ this.layoutWarnings.push(`component ${refdes} may not be placed correctly`);
619
633
  }
620
634
  }
621
635
  }
@@ -8,7 +8,7 @@ import { PinDefinition, PinIdType } from './objects/PinDefinition.js';
8
8
  import { PinTypes } from './objects/PinTypes.js';
9
9
  import { UndeclaredReference } from './objects/types.js';
10
10
  import { Logger } from './logger.js';
11
- import { ComponentTypes } from './globals.js';
11
+ import { BranchType, ComponentTypes, NoNetText } from './globals.js';
12
12
  import { SymbolDrawingCommands } from './draw_symbols.js';
13
13
  import { parseFileWithVisitor } from './parser.js';
14
14
  export class MainVisitor extends ParseTreeVisitor {
@@ -223,8 +223,18 @@ export class MainVisitor extends ParseTreeVisitor {
223
223
  }
224
224
  }
225
225
  visitBranch_blocks(ctx) {
226
- this.getExecutor().enterBranches();
227
226
  const branches = ctx.branch_block_inner_list();
227
+ let branchType = BranchType.Branch;
228
+ if (branches.length > 0) {
229
+ const firstBranch = branches[0];
230
+ if (firstBranch.Branch()) {
231
+ branchType = BranchType.Branch;
232
+ }
233
+ else if (firstBranch.Join()) {
234
+ branchType = BranchType.Join;
235
+ }
236
+ }
237
+ this.getExecutor().enterBranches(branchType);
228
238
  branches.forEach((branch, index) => {
229
239
  this.getExecutor().enterBranch(index);
230
240
  this.visit(branch);
@@ -945,8 +955,8 @@ export class MainVisitor extends ParseTreeVisitor {
945
955
  resolveNets(scope, instance) {
946
956
  const result = [];
947
957
  for (const [pinId, pin] of instance.pins) {
948
- let netName = 'NO_NET';
949
- let netBaseName = 'NO_NET';
958
+ let netName = NoNetText;
959
+ let netBaseName = NoNetText;
950
960
  if (scope.hasNet(instance, pinId)) {
951
961
  const netObject = scope.getNet(instance, pinId);
952
962
  netName = netObject.namespace + netObject.name;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "circuitscript",
3
- "version": "0.0.17",
3
+ "version": "0.0.18",
4
4
  "description": "Interpreter for the circuitscript language",
5
5
  "homepage": "https://circuitscript.net",
6
6
  "engines": {
@@ -21,6 +21,7 @@ Point: 'point';
21
21
  Return: 'return';
22
22
  Define: 'def';
23
23
  Import: 'import';
24
+ Join: 'join';
24
25
 
25
26
  If: 'if';
26
27
  Not: '!';
@@ -57,7 +58,7 @@ expression: add_component_expr
57
58
 
58
59
  branch_blocks: branch_block_inner+;
59
60
  branch_block_inner:
60
- Branch ':' NEWLINE INDENT (NEWLINE | expression)+ DEDENT;
61
+ (Branch|Join) ':' NEWLINE INDENT (NEWLINE | expression)+ DEDENT;
61
62
 
62
63
  property_set_expr2:
63
64
  atom_expr ':' NEWLINE INDENT ( NEWLINE | assignment_expr2)+ DEDENT;