@ugo-studio/jspp 0.2.6 → 0.2.7

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 (42) hide show
  1. package/dist/analysis/typeAnalyzer.js +56 -24
  2. package/dist/ast/symbols.js +28 -19
  3. package/dist/cli/index.js +1 -1
  4. package/dist/core/codegen/class-handlers.js +8 -8
  5. package/dist/core/codegen/control-flow-handlers.js +17 -7
  6. package/dist/core/codegen/declaration-handlers.js +21 -9
  7. package/dist/core/codegen/expression-handlers.js +558 -126
  8. package/dist/core/codegen/function-handlers.js +101 -108
  9. package/dist/core/codegen/helpers.js +28 -7
  10. package/dist/core/codegen/index.js +6 -4
  11. package/dist/core/codegen/literal-handlers.js +4 -2
  12. package/dist/core/codegen/statement-handlers.js +39 -19
  13. package/package.json +1 -1
  14. package/src/prelude/any_value.hpp +89 -59
  15. package/src/prelude/any_value_access.hpp +1 -1
  16. package/src/prelude/any_value_helpers.hpp +85 -43
  17. package/src/prelude/index.hpp +1 -0
  18. package/src/prelude/library/array.hpp +3 -2
  19. package/src/prelude/types.hpp +8 -8
  20. package/src/prelude/utils/access.hpp +62 -6
  21. package/src/prelude/utils/assignment_operators.hpp +14 -14
  22. package/src/prelude/utils/log_any_value/array.hpp +0 -15
  23. package/src/prelude/utils/log_any_value/primitives.hpp +2 -0
  24. package/src/prelude/utils/operators.hpp +117 -474
  25. package/src/prelude/utils/operators_primitive.hpp +337 -0
  26. package/src/prelude/values/helpers/array.hpp +4 -4
  27. package/src/prelude/values/helpers/async_iterator.hpp +2 -2
  28. package/src/prelude/values/helpers/function.hpp +3 -3
  29. package/src/prelude/values/helpers/iterator.hpp +2 -2
  30. package/src/prelude/values/helpers/object.hpp +3 -3
  31. package/src/prelude/values/helpers/promise.hpp +1 -1
  32. package/src/prelude/values/helpers/string.hpp +1 -1
  33. package/src/prelude/values/helpers/symbol.hpp +1 -1
  34. package/src/prelude/values/prototypes/array.hpp +1125 -853
  35. package/src/prelude/values/prototypes/async_iterator.hpp +32 -14
  36. package/src/prelude/values/prototypes/function.hpp +30 -18
  37. package/src/prelude/values/prototypes/iterator.hpp +40 -17
  38. package/src/prelude/values/prototypes/number.hpp +119 -62
  39. package/src/prelude/values/prototypes/object.hpp +10 -4
  40. package/src/prelude/values/prototypes/promise.hpp +167 -109
  41. package/src/prelude/values/prototypes/string.hpp +407 -231
  42. package/src/prelude/values/prototypes/symbol.hpp +45 -23
@@ -9,50 +9,72 @@ namespace jspp
9
9
  {
10
10
  namespace SymbolPrototypes
11
11
  {
12
- inline std::optional<AnyValue> get(const std::string &key, JsSymbol *self)
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)
13
52
  {
14
53
  // --- toString() method ---
15
54
  if (key == "toString" || key == WellKnownSymbols::toStringTag->key)
16
55
  {
17
- return AnyValue::make_function([self](const AnyValue &thisVal, std::span<const AnyValue>) -> AnyValue
18
- { return AnyValue::make_string(self->to_std_string()); },
19
- key);
56
+ return get_toString_fn();
20
57
  }
21
58
 
22
59
  // --- valueOf() method ---
23
60
  if (key == "valueOf")
24
61
  {
25
- return AnyValue::make_function([self](const AnyValue &thisVal, std::span<const AnyValue>) -> AnyValue
26
- { return thisVal; },
27
- key);
62
+ return get_valueOf_fn();
28
63
  }
29
64
 
30
65
  // --- [Symbol.toPrimitive] ---
31
66
  if (key == WellKnownSymbols::toPrimitive->key)
32
67
  {
33
- return AnyValue::make_function([self](const AnyValue &thisVal, std::span<const AnyValue>) -> AnyValue
34
- { return thisVal; },
35
- "[Symbol.toPrimitive]");
68
+ return get_toPrimitive_fn();
36
69
  }
37
70
 
38
71
  // --- description property ---
39
72
  if (key == "description")
40
73
  {
41
- return AnyValue::make_accessor_descriptor(
42
- [self](const AnyValue &thisVal, std::span<const AnyValue>) -> AnyValue
43
- {
44
- if (self->description.empty())
45
- {
46
- return Constants::UNDEFINED;
47
- }
48
- return AnyValue::make_string(self->description);
49
- },
50
- std::nullopt,
51
- false,
52
- true);
74
+ return get_description_desc();
53
75
  }
54
76
 
55
77
  return std::nullopt;
56
78
  }
57
79
  }
58
- }
80
+ }