mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2026-01-01 03:12:23 +08:00
Handful for C++17 things
This commit is contained in:
parent
f9a1784b9b
commit
e6a6a20eb6
@ -82,10 +82,7 @@ namespace chaiscript
|
||||
{
|
||||
try {
|
||||
std::vector<Boxed_Value>::size_type i = 0;
|
||||
(void)i;
|
||||
(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)...};
|
||||
( boxed_cast<Params>(params[i++], &t_conversions), ... );
|
||||
return true;
|
||||
} catch (const exception::bad_boxed_cast &) {
|
||||
return false;
|
||||
@ -111,23 +108,12 @@ namespace chaiscript
|
||||
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)
|
||||
{
|
||||
return Handle_Return<Ret>::handle(call_func(sig, std::index_sequence_for<Params...>{}, f, params, t_conversions));
|
||||
}
|
||||
|
||||
template<typename Callable, typename ... Params>
|
||||
Boxed_Value call_func(const chaiscript::dispatch::detail::Function_Signature<void (Params...)> &sig, const Callable &f,
|
||||
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
|
||||
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();
|
||||
} else {
|
||||
return Handle_Return<Ret>::handle(call_func(sig, std::index_sequence_for<Params...>{}, f, params, t_conversions));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -57,8 +57,9 @@ namespace chaiscript
|
||||
chaiscript::detail::Dispatch_State state(t_ss);
|
||||
|
||||
const Boxed_Value *thisobj = [&]() -> const Boxed_Value *{
|
||||
auto &stack = t_ss.get_stack_data(state.stack_holder()).back();
|
||||
if (!stack.empty() && stack.back().first == "__this") {
|
||||
if (auto &stack = t_ss.get_stack_data(state.stack_holder()).back();
|
||||
!stack.empty() && stack.back().first == "__this")
|
||||
{
|
||||
return &stack.back().second;
|
||||
} else if (!t_vals.empty()) {
|
||||
return &t_vals[0];
|
||||
@ -71,8 +72,8 @@ namespace chaiscript
|
||||
if (thisobj && !has_this_capture) { state.add_object("this", *thisobj); }
|
||||
|
||||
if (t_locals) {
|
||||
for (const auto &local : *t_locals) {
|
||||
state.add_object(local.first, local.second);
|
||||
for (const auto &[name, value] : *t_locals) {
|
||||
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>> retval;
|
||||
retval.reserve(children.size());
|
||||
for (auto &&child : children) {
|
||||
for (auto &child : children) {
|
||||
retval.emplace_back(*child);
|
||||
}
|
||||
|
||||
@ -868,9 +869,9 @@ namespace chaiscript
|
||||
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){
|
||||
uint_fast32_t hint = t_hint;
|
||||
auto funs = t_ss->get_function(t_name, hint);
|
||||
if (funs.first != hint) { t_hint = uint_fast32_t(funs.first); }
|
||||
return std::move(funs.second);
|
||||
auto [funs_loc, funs] = t_ss->get_function(t_name, hint);
|
||||
if (funs_loc != hint) { t_hint = uint_fast32_t(funs_loc); }
|
||||
return std::move(funs);
|
||||
};
|
||||
|
||||
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()) {
|
||||
vec.reserve(this->children[0]->children.size());
|
||||
for (const auto &child : this->children[0]->children) {
|
||||
auto obj = child->eval(t_ss);
|
||||
if (!obj.is_return_value()) {
|
||||
if (auto obj = child->eval(t_ss);
|
||||
!obj.is_return_value()) {
|
||||
vec.push_back(t_ss->call_function("clone", m_loc, {obj}, t_ss.conversions()));
|
||||
} else {
|
||||
vec.push_back(std::move(obj));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user