diff --git a/include/chaiscript/dispatchkit/dynamic_object.hpp b/include/chaiscript/dispatchkit/dynamic_object.hpp index 0269088..e94e893 100644 --- a/include/chaiscript/dispatchkit/dynamic_object.hpp +++ b/include/chaiscript/dispatchkit/dynamic_object.hpp @@ -7,7 +7,6 @@ #ifndef CHAISCRIPT_DYNAMIC_OBJECT_HPP_ #define CHAISCRIPT_DYNAMIC_OBJECT_HPP_ -#include namespace chaiscript { @@ -66,16 +65,26 @@ namespace chaiscript class Dynamic_Object_Function : public Proxy_Function_Base { public: + Dynamic_Object_Function( + const std::string &t_type_name, + const Proxy_Function &t_func) + : Proxy_Function_Base(t_func->get_param_types()), + m_type_name(t_type_name), m_func(t_func) + { + assert( (t_func->get_arity() > 0 || t_func->get_arity() < 0) + && "Programming error, Dynamic_Object_Function must have at least one parameter (this)"); + } + Dynamic_Object_Function( const std::string &t_type_name, const Proxy_Function &t_func, - const boost::optional &t_ti = boost::optional()) + const Type_Info &t_ti) : Proxy_Function_Base(build_param_types(t_func->get_param_types(), t_ti)), - m_type_name(t_type_name), m_func(t_func), m_ti(t_ti) - { - assert( (t_func->get_arity() > 0 || t_func->get_arity() < 0) - && "Programming error, Dynamic_Object_Function must have at least one parameter (this)"); - } + m_type_name(t_type_name), m_func(t_func), m_ti(new Type_Info(t_ti)) + { + assert( (t_func->get_arity() > 0 || t_func->get_arity() < 0) + && "Programming error, Dynamic_Object_Function must have at least one parameter (this)"); + } virtual ~Dynamic_Object_Function() {} @@ -137,23 +146,18 @@ namespace chaiscript private: static std::vector build_param_types( - const std::vector &t_inner_types, boost::optional t_objectti) + const std::vector &t_inner_types, const Type_Info& t_objectti) { - if (t_objectti) - { - std::vector types(t_inner_types); + std::vector types(t_inner_types); - assert(types.size() > 1); - assert(types[1].bare_equal(user_type())); - types[1] = *t_objectti; - return types; - } else { - return t_inner_types; - } + assert(types.size() > 1); + assert(types[1].bare_equal(user_type())); + types[1] = t_objectti; + return types; } static bool dynamic_object_typename_match(const Boxed_Value &bv, const std::string &name, - const boost::optional &ti) + const std::shared_ptr &ti) { static Type_Info doti = user_type(); if (bv.get_type_info().bare_equal(doti)) @@ -176,7 +180,7 @@ namespace chaiscript } static bool dynamic_object_typename_match(const std::vector &bvs, const std::string &name, - const boost::optional &ti) + const std::shared_ptr &ti) { if (bvs.size() > 0) { @@ -188,7 +192,7 @@ namespace chaiscript std::string m_type_name; Proxy_Function m_func; - boost::optional m_ti; + std::shared_ptr m_ti; }; @@ -207,10 +211,10 @@ namespace chaiscript const Proxy_Function &t_func) : Proxy_Function_Base(build_type_list(t_func->get_param_types())), m_type_name(t_type_name), m_func(t_func) - { - assert( (t_func->get_arity() > 0 || t_func->get_arity() < 0) - && "Programming error, Dynamic_Object_Function must have at least one parameter (this)"); - } + { + assert( (t_func->get_arity() > 0 || t_func->get_arity() < 0) + && "Programming error, Dynamic_Object_Function must have at least one parameter (this)"); + } static std::vector build_type_list(const std::vector &tl) { diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index 356299a..b3b4b0c 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -1117,19 +1117,23 @@ namespace chaiscript } else { - boost::optional ti; try { - ti = t_ss.get_type(class_name); + // Do know type name + t_ss.add(Proxy_Function + (new dispatch::detail::Dynamic_Object_Function(class_name, 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)), t_ss.get_type(class_name))), function_name); } catch (const std::range_error &) { - // No biggie, the type name is just not known + // Do not know type name + t_ss.add(Proxy_Function + (new dispatch::detail::Dynamic_Object_Function(class_name, 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)))), function_name); } - t_ss.add(Proxy_Function - (new dispatch::detail::Dynamic_Object_Function(class_name, 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)), ti)), function_name); - } } catch (const exception::reserved_word_error &e) { diff --git a/src/multithreaded.cpp b/src/multithreaded.cpp index e0d7767..27e3e66 100644 --- a/src/multithreaded.cpp +++ b/src/multithreaded.cpp @@ -9,7 +9,7 @@ #include #include -#include +#include void do_work(chaiscript::ChaiScript &c) { @@ -20,21 +20,21 @@ void do_work(chaiscript::ChaiScript &c) } int main(int argc, char *argv[]) { - std::string input; - chaiscript::ChaiScript chai; + std::string input; + chaiscript::ChaiScript chai; - //chai.add_shared_object(chaiscript::Boxed_Value(10000), "num_iterations"); + //chai.add_shared_object(chaiscript::Boxed_Value(10000), "num_iterations"); - std::vector > threads; + std::vector > threads; - for (int i = 0; i < argc - 1; ++i) - { - threads.push_back(std::shared_ptr(new boost::thread(std::bind(do_work, std::ref(chai))))); - } + for (int i = 0; i < argc - 1; ++i) + { + threads.push_back(std::shared_ptr(new std::thread(std::bind(do_work, std::ref(chai))))); + } - for (int i = 0; i < argc - 1; ++i) - { - threads[i]->join(); - } + for (int i = 0; i < argc - 1; ++i) + { + threads[i]->join(); + } }