circuitscript 0.1.15 → 0.1.17

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 (49) hide show
  1. package/dist/cjs/BaseVisitor.js +98 -35
  2. package/dist/cjs/antlr/CircuitScriptLexer.js +3 -3
  3. package/dist/cjs/antlr/CircuitScriptParser.js +868 -757
  4. package/dist/cjs/builtinMethods.js +11 -1
  5. package/dist/cjs/draw_symbols.js +18 -17
  6. package/dist/cjs/execute.js +58 -31
  7. package/dist/cjs/globals.js +4 -1
  8. package/dist/cjs/graph.js +372 -0
  9. package/dist/cjs/helpers.js +6 -2
  10. package/dist/cjs/layout.js +18 -259
  11. package/dist/cjs/objects/ClassComponent.js +27 -20
  12. package/dist/cjs/objects/ExecutionScope.js +7 -2
  13. package/dist/cjs/objects/Net.js +1 -1
  14. package/dist/cjs/objects/PinDefinition.js +55 -3
  15. package/dist/cjs/objects/types.js +42 -6
  16. package/dist/cjs/visitor.js +88 -48
  17. package/dist/esm/BaseVisitor.js +98 -35
  18. package/dist/esm/antlr/CircuitScriptLexer.js +3 -3
  19. package/dist/esm/antlr/CircuitScriptParser.js +864 -755
  20. package/dist/esm/antlr/CircuitScriptVisitor.js +2 -0
  21. package/dist/esm/builtinMethods.js +11 -1
  22. package/dist/esm/draw_symbols.js +18 -17
  23. package/dist/esm/execute.js +60 -33
  24. package/dist/esm/globals.js +3 -0
  25. package/dist/esm/graph.js +344 -0
  26. package/dist/esm/helpers.js +6 -2
  27. package/dist/esm/layout.js +14 -235
  28. package/dist/esm/objects/ClassComponent.js +28 -21
  29. package/dist/esm/objects/ExecutionScope.js +7 -2
  30. package/dist/esm/objects/Net.js +1 -1
  31. package/dist/esm/objects/PinDefinition.js +53 -2
  32. package/dist/esm/objects/types.js +42 -6
  33. package/dist/esm/visitor.js +90 -50
  34. package/dist/libs/std.cst +3 -2
  35. package/dist/types/BaseVisitor.d.ts +5 -2
  36. package/dist/types/antlr/CircuitScriptParser.d.ts +42 -26
  37. package/dist/types/antlr/CircuitScriptVisitor.d.ts +4 -0
  38. package/dist/types/draw_symbols.d.ts +13 -7
  39. package/dist/types/execute.d.ts +12 -12
  40. package/dist/types/globals.d.ts +4 -1
  41. package/dist/types/graph.d.ts +29 -0
  42. package/dist/types/layout.d.ts +4 -9
  43. package/dist/types/objects/ClassComponent.d.ts +8 -8
  44. package/dist/types/objects/ExecutionScope.d.ts +8 -7
  45. package/dist/types/objects/Net.d.ts +2 -2
  46. package/dist/types/objects/PinDefinition.d.ts +17 -2
  47. package/dist/types/objects/types.d.ts +31 -7
  48. package/libs/std.cst +3 -2
  49. package/package.json +2 -1
@@ -1,7 +1,8 @@
1
1
  import { SymbolDrawingCommands } from '../draw_symbols.js';
2
- import { PinDefinition, PinIdType } from './PinDefinition.js';
2
+ import { PinDefinition, PinId, PinIdType } from './PinDefinition.js';
3
3
  import { PinTypes } from './PinTypes.js';
4
4
  import { ParamKeys } from '../globals.js';
