@ugo-studio/jspp 0.1.8 → 0.2.0

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 (50) hide show
  1. package/README.md +1 -1
  2. package/dist/cli-utils/args.js +2 -0
  3. package/dist/cli.js +1 -1
  4. package/package.json +3 -2
  5. package/scripts/precompile-headers.ts +110 -0
  6. package/scripts/setup-compiler.ts +63 -0
  7. package/src/prelude/any_value.hpp +185 -391
  8. package/src/prelude/any_value_access.hpp +170 -190
  9. package/src/prelude/any_value_defines.hpp +12 -12
  10. package/src/prelude/any_value_helpers.hpp +208 -26
  11. package/src/prelude/exception.hpp +27 -31
  12. package/src/prelude/exception_helpers.hpp +53 -49
  13. package/src/prelude/index.hpp +9 -4
  14. package/src/prelude/library/array.hpp +4 -9
  15. package/src/prelude/library/console.hpp +112 -112
  16. package/src/prelude/library/error.hpp +8 -8
  17. package/src/prelude/library/math.hpp +3 -3
  18. package/src/prelude/library/object.hpp +12 -24
  19. package/src/prelude/library/promise.hpp +1 -1
  20. package/src/prelude/library/symbol.hpp +1 -1
  21. package/src/prelude/library/timer.hpp +3 -3
  22. package/src/prelude/types.hpp +178 -130
  23. package/src/prelude/utils/access.hpp +338 -378
  24. package/src/prelude/utils/log_any_value/function.hpp +39 -39
  25. package/src/prelude/utils/log_any_value/log_any_value.hpp +1 -1
  26. package/src/prelude/utils/operators.hpp +20 -82
  27. package/src/prelude/utils/well_known_symbols.hpp +14 -15
  28. package/src/prelude/values/array.hpp +5 -3
  29. package/src/prelude/values/async_iterator.hpp +3 -1
  30. package/src/prelude/values/descriptors.hpp +15 -3
  31. package/src/prelude/values/function.hpp +5 -9
  32. package/src/prelude/values/helpers/array.hpp +208 -219
  33. package/src/prelude/values/helpers/async_iterator.hpp +7 -11
  34. package/src/prelude/values/helpers/function.hpp +12 -17
  35. package/src/prelude/values/helpers/iterator.hpp +108 -107
  36. package/src/prelude/values/helpers/object.hpp +104 -109
  37. package/src/prelude/values/helpers/promise.hpp +185 -119
  38. package/src/prelude/values/helpers/string.hpp +7 -10
  39. package/src/prelude/values/helpers/symbol.hpp +21 -23
  40. package/src/prelude/values/iterator.hpp +4 -1
  41. package/src/prelude/values/object.hpp +6 -4
  42. package/src/prelude/values/promise.hpp +5 -2
  43. package/src/prelude/values/prototypes/array.hpp +22 -22
  44. package/src/prelude/values/prototypes/async_iterator.hpp +3 -10
  45. package/src/prelude/values/prototypes/iterator.hpp +51 -58
  46. package/src/prelude/values/prototypes/promise.hpp +32 -28
  47. package/src/prelude/values/prototypes/string.hpp +5 -5
  48. package/src/prelude/values/prototypes/symbol.hpp +1 -1
  49. package/src/prelude/values/string.hpp +3 -1
  50. package/src/prelude/values/symbol.hpp +101 -102
