circuitscript 0.1.13 → 0.1.14

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.
@@ -48,7 +48,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
48
48
  }
49
49
  const result = this.runExpressions(this.getExecutor(), ctx.expression());
50
50
  this.setResult(ctx, result);
51
- this.getExecutor().closeAllBlocks();
51
+ this.getExecutor().closeOpenPathBlocks();
52
52
  this.log('===', 'end', '===');
53
53
  };
54
54
  this.visitAssignment_expr = (ctx) => {
@@ -669,7 +669,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
669
669
  const executionLevel = currentExecutionContext.executionLevel;
670
670
  const executionContextNamespace = currentExecutionContext.namespace
671
671
  + executionContextName + ".";
672
- const newExecutor = new execute_js_1.ExecutionContext(executionContextName, executionContextNamespace, netNamespace, executionLevel + 1, this.getExecutor().scope.indentLevel + 1, currentExecutionContext.silent, currentExecutionContext.logger, currentExecutionContext.warnings, parentContext);
672
+ const newExecutor = new execute_js_1.ExecutionContext(executionContextName, executionContextNamespace, netNamespace, executionLevel + 1, this.getExecutor().scope.scopeLevel + 1, currentExecutionContext.silent, currentExecutionContext.logger, currentExecutionContext.warnings, parentContext);
673
673
  executionStack.push(newExecutor);
674
674
  this.setupDefinedParameters(funcDefinedParameters, passedInParameters, newExecutor);
675
675
  return newExecutor;
@@ -15,7 +15,7 @@ const helpers_js_1 = require("./helpers.js");
15
15
  const draw_symbols_js_1 = require("./draw_symbols.js");
16
16
  const utils_js_1 = require("./utils.js");
17
17
  class ExecutionContext {
18
- constructor(name, namespace, netNamespace, executionLevel = 0, indentLevel = 0, silent = false, logger, warnings, parent) {
18
+ constructor(name, namespace, netNamespace, executionLevel = 0, scopeLevel = 0, silent = false, logger, warnings, parent) {
19
19
  this.tmpPointId = 0;
20
20
  this.resolveNet = null;
21
21
  this.stopFurtherExpressions = false;
@@ -30,10 +30,10 @@ class ExecutionContext {
30
30
  this.executionLevel = executionLevel;
31
31
  this.logger = logger;
32
32
  this.scope = ExecutionScope_js_1.ExecutionScope.create();
33
- this.scope.indentLevel = indentLevel;
33
+ this.scope.scopeLevel = scopeLevel;
34
34
  this.setupRoot();
35
35
  this.silent = silent;
36
- this.log('create new execution context', this.namespace, this.name, this.scope.indentLevel);
36
+ this.log('create new execution context', this.namespace, this.name, this.scope.scopeLevel);
37
37
  this.parentContext = parent;
38
38
  this.warnings = warnings;
39
39
  }
@@ -45,8 +45,8 @@ class ExecutionContext {
45
45
  });
46
46
  }
47
47
  log(...params) {
48
- const indentOutput = ''.padStart(this.scope.indentLevel * 4, ' ');
49
- const indentLevelText = this.scope.indentLevel
48
+ const indentOutput = ''.padStart(this.scope.scopeLevel * 4, ' ');
49
+ const indentLevelText = this.scope.scopeLevel
50
50
  .toString()
51
51
  .padStart(3, ' ');
52
52
  const args = ['[' + indentLevelText + ']', indentOutput, ...params];
@@ -398,7 +398,7 @@ class ExecutionContext {
398
398
  this.addPoint(`${globals_js_1.Delimiter1}${key}.${this.name}.${this.tmpPointId}`, false);
399
399
  this.tmpPointId += 1;
400
400
  }
401
- this.scope.blockStack.set(this.scope.indentLevel, {
401
+ this.scope.blockStack.set(this.scope.scopeLevel, {
402
402
  start_point: [
403
403
  this.scope.currentComponent,
404
404
  this.scope.currentPin,
@@ -411,8 +411,11 @@ class ExecutionContext {
411
411
  });
412
412
  this.log('enter blocks');
413
413
  }
414
- exitBlocks() {
415
- const stackRef = this.scope.blockStack.get(this.scope.indentLevel);
414
+ exitBlocks(scopeLevel = null) {
415
+ if (scopeLevel === null) {
416
+ scopeLevel = this.scope.scopeLevel;
417
+ }
418
+ const stackRef = this.scope.blockStack.get(scopeLevel);
416
419
  const { type: blockType } = stackRef;
417
420
  if (blockType === globals_js_1.BlockTypes.Join || blockType === globals_js_1.BlockTypes.Parallel) {
418
421
  const { end_point: finalPoint } = stackRef;
@@ -429,16 +432,18 @@ class ExecutionContext {
429
432
  const { start_point: [component, pin,] } = stackRef;
430
433
  this.atComponent(component, pin, { addSequence: true });
431
434
  }
432
- this.scope.blockStack.delete(this.scope.indentLevel);
435
+ this.scope.blockStack.delete(scopeLevel);
433
436
  this.log('exit blocks');
434
437
  }
435
- closeAllBlocks() {
436
- if (this.scope.blockStack.has(this.scope.indentLevel)) {
438
+ closeOpenPathBlocks() {
439
+ const scope = this.scope;
440
+ const scopeLevel = scope.scopeLevel;
441
+ if (scope.blockStack.has(scopeLevel)) {
437
442
  this.exitBlocks();
438
443
  }
439
444
  }
440
445
  enterBlock(blockIndex) {
441
- const stackRef = this.scope.blockStack.get(this.scope.indentLevel);
446
+ const stackRef = this.scope.blockStack.get(this.scope.scopeLevel);
442
447
  const { type: blockType } = stackRef;
443
448
  const blockTypeName = (0, utils_js_1.getBlockTypeString)(blockType);
444
449
  stackRef.inner_blocks.set(blockIndex, {
@@ -454,10 +459,10 @@ class ExecutionContext {
454
459
  this.atComponent(component, pin, { addSequence: true });
455
460
  }
456
461
  this.log(`enter inner block of type (${blockTypeName}) >>>`);
457
- this.scope.indentLevel += 1;
462
+ this.scope.scopeLevel += 1;
458
463
  }
459
464
  exitBlock(blockIndex) {
460
- const stackRef = this.scope.blockStack.get(this.scope.indentLevel - 1);
465
+ const stackRef = this.scope.blockStack.get(this.scope.scopeLevel - 1);
461
466
  const { type: blockType } = stackRef;
462
467
  const blockIndexRef = stackRef.inner_blocks.get(blockIndex);
463
468
  blockIndexRef.last_net = [
@@ -465,7 +470,7 @@ class ExecutionContext {
465
470
  this.scope.currentPin,
466
471
  this.scope.currentWireId
467
472
  ];
468
- this.scope.indentLevel -= 1;
473
+ this.scope.scopeLevel -= 1;
469
474
  this.log('exit inner block <<<');
470
475
  if (blockType === globals_js_1.BlockTypes.Branch) {
471
476
  const { start_point: [component, pin, wireId] } = stackRef;
@@ -506,8 +511,8 @@ class ExecutionContext {
506
511
  }
507
512
  getPointBlockLocation() {
508
513
  this.log('get block point');
509
- for (let i = 0; i < this.scope.indentLevel; i++) {
510
- const stackRef = this.scope.blockStack.get(this.scope.indentLevel - 1 - i);
514
+ for (let i = 0; i < this.scope.scopeLevel; i++) {
515
+ const stackRef = this.scope.blockStack.get(this.scope.scopeLevel - 1 - i);
511
516
  const { start_point } = stackRef;
512
517
  const component = start_point[0];
513
518
  if (component.instanceName.startsWith(`${globals_js_1.Delimiter1}point.`)) {
@@ -15,7 +15,7 @@ class ExecutionScope {
15
15
  this.breakStack = [];
16
16
  this.wires = [];
17
17
  this.frames = [];
18
- this.indentLevel = 0;
18
+ this.scopeLevel = 0;
19
19
  this.netCounter = 1;
20
20
  this.unnamedCounter = 1;
21
21
  this.currentComponent = null;
@@ -104,17 +104,17 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
104
104
  }
105
105
  const scope = this.getScope();
106
106
  const executor = this.getExecutor();
107
- const indentLevel = scope.indentLevel;
108
- if (scope.blockStack.has(indentLevel)) {
109
- const blockStackEntry = scope.blockStack.get(indentLevel);
107
+ const scopeLevel = scope.scopeLevel;
108
+ if (scope.blockStack.has(scopeLevel)) {
109
+ const blockStackEntry = scope.blockStack.get(scopeLevel);
110
110
  if (blockStackEntry.type !== blockType) {
111
111
  executor.exitBlocks();
112
112
  }
113
113
  }
114
- if (!scope.blockStack.has(indentLevel)) {
114
+ if (!scope.blockStack.has(scopeLevel)) {
115
115
  executor.enterBlocks(blockType);
116
116
  }
117
- const blockStackEntry = scope.blockStack.get(indentLevel);
117
+ const blockStackEntry = scope.blockStack.get(scopeLevel);
118
118
  const { current_index } = blockStackEntry;
119
119
  executor.enterBlock(current_index);
120
120
  this.visit(ctx.expressions_block());
@@ -122,12 +122,9 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
122
122
  blockStackEntry.current_index++;
123
123
  };
124
124
  this.visitGraph_expressions = (ctx) => {
125
+ this.getExecutor().log('graph expressions', this.getScope().scopeLevel);
125
126
  if (ctx.path_block() === null) {
126
- const scope = this.getScope();
127
- const indentLevel = scope.indentLevel;
128
- if (scope.blockStack.has(indentLevel)) {
129
- this.getExecutor().exitBlocks();
130
- }
127
+ this.getExecutor().closeOpenPathBlocks();
131
128
  }
132
129
  const ctxPathBlock = ctx.path_block();
133
130
  const ctxNotPathBlock = ctx.graph_linear_expression();
@@ -818,9 +815,10 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
818
815
  this.setResult(ctx, result);
819
816
  };
820
817
  this.visitAt_block_pin_expr = (ctx) => {
821
- const atPin = this.visitResult(ctx.pin_select_expr2());
822
818
  const executor = this.getExecutor();
823
819
  const [currentComponent, currentPin] = executor.getCurrentPoint();
820
+ executor.closeOpenPathBlocks();
821
+ const atPin = this.visitResult(ctx.pin_select_expr2());
824
822
  executor.atComponent(currentComponent, atPin, {
825
823
  addSequence: true
826
824
  });
@@ -841,11 +839,11 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
841
839
  executor.log('entering at block');
842
840
  this.visit(ctx.at_component_expr());
843
841
  const [currentComponent, currentPin] = executor.getCurrentPoint();
844
- executor.scope.indentLevel += 1;
842
+ executor.scope.scopeLevel += 1;
845
843
  ctx.at_block_expressions().forEach(expression => {
846
844
  this.visit(expression);
847
845
  });
848
- executor.scope.indentLevel -= 1;
846
+ executor.scope.scopeLevel -= 1;
849
847
  executor.scope.setCurrent(currentComponent, currentPin);
850
848
  executor.log('leaving at block');
851
849
  };
@@ -127,7 +127,7 @@ export class BaseVisitor extends CircuitScriptVisitor {
127
127
  }
128
128
  const result = this.runExpressions(this.getExecutor(), ctx.expression());
129
129
  this.setResult(ctx, result);
130
- this.getExecutor().closeAllBlocks();
130
+ this.getExecutor().closeOpenPathBlocks();
131
131
  this.log('===', 'end', '===');
132
132
  };
133
133
  visitAssignment_expr = (ctx) => {
@@ -670,7 +670,7 @@ export class BaseVisitor extends CircuitScriptVisitor {
670
670
  const executionLevel = currentExecutionContext.executionLevel;
671
671
  const executionContextNamespace = currentExecutionContext.namespace
672
672
  + executionContextName + ".";
673
- const newExecutor = new ExecutionContext(executionContextName, executionContextNamespace, netNamespace, executionLevel + 1, this.getExecutor().scope.indentLevel + 1, currentExecutionContext.silent, currentExecutionContext.logger, currentExecutionContext.warnings, parentContext);
673
+ const newExecutor = new ExecutionContext(executionContextName, executionContextNamespace, netNamespace, executionLevel + 1, this.getExecutor().scope.scopeLevel + 1, currentExecutionContext.silent, currentExecutionContext.logger, currentExecutionContext.warnings, parentContext);
674
674
  executionStack.push(newExecutor);
675
675
  this.setupDefinedParameters(funcDefinedParameters, passedInParameters, newExecutor);
676
676
  return newExecutor;
@@ -28,17 +28,17 @@ export class ExecutionContext {
28
28
  parentContext;
29
29
  componentAngleFollowsWire = true;
30
30
  warnings = [];
31
- constructor(name, namespace, netNamespace, executionLevel = 0, indentLevel = 0, silent = false, logger, warnings, parent) {
31
+ constructor(name, namespace, netNamespace, executionLevel = 0, scopeLevel = 0, silent = false, logger, warnings, parent) {
32
32
  this.name = name;
33
33
  this.namespace = namespace;
34
34
  this.netNamespace = netNamespace;
35
35
  this.executionLevel = executionLevel;
36
36
  this.logger = logger;
37
37
  this.scope = ExecutionScope.create();
38
- this.scope.indentLevel = indentLevel;
38
+ this.scope.scopeLevel = scopeLevel;
39
39
  this.setupRoot();
40
40
  this.silent = silent;
41
- this.log('create new execution context', this.namespace, this.name, this.scope.indentLevel);
41
+ this.log('create new execution context', this.namespace, this.name, this.scope.scopeLevel);
42
42
  this.parentContext = parent;
43
43
  this.warnings = warnings;
44
44
  }
@@ -50,8 +50,8 @@ export class ExecutionContext {
50
50
  });
51
51
  }
52
52
  log(...params) {
53
- const indentOutput = ''.padStart(this.scope.indentLevel * 4, ' ');
54
- const indentLevelText = this.scope.indentLevel
53
+ const indentOutput = ''.padStart(this.scope.scopeLevel * 4, ' ');
54
+ const indentLevelText = this.scope.scopeLevel
55
55
  .toString()
56
56
  .padStart(3, ' ');
57
57
  const args = ['[' + indentLevelText + ']', indentOutput, ...params];
@@ -403,7 +403,7 @@ export class ExecutionContext {
403
403
  this.addPoint(`${Delimiter1}${key}.${this.name}.${this.tmpPointId}`, false);
404
404
  this.tmpPointId += 1;
405
405
  }
406
- this.scope.blockStack.set(this.scope.indentLevel, {
406
+ this.scope.blockStack.set(this.scope.scopeLevel, {
407
407
  start_point: [
408
408
  this.scope.currentComponent,
409
409
  this.scope.currentPin,
@@ -416,8 +416,11 @@ export class ExecutionContext {
416
416
  });
417
417
  this.log('enter blocks');
418
418
  }
419
- exitBlocks() {
420
- const stackRef = this.scope.blockStack.get(this.scope.indentLevel);
419
+ exitBlocks(scopeLevel = null) {
420
+ if (scopeLevel === null) {
421
+ scopeLevel = this.scope.scopeLevel;
422
+ }
423
+ const stackRef = this.scope.blockStack.get(scopeLevel);
421
424
  const { type: blockType } = stackRef;
422
425
  if (blockType === BlockTypes.Join || blockType === BlockTypes.Parallel) {
423
426
  const { end_point: finalPoint } = stackRef;
@@ -434,16 +437,18 @@ export class ExecutionContext {
434
437
  const { start_point: [component, pin,] } = stackRef;
435
438
  this.atComponent(component, pin, { addSequence: true });
436
439
  }
437
- this.scope.blockStack.delete(this.scope.indentLevel);
440
+ this.scope.blockStack.delete(scopeLevel);
438
441
  this.log('exit blocks');
439
442
  }
440
- closeAllBlocks() {
441
- if (this.scope.blockStack.has(this.scope.indentLevel)) {
443
+ closeOpenPathBlocks() {
444
+ const scope = this.scope;
445
+ const scopeLevel = scope.scopeLevel;
446
+ if (scope.blockStack.has(scopeLevel)) {
442
447
  this.exitBlocks();
443
448
  }
444
449
  }
445
450
  enterBlock(blockIndex) {
446
- const stackRef = this.scope.blockStack.get(this.scope.indentLevel);
451
+ const stackRef = this.scope.blockStack.get(this.scope.scopeLevel);
447
452
  const { type: blockType } = stackRef;
448
453
  const blockTypeName = getBlockTypeString(blockType);
449
454
  stackRef.inner_blocks.set(blockIndex, {
@@ -459,10 +464,10 @@ export class ExecutionContext {
459
464
  this.atComponent(component, pin, { addSequence: true });
460
465
  }
461
466
  this.log(`enter inner block of type (${blockTypeName}) >>>`);
462
- this.scope.indentLevel += 1;
467
+ this.scope.scopeLevel += 1;
463
468
  }
464
469
  exitBlock(blockIndex) {
465
- const stackRef = this.scope.blockStack.get(this.scope.indentLevel - 1);
470
+ const stackRef = this.scope.blockStack.get(this.scope.scopeLevel - 1);
466
471
  const { type: blockType } = stackRef;
467
472
  const blockIndexRef = stackRef.inner_blocks.get(blockIndex);
468
473
  blockIndexRef.last_net = [
@@ -470,7 +475,7 @@ export class ExecutionContext {
470
475
  this.scope.currentPin,
471
476
  this.scope.currentWireId
472
477
  ];
473
- this.scope.indentLevel -= 1;
478
+ this.scope.scopeLevel -= 1;
474
479
  this.log('exit inner block <<<');
475
480
  if (blockType === BlockTypes.Branch) {
476
481
  const { start_point: [component, pin, wireId] } = stackRef;
@@ -511,8 +516,8 @@ export class ExecutionContext {
511
516
  }
512
517
  getPointBlockLocation() {
513
518
  this.log('get block point');
514
- for (let i = 0; i < this.scope.indentLevel; i++) {
515
- const stackRef = this.scope.blockStack.get(this.scope.indentLevel - 1 - i);
519
+ for (let i = 0; i < this.scope.scopeLevel; i++) {
520
+ const stackRef = this.scope.blockStack.get(this.scope.scopeLevel - 1 - i);
516
521
  const { start_point } = stackRef;
517
522
  const component = start_point[0];
518
523
  if (component.instanceName.startsWith(`${Delimiter1}point.`)) {
@@ -12,7 +12,7 @@ export class ExecutionScope {
12
12
  breakStack = [];
13
13
  wires = [];
14
14
  frames = [];
15
- indentLevel = 0;
15
+ scopeLevel = 0;
16
16
  netCounter = 1;
17
17
  unnamedCounter = 1;
18
18
  currentComponent = null;
@@ -99,17 +99,17 @@ export class ParserVisitor extends BaseVisitor {
99
99
  }
100
100
  const scope = this.getScope();
101
101
  const executor = this.getExecutor();
102
- const indentLevel = scope.indentLevel;
103
- if (scope.blockStack.has(indentLevel)) {
104
- const blockStackEntry = scope.blockStack.get(indentLevel);
102
+ const scopeLevel = scope.scopeLevel;
103
+ if (scope.blockStack.has(scopeLevel)) {
104
+ const blockStackEntry = scope.blockStack.get(scopeLevel);
105
105
  if (blockStackEntry.type !== blockType) {
106
106
  executor.exitBlocks();
107
107
  }
108
108
  }
109
- if (!scope.blockStack.has(indentLevel)) {
109
+ if (!scope.blockStack.has(scopeLevel)) {
110
110
  executor.enterBlocks(blockType);
111
111
  }
112
- const blockStackEntry = scope.blockStack.get(indentLevel);
112
+ const blockStackEntry = scope.blockStack.get(scopeLevel);
113
113
  const { current_index } = blockStackEntry;
114
114
  executor.enterBlock(current_index);
115
115
  this.visit(ctx.expressions_block());
@@ -117,12 +117,9 @@ export class ParserVisitor extends BaseVisitor {
117
117
  blockStackEntry.current_index++;
118
118
  };
119
119
  visitGraph_expressions = (ctx) => {
120
+ this.getExecutor().log('graph expressions', this.getScope().scopeLevel);
120
121
  if (ctx.path_block() === null) {
121
- const scope = this.getScope();
122
- const indentLevel = scope.indentLevel;
123
- if (scope.blockStack.has(indentLevel)) {
124
- this.getExecutor().exitBlocks();
125
- }
122
+ this.getExecutor().closeOpenPathBlocks();
126
123
  }
127
124
  const ctxPathBlock = ctx.path_block();
128
125
  const ctxNotPathBlock = ctx.graph_linear_expression();
@@ -863,9 +860,10 @@ export class ParserVisitor extends BaseVisitor {
863
860
  this.setResult(ctx, result);
864
861
  };
865
862
  visitAt_block_pin_expr = (ctx) => {
866
- const atPin = this.visitResult(ctx.pin_select_expr2());
867
863
  const executor = this.getExecutor();
868
864
  const [currentComponent, currentPin] = executor.getCurrentPoint();
865
+ executor.closeOpenPathBlocks();
866
+ const atPin = this.visitResult(ctx.pin_select_expr2());
869
867
  executor.atComponent(currentComponent, atPin, {
870
868
  addSequence: true
871
869
  });
@@ -886,11 +884,11 @@ export class ParserVisitor extends BaseVisitor {
886
884
  executor.log('entering at block');
887
885
  this.visit(ctx.at_component_expr());
888
886
  const [currentComponent, currentPin] = executor.getCurrentPoint();
889
- executor.scope.indentLevel += 1;
887
+ executor.scope.scopeLevel += 1;
890
888
  ctx.at_block_expressions().forEach(expression => {
891
889
  this.visit(expression);
892
890
  });
893
- executor.scope.indentLevel -= 1;
891
+ executor.scope.scopeLevel -= 1;
894
892
  executor.scope.setCurrent(currentComponent, currentPin);
895
893
  executor.log('leaving at block');
896
894
  };
@@ -30,7 +30,7 @@ export declare class ExecutionContext {
30
30
  parentContext: ExecutionContext;
31
31
  componentAngleFollowsWire: boolean;
32
32
  warnings: ExecutionWarning[];
33
- constructor(name: string, namespace: string, netNamespace: string, executionLevel: number | undefined, indentLevel: number | undefined, silent: boolean | undefined, logger: Logger, warnings: ExecutionWarning[], parent: ExecutionContext);
33
+ constructor(name: string, namespace: string, netNamespace: string, executionLevel: number | undefined, scopeLevel: number | undefined, silent: boolean | undefined, logger: Logger, warnings: ExecutionWarning[], parent: ExecutionContext);
34
34
  logWarning(message: string, context?: ParserRuleContext, fileName?: string): void;
35
35
  log(...params: any[]): void;
36
36
  private setupRoot;
@@ -61,8 +61,8 @@ export declare class ExecutionContext {
61
61
  }): ComponentPin;
62
62
  copyComponent(component: ClassComponent): ClassComponent;
63
63
  enterBlocks(blockType: BlockTypes): void;
64
- exitBlocks(): void;
65
- closeAllBlocks(): void;
64
+ exitBlocks(scopeLevel?: number | null): void;
65
+ closeOpenPathBlocks(): void;
66
66
  enterBlock(blockIndex: number): void;
67
67
  exitBlock(blockIndex: number): void;
68
68
  atPointBlock(): void;
@@ -23,7 +23,7 @@ export declare class ExecutionScope {
23
23
  breakStack: ParserRuleContext[];
24
24
  wires: Wire[];
25
25
  frames: Frame[];
26
- indentLevel: number;
26
+ scopeLevel: number;
27
27
  netCounter: number;
28
28
  unnamedCounter: number;
29
29
  currentComponent: ClassComponent | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "circuitscript",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
4
4
  "description": "Interpreter for the circuitscript language",
5
5
  "homepage": "https://circuitscript.net",
6
6
  "engines": {