circuitscript 0.0.38 → 0.1.2

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 (66) hide show
  1. package/dist/cjs/BaseVisitor.js +69 -46
  2. package/dist/cjs/SymbolValidatorVisitor.js +1 -1
  3. package/dist/cjs/antlr/CircuitScriptLexer.js +80 -80
  4. package/dist/cjs/antlr/CircuitScriptParser.js +580 -613
  5. package/dist/cjs/builtinMethods.js +32 -10
  6. package/dist/cjs/draw_symbols.js +375 -233
  7. package/dist/cjs/execute.js +142 -131
  8. package/dist/cjs/export.js +2 -4
  9. package/dist/cjs/geometry.js +52 -19
  10. package/dist/cjs/globals.js +14 -9
  11. package/dist/cjs/helpers.js +16 -3
  12. package/dist/cjs/layout.js +143 -151
  13. package/dist/cjs/logger.js +8 -1
  14. package/dist/cjs/objects/ClassComponent.js +22 -22
  15. package/dist/cjs/objects/ExecutionScope.js +10 -4
  16. package/dist/cjs/objects/Frame.js +4 -1
  17. package/dist/cjs/objects/ParamDefinition.js +120 -4
  18. package/dist/cjs/objects/PinDefinition.js +1 -4
  19. package/dist/cjs/objects/types.js +41 -0
  20. package/dist/cjs/render.js +41 -110
  21. package/dist/cjs/sizing.js +33 -7
  22. package/dist/cjs/utils.js +92 -2
  23. package/dist/cjs/visitor.js +279 -284
  24. package/dist/esm/BaseVisitor.mjs +70 -47
  25. package/dist/esm/SymbolValidatorVisitor.mjs +1 -1
  26. package/dist/esm/antlr/CircuitScriptLexer.mjs +80 -80
  27. package/dist/esm/antlr/CircuitScriptParser.mjs +580 -613
  28. package/dist/esm/builtinMethods.mjs +29 -10
  29. package/dist/esm/draw_symbols.mjs +381 -238
  30. package/dist/esm/execute.mjs +144 -133
  31. package/dist/esm/export.mjs +2 -4
  32. package/dist/esm/geometry.mjs +52 -19
  33. package/dist/esm/globals.mjs +13 -8
  34. package/dist/esm/helpers.mjs +17 -4
  35. package/dist/esm/layout.mjs +144 -153
  36. package/dist/esm/logger.mjs +8 -1
  37. package/dist/esm/objects/ClassComponent.mjs +21 -26
  38. package/dist/esm/objects/ExecutionScope.mjs +10 -4
  39. package/dist/esm/objects/Frame.mjs +4 -1
  40. package/dist/esm/objects/ParamDefinition.mjs +119 -3
  41. package/dist/esm/objects/PinDefinition.mjs +0 -2
  42. package/dist/esm/objects/types.mjs +42 -0
  43. package/dist/esm/render.mjs +44 -113
  44. package/dist/esm/sizing.mjs +34 -8
  45. package/dist/esm/utils.mjs +86 -1
  46. package/dist/esm/visitor.mjs +281 -286
  47. package/dist/types/BaseVisitor.d.ts +3 -2
  48. package/dist/types/antlr/CircuitScriptParser.d.ts +5 -3
  49. package/dist/types/draw_symbols.d.ts +81 -49
  50. package/dist/types/execute.d.ts +16 -11
  51. package/dist/types/geometry.d.ts +31 -19
  52. package/dist/types/globals.d.ts +15 -10
  53. package/dist/types/helpers.d.ts +2 -1
  54. package/dist/types/layout.d.ts +22 -21
  55. package/dist/types/logger.d.ts +1 -1
  56. package/dist/types/objects/ClassComponent.d.ts +19 -16
  57. package/dist/types/objects/ExecutionScope.d.ts +2 -1
  58. package/dist/types/objects/Frame.d.ts +5 -3
  59. package/dist/types/objects/ParamDefinition.d.ts +31 -2
  60. package/dist/types/objects/PinDefinition.d.ts +0 -2
  61. package/dist/types/objects/types.d.ts +7 -2
  62. package/dist/types/render.d.ts +2 -1
  63. package/dist/types/utils.d.ts +9 -1
  64. package/dist/types/visitor.d.ts +5 -5
  65. package/libs/lib.cst +102 -32
  66. package/package.json +7 -3
@@ -1,3 +1,6 @@
1
+ import Big from "big.js";
2
+ import { numeric, NumericValue } from "./objects/ParamDefinition";
3
+ import { resolveToNumericValue } from "./utils";
1
4
  export function linkBuiltInMethods(context, visitor) {
2
5
  context.createFunction('print', (params) => {
3
6
  const args = getPositionParams(params);
@@ -24,8 +27,8 @@ export function linkBuiltInMethods(context, visitor) {
24
27
  });
25
28
  }
26
29
  function range(...args) {
27
- let startValue = 0;
28
- let endValue = 0;
30
+ let startValue = numeric(0);
31
+ let endValue = numeric(0);
29
32
  if (args.length === 1) {
30
33
  endValue = args[0];
31
34
  }
@@ -33,15 +36,17 @@ function range(...args) {
33
36
  startValue = args[0];
34
37
  endValue = args[1];
35
38
  }
39
+ const startValueNum = startValue.toNumber();
40
+ const endValueNum = endValue.toNumber();
36
41
  const returnArray = [];
37
- for (let i = startValue; i < endValue; i++) {
42
+ for (let i = startValueNum; i < endValueNum; i++) {
38
43
  returnArray.push(i);
39
44
  }
40
45
  return returnArray;
41
46
  }
42
47
  function enumerate(array) {
43
48
  if (!Array.isArray(array)) {
44
- throw "Invalid parameter for enumerate function!";
49
+ throw "Invalid parameter for enumerate function";
45
50
  }
46
51
  const output = array.map((item, index) => {
47
52
  return [index, item];
@@ -49,18 +54,26 @@ function enumerate(array) {
49
54
  return output;
50
55
  }
51
56
  function toMils(value) {
52
- if (isNaN(value)) {
53
- throw "Invalid input for method toMils";
57
+ let bigValue;
58
+ if (value instanceof NumericValue) {
59
+ bigValue = value.toBigNumber();
54
60
  }
55
- return value / 25.4 * 1000;
61
+ else {
62
+ if (isNaN(value)) {
63
+ throw "Invalid input for method toMils";
64
+ }
65
+ bigValue = new Big(value);
66
+ }
67
+ bigValue = bigValue.div(new Big(25.4 / 1000));
68
+ return resolveToNumericValue(bigValue);
56
69
  }
57
70
  function objectLength(obj) {
58
71
  if (Array.isArray(obj)) {
59
- return obj.length;
72
+ return numeric(obj.length);
60
73
  }
61
74
  else {
62
75
  if (obj.length) {
63
- return obj.length;
76
+ return numeric(obj.length);
64
77
  }
65
78
  else {
66
79
  throw "Could not get length of object: " + obj;
@@ -81,8 +94,14 @@ function toString(obj) {
81
94
  const inner = obj.map(item => toString(item)).join(", ");
82
95
  return "[" + inner + "]";
83
96
  }
97
+ else if (obj instanceof NumericValue) {
98
+ return obj.toBigNumber().toString();
99
+ }
84
100
  else {
85
- if (obj.toString) {
101
+ if (obj.toDisplayString) {
102
+ return obj.toDisplayString();
103
+ }
104
+ else if (obj.toString) {
86
105
  return obj.toString();
87
106
  }
88
107
  else {