circuitscript 0.0.17 → 0.0.19

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,7 +15,7 @@ export class ExecutionScope {
15
15
 
16
16
  variables: Map<string, ValueType | ClassComponent> = new Map();
17
17
 
18
- branchStack: Map<number, any> = new Map();
18
+ blockStack: Map<number, any> = new Map();
19
19
 
20
20
  wires: Wire[] = [];
21
21
  frames: Frame[] = [];
@@ -165,12 +165,20 @@ export class ExecutionScope {
165
165
  }
166
166
 
167
167
  export enum SequenceAction {
168
+ // Link current insertion point to component pin
168
169
  To = 'to',
170
+
171
+ // Move insertion point at component pin
169
172
  At = 'at',
173
+
174
+ // Link current insertion point with wire of given segments
170
175
  Wire = 'wire',
171
176
 
177
+ // Jump to wire with target ID. Pin 0 of wire is the start of the
178
+ // wire, pin 1 is the other end of the wire.
172
179
  WireJump = 'wire-jump',
173
180
 
181
+ // Creates a new frame group
174
182
  Frame = 'frame',
175
183
  }
176
184
 
@@ -187,7 +195,7 @@ export enum ActiveObject {
187
195
 
188
196
  export type SequenceItem =
189
197
  [SequenceAction.To | SequenceAction.At, ClassComponent, number, LayoutDirection?, string?]
190
- | [SequenceAction.Wire, number, WireSegment[]]
191
- | [SequenceAction.WireJump, number]
198
+ | [SequenceAction.Wire, wireId: number, WireSegment[]]
199
+ | [SequenceAction.WireJump, wireId: number, pinId: number]
192
200
  | [SequenceAction.Frame, Frame, "enter" | "exit"]
193
201
  ;
package/src/visitor.ts CHANGED
@@ -15,7 +15,7 @@ import {
15
15
  Atom_exprContext,
16
16
  BinaryOperatorExprContext,
17
17
  Blank_exprContext,
18
- Branch_blocksContext,
18
+ Path_blocksContext,
19
19
  Component_select_exprContext,
20
20
  Create_component_exprContext,
21
21
  Create_graphic_exprContext,
@@ -59,10 +59,10 @@ import {
59
59
  import { PinDefinition, PinIdType } from './objects/PinDefinition.js';
60
60
  import { PinTypes } from './objects/PinTypes.js';
61
61
  import { ExecutionScope } from './objects/ExecutionScope.js';
62
- import { CFunction, CFunctionOptions, CallableParameter, ComplexType, ComponentPin,
62
+ import { CFunctionOptions, CallableParameter, ComplexType, ComponentPin,
63
63
  ComponentPinNet, FunctionDefinedParameter, ReferenceType, UndeclaredReference, ValueType } from './objects/types.js';
64
64
  import { Logger } from './logger.js';
65
- import { ComponentTypes } from './globals.js';
65
+ import { BlockTypes, ComponentTypes, NoNetText } from './globals.js';
66
66
  import { Net } from './objects/Net.js';
67
67
  import { SubExpressionCommand, SymbolDrawingCommands } from './draw_symbols.js';
68
68
  import { parseFileWithVisitor } from './parser.js';
@@ -303,36 +303,48 @@ export class MainVisitor extends ParseTreeVisitor<any> {
303
303
  }
304
304
 
305
305
  visitAt_component_expr(ctx: At_component_exprContext): ComponentPin {
306
- const [component, pin] = this.visit(ctx.component_select_expr());
306
+ if (ctx.Point()) {
307
+ this.getExecutor().atPointBlock();
307
308
 
308
- const currentPoint = this.getExecutor().atComponent(component, pin, {
309
- addSequence: true,
310
- cloneNetComponent: true
311
- });
312
-
313
- if (ctx.ID()){
314
- // If there is ID specified, then it can only be for the
315
- // component orientation.
316
- this.setComponentOrientation(currentPoint[0],
317
- currentPoint[1], ctx.ID().getText())
309
+ } else {
310
+ const [component, pin] = this.visit(ctx.component_select_expr());
311
+
312
+ const currentPoint = this.getExecutor().atComponent(component, pin, {
313
+ addSequence: true,
314
+ cloneNetComponent: true
315
+ });
316
+
317
+ if (ctx.ID()) {
318
+ // If there is ID specified, then it can only be for the
319
+ // component orientation.
320
+ this.setComponentOrientation(currentPoint[0],
321
+ currentPoint[1], ctx.ID().getText())
322
+ }
318
323
  }
319
-
320
- return currentPoint;
324
+
325
+ return this.getExecutor().getCurrentPoint();
321
326
  }
322
327
 
323
- visitTo_component_expr(ctx: To_component_exprContext): ComponentPin {
328
+ visitTo_component_expr(ctx: To_component_exprContext): ComponentPin {
324
329
  let currentPoint: ComponentPin;
325
- ctx.component_select_expr_list().forEach((item) => {
326
- const [component, pin] = this.visit(item);
327
- currentPoint = this.getExecutor().toComponent(component, pin, {
328
- addSequence: true, cloneNetComponent: true});
329
- });
330
330
 
331
- if (ctx.ID()){
332
- // If there is ID specified, then it can only be for the
333
- // component orientation.
334
- this.setComponentOrientation(currentPoint[0],
335
- currentPoint[1], ctx.ID().getText())
331
+ if (ctx.Point()) {
332
+ this.getExecutor().toPointBlock();
333
+
334
+ } else {
335
+ ctx.component_select_expr_list().forEach((item) => {
336
+ const [component, pin] = this.visit(item);
337
+ currentPoint = this.getExecutor().toComponent(component, pin, {
338
+ addSequence: true, cloneNetComponent: true
339
+ });
340
+ });
341
+
342
+ if (ctx.ID()) {
343
+ // If there is ID specified, then it can only be for the
344
+ // component orientation.
345
+ this.setComponentOrientation(currentPoint[0],
346
+ currentPoint[1], ctx.ID().getText())
347
+ }
336
348
  }
337
349
 
338
350
  return this.getExecutor().getCurrentPoint();
@@ -352,19 +364,34 @@ export class MainVisitor extends ParseTreeVisitor<any> {
352
364
  }
353
365
  }
354
366
 
355
- visitBranch_blocks(ctx: Branch_blocksContext): ComponentPin {
356
- this.getExecutor().enterBranches();
367
+ visitPath_blocks(ctx: Path_blocksContext): ComponentPin {
368
+ const blocks = ctx.path_block_inner_list();
369
+ let blockType = BlockTypes.Branch;
370
+
371
+ if (blocks.length > 0){
372
+ const firstBlock = blocks[0];
373
+ if (firstBlock.Branch()){
374
+ blockType = BlockTypes.Branch
375
+ } else if (firstBlock.Join()){
376
+ blockType = BlockTypes.Join;
377
+ } else if (firstBlock.Parallel()){
378
+ blockType = BlockTypes.Parallel;
379
+ } else if (firstBlock.Point()){
380
+ blockType = BlockTypes.Point;
381
+ }
382
+ }
383
+
384
+ this.getExecutor().enterBlocks(blockType);
357
385
 
358
- const branches = ctx.branch_block_inner_list();
359
- branches.forEach((branch, index) => {
360
- this.getExecutor().enterBranch(index);
386
+ blocks.forEach((branch, index) => {
387
+ this.getExecutor().enterBlock(index);
361
388
 
362
389
  this.visit(branch);
363
390
 
364
- this.getExecutor().exitBranch(index);
391
+ this.getExecutor().exitBlock(index);
365
392
  });
366
393
 
367
- this.getExecutor().exitBranches();
394
+ this.getExecutor().exitBlocks();
368
395
  return this.getExecutor().getCurrentPoint();
369
396
  }
370
397
 
@@ -733,7 +760,7 @@ export class MainVisitor extends ParseTreeVisitor<any> {
733
760
 
734
761
  // Function execution is completed, get the last executor
735
762
  const lastExecution = executionStack.pop();
736
-
763
+
737
764
  // Merge what ever was created in the scope with the outer scope
738
765
  const nextLastExecution = executionStack[executionStack.length - 1];
739
766
  nextLastExecution.mergeScope(
@@ -1396,8 +1423,8 @@ export class MainVisitor extends ParseTreeVisitor<any> {
1396
1423
  const result = [];
1397
1424
 
1398
1425
  for (const [pinId, pin] of instance.pins) {
1399
- let netName = 'NO_NET';
1400
- let netBaseName = 'NO_NET';
1426
+ let netName = NoNetText;
1427
+ let netBaseName = NoNetText;
1401
1428
 
1402
1429
  if (scope.hasNet(instance, pinId)) {
1403
1430
  const netObject = scope.getNet(instance, pinId);