@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
|
@@ -1,337 +1,337 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include "types.hpp"
|
|
4
|
-
#include "any_value.hpp"
|
|
5
|
-
#include <cstdint> // For int32_t
|
|
6
|
-
#include <cmath> // For fmod, isnan, isinf, floor, abs, pow
|
|
7
|
-
#include <string> // For std::to_string, std::stod
|
|
8
|
-
#include <algorithm> // For std::all_of
|
|
9
|
-
#include <limits> // For numeric_limits
|
|
10
|
-
|
|
11
|
-
namespace jspp
|
|
12
|
-
{
|
|
13
|
-
// Private namespace for helper functions that implement JS type conversions.
|
|
14
|
-
namespace Operators_Private
|
|
15
|
-
{
|
|
16
|
-
// Implements the ToNumber abstract operation from ECMA-262.
|
|
17
|
-
inline double ToNumber(const AnyValue &val)
|
|
18
|
-
{
|
|
19
|
-
if (val.is_number())
|
|
20
|
-
return val.as_double();
|
|
21
|
-
if (val.is_null())
|
|
22
|
-
return 0.0;
|
|
23
|
-
if (val.is_undefined())
|
|
24
|
-
return std::numeric_limits<double>::quiet_NaN();
|
|
25
|
-
if (val.is_boolean())
|
|
26
|
-
return val.as_boolean() ? 1.0 : 0.0;
|
|
27
|
-
if (val.is_string())
|
|
28
|
-
{
|
|
29
|
-
const std::string &s = val.as_string()->value;
|
|
30
|
-
if (s.empty() || std::all_of(s.begin(), s.end(), [](unsigned char c)
|
|
31
|
-
{ return std::isspace(c); }))
|
|
32
|
-
return 0.0;
|
|
33
|
-
try
|
|
34
|
-
{
|
|
35
|
-
size_t pos;
|
|
36
|
-
double num = std::stod(s, &pos);
|
|
37
|
-
while (pos < s.length() && std::isspace(static_cast<unsigned char>(s[pos])))
|
|
38
|
-
pos++;
|
|
39
|
-
if (pos != s.length())
|
|
40
|
-
return std::numeric_limits<double>::quiet_NaN();
|
|
41
|
-
return num;
|
|
42
|
-
}
|
|
43
|
-
catch (...)
|
|
44
|
-
{
|
|
45
|
-
return std::numeric_limits<double>::quiet_NaN();
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (val.is_uninitialized())
|
|
49
|
-
{
|
|
50
|
-
// THROW
|
|
51
|
-
Exception::throw_uninitialized_reference("#<Object>");
|
|
52
|
-
}
|
|
53
|
-
// Default to NaN
|
|
54
|
-
return std::numeric_limits<double>::quiet_NaN();
|
|
55
|
-
}
|
|
56
|
-
// Implements the ToInt32 abstract operation from ECMA-262.
|
|
57
|
-
inline int32_t ToInt32(const AnyValue &val)
|
|
58
|
-
{
|
|
59
|
-
double num = ToNumber(val);
|
|
60
|
-
|
|
61
|
-
if (std::isnan(num) || std::isinf(num) || num == 0)
|
|
62
|
-
return 0;
|
|
63
|
-
|
|
64
|
-
double posInt = std::signbit(num) ? -std::floor(std::abs(num)) : std::floor(std::abs(num));
|
|
65
|
-
double int32bit = fmod(posInt, 4294967296.0); // 2^32
|
|
66
|
-
|
|
67
|
-
if (int32bit >= 2147483648.0) // 2^31
|
|
68
|
-
return static_cast<int32_t>(int32bit - 4294967296.0);
|
|
69
|
-
else
|
|
70
|
-
return static_cast<int32_t>(int32bit);
|
|
71
|
-
}
|
|
72
|
-
// Implements the ToUint32 abstract operation from ECMA-262.
|
|
73
|
-
inline uint32_t ToUint32(const AnyValue &val)
|
|
74
|
-
{
|
|
75
|
-
double num = ToNumber(val);
|
|
76
|
-
if (std::isnan(num) || std::isinf(num) || num == 0)
|
|
77
|
-
return 0;
|
|
78
|
-
double posInt = std::signbit(num) ? -std::floor(std::abs(num)) : std::floor(std::abs(num));
|
|
79
|
-
uint32_t uint32bit = static_cast<uint32_t>(fmod(posInt, 4294967296.0));
|
|
80
|
-
return uint32bit;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// --- TRUTHY CHECKER ---
|
|
85
|
-
inline const bool is_truthy(const double &val) noexcept
|
|
86
|
-
{
|
|
87
|
-
return val != 0.0 && !std::isnan(val);
|
|
88
|
-
}
|
|
89
|
-
inline const bool is_truthy(const std::string &val) noexcept
|
|
90
|
-
{
|
|
91
|
-
return !val.empty();
|
|
92
|
-
}
|
|
93
|
-
inline const bool is_truthy(const AnyValue &val) noexcept
|
|
94
|
-
{
|
|
95
|
-
switch (val.get_type())
|
|
96
|
-
{
|
|
97
|
-
case JsType::Number:
|
|
98
|
-
return is_truthy(val.as_double());
|
|
99
|
-
case JsType::String:
|
|
100
|
-
return is_truthy(val.as_string()->value);
|
|
101
|
-
case JsType::Boolean:
|
|
102
|
-
return val.as_boolean();
|
|
103
|
-
case JsType::Null:
|
|
104
|
-
case JsType::Undefined:
|
|
105
|
-
case JsType::Uninitialized:
|
|
106
|
-
return false;
|
|
107
|
-
default:
|
|
108
|
-
return true;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// --- BASIC EQUALITY ---
|
|
113
|
-
|
|
114
|
-
// Operator === (returns primitive boolean)
|
|
115
|
-
inline const bool is_strictly_equal_to_primitive(const AnyValue &lhs, const double &rhs) noexcept
|
|
116
|
-
{
|
|
117
|
-
if (lhs.is_number())
|
|
118
|
-
return lhs.as_double() == rhs;
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
inline const bool is_strictly_equal_to_primitive(const double &lhs, const AnyValue &rhs) noexcept
|
|
122
|
-
{
|
|
123
|
-
if (rhs.is_number())
|
|
124
|
-
return lhs == rhs.as_double();
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
inline const bool is_strictly_equal_to_primitive(const double &lhs, const double &rhs) noexcept
|
|
128
|
-
{
|
|
129
|
-
return lhs == rhs;
|
|
130
|
-
}
|
|
131
|
-
inline const bool is_strictly_equal_to_primitive(const AnyValue &lhs, const AnyValue &rhs) noexcept
|
|
132
|
-
{
|
|
133
|
-
JsType type = lhs.get_type();
|
|
134
|
-
if (type != rhs.get_type())
|
|
135
|
-
return false;
|
|
136
|
-
switch (type)
|
|
137
|
-
{
|
|
138
|
-
case JsType::Boolean:
|
|
139
|
-
return lhs.as_boolean() == rhs.as_boolean();
|
|
140
|
-
case JsType::Number:
|
|
141
|
-
return lhs.as_double() == rhs.as_double();
|
|
142
|
-
case JsType::String:
|
|
143
|
-
return lhs.as_string()->value == rhs.as_string()->value;
|
|
144
|
-
case JsType::Array:
|
|
145
|
-
return lhs.as_array() == rhs.as_array();
|
|
146
|
-
case JsType::Object:
|
|
147
|
-
return lhs.as_object() == rhs.as_object();
|
|
148
|
-
case JsType::Function:
|
|
149
|
-
return lhs.as_function() == rhs.as_function();
|
|
150
|
-
case JsType::Iterator:
|
|
151
|
-
return lhs.as_iterator() == rhs.as_iterator();
|
|
152
|
-
case JsType::AsyncIterator:
|
|
153
|
-
return lhs.as_async_iterator() == rhs.as_async_iterator();
|
|
154
|
-
case JsType::Promise:
|
|
155
|
-
return lhs.as_promise() == rhs.as_promise();
|
|
156
|
-
case JsType::Symbol:
|
|
157
|
-
return lhs.as_symbol() == rhs.as_symbol();
|
|
158
|
-
case JsType::DataDescriptor:
|
|
159
|
-
return lhs.as_data_descriptor() == rhs.as_data_descriptor();
|
|
160
|
-
case JsType::AccessorDescriptor:
|
|
161
|
-
return lhs.as_accessor_descriptor() == rhs.as_accessor_descriptor();
|
|
162
|
-
default:
|
|
163
|
-
return true;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// Operator == (returns primitive boolean)
|
|
168
|
-
inline const bool is_equal_to_primitive(const AnyValue &lhs, const double &rhs) noexcept
|
|
169
|
-
{
|
|
170
|
-
return is_equal_to_primitive(lhs, AnyValue::make_number(rhs));
|
|
171
|
-
}
|
|
172
|
-
inline const bool is_equal_to_primitive(const double &lhs, const AnyValue &rhs) noexcept
|
|
173
|
-
{
|
|
174
|
-
return is_equal_to_primitive(AnyValue::make_number(lhs), rhs);
|
|
175
|
-
}
|
|
176
|
-
inline const bool is_equal_to_primitive(const double &lhs, const double &rhs) noexcept
|
|
177
|
-
{
|
|
178
|
-
return lhs == rhs;
|
|
179
|
-
}
|
|
180
|
-
inline const bool is_equal_to_primitive(const AnyValue &lhs, const AnyValue &rhs) noexcept
|
|
181
|
-
{
|
|
182
|
-
JsType lhs_type = lhs.get_type();
|
|
183
|
-
JsType rhs_type = rhs.get_type();
|
|
184
|
-
if (lhs_type == rhs_type)
|
|
185
|
-
{
|
|
186
|
-
return is_strictly_equal_to_primitive(lhs, rhs);
|
|
187
|
-
}
|
|
188
|
-
if ((lhs_type == JsType::Null && rhs_type == JsType::Undefined) || (lhs_type == JsType::Undefined && rhs_type == JsType::Null))
|
|
189
|
-
{
|
|
190
|
-
return true;
|
|
191
|
-
}
|
|
192
|
-
if (lhs_type == JsType::Number && rhs_type == JsType::String)
|
|
193
|
-
{
|
|
194
|
-
return lhs.as_double() == Operators_Private::ToNumber(rhs);
|
|
195
|
-
}
|
|
196
|
-
if (lhs_type == JsType::String && rhs_type == JsType::Number)
|
|
197
|
-
{
|
|
198
|
-
return Operators_Private::ToNumber(lhs) == rhs.as_double();
|
|
199
|
-
}
|
|
200
|
-
if (lhs_type == JsType::Boolean)
|
|
201
|
-
{
|
|
202
|
-
return is_equal_to_primitive(lhs.as_boolean() ? 1.0 : 0.0, rhs);
|
|
203
|
-
}
|
|
204
|
-
if (rhs_type == JsType::Boolean)
|
|
205
|
-
{
|
|
206
|
-
return is_equal_to_primitive(lhs, AnyValue::make_number(rhs.as_boolean() ? 1.0 : 0.0));
|
|
207
|
-
}
|
|
208
|
-
if ((lhs_type == JsType::Object || lhs_type == JsType::Array || lhs_type == JsType::Function || lhs_type == JsType::Promise || lhs_type == JsType::Iterator) &&
|
|
209
|
-
(rhs_type == JsType::String || rhs_type == JsType::Number || rhs_type == JsType::Symbol))
|
|
210
|
-
{
|
|
211
|
-
return is_equal_to_primitive(AnyValue::make_string(lhs.to_std_string()), rhs);
|
|
212
|
-
}
|
|
213
|
-
if ((rhs_type == JsType::Object || rhs_type == JsType::Array || rhs_type == JsType::Function || rhs_type == JsType::Promise || rhs_type == JsType::Iterator) &&
|
|
214
|
-
(lhs_type == JsType::String || lhs_type == JsType::Number || lhs_type == JsType::Symbol))
|
|
215
|
-
{
|
|
216
|
-
return is_equal_to_primitive(lhs, AnyValue::make_string(rhs.to_std_string()));
|
|
217
|
-
}
|
|
218
|
-
if (lhs_type == JsType::DataDescriptor || lhs_type == JsType::AccessorDescriptor)
|
|
219
|
-
{
|
|
220
|
-
return is_strictly_equal_to_primitive(lhs, rhs);
|
|
221
|
-
}
|
|
222
|
-
return false;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// --- PRIMITIVE ARITHMETIC OPERATORS ---
|
|
226
|
-
inline double add_primitive(const double &lhs, const double &rhs) { return lhs + rhs; }
|
|
227
|
-
inline double add_primitive(const AnyValue &lhs, const AnyValue &rhs) { return Operators_Private::ToNumber(lhs) + Operators_Private::ToNumber(rhs); }
|
|
228
|
-
inline double add_primitive(const AnyValue &lhs, const double &rhs) { return Operators_Private::ToNumber(lhs) + rhs; }
|
|
229
|
-
inline double add_primitive(const double &lhs, const AnyValue &rhs) { return lhs + Operators_Private::ToNumber(rhs); }
|
|
230
|
-
|
|
231
|
-
inline double sub_primitive(const double &lhs, const double &rhs) { return lhs - rhs; }
|
|
232
|
-
inline double sub_primitive(const AnyValue &lhs, const AnyValue &rhs) { return Operators_Private::ToNumber(lhs) - Operators_Private::ToNumber(rhs); }
|
|
233
|
-
inline double sub_primitive(const AnyValue &lhs, const double &rhs) { return Operators_Private::ToNumber(lhs) - rhs; }
|
|
234
|
-
inline double sub_primitive(const double &lhs, const AnyValue &rhs) { return lhs - Operators_Private::ToNumber(rhs); }
|
|
235
|
-
|
|
236
|
-
inline double mul_primitive(const double &lhs, const double &rhs) { return lhs * rhs; }
|
|
237
|
-
inline double mul_primitive(const AnyValue &lhs, const AnyValue &rhs) { return Operators_Private::ToNumber(lhs) * Operators_Private::ToNumber(rhs); }
|
|
238
|
-
inline double mul_primitive(const AnyValue &lhs, const double &rhs) { return Operators_Private::ToNumber(lhs) * rhs; }
|
|
239
|
-
inline double mul_primitive(const double &lhs, const AnyValue &rhs) { return lhs * Operators_Private::ToNumber(rhs); }
|
|
240
|
-
|
|
241
|
-
inline double div_primitive(const double &lhs, const double &rhs) { return lhs / rhs; }
|
|
242
|
-
inline double div_primitive(const AnyValue &lhs, const AnyValue &rhs) { return Operators_Private::ToNumber(lhs) / Operators_Private::ToNumber(rhs); }
|
|
243
|
-
inline double div_primitive(const AnyValue &lhs, const double &rhs) { return Operators_Private::ToNumber(lhs) / rhs; }
|
|
244
|
-
inline double div_primitive(const double &lhs, const AnyValue &rhs) { return lhs / Operators_Private::ToNumber(rhs); }
|
|
245
|
-
|
|
246
|
-
inline double mod_primitive(const double &lhs, const double &rhs) { return std::fmod(lhs, rhs); }
|
|
247
|
-
inline double mod_primitive(const AnyValue &lhs, const AnyValue &rhs) { return std::fmod(Operators_Private::ToNumber(lhs), Operators_Private::ToNumber(rhs)); }
|
|
248
|
-
inline double mod_primitive(const AnyValue &lhs, const double &rhs) { return std::fmod(Operators_Private::ToNumber(lhs), rhs); }
|
|
249
|
-
inline double mod_primitive(const double &lhs, const AnyValue &rhs) { return std::fmod(lhs, Operators_Private::ToNumber(rhs)); }
|
|
250
|
-
|
|
251
|
-
inline double pow_primitive(const double &lhs, const double &rhs) { return std::pow(lhs, rhs); }
|
|
252
|
-
inline double pow_primitive(const AnyValue &lhs, const AnyValue &rhs) { return std::pow(Operators_Private::ToNumber(lhs), Operators_Private::ToNumber(rhs)); }
|
|
253
|
-
inline double pow_primitive(const AnyValue &lhs, const double &rhs) { return std::pow(Operators_Private::ToNumber(lhs), rhs); }
|
|
254
|
-
inline double pow_primitive(const double &lhs, const AnyValue &rhs) { return std::pow(lhs, Operators_Private::ToNumber(rhs)); }
|
|
255
|
-
|
|
256
|
-
// --- PRIMITIVE COMPARISON OPERATORS ---
|
|
257
|
-
inline bool less_than_primitive(const double &lhs, const double &rhs) { return lhs < rhs; }
|
|
258
|
-
inline bool less_than_primitive(const AnyValue &lhs, const AnyValue &rhs) { return less_than_primitive(Operators_Private::ToNumber(lhs), Operators_Private::ToNumber(rhs)); }
|
|
259
|
-
inline bool less_than_primitive(const AnyValue &lhs, const double &rhs) { return less_than_primitive(Operators_Private::ToNumber(lhs), rhs); }
|
|
260
|
-
inline bool less_than_primitive(const double &lhs, const AnyValue &rhs) { return less_than_primitive(lhs, Operators_Private::ToNumber(rhs)); }
|
|
261
|
-
|
|
262
|
-
inline bool greater_than_primitive(const double &lhs, const double &rhs) { return lhs > rhs; }
|
|
263
|
-
inline bool greater_than_primitive(const AnyValue &lhs, const AnyValue &rhs) { return greater_than_primitive(Operators_Private::ToNumber(lhs), Operators_Private::ToNumber(rhs)); }
|
|
264
|
-
inline bool greater_than_primitive(const AnyValue &lhs, const double &rhs) { return greater_than_primitive(Operators_Private::ToNumber(lhs), rhs); }
|
|
265
|
-
inline bool greater_than_primitive(const double &lhs, const AnyValue &rhs) { return greater_than_primitive(lhs, Operators_Private::ToNumber(rhs)); }
|
|
266
|
-
|
|
267
|
-
inline bool less_than_or_equal_primitive(const double &lhs, const double &rhs) { return lhs <= rhs; }
|
|
268
|
-
inline bool less_than_or_equal_primitive(const AnyValue &lhs, const AnyValue &rhs) { return less_than_or_equal_primitive(Operators_Private::ToNumber(lhs), Operators_Private::ToNumber(rhs)); }
|
|
269
|
-
inline bool less_than_or_equal_primitive(const AnyValue &lhs, const double &rhs) { return less_than_or_equal_primitive(Operators_Private::ToNumber(lhs), rhs); }
|
|
270
|
-
inline bool less_than_or_equal_primitive(const double &lhs, const AnyValue &rhs) { return less_than_or_equal_primitive(lhs, Operators_Private::ToNumber(rhs)); }
|
|
271
|
-
|
|
272
|
-
inline bool greater_than_or_equal_primitive(const double &lhs, const double &rhs) { return lhs >= rhs; }
|
|
273
|
-
inline bool greater_than_or_equal_primitive(const AnyValue &lhs, const AnyValue &rhs) { return greater_than_or_equal_primitive(Operators_Private::ToNumber(lhs), Operators_Private::ToNumber(rhs)); }
|
|
274
|
-
inline bool greater_than_or_equal_primitive(const AnyValue &lhs, const double &rhs) { return greater_than_or_equal_primitive(Operators_Private::ToNumber(lhs), rhs); }
|
|
275
|
-
inline bool greater_than_or_equal_primitive(const double &lhs, const AnyValue &rhs) { return greater_than_or_equal_primitive(lhs, Operators_Private::ToNumber(rhs)); }
|
|
276
|
-
|
|
277
|
-
inline bool equal_primitive(const double &lhs, const double &rhs) { return lhs == rhs; }
|
|
278
|
-
inline bool equal_primitive(const AnyValue &lhs, const AnyValue &rhs) { return equal_primitive(Operators_Private::ToNumber(lhs), Operators_Private::ToNumber(rhs)); }
|
|
279
|
-
inline bool equal_primitive(const AnyValue &lhs, const double &rhs) { return equal_primitive(Operators_Private::ToNumber(lhs), rhs); }
|
|
280
|
-
inline bool equal_primitive(const double &lhs, const AnyValue &rhs) { return equal_primitive(lhs, Operators_Private::ToNumber(rhs)); }
|
|
281
|
-
|
|
282
|
-
inline bool not_equal_primitive(const double &lhs, const double &rhs) { return lhs != rhs; }
|
|
283
|
-
inline bool not_equal_primitive(const AnyValue &lhs, const AnyValue &rhs) { return not_equal_primitive(Operators_Private::ToNumber(lhs), Operators_Private::ToNumber(rhs)); }
|
|
284
|
-
inline bool not_equal_primitive(const AnyValue &lhs, const double &rhs) { return not_equal_primitive(Operators_Private::ToNumber(lhs), rhs); }
|
|
285
|
-
inline bool not_equal_primitive(const double &lhs, const AnyValue &rhs) { return not_equal_primitive(lhs, Operators_Private::ToNumber(rhs)); }
|
|
286
|
-
|
|
287
|
-
// --- PRIMITIVE BITWISE OPERATORS ---
|
|
288
|
-
inline double bitwise_and_primitive(const double &lhs, const double &rhs)
|
|
289
|
-
{
|
|
290
|
-
return static_cast<double>(static_cast<int32_t>(lhs) & static_cast<int32_t>(rhs));
|
|
291
|
-
}
|
|
292
|
-
inline double bitwise_and_primitive(const AnyValue &lhs, const AnyValue &rhs) { return bitwise_and_primitive(Operators_Private::ToInt32(lhs), Operators_Private::ToInt32(rhs)); }
|
|
293
|
-
inline double bitwise_and_primitive(const AnyValue &lhs, const double &rhs) { return bitwise_and_primitive(Operators_Private::ToInt32(lhs), rhs); }
|
|
294
|
-
inline double bitwise_and_primitive(const double &lhs, const AnyValue &rhs) { return bitwise_and_primitive(lhs, Operators_Private::ToInt32(rhs)); }
|
|
295
|
-
|
|
296
|
-
inline double bitwise_or_primitive(const double &lhs, const double &rhs)
|
|
297
|
-
{
|
|
298
|
-
return static_cast<double>(static_cast<int32_t>(lhs) | static_cast<int32_t>(rhs));
|
|
299
|
-
}
|
|
300
|
-
inline double bitwise_or_primitive(const AnyValue &lhs, const AnyValue &rhs) { return bitwise_or_primitive(Operators_Private::ToInt32(lhs), Operators_Private::ToInt32(rhs)); }
|
|
301
|
-
inline double bitwise_or_primitive(const AnyValue &lhs, const double &rhs) { return bitwise_or_primitive(Operators_Private::ToInt32(lhs), rhs); }
|
|
302
|
-
inline double bitwise_or_primitive(const double &lhs, const AnyValue &rhs) { return bitwise_or_primitive(lhs, Operators_Private::ToInt32(rhs)); }
|
|
303
|
-
|
|
304
|
-
inline double bitwise_xor_primitive(const double &lhs, const double &rhs)
|
|
305
|
-
{
|
|
306
|
-
return static_cast<double>(static_cast<int32_t>(lhs) ^ static_cast<int32_t>(rhs));
|
|
307
|
-
}
|
|
308
|
-
inline double bitwise_xor_primitive(const AnyValue &lhs, const AnyValue &rhs) { return bitwise_xor_primitive(Operators_Private::ToInt32(lhs), Operators_Private::ToInt32(rhs)); }
|
|
309
|
-
inline double bitwise_xor_primitive(const AnyValue &lhs, const double &rhs) { return bitwise_xor_primitive(Operators_Private::ToInt32(lhs), rhs); }
|
|
310
|
-
inline double bitwise_xor_primitive(const double &lhs, const AnyValue &rhs) { return bitwise_xor_primitive(lhs, Operators_Private::ToInt32(rhs)); }
|
|
311
|
-
|
|
312
|
-
inline double left_shift_primitive(const double &lhs, const double &rhs)
|
|
313
|
-
{
|
|
314
|
-
return static_cast<double>(static_cast<int32_t>(lhs) << (static_cast<int32_t>(rhs) & 0x1F));
|
|
315
|
-
}
|
|
316
|
-
inline double left_shift_primitive(const AnyValue &lhs, const AnyValue &rhs) { return left_shift_primitive(Operators_Private::ToInt32(lhs), Operators_Private::ToInt32(rhs)); }
|
|
317
|
-
inline double left_shift_primitive(const AnyValue &lhs, const double &rhs) { return left_shift_primitive(Operators_Private::ToInt32(lhs), rhs); }
|
|
318
|
-
inline double left_shift_primitive(const double &lhs, const AnyValue &rhs) { return left_shift_primitive(lhs, Operators_Private::ToInt32(rhs)); }
|
|
319
|
-
|
|
320
|
-
inline double right_shift_primitive(const double &lhs, const double &rhs)
|
|
321
|
-
{
|
|
322
|
-
return static_cast<double>(static_cast<int32_t>(lhs) >> (static_cast<int32_t>(rhs) & 0x1F));
|
|
323
|
-
}
|
|
324
|
-
inline double right_shift_primitive(const AnyValue &lhs, const AnyValue &rhs) { return right_shift_primitive(Operators_Private::ToInt32(lhs), Operators_Private::ToInt32(rhs)); }
|
|
325
|
-
inline double right_shift_primitive(const AnyValue &lhs, const double &rhs) { return right_shift_primitive(Operators_Private::ToInt32(lhs), rhs); }
|
|
326
|
-
inline double right_shift_primitive(const double &lhs, const AnyValue &rhs) { return right_shift_primitive(lhs, Operators_Private::ToInt32(rhs)); }
|
|
327
|
-
|
|
328
|
-
inline double unsigned_right_shift_primitive(const double &lhs, const double &rhs)
|
|
329
|
-
{
|
|
330
|
-
uint32_t l = static_cast<uint32_t>(fmod(lhs, 4294967296.0));
|
|
331
|
-
return static_cast<double>(l >> (static_cast<int32_t>(rhs) & 0x1F));
|
|
332
|
-
}
|
|
333
|
-
inline double unsigned_right_shift_primitive(const AnyValue &lhs, const AnyValue &rhs) { return unsigned_right_shift_primitive(Operators_Private::ToUint32(lhs), Operators_Private::ToInt32(rhs)); }
|
|
334
|
-
inline double unsigned_right_shift_primitive(const AnyValue &lhs, const double &rhs) { return unsigned_right_shift_primitive(Operators_Private::ToUint32(lhs), rhs); }
|
|
335
|
-
inline double unsigned_right_shift_primitive(const double &lhs, const AnyValue &rhs) { return unsigned_right_shift_primitive(lhs, Operators_Private::ToInt32(rhs)); }
|
|
336
|
-
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "types.hpp"
|
|
4
|
+
#include "any_value.hpp"
|
|
5
|
+
#include <cstdint> // For int32_t
|
|
6
|
+
#include <cmath> // For fmod, isnan, isinf, floor, abs, pow
|
|
7
|
+
#include <string> // For std::to_string, std::stod
|
|
8
|
+
#include <algorithm> // For std::all_of
|
|
9
|
+
#include <limits> // For numeric_limits
|
|
10
|
+
|
|
11
|
+
namespace jspp
|
|
12
|
+
{
|
|
13
|
+
// Private namespace for helper functions that implement JS type conversions.
|
|
14
|
+
namespace Operators_Private
|
|
15
|
+
{
|
|
16
|
+
// Implements the ToNumber abstract operation from ECMA-262.
|
|
17
|
+
inline double ToNumber(const AnyValue &val)
|
|
18
|
+
{
|
|
19
|
+
if (val.is_number())
|
|
20
|
+
return val.as_double();
|
|
21
|
+
if (val.is_null())
|
|
22
|
+
return 0.0;
|
|
23
|
+
if (val.is_undefined())
|
|
24
|
+
return std::numeric_limits<double>::quiet_NaN();
|
|
25
|
+
if (val.is_boolean())
|
|
26
|
+
return val.as_boolean() ? 1.0 : 0.0;
|
|
27
|
+
if (val.is_string())
|
|
28
|
+
{
|
|
29
|
+
const std::string &s = val.as_string()->value;
|
|
30
|
+
if (s.empty() || std::all_of(s.begin(), s.end(), [](unsigned char c)
|
|
31
|
+
{ return std::isspace(c); }))
|
|
32
|
+
return 0.0;
|
|
33
|
+
try
|
|
34
|
+
{
|
|
35
|
+
size_t pos;
|
|
36
|
+
double num = std::stod(s, &pos);
|
|
37
|
+
while (pos < s.length() && std::isspace(static_cast<unsigned char>(s[pos])))
|
|
38
|
+
pos++;
|
|
39
|
+
if (pos != s.length())
|
|
40
|
+
return std::numeric_limits<double>::quiet_NaN();
|
|
41
|
+
return num;
|
|
42
|
+
}
|
|
43
|
+
catch (...)
|
|
44
|
+
{
|
|
45
|
+
return std::numeric_limits<double>::quiet_NaN();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (val.is_uninitialized())
|
|
49
|
+
{
|
|
50
|
+
// THROW
|
|
51
|
+
Exception::throw_uninitialized_reference("#<Object>");
|
|
52
|
+
}
|
|
53
|
+
// Default to NaN
|
|
54
|
+
return std::numeric_limits<double>::quiet_NaN();
|
|
55
|
+
}
|
|
56
|
+
// Implements the ToInt32 abstract operation from ECMA-262.
|
|
57
|
+
inline int32_t ToInt32(const AnyValue &val)
|
|
58
|
+
{
|
|
59
|
+
double num = ToNumber(val);
|
|
60
|
+
|
|
61
|
+
if (std::isnan(num) || std::isinf(num) || num == 0)
|
|
62
|
+
return 0;
|
|
63
|
+
|
|
64
|
+
double posInt = std::signbit(num) ? -std::floor(std::abs(num)) : std::floor(std::abs(num));
|
|
65
|
+
double int32bit = fmod(posInt, 4294967296.0); // 2^32
|
|
66
|
+
|
|
67
|
+
if (int32bit >= 2147483648.0) // 2^31
|
|
68
|
+
return static_cast<int32_t>(int32bit - 4294967296.0);
|
|
69
|
+
else
|
|
70
|
+
return static_cast<int32_t>(int32bit);
|
|
71
|
+
}
|
|
72
|
+
// Implements the ToUint32 abstract operation from ECMA-262.
|
|
73
|
+
inline uint32_t ToUint32(const AnyValue &val)
|
|
74
|
+
{
|
|
75
|
+
double num = ToNumber(val);
|
|
76
|
+
if (std::isnan(num) || std::isinf(num) || num == 0)
|
|
77
|
+
return 0;
|
|
78
|
+
double posInt = std::signbit(num) ? -std::floor(std::abs(num)) : std::floor(std::abs(num));
|
|
79
|
+
uint32_t uint32bit = static_cast<uint32_t>(fmod(posInt, 4294967296.0));
|
|
80
|
+
return uint32bit;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// --- TRUTHY CHECKER ---
|
|
85
|
+
inline const bool is_truthy(const double &val) noexcept
|
|
86
|
+
{
|
|
87
|
+
return val != 0.0 && !std::isnan(val);
|
|
88
|
+
}
|
|
89
|
+
inline const bool is_truthy(const std::string &val) noexcept
|
|
90
|
+
{
|
|
91
|
+
return !val.empty();
|
|
92
|
+
}
|
|
93
|
+
inline const bool is_truthy(const AnyValue &val) noexcept
|
|
94
|
+
{
|
|
95
|
+
switch (val.get_type())
|
|
96
|
+
{
|
|
97
|
+
case JsType::Number:
|
|
98
|
+
return is_truthy(val.as_double());
|
|
99
|
+
case JsType::String:
|
|
100
|
+
return is_truthy(val.as_string()->value);
|
|
101
|
+
case JsType::Boolean:
|
|
102
|
+
return val.as_boolean();
|
|
103
|
+
case JsType::Null:
|
|
104
|
+
case JsType::Undefined:
|
|
105
|
+
case JsType::Uninitialized:
|
|
106
|
+
return false;
|
|
107
|
+
default:
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// --- BASIC EQUALITY ---
|
|
113
|
+
|
|
114
|
+
// Operator === (returns primitive boolean)
|
|
115
|
+
inline const bool is_strictly_equal_to_primitive(const AnyValue &lhs, const double &rhs) noexcept
|
|
116
|
+
{
|
|
117
|
+
if (lhs.is_number())
|
|
118
|
+
return lhs.as_double() == rhs;
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
inline const bool is_strictly_equal_to_primitive(const double &lhs, const AnyValue &rhs) noexcept
|
|
122
|
+
{
|
|
123
|
+
if (rhs.is_number())
|
|
124
|
+
return lhs == rhs.as_double();
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
inline const bool is_strictly_equal_to_primitive(const double &lhs, const double &rhs) noexcept
|
|
128
|
+
{
|
|
129
|
+
return lhs == rhs;
|
|
130
|
+
}
|
|
131
|
+
inline const bool is_strictly_equal_to_primitive(const AnyValue &lhs, const AnyValue &rhs) noexcept
|
|
132
|
+
{
|
|
133
|
+
JsType type = lhs.get_type();
|
|
134
|
+
if (type != rhs.get_type())
|
|
135
|
+
return false;
|
|
136
|
+
switch (type)
|
|
137
|
+
{
|
|
138
|
+
case JsType::Boolean:
|
|
139
|
+
return lhs.as_boolean() == rhs.as_boolean();
|
|
140
|
+
case JsType::Number:
|
|
141
|
+
return lhs.as_double() == rhs.as_double();
|
|
142
|
+
case JsType::String:
|
|
143
|
+
return lhs.as_string()->value == rhs.as_string()->value;
|
|
144
|
+
case JsType::Array:
|
|
145
|
+
return lhs.as_array() == rhs.as_array();
|
|
146
|
+
case JsType::Object:
|
|
147
|
+
return lhs.as_object() == rhs.as_object();
|
|
148
|
+
case JsType::Function:
|
|
149
|
+
return lhs.as_function() == rhs.as_function();
|
|
150
|
+
case JsType::Iterator:
|
|
151
|
+
return lhs.as_iterator() == rhs.as_iterator();
|
|
152
|
+
case JsType::AsyncIterator:
|
|
153
|
+
return lhs.as_async_iterator() == rhs.as_async_iterator();
|
|
154
|
+
case JsType::Promise:
|
|
155
|
+
return lhs.as_promise() == rhs.as_promise();
|
|
156
|
+
case JsType::Symbol:
|
|
157
|
+
return lhs.as_symbol() == rhs.as_symbol();
|
|
158
|
+
case JsType::DataDescriptor:
|
|
159
|
+
return lhs.as_data_descriptor() == rhs.as_data_descriptor();
|
|
160
|
+
case JsType::AccessorDescriptor:
|
|
161
|
+
return lhs.as_accessor_descriptor() == rhs.as_accessor_descriptor();
|
|
162
|
+
default:
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Operator == (returns primitive boolean)
|
|
168
|
+
inline const bool is_equal_to_primitive(const AnyValue &lhs, const double &rhs) noexcept
|
|
169
|
+
{
|
|
170
|
+
return is_equal_to_primitive(lhs, AnyValue::make_number(rhs));
|
|
171
|
+
}
|
|
172
|
+
inline const bool is_equal_to_primitive(const double &lhs, const AnyValue &rhs) noexcept
|
|
173
|
+
{
|
|
174
|
+
return is_equal_to_primitive(AnyValue::make_number(lhs), rhs);
|
|
175
|
+
}
|
|
176
|
+
inline const bool is_equal_to_primitive(const double &lhs, const double &rhs) noexcept
|
|
177
|
+
{
|
|
178
|
+
return lhs == rhs;
|
|
179
|
+
}
|
|
180
|
+
inline const bool is_equal_to_primitive(const AnyValue &lhs, const AnyValue &rhs) noexcept
|
|
181
|
+
{
|
|
182
|
+
JsType lhs_type = lhs.get_type();
|
|
183
|
+
JsType rhs_type = rhs.get_type();
|
|
184
|
+
if (lhs_type == rhs_type)
|
|
185
|
+
{
|
|
186
|
+
return is_strictly_equal_to_primitive(lhs, rhs);
|
|
187
|
+
}
|
|
188
|
+
if ((lhs_type == JsType::Null && rhs_type == JsType::Undefined) || (lhs_type == JsType::Undefined && rhs_type == JsType::Null))
|
|
189
|
+
{
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
if (lhs_type == JsType::Number && rhs_type == JsType::String)
|
|
193
|
+
{
|
|
194
|
+
return lhs.as_double() == Operators_Private::ToNumber(rhs);
|
|
195
|
+
}
|
|
196
|
+
if (lhs_type == JsType::String && rhs_type == JsType::Number)
|
|
197
|
+
{
|
|
198
|
+
return Operators_Private::ToNumber(lhs) == rhs.as_double();
|
|
199
|
+
}
|
|
200
|
+
if (lhs_type == JsType::Boolean)
|
|
201
|
+
{
|
|
202
|
+
return is_equal_to_primitive(lhs.as_boolean() ? 1.0 : 0.0, rhs);
|
|
203
|
+
}
|
|
204
|
+
if (rhs_type == JsType::Boolean)
|
|
205
|
+
{
|
|
206
|
+
return is_equal_to_primitive(lhs, AnyValue::make_number(rhs.as_boolean() ? 1.0 : 0.0));
|
|
207
|
+
}
|
|
208
|
+
if ((lhs_type == JsType::Object || lhs_type == JsType::Array || lhs_type == JsType::Function || lhs_type == JsType::Promise || lhs_type == JsType::Iterator) &&
|
|
209
|
+
(rhs_type == JsType::String || rhs_type == JsType::Number || rhs_type == JsType::Symbol))
|
|
210
|
+
{
|
|
211
|
+
return is_equal_to_primitive(AnyValue::make_string(lhs.to_std_string()), rhs);
|
|
212
|
+
}
|
|
213
|
+
if ((rhs_type == JsType::Object || rhs_type == JsType::Array || rhs_type == JsType::Function || rhs_type == JsType::Promise || rhs_type == JsType::Iterator) &&
|
|
214
|
+
(lhs_type == JsType::String || lhs_type == JsType::Number || lhs_type == JsType::Symbol))
|
|
215
|
+
{
|
|
216
|
+
return is_equal_to_primitive(lhs, AnyValue::make_string(rhs.to_std_string()));
|
|
217
|
+
}
|
|
218
|
+
if (lhs_type == JsType::DataDescriptor || lhs_type == JsType::AccessorDescriptor)
|
|
219
|
+
{
|
|
220
|
+
return is_strictly_equal_to_primitive(lhs, rhs);
|
|
221
|
+
}
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// --- PRIMITIVE ARITHMETIC OPERATORS ---
|
|
226
|
+
inline double add_primitive(const double &lhs, const double &rhs) { return lhs + rhs; }
|
|
227
|
+
inline double add_primitive(const AnyValue &lhs, const AnyValue &rhs) { return Operators_Private::ToNumber(lhs) + Operators_Private::ToNumber(rhs); }
|
|
228
|
+
inline double add_primitive(const AnyValue &lhs, const double &rhs) { return Operators_Private::ToNumber(lhs) + rhs; }
|
|
229
|
+
inline double add_primitive(const double &lhs, const AnyValue &rhs) { return lhs + Operators_Private::ToNumber(rhs); }
|
|
230
|
+
|
|
231
|
+
inline double sub_primitive(const double &lhs, const double &rhs) { return lhs - rhs; }
|
|
232
|
+
inline double sub_primitive(const AnyValue &lhs, const AnyValue &rhs) { return Operators_Private::ToNumber(lhs) - Operators_Private::ToNumber(rhs); }
|
|
233
|
+
inline double sub_primitive(const AnyValue &lhs, const double &rhs) { return Operators_Private::ToNumber(lhs) - rhs; }
|
|
234
|
+
inline double sub_primitive(const double &lhs, const AnyValue &rhs) { return lhs - Operators_Private::ToNumber(rhs); }
|
|
235
|
+
|
|
236
|
+
inline double mul_primitive(const double &lhs, const double &rhs) { return lhs * rhs; }
|
|
237
|
+
inline double mul_primitive(const AnyValue &lhs, const AnyValue &rhs) { return Operators_Private::ToNumber(lhs) * Operators_Private::ToNumber(rhs); }
|
|
238
|
+
inline double mul_primitive(const AnyValue &lhs, const double &rhs) { return Operators_Private::ToNumber(lhs) * rhs; }
|
|
239
|
+
inline double mul_primitive(const double &lhs, const AnyValue &rhs) { return lhs * Operators_Private::ToNumber(rhs); }
|
|
240
|
+
|
|
241
|
+
inline double div_primitive(const double &lhs, const double &rhs) { return lhs / rhs; }
|
|
242
|
+
inline double div_primitive(const AnyValue &lhs, const AnyValue &rhs) { return Operators_Private::ToNumber(lhs) / Operators_Private::ToNumber(rhs); }
|
|
243
|
+
inline double div_primitive(const AnyValue &lhs, const double &rhs) { return Operators_Private::ToNumber(lhs) / rhs; }
|
|
244
|
+
inline double div_primitive(const double &lhs, const AnyValue &rhs) { return lhs / Operators_Private::ToNumber(rhs); }
|
|
245
|
+
|
|
246
|
+
inline double mod_primitive(const double &lhs, const double &rhs) { return std::fmod(lhs, rhs); }
|
|
247
|
+
inline double mod_primitive(const AnyValue &lhs, const AnyValue &rhs) { return std::fmod(Operators_Private::ToNumber(lhs), Operators_Private::ToNumber(rhs)); }
|
|
248
|
+
inline double mod_primitive(const AnyValue &lhs, const double &rhs) { return std::fmod(Operators_Private::ToNumber(lhs), rhs); }
|
|
249
|
+
inline double mod_primitive(const double &lhs, const AnyValue &rhs) { return std::fmod(lhs, Operators_Private::ToNumber(rhs)); }
|
|
250
|
+
|
|
251
|
+
inline double pow_primitive(const double &lhs, const double &rhs) { return std::pow(lhs, rhs); }
|
|
252
|
+
inline double pow_primitive(const AnyValue &lhs, const AnyValue &rhs) { return std::pow(Operators_Private::ToNumber(lhs), Operators_Private::ToNumber(rhs)); }
|
|
253
|
+
inline double pow_primitive(const AnyValue &lhs, const double &rhs) { return std::pow(Operators_Private::ToNumber(lhs), rhs); }
|
|
254
|
+
inline double pow_primitive(const double &lhs, const AnyValue &rhs) { return std::pow(lhs, Operators_Private::ToNumber(rhs)); }
|
|
255
|
+
|
|
256
|
+
// --- PRIMITIVE COMPARISON OPERATORS ---
|
|
257
|
+
inline bool less_than_primitive(const double &lhs, const double &rhs) { return lhs < rhs; }
|
|
258
|
+
inline bool less_than_primitive(const AnyValue &lhs, const AnyValue &rhs) { return less_than_primitive(Operators_Private::ToNumber(lhs), Operators_Private::ToNumber(rhs)); }
|
|
259
|
+
inline bool less_than_primitive(const AnyValue &lhs, const double &rhs) { return less_than_primitive(Operators_Private::ToNumber(lhs), rhs); }
|
|
260
|
+
inline bool less_than_primitive(const double &lhs, const AnyValue &rhs) { return less_than_primitive(lhs, Operators_Private::ToNumber(rhs)); }
|
|
261
|
+
|
|
262
|
+
inline bool greater_than_primitive(const double &lhs, const double &rhs) { return lhs > rhs; }
|
|
263
|
+
inline bool greater_than_primitive(const AnyValue &lhs, const AnyValue &rhs) { return greater_than_primitive(Operators_Private::ToNumber(lhs), Operators_Private::ToNumber(rhs)); }
|
|
264
|
+
inline bool greater_than_primitive(const AnyValue &lhs, const double &rhs) { return greater_than_primitive(Operators_Private::ToNumber(lhs), rhs); }
|
|
265
|
+
inline bool greater_than_primitive(const double &lhs, const AnyValue &rhs) { return greater_than_primitive(lhs, Operators_Private::ToNumber(rhs)); }
|
|
266
|
+
|
|
267
|
+
inline bool less_than_or_equal_primitive(const double &lhs, const double &rhs) { return lhs <= rhs; }
|
|
268
|
+
inline bool less_than_or_equal_primitive(const AnyValue &lhs, const AnyValue &rhs) { return less_than_or_equal_primitive(Operators_Private::ToNumber(lhs), Operators_Private::ToNumber(rhs)); }
|
|
269
|
+
inline bool less_than_or_equal_primitive(const AnyValue &lhs, const double &rhs) { return less_than_or_equal_primitive(Operators_Private::ToNumber(lhs), rhs); }
|
|
270
|
+
inline bool less_than_or_equal_primitive(const double &lhs, const AnyValue &rhs) { return less_than_or_equal_primitive(lhs, Operators_Private::ToNumber(rhs)); }
|
|
271
|
+
|
|
272
|
+
inline bool greater_than_or_equal_primitive(const double &lhs, const double &rhs) { return lhs >= rhs; }
|
|
273
|
+
inline bool greater_than_or_equal_primitive(const AnyValue &lhs, const AnyValue &rhs) { return greater_than_or_equal_primitive(Operators_Private::ToNumber(lhs), Operators_Private::ToNumber(rhs)); }
|
|
274
|
+
inline bool greater_than_or_equal_primitive(const AnyValue &lhs, const double &rhs) { return greater_than_or_equal_primitive(Operators_Private::ToNumber(lhs), rhs); }
|
|
275
|
+
inline bool greater_than_or_equal_primitive(const double &lhs, const AnyValue &rhs) { return greater_than_or_equal_primitive(lhs, Operators_Private::ToNumber(rhs)); }
|
|
276
|
+
|
|
277
|
+
inline bool equal_primitive(const double &lhs, const double &rhs) { return lhs == rhs; }
|
|
278
|
+
inline bool equal_primitive(const AnyValue &lhs, const AnyValue &rhs) { return equal_primitive(Operators_Private::ToNumber(lhs), Operators_Private::ToNumber(rhs)); }
|
|
279
|
+
inline bool equal_primitive(const AnyValue &lhs, const double &rhs) { return equal_primitive(Operators_Private::ToNumber(lhs), rhs); }
|
|
280
|
+
inline bool equal_primitive(const double &lhs, const AnyValue &rhs) { return equal_primitive(lhs, Operators_Private::ToNumber(rhs)); }
|
|
281
|
+
|
|
282
|
+
inline bool not_equal_primitive(const double &lhs, const double &rhs) { return lhs != rhs; }
|
|
283
|
+
inline bool not_equal_primitive(const AnyValue &lhs, const AnyValue &rhs) { return not_equal_primitive(Operators_Private::ToNumber(lhs), Operators_Private::ToNumber(rhs)); }
|
|
284
|
+
inline bool not_equal_primitive(const AnyValue &lhs, const double &rhs) { return not_equal_primitive(Operators_Private::ToNumber(lhs), rhs); }
|
|
285
|
+
inline bool not_equal_primitive(const double &lhs, const AnyValue &rhs) { return not_equal_primitive(lhs, Operators_Private::ToNumber(rhs)); }
|
|
286
|
+
|
|
287
|
+
// --- PRIMITIVE BITWISE OPERATORS ---
|
|
288
|
+
inline double bitwise_and_primitive(const double &lhs, const double &rhs)
|
|
289
|
+
{
|
|
290
|
+
return static_cast<double>(static_cast<int32_t>(lhs) & static_cast<int32_t>(rhs));
|
|
291
|
+
}
|
|
292
|
+
inline double bitwise_and_primitive(const AnyValue &lhs, const AnyValue &rhs) { return bitwise_and_primitive(Operators_Private::ToInt32(lhs), Operators_Private::ToInt32(rhs)); }
|
|
293
|
+
inline double bitwise_and_primitive(const AnyValue &lhs, const double &rhs) { return bitwise_and_primitive(Operators_Private::ToInt32(lhs), rhs); }
|
|
294
|
+
inline double bitwise_and_primitive(const double &lhs, const AnyValue &rhs) { return bitwise_and_primitive(lhs, Operators_Private::ToInt32(rhs)); }
|
|
295
|
+
|
|
296
|
+
inline double bitwise_or_primitive(const double &lhs, const double &rhs)
|
|
297
|
+
{
|
|
298
|
+
return static_cast<double>(static_cast<int32_t>(lhs) | static_cast<int32_t>(rhs));
|
|
299
|
+
}
|
|
300
|
+
inline double bitwise_or_primitive(const AnyValue &lhs, const AnyValue &rhs) { return bitwise_or_primitive(Operators_Private::ToInt32(lhs), Operators_Private::ToInt32(rhs)); }
|
|
301
|
+
inline double bitwise_or_primitive(const AnyValue &lhs, const double &rhs) { return bitwise_or_primitive(Operators_Private::ToInt32(lhs), rhs); }
|
|
302
|
+
inline double bitwise_or_primitive(const double &lhs, const AnyValue &rhs) { return bitwise_or_primitive(lhs, Operators_Private::ToInt32(rhs)); }
|
|
303
|
+
|
|
304
|
+
inline double bitwise_xor_primitive(const double &lhs, const double &rhs)
|
|
305
|
+
{
|
|
306
|
+
return static_cast<double>(static_cast<int32_t>(lhs) ^ static_cast<int32_t>(rhs));
|
|
307
|
+
}
|
|
308
|
+
inline double bitwise_xor_primitive(const AnyValue &lhs, const AnyValue &rhs) { return bitwise_xor_primitive(Operators_Private::ToInt32(lhs), Operators_Private::ToInt32(rhs)); }
|
|
309
|
+
inline double bitwise_xor_primitive(const AnyValue &lhs, const double &rhs) { return bitwise_xor_primitive(Operators_Private::ToInt32(lhs), rhs); }
|
|
310
|
+
inline double bitwise_xor_primitive(const double &lhs, const AnyValue &rhs) { return bitwise_xor_primitive(lhs, Operators_Private::ToInt32(rhs)); }
|
|
311
|
+
|
|
312
|
+
inline double left_shift_primitive(const double &lhs, const double &rhs)
|
|
313
|
+
{
|
|
314
|
+
return static_cast<double>(static_cast<int32_t>(lhs) << (static_cast<int32_t>(rhs) & 0x1F));
|
|
315
|
+
}
|
|
316
|
+
inline double left_shift_primitive(const AnyValue &lhs, const AnyValue &rhs) { return left_shift_primitive(Operators_Private::ToInt32(lhs), Operators_Private::ToInt32(rhs)); }
|
|
317
|
+
inline double left_shift_primitive(const AnyValue &lhs, const double &rhs) { return left_shift_primitive(Operators_Private::ToInt32(lhs), rhs); }
|
|
318
|
+
inline double left_shift_primitive(const double &lhs, const AnyValue &rhs) { return left_shift_primitive(lhs, Operators_Private::ToInt32(rhs)); }
|
|
319
|
+
|
|
320
|
+
inline double right_shift_primitive(const double &lhs, const double &rhs)
|
|
321
|
+
{
|
|
322
|
+
return static_cast<double>(static_cast<int32_t>(lhs) >> (static_cast<int32_t>(rhs) & 0x1F));
|
|
323
|
+
}
|
|
324
|
+
inline double right_shift_primitive(const AnyValue &lhs, const AnyValue &rhs) { return right_shift_primitive(Operators_Private::ToInt32(lhs), Operators_Private::ToInt32(rhs)); }
|
|
325
|
+
inline double right_shift_primitive(const AnyValue &lhs, const double &rhs) { return right_shift_primitive(Operators_Private::ToInt32(lhs), rhs); }
|
|
326
|
+
inline double right_shift_primitive(const double &lhs, const AnyValue &rhs) { return right_shift_primitive(lhs, Operators_Private::ToInt32(rhs)); }
|
|
327
|
+
|
|
328
|
+
inline double unsigned_right_shift_primitive(const double &lhs, const double &rhs)
|
|
329
|
+
{
|
|
330
|
+
uint32_t l = static_cast<uint32_t>(fmod(lhs, 4294967296.0));
|
|
331
|
+
return static_cast<double>(l >> (static_cast<int32_t>(rhs) & 0x1F));
|
|
332
|
+
}
|
|
333
|
+
inline double unsigned_right_shift_primitive(const AnyValue &lhs, const AnyValue &rhs) { return unsigned_right_shift_primitive(Operators_Private::ToUint32(lhs), Operators_Private::ToInt32(rhs)); }
|
|
334
|
+
inline double unsigned_right_shift_primitive(const AnyValue &lhs, const double &rhs) { return unsigned_right_shift_primitive(Operators_Private::ToUint32(lhs), rhs); }
|
|
335
|
+
inline double unsigned_right_shift_primitive(const double &lhs, const AnyValue &rhs) { return unsigned_right_shift_primitive(lhs, Operators_Private::ToInt32(rhs)); }
|
|
336
|
+
|
|
337
337
|
}
|