circuitscript 0.1.0 → 0.1.3

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 (61) hide show
  1. package/dist/cjs/BaseVisitor.js +13 -8
  2. package/dist/cjs/antlr/CircuitScriptLexer.js +80 -80
  3. package/dist/cjs/antlr/CircuitScriptParser.js +599 -657
  4. package/dist/cjs/builtinMethods.js +27 -8
  5. package/dist/cjs/draw_symbols.js +320 -197
  6. package/dist/cjs/execute.js +114 -116
  7. package/dist/cjs/export.js +2 -4
  8. package/dist/cjs/geometry.js +52 -19
  9. package/dist/cjs/globals.js +17 -12
  10. package/dist/cjs/helpers.js +16 -3
  11. package/dist/cjs/layout.js +473 -354
  12. package/dist/cjs/logger.js +8 -1
  13. package/dist/cjs/objects/ClassComponent.js +22 -22
  14. package/dist/cjs/objects/ExecutionScope.js +10 -4
  15. package/dist/cjs/objects/Frame.js +11 -2
  16. package/dist/cjs/objects/ParamDefinition.js +123 -4
  17. package/dist/cjs/objects/PinDefinition.js +1 -4
  18. package/dist/cjs/render.js +76 -138
  19. package/dist/cjs/sizing.js +33 -7
  20. package/dist/cjs/utils.js +86 -2
  21. package/dist/cjs/visitor.js +224 -255
  22. package/dist/esm/BaseVisitor.mjs +15 -10
  23. package/dist/esm/antlr/CircuitScriptLexer.mjs +80 -80
  24. package/dist/esm/antlr/CircuitScriptParser.mjs +599 -657
  25. package/dist/esm/builtinMethods.mjs +24 -8
  26. package/dist/esm/draw_symbols.mjs +322 -200
  27. package/dist/esm/execute.mjs +116 -118
  28. package/dist/esm/export.mjs +2 -4
  29. package/dist/esm/geometry.mjs +52 -19
  30. package/dist/esm/globals.mjs +17 -12
  31. package/dist/esm/helpers.mjs +17 -4
  32. package/dist/esm/layout.mjs +479 -360
  33. package/dist/esm/logger.mjs +8 -1
  34. package/dist/esm/objects/ClassComponent.mjs +21 -26
  35. package/dist/esm/objects/ExecutionScope.mjs +10 -4
  36. package/dist/esm/objects/Frame.mjs +10 -1
  37. package/dist/esm/objects/ParamDefinition.mjs +122 -3
  38. package/dist/esm/objects/PinDefinition.mjs +0 -2
  39. package/dist/esm/render.mjs +79 -141
  40. package/dist/esm/sizing.mjs +34 -8
  41. package/dist/esm/utils.mjs +80 -1
  42. package/dist/esm/visitor.mjs +226 -257
  43. package/dist/types/BaseVisitor.d.ts +1 -1
  44. package/dist/types/antlr/CircuitScriptParser.d.ts +2 -3
  45. package/dist/types/draw_symbols.d.ts +72 -45
  46. package/dist/types/execute.d.ts +15 -10
  47. package/dist/types/geometry.d.ts +31 -19
  48. package/dist/types/globals.d.ts +15 -11
  49. package/dist/types/helpers.d.ts +2 -1
  50. package/dist/types/layout.d.ts +35 -54
  51. package/dist/types/logger.d.ts +1 -1
  52. package/dist/types/objects/ClassComponent.d.ts +19 -16
  53. package/dist/types/objects/ExecutionScope.d.ts +3 -2
  54. package/dist/types/objects/Frame.d.ts +9 -2
  55. package/dist/types/objects/ParamDefinition.d.ts +32 -2
  56. package/dist/types/objects/PinDefinition.d.ts +0 -2
  57. package/dist/types/render.d.ts +2 -1
  58. package/dist/types/utils.d.ts +14 -1
  59. package/dist/types/visitor.d.ts +4 -5
  60. package/libs/lib.cst +25 -8
  61. package/package.json +7 -3
