@ugo-studio/jspp 0.2.9 → 0.3.1

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 (97) hide show
  1. package/LICENSE +25 -25
  2. package/README.md +20 -12
  3. package/dist/analysis/scope.js +5 -3
  4. package/dist/analysis/typeAnalyzer.js +21 -25
  5. package/dist/cli/index.js +14 -4
  6. package/dist/cli/utils.js +61 -0
  7. package/dist/core/codegen/class-handlers.js +6 -6
  8. package/dist/core/codegen/control-flow-handlers.js +10 -9
  9. package/dist/core/codegen/declaration-handlers.js +10 -3
  10. package/dist/core/codegen/destructuring-handlers.js +9 -4
  11. package/dist/core/codegen/expression-handlers.js +40 -29
  12. package/dist/core/codegen/function-handlers.js +78 -12
  13. package/dist/core/codegen/helpers.js +91 -14
  14. package/dist/core/codegen/index.js +4 -2
  15. package/dist/core/codegen/statement-handlers.js +9 -7
  16. package/package.json +2 -2
  17. package/scripts/precompile-headers.ts +249 -50
  18. package/scripts/setup-compiler.ts +63 -63
  19. package/src/prelude/any_value.cpp +636 -0
  20. package/src/prelude/any_value.hpp +369 -362
  21. package/src/prelude/{exception_helpers.hpp → exception.cpp} +53 -53
  22. package/src/prelude/exception.hpp +27 -27
  23. package/src/prelude/iterator_instantiations.hpp +10 -0
  24. package/src/prelude/{index.hpp → jspp.hpp} +10 -16
  25. package/src/prelude/library/array.cpp +191 -0
  26. package/src/prelude/library/array.hpp +13 -186
  27. package/src/prelude/library/console.cpp +125 -0
  28. package/src/prelude/library/console.hpp +24 -112
  29. package/src/prelude/library/error.cpp +100 -0
  30. package/src/prelude/library/error.hpp +13 -113
  31. package/src/prelude/library/function.cpp +69 -0
  32. package/src/prelude/library/function.hpp +11 -10
  33. package/src/prelude/library/global.cpp +96 -0
  34. package/src/prelude/library/global.hpp +12 -28
  35. package/src/prelude/library/global_usings.hpp +15 -0
  36. package/src/prelude/library/math.cpp +258 -0
  37. package/src/prelude/library/math.hpp +26 -308
  38. package/src/prelude/library/object.cpp +379 -0
  39. package/src/prelude/library/object.hpp +14 -276
  40. package/src/prelude/library/performance.cpp +21 -0
  41. package/src/prelude/library/performance.hpp +5 -20
  42. package/src/prelude/library/process.cpp +38 -0
  43. package/src/prelude/library/process.hpp +11 -39
  44. package/src/prelude/library/promise.cpp +131 -0
  45. package/src/prelude/library/promise.hpp +12 -123
  46. package/src/prelude/library/symbol.cpp +56 -0
  47. package/src/prelude/library/symbol.hpp +11 -52
  48. package/src/prelude/library/timer.cpp +88 -0
  49. package/src/prelude/library/timer.hpp +16 -92
  50. package/src/prelude/runtime.cpp +19 -0
  51. package/src/prelude/types.hpp +184 -179
  52. package/src/prelude/utils/access.hpp +502 -411
  53. package/src/prelude/utils/assignment_operators.hpp +99 -99
  54. package/src/prelude/utils/log_any_value/array.hpp +61 -40
  55. package/src/prelude/utils/log_any_value/function.hpp +39 -39
  56. package/src/prelude/utils/log_any_value/object.hpp +60 -3
  57. package/src/prelude/utils/operators.hpp +351 -336
  58. package/src/prelude/utils/operators_primitive.hpp +336 -336
  59. package/src/prelude/utils/well_known_symbols.hpp +24 -24
  60. package/src/prelude/values/array.cpp +1399 -0
  61. package/src/prelude/values/array.hpp +4 -1
  62. package/src/prelude/values/async_iterator.cpp +251 -0
  63. package/src/prelude/values/async_iterator.hpp +111 -83
  64. package/src/prelude/values/function.cpp +262 -0
  65. package/src/prelude/values/function.hpp +62 -82
  66. package/src/prelude/values/iterator.cpp +309 -0
  67. package/src/prelude/values/iterator.hpp +33 -64
  68. package/src/prelude/values/number.cpp +176 -0
  69. package/src/prelude/values/object.cpp +159 -0
  70. package/src/prelude/values/object.hpp +4 -0
  71. package/src/prelude/values/promise.cpp +479 -0
  72. package/src/prelude/values/promise.hpp +79 -72
  73. package/src/prelude/values/prototypes/array.hpp +46 -1336
  74. package/src/prelude/values/prototypes/async_iterator.hpp +19 -61
  75. package/src/prelude/values/prototypes/function.hpp +7 -46
  76. package/src/prelude/values/prototypes/iterator.hpp +25 -201
  77. package/src/prelude/values/prototypes/number.hpp +23 -210
  78. package/src/prelude/values/prototypes/object.hpp +7 -23
  79. package/src/prelude/values/prototypes/promise.hpp +18 -196
  80. package/src/prelude/values/prototypes/string.hpp +39 -542
  81. package/src/prelude/values/prototypes/symbol.hpp +9 -70
  82. package/src/prelude/values/shape.hpp +52 -52
  83. package/src/prelude/values/string.cpp +485 -0
  84. package/src/prelude/values/string.hpp +25 -26
  85. package/src/prelude/values/symbol.cpp +89 -0
  86. package/src/prelude/values/symbol.hpp +101 -101
  87. package/src/prelude/any_value_access.hpp +0 -170
  88. package/src/prelude/any_value_defines.hpp +0 -190
  89. package/src/prelude/any_value_helpers.hpp +0 -374
  90. package/src/prelude/values/helpers/array.hpp +0 -209
  91. package/src/prelude/values/helpers/async_iterator.hpp +0 -275
  92. package/src/prelude/values/helpers/function.hpp +0 -109
  93. package/src/prelude/values/helpers/iterator.hpp +0 -145
  94. package/src/prelude/values/helpers/object.hpp +0 -104
  95. package/src/prelude/values/helpers/promise.hpp +0 -254
  96. package/src/prelude/values/helpers/string.hpp +0 -61
  97. package/src/prelude/values/helpers/symbol.hpp +0 -21
