@ugo-studio/jspp 0.1.3 → 0.1.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 -2
- package/dist/analysis/scope.js +16 -4
- package/dist/analysis/typeAnalyzer.js +253 -20
- package/dist/ast/types.js +6 -0
- package/dist/cli.js +1 -2
- package/dist/core/codegen/class-handlers.js +127 -0
- package/dist/core/codegen/control-flow-handlers.js +464 -0
- package/dist/core/codegen/declaration-handlers.js +31 -14
- package/dist/core/codegen/expression-handlers.js +429 -117
- package/dist/core/codegen/function-handlers.js +91 -15
- package/dist/core/codegen/helpers.js +66 -2
- package/dist/core/codegen/index.js +17 -6
- package/dist/core/codegen/literal-handlers.js +3 -0
- package/dist/core/codegen/statement-handlers.js +133 -204
- package/dist/core/codegen/visitor.js +29 -3
- package/package.json +3 -3
- package/src/prelude/any_value.hpp +658 -634
- package/src/prelude/any_value_access.hpp +103 -0
- package/src/prelude/any_value_defines.hpp +151 -0
- package/src/prelude/any_value_helpers.hpp +246 -225
- package/src/prelude/exception.hpp +31 -0
- package/src/prelude/exception_helpers.hpp +49 -0
- package/src/prelude/index.hpp +18 -9
- package/src/prelude/library/console.hpp +13 -13
- package/src/prelude/library/error.hpp +111 -0
- package/src/prelude/library/global.hpp +15 -4
- package/src/prelude/library/performance.hpp +2 -2
- package/src/prelude/library/promise.hpp +121 -0
- package/src/prelude/library/symbol.hpp +3 -4
- package/src/prelude/library/timer.hpp +92 -0
- package/src/prelude/scheduler.hpp +145 -0
- package/src/prelude/types.hpp +10 -1
- package/src/prelude/utils/access.hpp +174 -0
- package/src/prelude/utils/log_any_value/array.hpp +245 -0
- package/src/prelude/utils/log_any_value/config.hpp +32 -0
- package/src/prelude/utils/log_any_value/function.hpp +37 -0
- package/src/prelude/utils/log_any_value/fwd.hpp +15 -0
- package/src/prelude/utils/log_any_value/helpers.hpp +62 -0
- package/src/prelude/utils/log_any_value/log_any_value.hpp +94 -0
- package/src/prelude/utils/log_any_value/object.hpp +119 -0
- package/src/prelude/utils/log_any_value/primitives.hpp +41 -0
- package/src/prelude/{operators.hpp → utils/operators.hpp} +29 -10
- package/src/prelude/{well_known_symbols.hpp → utils/well_known_symbols.hpp} +0 -1
- package/src/prelude/values/array.hpp +3 -2
- package/src/prelude/{descriptors.hpp → values/descriptors.hpp} +2 -2
- package/src/prelude/values/function.hpp +76 -51
- package/src/prelude/values/helpers/array.hpp +20 -11
- package/src/prelude/values/helpers/function.hpp +125 -77
- package/src/prelude/values/helpers/iterator.hpp +13 -7
- package/src/prelude/values/helpers/object.hpp +36 -6
- package/src/prelude/values/helpers/promise.hpp +181 -0
- package/src/prelude/values/helpers/string.hpp +3 -3
- package/src/prelude/values/helpers/symbol.hpp +2 -2
- package/src/prelude/values/iterator.hpp +13 -5
- package/src/prelude/values/object.hpp +6 -2
- package/src/prelude/values/promise.hpp +73 -0
- package/src/prelude/values/prototypes/array.hpp +16 -16
- package/src/prelude/values/prototypes/function.hpp +4 -4
- package/src/prelude/values/prototypes/iterator.hpp +11 -10
- package/src/prelude/values/prototypes/object.hpp +26 -0
- package/src/prelude/values/prototypes/promise.hpp +124 -0
- package/src/prelude/values/prototypes/string.hpp +26 -26
- package/src/prelude/values/prototypes/symbol.hpp +5 -3
- package/src/prelude/values/string.hpp +1 -1
- package/src/prelude/values/symbol.hpp +1 -1
- package/src/prelude/access.hpp +0 -91
- package/src/prelude/error.hpp +0 -31
- package/src/prelude/error_helpers.hpp +0 -59
- package/src/prelude/log_string.hpp +0 -407
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "types.hpp"
|
|
4
|
+
#include "any_value.hpp"
|
|
5
|
+
|
|
6
|
+
jspp::AnyValue jspp::AnyValue::get_own_property(const std::string &key) const
|
|
7
|
+
{
|
|
8
|
+
return get_property_with_receiver(key, *this);
|
|
9
|
+
}
|
|
10
|
+
jspp::AnyValue jspp::AnyValue::get_own_property(uint32_t idx) const noexcept
|
|
11
|
+
{
|
|
12
|
+
switch (storage.type)
|
|
13
|
+
{
|
|
14
|
+
case JsType::Array:
|
|
15
|
+
return storage.array->get_property(idx);
|
|
16
|
+
case JsType::String:
|
|
17
|
+
return storage.str->get_property(idx);
|
|
18
|
+
default:
|
|
19
|
+
return get_own_property(std::to_string(idx));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
jspp::AnyValue jspp::AnyValue::get_own_property(const AnyValue &key) const noexcept
|
|
23
|
+
{
|
|
24
|
+
if (key.storage.type == JsType::Number && storage.type == JsType::Array)
|
|
25
|
+
return storage.array->get_property(key.storage.number);
|
|
26
|
+
if (key.storage.type == JsType::Number && storage.type == JsType::String)
|
|
27
|
+
return storage.str->get_property(key.storage.number);
|
|
28
|
+
|
|
29
|
+
// If the key is a Symbol, use its internal key string
|
|
30
|
+
if (key.storage.type == JsType::Symbol)
|
|
31
|
+
return get_own_property(key.storage.symbol->key);
|
|
32
|
+
|
|
33
|
+
return get_own_property(key.to_std_string());
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
jspp::AnyValue jspp::AnyValue::get_property_with_receiver(const std::string &key, const AnyValue &receiver) const
|
|
37
|
+
{
|
|
38
|
+
switch (storage.type)
|
|
39
|
+
{
|
|
40
|
+
case JsType::Object:
|
|
41
|
+
return storage.object->get_property(key, receiver);
|
|
42
|
+
case JsType::Array:
|
|
43
|
+
return storage.array->get_property(key, receiver);
|
|
44
|
+
case JsType::Function:
|
|
45
|
+
return storage.function->get_property(key, receiver);
|
|
46
|
+
case JsType::Promise:
|
|
47
|
+
return storage.promise->get_property(key, receiver);
|
|
48
|
+
case JsType::Iterator:
|
|
49
|
+
return storage.iterator->get_property(key, receiver);
|
|
50
|
+
case JsType::Symbol:
|
|
51
|
+
return storage.symbol->get_property(key, receiver);
|
|
52
|
+
case JsType::String:
|
|
53
|
+
return storage.str->get_property(key, receiver);
|
|
54
|
+
case JsType::Undefined:
|
|
55
|
+
throw Exception::make_exception("Cannot read properties of undefined (reading '" + key + "')", "TypeError");
|
|
56
|
+
case JsType::Null:
|
|
57
|
+
throw Exception::make_exception("Cannot read properties of null (reading '" + key + "')", "TypeError");
|
|
58
|
+
default:
|
|
59
|
+
return AnyValue::make_undefined();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
jspp::AnyValue jspp::AnyValue::set_own_property(const std::string &key, const AnyValue &value) const
|
|
64
|
+
{
|
|
65
|
+
switch (storage.type)
|
|
66
|
+
{
|
|
67
|
+
case JsType::Object:
|
|
68
|
+
return storage.object->set_property(key, value, *this);
|
|
69
|
+
case JsType::Array:
|
|
70
|
+
return storage.array->set_property(key, value, *this);
|
|
71
|
+
case JsType::Function:
|
|
72
|
+
return storage.function->set_property(key, value, *this);
|
|
73
|
+
case JsType::Promise:
|
|
74
|
+
return storage.promise->set_property(key, value, *this);
|
|
75
|
+
case JsType::Undefined:
|
|
76
|
+
throw Exception::make_exception("Cannot set properties of undefined (setting '" + key + "')", "TypeError");
|
|
77
|
+
case JsType::Null:
|
|
78
|
+
throw Exception::make_exception("Cannot set properties of null (setting '" + key + "')", "TypeError");
|
|
79
|
+
default:
|
|
80
|
+
return value;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
jspp::AnyValue jspp::AnyValue::set_own_property(uint32_t idx, const AnyValue &value) const
|
|
84
|
+
{
|
|
85
|
+
if (storage.type == JsType::Array)
|
|
86
|
+
{
|
|
87
|
+
return storage.array->set_property(idx, value);
|
|
88
|
+
}
|
|
89
|
+
return set_own_property(std::to_string(idx), value);
|
|
90
|
+
}
|
|
91
|
+
jspp::AnyValue jspp::AnyValue::set_own_property(const AnyValue &key, const AnyValue &value) const
|
|
92
|
+
{
|
|
93
|
+
if (key.storage.type == JsType::Number && storage.type == JsType::Array)
|
|
94
|
+
{
|
|
95
|
+
return storage.array->set_property(key.storage.number, value);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// If the key is a Symbol, use its internal key string
|
|
99
|
+
if (key.storage.type == JsType::Symbol)
|
|
100
|
+
return set_own_property(key.storage.symbol->key, value);
|
|
101
|
+
|
|
102
|
+
return set_own_property(key.to_std_string(), value);
|
|
103
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
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
|
+
|
|
11
|
+
inline void AnyValue::define_data_property(const std::string &key, const AnyValue &value)
|
|
12
|
+
{
|
|
13
|
+
if (is_object())
|
|
14
|
+
{
|
|
15
|
+
storage.object->props[key] = value;
|
|
16
|
+
}
|
|
17
|
+
else if (is_function())
|
|
18
|
+
{
|
|
19
|
+
storage.function->props[key] = value;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
inline void AnyValue::define_data_property(const AnyValue &key, const AnyValue &value)
|
|
24
|
+
{
|
|
25
|
+
if (key.is_symbol())
|
|
26
|
+
define_data_property(key.as_symbol()->key, value);
|
|
27
|
+
else
|
|
28
|
+
define_data_property(key.to_std_string(), value);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
inline void AnyValue::define_data_property(const std::string &key, const AnyValue &value, bool writable, bool enumerable, bool configurable)
|
|
32
|
+
{
|
|
33
|
+
define_data_property(key, AnyValue::make_data_descriptor(value, writable, enumerable, configurable));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
inline void AnyValue::define_getter(const std::string &key, const AnyValue &getter)
|
|
37
|
+
{
|
|
38
|
+
if (is_object())
|
|
39
|
+
{
|
|
40
|
+
auto &props = storage.object->props;
|
|
41
|
+
auto it = props.find(key);
|
|
42
|
+
if (it != props.end() && it->second.is_accessor_descriptor())
|
|
43
|
+
{
|
|
44
|
+
auto desc = it->second.as_accessor_descriptor();
|
|
45
|
+
desc->get = [getter](const AnyValue &thisVal, const std::vector<AnyValue> &args) -> AnyValue
|
|
46
|
+
{
|
|
47
|
+
return getter.as_function()->call(thisVal, args);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
else
|
|
51
|
+
{
|
|
52
|
+
auto getFunc = [getter](const AnyValue &thisVal, const std::vector<AnyValue> &args) -> AnyValue
|
|
53
|
+
{
|
|
54
|
+
return getter.as_function()->call(thisVal, args);
|
|
55
|
+
};
|
|
56
|
+
props[key] = AnyValue::make_accessor_descriptor(getFunc, std::nullopt, true, true);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else if (is_function())
|
|
60
|
+
{
|
|
61
|
+
auto &props = storage.function->props;
|
|
62
|
+
auto it = props.find(key);
|
|
63
|
+
if (it != props.end() && it->second.is_accessor_descriptor())
|
|
64
|
+
{
|
|
65
|
+
auto desc = it->second.as_accessor_descriptor();
|
|
66
|
+
desc->get = [getter](const AnyValue &thisVal, const std::vector<AnyValue> &args) -> AnyValue
|
|
67
|
+
{
|
|
68
|
+
return getter.as_function()->call(thisVal, args);
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
else
|
|
72
|
+
{
|
|
73
|
+
auto getFunc = [getter](const AnyValue &thisVal, const std::vector<AnyValue> &args) -> AnyValue
|
|
74
|
+
{
|
|
75
|
+
return getter.as_function()->call(thisVal, args);
|
|
76
|
+
};
|
|
77
|
+
props[key] = AnyValue::make_accessor_descriptor(getFunc, std::nullopt, true, true);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
inline void AnyValue::define_getter(const AnyValue &key, const AnyValue &getter)
|
|
83
|
+
{
|
|
84
|
+
if (key.is_symbol())
|
|
85
|
+
define_getter(key.as_symbol()->key, getter);
|
|
86
|
+
else
|
|
87
|
+
define_getter(key.to_std_string(), getter);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
inline void AnyValue::define_setter(const std::string &key, const AnyValue &setter)
|
|
91
|
+
{
|
|
92
|
+
if (is_object())
|
|
93
|
+
{
|
|
94
|
+
auto &props = storage.object->props;
|
|
95
|
+
auto it = props.find(key);
|
|
96
|
+
if (it != props.end() && it->second.is_accessor_descriptor())
|
|
97
|
+
{
|
|
98
|
+
auto desc = it->second.as_accessor_descriptor();
|
|
99
|
+
desc->set = [setter](const AnyValue &thisVal, const std::vector<AnyValue> &args) -> AnyValue
|
|
100
|
+
{
|
|
101
|
+
if (args.empty())
|
|
102
|
+
return AnyValue::make_undefined();
|
|
103
|
+
return setter.as_function()->call(thisVal, args);
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
else
|
|
107
|
+
{
|
|
108
|
+
auto setFunc = [setter](const AnyValue &thisVal, const std::vector<AnyValue> &args) -> AnyValue
|
|
109
|
+
{
|
|
110
|
+
if (args.empty())
|
|
111
|
+
return AnyValue::make_undefined();
|
|
112
|
+
return setter.as_function()->call(thisVal, args);
|
|
113
|
+
};
|
|
114
|
+
props[key] = AnyValue::make_accessor_descriptor(std::nullopt, setFunc, true, true);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else if (is_function())
|
|
118
|
+
{
|
|
119
|
+
auto &props = storage.function->props;
|
|
120
|
+
auto it = props.find(key);
|
|
121
|
+
if (it != props.end() && it->second.is_accessor_descriptor())
|
|
122
|
+
{
|
|
123
|
+
auto desc = it->second.as_accessor_descriptor();
|
|
124
|
+
desc->set = [setter](const AnyValue &thisVal, const std::vector<AnyValue> &args) -> AnyValue
|
|
125
|
+
{
|
|
126
|
+
if (args.empty())
|
|
127
|
+
return AnyValue::make_undefined();
|
|
128
|
+
return setter.as_function()->call(thisVal, args);
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
else
|
|
132
|
+
{
|
|
133
|
+
auto setFunc = [setter](const AnyValue &thisVal, const std::vector<AnyValue> &args) -> AnyValue
|
|
134
|
+
{
|
|
135
|
+
if (args.empty())
|
|
136
|
+
return AnyValue::make_undefined();
|
|
137
|
+
return setter.as_function()->call(thisVal, args);
|
|
138
|
+
};
|
|
139
|
+
props[key] = AnyValue::make_accessor_descriptor(std::nullopt, setFunc, true, true);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
inline void AnyValue::define_setter(const AnyValue &key, const AnyValue &setter)
|
|
145
|
+
{
|
|
146
|
+
if (key.is_symbol())
|
|
147
|
+
define_setter(key.as_symbol()->key, setter);
|
|
148
|
+
else
|
|
149
|
+
define_setter(key.to_std_string(), setter);
|
|
150
|
+
}
|
|
151
|
+
}
|