5
+ import { RuntimeExecutionError } from '../utils.js';
5
6
  export class ClassComponent {
6
7
  instanceName;
7
8
  numPins;
@@ -35,47 +36,53 @@ export class ClassComponent {
35
36
  setupPins() {
36
37
  for (let i = 1; i < this.numPins + 1; i++) {
37
38
  const pinIndex = i;
38
- this.pins.set(pinIndex, new PinDefinition(pinIndex, PinIdType.Int, pinIndex.toString(), PinTypes.Any));
39
+ this.pins.set(new PinId(pinIndex), new PinDefinition(pinIndex, PinIdType.Int, pinIndex.toString(), PinTypes.Any));
39
40
  }
40
41
  this.refreshPinsCache();
41
42
  }
42
43
  getDefaultPin() {
43
- return 1;
44
+ const pins = Array.from(this.pins.keys());
45
+ pins.sort();
46
+ return pins[0];
44
47
  }
45
48
  hasPin(pinId) {
46
- if (typeof pinId === 'number') {
47
- return this.pins.has(pinId);
48
- }
49
- else {
50
- for (const [, pinDef] of this.pins) {
51
- if (pinDef.name === pinId ||
52
- pinDef.altNames.indexOf(pinId) !== -1) {
53
- return true;
54
- }
49
+ for (const [pin, pinDef] of this.pins) {
50
+ if (pin.equals(pinId)) {
51
+ return true;
52
+ }
53
+ if (pinId.getType() === PinIdType.Str && (pinDef.name === pinId.getValue() ||
54
+ pinDef.altNames.indexOf(pinId.getValue()) !== -1)) {
55
+ return true;
55
56
  }
56
57
  }
57
58
  return false;
58
59
  }
59
60
  getPin(pinId) {
60
- if (typeof pinId === 'number') {
61
- return pinId;
61
+ for (const [pin,] of this.pins) {
62
+ if (pin.equals(pinId)) {
63
+ return pin;
64
+ }
62
65
  }
63
- else {
66
+ if (pinId.getType() === PinIdType.Str) {
67
+ const pinIdStringValue = pinId.getValue();
64
68
  for (const [pin, pinDef] of this.pins) {
65
- if (pinDef.name === pinId ||
66
- pinDef.altNames.indexOf(pinId) !== -1) {
69
+ if (pinDef.name === pinIdStringValue ||
70
+ pinDef.altNames.indexOf(pinIdStringValue) !== -1) {
67
71
  return pin;
68
72
  }
69
73
  }
70
- return -1;
71
74
  }
75
+ throw new RuntimeExecutionError(`Could not find pin '${pinId}' on component '${this.instanceName}'`);
72
76
  }
73
77
  getNextPinAfter(pinIndex) {
74
- if (pinIndex + 1 <= this.numPins) {
75
- return pinIndex + 1;
78
+ const pins = Array.from(this.pins.keys());
79
+ pins.sort();
80
+ const index = pins.findIndex(tmp => tmp.equals(pinIndex));
81
+ if (index + 1 < pins.length) {
82
+ return pins[index + 1];
76
83
  }
77
84
  else {
78
- return 1;
85
+ return this.getDefaultPin();
79
86
  }
80
87
  }
81
88
  setParam(key, value) {
@@ -1,4 +1,6 @@
1
1
  import { Property_key_exprContext } from '../antlr/CircuitScriptParser.js';
2
+ import { PinId } from './PinDefinition.js';
3
+ import { RuntimeExecutionError } from '../utils.js';
2
4
  export class ExecutionScope {
3
5
  scopeId;
4
6
  nets = [];
@@ -32,8 +34,11 @@ export class ExecutionScope {
32
34
  return scope;
33
35
  }
34
36
  findNet(component, pin) {
37
+ if (!(pin instanceof PinId)) {
38
+ throw new RuntimeExecutionError('Invalid value for PinId: ' + pin);
39
+ }
35
40
  return this.nets.find(([tmpComponent, tmpPin]) => {
36
- return tmpComponent.isEqual(component) && tmpPin === pin;
41
+ return tmpComponent.isEqual(component) && tmpPin.equals(pin);
37
42
  });
38
43
  }
39
44
  getNetWithName(name) {
@@ -94,7 +99,7 @@ export class ExecutionScope {
94
99
  }
95
100
  });
96
101
  return sortedNet.map(([component, pin, net]) => {
97
- return [net.toString(), component.instanceName, pin];
102
+ return [net.toString(), component.instanceName, pin.value];
98
103
  });
99
104
  }
100
105
  printNets() {
@@ -5,7 +5,7 @@ export class Net {
5
5
  priority;
6
6
  type;
7
7
  params = new Map();
8
- constructor(namespace, name, priority = 0, type = null) {
8
+ constructor(namespace, name, priority = 0, type = 'any') {
9
9
  if (namespace.indexOf(' ') !== -1) {
10
10
  throw "Invalid net namespace provided";
11
11
  }
@@ -1,4 +1,47 @@
1
+ import { RuntimeExecutionError } from '../utils.js';
2
+ import { NumericValue } from './ParamDefinition.js';
1
3
  import { PinTypes } from './PinTypes.js';
4
+ export class PinId {
5
+ value;
6
+ type;
7
+ constructor(value) {
8
+ if (typeof value !== 'string' && typeof value !== 'number') {
9
+ throw new RuntimeExecutionError("Invalid value for PinId: " + value);
10
+ }
11
+ this.value = value;
12
+ this.type = typeof value === 'number' ? PinIdType.Int : PinIdType.Str;
13
+ }
14
+ getValue() {
15
+ return this.value;
16
+ }
17
+ getType() {
18
+ return this.type;
19
+ }
20
+ isNumeric() {
21
+ return this.type === PinIdType.Int;
22
+ }
23
+ isString() {
24
+ return this.type === PinIdType.Str;
25
+ }
26
+ toString() {
27
+ return this.value.toString();
28
+ }
29
+ equals(other) {
30
+ if (other instanceof PinId) {
31
+ return this.value === other.value;
32
+ }
33
+ return this.value === other;
34
+ }
35
+ static from(value) {
36
+ if (value instanceof NumericValue) {
37
+ return new PinId(value.toNumber());
38
+ }
39
+ return new PinId(value);
40
+ }
41
+ static isPinIdType(value) {
42
+ return (typeof value === 'number' || typeof value === 'string');
43
+ }
44
+ }
2
45
  export class PinDefinition {
3
46
  id;
4
47
  idType;
@@ -8,8 +51,8 @@ export class PinDefinition {
8
51
  side = PortSide.EAST;
9
52
  position = -1;
10
53
  constructor(id, idType, name, pinType = PinTypes.Any, altNames = []) {
11
- this.id = id;
12
- this.idType = idType;
54
+ this.id = id instanceof PinId ? id : new PinId(id);
55
+ this.idType = this.id.getType();
13
56
  this.pinType = pinType;
14
57
  this.name = name;
15
58
  this.altNames = altNames;
@@ -27,3 +70,11 @@ export var PortSide;
27
70
  PortSide["SOUTH"] = "SOUTH";
28
71
  PortSide["NORTH"] = "NORTH";
29
72
  })(PortSide || (PortSide = {}));
73
+ export function isPinId(item) {
74
+ return item instanceof PinId || (typeof item === 'number' || typeof item === 'string');
75
+ }
76
+ export function getPinDefinition(map, id) {
77
+ const keys = Array.from(map.keys());
78
+ const tmpKey = keys.find(item => item.equals(id));
79
+ return map.get(tmpKey);
80
+ }
@@ -1,4 +1,21 @@
1
+ import { ReferenceTypes } from '../globals.js';
1
2
  import { RuntimeExecutionError } from '../utils.js';
3
+ export class CFunctionEntry {
4
+ name;
5
+ execute;
6
+ uniqueId;
7
+ source;
8
+ constructor(name, execute, source, uniqueId) {
9
+ this.name = name;
10
+ this.execute = execute;
11
+ this.uniqueId = uniqueId;
12
+ this.source = source;
13
+ }
14
+ toString() {
15
+ return `[Function: ${this.name}]`;
16
+ }
17
+ }
18
+ ;
2
19
  export class AnyReference {
3
20
  found = false;
4
21
  name;
@@ -6,21 +23,27 @@ export class AnyReference {
6
23
  type;
7
24
  value;
8
25
  parentValue;
26
+ referenceName = 'AnyReference';
9
27
  constructor(refType) {
10
- if (refType.value instanceof AnyReference) {
28
+ if (refType.value instanceof AnyReference
29
+ && refType.value.type !== ReferenceTypes.function) {
11
30
  throw new RuntimeExecutionError("Nested reference types!");
12
31
  }
13
32
  this.found = refType.found;
14
33
  this.name = refType.name;
15
34
  this.trailers = refType.trailers;
16
- this.type = refType.type;
35
+ this.type = refType.type ?? ReferenceTypes.unknown;
17
36
  this.value = refType.value;
18
37
  this.parentValue = refType.parentValue;
19
38
  }
39
+ toString() {
40
+ return `[${this.referenceName} name: ${this.name} trailers:${this.trailers} found: ${this.found}]`;
41
+ }
20
42
  }
21
- export class UndeclaredReference {
43
+ export class UndeclaredReference extends AnyReference {
22
44
  reference;
23
45
  constructor(reference) {
46
+ super(reference);
24
47
  this.reference = reference;
25
48
  }
26
49
  throwMessage() {
@@ -39,9 +62,7 @@ export class UndeclaredReference {
39
62
  }
40
63
  }
41
64
  export class DeclaredReference extends AnyReference {
42
- toString() {
43
- return `[DeclaredReference name: ${this.name} trailers:${this.trailers} found: ${this.found}]`;
44
- }
65
+ referenceName = 'DeclaredReference';
45
66
  toDisplayString() {
46
67
  let returnValue = undefined;
47
68
  if (this.parentValue) {
@@ -85,3 +106,18 @@ export var Direction;
85
106
  Direction["Down"] = "down";
86
107
  Direction["Up"] = "up";
87
108
  })(Direction || (Direction = {}));
109
+ export var TypeProps;
110
+ (function (TypeProps) {
111
+ TypeProps["Net"] = "net";
112
+ TypeProps["Port"] = "port";
113
+ TypeProps["Graphic"] = "graphic";
114
+ TypeProps["Resistor"] = "res";
115
+ TypeProps["Capacitor"] = "cap";
116
+ TypeProps["Inductor"] = "ind";
117
+ TypeProps["Diode"] = "diode";
118
+ })(TypeProps || (TypeProps = {}));
119
+ export var NetTypes;
120
+ (function (NetTypes) {
121
+ NetTypes["Any"] = "any";
122
+ NetTypes["Source"] = "source";
123
+ })(NetTypes || (NetTypes = {}));
@@ -1,8 +1,8 @@
1
1
  import { ClassComponent } from './objects/ClassComponent.js';
2
2
  import { NumberOperator, numeric, NumericValue, ParamDefinition } from './objects/ParamDefinition.js';
3
- import { PinDefinition, PinIdType } from './objects/PinDefinition.js';
3
+ import { PinDefinition, PinId, PinIdType } from './objects/PinDefinition.js';
4
4
  import { PinTypes } from './objects/PinTypes.js';
5
- import { DeclaredReference, UndeclaredReference } from './objects/types.js';
5
+ import { AnyReference, DeclaredReference, TypeProps, UndeclaredReference } from './objects/types.js';
6
6
  import { BlockTypes, ComponentTypes, Delimiter1, FrameType, GlobalDocumentName, ModuleContainsKeyword, NoNetText, ParamKeys, ReferenceTypes, SymbolPinSide, ValidPinSides, WireAutoDirection } from './globals.js';
7
7
  import { unwrapValue } from "./utils.js";
8
8
  import { PlaceHolderCommands, SymbolDrawingCommands } from './draw_symbols.js';
@@ -17,19 +17,23 @@ export class ParserVisitor extends BaseVisitor {
17
17
  this.setResult(ctx, [id, value]);
18
18
  };
19
19
  visitPin_select_expr = (ctx) => {
20
- let value = null;
20
+ let pinId = null;
21
21
  const ctxData = ctx.data_expr();
22
22
  const result = this.visitResult(ctxData);
23
+ let pinValue;
23
24
  if (result instanceof NumericValue) {
24
- value = result.toNumber();
25
+ pinValue = result.toNumber();
25
26
  }
26
27
  else if (typeof result === 'string') {
27
- value = result;
28
+ pinValue = result;
28
29
  }
29
30
  else {
30
- throw new RuntimeExecutionError("Invalid value for pin", ctx);
31
+ throw new RuntimeExecutionError("Invalid select pin: " + result, ctx);
31
32
  }
32
- this.setResult(ctx, value);
33
+ if (pinValue !== undefined) {
34
+ pinId = new PinId(pinValue);
35
+ }
36
+ this.setResult(ctx, pinId);
33
37
  };
34
38
  visitAdd_component_expr = (ctx) => {
35
39
  const [component, pinValue] = this.visitResult(ctx.data_expr_with_assignment());
@@ -216,11 +220,18 @@ export class ParserVisitor extends BaseVisitor {
216
220
  }
217
221
  }
218
222
  else {
219
- if (!(value instanceof NumericValue)) {
223
+ if (!(value instanceof NumericValue) && !(typeof value === 'string')) {
220
224
  throw new RuntimeExecutionError(`Invalid numeric value for arrange.${sideKeyName}`, ctx);
221
225
  }
222
226
  else {
223
- checkPinExistsAndNotDuplicated(value.toNumber(), ctx);
227
+ let useValue;
228
+ if (value instanceof NumericValue) {
229
+ useValue = value.toNumber();
230
+ }
231
+ else if (typeof value === 'string') {
232
+ useValue = value;
233
+ }
234
+ value && checkPinExistsAndNotDuplicated(useValue, ctx);
224
235
  }
225
236
  }
226
237
  }
@@ -260,7 +271,6 @@ export class ParserVisitor extends BaseVisitor {
260
271
  scope.exitContext();
261
272
  scope.popOnPropertyHandler();
262
273
  const properties = this.getPropertyExprList(ctx.property_expr());
263
- const pins = this.parseCreateComponentPins(properties.get('pins'));
264
274
  let instanceName = this.getExecutor().getUniqueInstanceName();
265
275
  const propParams = properties.get('params');
266
276
  const params = this.parseCreateComponentParams(propParams);
@@ -273,11 +283,11 @@ export class ParserVisitor extends BaseVisitor {
273
283
  }
274
284
  instanceName += `${Delimiter1}${appendValue}`;
275
285
  }
276
- const arrange = properties.has('arrange') ?
286
+ const arrangeProp = properties.has('arrange') ?
277
287
  properties.get('arrange') : null;
278
- const display = properties.has('display') ?
288
+ const displayProp = properties.has('display') ?
279
289
  properties.get('display') : null;
280
- const type = properties.has('type') ?
290
+ const typeProp = properties.has('type') ?
281
291
  properties.get('type') : null;
282
292
  const copy = properties.has('copy') ?
283
293
  properties.get('copy') : false;
@@ -289,8 +299,29 @@ export class ParserVisitor extends BaseVisitor {
289
299
  properties.get(ParamKeys.angle) : null;
290
300
  const followWireOrientation = properties.has('followWireOrientation') ?
291
301
  properties.get('followWireOrientation') : true;
302
+ let pins = [];
303
+ if (displayProp !== null && arrangeProp === null
304
+ && typeProp !== TypeProps.Graphic) {
305
+ const drawCommands = displayProp.getCommands();
306
+ drawCommands.forEach(command => {
307
+ const [commandValue,] = command;
308
+ if (commandValue === PlaceHolderCommands.vpin
309
+ || commandValue === PlaceHolderCommands.hpin
310
+ || commandValue === PlaceHolderCommands.pin) {
311
+ const id = PinId.from(command[1][0]);
312
+ const pinType = id.getType();
313
+ const pinName = id.toString();
314
+ pins.push(new PinDefinition(id, pinType, pinName, PinTypes.Any));
315
+ }
316
+ });
317
+ }
318
+ else {
319
+ pins = this.parseCreateComponentPins(properties.get('pins'));
320
+ }
292
321
  const props = {
293
- arrange, display, type, width, height, copy,
322
+ arrange: arrangeProp,
323
+ display: displayProp,
324
+ type: typeProp, width, height, copy,
294
325
  angle, followWireOrientation
295
326
  };
296
327
  try {
@@ -376,7 +407,7 @@ export class ParserVisitor extends BaseVisitor {
376
407
  if (ctxNestedProperties) {
377
408
  const nestedKeyValues = this.visitResult(ctxNestedProperties);
378
409
  nestedKeyValues.forEach((value, key) => {
379
- parameters.push(['keyword', key, value]);
410
+ parameters.push(['keyword', key, unwrapValue(value)]);
380
411
  });
381
412
  }
382
413
  else {
@@ -534,36 +565,36 @@ export class ParserVisitor extends BaseVisitor {
534
565
  this.setResult(ctx, result);
535
566
  };
536
567
  visitData_expr_with_assignment = (ctx) => {
537
- let component = null;
538
- let componentCtx = null;
568
+ let dataResult = null;
569
+ let componentCtx;
539
570
  const ctxDataExpr = ctx.data_expr();
540
571
  const ctxAssignmentExpr = ctx.assignment_expr();
541
572
  if (ctxDataExpr) {
542
- component = this.visitResult(ctxDataExpr);
543
- component = unwrapValue(component);
573
+ dataResult = this.visitResult(ctxDataExpr);
544
574
  componentCtx = ctxDataExpr;
545
- if (component === null || component === undefined) {
546
- this.throwWithContext(ctxDataExpr, "Could not find component: " + ctxDataExpr.getText());
547
- }
548
575
  }
549
576
  else if (ctxAssignmentExpr) {
550
- component = this.visitResult(ctxAssignmentExpr);
577
+ dataResult = this.visitResult(ctxAssignmentExpr);
551
578
  componentCtx = ctxAssignmentExpr;
552
579
  }
553
- if (component instanceof ClassComponent
554
- && component.copyProp) {
555
- component = this.getExecutor().copyComponent(component);
556
- }
557
- if (component instanceof UndeclaredReference) {
558
- const { reference: { trailers = [], parentValue = null } } = component;
580
+ if (dataResult instanceof AnyReference) {
581
+ const { trailers = [], parentValue = null } = dataResult;
559
582
  if (parentValue instanceof ClassComponent
560
583
  && trailers.length > 0
561
584
  && trailers[0] === ModuleContainsKeyword) {
562
- component = parentValue;
563
- this.placeModuleContains(component);
585
+ dataResult = parentValue;
586
+ this.placeModuleContains(dataResult);
564
587
  }
565
588
  }
566
- if (component && component instanceof ClassComponent) {
589
+ dataResult = unwrapValue(dataResult);
590
+ if (dataResult === null || dataResult === undefined) {
591
+ this.throwWithContext(componentCtx, "Could not find component: " + componentCtx.getText());
592
+ }
593
+ if (dataResult instanceof ClassComponent
594
+ && dataResult.copyProp) {
595
+ dataResult = this.getExecutor().copyComponent(dataResult);
596
+ }
597
+ if (dataResult && dataResult instanceof ClassComponent) {
567
598
  const modifiers = ctx.component_modifier_expr();
568
599
  modifiers.forEach(modifier => {
569
600
  const modifierText = modifier.ID(0).getText();
@@ -580,23 +611,23 @@ export class ParserVisitor extends BaseVisitor {
580
611
  if (modifierText === ParamKeys.flip) {
581
612
  const flipValue = result;
582
613
  if (flipValue.indexOf('x') !== -1) {
583
- component.setParam(ParamKeys.flipX, 1);
614
+ dataResult.setParam(ParamKeys.flipX, 1);
584
615
  shouldIgnoreWireOrientation = true;
585
616
  }
586
617
  if (flipValue.indexOf('y') !== -1) {
587
- component.setParam(ParamKeys.flipY, 1);
618
+ dataResult.setParam(ParamKeys.flipY, 1);
588
619
  shouldIgnoreWireOrientation = true;
589
620
  }
590
621
  }
591
622
  else if (modifierText === ParamKeys.angle) {
592
- component.setParam(ParamKeys.angle, result);
623
+ dataResult.setParam(ParamKeys.angle, result);
593
624
  shouldIgnoreWireOrientation = true;
594
625
  }
595
626
  else if (modifierText === 'anchor') {
596
- component.setParam('anchor', result);
627
+ dataResult.setParam('anchor', result);
597
628
  }
598
629
  if (shouldIgnoreWireOrientation) {
599
- component.useWireOrientationAngle = false;
630
+ dataResult.useWireOrientationAngle = false;
600
631
  }
601
632
  });
602
633
  }
@@ -606,15 +637,15 @@ export class ParserVisitor extends BaseVisitor {
606
637
  pinValue = this.visitResult(ctxPinSelectExpr);
607
638
  }
608
639
  else {
609
- if (component instanceof ClassComponent) {
610
- pinValue = component.getDefaultPin();
640
+ if (dataResult instanceof ClassComponent) {
641
+ pinValue = dataResult.getDefaultPin();
611
642
  }
612
643
  else {
613
- const undeclaredRef = component;
644
+ const undeclaredRef = dataResult;
614
645
  this.throwWithContext(componentCtx, 'Invalid component: ' + undeclaredRef.reference.name);
615
646
  }
616
647
  }
617
- this.setResult(ctx, [component, pinValue]);
648
+ this.setResult(ctx, [dataResult, pinValue]);
618
649
  };
619
650
  expandModuleContains(component, netNamespace) {
620
651
  this.getExecutor().log('expanding module `contains`');
@@ -794,8 +825,8 @@ export class ParserVisitor extends BaseVisitor {
794
825
  this.setResult(ctx, result);
795
826
  };
796
827
  visitAdditionExpr = (ctx) => {
797
- const value1 = this.resolveDataExpr(ctx.data_expr(0));
798
- const value2 = this.resolveDataExpr(ctx.data_expr(1));
828
+ const value1 = unwrapValue(this.resolveDataExpr(ctx.data_expr(0)));
829
+ const value2 = unwrapValue(this.resolveDataExpr(ctx.data_expr(1)));
799
830
  if (ctx.Addition() && (typeof value1 === 'string' || typeof value2 === 'string')) {
800
831
  let tmpValue1 = value1;
801
832
  if (value1 instanceof NumericValue) {
@@ -824,6 +855,8 @@ export class ParserVisitor extends BaseVisitor {
824
855
  };
825
856
  visitFunction_def_expr = (ctx) => {
826
857
  const functionName = ctx.ID().getText();
858
+ const uniqueFunctionID = '__._' + ctx.start.line + '_'
859
+ + ctx.start.column + '_' + functionName + '_' + ctx.getText();
827
860
  let funcDefinedParameters = [];
828
861
  const ctxFunctionArgsExpr = ctx.function_args_expr();
829
862
  if (ctxFunctionArgsExpr) {
@@ -845,19 +878,26 @@ export class ParserVisitor extends BaseVisitor {
845
878
  nextLastExecution.mergeScope(lastExecution.scope, executionContextName);
846
879
  return [lastExecution, returnValue];
847
880
  };
848
- this.getExecutor().createFunction(functionName, __runFunc);
881
+ this.getExecutor().createFunction(functionName, __runFunc, ctx, uniqueFunctionID);
849
882
  };
850
883
  visitPin_select_expr2 = (ctx) => {
851
884
  const ctxStringValue = ctx.STRING_VALUE();
852
885
  const ctxIntegerValue = ctx.INTEGER_VALUE();
853
- let result = null;
886
+ let pinIdValue;
887
+ let pinId = null;
854
888
  if (ctxStringValue) {
855
- result = this.prepareStringValue(ctxStringValue.getText());
889
+ pinIdValue = this.prepareStringValue(ctxStringValue.getText());
856
890
  }
857
891
  else if (ctxIntegerValue) {
858
- result = Number(ctxIntegerValue.getText());
892
+ pinIdValue = Number(ctxIntegerValue.getText());
859
893
  }
860
- this.setResult(ctx, result);
894
+ if (pinIdValue !== undefined) {
895
+ pinId = new PinId(pinIdValue);
896
+ }
897
+ else {
898
+ throw new RuntimeExecutionError("Invalid select pin", ctx);
899
+ }
900
+ this.setResult(ctx, pinId);
861
901
  };
862
902
  visitAt_block_pin_expr = (ctx) => {
863
903
  const executor = this.getExecutor();
@@ -1198,7 +1238,7 @@ export class ParserVisitor extends BaseVisitor {
1198
1238
  return item;
1199
1239
  }
1200
1240
  else {
1201
- return numeric(nameToPinId.get(item));
1241
+ return new PinId(nameToPinId.get(item));
1202
1242
  }
1203
1243
  });
1204
1244
  if (items.length > 0) {
@@ -1289,7 +1329,7 @@ export class ParserVisitor extends BaseVisitor {
1289
1329
  getGraph() {
1290
1330
  const executor = this.getExecutor();
1291
1331
  const fullSequence = executor.scope.sequence;
1292
- const tmpNet = executor.scope.getNet(executor.scope.componentRoot, 1);
1332
+ const tmpNet = executor.scope.getNet(executor.scope.componentRoot, new PinId(1));
1293
1333
  const sequence = (tmpNet === null)
1294
1334
  ? fullSequence.slice(1) : fullSequence;
1295
1335
  const nets = executor.scope.getNets();
package/dist/libs/std.cst CHANGED
@@ -1,6 +1,6 @@
1
1
  # Circuitscript default lib
2
2
 
3
- def net(net_name):
3
+ def net(net_name, net_type = "any"):
4
4
  return create component:
5
5
  pins: 1
6
6
  copy: true
@@ -13,9 +13,10 @@ def net(net_name):
13
13
  params:
14
14
  net_name: net_name
15
15
  priority: 10
16
+ net_type: net_type
16
17
 
17
18
  def supply(net_name):
18
- net_obj = net(net_name)
19
+ net_obj = net(net_name, "source")
19
20
  return net_obj
20
21
 
21
22
  def label(value, anchor="left"):
@@ -1,4 +1,4 @@
1
- import { Array_exprContext, ArrayExprContext, Assignment_exprContext, Atom_exprContext, ExpressionContext, Flow_expressionsContext, Function_args_exprContext, Function_call_exprContext, Function_exprContext, Function_return_exprContext, FunctionCallExprContext, Import_exprContext, Operator_assignment_exprContext, ParametersContext, RoundedBracketsExprContext, ScriptContext, Value_exprContext, ValueAtomExprContext } from "./antlr/CircuitScriptParser.js";
1
+ import { Array_exprContext, ArrayExprContext, ArrayIndexExprContext, Assignment_exprContext, Atom_exprContext, ExpressionContext, Flow_expressionsContext, Function_args_exprContext, Function_call_exprContext, Function_exprContext, Function_return_exprContext, FunctionCallExprContext, Import_exprContext, Operator_assignment_exprContext, ParametersContext, RoundedBracketsExprContext, ScriptContext, Trailer_expr2Context, Value_exprContext, ValueAtomExprContext } from "./antlr/CircuitScriptParser.js";
2
2
  import { CircuitScriptVisitor } from "./antlr/CircuitScriptVisitor.js";
3
3
  import { ExecutionContext } from "./execute.js";
4
4
  import { Logger } from "./logger.js";
@@ -10,6 +10,7 @@ import { ExecutionWarning } from "./utils.js";
10
10
  import { BaseError } from './utils.js';
11
11
  import { ExecutionScope } from './objects/ExecutionScope.js';
12
12
  import { NodeScriptEnvironment } from "./environment.js";
13
+ import { PinId } from './objects/PinDefinition.js';
13
14
  export declare class BaseVisitor extends CircuitScriptVisitor<ComplexType | AnyReference | any> {
14
15
  indentLevel: number;
15
16
  startingContext: ExecutionContext;
@@ -38,7 +39,7 @@ export declare class BaseVisitor extends CircuitScriptVisitor<ComplexType | AnyR
38
39
  found: boolean;
39
40
  net?: Net;
40
41
  };
41
- createComponentPinNetResolver(executionStack: ExecutionContext[]): (component: ClassComponent, pin: number) => Net | null;
42
+ createComponentPinNetResolver(executionStack: ExecutionContext[]): (component: ClassComponent, pin: PinId) => Net | null;
42
43
  log(...params: any[]): void;
43
44
  log2(message: string): void;
44
45
  visitAsync(ctx: ParserRuleContext): Promise<void>;
@@ -46,6 +47,7 @@ export declare class BaseVisitor extends CircuitScriptVisitor<ComplexType | AnyR
46
47
  visitAssignment_expr: (ctx: Assignment_exprContext) => void;
47
48
  visitOperator_assignment_expr: (ctx: Operator_assignment_exprContext) => void;
48
49
  private getReference;
50
+ visitTrailer_expr2: (ctx: Trailer_expr2Context) => void;
49
51
  visitAtom_expr: (ctx: Atom_exprContext) => void;
50
52
  visitFunctionCallExpr: (ctx: FunctionCallExprContext) => void;
51
53
  visitFunction_call_expr: (ctx: Function_call_exprContext) => void;
@@ -59,6 +61,7 @@ export declare class BaseVisitor extends CircuitScriptVisitor<ComplexType | AnyR
59
61
  visitFlow_expressions: (ctx: Flow_expressionsContext) => void;
60
62
  visitArray_expr: (ctx: Array_exprContext) => void;
61
63
  visitArrayExpr: (ctx: ArrayExprContext) => void;
64
+ visitArrayIndexExpr: (ctx: ArrayIndexExprContext) => void;
62
65
  protected setResult(ctx: ParserRuleContext, value: any): void;
63
66
  protected getResult(ctx: ParserRuleContext): any;
64
67
  visitResult(ctx: ParserRuleContext): any;