@@ -1,80 +1,19 @@
1
1
  #pragma once
2
2
 
3
3
  #include "types.hpp"
4
- #include "values/symbol.hpp"
5
- #include "any_value.hpp"
6
- #include "utils/well_known_symbols.hpp"
4
+ #include <optional>
7
5
 
8
6
  namespace jspp
9
7
  {
8
+ class AnyValue;
9
+
10
10
  namespace SymbolPrototypes
11
11
  {
12
- inline AnyValue &get_toString_fn()
13
- {
14
- static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue>) -> AnyValue
15
- { return AnyValue::make_string(thisVal.as_symbol()->to_std_string()); },
16
- "toString");
17
- return fn;
18
- }
19
-
20
- inline AnyValue &get_valueOf_fn()
21
- {
22
- static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue>) -> AnyValue
23
- { return thisVal; },
24
- "valueOf");
25
- return fn;
26
- }
27
-
28
- inline AnyValue &get_toPrimitive_fn()
29
- {
30
- static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue>) -> AnyValue
31
- { return thisVal; },
32
- "[Symbol.toPrimitive]");
33
- return fn;
34
- }
35
-
36
- inline AnyValue &get_description_desc()
37
- {
38
- static auto getter = [](const AnyValue &thisVal, std::span<const AnyValue>) -> AnyValue
39
- {
40
- auto self = thisVal.as_symbol();
41
- if (self->description.empty())
42
- {
43
- return Constants::UNDEFINED;
44
- }
45
- return AnyValue::make_string(self->description);
46
- };
47
- static AnyValue desc = AnyValue::make_accessor_descriptor(getter, std::nullopt, false, true);
48
- return desc;
49
- }
50
-
51
- inline std::optional<AnyValue> get(const std::string &key)
52
- {
53
- // --- toString() method ---
54
- if (key == "toString" || key == WellKnownSymbols::toStringTag->key)
55
- {
56
- return get_toString_fn();
57
- }
58
-
59
- // --- valueOf() method ---
60
- if (key == "valueOf")
61
- {
62
- return get_valueOf_fn();
63
- }
64
-
65
- // --- [Symbol.toPrimitive] ---
66
- if (key == WellKnownSymbols::toPrimitive->key)
67
- {
68
- return get_toPrimitive_fn();
69
- }
70
-
71
- // --- description property ---
72
- if (key == "description")
73
- {
74
- return get_description_desc();
75
- }
76
-
77
- return std::nullopt;
78
- }
12
+ AnyValue &get_toString_fn();
13
+ AnyValue &get_valueOf_fn();
14
+ AnyValue &get_toPrimitive_fn();
15
+ AnyValue &get_description_desc();
16
+ std::optional<AnyValue> get(const std::string &key);
17
+ std::optional<AnyValue> get(const AnyValue &key);
79
18
  }
