@ugo-studio/jspp 0.2.9 → 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.
Files changed (35) hide show
  1. package/dist/core/codegen/class-handlers.js +6 -6
  2. package/dist/core/codegen/statement-handlers.js +1 -1
  3. package/package.json +1 -1
  4. package/src/prelude/any_value.hpp +362 -362
  5. package/src/prelude/any_value_access.hpp +170 -170
  6. package/src/prelude/any_value_defines.hpp +189 -189
  7. package/src/prelude/any_value_helpers.hpp +374 -374
  8. package/src/prelude/library/array.hpp +185 -185
  9. package/src/prelude/library/console.hpp +111 -111
  10. package/src/prelude/library/error.hpp +112 -112
  11. package/src/prelude/library/function.hpp +10 -10
  12. package/src/prelude/library/math.hpp +307 -307
  13. package/src/prelude/library/object.hpp +275 -275
  14. package/src/prelude/library/process.hpp +39 -39
  15. package/src/prelude/library/promise.hpp +123 -123
  16. package/src/prelude/library/symbol.hpp +52 -52
  17. package/src/prelude/library/timer.hpp +91 -91
  18. package/src/prelude/types.hpp +178 -178
  19. package/src/prelude/utils/access.hpp +411 -411
  20. package/src/prelude/utils/operators.hpp +336 -336
  21. package/src/prelude/values/array.hpp +0 -1
  22. package/src/prelude/values/async_iterator.hpp +83 -83
  23. package/src/prelude/values/function.hpp +82 -82
  24. package/src/prelude/values/helpers/array.hpp +198 -208
  25. package/src/prelude/values/helpers/async_iterator.hpp +275 -275
  26. package/src/prelude/values/helpers/function.hpp +108 -108
  27. package/src/prelude/values/helpers/iterator.hpp +144 -144
  28. package/src/prelude/values/helpers/promise.hpp +253 -253
  29. package/src/prelude/values/helpers/string.hpp +37 -61
  30. package/src/prelude/values/promise.hpp +72 -72
  31. package/src/prelude/values/prototypes/array.hpp +14 -2
  32. package/src/prelude/values/prototypes/iterator.hpp +201 -201
  33. package/src/prelude/values/prototypes/promise.hpp +196 -196
  34. package/src/prelude/values/prototypes/string.hpp +564 -542
  35. 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, 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
- }
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
  }