@ugo-studio/jspp 0.3.2 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -6
- package/dist/cli/args.js +5 -0
- package/dist/cli/compiler.js +1 -1
- package/dist/cli/index.js +4 -2
- package/dist/interpreter/analysis/typeAnalyzer.js +62 -25
- package/dist/interpreter/core/codegen/control-flow-handlers.js +34 -10
- package/dist/interpreter/core/codegen/expression-handlers.js +92 -21
- package/dist/interpreter/core/codegen/function-handlers.js +16 -11
- package/dist/interpreter/core/codegen/helpers.js +5 -1
- package/dist/interpreter/core/codegen/index.js +1 -1
- package/dist/interpreter/core/codegen/statement-handlers.js +15 -11
- package/dist/interpreter/core/traverser.js +1 -2
- package/package.json +2 -2
- package/scripts/precompile-headers.ts +9 -1
- package/src/prelude/library/array.cpp +2 -2
- package/src/prelude/library/math.cpp +8 -8
- package/src/prelude/utils/access.hpp +0 -34
- package/src/prelude/utils/assignment_operators.hpp +96 -0
- package/src/prelude/utils/operators.hpp +39 -4
- package/src/prelude/utils/operators_native.hpp +73 -62
- package/src/prelude/values/array.cpp +17 -17
- package/src/prelude/values/iterator.cpp +262 -210
- package/src/prelude/values/number.cpp +4 -4
- package/src/prelude/values/string.cpp +13 -13
|
@@ -92,7 +92,7 @@ AnyValue &get_charAt_fn()
|
|
|
92
92
|
static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
93
93
|
{
|
|
94
94
|
auto self = thisVal.as_string();
|
|
95
|
-
double pos = args.empty() ? 0 :
|
|
95
|
+
double pos = args.empty() ? 0 : NumberOperators::ToDouble(args[0]);
|
|
96
96
|
int index = static_cast<int>(pos);
|
|
97
97
|
if (index < 0 || index >= self->value.length())
|
|
98
98
|
{
|
|
@@ -125,7 +125,7 @@ AnyValue &get_endsWith_fn()
|
|
|
125
125
|
if (args.empty())
|
|
126
126
|
return Constants::FALSE;
|
|
127
127
|
std::string search = args[0].to_std_string();
|
|
128
|
-
size_t end_pos = (args.size() > 1 && !args[1].is_undefined()) ? static_cast<size_t>(
|
|
128
|
+
size_t end_pos = (args.size() > 1 && !args[1].is_undefined()) ? static_cast<size_t>(NumberOperators::ToDouble(args[1])) : self->value.length();
|
|
129
129
|
|
|
130
130
|
if (end_pos > self->value.length())
|
|
131
131
|
end_pos = self->value.length();
|
|
@@ -145,7 +145,7 @@ AnyValue &get_includes_fn()
|
|
|
145
145
|
if (args.empty())
|
|
146
146
|
return Constants::FALSE;
|
|
147
147
|
std::string search = args[0].to_std_string();
|
|
148
|
-
size_t pos = (args.size() > 1) ? static_cast<size_t>(
|
|
148
|
+
size_t pos = (args.size() > 1) ? static_cast<size_t>(NumberOperators::ToDouble(args[1])) : 0;
|
|
149
149
|
|
|
150
150
|
return AnyValue::make_boolean(self->value.find(search, pos) != std::string::npos); },
|
|
151
151
|
"includes");
|
|
@@ -160,7 +160,7 @@ AnyValue &get_indexOf_fn()
|
|
|
160
160
|
if (args.empty())
|
|
161
161
|
return AnyValue::make_number(-1);
|
|
162
162
|
std::string search = args[0].to_std_string();
|
|
163
|
-
size_t pos = (args.size() > 1) ? static_cast<size_t>(
|
|
163
|
+
size_t pos = (args.size() > 1) ? static_cast<size_t>(NumberOperators::ToDouble(args[1])) : 0;
|
|
164
164
|
size_t result = self->value.find(search, pos);
|
|
165
165
|
return result == std::string::npos ? AnyValue::make_number(-1) : AnyValue::make_number(result); },
|
|
166
166
|
"indexOf");
|
|
@@ -175,7 +175,7 @@ AnyValue &get_lastIndexOf_fn()
|
|
|
175
175
|
if (args.empty())
|
|
176
176
|
return AnyValue::make_number(-1);
|
|
177
177
|
std::string search = args[0].to_std_string();
|
|
178
|
-
size_t pos = (args.size() > 1 && !args[1].is_undefined()) ? static_cast<size_t>(
|
|
178
|
+
size_t pos = (args.size() > 1 && !args[1].is_undefined()) ? static_cast<size_t>(NumberOperators::ToDouble(args[1])) : std::string::npos;
|
|
179
179
|
size_t result = self->value.rfind(search, pos);
|
|
180
180
|
return result == std::string::npos ? AnyValue::make_number(-1) : AnyValue::make_number(result); },
|
|
181
181
|
"lastIndexOf");
|
|
@@ -187,7 +187,7 @@ AnyValue &get_padEnd_fn()
|
|
|
187
187
|
static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
188
188
|
{
|
|
189
189
|
auto self = thisVal.as_string();
|
|
190
|
-
size_t target_length = args.empty() ? 0 : static_cast<size_t>(
|
|
190
|
+
size_t target_length = args.empty() ? 0 : static_cast<size_t>(NumberOperators::ToDouble(args[0]));
|
|
191
191
|
if (self->value.length() >= target_length)
|
|
192
192
|
return AnyValue::make_string(self->value);
|
|
193
193
|
std::string pad_string = (args.size() > 1 && !args[1].is_undefined() && !args[1].to_std_string().empty()) ? args[1].to_std_string() : " ";
|
|
@@ -206,7 +206,7 @@ AnyValue &get_padStart_fn()
|
|
|
206
206
|
static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
207
207
|
{
|
|
208
208
|
auto self = thisVal.as_string();
|
|
209
|
-
size_t target_length = args.empty() ? 0 : static_cast<size_t>(
|
|
209
|
+
size_t target_length = args.empty() ? 0 : static_cast<size_t>(NumberOperators::ToDouble(args[0]));
|
|
210
210
|
if (self->value.length() >= target_length)
|
|
211
211
|
return AnyValue::make_string(self->value);
|
|
212
212
|
std::string pad_string = (args.size() > 1 && !args[1].is_undefined() && !args[1].to_std_string().empty()) ? args[1].to_std_string() : " ";
|
|
@@ -225,7 +225,7 @@ AnyValue &get_repeat_fn()
|
|
|
225
225
|
static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
226
226
|
{
|
|
227
227
|
auto self = thisVal.as_string();
|
|
228
|
-
double count = args.empty() ? 0 :
|
|
228
|
+
double count = args.empty() ? 0 : NumberOperators::ToDouble(args[0]);
|
|
229
229
|
if (count < 0)
|
|
230
230
|
{
|
|
231
231
|
// In a real implementation, this should throw a RangeError.
|
|
@@ -290,8 +290,8 @@ AnyValue &get_slice_fn()
|
|
|
290
290
|
{
|
|
291
291
|
auto self = thisVal.as_string();
|
|
292
292
|
int len = self->value.length();
|
|
293
|
-
int start = args.empty() ? 0 :
|
|
294
|
-
int end = (args.size() < 2 || args[1].is_undefined()) ? len :
|
|
293
|
+
int start = args.empty() ? 0 : NumberOperators::ToInt32(args[0]);
|
|
294
|
+
int end = (args.size() < 2 || args[1].is_undefined()) ? len : NumberOperators::ToInt32(args[1]);
|
|
295
295
|
|
|
296
296
|
if (start < 0)
|
|
297
297
|
start += len;
|
|
@@ -347,7 +347,7 @@ AnyValue &get_startsWith_fn()
|
|
|
347
347
|
if (args.empty())
|
|
348
348
|
return Constants::FALSE;
|
|
349
349
|
std::string search = args[0].to_std_string();
|
|
350
|
-
size_t pos = (args.size() > 1) ? static_cast<size_t>(
|
|
350
|
+
size_t pos = (args.size() > 1) ? static_cast<size_t>(NumberOperators::ToDouble(args[1])) : 0;
|
|
351
351
|
if (pos > self->value.length())
|
|
352
352
|
pos = self->value.length();
|
|
353
353
|
|
|
@@ -362,8 +362,8 @@ AnyValue &get_substring_fn()
|
|
|
362
362
|
{
|
|
363
363
|
auto self = thisVal.as_string();
|
|
364
364
|
int len = self->value.length();
|
|
365
|
-
int start = args.empty() ? 0 :
|
|
366
|
-
int end = (args.size() < 2 || args[1].is_undefined()) ? len :
|
|
365
|
+
int start = args.empty() ? 0 : NumberOperators::ToInt32(args[0]);
|
|
366
|
+
int end = (args.size() < 2 || args[1].is_undefined()) ? len : NumberOperators::ToInt32(args[1]);
|
|
367
367
|
|
|
368
368
|
start = std::max(0, start);
|
|
369
369
|
end = std::max(0, end);
|