@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,190 +1,190 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include "types.hpp"
|
|
4
|
-
#include "any_value.hpp"
|
|
5
|
-
#include "values/object.hpp"
|
|
6
|
-
#include "values/function.hpp"
|
|
7
|
-
|
|
8
|
-
namespace jspp
|
|
9
|
-
{
|
|
10
|
-
inline void AnyValue::define_data_property(const std::string &key,
|
|
11
|
-
{
|
|
12
|
-
if (is_object())
|
|
13
|
-
{
|
|
14
|
-
auto obj = as_object();
|
|
15
|
-
auto offset = obj->shape->get_offset(key);
|
|
16
|
-
if (offset.has_value())
|
|
17
|
-
{
|
|
18
|
-
obj->storage[offset.value()] = value;
|
|
19
|
-
}
|
|
20
|
-
else
|
|
21
|
-
{
|
|
22
|
-
obj->shape = obj->shape->transition(key);
|
|
23
|
-
obj->storage.push_back(value);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
else if (is_function())
|
|
27
|
-
{
|
|
28
|
-
as_function()->props[key] = value;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
inline void AnyValue::define_data_property(const AnyValue &key,
|
|
33
|
-
{
|
|
34
|
-
if (key.is_symbol())
|
|
35
|
-
define_data_property(key.as_symbol()->key, value);
|
|
36
|
-
else
|
|
37
|
-
define_data_property(key.to_std_string(), value);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
inline void AnyValue::define_data_property(const std::string &key,
|
|
41
|
-
{
|
|
42
|
-
define_data_property(key, AnyValue::make_data_descriptor(value, writable, enumerable, configurable));
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
inline void AnyValue::define_getter(const std::string &key,
|
|
46
|
-
{
|
|
47
|
-
if (is_object())
|
|
48
|
-
{
|
|
49
|
-
auto obj = as_object();
|
|
50
|
-
auto offset = obj->shape->get_offset(key);
|
|
51
|
-
|
|
52
|
-
if (offset.has_value())
|
|
53
|
-
{
|
|
54
|
-
auto &val = obj->storage[offset.value()];
|
|
55
|
-
if (val.is_accessor_descriptor())
|
|
56
|
-
{
|
|
57
|
-
auto desc = val.as_accessor_descriptor();
|
|
58
|
-
desc->get = [getter](
|
|
59
|
-
{
|
|
60
|
-
return getter.call(thisVal, args);
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
else
|
|
64
|
-
{
|
|
65
|
-
auto getFunc = [getter](
|
|
66
|
-
{
|
|
67
|
-
return getter.call(thisVal, args);
|
|
68
|
-
};
|
|
69
|
-
obj->storage[offset.value()] = AnyValue::make_accessor_descriptor(getFunc, std::nullopt, true, true);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
else
|
|
73
|
-
{
|
|
74
|
-
auto getFunc = [getter](
|
|
75
|
-
{
|
|
76
|
-
return getter.call(thisVal, args);
|
|
77
|
-
};
|
|
78
|
-
obj->shape = obj->shape->transition(key);
|
|
79
|
-
obj->storage.push_back(AnyValue::make_accessor_descriptor(getFunc, std::nullopt, true, true));
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
else if (is_function())
|
|
83
|
-
{
|
|
84
|
-
auto &props = as_function()->props;
|
|
85
|
-
auto it = props.find(key);
|
|
86
|
-
if (it != props.end() && it->second.is_accessor_descriptor())
|
|
87
|
-
{
|
|
88
|
-
auto desc = it->second.as_accessor_descriptor();
|
|
89
|
-
desc->get = [getter](
|
|
90
|
-
{
|
|
91
|
-
return getter.call(thisVal, args);
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
else
|
|
95
|
-
{
|
|
96
|
-
auto getFunc = [getter](
|
|
97
|
-
{
|
|
98
|
-
return getter.call(thisVal, args);
|
|
99
|
-
};
|
|
100
|
-
props[key] = AnyValue::make_accessor_descriptor(getFunc, std::nullopt, true, true);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
inline void AnyValue::define_getter(const AnyValue &key,
|
|
106
|
-
{
|
|
107
|
-
if (key.is_symbol())
|
|
108
|
-
define_getter(key.as_symbol()->key, getter);
|
|
109
|
-
else
|
|
110
|
-
define_getter(key.to_std_string(), getter);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
inline void AnyValue::define_setter(const std::string &key,
|
|
114
|
-
{
|
|
115
|
-
if (is_object())
|
|
116
|
-
{
|
|
117
|
-
auto obj = as_object();
|
|
118
|
-
auto offset = obj->shape->get_offset(key);
|
|
119
|
-
|
|
120
|
-
if (offset.has_value())
|
|
121
|
-
{
|
|
122
|
-
auto &val = obj->storage[offset.value()];
|
|
123
|
-
if (val.is_accessor_descriptor())
|
|
124
|
-
{
|
|
125
|
-
auto desc = val.as_accessor_descriptor();
|
|
126
|
-
desc->set = [setter](
|
|
127
|
-
{
|
|
128
|
-
if (args.empty())
|
|
129
|
-
return Constants::UNDEFINED;
|
|
130
|
-
return setter.call(thisVal, args);
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
else
|
|
134
|
-
{
|
|
135
|
-
auto setFunc = [setter](
|
|
136
|
-
{
|
|
137
|
-
if (args.empty())
|
|
138
|
-
return Constants::UNDEFINED;
|
|
139
|
-
return setter.call(thisVal, args);
|
|
140
|
-
};
|
|
141
|
-
obj->storage[offset.value()] = AnyValue::make_accessor_descriptor(std::nullopt, setFunc, true, true);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
else
|
|
145
|
-
{
|
|
146
|
-
auto setFunc = [setter](
|
|
147
|
-
{
|
|
148
|
-
if (args.empty())
|
|
149
|
-
return Constants::UNDEFINED;
|
|
150
|
-
return setter.call(thisVal, args);
|
|
151
|
-
};
|
|
152
|
-
obj->shape = obj->shape->transition(key);
|
|
153
|
-
obj->storage.push_back(AnyValue::make_accessor_descriptor(std::nullopt, setFunc, true, true));
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
else if (is_function())
|
|
157
|
-
{
|
|
158
|
-
auto &props = as_function()->props;
|
|
159
|
-
auto it = props.find(key);
|
|
160
|
-
if (it != props.end() && it->second.is_accessor_descriptor())
|
|
161
|
-
{
|
|
162
|
-
auto desc = it->second.as_accessor_descriptor();
|
|
163
|
-
desc->set = [setter](
|
|
164
|
-
{
|
|
165
|
-
if (args.empty())
|
|
166
|
-
return Constants::UNDEFINED;
|
|
167
|
-
return setter.call(thisVal, args);
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
else
|
|
171
|
-
{
|
|
172
|
-
auto setFunc = [setter](
|
|
173
|
-
{
|
|
174
|
-
if (args.empty())
|
|
175
|
-
return Constants::UNDEFINED;
|
|
176
|
-
return setter.call(thisVal, args);
|
|
177
|
-
};
|
|
178
|
-
props[key] = AnyValue::make_accessor_descriptor(std::nullopt, setFunc, true, true);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
inline void AnyValue::define_setter(const AnyValue &key,
|
|
184
|
-
{
|
|
185
|
-
if (key.is_symbol())
|
|
186
|
-
define_setter(key.as_symbol()->key, setter);
|
|
187
|
-
else
|
|
188
|
-
define_setter(key.to_std_string(), setter);
|
|
189
|
-
}
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "types.hpp"
|
|
4
|
+
#include "any_value.hpp"
|
|
5
|
+
#include "values/object.hpp"
|
|
6
|
+
#include "values/function.hpp"
|
|
7
|
+
|
|
8
|
+
namespace jspp
|
|
9
|
+
{
|
|
10
|
+
inline void AnyValue::define_data_property(const std::string &key, AnyValue value)
|
|
11
|
+
{
|
|
12
|
+
if (is_object())
|
|
13
|
+
{
|
|
14
|
+
auto obj = as_object();
|
|
15
|
+
auto offset = obj->shape->get_offset(key);
|
|
16
|
+
if (offset.has_value())
|
|
17
|
+
{
|
|
18
|
+
obj->storage[offset.value()] = value;
|
|
19
|
+
}
|
|
20
|
+
else
|
|
21
|
+
{
|
|
22
|
+
obj->shape = obj->shape->transition(key);
|
|
23
|
+
obj->storage.push_back(value);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else if (is_function())
|
|
27
|
+
{
|
|
28
|
+
as_function()->props[key] = value;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
inline void AnyValue::define_data_property(const AnyValue &key, AnyValue value)
|
|
33
|
+
{
|
|
34
|
+
if (key.is_symbol())
|
|
35
|
+
define_data_property(key.as_symbol()->key, value);
|
|
36
|
+
else
|
|
37
|
+
define_data_property(key.to_std_string(), value);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
inline void AnyValue::define_data_property(const std::string &key, AnyValue value, bool writable, bool enumerable, bool configurable)
|
|
41
|
+
{
|
|
42
|
+
define_data_property(key, AnyValue::make_data_descriptor(value, writable, enumerable, configurable));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
inline void AnyValue::define_getter(const std::string &key, AnyValue getter)
|
|
46
|
+
{
|
|
47
|
+
if (is_object())
|
|
48
|
+
{
|
|
49
|
+
auto obj = as_object();
|
|
50
|
+
auto offset = obj->shape->get_offset(key);
|
|
51
|
+
|
|
52
|
+
if (offset.has_value())
|
|
53
|
+
{
|
|
54
|
+
auto &val = obj->storage[offset.value()];
|
|
55
|
+
if (val.is_accessor_descriptor())
|
|
56
|
+
{
|
|
57
|
+
auto desc = val.as_accessor_descriptor();
|
|
58
|
+
desc->get = [getter](AnyValue thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
59
|
+
{
|
|
60
|
+
return getter.call(thisVal, args);
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
else
|
|
64
|
+
{
|
|
65
|
+
auto getFunc = [getter](AnyValue thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
66
|
+
{
|
|
67
|
+
return getter.call(thisVal, args);
|
|
68
|
+
};
|
|
69
|
+
obj->storage[offset.value()] = AnyValue::make_accessor_descriptor(getFunc, std::nullopt, true, true);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else
|
|
73
|
+
{
|
|
74
|
+
auto getFunc = [getter](AnyValue thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
75
|
+
{
|
|
76
|
+
return getter.call(thisVal, args);
|
|
77
|
+
};
|
|
78
|
+
obj->shape = obj->shape->transition(key);
|
|
79
|
+
obj->storage.push_back(AnyValue::make_accessor_descriptor(getFunc, std::nullopt, true, true));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else if (is_function())
|
|
83
|
+
{
|
|
84
|
+
auto &props = as_function()->props;
|
|
85
|
+
auto it = props.find(key);
|
|
86
|
+
if (it != props.end() && it->second.is_accessor_descriptor())
|
|
87
|
+
{
|
|
88
|
+
auto desc = it->second.as_accessor_descriptor();
|
|
89
|
+
desc->get = [getter](AnyValue thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
90
|
+
{
|
|
91
|
+
return getter.call(thisVal, args);
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
else
|
|
95
|
+
{
|
|
96
|
+
auto getFunc = [getter](AnyValue thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
97
|
+
{
|
|
98
|
+
return getter.call(thisVal, args);
|
|
99
|
+
};
|
|
100
|
+
props[key] = AnyValue::make_accessor_descriptor(getFunc, std::nullopt, true, true);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
inline void AnyValue::define_getter(const AnyValue &key, AnyValue getter)
|
|
106
|
+
{
|
|
107
|
+
if (key.is_symbol())
|
|
108
|
+
define_getter(key.as_symbol()->key, getter);
|
|
109
|
+
else
|
|
110
|
+
define_getter(key.to_std_string(), getter);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
inline void AnyValue::define_setter(const std::string &key, AnyValue setter)
|
|
114
|
+
{
|
|
115
|
+
if (is_object())
|
|
116
|
+
{
|
|
117
|
+
auto obj = as_object();
|
|
118
|
+
auto offset = obj->shape->get_offset(key);
|
|
119
|
+
|
|
120
|
+
if (offset.has_value())
|
|
121
|
+
{
|
|
122
|
+
auto &val = obj->storage[offset.value()];
|
|
123
|
+
if (val.is_accessor_descriptor())
|
|
124
|
+
{
|
|
125
|
+
auto desc = val.as_accessor_descriptor();
|
|
126
|
+
desc->set = [setter](AnyValue thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
127
|
+
{
|
|
128
|
+
if (args.empty())
|
|
129
|
+
return Constants::UNDEFINED;
|
|
130
|
+
return setter.call(thisVal, args);
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
else
|
|
134
|
+
{
|
|
135
|
+
auto setFunc = [setter](AnyValue thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
136
|
+
{
|
|
137
|
+
if (args.empty())
|
|
138
|
+
return Constants::UNDEFINED;
|
|
139
|
+
return setter.call(thisVal, args);
|
|
140
|
+
};
|
|
141
|
+
obj->storage[offset.value()] = AnyValue::make_accessor_descriptor(std::nullopt, setFunc, true, true);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
else
|
|
145
|
+
{
|
|
146
|
+
auto setFunc = [setter](AnyValue thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
147
|
+
{
|
|
148
|
+
if (args.empty())
|
|
149
|
+
return Constants::UNDEFINED;
|
|
150
|
+
return setter.call(thisVal, args);
|
|
151
|
+
};
|
|
152
|
+
obj->shape = obj->shape->transition(key);
|
|
153
|
+
obj->storage.push_back(AnyValue::make_accessor_descriptor(std::nullopt, setFunc, true, true));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
else if (is_function())
|
|
157
|
+
{
|
|
158
|
+
auto &props = as_function()->props;
|
|
159
|
+
auto it = props.find(key);
|
|
160
|
+
if (it != props.end() && it->second.is_accessor_descriptor())
|
|
161
|
+
{
|
|
162
|
+
auto desc = it->second.as_accessor_descriptor();
|
|
163
|
+
desc->set = [setter](AnyValue thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
164
|
+
{
|
|
165
|
+
if (args.empty())
|
|
166
|
+
return Constants::UNDEFINED;
|
|
167
|
+
return setter.call(thisVal, args);
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
else
|
|
171
|
+
{
|
|
172
|
+
auto setFunc = [setter](AnyValue thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
173
|
+
{
|
|
174
|
+
if (args.empty())
|
|
175
|
+
return Constants::UNDEFINED;
|
|
176
|
+
return setter.call(thisVal, args);
|
|
177
|
+
};
|
|
178
|
+
props[key] = AnyValue::make_accessor_descriptor(std::nullopt, setFunc, true, true);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
inline void AnyValue::define_setter(const AnyValue &key, AnyValue setter)
|
|
184
|
+
{
|
|
185
|
+
if (key.is_symbol())
|
|
186
|
+
define_setter(key.as_symbol()->key, setter);
|
|
187
|
+
else
|
|
188
|
+
define_setter(key.to_std_string(), setter);
|
|
189
|
+
}
|
|
190
190
|
}
|