80
19
  }
@@ -1,52 +1,52 @@
1
- #pragma once
2
-
3
- #include <string>
4
- #include <unordered_map>
5
- #include <vector>
6
- #include <memory>
7
- #include <optional>
8
- #include <span>
9
-
10
- namespace jspp {
11
-
12
- class Shape {
13
- public:
14
- // Map property name -> storage index
15
- std::unordered_map<std::string, uint32_t> property_offsets;
16
- // Map property name -> next Shape (transitions)
17
- std::unordered_map<std::string, std::shared_ptr<Shape>> transitions;
18
-
19
- // For fast enumeration (Object.keys)
20
- std::vector<std::string> property_names;
21
-
22
- // Singleton empty shape
23
- static std::shared_ptr<Shape> empty_shape() {
24
- static auto shape = std::make_shared<Shape>();
25
- return shape;
26
- }
27
-
28
- std::optional<uint32_t> get_offset(const std::string& name) const {
29
- auto it = property_offsets.find(name);
30
- if (it != property_offsets.end()) return it->second;
31
- return std::nullopt;
32
- }
33
-
34
- std::shared_ptr<Shape> transition(const std::string& name) {
35
- auto it = transitions.find(name);
36
- if (it != transitions.end()) return it->second;
37
-
38
- // Create new shape
39
- auto new_shape = std::make_shared<Shape>();
40
- new_shape->property_offsets = this->property_offsets;
41
- new_shape->property_names = this->property_names;
42
-
43
- uint32_t new_offset = static_cast<uint32_t>(new_shape->property_offsets.size());
44
- new_shape->property_offsets[name] = new_offset;
45
- new_shape->property_names.push_back(name);
46
-
47
- transitions[name] = new_shape;
48
- return new_shape;
49
- }
50
- };
51
-
52
- }
1
+ #pragma once
2
+
3
+ #include <string>
4
+ #include <unordered_map>
5
+ #include <vector>
6
+ #include <memory>
7
+ #include <optional>
8
+ #include <span>
9
+
10
+ namespace jspp {
11
+
12
+ class Shape {
13
+ public:
14
+ // Map property name -> storage index
15
+ std::unordered_map<std::string, uint32_t> property_offsets;
16
+ // Map property name -> next Shape (transitions)
17
+ std::unordered_map<std::string, std::shared_ptr<Shape>> transitions;
18
+
19
+ // For fast enumeration (Object.keys)
20
+ std::vector<std::string> property_names;
21
+
22
+ // Singleton empty shape
23
+ static std::shared_ptr<Shape> empty_shape() {
24
+ static auto shape = std::make_shared<Shape>();
25
+ return shape;
26
+ }
27
+
28
+ std::optional<uint32_t> get_offset(const std::string& name) const {
29
+ auto it = property_offsets.find(name);
30
+ if (it != property_offsets.end()) return it->second;
31
+ return std::nullopt;
32
+ }
33
+
34
+ std::shared_ptr<Shape> transition(const std::string& name) {
35
+ auto it = transitions.find(name);
36
+ if (it != transitions.end()) return it->second;
37
+
38
+ // Create new shape
39
+ auto new_shape = std::make_shared<Shape>();
40
+ new_shape->property_offsets = this->property_offsets;
41
+ new_shape->property_names = this->property_names;
42
+
43
+ uint32_t new_offset = static_cast<uint32_t>(new_shape->property_offsets.size());
44
+ new_shape->property_offsets[name] = new_offset;
45
+ new_shape->property_names.push_back(name);
46
+
47
+ transitions[name] = new_shape;
48
+ return new_shape;
49
+ }
50
+ };
51
+
52
+ }