@@ -7,7 +7,14 @@ class Logger {
7
7
  this.add((new Date()).toISOString());
8
8
  this.add('starting logger...');
9
9
  }
10
- add(message) {
10
+ add(...args) {
11
+ let message = "";
12
+ if (args.length === 1) {
13
+ message = args[0].toString();
14
+ }
15
+ else {
16
+ message = args.join(" ");
17
+ }
11
18
  this.logs.push((new Date()).toISOString() + " | " + message);
12
19
  }
13
20
  dump() {
@@ -1,20 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ClassComponent = void 0;
3
+ exports.ModuleComponent = exports.ClassComponent = void 0;
4
4
  const draw_symbols_js_1 = require("../draw_symbols.js");
5
5
  const PinDefinition_js_1 = require("./PinDefinition.js");
6
6
  const PinTypes_js_1 = require("./PinTypes.js");
7
+ const globals_js_1 = require("../globals.js");
7
8
  class ClassComponent {
8
- constructor(instanceName, numPins, className) {
9
+ constructor(instanceName, numPins) {
9
10
  this.parameters = new Map();
10
11
  this.pins = new Map();
11
12
  this.pinNets = new Map();
12
13
  this.pinWires = new Map();
14
+ this.pinsMaxPositions = {};
13
15
  this._copyID = null;
14
16
  this._copyFrom = null;
15
17
  this.arrangeProps = null;
16
18
  this.displayProp = null;
17
19
  this.widthProp = null;
20
+ this.heightProp = null;
18
21
  this.typeProp = null;
19
22
  this.copyProp = false;
20
23
  this.angleProp = 0;
@@ -22,12 +25,9 @@ class ClassComponent {
22
25
  this.wireOrientationAngle = 0;
23
26
  this.useWireOrientationAngle = true;
24
27
  this.didSetWireOrientationAngle = false;
25
- this.styles = {};
26
28
  this.assignedRefDes = null;
27
- this.moduleCounter = 0;
28
29
  this.instanceName = instanceName;
29
30
  this.numPins = numPins;
30
- this.className = className;
31
31
  }
32
32
  setupPins() {
33
33
  for (let i = 1; i < this.numPins + 1; i++) {
@@ -104,25 +104,26 @@ class ClassComponent {
104
104
  toString() {
105
105
  return this.instanceName;
106
106
  }
107
- static simple(instanceName, numPins, className) {
108
- const component = new ClassComponent(instanceName, numPins, className);
107
+ static simple(instanceName, numPins) {
108
+ const component = new ClassComponent(instanceName, numPins);
109
109
  component.setupPins();
110
110
  return component;
111
111
  }
112
112
  isEqual(other) {
113
113
  return this.instanceName === other.instanceName
114
114
  && this.numPins === other.numPins
115
- && this.className === other.className
116
115
  && this._copyID === other._copyID
117
116
  && this.arrangeProps === other.arrangeProps
118
- && this.displayProp === other.displayProp
117
+ && ((this.displayProp === null && other.displayProp === null)
118
+ ||
119
+ (this.displayProp !== null && other.displayProp !== null && this.displayProp.eq(other.displayProp)))
119
120
  && this.widthProp === other.widthProp
120
121
  && this.typeProp === other.typeProp
121
122
  && this._cachedPins === other._cachedPins
122
123
  && this._cachedParams === other._cachedParams;
123
124
  }
124
125
  clone() {
125
- const component = new ClassComponent(this.instanceName, this.numPins, this.className);
126
+ const component = new ClassComponent(this.instanceName, this.numPins);
126
127
  component._copyID = this._copyID;
127
128
  component.arrangeProps = this.arrangeProps;
128
129
  component.widthProp = this.widthProp;
@@ -130,17 +131,12 @@ class ClassComponent {
130
131
  component.angleProp = this.angleProp;
131
132
  component.followWireOrientationProp = this.followWireOrientationProp;
132
133
  component.useWireOrientationAngle = this.useWireOrientationAngle;
133
- if (this.displayProp) {
134
- if (typeof this.displayProp === "string") {
135
- component.displayProp = this.displayProp;
136
- }
137
- else if (this.displayProp instanceof draw_symbols_js_1.SymbolDrawingCommands) {
138
- component.displayProp =
139
- this.displayProp.clone();
140
- }
134
+ if (this.displayProp instanceof draw_symbols_js_1.SymbolDrawingCommands) {
135
+ component.displayProp =
136
+ this.displayProp.clone();
141
137
  }
142
138
  for (const [key, value] of this.parameters) {
143
- if (key === 'flipX' || key === 'flipY' || key === 'angle') {
139
+ if (key === globals_js_1.ParamKeys.flipX || key === globals_js_1.ParamKeys.flipY || key === globals_js_1.ParamKeys.angle) {
144
140
  continue;
145
141
  }
146
142
  component.parameters.set(key, value);
@@ -148,11 +144,15 @@ class ClassComponent {
148
144
  for (const [key, value] of this.pins) {
149
145
  component.pins.set(key, value);
150
146
  }
151
- for (const key in this.styles) {
152
- component.styles[key] = this.styles[key];
153
- }
154
147
  component.refreshCache();
155
148
  return component;
156
149
  }
157
150
  }
158
151
  exports.ClassComponent = ClassComponent;
152
+ class ModuleComponent extends ClassComponent {
153
+ constructor() {
154
+ super(...arguments);
155
+ this.moduleCounter = 0;
156
+ }
157
+ }
158
+ exports.ModuleComponent = ModuleComponent;
@@ -47,10 +47,7 @@ class ExecutionScope {
47
47
  }
48
48
  getNet(component, pin) {
49
49
  const result = this.findNet(component, pin);
50
- if (result) {
51
- return result[2];
52
- }
53
- return null;
50
+ return result ? result[2] : null;
54
51
  }
55
52
  setNet(component, pin, net) {
56
53
  const pair = this.findNet(component, pin);
@@ -113,6 +110,15 @@ class ExecutionScope {
113
110
  this.currentWireId = -1;
114
111
  this.currentFrameId = -1;
115
112
  }
113
+ setCurrent(component, pin = null) {
114
+ this.currentComponent = component;
115
+ if (component !== null) {
116
+ this.currentPin = (pin === null) ? component.getDefaultPin() : pin;
117
+ }
118
+ else {
119
+ this.currentPin = null;
120
+ }
121
+ }
116
122
  }
117
123
  exports.ExecutionScope = ExecutionScope;
118
124
  ExecutionScope.scopeId = 0;
@@ -1,14 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FramePlotDirection = exports.FrameParamKeys = exports.Frame = void 0;
3
+ exports.FramePlotDirection = exports.FrameParamKeys = exports.FixedFrameIds = exports.Frame = void 0;
4
+ const globals_js_1 = require("../globals.js");
4
5
  class Frame {
5
- constructor(frameId, frameType) {
6
+ constructor(frameId, frameType = globals_js_1.FrameType.Frame) {
6
7
  this.parameters = new Map();
7
8
  this.frameId = frameId;
8
9
  this.frameType = frameType;
9
10
  }
10
11
  }
11
12
  exports.Frame = Frame;
13
+ var FixedFrameIds;
14
+ (function (FixedFrameIds) {
15
+ FixedFrameIds[FixedFrameIds["BaseFrame"] = -1] = "BaseFrame";
16
+ FixedFrameIds[FixedFrameIds["FrameIdNotUsed"] = -2] = "FrameIdNotUsed";
17
+ })(FixedFrameIds || (exports.FixedFrameIds = FixedFrameIds = {}));
12
18
  var FrameParamKeys;
13
19
  (function (FrameParamKeys) {
14
20
  FrameParamKeys["Title"] = "title";
@@ -19,6 +25,9 @@ var FrameParamKeys;
19
25
  FrameParamKeys["Height"] = "height";
20
26
  FrameParamKeys["PaperSize"] = "paper_size";
21
27
  FrameParamKeys["SheetType"] = "sheet_type";
28
+ FrameParamKeys["TitleAlign"] = "title_align";
29
+ FrameParamKeys["HorizontalAlign"] = "align";
30
+ FrameParamKeys["VerticalAlign"] = "valign";
22
31
  FrameParamKeys["SheetNumber"] = "sheet_number";
23
32
  FrameParamKeys["SheetTotal"] = "sheet_total";
24
33
  })(FrameParamKeys || (exports.FrameParamKeys = FrameParamKeys = {}));
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PercentageValue = exports.NumericValue = exports.ParamDefinition = void 0;
3
+ exports.NumberOperator = exports.WrappedNumber = exports.PercentageValue = exports.numeric = exports.NumericValue = exports.ParamDefinition = void 0;
4
+ const utils_1 = require("../utils");
5
+ const big_js_1 = require("big.js");
4
6
  class ParamDefinition {
5
7
  constructor(paramName, paramValue) {
6
8
  this.paramName = paramName;
@@ -9,8 +11,24 @@ class ParamDefinition {
9
11
  }
10
12
  exports.ParamDefinition = ParamDefinition;
11
13
  class NumericValue {
12
- constructor(value) {
14
+ constructor(value, prefix = 0) {
13
15
  this.value = value;
16
+ if (typeof value === 'string') {
17
+ const matches = value.match(/^([\d]+(?:.[\d]+)?)([\w]*)$/);
18
+ if (matches) {
19
+ this.valuePart = new big_js_1.Big(matches[1]);
20
+ this.prefixPart = (0, utils_1.getNumberExponential)(matches[2]);
21
+ }
22
+ else {
23
+ throw new Error("Invalid numeric value: " + value);
24
+ }
25
+ }
26
+ else {
27
+ this.valuePart = new big_js_1.Big(value);
28
+ this.prefixPart = prefix;
29
+ this.value = this.valuePart.toString()
30
+ + (0, utils_1.getNumberExponentialText)(prefix);
31
+ }
14
32
  }
15
33
  toString() {
16
34
  return 'numeric:' + this.value;
@@ -19,12 +37,62 @@ class NumericValue {
19
37
  if (typeof this.value === 'number') {
20
38
  return this.value.toString();
21
39
  }
22
- else if (typeof this.value === 'string') {
23
- return this.value;
40
+ else {
41
+ return this.valuePart.toString()
42
+ + (0, utils_1.getNumberExponentialText)(this.prefixPart);
43
+ }
44
+ }
45
+ toNumber() {
46
+ return this.toBigNumber().toNumber();
47
+ }
48
+ toBigNumber() {
49
+ return this.valuePart.mul(new big_js_1.Big(Math.pow(10, this.prefixPart)));
50
+ }
51
+ div(value) {
52
+ if (typeof value === 'number') {
53
+ value = numeric(value);
54
+ }
55
+ return (0, utils_1.resolveToNumericValue)(this.toBigNumber().div(value.toBigNumber()));
56
+ }
57
+ half() {
58
+ return this.div(2);
59
+ }
60
+ mul(value) {
61
+ if (typeof value === 'number') {
62
+ value = numeric(value);
24
63
  }
64
+ return (0, utils_1.resolveToNumericValue)(this.toBigNumber().mul(value.toBigNumber()));
65
+ }
66
+ add(value) {
67
+ if (typeof value === 'number') {
68
+ value = numeric(value);
69
+ }
70
+ return (0, utils_1.resolveToNumericValue)(this.toBigNumber().add(value.toBigNumber()));
71
+ }
72
+ sub(value) {
73
+ if (typeof value === 'number') {
74
+ value = numeric(value);
75
+ }
76
+ return (0, utils_1.resolveToNumericValue)(this.toBigNumber().sub(value.toBigNumber()));
77
+ }
78
+ mod(value) {
79
+ if (typeof value === 'number') {
80
+ value = numeric(value);
81
+ }
82
+ return (0, utils_1.resolveToNumericValue)(this.toBigNumber().mod(value.toBigNumber()));
83
+ }
84
+ neg() {
85
+ return (0, utils_1.resolveToNumericValue)(this.toBigNumber().neg());
86
+ }
87
+ eq(value) {
88
+ return this.toBigNumber().eq(value.toBigNumber());
25
89
  }
26
90
  }
27
91
  exports.NumericValue = NumericValue;
92
+ function numeric(value) {
93
+ return new NumericValue(value);
94
+ }
95
+ exports.numeric = numeric;
28
96
  class PercentageValue {
29
97
  constructor(value) {
30
98
  this.value = value;
@@ -32,5 +100,56 @@ class PercentageValue {
32
100
  toString() {
33
101
  return this.value.toString();
34
102
  }
103
+ toNumber() {
104
+ return 0;
105
+ }
35
106
  }
36
107
  exports.PercentageValue = PercentageValue;
108
+ class WrappedNumber {
109
+ constructor(value) {
110
+ this.value = value;
111
+ }
112
+ toString() {
113
+ return this.value.toString();
114
+ }
115
+ toNumber() {
116
+ return this.value;
117
+ }
118
+ }
119
+ exports.WrappedNumber = WrappedNumber;
120
+ class NumberOperator {
121
+ prepare(value) {
122
+ if (typeof value === 'number') {
123
+ return new WrappedNumber(value);
124
+ }
125
+ else {
126
+ return value;
127
+ }
128
+ }
129
+ multiply(value1, value2) {
130
+ const big1 = new big_js_1.Big(value1.toNumber());
131
+ const big2 = new big_js_1.Big(value2.toNumber());
132
+ return (0, utils_1.resolveToNumericValue)(big1.mul(big2));
133
+ }
134
+ divide(value1, value2) {
135
+ const big1 = new big_js_1.Big(value1.toNumber());
136
+ const big2 = new big_js_1.Big(value2.toNumber());
137
+ return (0, utils_1.resolveToNumericValue)(big1.div(big2));
138
+ }
139
+ addition(value1, value2) {
140
+ const big1 = new big_js_1.Big(value1.toNumber());
141
+ const big2 = new big_js_1.Big(value2.toNumber());
142
+ return (0, utils_1.resolveToNumericValue)(big1.add(big2));
143
+ }
144
+ subtraction(value1, value2) {
145
+ const big1 = new big_js_1.Big(value1.toNumber());
146
+ const big2 = new big_js_1.Big(value2.toNumber());
147
+ return (0, utils_1.resolveToNumericValue)(big1.sub(big2));
148
+ }
149
+ modulus(value1, value2) {
150
+ const big1 = new big_js_1.Big(value1.toNumber());
151
+ const big2 = new big_js_1.Big(value2.toNumber());
152
+ return (0, utils_1.resolveToNumericValue)(big1.mod(big2));
153
+ }
154
+ }
155
+ exports.NumberOperator = NumberOperator;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PinReference = exports.PortSide = exports.PinIdType = exports.PinDefinition = void 0;
3
+ exports.PortSide = exports.PinIdType = exports.PinDefinition = void 0;
4
4
  const PinTypes_js_1 = require("./PinTypes.js");
5
5
  class PinDefinition {
6
6
  constructor(id, idType, name, pinType = PinTypes_js_1.PinTypes.Any, altNames = []) {
@@ -26,6 +26,3 @@ var PortSide;
26
26
  PortSide["SOUTH"] = "SOUTH";
27
27
  PortSide["NORTH"] = "NORTH";
28
28
  })(PortSide || (exports.PortSide = PortSide = {}));
29
- class PinReference {
30
- }
31
- exports.PinReference = PinReference;