@ugo-studio/jspp 0.1.4 → 0.1.5
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/scope.js +17 -0
- package/dist/analysis/typeAnalyzer.js +7 -1
- package/dist/ast/symbols.js +29 -0
- package/dist/ast/types.js +0 -6
- package/dist/cli-utils/args.js +57 -0
- package/dist/cli-utils/colors.js +9 -0
- package/dist/cli-utils/file-utils.js +20 -0
- package/dist/cli-utils/spinner.js +55 -0
- package/dist/cli.js +105 -30
- package/dist/core/codegen/class-handlers.js +10 -6
- package/dist/core/codegen/control-flow-handlers.js +31 -21
- package/dist/core/codegen/declaration-handlers.js +10 -6
- package/dist/core/codegen/expression-handlers.js +202 -60
- package/dist/core/codegen/function-handlers.js +179 -70
- package/dist/core/codegen/helpers.js +107 -17
- package/dist/core/codegen/index.js +9 -8
- package/dist/core/codegen/literal-handlers.js +15 -6
- package/dist/core/codegen/statement-handlers.js +67 -53
- package/dist/core/codegen/visitor.js +3 -1
- package/package.json +1 -1
- package/src/prelude/any_value.hpp +195 -342
- package/src/prelude/any_value_access.hpp +78 -30
- package/src/prelude/any_value_defines.hpp +74 -35
- package/src/prelude/any_value_helpers.hpp +73 -180
- package/src/prelude/exception.hpp +1 -0
- package/src/prelude/exception_helpers.hpp +4 -4
- package/src/prelude/index.hpp +9 -2
- package/src/prelude/library/array.hpp +190 -0
- package/src/prelude/library/console.hpp +6 -5
- package/src/prelude/library/error.hpp +10 -8
- package/src/prelude/library/function.hpp +10 -0
- package/src/prelude/library/global.hpp +20 -0
- package/src/prelude/library/math.hpp +308 -0
- package/src/prelude/library/object.hpp +288 -0
- package/src/prelude/library/performance.hpp +1 -1
- package/src/prelude/library/process.hpp +39 -0
- package/src/prelude/library/promise.hpp +53 -43
- package/src/prelude/library/symbol.hpp +45 -57
- package/src/prelude/library/timer.hpp +6 -6
- package/src/prelude/types.hpp +48 -0
- package/src/prelude/utils/access.hpp +182 -11
- package/src/prelude/utils/assignment_operators.hpp +99 -0
- package/src/prelude/utils/log_any_value/array.hpp +8 -8
- package/src/prelude/utils/log_any_value/function.hpp +6 -4
- package/src/prelude/utils/log_any_value/object.hpp +41 -24
- package/src/prelude/utils/log_any_value/primitives.hpp +3 -1
- package/src/prelude/utils/operators.hpp +750 -274
- package/src/prelude/utils/well_known_symbols.hpp +12 -0
- package/src/prelude/values/array.hpp +8 -6
- package/src/prelude/values/descriptors.hpp +2 -2
- package/src/prelude/values/function.hpp +71 -62
- package/src/prelude/values/helpers/array.hpp +64 -28
- package/src/prelude/values/helpers/function.hpp +77 -92
- package/src/prelude/values/helpers/iterator.hpp +3 -3
- package/src/prelude/values/helpers/object.hpp +54 -9
- package/src/prelude/values/helpers/promise.hpp +3 -3
- package/src/prelude/values/iterator.hpp +1 -1
- package/src/prelude/values/object.hpp +10 -3
- package/src/prelude/values/promise.hpp +3 -3
- package/src/prelude/values/prototypes/array.hpp +851 -12
- package/src/prelude/values/prototypes/function.hpp +2 -2
- package/src/prelude/values/prototypes/iterator.hpp +5 -5
- package/src/prelude/values/prototypes/number.hpp +153 -0
- package/src/prelude/values/prototypes/object.hpp +2 -2
- package/src/prelude/values/prototypes/promise.hpp +40 -30
- package/src/prelude/values/prototypes/string.hpp +28 -28
- package/src/prelude/values/prototypes/symbol.hpp +20 -3
- package/src/prelude/values/shape.hpp +52 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "types.hpp"
|
|
4
|
+
#include "any_value.hpp"
|
|
5
|
+
#include "utils/operators.hpp"
|
|
6
|
+
|
|
7
|
+
namespace jspp {
|
|
8
|
+
|
|
9
|
+
// --- FRIEND IMPLEMENTATIONS ---
|
|
10
|
+
|
|
11
|
+
inline AnyValue &operator+=(AnyValue &lhs, const AnyValue &rhs) {
|
|
12
|
+
lhs = lhs + rhs;
|
|
13
|
+
return lhs;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
inline AnyValue &operator-=(AnyValue &lhs, const AnyValue &rhs) {
|
|
17
|
+
lhs = lhs - rhs;
|
|
18
|
+
return lhs;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
inline AnyValue &operator*=(AnyValue &lhs, const AnyValue &rhs) {
|
|
22
|
+
lhs = lhs * rhs;
|
|
23
|
+
return lhs;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
inline AnyValue &operator/=(AnyValue &lhs, const AnyValue &rhs) {
|
|
27
|
+
lhs = lhs / rhs;
|
|
28
|
+
return lhs;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
inline AnyValue &operator%=(AnyValue &lhs, const AnyValue &rhs) {
|
|
32
|
+
lhs = lhs % rhs;
|
|
33
|
+
return lhs;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
inline AnyValue &operator++(AnyValue &val) {
|
|
37
|
+
val = val + 1.0;
|
|
38
|
+
return val;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
inline AnyValue operator++(AnyValue &val, int) {
|
|
42
|
+
AnyValue temp = val;
|
|
43
|
+
val = val + 1.0;
|
|
44
|
+
return temp;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
inline AnyValue &operator--(AnyValue &val) {
|
|
48
|
+
val = val - 1.0;
|
|
49
|
+
return val;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
inline AnyValue operator--(AnyValue &val, int) {
|
|
53
|
+
AnyValue temp = val;
|
|
54
|
+
val = val - 1.0;
|
|
55
|
+
return temp;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// --- OVERLOADS FOR PRIMITIVES ---
|
|
59
|
+
|
|
60
|
+
inline AnyValue &operator+=(AnyValue &lhs, const double &rhs) {
|
|
61
|
+
lhs = lhs + rhs;
|
|
62
|
+
return lhs;
|
|
63
|
+
}
|
|
64
|
+
inline AnyValue &operator+=(AnyValue &lhs, const int &rhs) {
|
|
65
|
+
return lhs += static_cast<double>(rhs);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
inline AnyValue &operator-=(AnyValue &lhs, const double &rhs) {
|
|
69
|
+
lhs = lhs - rhs;
|
|
70
|
+
return lhs;
|
|
71
|
+
}
|
|
72
|
+
inline AnyValue &operator-=(AnyValue &lhs, const int &rhs) {
|
|
73
|
+
return lhs -= static_cast<double>(rhs);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
inline AnyValue &operator*=(AnyValue &lhs, const double &rhs) {
|
|
77
|
+
lhs = lhs * rhs;
|
|
78
|
+
return lhs;
|
|
79
|
+
}
|
|
80
|
+
inline AnyValue &operator*=(AnyValue &lhs, const int &rhs) {
|
|
81
|
+
return lhs *= static_cast<double>(rhs);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
inline AnyValue &operator/=(AnyValue &lhs, const double &rhs) {
|
|
85
|
+
lhs = lhs / rhs;
|
|
86
|
+
return lhs;
|
|
87
|
+
}
|
|
88
|
+
inline AnyValue &operator/=(AnyValue &lhs, const int &rhs) {
|
|
89
|
+
return lhs /= static_cast<double>(rhs);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
inline AnyValue &operator%=(AnyValue &lhs, const double &rhs) {
|
|
93
|
+
lhs = lhs % rhs;
|
|
94
|
+
return lhs;
|
|
95
|
+
}
|
|
96
|
+
inline AnyValue &operator%=(AnyValue &lhs, const int &rhs) {
|
|
97
|
+
return lhs %= static_cast<double>(rhs);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -45,7 +45,7 @@ namespace jspp
|
|
|
45
45
|
{
|
|
46
46
|
for (size_t i = 0; i < item_count; ++i)
|
|
47
47
|
{
|
|
48
|
-
|
|
48
|
+
AnyValue itemVal = AnyValue::make_uninitialized();
|
|
49
49
|
if (i < arr->dense.size())
|
|
50
50
|
{
|
|
51
51
|
itemVal = arr->dense[i];
|
|
@@ -58,7 +58,7 @@ namespace jspp
|
|
|
58
58
|
itemVal = it->second;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
if (itemVal.
|
|
61
|
+
if (!itemVal.is_uninitialized() && !is_simple_value(itemVal))
|
|
62
62
|
{
|
|
63
63
|
use_horizontal_layout = false;
|
|
64
64
|
break;
|
|
@@ -74,7 +74,7 @@ namespace jspp
|
|
|
74
74
|
|
|
75
75
|
for (size_t i = 0; i < item_count; ++i)
|
|
76
76
|
{
|
|
77
|
-
|
|
77
|
+
AnyValue itemVal = AnyValue::make_uninitialized();
|
|
78
78
|
if (i < arr->dense.size())
|
|
79
79
|
{
|
|
80
80
|
itemVal = arr->dense[i];
|
|
@@ -88,7 +88,7 @@ namespace jspp
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
if (itemVal.
|
|
91
|
+
if (!itemVal.is_uninitialized())
|
|
92
92
|
{
|
|
93
93
|
if (empty_count > 0)
|
|
94
94
|
{
|
|
@@ -100,7 +100,7 @@ namespace jspp
|
|
|
100
100
|
}
|
|
101
101
|
if (needs_comma)
|
|
102
102
|
ss << Color::BRIGHT_BLACK << ", " << Color::RESET;
|
|
103
|
-
ss << to_log_string(itemVal
|
|
103
|
+
ss << to_log_string(itemVal, visited, depth + 1);
|
|
104
104
|
needs_comma = true;
|
|
105
105
|
}
|
|
106
106
|
else
|
|
@@ -154,7 +154,7 @@ namespace jspp
|
|
|
154
154
|
|
|
155
155
|
for (size_t i = 0; i < items_to_show; ++i)
|
|
156
156
|
{
|
|
157
|
-
|
|
157
|
+
AnyValue itemVal = AnyValue::make_uninitialized();
|
|
158
158
|
if (i < arr->dense.size())
|
|
159
159
|
{
|
|
160
160
|
itemVal = arr->dense[i];
|
|
@@ -168,7 +168,7 @@ namespace jspp
|
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
-
if (itemVal.
|
|
171
|
+
if (!itemVal.is_uninitialized())
|
|
172
172
|
{
|
|
173
173
|
if (empty_count > 0)
|
|
174
174
|
{
|
|
@@ -182,7 +182,7 @@ namespace jspp
|
|
|
182
182
|
if (first_item_printed)
|
|
183
183
|
ss << Color::BRIGHT_BLACK << ",\n"
|
|
184
184
|
<< Color::RESET;
|
|
185
|
-
ss << next_indent << to_log_string(itemVal
|
|
185
|
+
ss << next_indent << to_log_string(itemVal, visited, depth + 1);
|
|
186
186
|
first_item_printed = true;
|
|
187
187
|
}
|
|
188
188
|
else
|
|
@@ -20,17 +20,19 @@ namespace jspp
|
|
|
20
20
|
if (fn->proto->is_function())
|
|
21
21
|
{
|
|
22
22
|
auto parent = fn->proto->as_function();
|
|
23
|
-
|
|
23
|
+
std::string name = parent->name.value_or("");
|
|
24
|
+
if (!name.empty())
|
|
24
25
|
{
|
|
25
|
-
extends_part = " extends " +
|
|
26
|
+
extends_part = " extends " + name;
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
|
-
|
|
30
|
+
std::string name = fn->name.value_or("");
|
|
31
|
+
return Color::CYAN + std::string("[class ") + (name.empty() ? "(anonymous)" : name) + extends_part + "]" + Color::RESET;
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
auto type_part = fn->is_generator ? "GeneratorFunction" : "Function";
|
|
33
|
-
auto name_part = fn->name.
|
|
35
|
+
auto name_part = fn->name.has_value() ? ": " + fn->name.value() : " (anonymous)";
|
|
34
36
|
return Color::CYAN + "[" + type_part + name_part + "]" + Color::RESET;
|
|
35
37
|
}
|
|
36
38
|
}
|
|
@@ -17,18 +17,21 @@ namespace jspp
|
|
|
17
17
|
{
|
|
18
18
|
auto obj = val.as_object();
|
|
19
19
|
|
|
20
|
-
size_t prop_count = obj->
|
|
20
|
+
size_t prop_count = obj->storage.size();
|
|
21
21
|
bool use_horizontal_layout = prop_count > 0 && prop_count <= HORIZONTAL_OBJECT_MAX_PROPS;
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
for (size_t i = 0; i < obj->storage.size(); ++i)
|
|
24
24
|
{
|
|
25
|
-
|
|
25
|
+
const auto& prop_val = obj->storage[i];
|
|
26
|
+
if (!is_enumerable_property(prop_val))
|
|
26
27
|
{
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
prop_count--;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (use_horizontal_layout && !is_simple_value(prop_val))
|
|
32
|
+
{
|
|
33
|
+
use_horizontal_layout = false;
|
|
34
|
+
break;
|
|
32
35
|
}
|
|
33
36
|
}
|
|
34
37
|
|
|
@@ -39,13 +42,19 @@ namespace jspp
|
|
|
39
42
|
// Special handling for Error objects
|
|
40
43
|
try
|
|
41
44
|
{
|
|
42
|
-
|
|
45
|
+
const AnyValue args[] = {val};
|
|
46
|
+
auto is_error = is_truthy(isErrorFn.call(isErrorFn, std::span<const AnyValue>(args, 1)));
|
|
43
47
|
if (is_error)
|
|
44
48
|
{
|
|
45
|
-
auto result = errorToStringFn.
|
|
49
|
+
auto result = errorToStringFn.call(val, std::span<const AnyValue>{});
|
|
46
50
|
if (result.is_string())
|
|
47
51
|
{
|
|
48
|
-
ss << result.to_std_string()
|
|
52
|
+
ss << result.to_std_string();
|
|
53
|
+
if (prop_count == 0)
|
|
54
|
+
{
|
|
55
|
+
return ss.str();
|
|
56
|
+
}
|
|
57
|
+
ss << " ";
|
|
49
58
|
}
|
|
50
59
|
}
|
|
51
60
|
}
|
|
@@ -58,20 +67,23 @@ namespace jspp
|
|
|
58
67
|
{
|
|
59
68
|
ss << "{ ";
|
|
60
69
|
size_t current_prop = 0;
|
|
61
|
-
for (
|
|
70
|
+
for (size_t i = 0; i < obj->shape->property_names.size(); ++i)
|
|
62
71
|
{
|
|
63
|
-
|
|
72
|
+
const auto& key = obj->shape->property_names[i];
|
|
73
|
+
const auto& prop_val = obj->storage[i];
|
|
74
|
+
|
|
75
|
+
if (!is_enumerable_property(prop_val))
|
|
64
76
|
continue;
|
|
65
77
|
|
|
66
|
-
if (is_valid_js_identifier(
|
|
78
|
+
if (is_valid_js_identifier(key))
|
|
67
79
|
{
|
|
68
|
-
ss <<
|
|
80
|
+
ss << key;
|
|
69
81
|
}
|
|
70
82
|
else
|
|
71
83
|
{
|
|
72
|
-
ss << "\"" <<
|
|
84
|
+
ss << "\"" << key << "\"";
|
|
73
85
|
}
|
|
74
|
-
ss << ": " << to_log_string(
|
|
86
|
+
ss << ": " << to_log_string(prop_val, visited, depth + 1);
|
|
75
87
|
if (++current_prop < prop_count)
|
|
76
88
|
ss << Color::BRIGHT_BLACK << ", " << Color::RESET;
|
|
77
89
|
}
|
|
@@ -84,25 +96,30 @@ namespace jspp
|
|
|
84
96
|
{
|
|
85
97
|
ss << "\n";
|
|
86
98
|
size_t props_shown = 0;
|
|
87
|
-
for (
|
|
99
|
+
for (size_t i = 0; i < obj->shape->property_names.size(); ++i)
|
|
88
100
|
{
|
|
101
|
+
const auto& key = obj->shape->property_names[i];
|
|
102
|
+
const auto& prop_val = obj->storage[i];
|
|
103
|
+
|
|
89
104
|
if (props_shown >= MAX_OBJECT_PROPS)
|
|
90
105
|
break;
|
|
106
|
+
|
|
107
|
+
if (!is_enumerable_property(prop_val))
|
|
108
|
+
continue;
|
|
109
|
+
|
|
91
110
|
if (props_shown > 0)
|
|
92
111
|
ss << ",\n";
|
|
93
|
-
if (!is_enumerable_property(pair.second))
|
|
94
|
-
continue;
|
|
95
112
|
|
|
96
113
|
ss << next_indent;
|
|
97
|
-
if (is_valid_js_identifier(
|
|
114
|
+
if (is_valid_js_identifier(key))
|
|
98
115
|
{
|
|
99
|
-
ss <<
|
|
116
|
+
ss << key;
|
|
100
117
|
}
|
|
101
118
|
else
|
|
102
119
|
{
|
|
103
|
-
ss << "\"" <<
|
|
120
|
+
ss << "\"" << key << "\"";
|
|
104
121
|
}
|
|
105
|
-
ss << ": " << to_log_string(
|
|
122
|
+
ss << ": " << to_log_string(prop_val, visited, depth + 1);
|
|
106
123
|
props_shown++;
|
|
107
124
|
}
|
|
108
125
|
if (prop_count > MAX_OBJECT_PROPS)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#pragma once
|
|
2
|
+
|
|
2
3
|
#include "types.hpp"
|
|
3
4
|
#include "any_value.hpp"
|
|
4
5
|
#include "utils/log_any_value/config.hpp"
|
|
@@ -13,7 +14,8 @@ namespace jspp
|
|
|
13
14
|
inline std::optional<std::string> format_primitive(const AnyValue &val, int depth)
|
|
14
15
|
{
|
|
15
16
|
if (val.is_uninitialized())
|
|
16
|
-
|
|
17
|
+
// THROW
|
|
18
|
+
Exception::throw_uninitialized_reference("#<Object>");
|
|
17
19
|
if (val.is_undefined())
|
|
18
20
|
return Color::BRIGHT_BLACK + std::string("undefined") + Color::RESET;
|
|
19
21
|
if (val.is_null())
|