@ugo-studio/jspp 0.1.1 → 0.1.3
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 +3 -1
- package/dist/analysis/scope.js +22 -11
- package/dist/analysis/typeAnalyzer.js +4 -3
- package/dist/cli.js +7 -5
- package/dist/core/codegen/expression-handlers.js +10 -6
- package/dist/core/codegen/function-handlers.js +27 -6
- package/dist/core/codegen/helpers.js +12 -8
- package/dist/core/codegen/index.js +3 -1
- package/dist/core/codegen/statement-handlers.js +53 -16
- package/dist/core/codegen/visitor.js +7 -1
- package/package.json +2 -2
- package/src/prelude/access.hpp +8 -3
- package/src/prelude/any_value.hpp +141 -241
- package/src/prelude/any_value_helpers.hpp +225 -0
- package/src/prelude/error_helpers.hpp +3 -3
- package/src/prelude/index.hpp +17 -3
- package/src/prelude/library/console.hpp +7 -7
- package/src/prelude/library/performance.hpp +25 -0
- package/src/prelude/library/symbol.hpp +60 -3
- package/src/prelude/log_string.hpp +10 -6
- package/src/prelude/operators.hpp +2 -2
- package/src/prelude/types.hpp +24 -6
- package/src/prelude/values/array.hpp +2 -0
- package/src/prelude/values/function.hpp +33 -1
- package/src/prelude/values/{operators → helpers}/array.hpp +14 -7
- package/src/prelude/values/helpers/function.hpp +77 -0
- package/src/prelude/values/helpers/iterator.hpp +101 -0
- package/src/prelude/values/helpers/string.hpp +50 -0
- package/src/prelude/values/helpers/symbol.hpp +23 -0
- package/src/prelude/values/iterator.hpp +88 -0
- package/src/prelude/values/object.hpp +2 -1
- package/src/prelude/values/prototypes/array.hpp +18 -11
- package/src/prelude/values/prototypes/function.hpp +26 -0
- package/src/prelude/values/prototypes/iterator.hpp +57 -0
- package/src/prelude/values/prototypes/string.hpp +366 -357
- package/src/prelude/values/prototypes/symbol.hpp +39 -0
- package/src/prelude/values/string.hpp +25 -0
- package/src/prelude/values/symbol.hpp +102 -0
- package/src/prelude/well_known_symbols.hpp +7 -3
- package/src/prelude/values/operators/function.hpp +0 -34
- /package/src/prelude/values/{operators → helpers}/object.hpp +0 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "types.hpp"
|
|
4
|
+
#include "values/symbol.hpp"
|
|
5
|
+
#include "any_value.hpp"
|
|
6
|
+
|
|
7
|
+
namespace jspp
|
|
8
|
+
{
|
|
9
|
+
namespace SymbolPrototypes
|
|
10
|
+
{
|
|
11
|
+
inline std::optional<AnyValue> get(const std::string &key, JsSymbol *self)
|
|
12
|
+
{
|
|
13
|
+
// --- toString() method ---
|
|
14
|
+
if (key == "toString" || key == WellKnownSymbols::toString->key)
|
|
15
|
+
{
|
|
16
|
+
return AnyValue::make_function([self](const std::vector<AnyValue> &) -> AnyValue
|
|
17
|
+
{ return AnyValue::make_string(self->to_std_string()); },
|
|
18
|
+
key);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// --- description property ---
|
|
22
|
+
if (key == "description")
|
|
23
|
+
{
|
|
24
|
+
return AnyValue::make_accessor_descriptor(
|
|
25
|
+
[self](const std::vector<AnyValue> &) -> AnyValue
|
|
26
|
+
{
|
|
27
|
+
if (self->description.empty())
|
|
28
|
+
return AnyValue::make_undefined();
|
|
29
|
+
return AnyValue::make_string(self->description);
|
|
30
|
+
},
|
|
31
|
+
std::nullopt,
|
|
32
|
+
false,
|
|
33
|
+
true);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return std::nullopt;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "types.hpp"
|
|
4
|
+
#include <string>
|
|
5
|
+
#include <unordered_map>
|
|
6
|
+
|
|
7
|
+
namespace jspp
|
|
8
|
+
{
|
|
9
|
+
// Forward declaration of AnyValue
|
|
10
|
+
class AnyValue;
|
|
11
|
+
|
|
12
|
+
struct JsString
|
|
13
|
+
{
|
|
14
|
+
std::string value;
|
|
15
|
+
|
|
16
|
+
JsString() = default;
|
|
17
|
+
explicit JsString(const std::string &s) : value(s) {}
|
|
18
|
+
|
|
19
|
+
std::string to_std_string() const;
|
|
20
|
+
JsIterator<AnyValue> get_iterator();
|
|
21
|
+
|
|
22
|
+
AnyValue get_property(const std::string &key);
|
|
23
|
+
AnyValue get_property(uint32_t idx);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,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 <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>> ®istry()
|
|
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 ®istryKey)
|
|
69
|
+
{
|
|
70
|
+
auto ® = 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 ® = 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);
|
|
101
|
+
};
|
|
102
|
+
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
+
#include "values/symbol.hpp"
|
|
4
|
+
#include <memory>
|
|
5
|
+
|
|
3
6
|
namespace jspp
|
|
4
7
|
{
|
|
5
8
|
namespace WellKnownSymbols
|
|
6
9
|
{
|
|
7
|
-
|
|
8
|
-
inline std::
|
|
10
|
+
// We use a specific prefix "@@" for well-known symbols to distinguish them from user symbols
|
|
11
|
+
inline std::shared_ptr<JsSymbol> iterator = std::make_shared<JsSymbol>("Symbol.iterator", "@@iterator");
|
|
12
|
+
inline std::shared_ptr<JsSymbol> toString = std::make_shared<JsSymbol>("Symbol.toString", "@@toString");
|
|
9
13
|
}
|
|
10
|
-
}
|
|
14
|
+
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include "types.hpp"
|
|
4
|
-
#include "values/function.hpp"
|
|
5
|
-
#include "any_value.hpp"
|
|
6
|
-
|
|
7
|
-
std::string jspp::JsFunction::to_std_string() const
|
|
8
|
-
{
|
|
9
|
-
return "function " + name + "() { [native code] }";
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
jspp::AnyValue jspp::JsFunction::get_property(const std::string &key)
|
|
13
|
-
{
|
|
14
|
-
auto it = props.find(key);
|
|
15
|
-
if (it != props.end())
|
|
16
|
-
{
|
|
17
|
-
return jspp::AnyValue::resolve_property_for_read(it->second);
|
|
18
|
-
}
|
|
19
|
-
return jspp::AnyValue::make_undefined();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
jspp::AnyValue jspp::JsFunction::set_property(const std::string &key, const AnyValue &value)
|
|
23
|
-
{
|
|
24
|
-
auto it = props.find(key);
|
|
25
|
-
if (it != props.end())
|
|
26
|
-
{
|
|
27
|
-
return jspp::AnyValue::resolve_property_for_write(it->second, value);
|
|
28
|
-
}
|
|
29
|
-
else
|
|
30
|
-
{
|
|
31
|
-
props[key] = value;
|
|
32
|
-
return value;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
File without changes
|