@ugo-studio/jspp 0.1.9 → 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 +1 -1
- 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
package/src/prelude/types.hpp
CHANGED
|
@@ -1,131 +1,179 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <iostream>
|
|
4
|
-
#include <string>
|
|
5
|
-
#include <vector>
|
|
6
|
-
#include <variant>
|
|
7
|
-
#include <functional>
|
|
8
|
-
#include <memory>
|
|
9
|
-
#include <map>
|
|
10
|
-
#include <unordered_map>
|
|
11
|
-
#include <algorithm>
|
|
12
|
-
#include <cctype>
|
|
13
|
-
#include <cstring>
|
|
14
|
-
#include <set>
|
|
15
|
-
#include <cmath>
|
|
16
|
-
#include <optional>
|
|
17
|
-
#include <span>
|
|
18
|
-
|
|
19
|
-
// JSPP standard library
|
|
20
|
-
namespace jspp
|
|
21
|
-
{
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
struct
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <iostream>
|
|
4
|
+
#include <string>
|
|
5
|
+
#include <vector>
|
|
6
|
+
#include <variant>
|
|
7
|
+
#include <functional>
|
|
8
|
+
#include <memory>
|
|
9
|
+
#include <map>
|
|
10
|
+
#include <unordered_map>
|
|
11
|
+
#include <algorithm>
|
|
12
|
+
#include <cctype>
|
|
13
|
+
#include <cstring>
|
|
14
|
+
#include <set>
|
|
15
|
+
#include <cmath>
|
|
16
|
+
#include <optional>
|
|
17
|
+
#include <span>
|
|
18
|
+
|
|
19
|
+
// JSPP standard library
|
|
20
|
+
namespace jspp
|
|
21
|
+
{
|
|
22
|
+
enum class JsType : uint8_t
|
|
23
|
+
{
|
|
24
|
+
Undefined = 0,
|
|
25
|
+
Null = 1,
|
|
26
|
+
Uninitialized = 2,
|
|
27
|
+
Boolean = 3,
|
|
28
|
+
Number = 4,
|
|
29
|
+
String = 5,
|
|
30
|
+
Object = 6,
|
|
31
|
+
Array = 7,
|
|
32
|
+
Function = 8,
|
|
33
|
+
Iterator = 9,
|
|
34
|
+
Symbol = 10,
|
|
35
|
+
Promise = 11,
|
|
36
|
+
DataDescriptor = 12,
|
|
37
|
+
AccessorDescriptor = 13,
|
|
38
|
+
AsyncIterator = 14,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
struct HeapObject {
|
|
42
|
+
mutable uint32_t ref_count = 0;
|
|
43
|
+
|
|
44
|
+
HeapObject() noexcept : ref_count(0) {}
|
|
45
|
+
|
|
46
|
+
// Disable copying/assignment of ref_count
|
|
47
|
+
HeapObject(const HeapObject&) noexcept : ref_count(0) {}
|
|
48
|
+
HeapObject& operator=(const HeapObject&) noexcept { return *this; }
|
|
49
|
+
|
|
50
|
+
virtual ~HeapObject() = default;
|
|
51
|
+
virtual JsType get_heap_type() const = 0;
|
|
52
|
+
|
|
53
|
+
void ref() const {
|
|
54
|
+
++ref_count;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
void deref() const {
|
|
58
|
+
if (--ref_count == 0) {
|
|
59
|
+
delete this;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// Js value forward declarations
|
|
65
|
+
struct JsUndefined; // cannot set property
|
|
66
|
+
struct JsNull; // cannot set property
|
|
67
|
+
struct JsUninitialized; // cannot set property
|
|
68
|
+
struct JsString; // can set property
|
|
69
|
+
struct JsObject; // can set property
|
|
70
|
+
struct JsArray; // can set property
|
|
71
|
+
struct JsFunction; // can set property
|
|
72
|
+
struct JsPromise; // can set property
|
|
73
|
+
struct JsSymbol; // can set property (but usually doesn't have own props)
|
|
74
|
+
|
|
75
|
+
template <typename T>
|
|
76
|
+
class JsIterator; // can set property
|
|
77
|
+
|
|
78
|
+
template <typename T>
|
|
79
|
+
class JsAsyncIterator; // can set property
|
|
80
|
+
|
|
81
|
+
// Object property configuration forward declarations
|
|
82
|
+
struct DataDescriptor;
|
|
83
|
+
struct AccessorDescriptor;
|
|
84
|
+
|
|
85
|
+
// Custom runtime exception
|
|
86
|
+
struct Exception;
|
|
87
|
+
|
|
88
|
+
// Dynamic AnyValue
|
|
89
|
+
class AnyValue;
|
|
90
|
+
|
|
91
|
+
using JsFunctionCallable = std::variant<
|
|
92
|
+
std::function<AnyValue(const AnyValue &, std::span<const AnyValue>)>,
|
|
93
|
+
std::function<JsIterator<AnyValue>(const AnyValue &, std::span<const AnyValue>)>,
|
|
94
|
+
std::function<JsPromise(const AnyValue &, std::span<const AnyValue>)>,
|
|
95
|
+
std::function<JsAsyncIterator<AnyValue>(const AnyValue &, std::span<const AnyValue>)>>;
|
|
96
|
+
|
|
97
|
+
// Awaiter for AnyValue
|
|
98
|
+
struct AnyValueAwaiter;
|
|
99
|
+
|
|
100
|
+
// Truthiness checker
|
|
101
|
+
const bool is_truthy(const double &val) noexcept;
|
|
102
|
+
const bool is_truthy(const std::string &val) noexcept;
|
|
103
|
+
const bool is_truthy(const AnyValue &val) noexcept;
|
|
104
|
+
|
|
105
|
+
// Basic equality operators
|
|
106
|
+
inline const bool is_strictly_equal_to_primitive(const AnyValue &lhs, const double &rhs) noexcept;
|
|
107
|
+
inline const bool is_strictly_equal_to_primitive(const double &lhs, const AnyValue &rhs) noexcept;
|
|
108
|
+
inline const bool is_strictly_equal_to_primitive(const double &lhs, const double &rhs) noexcept;
|
|
109
|
+
inline const bool is_strictly_equal_to_primitive(const AnyValue &lhs, const AnyValue &rhs) noexcept;
|
|
110
|
+
|
|
111
|
+
inline const bool is_equal_to_primitive(const AnyValue &lhs, const double &rhs) noexcept;
|
|
112
|
+
inline const bool is_equal_to_primitive(const double &lhs, const AnyValue &rhs) noexcept;
|
|
113
|
+
inline const bool is_equal_to_primitive(const double &lhs, const double &rhs) noexcept;
|
|
114
|
+
inline const bool is_equal_to_primitive(const AnyValue &lhs, const AnyValue &rhs) noexcept;
|
|
115
|
+
|
|
116
|
+
inline const AnyValue is_strictly_equal_to(const AnyValue &lhs, const double &rhs) noexcept;
|
|
117
|
+
inline const AnyValue is_strictly_equal_to(const double &lhs, const AnyValue &rhs) noexcept;
|
|
118
|
+
inline const AnyValue is_strictly_equal_to(const double &lhs, const double &rhs) noexcept;
|
|
119
|
+
inline const AnyValue is_strictly_equal_to(const AnyValue &lhs, const AnyValue &rhs) noexcept;
|
|
120
|
+
|
|
121
|
+
inline const AnyValue is_equal_to(const AnyValue &lhs, const double &rhs) noexcept;
|
|
122
|
+
inline const AnyValue is_equal_to(const double &lhs, const AnyValue &rhs) noexcept;
|
|
123
|
+
inline const AnyValue is_equal_to(const double &lhs, const double &rhs) noexcept;
|
|
124
|
+
inline const AnyValue is_equal_to(const AnyValue &lhs, const AnyValue &rhs) noexcept;
|
|
125
|
+
|
|
126
|
+
inline const AnyValue not_strictly_equal_to(const AnyValue &lhs, const double &rhs) noexcept;
|
|
127
|
+
inline const AnyValue not_strictly_equal_to(const double &lhs, const AnyValue &rhs) noexcept;
|
|
128
|
+
inline const AnyValue not_strictly_equal_to(const double &lhs, const double &rhs) noexcept;
|
|
129
|
+
inline const AnyValue not_strictly_equal_to(const AnyValue &lhs, const AnyValue &rhs) noexcept;
|
|
130
|
+
|
|
131
|
+
inline const AnyValue not_equal_to(const AnyValue &lhs, const double &rhs) noexcept;
|
|
132
|
+
inline const AnyValue not_equal_to(const double &lhs, const AnyValue &rhs) noexcept;
|
|
133
|
+
inline const AnyValue not_equal_to(const AnyValue &lhs, const AnyValue &rhs) noexcept;
|
|
134
|
+
|
|
135
|
+
// Bitwise operators
|
|
136
|
+
inline AnyValue unsigned_right_shift(const AnyValue &lhs, const AnyValue &rhs);
|
|
137
|
+
inline AnyValue unsigned_right_shift(const AnyValue &lhs, const double &rhs);
|
|
138
|
+
inline AnyValue unsigned_right_shift(const double &lhs, const AnyValue &rhs);
|
|
139
|
+
|
|
140
|
+
// Arithemetic operators
|
|
141
|
+
|
|
142
|
+
inline AnyValue pow(const double &lhs, const double &rhs);
|
|
143
|
+
inline AnyValue pow(const AnyValue &lhs, const double &rhs);
|
|
144
|
+
inline AnyValue pow(const AnyValue &lhs, const AnyValue &rhs);
|
|
145
|
+
|
|
146
|
+
// AnyValue prototypes
|
|
147
|
+
namespace ObjectPrototypes
|
|
148
|
+
{
|
|
149
|
+
inline std::optional<AnyValue> get(const std::string &key, JsObject *self);
|
|
150
|
+
}
|
|
151
|
+
namespace StringPrototypes
|
|
152
|
+
{
|
|
153
|
+
inline std::optional<AnyValue> get(const std::string &key, JsString *self);
|
|
154
|
+
}
|
|
155
|
+
namespace NumberPrototypes
|
|
156
|
+
{
|
|
157
|
+
inline std::optional<AnyValue> get(const std::string &key, double self);
|
|
158
|
+
}
|
|
159
|
+
namespace ArrayPrototypes
|
|
160
|
+
{
|
|
161
|
+
inline std::optional<AnyValue> get(const std::string &key, JsArray *self);
|
|
162
|
+
}
|
|
163
|
+
namespace FunctionPrototypes
|
|
164
|
+
{
|
|
165
|
+
inline std::optional<AnyValue> get(const std::string &key, JsFunction *self);
|
|
166
|
+
}
|
|
167
|
+
namespace PromisePrototypes
|
|
168
|
+
{
|
|
169
|
+
inline std::optional<AnyValue> get(const std::string &key, JsPromise *self);
|
|
170
|
+
}
|
|
171
|
+
namespace IteratorPrototypes
|
|
172
|
+
{
|
|
173
|
+
inline std::optional<AnyValue> get(const std::string &key, JsIterator<AnyValue> *self);
|
|
174
|
+
}
|
|
175
|
+
namespace SymbolPrototypes
|
|
176
|
+
{
|
|
177
|
+
inline std::optional<AnyValue> get(const std::string &key, JsSymbol *self);
|
|
178
|
+
}
|
|
131
179
|
}
|