@ugo-studio/jspp 0.2.8 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analysis/typeAnalyzer.js +42 -27
- package/dist/core/codegen/class-handlers.js +6 -6
- package/dist/core/codegen/control-flow-handlers.js +4 -4
- package/dist/core/codegen/declaration-handlers.js +21 -3
- package/dist/core/codegen/destructuring-handlers.js +187 -0
- package/dist/core/codegen/expression-handlers.js +7 -0
- package/dist/core/codegen/function-handlers.js +58 -36
- package/dist/core/codegen/helpers.js +288 -52
- package/dist/core/codegen/index.js +7 -4
- package/dist/core/codegen/statement-handlers.js +43 -23
- package/package.json +1 -1
- package/scripts/precompile-headers.ts +13 -5
- package/src/prelude/any_value.hpp +362 -361
- package/src/prelude/any_value_access.hpp +170 -170
- package/src/prelude/any_value_defines.hpp +189 -189
- package/src/prelude/any_value_helpers.hpp +374 -365
- package/src/prelude/library/array.hpp +185 -185
- package/src/prelude/library/console.hpp +111 -111
- package/src/prelude/library/error.hpp +112 -112
- package/src/prelude/library/function.hpp +10 -10
- package/src/prelude/library/math.hpp +307 -307
- package/src/prelude/library/object.hpp +275 -275
- package/src/prelude/library/performance.hpp +1 -1
- package/src/prelude/library/process.hpp +39 -39
- package/src/prelude/library/promise.hpp +123 -123
- package/src/prelude/library/symbol.hpp +52 -52
- package/src/prelude/library/timer.hpp +91 -91
- package/src/prelude/types.hpp +178 -178
- package/src/prelude/utils/access.hpp +411 -393
- package/src/prelude/utils/operators.hpp +336 -329
- package/src/prelude/values/array.hpp +0 -1
- package/src/prelude/values/async_iterator.hpp +83 -81
- package/src/prelude/values/function.hpp +82 -82
- package/src/prelude/values/helpers/array.hpp +198 -208
- package/src/prelude/values/helpers/async_iterator.hpp +275 -271
- package/src/prelude/values/helpers/function.hpp +108 -108
- package/src/prelude/values/helpers/iterator.hpp +144 -107
- package/src/prelude/values/helpers/promise.hpp +253 -253
- package/src/prelude/values/helpers/string.hpp +37 -47
- package/src/prelude/values/iterator.hpp +32 -5
- package/src/prelude/values/promise.hpp +72 -72
- package/src/prelude/values/prototypes/array.hpp +54 -42
- package/src/prelude/values/prototypes/iterator.hpp +201 -74
- package/src/prelude/values/prototypes/promise.hpp +196 -196
- package/src/prelude/values/prototypes/string.hpp +564 -542
- package/src/prelude/values/string.hpp +25 -26
|
@@ -1,330 +1,337 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include "types.hpp"
|
|
4
|
-
#include "any_value.hpp"
|
|
5
|
-
#include "operators_primitive.hpp"
|
|
6
|
-
#include <cstdint> // For int32_t
|
|
7
|
-
#include <cmath> // For fmod, isnan, isinf, floor, abs, pow
|
|
8
|
-
#include <string> // For std::to_string, std::stod
|
|
9
|
-
#include <algorithm> // For std::all_of
|
|
10
|
-
#include <limits> // For numeric_limits
|
|
11
|
-
|
|
12
|
-
namespace jspp
|
|
13
|
-
{
|
|
14
|
-
// Operator === (returns boolean wrapped in AnyValue)
|
|
15
|
-
inline const AnyValue is_strictly_equal_to(const AnyValue &lhs, const double &rhs) noexcept
|
|
16
|
-
{
|
|
17
|
-
return AnyValue::make_boolean(is_strictly_equal_to_primitive(lhs, rhs));
|
|
18
|
-
}
|
|
19
|
-
inline const AnyValue is_strictly_equal_to(const double &lhs, const AnyValue &rhs) noexcept
|
|
20
|
-
{
|
|
21
|
-
return AnyValue::make_boolean(is_strictly_equal_to_primitive(lhs, rhs));
|
|
22
|
-
}
|
|
23
|
-
inline const AnyValue is_strictly_equal_to(const double &lhs, const double &rhs) noexcept
|
|
24
|
-
{
|
|
25
|
-
return AnyValue::make_boolean(is_strictly_equal_to_primitive(lhs, rhs));
|
|
26
|
-
}
|
|
27
|
-
inline const AnyValue is_strictly_equal_to(const AnyValue &lhs, const AnyValue &rhs) noexcept
|
|
28
|
-
{
|
|
29
|
-
return AnyValue::make_boolean(is_strictly_equal_to_primitive(lhs, rhs));
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Operator == (returns boolean wrapped in AnyValue)
|
|
33
|
-
inline const AnyValue is_equal_to(const AnyValue &lhs, const double &rhs) noexcept
|
|
34
|
-
{
|
|
35
|
-
return AnyValue::make_boolean(is_equal_to_primitive(lhs, rhs));
|
|
36
|
-
}
|
|
37
|
-
inline const AnyValue is_equal_to(const double &lhs, const AnyValue &rhs) noexcept
|
|
38
|
-
{
|
|
39
|
-
return AnyValue::make_boolean(is_equal_to_primitive(lhs, rhs));
|
|
40
|
-
}
|
|
41
|
-
inline const AnyValue is_equal_to(const double &lhs, const double &rhs) noexcept
|
|
42
|
-
{
|
|
43
|
-
return AnyValue::make_boolean(is_equal_to_primitive(lhs, rhs));
|
|
44
|
-
}
|
|
45
|
-
inline const AnyValue is_equal_to(const AnyValue &lhs, const AnyValue &rhs) noexcept
|
|
46
|
-
{
|
|
47
|
-
return AnyValue::make_boolean(is_equal_to_primitive(lhs, rhs));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Operator !== (returns boolean wrapped in AnyValue)
|
|
51
|
-
inline const AnyValue not_strictly_equal_to(const AnyValue &lhs, const double &rhs) noexcept
|
|
52
|
-
{
|
|
53
|
-
return AnyValue::make_boolean(!is_strictly_equal_to_primitive(lhs, rhs));
|
|
54
|
-
}
|
|
55
|
-
inline const AnyValue not_strictly_equal_to(const double &lhs, const AnyValue &rhs) noexcept
|
|
56
|
-
{
|
|
57
|
-
return AnyValue::make_boolean(!is_strictly_equal_to_primitive(lhs, rhs));
|
|
58
|
-
}
|
|
59
|
-
inline const AnyValue not_strictly_equal_to(const double &lhs, const double &rhs) noexcept
|
|
60
|
-
{
|
|
61
|
-
return AnyValue::make_boolean(!is_strictly_equal_to_primitive(lhs, rhs));
|
|
62
|
-
}
|
|
63
|
-
inline const AnyValue not_strictly_equal_to(const AnyValue &lhs, const AnyValue &rhs) noexcept
|
|
64
|
-
{
|
|
65
|
-
return AnyValue::make_boolean(!is_strictly_equal_to_primitive(lhs, rhs));
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Operator != (returns boolean wrapped in AnyValue)
|
|
69
|
-
inline const AnyValue not_equal_to(const AnyValue &lhs, const double &rhs) noexcept
|
|
70
|
-
{
|
|
71
|
-
return AnyValue::make_boolean(!is_equal_to_primitive(lhs, rhs));
|
|
72
|
-
}
|
|
73
|
-
inline const AnyValue not_equal_to(const double &lhs, const AnyValue &rhs) noexcept
|
|
74
|
-
{
|
|
75
|
-
return AnyValue::make_boolean(!is_equal_to_primitive(lhs, rhs));
|
|
76
|
-
}
|
|
77
|
-
inline const AnyValue not_equal_to(const double &lhs, const double &rhs) noexcept
|
|
78
|
-
{
|
|
79
|
-
return AnyValue::make_boolean(!is_equal_to_primitive(lhs, rhs));
|
|
80
|
-
}
|
|
81
|
-
inline const AnyValue not_equal_to(const AnyValue &lhs, const AnyValue &rhs) noexcept
|
|
82
|
-
{
|
|
83
|
-
return AnyValue::make_boolean(!is_equal_to_primitive(lhs, rhs));
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// --- BASIC ARITHMETIC ---
|
|
87
|
-
|
|
88
|
-
// Function add
|
|
89
|
-
inline AnyValue add(const AnyValue &lhs, const AnyValue &rhs)
|
|
90
|
-
{
|
|
91
|
-
if (lhs.is_number() && rhs.is_number())
|
|
92
|
-
return AnyValue::make_number(add_primitive(lhs.as_double(), rhs.as_double()));
|
|
93
|
-
if (lhs.is_string() || rhs.is_string())
|
|
94
|
-
return AnyValue::make_string(lhs.to_std_string() + rhs.to_std_string());
|
|
95
|
-
return AnyValue::make_number(add_primitive(lhs, rhs));
|
|
96
|
-
}
|
|
97
|
-
inline AnyValue add(const AnyValue &lhs, const double &rhs)
|
|
98
|
-
{
|
|
99
|
-
if (lhs.is_number())
|
|
100
|
-
return AnyValue::make_number(add_primitive(lhs.as_double(), rhs));
|
|
101
|
-
if (lhs.is_string())
|
|
102
|
-
return AnyValue::make_string(lhs.to_std_string() + std::to_string(rhs));
|
|
103
|
-
return AnyValue::make_number(add_primitive(lhs, rhs));
|
|
104
|
-
}
|
|
105
|
-
inline AnyValue add(const double &lhs, const AnyValue &rhs)
|
|
106
|
-
{
|
|
107
|
-
if (rhs.is_number())
|
|
108
|
-
return AnyValue::make_number(add_primitive(lhs, rhs.as_double()));
|
|
109
|
-
if (rhs.is_string())
|
|
110
|
-
return AnyValue::make_string(std::to_string(lhs) + rhs.to_std_string());
|
|
111
|
-
return AnyValue::make_number(add_primitive(lhs, rhs));
|
|
112
|
-
}
|
|
113
|
-
inline AnyValue add(const double &lhs, const double &rhs)
|
|
114
|
-
{
|
|
115
|
-
return AnyValue::make_number(add_primitive(lhs, rhs));
|
|
116
|
-
}
|
|
117
|
-
|
|
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)); }
|
|
123
|
-
|
|
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)); }
|
|
129
|
-
|
|
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)); }
|
|
141
|
-
|
|
142
|
-
// --- UNARY OPERATORS ---
|
|
143
|
-
inline AnyValue plus(const AnyValue &val)
|
|
144
|
-
{
|
|
145
|
-
return AnyValue::make_number(Operators_Private::ToNumber(val));
|
|
146
|
-
}
|
|
147
|
-
inline AnyValue negate(const AnyValue &val)
|
|
148
|
-
{
|
|
149
|
-
return AnyValue::make_number(-Operators_Private::ToNumber(val));
|
|
150
|
-
}
|
|
151
|
-
inline AnyValue bitwise_not(const AnyValue &val)
|
|
152
|
-
{
|
|
153
|
-
return AnyValue::make_number(~Operators_Private::ToInt32(val));
|
|
154
|
-
}
|
|
155
|
-
inline AnyValue logical_not(const AnyValue &val)
|
|
156
|
-
{
|
|
157
|
-
return AnyValue::make_boolean(!is_truthy(val));
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// --- EXPONENTIATION ---
|
|
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)); }
|
|
165
|
-
|
|
166
|
-
// --- COMPARISON OPERATORS ---
|
|
167
|
-
|
|
168
|
-
// Less than <
|
|
169
|
-
inline AnyValue less_than(const AnyValue &lhs, const AnyValue &rhs)
|
|
170
|
-
{
|
|
171
|
-
if (lhs.is_string() && rhs.is_string())
|
|
172
|
-
return AnyValue::make_boolean(lhs.as_string()->value < rhs.as_string()->value);
|
|
173
|
-
|
|
174
|
-
return AnyValue::make_boolean(less_than_primitive(lhs, rhs));
|
|
175
|
-
}
|
|
176
|
-
inline AnyValue less_than(const AnyValue &lhs, const double &rhs)
|
|
177
|
-
{
|
|
178
|
-
return AnyValue::make_boolean(less_than_primitive(lhs, rhs));
|
|
179
|
-
}
|
|
180
|
-
inline AnyValue less_than(const double &lhs, const AnyValue &rhs)
|
|
181
|
-
{
|
|
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));
|
|
187
|
-
}
|
|
188
|
-
|
|
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)); }
|
|
193
|
-
|
|
194
|
-
inline AnyValue less_than_or_equal(const AnyValue &lhs, const AnyValue &rhs)
|
|
195
|
-
{
|
|
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));
|
|
203
|
-
}
|
|
204
|
-
inline AnyValue less_than_or_equal(const double &lhs, const AnyValue &rhs)
|
|
205
|
-
{
|
|
206
|
-
return AnyValue::make_boolean(less_than_or_equal_primitive(lhs, rhs));
|
|
207
|
-
}
|
|
208
|
-
inline AnyValue less_than_or_equal(const double &lhs, const double &rhs)
|
|
209
|
-
{
|
|
210
|
-
return AnyValue::make_boolean(less_than_or_equal_primitive(lhs, rhs));
|
|
211
|
-
}
|
|
212
|
-
|
|
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)
|
|
220
|
-
{
|
|
221
|
-
return AnyValue::make_boolean(greater_than_or_equal_primitive(lhs, rhs));
|
|
222
|
-
}
|
|
223
|
-
inline AnyValue greater_than_or_equal(const double &lhs, const AnyValue &rhs)
|
|
224
|
-
{
|
|
225
|
-
return AnyValue::make_boolean(greater_than_or_equal_primitive(lhs, rhs));
|
|
226
|
-
}
|
|
227
|
-
inline AnyValue greater_than_or_equal(const double &lhs, const double &rhs)
|
|
228
|
-
{
|
|
229
|
-
return AnyValue::make_boolean(greater_than_or_equal_primitive(lhs, rhs));
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// Equality ==
|
|
233
|
-
inline AnyValue equal(const AnyValue &lhs, const AnyValue &rhs)
|
|
234
|
-
{
|
|
235
|
-
return AnyValue::make_boolean(is_equal_to_primitive(lhs, rhs));
|
|
236
|
-
}
|
|
237
|
-
inline AnyValue equal(const AnyValue &lhs, const double &rhs)
|
|
238
|
-
{
|
|
239
|
-
if (lhs.is_number())
|
|
240
|
-
return AnyValue::make_boolean(equal_primitive(lhs.as_double(), rhs));
|
|
241
|
-
return AnyValue::make_boolean(is_equal_to_primitive(lhs, AnyValue::make_number(rhs)));
|
|
242
|
-
}
|
|
243
|
-
inline AnyValue equal(const double &lhs, const AnyValue &rhs)
|
|
244
|
-
{
|
|
245
|
-
if (rhs.is_number())
|
|
246
|
-
return AnyValue::make_boolean(equal_primitive(lhs, rhs.as_double()));
|
|
247
|
-
return AnyValue::make_boolean(is_equal_to_primitive(rhs, AnyValue::make_number(lhs)));
|
|
248
|
-
}
|
|
249
|
-
inline AnyValue equal(const double &lhs, const double &rhs)
|
|
250
|
-
{
|
|
251
|
-
return AnyValue::make_boolean(equal_primitive(lhs, rhs));
|
|
252
|
-
}
|
|
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
|
-
|
|
259
|
-
// --- BITWISE OPERATORS ---
|
|
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)); }
|
|
264
|
-
|
|
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)); }
|
|
269
|
-
|
|
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)); }
|
|
274
|
-
|
|
275
|
-
// --- SHIFT OPERATORS ---
|
|
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)); }
|
|
280
|
-
|
|
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)); }
|
|
285
|
-
|
|
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)); }
|
|
290
|
-
|
|
291
|
-
// --- LOGICAL SHORT-CIRCUITING HELPERS ---
|
|
292
|
-
inline AnyValue logical_and(const AnyValue &lhs, const AnyValue &rhs)
|
|
293
|
-
{
|
|
294
|
-
if (!is_truthy(lhs))
|
|
295
|
-
return lhs;
|
|
296
|
-
return rhs;
|
|
297
|
-
}
|
|
298
|
-
inline AnyValue logical_or(const AnyValue &lhs, const AnyValue &rhs)
|
|
299
|
-
{
|
|
300
|
-
if (is_truthy(lhs))
|
|
301
|
-
return lhs;
|
|
302
|
-
return rhs;
|
|
303
|
-
}
|
|
304
|
-
inline AnyValue nullish_coalesce(const AnyValue &lhs, const AnyValue &rhs)
|
|
305
|
-
{
|
|
306
|
-
if (!lhs.is_null() && !lhs.is_undefined())
|
|
307
|
-
return lhs;
|
|
308
|
-
return rhs;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
// --- LOGICAL ASSIGNMENT HELPERS ---
|
|
312
|
-
inline AnyValue &logical_and_assign(AnyValue &lhs, const AnyValue &rhs)
|
|
313
|
-
{
|
|
314
|
-
if (is_truthy(lhs))
|
|
315
|
-
lhs = rhs;
|
|
316
|
-
return lhs;
|
|
317
|
-
}
|
|
318
|
-
inline AnyValue &logical_or_assign(AnyValue &lhs, const AnyValue &rhs)
|
|
319
|
-
{
|
|
320
|
-
if (!is_truthy(lhs))
|
|
321
|
-
lhs = rhs;
|
|
322
|
-
return lhs;
|
|
323
|
-
}
|
|
324
|
-
inline AnyValue &nullish_coalesce_assign(AnyValue &lhs, const AnyValue &rhs)
|
|
325
|
-
{
|
|
326
|
-
if (lhs.is_null() || lhs.is_undefined())
|
|
327
|
-
lhs = rhs;
|
|
328
|
-
return lhs;
|
|
329
|
-
}
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "types.hpp"
|
|
4
|
+
#include "any_value.hpp"
|
|
5
|
+
#include "operators_primitive.hpp"
|
|
6
|
+
#include <cstdint> // For int32_t
|
|
7
|
+
#include <cmath> // For fmod, isnan, isinf, floor, abs, pow
|
|
8
|
+
#include <string> // For std::to_string, std::stod
|
|
9
|
+
#include <algorithm> // For std::all_of
|
|
10
|
+
#include <limits> // For numeric_limits
|
|
11
|
+
|
|
12
|
+
namespace jspp
|
|
13
|
+
{
|
|
14
|
+
// Operator === (returns boolean wrapped in AnyValue)
|
|
15
|
+
inline const AnyValue is_strictly_equal_to(const AnyValue &lhs, const double &rhs) noexcept
|
|
16
|
+
{
|
|
17
|
+
return AnyValue::make_boolean(is_strictly_equal_to_primitive(lhs, rhs));
|
|
18
|
+
}
|
|
19
|
+
inline const AnyValue is_strictly_equal_to(const double &lhs, const AnyValue &rhs) noexcept
|
|
20
|
+
{
|
|
21
|
+
return AnyValue::make_boolean(is_strictly_equal_to_primitive(lhs, rhs));
|
|
22
|
+
}
|
|
23
|
+
inline const AnyValue is_strictly_equal_to(const double &lhs, const double &rhs) noexcept
|
|
24
|
+
{
|
|
25
|
+
return AnyValue::make_boolean(is_strictly_equal_to_primitive(lhs, rhs));
|
|
26
|
+
}
|
|
27
|
+
inline const AnyValue is_strictly_equal_to(const AnyValue &lhs, const AnyValue &rhs) noexcept
|
|
28
|
+
{
|
|
29
|
+
return AnyValue::make_boolean(is_strictly_equal_to_primitive(lhs, rhs));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Operator == (returns boolean wrapped in AnyValue)
|
|
33
|
+
inline const AnyValue is_equal_to(const AnyValue &lhs, const double &rhs) noexcept
|
|
34
|
+
{
|
|
35
|
+
return AnyValue::make_boolean(is_equal_to_primitive(lhs, rhs));
|
|
36
|
+
}
|
|
37
|
+
inline const AnyValue is_equal_to(const double &lhs, const AnyValue &rhs) noexcept
|
|
38
|
+
{
|
|
39
|
+
return AnyValue::make_boolean(is_equal_to_primitive(lhs, rhs));
|
|
40
|
+
}
|
|
41
|
+
inline const AnyValue is_equal_to(const double &lhs, const double &rhs) noexcept
|
|
42
|
+
{
|
|
43
|
+
return AnyValue::make_boolean(is_equal_to_primitive(lhs, rhs));
|
|
44
|
+
}
|
|
45
|
+
inline const AnyValue is_equal_to(const AnyValue &lhs, const AnyValue &rhs) noexcept
|
|
46
|
+
{
|
|
47
|
+
return AnyValue::make_boolean(is_equal_to_primitive(lhs, rhs));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Operator !== (returns boolean wrapped in AnyValue)
|
|
51
|
+
inline const AnyValue not_strictly_equal_to(const AnyValue &lhs, const double &rhs) noexcept
|
|
52
|
+
{
|
|
53
|
+
return AnyValue::make_boolean(!is_strictly_equal_to_primitive(lhs, rhs));
|
|
54
|
+
}
|
|
55
|
+
inline const AnyValue not_strictly_equal_to(const double &lhs, const AnyValue &rhs) noexcept
|
|
56
|
+
{
|
|
57
|
+
return AnyValue::make_boolean(!is_strictly_equal_to_primitive(lhs, rhs));
|
|
58
|
+
}
|
|
59
|
+
inline const AnyValue not_strictly_equal_to(const double &lhs, const double &rhs) noexcept
|
|
60
|
+
{
|
|
61
|
+
return AnyValue::make_boolean(!is_strictly_equal_to_primitive(lhs, rhs));
|
|
62
|
+
}
|
|
63
|
+
inline const AnyValue not_strictly_equal_to(const AnyValue &lhs, const AnyValue &rhs) noexcept
|
|
64
|
+
{
|
|
65
|
+
return AnyValue::make_boolean(!is_strictly_equal_to_primitive(lhs, rhs));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Operator != (returns boolean wrapped in AnyValue)
|
|
69
|
+
inline const AnyValue not_equal_to(const AnyValue &lhs, const double &rhs) noexcept
|
|
70
|
+
{
|
|
71
|
+
return AnyValue::make_boolean(!is_equal_to_primitive(lhs, rhs));
|
|
72
|
+
}
|
|
73
|
+
inline const AnyValue not_equal_to(const double &lhs, const AnyValue &rhs) noexcept
|
|
74
|
+
{
|
|
75
|
+
return AnyValue::make_boolean(!is_equal_to_primitive(lhs, rhs));
|
|
76
|
+
}
|
|
77
|
+
inline const AnyValue not_equal_to(const double &lhs, const double &rhs) noexcept
|
|
78
|
+
{
|
|
79
|
+
return AnyValue::make_boolean(!is_equal_to_primitive(lhs, rhs));
|
|
80
|
+
}
|
|
81
|
+
inline const AnyValue not_equal_to(const AnyValue &lhs, const AnyValue &rhs) noexcept
|
|
82
|
+
{
|
|
83
|
+
return AnyValue::make_boolean(!is_equal_to_primitive(lhs, rhs));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// --- BASIC ARITHMETIC ---
|
|
87
|
+
|
|
88
|
+
// Function add
|
|
89
|
+
inline AnyValue add(const AnyValue &lhs, const AnyValue &rhs)
|
|
90
|
+
{
|
|
91
|
+
if (lhs.is_number() && rhs.is_number())
|
|
92
|
+
return AnyValue::make_number(add_primitive(lhs.as_double(), rhs.as_double()));
|
|
93
|
+
if (lhs.is_string() || rhs.is_string())
|
|
94
|
+
return AnyValue::make_string(lhs.to_std_string() + rhs.to_std_string());
|
|
95
|
+
return AnyValue::make_number(add_primitive(lhs, rhs));
|
|
96
|
+
}
|
|
97
|
+
inline AnyValue add(const AnyValue &lhs, const double &rhs)
|
|
98
|
+
{
|
|
99
|
+
if (lhs.is_number())
|
|
100
|
+
return AnyValue::make_number(add_primitive(lhs.as_double(), rhs));
|
|
101
|
+
if (lhs.is_string())
|
|
102
|
+
return AnyValue::make_string(lhs.to_std_string() + std::to_string(rhs));
|
|
103
|
+
return AnyValue::make_number(add_primitive(lhs, rhs));
|
|
104
|
+
}
|
|
105
|
+
inline AnyValue add(const double &lhs, const AnyValue &rhs)
|
|
106
|
+
{
|
|
107
|
+
if (rhs.is_number())
|
|
108
|
+
return AnyValue::make_number(add_primitive(lhs, rhs.as_double()));
|
|
109
|
+
if (rhs.is_string())
|
|
110
|
+
return AnyValue::make_string(std::to_string(lhs) + rhs.to_std_string());
|
|
111
|
+
return AnyValue::make_number(add_primitive(lhs, rhs));
|
|
112
|
+
}
|
|
113
|
+
inline AnyValue add(const double &lhs, const double &rhs)
|
|
114
|
+
{
|
|
115
|
+
return AnyValue::make_number(add_primitive(lhs, rhs));
|
|
116
|
+
}
|
|
117
|
+
|
|
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)); }
|
|
123
|
+
|
|
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)); }
|
|
129
|
+
|
|
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)); }
|
|
141
|
+
|
|
142
|
+
// --- UNARY OPERATORS ---
|
|
143
|
+
inline AnyValue plus(const AnyValue &val)
|
|
144
|
+
{
|
|
145
|
+
return AnyValue::make_number(Operators_Private::ToNumber(val));
|
|
146
|
+
}
|
|
147
|
+
inline AnyValue negate(const AnyValue &val)
|
|
148
|
+
{
|
|
149
|
+
return AnyValue::make_number(-Operators_Private::ToNumber(val));
|
|
150
|
+
}
|
|
151
|
+
inline AnyValue bitwise_not(const AnyValue &val)
|
|
152
|
+
{
|
|
153
|
+
return AnyValue::make_number(~Operators_Private::ToInt32(val));
|
|
154
|
+
}
|
|
155
|
+
inline AnyValue logical_not(const AnyValue &val)
|
|
156
|
+
{
|
|
157
|
+
return AnyValue::make_boolean(!is_truthy(val));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// --- EXPONENTIATION ---
|
|
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)); }
|
|
165
|
+
|
|
166
|
+
// --- COMPARISON OPERATORS ---
|
|
167
|
+
|
|
168
|
+
// Less than <
|
|
169
|
+
inline AnyValue less_than(const AnyValue &lhs, const AnyValue &rhs)
|
|
170
|
+
{
|
|
171
|
+
if (lhs.is_string() && rhs.is_string())
|
|
172
|
+
return AnyValue::make_boolean(lhs.as_string()->value < rhs.as_string()->value);
|
|
173
|
+
|
|
174
|
+
return AnyValue::make_boolean(less_than_primitive(lhs, rhs));
|
|
175
|
+
}
|
|
176
|
+
inline AnyValue less_than(const AnyValue &lhs, const double &rhs)
|
|
177
|
+
{
|
|
178
|
+
return AnyValue::make_boolean(less_than_primitive(lhs, rhs));
|
|
179
|
+
}
|
|
180
|
+
inline AnyValue less_than(const double &lhs, const AnyValue &rhs)
|
|
181
|
+
{
|
|
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));
|
|
187
|
+
}
|
|
188
|
+
|
|
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)); }
|
|
193
|
+
|
|
194
|
+
inline AnyValue less_than_or_equal(const AnyValue &lhs, const AnyValue &rhs)
|
|
195
|
+
{
|
|
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));
|
|
203
|
+
}
|
|
204
|
+
inline AnyValue less_than_or_equal(const double &lhs, const AnyValue &rhs)
|
|
205
|
+
{
|
|
206
|
+
return AnyValue::make_boolean(less_than_or_equal_primitive(lhs, rhs));
|
|
207
|
+
}
|
|
208
|
+
inline AnyValue less_than_or_equal(const double &lhs, const double &rhs)
|
|
209
|
+
{
|
|
210
|
+
return AnyValue::make_boolean(less_than_or_equal_primitive(lhs, rhs));
|
|
211
|
+
}
|
|
212
|
+
|
|
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)
|
|
220
|
+
{
|
|
221
|
+
return AnyValue::make_boolean(greater_than_or_equal_primitive(lhs, rhs));
|
|
222
|
+
}
|
|
223
|
+
inline AnyValue greater_than_or_equal(const double &lhs, const AnyValue &rhs)
|
|
224
|
+
{
|
|
225
|
+
return AnyValue::make_boolean(greater_than_or_equal_primitive(lhs, rhs));
|
|
226
|
+
}
|
|
227
|
+
inline AnyValue greater_than_or_equal(const double &lhs, const double &rhs)
|
|
228
|
+
{
|
|
229
|
+
return AnyValue::make_boolean(greater_than_or_equal_primitive(lhs, rhs));
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// Equality ==
|
|
233
|
+
inline AnyValue equal(const AnyValue &lhs, const AnyValue &rhs)
|
|
234
|
+
{
|
|
235
|
+
return AnyValue::make_boolean(is_equal_to_primitive(lhs, rhs));
|
|
236
|
+
}
|
|
237
|
+
inline AnyValue equal(const AnyValue &lhs, const double &rhs)
|
|
238
|
+
{
|
|
239
|
+
if (lhs.is_number())
|
|
240
|
+
return AnyValue::make_boolean(equal_primitive(lhs.as_double(), rhs));
|
|
241
|
+
return AnyValue::make_boolean(is_equal_to_primitive(lhs, AnyValue::make_number(rhs)));
|
|
242
|
+
}
|
|
243
|
+
inline AnyValue equal(const double &lhs, const AnyValue &rhs)
|
|
244
|
+
{
|
|
245
|
+
if (rhs.is_number())
|
|
246
|
+
return AnyValue::make_boolean(equal_primitive(lhs, rhs.as_double()));
|
|
247
|
+
return AnyValue::make_boolean(is_equal_to_primitive(rhs, AnyValue::make_number(lhs)));
|
|
248
|
+
}
|
|
249
|
+
inline AnyValue equal(const double &lhs, const double &rhs)
|
|
250
|
+
{
|
|
251
|
+
return AnyValue::make_boolean(equal_primitive(lhs, rhs));
|
|
252
|
+
}
|
|
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
|
+
|
|
259
|
+
// --- BITWISE OPERATORS ---
|
|
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)); }
|
|
264
|
+
|
|
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)); }
|
|
269
|
+
|
|
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)); }
|
|
274
|
+
|
|
275
|
+
// --- SHIFT OPERATORS ---
|
|
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)); }
|
|
280
|
+
|
|
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)); }
|
|
285
|
+
|
|
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)); }
|
|
290
|
+
|
|
291
|
+
// --- LOGICAL SHORT-CIRCUITING HELPERS ---
|
|
292
|
+
inline AnyValue logical_and(const AnyValue &lhs, const AnyValue &rhs)
|
|
293
|
+
{
|
|
294
|
+
if (!is_truthy(lhs))
|
|
295
|
+
return lhs;
|
|
296
|
+
return rhs;
|
|
297
|
+
}
|
|
298
|
+
inline AnyValue logical_or(const AnyValue &lhs, const AnyValue &rhs)
|
|
299
|
+
{
|
|
300
|
+
if (is_truthy(lhs))
|
|
301
|
+
return lhs;
|
|
302
|
+
return rhs;
|
|
303
|
+
}
|
|
304
|
+
inline AnyValue nullish_coalesce(const AnyValue &lhs, const AnyValue &rhs)
|
|
305
|
+
{
|
|
306
|
+
if (!lhs.is_null() && !lhs.is_undefined())
|
|
307
|
+
return lhs;
|
|
308
|
+
return rhs;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// --- LOGICAL ASSIGNMENT HELPERS ---
|
|
312
|
+
inline AnyValue &logical_and_assign(AnyValue &lhs, const AnyValue &rhs)
|
|
313
|
+
{
|
|
314
|
+
if (is_truthy(lhs))
|
|
315
|
+
lhs = rhs;
|
|
316
|
+
return lhs;
|
|
317
|
+
}
|
|
318
|
+
inline AnyValue &logical_or_assign(AnyValue &lhs, const AnyValue &rhs)
|
|
319
|
+
{
|
|
320
|
+
if (!is_truthy(lhs))
|
|
321
|
+
lhs = rhs;
|
|
322
|
+
return lhs;
|
|
323
|
+
}
|
|
324
|
+
inline AnyValue &nullish_coalesce_assign(AnyValue &lhs, const AnyValue &rhs)
|
|
325
|
+
{
|
|
326
|
+
if (lhs.is_null() || lhs.is_undefined())
|
|
327
|
+
lhs = rhs;
|
|
328
|
+
return lhs;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
inline AnyValue undefined_coalesce(const AnyValue &lhs, const AnyValue &rhs)
|
|
332
|
+
{
|
|
333
|
+
if (!lhs.is_undefined())
|
|
334
|
+
return lhs;
|
|
335
|
+
return rhs;
|
|
336
|
+
}
|
|
330
337
|
}
|