@ugo-studio/jspp 0.3.1 → 0.3.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 (65) hide show
  1. package/dist/cli/args.js +22 -0
  2. package/dist/cli/compiler.js +53 -0
  3. package/dist/cli/index.js +43 -117
  4. package/dist/cli/pch.js +71 -0
  5. package/dist/cli/runner.js +23 -0
  6. package/dist/cli/spinner.js +27 -11
  7. package/dist/cli/transpiler.js +20 -0
  8. package/dist/cli/utils.js +25 -27
  9. package/dist/cli/wasm.js +70 -0
  10. package/dist/index.js +17 -6
  11. package/dist/{analysis → interpreter/analysis}/scope.js +34 -1
  12. package/dist/{analysis → interpreter/analysis}/typeAnalyzer.js +542 -3
  13. package/dist/{core → interpreter/core}/codegen/class-handlers.js +1 -1
  14. package/dist/{core → interpreter/core}/codegen/control-flow-handlers.js +2 -2
  15. package/dist/{core → interpreter/core}/codegen/declaration-handlers.js +21 -9
  16. package/dist/{core → interpreter/core}/codegen/destructuring-handlers.js +3 -3
  17. package/dist/{core → interpreter/core}/codegen/expression-handlers.js +136 -82
  18. package/dist/{core → interpreter/core}/codegen/function-handlers.js +108 -61
  19. package/dist/{core → interpreter/core}/codegen/helpers.js +79 -11
  20. package/dist/interpreter/core/codegen/index.js +156 -0
  21. package/dist/{core → interpreter/core}/codegen/literal-handlers.js +9 -0
  22. package/dist/{core → interpreter/core}/codegen/statement-handlers.js +39 -1
  23. package/package.json +6 -4
  24. package/scripts/precompile-headers.ts +71 -19
  25. package/scripts/setup-emsdk.ts +114 -0
  26. package/src/prelude/any_value.cpp +851 -599
  27. package/src/prelude/any_value.hpp +28 -30
  28. package/src/prelude/jspp.hpp +3 -1
  29. package/src/prelude/library/boolean.cpp +30 -0
  30. package/src/prelude/library/boolean.hpp +14 -0
  31. package/src/prelude/library/error.cpp +2 -2
  32. package/src/prelude/library/global.cpp +2 -0
  33. package/src/prelude/library/math.cpp +46 -43
  34. package/src/prelude/library/math.hpp +2 -0
  35. package/src/prelude/library/object.cpp +1 -1
  36. package/src/prelude/types.hpp +10 -9
  37. package/src/prelude/utils/access.hpp +2 -36
  38. package/src/prelude/utils/assignment_operators.hpp +136 -20
  39. package/src/prelude/utils/log_any_value/log_any_value.hpp +1 -1
  40. package/src/prelude/utils/log_any_value/primitives.hpp +1 -1
  41. package/src/prelude/utils/operators.hpp +123 -88
  42. package/src/prelude/utils/operators_native.hpp +360 -0
  43. package/src/prelude/utils/well_known_symbols.hpp +13 -13
  44. package/src/prelude/values/array.cpp +3 -3
  45. package/src/prelude/values/boolean.cpp +64 -0
  46. package/src/prelude/values/iterator.cpp +262 -210
  47. package/src/prelude/values/number.cpp +137 -92
  48. package/src/prelude/values/object.cpp +163 -122
  49. package/src/prelude/values/prototypes/boolean.hpp +24 -0
  50. package/src/prelude/values/prototypes/number.hpp +8 -1
  51. package/dist/cli/file-utils.js +0 -20
  52. package/dist/cli-utils/args.js +0 -59
  53. package/dist/cli-utils/colors.js +0 -9
  54. package/dist/cli-utils/file-utils.js +0 -20
  55. package/dist/cli-utils/spinner.js +0 -55
  56. package/dist/cli.js +0 -153
  57. package/dist/core/codegen/index.js +0 -88
  58. package/src/prelude/utils/operators_primitive.hpp +0 -337
  59. /package/dist/{ast → interpreter/ast}/symbols.js +0 -0
  60. /package/dist/{ast → interpreter/ast}/types.js +0 -0
  61. /package/dist/{core → interpreter/core}/codegen/visitor.js +0 -0
  62. /package/dist/{core → interpreter/core}/constants.js +0 -0
  63. /package/dist/{core → interpreter/core}/error.js +0 -0
  64. /package/dist/{core → interpreter/core}/parser.js +0 -0
  65. /package/dist/{core → interpreter/core}/traverser.js +0 -0
@@ -4,52 +4,98 @@
4
4
  #include "any_value.hpp"
5
5
  #include "utils/operators.hpp"
6
6
 
