@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.
- package/README.md +1 -1
- package/dist/cli-utils/args.js +2 -0
- package/dist/cli.js +1 -1
- package/package.json +3 -2
- package/scripts/precompile-headers.ts +110 -0
- package/scripts/setup-compiler.ts +63 -0
- package/src/prelude/any_value.hpp +185 -391
- package/src/prelude/any_value_access.hpp +170 -190
- package/src/prelude/any_value_defines.hpp +12 -12
- package/src/prelude/any_value_helpers.hpp +208 -26
- package/src/prelude/exception.hpp +27 -31
- package/src/prelude/exception_helpers.hpp +53 -49
- package/src/prelude/index.hpp +9 -4
- package/src/prelude/library/array.hpp +4 -9
- package/src/prelude/library/console.hpp +112 -112
- package/src/prelude/library/error.hpp +8 -8
- package/src/prelude/library/math.hpp +3 -3
- package/src/prelude/library/object.hpp +12 -24
- package/src/prelude/library/promise.hpp +1 -1
- package/src/prelude/library/symbol.hpp +1 -1
- package/src/prelude/library/timer.hpp +3 -3
- package/src/prelude/types.hpp +178 -130
- package/src/prelude/utils/access.hpp +338 -378
- package/src/prelude/utils/log_any_value/function.hpp +39 -39
- package/src/prelude/utils/log_any_value/log_any_value.hpp +1 -1
- package/src/prelude/utils/operators.hpp +20 -82
- package/src/prelude/utils/well_known_symbols.hpp +14 -15
- package/src/prelude/values/array.hpp +5 -3
- package/src/prelude/values/async_iterator.hpp +3 -1
- package/src/prelude/values/descriptors.hpp +15 -3
- package/src/prelude/values/function.hpp +5 -9
- package/src/prelude/values/helpers/array.hpp +208 -219
- package/src/prelude/values/helpers/async_iterator.hpp +7 -11
- package/src/prelude/values/helpers/function.hpp +12 -17
- package/src/prelude/values/helpers/iterator.hpp +108 -107
- package/src/prelude/values/helpers/object.hpp +104 -109
- package/src/prelude/values/helpers/promise.hpp +185 -119
- package/src/prelude/values/helpers/string.hpp +7 -10
- package/src/prelude/values/helpers/symbol.hpp +21 -23
- package/src/prelude/values/iterator.hpp +4 -1
- package/src/prelude/values/object.hpp +6 -4
- package/src/prelude/values/promise.hpp +5 -2
- package/src/prelude/values/prototypes/array.hpp +22 -22
- package/src/prelude/values/prototypes/async_iterator.hpp +3 -10
- package/src/prelude/values/prototypes/iterator.hpp +51 -58
- package/src/prelude/values/prototypes/promise.hpp +32 -28
- package/src/prelude/values/prototypes/string.hpp +5 -5
- package/src/prelude/values/prototypes/symbol.hpp +1 -1
- package/src/prelude/values/string.hpp +3 -1
- 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 <
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
std::string
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
//
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
auto
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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 ® = registry();
|
|
87
|
-
for (const auto &pair : reg)
|
|
88
|
-
{
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
std::string
|
|
100
|
-
|
|
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*> ®istry()
|
|
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 ®istryKey)
|
|
68
|
+
{
|
|
69
|
+
auto ® = 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 ® = 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
|
+
}
|