@ugo-studio/jspp 0.2.6 → 0.2.7
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/dist/analysis/typeAnalyzer.js +56 -24
- package/dist/ast/symbols.js +28 -19
- package/dist/cli/index.js +1 -1
- package/dist/core/codegen/class-handlers.js +8 -8
- package/dist/core/codegen/control-flow-handlers.js +17 -7
- package/dist/core/codegen/declaration-handlers.js +21 -9
- package/dist/core/codegen/expression-handlers.js +558 -126
- package/dist/core/codegen/function-handlers.js +101 -108
- package/dist/core/codegen/helpers.js +28 -7
- package/dist/core/codegen/index.js +6 -4
- package/dist/core/codegen/literal-handlers.js +4 -2
- package/dist/core/codegen/statement-handlers.js +39 -19
- package/package.json +1 -1
- package/src/prelude/any_value.hpp +89 -59
- package/src/prelude/any_value_access.hpp +1 -1
- package/src/prelude/any_value_helpers.hpp +85 -43
- package/src/prelude/index.hpp +1 -0
- package/src/prelude/library/array.hpp +3 -2
- package/src/prelude/types.hpp +8 -8
- package/src/prelude/utils/access.hpp +62 -6
- package/src/prelude/utils/assignment_operators.hpp +14 -14
- package/src/prelude/utils/log_any_value/array.hpp +0 -15
- package/src/prelude/utils/log_any_value/primitives.hpp +2 -0
- package/src/prelude/utils/operators.hpp +117 -474
- package/src/prelude/utils/operators_primitive.hpp +337 -0
- package/src/prelude/values/helpers/array.hpp +4 -4
- package/src/prelude/values/helpers/async_iterator.hpp +2 -2
- package/src/prelude/values/helpers/function.hpp +3 -3
- package/src/prelude/values/helpers/iterator.hpp +2 -2
- package/src/prelude/values/helpers/object.hpp +3 -3
- package/src/prelude/values/helpers/promise.hpp +1 -1
- package/src/prelude/values/helpers/string.hpp +1 -1
- package/src/prelude/values/helpers/symbol.hpp +1 -1
- package/src/prelude/values/prototypes/array.hpp +1125 -853
- package/src/prelude/values/prototypes/async_iterator.hpp +32 -14
- package/src/prelude/values/prototypes/function.hpp +30 -18
- package/src/prelude/values/prototypes/iterator.hpp +40 -17
- package/src/prelude/values/prototypes/number.hpp +119 -62
- package/src/prelude/values/prototypes/object.hpp +10 -4
- package/src/prelude/values/prototypes/promise.hpp +167 -109
- package/src/prelude/values/prototypes/string.hpp +407 -231
- package/src/prelude/values/prototypes/symbol.hpp +45 -23
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
#include "types.hpp"
|
|
4
4
|
#include "any_value.hpp"
|
|
5
|
+
#include "operators_primitive.hpp"
|
|
5
6
|
#include <cstdint> // For int32_t
|
|
6
7
|
#include <cmath> // For fmod, isnan, isinf, floor, abs, pow
|
|
7
8
|
#include <string> // For std::to_string, std::stod
|
|
@@ -10,217 +11,6 @@
|
|
|
10
11
|
|
|
11
12
|
namespace jspp
|
|
12
13
|
{
|
|
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
|
-
switch (val.get_type())
|
|
20
|
-
{
|
|
21
|
-
case JsType::Number:
|
|
22
|
-
return val.as_double();
|
|
23
|
-
case JsType::Null:
|
|
24
|
-
return 0.0;
|
|
25
|
-
case JsType::Uninitialized:
|
|
26
|
-
case JsType::Undefined:
|
|
27
|
-
return std::numeric_limits<double>::quiet_NaN();
|
|
28
|
-
case JsType::Boolean:
|
|
29
|
-
return val.as_boolean() ? 1.0 : 0.0;
|
|
30
|
-
case JsType::String:
|
|
31
|
-
{
|
|
32
|
-
const std::string &s = val.as_string()->value;
|
|
33
|
-
if (s.empty() || std::all_of(s.begin(), s.end(), [](unsigned char c)
|
|
34
|
-
{ return std::isspace(c); }))
|
|
35
|
-
return 0.0;
|
|
36
|
-
try
|
|
37
|
-
{
|
|
38
|
-
size_t pos;
|
|
39
|
-
double num = std::stod(s, &pos);
|
|
40
|
-
while (pos < s.length() && std::isspace(static_cast<unsigned char>(s[pos])))
|
|
41
|
-
pos++;
|
|
42
|
-
if (pos != s.length())
|
|
43
|
-
return std::numeric_limits<double>::quiet_NaN();
|
|
44
|
-
return num;
|
|
45
|
-
}
|
|
46
|
-
catch (...)
|
|
47
|
-
{
|
|
48
|
-
return std::numeric_limits<double>::quiet_NaN();
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
default:
|
|
52
|
-
return std::numeric_limits<double>::quiet_NaN();
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
// Implements the ToInt32 abstract operation from ECMA-262.
|
|
56
|
-
inline int32_t ToInt32(const AnyValue &val)
|
|
57
|
-
{
|
|
58
|
-
double num = ToNumber(val);
|
|
59
|
-
|
|
60
|
-
if (std::isnan(num) || std::isinf(num) || num == 0)
|
|
61
|
-
return 0;
|
|
62
|
-
|
|
63
|
-
double posInt = std::signbit(num) ? -std::floor(std::abs(num)) : std::floor(std::abs(num));
|
|
64
|
-
double int32bit = fmod(posInt, 4294967296.0); // 2^32
|
|
65
|
-
|
|
66
|
-
if (int32bit >= 2147483648.0) // 2^31
|
|
67
|
-
return static_cast<int32_t>(int32bit - 4294967296.0);
|
|
68
|
-
else
|
|
69
|
-
return static_cast<int32_t>(int32bit);
|
|
70
|
-
}
|
|
71
|
-
// Implements the ToUint32 abstract operation from ECMA-262.
|
|
72
|
-
inline uint32_t ToUint32(const AnyValue &val)
|
|
73
|
-
{
|
|
74
|
-
double num = ToNumber(val);
|
|
75
|
-
if (std::isnan(num) || std::isinf(num) || num == 0)
|
|
76
|
-
return 0;
|
|
77
|
-
double posInt = std::signbit(num) ? -std::floor(std::abs(num)) : std::floor(std::abs(num));
|
|
78
|
-
uint32_t uint32bit = static_cast<uint32_t>(fmod(posInt, 4294967296.0));
|
|
79
|
-
return uint32bit;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// --- TRUTHY CHECKER ---
|
|
84
|
-
inline const bool is_truthy(const double &val) noexcept
|
|
85
|
-
{
|
|
86
|
-
return val != 0.0 && !std::isnan(val);
|
|
87
|
-
}
|
|
88
|
-
inline const bool is_truthy(const std::string &val) noexcept
|
|
89
|
-
{
|
|
90
|
-
return !val.empty();
|
|
91
|
-
}
|
|
92
|
-
inline const bool is_truthy(const AnyValue &val) noexcept
|
|
93
|
-
{
|
|
94
|
-
switch (val.get_type())
|
|
95
|
-
{
|
|
96
|
-
case JsType::Number:
|
|
97
|
-
return is_truthy(val.as_double());
|
|
98
|
-
case JsType::String:
|
|
99
|
-
return is_truthy(val.as_string()->value);
|
|
100
|
-
case JsType::Boolean:
|
|
101
|
-
return val.as_boolean();
|
|
102
|
-
case JsType::Null:
|
|
103
|
-
case JsType::Undefined:
|
|
104
|
-
case JsType::Uninitialized:
|
|
105
|
-
return false;
|
|
106
|
-
default:
|
|
107
|
-
return true;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// --- BASIC EQUALITY ---
|
|
112
|
-
|
|
113
|
-
// Operator === (returns primitive boolean)
|
|
114
|
-
inline const bool is_strictly_equal_to_primitive(const AnyValue &lhs, const double &rhs) noexcept
|
|
115
|
-
{
|
|
116
|
-
if (lhs.is_number())
|
|
117
|
-
return lhs.as_double() == rhs;
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
inline const bool is_strictly_equal_to_primitive(const double &lhs, const AnyValue &rhs) noexcept
|
|
121
|
-
{
|
|
122
|
-
if (rhs.is_number())
|
|
123
|
-
return lhs == rhs.as_double();
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
inline const bool is_strictly_equal_to_primitive(const double &lhs, const double &rhs) noexcept
|
|
127
|
-
{
|
|
128
|
-
return lhs == rhs;
|
|
129
|
-
}
|
|
130
|
-
inline const bool is_strictly_equal_to_primitive(const AnyValue &lhs, const AnyValue &rhs) noexcept
|
|
131
|
-
{
|
|
132
|
-
JsType type = lhs.get_type();
|
|
133
|
-
if (type != rhs.get_type())
|
|
134
|
-
return false;
|
|
135
|
-
switch (type)
|
|
136
|
-
{
|
|
137
|
-
case JsType::Boolean:
|
|
138
|
-
return lhs.as_boolean() == rhs.as_boolean();
|
|
139
|
-
case JsType::Number:
|
|
140
|
-
return lhs.as_double() == rhs.as_double();
|
|
141
|
-
case JsType::String:
|
|
142
|
-
return lhs.as_string()->value == rhs.as_string()->value;
|
|
143
|
-
case JsType::Array:
|
|
144
|
-
return lhs.as_array() == rhs.as_array();
|
|
145
|
-
case JsType::Object:
|
|
146
|
-
return lhs.as_object() == rhs.as_object();
|
|
147
|
-
case JsType::Function:
|
|
148
|
-
return lhs.as_function() == rhs.as_function();
|
|
149
|
-
case JsType::Iterator:
|
|
150
|
-
return lhs.as_iterator() == rhs.as_iterator();
|
|
151
|
-
case JsType::AsyncIterator:
|
|
152
|
-
return lhs.as_async_iterator() == rhs.as_async_iterator();
|
|
153
|
-
case JsType::Promise:
|
|
154
|
-
return lhs.as_promise() == rhs.as_promise();
|
|
155
|
-
case JsType::Symbol:
|
|
156
|
-
return lhs.as_symbol() == rhs.as_symbol();
|
|
157
|
-
case JsType::DataDescriptor:
|
|
158
|
-
return lhs.as_data_descriptor() == rhs.as_data_descriptor();
|
|
159
|
-
case JsType::AccessorDescriptor:
|
|
160
|
-
return lhs.as_accessor_descriptor() == rhs.as_accessor_descriptor();
|
|
161
|
-
default:
|
|
162
|
-
return true;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// Operator == (returns primitive boolean)
|
|
167
|
-
inline const bool is_equal_to_primitive(const AnyValue &lhs, const double &rhs) noexcept
|
|
168
|
-
{
|
|
169
|
-
return is_equal_to_primitive(lhs, AnyValue::make_number(rhs));
|
|
170
|
-
}
|
|
171
|
-
inline const bool is_equal_to_primitive(const double &lhs, const AnyValue &rhs) noexcept
|
|
172
|
-
{
|
|
173
|
-
return is_equal_to_primitive(AnyValue::make_number(lhs), rhs);
|
|
174
|
-
}
|
|
175
|
-
inline const bool is_equal_to_primitive(const double &lhs, const double &rhs) noexcept
|
|
176
|
-
{
|
|
177
|
-
return lhs == rhs;
|
|
178
|
-
}
|
|
179
|
-
inline const bool is_equal_to_primitive(const AnyValue &lhs, const AnyValue &rhs) noexcept
|
|
180
|
-
{
|
|
181
|
-
JsType lhs_type = lhs.get_type();
|
|
182
|
-
JsType rhs_type = rhs.get_type();
|
|
183
|
-
if (lhs_type == rhs_type)
|
|
184
|
-
{
|
|
185
|
-
return is_strictly_equal_to_primitive(lhs, rhs);
|
|
186
|
-
}
|
|
187
|
-
if ((lhs_type == JsType::Null && rhs_type == JsType::Undefined) || (lhs_type == JsType::Undefined && rhs_type == JsType::Null))
|
|
188
|
-
{
|
|
189
|
-
return true;
|
|
190
|
-
}
|
|
191
|
-
if (lhs_type == JsType::Number && rhs_type == JsType::String)
|
|
192
|
-
{
|
|
193
|
-
return lhs.as_double() == Operators_Private::ToNumber(rhs);
|
|
194
|
-
}
|
|
195
|
-
if (lhs_type == JsType::String && rhs_type == JsType::Number)
|
|
196
|
-
{
|
|
197
|
-
return Operators_Private::ToNumber(lhs) == rhs.as_double();
|
|
198
|
-
}
|
|
199
|
-
if (lhs_type == JsType::Boolean)
|
|
200
|
-
{
|
|
201
|
-
return is_equal_to_primitive(lhs.as_boolean() ? 1.0 : 0.0, rhs);
|
|
202
|
-
}
|
|
203
|
-
if (rhs_type == JsType::Boolean)
|
|
204
|
-
{
|
|
205
|
-
return is_equal_to_primitive(lhs, AnyValue::make_number(rhs.as_boolean() ? 1.0 : 0.0));
|
|
206
|
-
}
|
|
207
|
-
if ((lhs_type == JsType::Object || lhs_type == JsType::Array || lhs_type == JsType::Function || lhs_type == JsType::Promise || lhs_type == JsType::Iterator) &&
|
|
208
|
-
(rhs_type == JsType::String || rhs_type == JsType::Number || rhs_type == JsType::Symbol))
|
|
209
|
-
{
|
|
210
|
-
return is_equal_to_primitive(AnyValue::make_string(lhs.to_std_string()), rhs);
|
|
211
|
-
}
|
|
212
|
-
if ((rhs_type == JsType::Object || rhs_type == JsType::Array || rhs_type == JsType::Function || rhs_type == JsType::Promise || rhs_type == JsType::Iterator) &&
|
|
213
|
-
(lhs_type == JsType::String || lhs_type == JsType::Number || lhs_type == JsType::Symbol))
|
|
214
|
-
{
|
|
215
|
-
return is_equal_to_primitive(lhs, AnyValue::make_string(rhs.to_std_string()));
|
|
216
|
-
}
|
|
217
|
-
if (lhs_type == JsType::DataDescriptor || lhs_type == JsType::AccessorDescriptor)
|
|
218
|
-
{
|
|
219
|
-
return is_strictly_equal_to_primitive(lhs, rhs);
|
|
220
|
-
}
|
|
221
|
-
return false;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
14
|
// Operator === (returns boolean wrapped in AnyValue)
|
|
225
15
|
inline const AnyValue is_strictly_equal_to(const AnyValue &lhs, const double &rhs) noexcept
|
|
226
16
|
{
|
|
@@ -295,351 +85,208 @@ namespace jspp
|
|
|
295
85
|
|
|
296
86
|
// --- BASIC ARITHMETIC ---
|
|
297
87
|
|
|
298
|
-
//
|
|
299
|
-
inline AnyValue
|
|
88
|
+
// Function add
|
|
89
|
+
inline AnyValue add(const AnyValue &lhs, const AnyValue &rhs)
|
|
300
90
|
{
|
|
301
91
|
if (lhs.is_number() && rhs.is_number())
|
|
302
|
-
return AnyValue::make_number(lhs.as_double()
|
|
92
|
+
return AnyValue::make_number(add_primitive(lhs.as_double(), rhs.as_double()));
|
|
303
93
|
if (lhs.is_string() || rhs.is_string())
|
|
304
94
|
return AnyValue::make_string(lhs.to_std_string() + rhs.to_std_string());
|
|
305
|
-
return AnyValue::make_number(
|
|
95
|
+
return AnyValue::make_number(add_primitive(lhs, rhs));
|
|
306
96
|
}
|
|
307
|
-
inline AnyValue
|
|
97
|
+
inline AnyValue add(const AnyValue &lhs, const double &rhs)
|
|
308
98
|
{
|
|
309
99
|
if (lhs.is_number())
|
|
310
|
-
return AnyValue::make_number(lhs.as_double()
|
|
100
|
+
return AnyValue::make_number(add_primitive(lhs.as_double(), rhs));
|
|
311
101
|
if (lhs.is_string())
|
|
312
102
|
return AnyValue::make_string(lhs.to_std_string() + std::to_string(rhs));
|
|
313
|
-
return AnyValue::make_number(
|
|
103
|
+
return AnyValue::make_number(add_primitive(lhs, rhs));
|
|
314
104
|
}
|
|
315
|
-
inline AnyValue
|
|
105
|
+
inline AnyValue add(const double &lhs, const AnyValue &rhs)
|
|
316
106
|
{
|
|
317
107
|
if (rhs.is_number())
|
|
318
|
-
return AnyValue::make_number(lhs
|
|
108
|
+
return AnyValue::make_number(add_primitive(lhs, rhs.as_double()));
|
|
319
109
|
if (rhs.is_string())
|
|
320
110
|
return AnyValue::make_string(std::to_string(lhs) + rhs.to_std_string());
|
|
321
|
-
return AnyValue::make_number(lhs
|
|
111
|
+
return AnyValue::make_number(add_primitive(lhs, rhs));
|
|
322
112
|
}
|
|
323
|
-
|
|
324
|
-
// Operator -
|
|
325
|
-
inline AnyValue operator-(const AnyValue &lhs, const AnyValue &rhs)
|
|
113
|
+
inline AnyValue add(const double &lhs, const double &rhs)
|
|
326
114
|
{
|
|
327
|
-
|
|
328
|
-
return AnyValue::make_number(lhs.as_double() - rhs.as_double());
|
|
329
|
-
return AnyValue::make_number(Operators_Private::ToNumber(lhs) - Operators_Private::ToNumber(rhs));
|
|
330
|
-
}
|
|
331
|
-
inline AnyValue operator-(const AnyValue &lhs, const double &rhs)
|
|
332
|
-
{
|
|
333
|
-
if (lhs.is_number())
|
|
334
|
-
return AnyValue::make_number(lhs.as_double() - rhs);
|
|
335
|
-
return AnyValue::make_number(Operators_Private::ToNumber(lhs) - rhs);
|
|
336
|
-
}
|
|
337
|
-
inline AnyValue operator-(const double &lhs, const AnyValue &rhs)
|
|
338
|
-
{
|
|
339
|
-
if (rhs.is_number())
|
|
340
|
-
return AnyValue::make_number(lhs - rhs.as_double());
|
|
341
|
-
return AnyValue::make_number(lhs - Operators_Private::ToNumber(rhs));
|
|
115
|
+
return AnyValue::make_number(add_primitive(lhs, rhs));
|
|
342
116
|
}
|
|
343
117
|
|
|
344
|
-
//
|
|
345
|
-
inline AnyValue
|
|
346
|
-
{
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
return AnyValue::make_number(Operators_Private::ToNumber(lhs) * Operators_Private::ToNumber(rhs));
|
|
350
|
-
}
|
|
351
|
-
inline AnyValue operator*(const AnyValue &lhs, const double &rhs)
|
|
352
|
-
{
|
|
353
|
-
if (lhs.is_number())
|
|
354
|
-
return AnyValue::make_number(lhs.as_double() * rhs);
|
|
355
|
-
return AnyValue::make_number(Operators_Private::ToNumber(lhs) * rhs);
|
|
356
|
-
}
|
|
357
|
-
inline AnyValue operator*(const double &lhs, const AnyValue &rhs)
|
|
358
|
-
{
|
|
359
|
-
if (rhs.is_number())
|
|
360
|
-
return AnyValue::make_number(lhs * rhs.as_double());
|
|
361
|
-
return AnyValue::make_number(lhs * Operators_Private::ToNumber(rhs));
|
|
362
|
-
}
|
|
118
|
+
// Function sub
|
|
119
|
+
inline AnyValue sub(const AnyValue &lhs, const AnyValue &rhs) { return AnyValue::make_number(sub_primitive(lhs, rhs)); }
|
|
120
|
+
inline AnyValue sub(const AnyValue &lhs, const double &rhs) { return AnyValue::make_number(sub_primitive(lhs, rhs)); }
|
|
121
|
+
inline AnyValue sub(const double &lhs, const AnyValue &rhs) { return AnyValue::make_number(sub_primitive(lhs, rhs)); }
|
|
122
|
+
inline AnyValue sub(const double &lhs, const double &rhs) { return AnyValue::make_number(sub_primitive(lhs, rhs)); }
|
|
363
123
|
|
|
364
|
-
//
|
|
365
|
-
inline AnyValue
|
|
366
|
-
{
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
return AnyValue::make_number(Operators_Private::ToNumber(lhs) / Operators_Private::ToNumber(rhs));
|
|
370
|
-
}
|
|
371
|
-
inline AnyValue operator/(const AnyValue &lhs, const double &rhs)
|
|
372
|
-
{
|
|
373
|
-
if (lhs.is_number())
|
|
374
|
-
return AnyValue::make_number(lhs.as_double() / rhs);
|
|
375
|
-
return AnyValue::make_number(Operators_Private::ToNumber(lhs) / rhs);
|
|
376
|
-
}
|
|
377
|
-
inline AnyValue operator/(const double &lhs, const AnyValue &rhs)
|
|
378
|
-
{
|
|
379
|
-
if (rhs.is_number())
|
|
380
|
-
return AnyValue::make_number(lhs / rhs.as_double());
|
|
381
|
-
return AnyValue::make_number(lhs / Operators_Private::ToNumber(rhs));
|
|
382
|
-
}
|
|
124
|
+
// Function mul
|
|
125
|
+
inline AnyValue mul(const AnyValue &lhs, const AnyValue &rhs) { return AnyValue::make_number(mul_primitive(lhs, rhs)); }
|
|
126
|
+
inline AnyValue mul(const AnyValue &lhs, const double &rhs) { return AnyValue::make_number(mul_primitive(lhs, rhs)); }
|
|
127
|
+
inline AnyValue mul(const double &lhs, const AnyValue &rhs) { return AnyValue::make_number(mul_primitive(lhs, rhs)); }
|
|
128
|
+
inline AnyValue mul(const double &lhs, const double &rhs) { return AnyValue::make_number(mul_primitive(lhs, rhs)); }
|
|
383
129
|
|
|
384
|
-
//
|
|
385
|
-
inline AnyValue
|
|
386
|
-
{
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
inline AnyValue
|
|
392
|
-
{
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
return AnyValue::make_number(std::fmod(Operators_Private::ToNumber(lhs), rhs));
|
|
396
|
-
}
|
|
397
|
-
inline AnyValue operator%(const double &lhs, const AnyValue &rhs)
|
|
398
|
-
{
|
|
399
|
-
if (rhs.is_number())
|
|
400
|
-
return AnyValue::make_number(std::fmod(lhs, rhs.as_double()));
|
|
401
|
-
return AnyValue::make_number(std::fmod(lhs, Operators_Private::ToNumber(rhs)));
|
|
402
|
-
}
|
|
130
|
+
// Function div
|
|
131
|
+
inline AnyValue div(const AnyValue &lhs, const AnyValue &rhs) { return AnyValue::make_number(div_primitive(lhs, rhs)); }
|
|
132
|
+
inline AnyValue div(const AnyValue &lhs, const double &rhs) { return AnyValue::make_number(div_primitive(lhs, rhs)); }
|
|
133
|
+
inline AnyValue div(const double &lhs, const AnyValue &rhs) { return AnyValue::make_number(div_primitive(lhs, rhs)); }
|
|
134
|
+
inline AnyValue div(const double &lhs, const double &rhs) { return AnyValue::make_number(div_primitive(lhs, rhs)); }
|
|
135
|
+
|
|
136
|
+
// Function mod
|
|
137
|
+
inline AnyValue mod(const AnyValue &lhs, const AnyValue &rhs) { return AnyValue::make_number(mod_primitive(lhs, rhs)); }
|
|
138
|
+
inline AnyValue mod(const AnyValue &lhs, const double &rhs) { return AnyValue::make_number(mod_primitive(lhs, rhs)); }
|
|
139
|
+
inline AnyValue mod(const double &lhs, const AnyValue &rhs) { return AnyValue::make_number(mod_primitive(lhs, rhs)); }
|
|
140
|
+
inline AnyValue mod(const double &lhs, const double &rhs) { return AnyValue::make_number(mod_primitive(lhs, rhs)); }
|
|
403
141
|
|
|
404
142
|
// --- UNARY OPERATORS ---
|
|
405
|
-
inline AnyValue
|
|
143
|
+
inline AnyValue plus(const AnyValue &val)
|
|
406
144
|
{
|
|
407
145
|
return AnyValue::make_number(Operators_Private::ToNumber(val));
|
|
408
146
|
}
|
|
409
|
-
inline AnyValue
|
|
147
|
+
inline AnyValue negate(const AnyValue &val)
|
|
410
148
|
{
|
|
411
149
|
return AnyValue::make_number(-Operators_Private::ToNumber(val));
|
|
412
150
|
}
|
|
413
|
-
inline AnyValue
|
|
151
|
+
inline AnyValue bitwise_not(const AnyValue &val)
|
|
414
152
|
{
|
|
415
153
|
return AnyValue::make_number(~Operators_Private::ToInt32(val));
|
|
416
154
|
}
|
|
417
|
-
inline AnyValue
|
|
155
|
+
inline AnyValue logical_not(const AnyValue &val)
|
|
418
156
|
{
|
|
419
157
|
return AnyValue::make_boolean(!is_truthy(val));
|
|
420
158
|
}
|
|
421
159
|
|
|
422
160
|
// --- EXPONENTIATION ---
|
|
423
|
-
inline AnyValue pow(const AnyValue &lhs, const AnyValue &rhs)
|
|
424
|
-
{
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
return AnyValue::make_number(std::pow(base, exp));
|
|
428
|
-
}
|
|
429
|
-
inline AnyValue pow(const AnyValue &lhs, const double &rhs)
|
|
430
|
-
{
|
|
431
|
-
double base = Operators_Private::ToNumber(lhs);
|
|
432
|
-
return AnyValue::make_number(std::pow(base, rhs));
|
|
433
|
-
}
|
|
434
|
-
inline AnyValue pow(const double &lhs, const AnyValue &rhs)
|
|
435
|
-
{
|
|
436
|
-
double exp = Operators_Private::ToNumber(rhs);
|
|
437
|
-
return AnyValue::make_number(std::pow(lhs, exp));
|
|
438
|
-
}
|
|
439
|
-
inline AnyValue pow(const double &lhs, const double &rhs)
|
|
440
|
-
{
|
|
441
|
-
return AnyValue::make_number(std::pow(lhs, rhs));
|
|
442
|
-
}
|
|
161
|
+
inline AnyValue pow(const AnyValue &lhs, const AnyValue &rhs) { return AnyValue::make_number(pow_primitive(lhs, rhs)); }
|
|
162
|
+
inline AnyValue pow(const AnyValue &lhs, const double &rhs) { return AnyValue::make_number(pow_primitive(lhs, rhs)); }
|
|
163
|
+
inline AnyValue pow(const double &lhs, const AnyValue &rhs) { return AnyValue::make_number(pow_primitive(lhs, rhs)); }
|
|
164
|
+
inline AnyValue pow(const double &lhs, const double &rhs) { return AnyValue::make_number(pow_primitive(lhs, rhs)); }
|
|
443
165
|
|
|
444
166
|
// --- COMPARISON OPERATORS ---
|
|
445
167
|
|
|
446
168
|
// Less than <
|
|
447
|
-
inline AnyValue
|
|
169
|
+
inline AnyValue less_than(const AnyValue &lhs, const AnyValue &rhs)
|
|
448
170
|
{
|
|
449
|
-
if (lhs.is_number() && rhs.is_number())
|
|
450
|
-
return AnyValue::make_boolean(lhs.as_double() < rhs.as_double());
|
|
451
|
-
|
|
452
171
|
if (lhs.is_string() && rhs.is_string())
|
|
453
172
|
return AnyValue::make_boolean(lhs.as_string()->value < rhs.as_string()->value);
|
|
454
173
|
|
|
455
|
-
|
|
456
|
-
double r = Operators_Private::ToNumber(rhs);
|
|
457
|
-
|
|
458
|
-
if (std::isnan(l) || std::isnan(r))
|
|
459
|
-
return Constants::FALSE;
|
|
460
|
-
|
|
461
|
-
return AnyValue::make_boolean(l < r);
|
|
174
|
+
return AnyValue::make_boolean(less_than_primitive(lhs, rhs));
|
|
462
175
|
}
|
|
463
|
-
inline AnyValue
|
|
176
|
+
inline AnyValue less_than(const AnyValue &lhs, const double &rhs)
|
|
464
177
|
{
|
|
465
|
-
|
|
466
|
-
return AnyValue::make_boolean(lhs.as_double() < rhs);
|
|
467
|
-
|
|
468
|
-
double l = Operators_Private::ToNumber(lhs);
|
|
469
|
-
if (std::isnan(l) || std::isnan(rhs))
|
|
470
|
-
return Constants::FALSE;
|
|
471
|
-
|
|
472
|
-
return AnyValue::make_boolean(l < rhs);
|
|
178
|
+
return AnyValue::make_boolean(less_than_primitive(lhs, rhs));
|
|
473
179
|
}
|
|
474
|
-
inline AnyValue
|
|
180
|
+
inline AnyValue less_than(const double &lhs, const AnyValue &rhs)
|
|
475
181
|
{
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
return Constants::FALSE;
|
|
482
|
-
|
|
483
|
-
return AnyValue::make_boolean(lhs < r);
|
|
182
|
+
return AnyValue::make_boolean(less_than_primitive(lhs, rhs));
|
|
183
|
+
}
|
|
184
|
+
inline AnyValue less_than(const double &lhs, const double &rhs)
|
|
185
|
+
{
|
|
186
|
+
return AnyValue::make_boolean(less_than_primitive(lhs, rhs));
|
|
484
187
|
}
|
|
485
188
|
|
|
486
|
-
inline AnyValue
|
|
487
|
-
inline AnyValue
|
|
488
|
-
inline AnyValue
|
|
189
|
+
inline AnyValue greater_than(const AnyValue &lhs, const AnyValue &rhs) { return less_than(rhs, lhs); }
|
|
190
|
+
inline AnyValue greater_than(const AnyValue &lhs, const double &rhs) { return less_than(rhs, lhs); }
|
|
191
|
+
inline AnyValue greater_than(const double &lhs, const AnyValue &rhs) { return less_than(rhs, lhs); }
|
|
192
|
+
inline AnyValue greater_than(const double &lhs, const double &rhs) { return AnyValue::make_boolean(greater_than_primitive(lhs, rhs)); }
|
|
489
193
|
|
|
490
|
-
inline AnyValue
|
|
194
|
+
inline AnyValue less_than_or_equal(const AnyValue &lhs, const AnyValue &rhs)
|
|
491
195
|
{
|
|
492
|
-
|
|
493
|
-
|
|
196
|
+
if (lhs.is_string() && rhs.is_string())
|
|
197
|
+
return AnyValue::make_boolean(lhs.as_string()->value <= rhs.as_string()->value);
|
|
198
|
+
return AnyValue::make_boolean(less_than_or_equal_primitive(lhs, rhs));
|
|
199
|
+
}
|
|
200
|
+
inline AnyValue less_than_or_equal(const AnyValue &lhs, const double &rhs)
|
|
201
|
+
{
|
|
202
|
+
return AnyValue::make_boolean(less_than_or_equal_primitive(lhs, rhs));
|
|
494
203
|
}
|
|
495
|
-
inline AnyValue
|
|
204
|
+
inline AnyValue less_than_or_equal(const double &lhs, const AnyValue &rhs)
|
|
496
205
|
{
|
|
497
|
-
AnyValue
|
|
498
|
-
return AnyValue::make_boolean(!result.as_boolean());
|
|
206
|
+
return AnyValue::make_boolean(less_than_or_equal_primitive(lhs, rhs));
|
|
499
207
|
}
|
|
500
|
-
inline AnyValue
|
|
208
|
+
inline AnyValue less_than_or_equal(const double &lhs, const double &rhs)
|
|
501
209
|
{
|
|
502
|
-
AnyValue
|
|
503
|
-
return AnyValue::make_boolean(!result.as_boolean());
|
|
210
|
+
return AnyValue::make_boolean(less_than_or_equal_primitive(lhs, rhs));
|
|
504
211
|
}
|
|
505
212
|
|
|
506
|
-
inline AnyValue
|
|
213
|
+
inline AnyValue greater_than_or_equal(const AnyValue &lhs, const AnyValue &rhs)
|
|
214
|
+
{
|
|
215
|
+
if (lhs.is_string() && rhs.is_string())
|
|
216
|
+
return AnyValue::make_boolean(lhs.as_string()->value >= rhs.as_string()->value);
|
|
217
|
+
return AnyValue::make_boolean(greater_than_or_equal_primitive(lhs, rhs));
|
|
218
|
+
}
|
|
219
|
+
inline AnyValue greater_than_or_equal(const AnyValue &lhs, const double &rhs)
|
|
507
220
|
{
|
|
508
|
-
AnyValue
|
|
509
|
-
return AnyValue::make_boolean(!result.as_boolean());
|
|
221
|
+
return AnyValue::make_boolean(greater_than_or_equal_primitive(lhs, rhs));
|
|
510
222
|
}
|
|
511
|
-
inline AnyValue
|
|
223
|
+
inline AnyValue greater_than_or_equal(const double &lhs, const AnyValue &rhs)
|
|
512
224
|
{
|
|
513
|
-
AnyValue
|
|
514
|
-
return AnyValue::make_boolean(!result.as_boolean());
|
|
225
|
+
return AnyValue::make_boolean(greater_than_or_equal_primitive(lhs, rhs));
|
|
515
226
|
}
|
|
516
|
-
inline AnyValue
|
|
227
|
+
inline AnyValue greater_than_or_equal(const double &lhs, const double &rhs)
|
|
517
228
|
{
|
|
518
|
-
AnyValue
|
|
519
|
-
return AnyValue::make_boolean(!result.as_boolean());
|
|
229
|
+
return AnyValue::make_boolean(greater_than_or_equal_primitive(lhs, rhs));
|
|
520
230
|
}
|
|
521
231
|
|
|
522
232
|
// Equality ==
|
|
523
|
-
inline AnyValue
|
|
233
|
+
inline AnyValue equal(const AnyValue &lhs, const AnyValue &rhs)
|
|
524
234
|
{
|
|
525
235
|
return AnyValue::make_boolean(is_equal_to_primitive(lhs, rhs));
|
|
526
236
|
}
|
|
527
|
-
inline AnyValue
|
|
237
|
+
inline AnyValue equal(const AnyValue &lhs, const double &rhs)
|
|
528
238
|
{
|
|
529
239
|
if (lhs.is_number())
|
|
530
|
-
return AnyValue::make_boolean(lhs.as_double()
|
|
240
|
+
return AnyValue::make_boolean(equal_primitive(lhs.as_double(), rhs));
|
|
531
241
|
return AnyValue::make_boolean(is_equal_to_primitive(lhs, AnyValue::make_number(rhs)));
|
|
532
242
|
}
|
|
533
|
-
inline AnyValue
|
|
243
|
+
inline AnyValue equal(const double &lhs, const AnyValue &rhs)
|
|
534
244
|
{
|
|
535
245
|
if (rhs.is_number())
|
|
536
|
-
return AnyValue::make_boolean(lhs
|
|
246
|
+
return AnyValue::make_boolean(equal_primitive(lhs, rhs.as_double()));
|
|
537
247
|
return AnyValue::make_boolean(is_equal_to_primitive(rhs, AnyValue::make_number(lhs)));
|
|
538
248
|
}
|
|
539
|
-
|
|
540
|
-
inline AnyValue operator!=(const AnyValue &lhs, const AnyValue &rhs) { return AnyValue::make_boolean(!is_equal_to_primitive(lhs, rhs)); }
|
|
541
|
-
inline AnyValue operator!=(const AnyValue &lhs, const double &rhs) { return AnyValue::make_boolean(!operator==(lhs, rhs).as_boolean()); }
|
|
542
|
-
inline AnyValue operator!=(const double &lhs, const AnyValue &rhs) { return AnyValue::make_boolean(!operator==(lhs, rhs).as_boolean()); }
|
|
543
|
-
|
|
544
|
-
// --- LOGICAL OPERATORS ---
|
|
545
|
-
inline AnyValue operator||(const AnyValue &lhs, const AnyValue &rhs)
|
|
546
|
-
{
|
|
547
|
-
if (is_truthy(lhs))
|
|
548
|
-
return lhs;
|
|
549
|
-
return rhs;
|
|
550
|
-
}
|
|
551
|
-
inline AnyValue operator&&(const AnyValue &lhs, const AnyValue &rhs)
|
|
249
|
+
inline AnyValue equal(const double &lhs, const double &rhs)
|
|
552
250
|
{
|
|
553
|
-
|
|
554
|
-
return lhs;
|
|
555
|
-
return rhs;
|
|
251
|
+
return AnyValue::make_boolean(equal_primitive(lhs, rhs));
|
|
556
252
|
}
|
|
557
253
|
|
|
254
|
+
inline AnyValue not_equal(const AnyValue &lhs, const AnyValue &rhs) { return AnyValue::make_boolean(!is_equal_to_primitive(lhs, rhs)); }
|
|
255
|
+
inline AnyValue not_equal(const AnyValue &lhs, const double &rhs) { return AnyValue::make_boolean(!equal(lhs, rhs).as_boolean()); }
|
|
256
|
+
inline AnyValue not_equal(const double &lhs, const AnyValue &rhs) { return AnyValue::make_boolean(!equal(lhs, rhs).as_boolean()); }
|
|
257
|
+
inline AnyValue not_equal(const double &lhs, const double &rhs) { return AnyValue::make_boolean(not_equal_primitive(lhs, rhs)); }
|
|
258
|
+
|
|
558
259
|
// --- BITWISE OPERATORS ---
|
|
559
|
-
inline AnyValue
|
|
560
|
-
{
|
|
561
|
-
|
|
562
|
-
}
|
|
563
|
-
inline AnyValue operator^(const AnyValue &lhs, const double &rhs)
|
|
564
|
-
{
|
|
565
|
-
return AnyValue::make_number(Operators_Private::ToInt32(lhs) ^ static_cast<int32_t>(rhs));
|
|
566
|
-
}
|
|
567
|
-
inline AnyValue operator^(const double &lhs, const AnyValue &rhs)
|
|
568
|
-
{
|
|
569
|
-
return AnyValue::make_number(static_cast<int32_t>(lhs) ^ Operators_Private::ToInt32(rhs));
|
|
570
|
-
}
|
|
260
|
+
inline AnyValue bitwise_xor(const AnyValue &lhs, const AnyValue &rhs) { return AnyValue::make_number(bitwise_xor_primitive(lhs, rhs)); }
|
|
261
|
+
inline AnyValue bitwise_xor(const AnyValue &lhs, const double &rhs) { return AnyValue::make_number(bitwise_xor_primitive(lhs, rhs)); }
|
|
262
|
+
inline AnyValue bitwise_xor(const double &lhs, const AnyValue &rhs) { return AnyValue::make_number(bitwise_xor_primitive(lhs, rhs)); }
|
|
263
|
+
inline AnyValue bitwise_xor(const double &lhs, const double &rhs) { return AnyValue::make_number(bitwise_xor_primitive(lhs, rhs)); }
|
|
571
264
|
|
|
572
|
-
inline AnyValue
|
|
573
|
-
{
|
|
574
|
-
|
|
575
|
-
}
|
|
576
|
-
inline AnyValue operator&(const AnyValue &lhs, const double &rhs)
|
|
577
|
-
{
|
|
578
|
-
return AnyValue::make_number(Operators_Private::ToInt32(lhs) & static_cast<int32_t>(rhs));
|
|
579
|
-
}
|
|
580
|
-
inline AnyValue operator&(const double &lhs, const AnyValue &rhs)
|
|
581
|
-
{
|
|
582
|
-
return AnyValue::make_number(static_cast<int32_t>(lhs) & Operators_Private::ToInt32(rhs));
|
|
583
|
-
}
|
|
265
|
+
inline AnyValue bitwise_and(const AnyValue &lhs, const AnyValue &rhs) { return AnyValue::make_number(bitwise_and_primitive(lhs, rhs)); }
|
|
266
|
+
inline AnyValue bitwise_and(const AnyValue &lhs, const double &rhs) { return AnyValue::make_number(bitwise_and_primitive(lhs, rhs)); }
|
|
267
|
+
inline AnyValue bitwise_and(const double &lhs, const AnyValue &rhs) { return AnyValue::make_number(bitwise_and_primitive(lhs, rhs)); }
|
|
268
|
+
inline AnyValue bitwise_and(const double &lhs, const double &rhs) { return AnyValue::make_number(bitwise_and_primitive(lhs, rhs)); }
|
|
584
269
|
|
|
585
|
-
inline AnyValue
|
|
586
|
-
{
|
|
587
|
-
|
|
588
|
-
}
|
|
589
|
-
inline AnyValue operator|(const AnyValue &lhs, const double &rhs)
|
|
590
|
-
{
|
|
591
|
-
return AnyValue::make_number(Operators_Private::ToInt32(lhs) | static_cast<int32_t>(rhs));
|
|
592
|
-
}
|
|
593
|
-
inline AnyValue operator|(const double &lhs, const AnyValue &rhs)
|
|
594
|
-
{
|
|
595
|
-
return AnyValue::make_number(static_cast<int32_t>(lhs) | Operators_Private::ToInt32(rhs));
|
|
596
|
-
}
|
|
270
|
+
inline AnyValue bitwise_or(const AnyValue &lhs, const AnyValue &rhs) { return AnyValue::make_number(bitwise_or_primitive(lhs, rhs)); }
|
|
271
|
+
inline AnyValue bitwise_or(const AnyValue &lhs, const double &rhs) { return AnyValue::make_number(bitwise_or_primitive(lhs, rhs)); }
|
|
272
|
+
inline AnyValue bitwise_or(const double &lhs, const AnyValue &rhs) { return AnyValue::make_number(bitwise_or_primitive(lhs, rhs)); }
|
|
273
|
+
inline AnyValue bitwise_or(const double &lhs, const double &rhs) { return AnyValue::make_number(bitwise_or_primitive(lhs, rhs)); }
|
|
597
274
|
|
|
598
275
|
// --- SHIFT OPERATORS ---
|
|
599
|
-
inline AnyValue
|
|
600
|
-
{
|
|
601
|
-
|
|
602
|
-
}
|
|
603
|
-
inline AnyValue operator<<(const AnyValue &lhs, const double &rhs)
|
|
604
|
-
{
|
|
605
|
-
return AnyValue::make_number(Operators_Private::ToInt32(lhs) << (static_cast<int32_t>(rhs) & 0x1F));
|
|
606
|
-
}
|
|
607
|
-
inline AnyValue operator<<(const double &lhs, const AnyValue &rhs)
|
|
608
|
-
{
|
|
609
|
-
return AnyValue::make_number(static_cast<int32_t>(lhs) << (Operators_Private::ToInt32(rhs) & 0x1F));
|
|
610
|
-
}
|
|
276
|
+
inline AnyValue left_shift(const AnyValue &lhs, const AnyValue &rhs) { return AnyValue::make_number(left_shift_primitive(lhs, rhs)); }
|
|
277
|
+
inline AnyValue left_shift(const AnyValue &lhs, const double &rhs) { return AnyValue::make_number(left_shift_primitive(lhs, rhs)); }
|
|
278
|
+
inline AnyValue left_shift(const double &lhs, const AnyValue &rhs) { return AnyValue::make_number(left_shift_primitive(lhs, rhs)); }
|
|
279
|
+
inline AnyValue left_shift(const double &lhs, const double &rhs) { return AnyValue::make_number(left_shift_primitive(lhs, rhs)); }
|
|
611
280
|
|
|
612
|
-
inline AnyValue
|
|
613
|
-
{
|
|
614
|
-
|
|
615
|
-
}
|
|
616
|
-
inline AnyValue operator>>(const AnyValue &lhs, const double &rhs)
|
|
617
|
-
{
|
|
618
|
-
return AnyValue::make_number(Operators_Private::ToInt32(lhs) >> (static_cast<int32_t>(rhs) & 0x1F));
|
|
619
|
-
}
|
|
620
|
-
inline AnyValue operator>>(const double &lhs, const AnyValue &rhs)
|
|
621
|
-
{
|
|
622
|
-
return AnyValue::make_number(static_cast<int32_t>(lhs) >> (Operators_Private::ToInt32(rhs) & 0x1F));
|
|
623
|
-
}
|
|
281
|
+
inline AnyValue right_shift(const AnyValue &lhs, const AnyValue &rhs) { return AnyValue::make_number(right_shift_primitive(lhs, rhs)); }
|
|
282
|
+
inline AnyValue right_shift(const AnyValue &lhs, const double &rhs) { return AnyValue::make_number(right_shift_primitive(lhs, rhs)); }
|
|
283
|
+
inline AnyValue right_shift(const double &lhs, const AnyValue &rhs) { return AnyValue::make_number(right_shift_primitive(lhs, rhs)); }
|
|
284
|
+
inline AnyValue right_shift(const double &lhs, const double &rhs) { return AnyValue::make_number(right_shift_primitive(lhs, rhs)); }
|
|
624
285
|
|
|
625
|
-
inline AnyValue unsigned_right_shift(const AnyValue &lhs, const AnyValue &rhs)
|
|
626
|
-
{
|
|
627
|
-
|
|
628
|
-
}
|
|
629
|
-
inline AnyValue unsigned_right_shift(const AnyValue &lhs, const double &rhs)
|
|
630
|
-
{
|
|
631
|
-
return AnyValue::make_number(static_cast<double>(Operators_Private::ToUint32(lhs) >> (static_cast<int32_t>(rhs) & 0x1F)));
|
|
632
|
-
}
|
|
633
|
-
inline AnyValue unsigned_right_shift(const double &lhs, const AnyValue &rhs)
|
|
634
|
-
{
|
|
635
|
-
uint32_t l = static_cast<uint32_t>(fmod(lhs, 4294967296.0));
|
|
636
|
-
return AnyValue::make_number(static_cast<double>(l >> (Operators_Private::ToInt32(rhs) & 0x1F)));
|
|
637
|
-
}
|
|
638
|
-
inline AnyValue unsigned_right_shift(const double &lhs, const double &rhs)
|
|
639
|
-
{
|
|
640
|
-
uint32_t l = static_cast<uint32_t>(fmod(lhs, 4294967296.0));
|
|
641
|
-
return AnyValue::make_number(static_cast<double>(l >> (static_cast<int32_t>(rhs) & 0x1F)));
|
|
642
|
-
}
|
|
286
|
+
inline AnyValue unsigned_right_shift(const AnyValue &lhs, const AnyValue &rhs) { return AnyValue::make_number(unsigned_right_shift_primitive(lhs, rhs)); }
|
|
287
|
+
inline AnyValue unsigned_right_shift(const AnyValue &lhs, const double &rhs) { return AnyValue::make_number(unsigned_right_shift_primitive(lhs, rhs)); }
|
|
288
|
+
inline AnyValue unsigned_right_shift(const double &lhs, const AnyValue &rhs) { return AnyValue::make_number(unsigned_right_shift_primitive(lhs, rhs)); }
|
|
289
|
+
inline AnyValue unsigned_right_shift(const double &lhs, const double &rhs) { return AnyValue::make_number(unsigned_right_shift_primitive(lhs, rhs)); }
|
|
643
290
|
|
|
644
291
|
// --- LOGICAL SHORT-CIRCUITING HELPERS ---
|
|
645
292
|
inline AnyValue logical_and(const AnyValue &lhs, const AnyValue &rhs)
|
|
@@ -648,14 +295,12 @@ namespace jspp
|
|
|
648
295
|
return lhs;
|
|
649
296
|
return rhs;
|
|
650
297
|
}
|
|
651
|
-
|
|
652
298
|
inline AnyValue logical_or(const AnyValue &lhs, const AnyValue &rhs)
|
|
653
299
|
{
|
|
654
300
|
if (is_truthy(lhs))
|
|
655
301
|
return lhs;
|
|
656
302
|
return rhs;
|
|
657
303
|
}
|
|
658
|
-
|
|
659
304
|
inline AnyValue nullish_coalesce(const AnyValue &lhs, const AnyValue &rhs)
|
|
660
305
|
{
|
|
661
306
|
if (!lhs.is_null() && !lhs.is_undefined())
|
|
@@ -670,18 +315,16 @@ namespace jspp
|
|
|
670
315
|
lhs = rhs;
|
|
671
316
|
return lhs;
|
|
672
317
|
}
|
|
673
|
-
|
|
674
318
|
inline AnyValue &logical_or_assign(AnyValue &lhs, const AnyValue &rhs)
|
|
675
319
|
{
|
|
676
320
|
if (!is_truthy(lhs))
|
|
677
321
|
lhs = rhs;
|
|
678
322
|
return lhs;
|
|
679
323
|
}
|
|
680
|
-
|
|
681
324
|
inline AnyValue &nullish_coalesce_assign(AnyValue &lhs, const AnyValue &rhs)
|
|
682
325
|
{
|
|
683
326
|
if (lhs.is_null() || lhs.is_undefined())
|
|
684
327
|
lhs = rhs;
|
|
685
328
|
return lhs;
|
|
686
329
|
}
|
|
687
|
-
}
|
|
330
|
+
}
|