mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2026-02-06 17:59:56 +08:00
Handful for C++17 things
This commit is contained in:
parent
f9a1784b9b
commit
e6a6a20eb6
@ -82,10 +82,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
std::vector<Boxed_Value>::size_type i = 0;
|
std::vector<Boxed_Value>::size_type i = 0;
|
||||||
(void)i;
|
( boxed_cast<Params>(params[i++], &t_conversions), ... );
|
||||||
(void)params; (void)t_conversions;
|
|
||||||
// this is ok because the order of evaluation of initializer lists is well defined
|
|
||||||
(void)std::initializer_list<int>{(boxed_cast<Params>(params[i++], &t_conversions), 0)...};
|
|
||||||
return true;
|
return true;
|
||||||
} catch (const exception::bad_boxed_cast &) {
|
} catch (const exception::bad_boxed_cast &) {
|
||||||
return false;
|
return false;
|
||||||
@ -111,23 +108,12 @@ namespace chaiscript
|
|||||||
Boxed_Value call_func(const chaiscript::dispatch::detail::Function_Signature<Ret (Params...)> &sig, const Callable &f,
|
Boxed_Value call_func(const chaiscript::dispatch::detail::Function_Signature<Ret (Params...)> &sig, const Callable &f,
|
||||||
const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions)
|
const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions)
|
||||||
{
|
{
|
||||||
return Handle_Return<Ret>::handle(call_func(sig, std::index_sequence_for<Params...>{}, f, params, t_conversions));
|
if constexpr (std::is_same_v<Ret, void>) {
|
||||||
}
|
call_func(sig, std::index_sequence_for<Params...>{}, f, params, t_conversions);
|
||||||
|
return Handle_Return<void>::handle();
|
||||||
template<typename Callable, typename ... Params>
|
} else {
|
||||||
Boxed_Value call_func(const chaiscript::dispatch::detail::Function_Signature<void (Params...)> &sig, const Callable &f,
|
return Handle_Return<Ret>::handle(call_func(sig, std::index_sequence_for<Params...>{}, f, params, t_conversions));
|
||||||
const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions)
|
}
|
||||||
{
|
|
||||||
call_func(sig, std::index_sequence_for<Params...>{}, f, params, t_conversions);
|
|
||||||
#ifdef CHAISCRIPT_MSVC
|
|
||||||
#pragma warning(push)
|
|
||||||
#pragma warning(disable : 4702)
|
|
||||||
#endif
|
|
||||||
// MSVC is reporting that this is unreachable code - and it's wrong.
|
|
||||||
return Handle_Return<void>::handle();
|
|
||||||
#ifdef CHAISCRIPT_MSVC
|
|
||||||
#pragma warning(pop)
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,8 +57,9 @@ namespace chaiscript
|
|||||||
chaiscript::detail::Dispatch_State state(t_ss);
|
chaiscript::detail::Dispatch_State state(t_ss);
|
||||||
|
|
||||||
const Boxed_Value *thisobj = [&]() -> const Boxed_Value *{
|
const Boxed_Value *thisobj = [&]() -> const Boxed_Value *{
|
||||||
auto &stack = t_ss.get_stack_data(state.stack_holder()).back();
|
if (auto &stack = t_ss.get_stack_data(state.stack_holder()).back();
|
||||||
if (!stack.empty() && stack.back().first == "__this") {
|
!stack.empty() && stack.back().first == "__this")
|
||||||
|
{
|
||||||
return &stack.back().second;
|
return &stack.back().second;
|
||||||
} else if (!t_vals.empty()) {
|
} else if (!t_vals.empty()) {
|
||||||
return &t_vals[0];
|
return &t_vals[0];
|
||||||
@ -71,8 +72,8 @@ namespace chaiscript
|
|||||||
if (thisobj && !has_this_capture) { state.add_object("this", *thisobj); }
|
if (thisobj && !has_this_capture) { state.add_object("this", *thisobj); }
|
||||||
|
|
||||||
if (t_locals) {
|
if (t_locals) {
|
||||||
for (const auto &local : *t_locals) {
|
for (const auto &[name, value] : *t_locals) {
|
||||||
state.add_object(local.first, local.second);
|
state.add_object(name, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +110,7 @@ namespace chaiscript
|
|||||||
std::vector<std::reference_wrapper<AST_Node>> get_children() const final {
|
std::vector<std::reference_wrapper<AST_Node>> get_children() const final {
|
||||||
std::vector<std::reference_wrapper<AST_Node>> retval;
|
std::vector<std::reference_wrapper<AST_Node>> retval;
|
||||||
retval.reserve(children.size());
|
retval.reserve(children.size());
|
||||||
for (auto &&child : children) {
|
for (auto &child : children) {
|
||||||
retval.emplace_back(*child);
|
retval.emplace_back(*child);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -868,9 +869,9 @@ namespace chaiscript
|
|||||||
Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{
|
Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{
|
||||||
const auto get_function = [&t_ss](const std::string &t_name, auto &t_hint){
|
const auto get_function = [&t_ss](const std::string &t_name, auto &t_hint){
|
||||||
uint_fast32_t hint = t_hint;
|
uint_fast32_t hint = t_hint;
|
||||||
auto funs = t_ss->get_function(t_name, hint);
|
auto [funs_loc, funs] = t_ss->get_function(t_name, hint);
|
||||||
if (funs.first != hint) { t_hint = uint_fast32_t(funs.first); }
|
if (funs_loc != hint) { t_hint = uint_fast32_t(funs_loc); }
|
||||||
return std::move(funs.second);
|
return std::move(funs);
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto call_function = [&t_ss](const auto &t_funcs, const Boxed_Value &t_param) {
|
const auto call_function = [&t_ss](const auto &t_funcs, const Boxed_Value &t_param) {
|
||||||
@ -1056,8 +1057,8 @@ namespace chaiscript
|
|||||||
if (!this->children.empty()) {
|
if (!this->children.empty()) {
|
||||||
vec.reserve(this->children[0]->children.size());
|
vec.reserve(this->children[0]->children.size());
|
||||||
for (const auto &child : this->children[0]->children) {
|
for (const auto &child : this->children[0]->children) {
|
||||||
auto obj = child->eval(t_ss);
|
if (auto obj = child->eval(t_ss);
|
||||||
if (!obj.is_return_value()) {
|
!obj.is_return_value()) {
|
||||||
vec.push_back(t_ss->call_function("clone", m_loc, {obj}, t_ss.conversions()));
|
vec.push_back(t_ss->call_function("clone", m_loc, {obj}, t_ss.conversions()));
|
||||||
} else {
|
} else {
|
||||||
vec.push_back(std::move(obj));
|
vec.push_back(std::move(obj));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user