From 6c2ccf3869fb7a5bebf9a010afc0785d3cabba43 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sun, 14 Sep 2014 21:53:11 -0600 Subject: [PATCH] Various cleanups prefering lambda to bind --- include/chaiscript/dispatchkit/bootstrap.hpp | 3 +- .../dispatchkit/proxy_functions_detail.hpp | 31 ++----------------- .../chaiscript/language/chaiscript_engine.hpp | 6 ++-- .../chaiscript/language/chaiscript_eval.hpp | 28 +++++++++++------ 4 files changed, 25 insertions(+), 43 deletions(-) diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index 870d506..76058d4 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -496,8 +496,7 @@ namespace chaiscript m->add(fun(&print), "print_string"); m->add(fun(&println), "println_string"); - m->add(Proxy_Function(new dispatch::Dynamic_Proxy_Function(std::bind(&bind_function, std::placeholders::_1))), - "bind"); + m->add(Proxy_Function(new dispatch::Dynamic_Proxy_Function(&bind_function)), "bind"); m->add(fun(&shared_ptr_unconst_clone), "clone"); m->add(fun(&ptr_assign::type>), "="); diff --git a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp index fa725f8..b908d1f 100644 --- a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp @@ -53,29 +53,6 @@ namespace chaiscript { namespace detail { - template - struct Build_Param_Type_List; - - template - struct Build_Param_Type_List - { - static void build(std::vector &t_params) - { - t_params.push_back(chaiscript::detail::Get_Type_Info::get()); - Build_Param_Type_List::build(t_params); - } - }; - - // 0th case - template<> - struct Build_Param_Type_List<> - { - static void build(std::vector &) - { - } - }; - - /** * Used by Proxy_Function_Impl to return a list of all param types * it contains. @@ -83,12 +60,8 @@ namespace chaiscript template std::vector build_param_type_list(Ret (*)(Params...)) { - /// \todo this code was previously using { chaiscript::detail::Get_Type_Info::get()... } - /// but this seems to indicate another bug with MSVC's uniform initializer lists - std::vector params; - params.push_back(chaiscript::detail::Get_Type_Info::get()); - Build_Param_Type_List::build(params); - return params; + /// \note somehow this is responsible for a large part of the code generation + return { user_type(), user_type()... }; } diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index af01ce3..8b96ef5 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -345,8 +345,10 @@ namespace chaiscript m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::function_exists, std::ref(m_engine)), "function_exists"); m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_function_objects, std::ref(m_engine)), "get_functions"); m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_scripting_objects, std::ref(m_engine)), "get_objects"); - m_engine.add(Proxy_Function(new dispatch::Dynamic_Proxy_Function(std::bind(&chaiscript::detail::Dispatch_Engine::call_exists, std::ref(m_engine), std::placeholders::_1))), - "call_exists"); + m_engine.add(Proxy_Function(new dispatch::Dynamic_Proxy_Function( + [this](const std::vector &t_params) { + return m_engine.call_exists(t_params); + })), "call_exists"); m_engine.add(fun &)>(std::bind(&chaiscript::dispatch::Proxy_Function_Base::operator(), std::placeholders::_1, std::placeholders::_2, std::ref(m_engine.conversions()))), "call"); m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_type_name, std::ref(m_engine)), "name"); diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index f40a9fc..b1ee795 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -732,9 +732,14 @@ namespace chaiscript numparams = 0; } - return Boxed_Value(Proxy_Function(new dispatch::Dynamic_Proxy_Function - (std::bind(chaiscript::eval::detail::eval_function, std::ref(t_ss), this->children.back(), t_param_names, std::placeholders::_1), - static_cast(numparams), this->children.back()))); + const auto &lambda_node = this->children.back(); + + return Boxed_Value(Proxy_Function(new dispatch::Dynamic_Proxy_Function( + [&t_ss, lambda_node, t_param_names](const std::vector &t_params) + { + return detail::eval_function(t_ss, lambda_node, t_param_names, t_params); + }, + static_cast(numparams), lambda_node))); } }; @@ -800,19 +805,22 @@ namespace chaiscript std::shared_ptr guard; if (guardnode) { guard = std::shared_ptr - (new dispatch::Dynamic_Proxy_Function(std::bind(chaiscript::eval::detail::eval_function, - std::ref(t_ss), guardnode, - t_param_names, std::placeholders::_1), static_cast(numparams), guardnode)); + (new dispatch::Dynamic_Proxy_Function([&t_ss, guardnode, t_param_names](const std::vector &t_params) + { + return detail::eval_function(t_ss, guardnode, t_param_names, t_params); + }, static_cast(numparams), guardnode)); } try { const std::string & l_function_name = this->children[0]->text; const std::string & l_annotation = this->annotation?this->annotation->text:""; + const auto & func_node = this->children.back(); t_ss.add(Proxy_Function - (new dispatch::Dynamic_Proxy_Function(std::bind(chaiscript::eval::detail::eval_function, - std::ref(t_ss), this->children.back(), - t_param_names, std::placeholders::_1), static_cast(numparams), this->children.back(), - l_annotation, guard)), l_function_name); + (new dispatch::Dynamic_Proxy_Function([&t_ss, guardnode, func_node, t_param_names](const std::vector &t_params) + { + return detail::eval_function(t_ss, func_node, t_param_names, t_params); + }, static_cast(numparams), this->children.back(), + l_annotation, guard)), l_function_name); } catch (const exception::reserved_word_error &e) { throw exception::eval_error("Reserved word used as function name '" + e.word() + "'");