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
@@ -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,8 +36,10 @@ 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;
@@ -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,6 +94,9 @@ 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
101
  if (obj.toDisplayString) {
86
102
  return obj.toDisplayString();