7
- namespace jspp {
7
+ namespace jspp
8
+ {
8
9
 
9
10
  // --- FRIEND IMPLEMENTATIONS ---
10
11
 
11
- inline AnyValue &operator+=(AnyValue &lhs, const AnyValue &rhs) {
12
+ inline AnyValue &operator+=(AnyValue &lhs, const AnyValue &rhs)
13
+ {
12
14
  lhs = jspp::add(lhs, rhs);
13
15
  return lhs;
14
16
  }
15
17
 
16
- inline AnyValue &operator-=(AnyValue &lhs, const AnyValue &rhs) {
18
+ inline AnyValue &operator-=(AnyValue &lhs, const AnyValue &rhs)
19
+ {
17
20
  lhs = jspp::sub(lhs, rhs);
18
21
  return lhs;
19
22
  }
20
23
 
21
- inline AnyValue &operator*=(AnyValue &lhs, const AnyValue &rhs) {
24
+ inline AnyValue &operator*=(AnyValue &lhs, const AnyValue &rhs)
25
+ {
22
26
  lhs = jspp::mul(lhs, rhs);
23
27
  return lhs;
24
28
  }
25
29
 
26
- inline AnyValue &operator/=(AnyValue &lhs, const AnyValue &rhs) {
30
+ inline AnyValue &operator/=(AnyValue &lhs, const AnyValue &rhs)
31
+ {
27
32
  lhs = jspp::div(lhs, rhs);
28
33
  return lhs;
29
34
  }
30
35
 
31
- inline AnyValue &operator%=(AnyValue &lhs, const AnyValue &rhs) {
36
+ inline AnyValue &operator%=(AnyValue &lhs, const AnyValue &rhs)
37
+ {
32
38
  lhs = jspp::mod(lhs, rhs);
33
39
  return lhs;
34
40
  }
35
41
 
36
- inline AnyValue &operator++(AnyValue &val) {
42
+ inline AnyValue &operator&=(AnyValue &lhs, const AnyValue &rhs)
43
+ {
44
+ lhs = jspp::bitwise_and(lhs, rhs);
45
+ return lhs;
46
+ }
47
+
48
+ inline AnyValue &operator|=(AnyValue &lhs, const AnyValue &rhs)
49
+ {
50
+ lhs = jspp::bitwise_or(lhs, rhs);
51
+ return lhs;
52
+ }
53
+
54
+ inline AnyValue &operator^=(AnyValue &lhs, const AnyValue &rhs)
55
+ {
56
+ lhs = jspp::bitwise_xor(lhs, rhs);
57
+ return lhs;
58
+ }
59
+
60
+ inline AnyValue &operator<<=(AnyValue &lhs, const AnyValue &rhs)
61
+ {
62
+ lhs = jspp::left_shift(lhs, rhs);
63
+ return lhs;
64
+ }
65
+
66
+ inline AnyValue &operator>>=(AnyValue &lhs, const AnyValue &rhs)
67
+ {
68
+ lhs = jspp::right_shift(lhs, rhs);
69
+ return lhs;
70
+ }
71
+
72
+ inline AnyValue &unsigned_right_shift_assign(AnyValue &lhs, const AnyValue &rhs)
73
+ {
74
+ lhs = jspp::unsigned_right_shift(lhs, rhs);
75
+ return lhs;
76
+ }
77
+
78
+ inline AnyValue &operator++(AnyValue &val)
79
+ {
37
80
  val = jspp::add(val, 1.0);
38
81
  return val;
39
82
  }
40
83
 
41
- inline AnyValue operator++(AnyValue &val, int) {
84
+ inline AnyValue operator++(AnyValue &val, int)
85
+ {
42
86
  AnyValue temp = val;
43
87
  val = jspp::add(val, 1.0);
44
88
  return temp;
45
89
  }
46
90
 
47
- inline AnyValue &operator--(AnyValue &val) {
91
+ inline AnyValue &operator--(AnyValue &val)
92
+ {
48
93
  val = jspp::sub(val, 1.0);
49
94
  return val;
50
95
  }
51
96
 
52
- inline AnyValue operator--(AnyValue &val, int) {
97
+ inline AnyValue operator--(AnyValue &val, int)
98
+ {
53
99
  AnyValue temp = val;
54
100
  val = jspp::sub(val, 1.0);
55
101
  return temp;
@@ -57,43 +103,113 @@ namespace jspp {
57
103
 
58
104
  // --- OVERLOADS FOR PRIMITIVES ---
59
105
 
60
- inline AnyValue &operator+=(AnyValue &lhs, const double &rhs) {
106
+ inline AnyValue &operator+=(AnyValue &lhs, const double &rhs)
107
+ {
61
108
  lhs = jspp::add(lhs, rhs);
62
109
  return lhs;
63
110
  }
64
- inline AnyValue &operator+=(AnyValue &lhs, const int &rhs) {
111
+ inline AnyValue &operator+=(AnyValue &lhs, const int &rhs)
112
+ {
65
113
  return lhs += static_cast<double>(rhs);
66
114
  }
67
115
 
68
- inline AnyValue &operator-=(AnyValue &lhs, const double &rhs) {
116
+ inline AnyValue &operator-=(AnyValue &lhs, const double &rhs)
117
+ {
69
118
  lhs = jspp::sub(lhs, rhs);
70
119
  return lhs;
71
120
  }
72
- inline AnyValue &operator-=(AnyValue &lhs, const int &rhs) {
121
+ inline AnyValue &operator-=(AnyValue &lhs, const int &rhs)
122
+ {
73
123
  return lhs -= static_cast<double>(rhs);
74
124
  }
75
125
 
76
- inline AnyValue &operator*=(AnyValue &lhs, const double &rhs) {
126
+ inline AnyValue &operator*=(AnyValue &lhs, const double &rhs)
127
+ {
77
128
  lhs = jspp::mul(lhs, rhs);
78
129
  return lhs;
79
130
  }
80
- inline AnyValue &operator*=(AnyValue &lhs, const int &rhs) {
131
+ inline AnyValue &operator*=(AnyValue &lhs, const int &rhs)
132
+ {
81
133
  return lhs *= static_cast<double>(rhs);
82
134
  }
83
135
 
84
- inline AnyValue &operator/=(AnyValue &lhs, const double &rhs) {
136
+ inline AnyValue &operator/=(AnyValue &lhs, const double &rhs)
137
+ {
85
138
  lhs = jspp::div(lhs, rhs);
86
139
  return lhs;
87
140
  }
88
- inline AnyValue &operator/=(AnyValue &lhs, const int &rhs) {
141
+ inline AnyValue &operator/=(AnyValue &lhs, const int &rhs)
142
+ {
89
143
  return lhs /= static_cast<double>(rhs);
90
144
  }
91
145
 
92
- inline AnyValue &operator%=(AnyValue &lhs, const double &rhs) {
146
+ inline AnyValue &operator%=(AnyValue &lhs, const double &rhs)
147
+ {
93
148
  lhs = jspp::mod(lhs, rhs);
94
149
  return lhs;
95
150
  }
96
- inline AnyValue &operator%=(AnyValue &lhs, const int &rhs) {
151
+ inline AnyValue &operator%=(AnyValue &lhs, const int &rhs)
152
+ {
97
153
  return lhs %= static_cast<double>(rhs);
98
154
  }
155
+
156
+ inline AnyValue &operator&=(AnyValue &lhs, const double &rhs)
157
+ {
158
+ lhs = jspp::bitwise_and(lhs, rhs);
159
+ return lhs;
160
+ }
161
+ inline AnyValue &operator&=(AnyValue &lhs, const int &rhs)
162
+ {
163
+ return lhs &= static_cast<double>(rhs);
164
+ }
165
+
166
+ inline AnyValue &operator|=(AnyValue &lhs, const double &rhs)
167
+ {
168
+ lhs = jspp::bitwise_or(lhs, rhs);
169
+ return lhs;
170
+ }
171
+ inline AnyValue &operator|=(AnyValue &lhs, const int &rhs)
172
+ {
173
+ return lhs |= static_cast<double>(rhs);
174
+ }
175
+
176
+ inline AnyValue &operator^=(AnyValue &lhs, const double &rhs)
177
+ {
178
+ lhs = jspp::bitwise_xor(lhs, rhs);
179
+ return lhs;
180
+ }
181
+ inline AnyValue &operator^=(AnyValue &lhs, const int &rhs)
182
+ {
183
+ return lhs ^= static_cast<double>(rhs);
184
+ }
185
+
186
+ inline AnyValue &operator<<=(AnyValue &lhs, const double &rhs)
187
+ {
188
+ lhs = jspp::left_shift(lhs, rhs);
189
+ return lhs;
190
+ }
191
+ inline AnyValue &operator<<=(AnyValue &lhs, const int &rhs)
192
+ {
193
+ return lhs <<= static_cast<double>(rhs);
194
+ }
195
+
196
+ inline AnyValue &operator>>=(AnyValue &lhs, const double &rhs)
197
+ {
198
+ lhs = jspp::right_shift(lhs, rhs);
199
+ return lhs;
200
+ }
201
+ inline AnyValue &operator>>=(AnyValue &lhs, const int &rhs)
202
+ {
203
+ return lhs >>= static_cast<double>(rhs);
204
+ }
205
+
206
+ inline AnyValue &unsigned_right_shift_assign(AnyValue &lhs, const double &rhs)
207
+ {
208
+ lhs = jspp::unsigned_right_shift(lhs, rhs);
209
+ return lhs;
210
+ }
211
+ inline AnyValue &unsigned_right_shift_assign(AnyValue &lhs, const int &rhs)
212
+ {
213
+ return unsigned_right_shift_assign(lhs, static_cast<double>(rhs));
214
+ }
99
215
  }
@@ -26,7 +26,7 @@ namespace jspp
26
26
  inline std::string to_log_string(const AnyValue &val, std::unordered_set<const void *> &visited, int depth)
27
27
  {
28
28
  // 1. Try Primitives
29
- auto primitiveStr = format_primitive(val, depth);
29
+ auto primitiveStr = format_native(val, depth);
30
30
  if (primitiveStr.has_value())
31
31
  {
32
32
  return primitiveStr.value();
@@ -11,7 +11,7 @@ namespace jspp
11
11
  {
12
12
  namespace LogAnyValue
13
13
  {
14
- inline std::optional<std::string> format_primitive(const AnyValue &val, int depth)
14
+ inline std::optional<std::string> format_native(const AnyValue &val, int depth)
15
15
  {
16
16
  if (val.is_uninitialized())
17
17
  {