@@ -1,102 +1,101 @@
1
- #pragma once
2
-
3
- #include "types.hpp"
4
- #include <atomic>
5
- #include <string>
6
- #include <unordered_map>
7
- #include <unordered_set>
8
- #include <memory>
9
- #include <optional>
10
-
11
- namespace jspp
12
- {
13
- // Forward declaration of AnyValue
14
- class AnyValue;
15
-
16
- struct JsSymbol
17
- {
18
- std::string description;
19
- std::string key; // Internal unique key used for AnyValue property maps
20
-
21
- // --- Registries ---
22
-
23
- // 1. Global Symbol Registry (for Symbol.for/keyFor)
24
- static std::unordered_map<std::string, std::shared_ptr<JsSymbol>> &registry()
25
- {
26
- static std::unordered_map<std::string, std::shared_ptr<JsSymbol>> reg;
27
- return reg;
28
- }
29
-
30
- // 2. All Internal Keys Registry (for robust Object.keys filtering)
31
- // Keeps track of every key string ever generated by a JsSymbol to distinguish
32
- // them from user strings that might coincidentally look like internal keys.
33
- static std::unordered_set<std::string> &internal_keys_registry()
34
- {
35
- static std::unordered_set<std::string> keys;
36
- return keys;
37
- }
38
-
39
- static bool is_internal_key(const std::string &k)
40
- {
41
- return internal_keys_registry().count(k) > 0;
42
- }
43
-
44
- // --- Constructors ---
45
-
46
- // Standard Constructor (creates unique symbol)
47
- JsSymbol(const std::string &desc) : description(desc)
48
- {
49
- static std::atomic<uint64_t> id_counter{0};
50
- // Ensure unique internal key for property storage
51
- key = "__Sym" + std::to_string(id_counter++) + "_" + desc;
52
-
53
- // Register this key as a valid symbol key
54
- internal_keys_registry().insert(key);
55
- }
56
-
57
- // Constructor for Well-Known Symbols (fixed keys)
58
- JsSymbol(const std::string &desc, const std::string &fixed_key)
59
- : description(desc), key(fixed_key)
60
- {
61
- // Register this key as a valid symbol key
62
- internal_keys_registry().insert(key);
63
- }
64
-
65
- // --- Global Registry API ---
66
-
67
- // Implements Symbol.for(key)
68
- static std::shared_ptr<JsSymbol> for_global(const std::string &registryKey)
69
- {
70
- auto &reg = registry();
71
- auto it = reg.find(registryKey);
72
- if (it != reg.end())
73
- {
74
- return it->second;
75
- }
76
-
77
- // Create new symbol with description = registryKey
78
- auto newSym = std::make_shared<JsSymbol>(registryKey);
79
- reg[registryKey] = newSym;
80
- return newSym;
81
- }
82
-
83
- // Implements Symbol.keyFor(sym)
84
- static std::optional<std::string> key_for(const JsSymbol *sym)
85
- {
86
- auto &reg = registry();
87
- for (const auto &pair : reg)
88
- {
89
- // Compare raw pointers
90
- if (pair.second.get() == sym)
91
- {
92
- return pair.first;
93
- }
94
- }
95
- return std::nullopt;
96
- }
97
-
98
- // --- Methods ---
99
- std::string to_std_string() const;
100
- AnyValue get_property(const std::string &key, const AnyValue &thisVal);
101
- };
102
- }
1
+ #pragma once
2
+
3
+ #include "types.hpp"
4
+ #include <atomic>
5
+ #include <string>
6
+ #include <unordered_map>
7
+ #include <unordered_set>
8
+ #include <optional>
9
+
10
+ namespace jspp
11
+ {
12
+ // Forward declaration of AnyValue
13
+ class AnyValue;
14
+
15
+ struct JsSymbol : HeapObject
16
+ {
17
+ std::string description;
18
+ std::string key; // Internal unique key used for AnyValue property maps
19
+
20
+ JsType get_heap_type() const override { return JsType::Symbol; }
21
+
22
+ // --- Registries ---
23
+
24
+ // 1. Global Symbol Registry (for Symbol.for/keyFor)
25
+ static std::unordered_map<std::string, JsSymbol*> &registry()
26
+ {
27
+ static std::unordered_map<std::string, JsSymbol*> reg;
28
+ return reg;
29
+ }
30
+
31
+ // 2. All Internal Keys Registry (for robust Object.keys filtering)
32
+ static std::unordered_set<std::string> &internal_keys_registry()
33
+ {
34
+ static std::unordered_set<std::string> keys;
35
+ return keys;
36
+ }
37
+
38
+ static bool is_internal_key(const std::string &k)
39
+ {
40
+ return internal_keys_registry().count(k) > 0;
41
+ }
42
+
43
+ // --- Constructors ---
44
+
45
+ // Standard Constructor (creates unique symbol)
46
+ JsSymbol(const std::string &desc) : description(desc)
47
+ {
48
+ static std::atomic<uint64_t> id_counter{0};
49
+ // Ensure unique internal key for property storage
50
+ key = "__Sym" + std::to_string(id_counter++) + "_" + desc;
51
+
52
+ // Register this key as a valid symbol key
53
+ internal_keys_registry().insert(key);
54
+ }
55
+
56
+ // Constructor for Well-Known Symbols (fixed keys)
57
+ JsSymbol(const std::string &desc, const std::string &fixed_key)
58
+ : description(desc), key(fixed_key)
59
+ {
60
+ // Register this key as a valid symbol key
61
+ internal_keys_registry().insert(key);
62
+ }
63
+
64
+ // --- Global Registry API ---
65
+
66
+ // Implements Symbol.for(key)
67
+ static JsSymbol* for_global(const std::string &registryKey)
68
+ {
69
+ auto &reg = registry();
70
+ auto it = reg.find(registryKey);
71
+ if (it != reg.end())
72
+ {
73
+ return it->second;
74
+ }
75
+
76
+ // Create new symbol with description = registryKey
77
+ auto newSym = new JsSymbol(registryKey);
78
+ newSym->ref(); // Keep it alive in registry
79
+ reg[registryKey] = newSym;
80
+ return newSym;
81
+ }
82
+
83
+ // Implements Symbol.keyFor(sym)
84
+ static std::optional<std::string> key_for(const JsSymbol *sym)
85
+ {
86
+ auto &reg = registry();
87
+ for (const auto &pair : reg)
88
+ {
89
+ if (pair.second == sym)
90
+ {
91
+ return pair.first;
92
+ }
93
+ }
94
+ return std::nullopt;
95
+ }
96
+
97
+ // --- Methods ---
98
+ std::string to_std_string() const;
99
+ AnyValue get_property(const std::string &key, const AnyValue &thisVal);
100
+ };
101
+ }