@ugo-studio/jspp 0.2.5 → 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 (54) hide show
  1. package/README.md +51 -36
  2. package/dist/analysis/scope.js +7 -0
  3. package/dist/analysis/typeAnalyzer.js +96 -43
  4. package/dist/ast/symbols.js +34 -24
  5. package/dist/cli/args.js +59 -0
  6. package/dist/cli/colors.js +9 -0
  7. package/dist/cli/file-utils.js +20 -0
  8. package/dist/cli/index.js +160 -0
  9. package/dist/cli/spinner.js +55 -0
  10. package/dist/core/codegen/class-handlers.js +8 -8
  11. package/dist/core/codegen/control-flow-handlers.js +19 -9
  12. package/dist/core/codegen/declaration-handlers.js +30 -10
  13. package/dist/core/codegen/expression-handlers.js +649 -161
  14. package/dist/core/codegen/function-handlers.js +107 -103
  15. package/dist/core/codegen/helpers.js +61 -14
  16. package/dist/core/codegen/index.js +13 -9
  17. package/dist/core/codegen/literal-handlers.js +4 -2
  18. package/dist/core/codegen/statement-handlers.js +147 -55
  19. package/dist/core/codegen/visitor.js +22 -2
  20. package/dist/core/constants.js +16 -0
  21. package/dist/core/error.js +58 -0
  22. package/dist/index.js +6 -3
  23. package/package.json +3 -3
  24. package/src/prelude/any_value.hpp +89 -59
  25. package/src/prelude/any_value_access.hpp +1 -1
  26. package/src/prelude/any_value_helpers.hpp +85 -43
  27. package/src/prelude/index.hpp +1 -0
  28. package/src/prelude/library/array.hpp +3 -2
  29. package/src/prelude/scheduler.hpp +144 -144
  30. package/src/prelude/types.hpp +8 -8
  31. package/src/prelude/utils/access.hpp +62 -6
  32. package/src/prelude/utils/assignment_operators.hpp +14 -14
  33. package/src/prelude/utils/log_any_value/array.hpp +0 -15
  34. package/src/prelude/utils/log_any_value/object.hpp +12 -10
  35. package/src/prelude/utils/log_any_value/primitives.hpp +2 -0
  36. package/src/prelude/utils/operators.hpp +117 -474
  37. package/src/prelude/utils/operators_primitive.hpp +337 -0
  38. package/src/prelude/values/helpers/array.hpp +4 -4
  39. package/src/prelude/values/helpers/async_iterator.hpp +2 -2
  40. package/src/prelude/values/helpers/function.hpp +3 -3
  41. package/src/prelude/values/helpers/iterator.hpp +2 -2
  42. package/src/prelude/values/helpers/object.hpp +3 -3
  43. package/src/prelude/values/helpers/promise.hpp +1 -1
  44. package/src/prelude/values/helpers/string.hpp +1 -1
  45. package/src/prelude/values/helpers/symbol.hpp +1 -1
  46. package/src/prelude/values/prototypes/array.hpp +1125 -853
  47. package/src/prelude/values/prototypes/async_iterator.hpp +32 -14
  48. package/src/prelude/values/prototypes/function.hpp +30 -18
  49. package/src/prelude/values/prototypes/iterator.hpp +40 -17
  50. package/src/prelude/values/prototypes/number.hpp +119 -62
  51. package/src/prelude/values/prototypes/object.hpp +10 -4
  52. package/src/prelude/values/prototypes/promise.hpp +167 -109
  53. package/src/prelude/values/prototypes/string.hpp +407 -231
  54. 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
+ }