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