@ugo-studio/jspp 0.2.9 → 0.3.1
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/LICENSE +25 -25
- package/README.md +20 -12
- package/dist/analysis/scope.js +5 -3
- package/dist/analysis/typeAnalyzer.js +21 -25
- package/dist/cli/index.js +14 -4
- package/dist/cli/utils.js +61 -0
- package/dist/core/codegen/class-handlers.js +6 -6
- package/dist/core/codegen/control-flow-handlers.js +10 -9
- package/dist/core/codegen/declaration-handlers.js +10 -3
- package/dist/core/codegen/destructuring-handlers.js +9 -4
- package/dist/core/codegen/expression-handlers.js +40 -29
- package/dist/core/codegen/function-handlers.js +78 -12
- package/dist/core/codegen/helpers.js +91 -14
- package/dist/core/codegen/index.js +4 -2
- package/dist/core/codegen/statement-handlers.js +9 -7
- package/package.json +2 -2
- package/scripts/precompile-headers.ts +249 -50
- package/scripts/setup-compiler.ts +63 -63
- package/src/prelude/any_value.cpp +636 -0
- package/src/prelude/any_value.hpp +369 -362
- package/src/prelude/{exception_helpers.hpp → exception.cpp} +53 -53
- package/src/prelude/exception.hpp +27 -27
- package/src/prelude/iterator_instantiations.hpp +10 -0
- package/src/prelude/{index.hpp → jspp.hpp} +10 -16
- package/src/prelude/library/array.cpp +191 -0
- package/src/prelude/library/array.hpp +13 -186
- package/src/prelude/library/console.cpp +125 -0
- package/src/prelude/library/console.hpp +24 -112
- package/src/prelude/library/error.cpp +100 -0
- package/src/prelude/library/error.hpp +13 -113
- package/src/prelude/library/function.cpp +69 -0
- package/src/prelude/library/function.hpp +11 -10
- package/src/prelude/library/global.cpp +96 -0
- package/src/prelude/library/global.hpp +12 -28
- package/src/prelude/library/global_usings.hpp +15 -0
- package/src/prelude/library/math.cpp +258 -0
- package/src/prelude/library/math.hpp +26 -308
- package/src/prelude/library/object.cpp +379 -0
- package/src/prelude/library/object.hpp +14 -276
- package/src/prelude/library/performance.cpp +21 -0
- package/src/prelude/library/performance.hpp +5 -20
- package/src/prelude/library/process.cpp +38 -0
- package/src/prelude/library/process.hpp +11 -39
- package/src/prelude/library/promise.cpp +131 -0
- package/src/prelude/library/promise.hpp +12 -123
- package/src/prelude/library/symbol.cpp +56 -0
- package/src/prelude/library/symbol.hpp +11 -52
- package/src/prelude/library/timer.cpp +88 -0
- package/src/prelude/library/timer.hpp +16 -92
- package/src/prelude/runtime.cpp +19 -0
- package/src/prelude/types.hpp +184 -179
- package/src/prelude/utils/access.hpp +502 -411
- package/src/prelude/utils/assignment_operators.hpp +99 -99
- package/src/prelude/utils/log_any_value/array.hpp +61 -40
- package/src/prelude/utils/log_any_value/function.hpp +39 -39
- package/src/prelude/utils/log_any_value/object.hpp +60 -3
- package/src/prelude/utils/operators.hpp +351 -336
- package/src/prelude/utils/operators_primitive.hpp +336 -336
- package/src/prelude/utils/well_known_symbols.hpp +24 -24
- package/src/prelude/values/array.cpp +1399 -0
- package/src/prelude/values/array.hpp +4 -1
- package/src/prelude/values/async_iterator.cpp +251 -0
- package/src/prelude/values/async_iterator.hpp +111 -83
- package/src/prelude/values/function.cpp +262 -0
- package/src/prelude/values/function.hpp +62 -82
- package/src/prelude/values/iterator.cpp +309 -0
- package/src/prelude/values/iterator.hpp +33 -64
- package/src/prelude/values/number.cpp +176 -0
- package/src/prelude/values/object.cpp +159 -0
- package/src/prelude/values/object.hpp +4 -0
- package/src/prelude/values/promise.cpp +479 -0
- package/src/prelude/values/promise.hpp +79 -72
- package/src/prelude/values/prototypes/array.hpp +46 -1336
- package/src/prelude/values/prototypes/async_iterator.hpp +19 -61
- package/src/prelude/values/prototypes/function.hpp +7 -46
- package/src/prelude/values/prototypes/iterator.hpp +25 -201
- package/src/prelude/values/prototypes/number.hpp +23 -210
- package/src/prelude/values/prototypes/object.hpp +7 -23
- package/src/prelude/values/prototypes/promise.hpp +18 -196
- package/src/prelude/values/prototypes/string.hpp +39 -542
- package/src/prelude/values/prototypes/symbol.hpp +9 -70
- package/src/prelude/values/shape.hpp +52 -52
- package/src/prelude/values/string.cpp +485 -0
- package/src/prelude/values/string.hpp +25 -26
- package/src/prelude/values/symbol.cpp +89 -0
- package/src/prelude/values/symbol.hpp +101 -101
- package/src/prelude/any_value_access.hpp +0 -170
- package/src/prelude/any_value_defines.hpp +0 -190
- package/src/prelude/any_value_helpers.hpp +0 -374
- package/src/prelude/values/helpers/array.hpp +0 -209
- package/src/prelude/values/helpers/async_iterator.hpp +0 -275
- package/src/prelude/values/helpers/function.hpp +0 -109
- package/src/prelude/values/helpers/iterator.hpp +0 -145
- package/src/prelude/values/helpers/object.hpp +0 -104
- package/src/prelude/values/helpers/promise.hpp +0 -254
- package/src/prelude/values/helpers/string.hpp +0 -61
- package/src/prelude/values/helpers/symbol.hpp +0 -21
package/src/prelude/types.hpp
CHANGED
|
@@ -1,179 +1,184 @@
|
|
|
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(AnyValue, std::span<const AnyValue>)>,
|
|
93
|
-
std::function<JsIterator<AnyValue>(AnyValue, std::vector<AnyValue>)>,
|
|
94
|
-
std::function<JsPromise(AnyValue, std::vector<AnyValue>)>,
|
|
95
|
-
std::function<JsAsyncIterator<AnyValue>(AnyValue, std::vector<AnyValue>)>>;
|
|
96
|
-
|
|
97
|
-
//
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const bool
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
inline const bool is_strictly_equal_to_primitive(const AnyValue &lhs, const
|
|
107
|
-
|
|
108
|
-
inline const bool
|
|
109
|
-
inline const bool
|
|
110
|
-
|
|
111
|
-
inline const bool is_equal_to_primitive(const AnyValue &lhs, const
|
|
112
|
-
|
|
113
|
-
inline const
|
|
114
|
-
inline const
|
|
115
|
-
|
|
116
|
-
inline const AnyValue is_strictly_equal_to(const AnyValue &lhs, const
|
|
117
|
-
|
|
118
|
-
inline const AnyValue
|
|
119
|
-
inline const AnyValue
|
|
120
|
-
|
|
121
|
-
inline const AnyValue is_equal_to(const AnyValue &lhs, const
|
|
122
|
-
|
|
123
|
-
inline const AnyValue
|
|
124
|
-
inline const AnyValue
|
|
125
|
-
|
|
126
|
-
inline const AnyValue not_strictly_equal_to(const AnyValue &lhs, const
|
|
127
|
-
|
|
128
|
-
inline const AnyValue
|
|
129
|
-
inline const AnyValue
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
inline
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
namespace ArrayPrototypes
|
|
160
|
-
{
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
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
|
+
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(AnyValue, std::span<const AnyValue>)>,
|
|
93
|
+
std::function<JsIterator<AnyValue>(AnyValue, std::vector<AnyValue>)>,
|
|
94
|
+
std::function<JsPromise(AnyValue, std::vector<AnyValue>)>,
|
|
95
|
+
std::function<JsAsyncIterator<AnyValue>(AnyValue, std::vector<AnyValue>)>>;
|
|
96
|
+
|
|
97
|
+
// Truthiness checker
|
|
98
|
+
const bool is_truthy(const double &val) noexcept;
|
|
99
|
+
const bool is_truthy(const std::string &val) noexcept;
|
|
100
|
+
const bool is_truthy(const AnyValue &val) noexcept;
|
|
101
|
+
|
|
102
|
+
// Basic equality operators
|
|
103
|
+
inline const bool is_strictly_equal_to_primitive(const AnyValue &lhs, const double &rhs) noexcept;
|
|
104
|
+
inline const bool is_strictly_equal_to_primitive(const double &lhs, const AnyValue &rhs) noexcept;
|
|
105
|
+
inline const bool is_strictly_equal_to_primitive(const double &lhs, const double &rhs) noexcept;
|
|
106
|
+
inline const bool is_strictly_equal_to_primitive(const AnyValue &lhs, const AnyValue &rhs) noexcept;
|
|
107
|
+
|
|
108
|
+
inline const bool is_equal_to_primitive(const AnyValue &lhs, const double &rhs) noexcept;
|
|
109
|
+
inline const bool is_equal_to_primitive(const double &lhs, const AnyValue &rhs) noexcept;
|
|
110
|
+
inline const bool is_equal_to_primitive(const double &lhs, const double &rhs) noexcept;
|
|
111
|
+
inline const bool is_equal_to_primitive(const AnyValue &lhs, const AnyValue &rhs) noexcept;
|
|
112
|
+
|
|
113
|
+
inline const AnyValue is_strictly_equal_to(const AnyValue &lhs, const double &rhs) noexcept;
|
|
114
|
+
inline const AnyValue is_strictly_equal_to(const double &lhs, const AnyValue &rhs) noexcept;
|
|
115
|
+
inline const AnyValue is_strictly_equal_to(const double &lhs, const double &rhs) noexcept;
|
|
116
|
+
inline const AnyValue is_strictly_equal_to(const AnyValue &lhs, const AnyValue &rhs) noexcept;
|
|
117
|
+
|
|
118
|
+
inline const AnyValue is_equal_to(const AnyValue &lhs, const double &rhs) noexcept;
|
|
119
|
+
inline const AnyValue is_equal_to(const double &lhs, const AnyValue &rhs) noexcept;
|
|
120
|
+
inline const AnyValue is_equal_to(const double &lhs, const double &rhs) noexcept;
|
|
121
|
+
inline const AnyValue is_equal_to(const AnyValue &lhs, const AnyValue &rhs) noexcept;
|
|
122
|
+
|
|
123
|
+
inline const AnyValue not_strictly_equal_to(const AnyValue &lhs, const double &rhs) noexcept;
|
|
124
|
+
inline const AnyValue not_strictly_equal_to(const double &lhs, const AnyValue &rhs) noexcept;
|
|
125
|
+
inline const AnyValue not_strictly_equal_to(const double &lhs, const double &rhs) noexcept;
|
|
126
|
+
inline const AnyValue not_strictly_equal_to(const AnyValue &lhs, const AnyValue &rhs) noexcept;
|
|
127
|
+
|
|
128
|
+
inline const AnyValue not_equal_to(const AnyValue &lhs, const double &rhs) noexcept;
|
|
129
|
+
inline const AnyValue not_equal_to(const double &lhs, const AnyValue &rhs) noexcept;
|
|
130
|
+
inline const AnyValue not_equal_to(const AnyValue &lhs, const AnyValue &rhs) noexcept;
|
|
131
|
+
|
|
132
|
+
// Bitwise operators
|
|
133
|
+
inline AnyValue unsigned_right_shift(const AnyValue &lhs, const AnyValue &rhs);
|
|
134
|
+
inline AnyValue unsigned_right_shift(const AnyValue &lhs, const double &rhs);
|
|
135
|
+
inline AnyValue unsigned_right_shift(const double &lhs, const AnyValue &rhs);
|
|
136
|
+
|
|
137
|
+
// Arithemetic operators
|
|
138
|
+
|
|
139
|
+
inline AnyValue pow(const double &lhs, const double &rhs);
|
|
140
|
+
inline AnyValue pow(const AnyValue &lhs, const double &rhs);
|
|
141
|
+
inline AnyValue pow(const AnyValue &lhs, const AnyValue &rhs);
|
|
142
|
+
|
|
143
|
+
// AnyValue prototypes
|
|
144
|
+
namespace ObjectPrototypes
|
|
145
|
+
{
|
|
146
|
+
std::optional<AnyValue> get(const std::string &key);
|
|
147
|
+
std::optional<AnyValue> get(const AnyValue &key);
|
|
148
|
+
}
|
|
149
|
+
namespace StringPrototypes
|
|
150
|
+
{
|
|
151
|
+
std::optional<AnyValue> get(const std::string &key);
|
|
152
|
+
std::optional<AnyValue> get(const AnyValue &key);
|
|
153
|
+
}
|
|
154
|
+
namespace NumberPrototypes
|
|
155
|
+
{
|
|
156
|
+
std::optional<AnyValue> get(const std::string &key);
|
|
157
|
+
std::optional<AnyValue> get(const AnyValue &key);
|
|
158
|
+
}
|
|
159
|
+
namespace ArrayPrototypes
|
|
160
|
+
{
|
|
161
|
+
std::optional<AnyValue> get(const std::string &key);
|
|
162
|
+
std::optional<AnyValue> get(const AnyValue &key);
|
|
163
|
+
}
|
|
164
|
+
namespace FunctionPrototypes
|
|
165
|
+
{
|
|
166
|
+
std::optional<AnyValue> get(const std::string &key);
|
|
167
|
+
std::optional<AnyValue> get(const AnyValue &key);
|
|
168
|
+
}
|
|
169
|
+
namespace PromisePrototypes
|
|
170
|
+
{
|
|
171
|
+
std::optional<AnyValue> get(const std::string &key);
|
|
172
|
+
std::optional<AnyValue> get(const AnyValue &key);
|
|
173
|
+
}
|
|
174
|
+
namespace IteratorPrototypes
|
|
175
|
+
{
|
|
176
|
+
std::optional<AnyValue> get(const std::string &key);
|
|
177
|
+
std::optional<AnyValue> get(const AnyValue &key);
|
|
178
|
+
}
|
|
179
|
+
namespace SymbolPrototypes
|
|
180
|
+
{
|
|
181
|
+
std::optional<AnyValue> get(const std::string &key);
|
|
182
|
+
std::optional<AnyValue> get(const AnyValue &key);
|
|
183
|
+
}
|
|
184
|
+
}
|