diff --git a/include/chaiscript/chaiscript.hpp b/include/chaiscript/chaiscript.hpp index 3733e19..70b27e5 100644 --- a/include/chaiscript/chaiscript.hpp +++ b/include/chaiscript/chaiscript.hpp @@ -20,7 +20,7 @@ #include "dispatchkit/dispatchkit.hpp" #include "dispatchkit/bootstrap.hpp" #include "dispatchkit/bootstrap_stl.hpp" - +#include "dispatchkit/function_call.hpp" namespace chaiscript { /** @@ -113,10 +113,10 @@ namespace chaiscript * Special type for returned values */ struct Return_Value { - dispatchkit::Boxed_Value retval; + Boxed_Value retval; TokenPtr location; - Return_Value(const dispatchkit::Boxed_Value &return_value, const TokenPtr where) : retval(return_value), location(where) { } + Return_Value(const Boxed_Value &return_value, const TokenPtr where) : retval(return_value), location(where) { } }; /** diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index 84d1290..b4a59b8 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -10,7 +10,7 @@ #include "dispatchkit.hpp" #include "register_function.hpp" -namespace dispatchkit +namespace chaiscript { /** * Set of helper functions for common operators @@ -215,7 +215,7 @@ namespace dispatchkit template void add_oper_equals(Dispatch_Engine &s) { - register_function(s, &equals, "="); + s.add(fun(&equals), "="); } /** @@ -224,7 +224,7 @@ namespace dispatchkit template void add_oper_add(Dispatch_Engine &s) { - register_function(s, &add, "+"); + s.add(fun(&add), "+"); } /** @@ -233,7 +233,7 @@ namespace dispatchkit template void add_oper_add_equals(Dispatch_Engine &s) { - register_function(s, &addsequal, "+="); + s.add(fun(&addsequal), "+="); } /** @@ -242,7 +242,7 @@ namespace dispatchkit template void add_oper_subtract(Dispatch_Engine &s) { - register_function(s, &subtract, "-"); + s.add(fun(&subtract), "-"); } /** @@ -251,7 +251,7 @@ namespace dispatchkit template void add_oper_divide(Dispatch_Engine &s) { - register_function(s, ÷, "/"); + s.add(fun(÷), "/"); } /** @@ -260,7 +260,7 @@ namespace dispatchkit template void add_oper_multiply(Dispatch_Engine &s) { - register_function(s, &multiply, "*"); + s.add(fun(&multiply), "*"); } /** @@ -269,7 +269,7 @@ namespace dispatchkit template void add_oper_not_equals(Dispatch_Engine &s) { - register_function(s, ¬_equals, "!="); + s.add(fun(¬_equals), "!="); } /** @@ -278,7 +278,7 @@ namespace dispatchkit template void add_oper_assign_overload(Dispatch_Engine &s) { - register_function(s, &assign, "="); + s.add(fun(&assign), "="); } @@ -288,7 +288,7 @@ namespace dispatchkit template void add_oper_assign(Dispatch_Engine &s) { - register_function(s, &assign, "="); + s.add(fun(&assign), "="); } @@ -298,7 +298,7 @@ namespace dispatchkit template void add_oper_assign_pod(Dispatch_Engine &s) { - register_function(s, &assign_pod, "="); + s.add(fun(&assign_pod), "="); } @@ -308,7 +308,7 @@ namespace dispatchkit template void add_oper_less_than(Dispatch_Engine &s) { - register_function(s, &less_than, "<"); + s.add(fun(&less_than), "<"); } /** @@ -317,7 +317,7 @@ namespace dispatchkit template void add_oper_greater_than(Dispatch_Engine &s) { - register_function(s, &greater_than, ">"); + s.add(fun(&greater_than), ">"); } /** @@ -326,7 +326,7 @@ namespace dispatchkit template void add_oper_less_than_equals(Dispatch_Engine &s) { - register_function(s, &less_than_equals, "<="); + s.add(fun(&less_than_equals), "<="); } /** @@ -335,7 +335,7 @@ namespace dispatchkit template void add_oper_greater_than_equals(Dispatch_Engine &s) { - register_function(s, &greater_than_equals, ">="); + s.add(fun(&greater_than_equals), ">="); } /** @@ -345,12 +345,12 @@ namespace dispatchkit template void add_opers_comparison_overload(Dispatch_Engine &s) { - register_function(s, &equals, "=="); - register_function(s, ¬_equals, "!="); - register_function(s, &less_than, "<"); - register_function(s, &greater_than, ">"); - register_function(s, &less_than_equals, "<="); - register_function(s, &greater_than_equals, ">="); + s.add(fun(&equals), "=="); + s.add(fun(¬_equals), "!="); + s.add(fun(&less_than), "<"); + s.add(fun(&greater_than), ">"); + s.add(fun(&less_than_equals), "<="); + s.add(fun(&greater_than_equals), ">="); } /** @@ -372,18 +372,18 @@ namespace dispatchkit template void add_opers_arithmetic_overload(Dispatch_Engine &s) { - register_function(s, &add, "+"); - register_function(s, &subtract, "-"); - register_function(s, ÷, "/"); - register_function(s, &multiply, "*"); - register_function(s, ×equal, "*="); - register_function(s, ÷sequal, "/="); - register_function(s, &subtractsequal, "-="); - register_function(s, &addsequal, "+="); - register_function(s, &prefixincrement, "++"); - register_function(s, &prefixdecrement, "--"); - register_function(s, &prefixnegate, "-"); - register_function(s, &prefixnot, "!"); + s.add(fun(&add), "+"); + s.add(fun(&subtract), "-"); + s.add(fun(÷), "/"); + s.add(fun(&multiply), "*"); + s.add(fun(×equal), "*="); + s.add(fun(÷sequal), "/="); + s.add(fun(&subtractsequal), "-="); + s.add(fun(&addsequal), "+="); + s.add(fun(&prefixincrement), "++"); + s.add(fun(&prefixdecrement), "--"); + s.add(fun(&prefixnegate), "-"); + s.add(fun(&prefixnot), "!"); } /** @@ -393,10 +393,10 @@ namespace dispatchkit template void add_opers_arithmetic_modify_pod(Dispatch_Engine &s) { - register_function(s, ×equal_pod, "*="); - register_function(s, ÷sequal_pod, "/="); - register_function(s, &subtractsequal_pod, "-="); - register_function(s, &addsequal_pod, "+="); + s.add(fun(×equal_pod), "*="); + s.add(fun(÷sequal_pod), "/="); + s.add(fun(&subtractsequal_pod), "-="); + s.add(fun(&addsequal_pod), "+="); } /** @@ -407,8 +407,8 @@ namespace dispatchkit template void add_copy_constructor(Dispatch_Engine &s, const std::string &type) { - s.register_function(build_constructor(), type); - s.register_function(build_constructor(), "clone"); + s.add(constructor(), type); + s.add(constructor(), "clone"); } /** @@ -417,7 +417,7 @@ namespace dispatchkit template void add_basic_constructors(Dispatch_Engine &s, const std::string &type) { - s.register_function(build_constructor(), type); + s.add(constructor(), type); add_copy_constructor(s, type); } @@ -427,7 +427,7 @@ namespace dispatchkit template void add_construct_pod(Dispatch_Engine &s, const std::string &type) { - register_function(s, &construct_pod, type); + s.add(fun(&construct_pod), type); } /** @@ -437,7 +437,7 @@ namespace dispatchkit template void add_constructor_overload(Dispatch_Engine &s, const std::string &type) { - s.register_function(build_constructor(), type); + s.add(constructor(), type); } /** @@ -489,22 +489,22 @@ namespace dispatchkit template void bootstrap_pod_type(Dispatch_Engine &s, const std::string &name) { - s.register_type(name); + s.add(type_(), name); add_basic_constructors(s, name); add_oper_assign(s); add_oper_assign_pod(s); add_construct_pod(s, name); add_opers_arithmetic(s); add_opers_arithmetic_modify_pod(s); - register_function(s, &to_string, "to_string"); - register_function(s, &parse_string, "to_" + name); + s.add(fun(&to_string), "to_string"); + s.add(fun(&parse_string), "to_" + name); } /** * "clone" function for a shared_ptr type. This is used in the case * where you do not want to make a deep copy of an object during cloning * but want to instead maintain the shared_ptr. It is needed internally - * for handling of boost::shared_ptr object (that is, + * for handling of Proxy_Function object (that is, * function variables. */ template @@ -560,12 +560,12 @@ namespace dispatchkit */ static void add_opers_comparison_pod(Dispatch_Engine &s) { - register_function(s, &equals, "=="); - register_function(s, ¬_equals, "!="); - register_function(s, &less_than, "<"); - register_function(s, &greater_than, ">"); - register_function(s, &less_than_equals, "<="); - register_function(s, &greater_than_equals, ">="); + s.add(fun(&equals), "=="); + s.add(fun(¬_equals), "!="); + s.add(fun(&less_than), "<"); + s.add(fun(&greater_than), ">"); + s.add(fun(&less_than_equals), "<="); + s.add(fun(&greater_than_equals), ">="); } /** @@ -573,10 +573,10 @@ namespace dispatchkit */ static void add_opers_arithmetic_pod(Dispatch_Engine &s) { - register_function(s, &add, "+"); - register_function(s, &subtract, "-"); - register_function(s, ÷, "/"); - register_function(s, &multiply, "*"); + s.add(fun(&add), "+"); + s.add(fun(&subtract), "-"); + s.add(fun(÷), "/"); + s.add(fun(&multiply), "*"); } /** @@ -611,9 +611,9 @@ namespace dispatchkit throw arity_error(params.size(), 2); } - boost::shared_ptr f = boxed_cast >(params[0]); + Proxy_Function f = boxed_cast(params[0]); - return Boxed_Value(boost::shared_ptr(new Bound_Function(f, + return Boxed_Value(Proxy_Function(new Bound_Function(f, std::vector(params.begin() + 1, params.end())))); } @@ -628,7 +628,7 @@ namespace dispatchkit throw arity_error(params.size(), 1); } - boost::shared_ptr f = boxed_cast >(params[0]); + Proxy_Function f = boxed_cast(params[0]); return Boxed_Value(f->types_match(std::vector(params.begin() + 1, params.end()))); } @@ -638,19 +638,19 @@ namespace dispatchkit */ static void bootstrap(Dispatch_Engine &s) { - s.register_type("void"); - s.register_type("bool"); - s.register_type("Object"); - s.register_type("PODObject"); - s.register_type("function"); + s.add(type_(), "void"); + s.add(type_(), "bool"); + s.add(type_(), "Object"); + s.add(type_(), "PODObject"); + s.add(type_(), "function"); add_basic_constructors(s, "bool"); add_oper_assign(s); add_oper_assign(s); - register_function(s, &to_string, "internal_to_string"); - register_function(s, &to_string, "internal_to_string"); - register_function(s, &unknown_assign, "="); + s.add(fun(&to_string), "internal_to_string"); + s.add(fun(&to_string), "internal_to_string"); + s.add(fun(&unknown_assign), "="); bootstrap_pod_type(s, "double"); bootstrap_pod_type(s, "int"); @@ -660,26 +660,26 @@ namespace dispatchkit add_opers_comparison_pod(s); add_opers_arithmetic_pod(s); - register_function(s, &modulus, "%"); + s.add(fun(&modulus), "%"); - register_function(s, &print, "print_string"); - register_function(s, &println, "println_string"); + s.add(fun(&print), "print_string"); + s.add(fun(&println), "println_string"); - s.register_function(boost::function(boost::bind(&dump_system, boost::ref(s))), "dump_system"); - s.register_function(boost::function(boost::bind(&dump_object, _1, boost::ref(s))), "dump_object"); - s.register_function(boost::function(boost::bind(&is_type, boost::ref(s), _2, _1)), + s.add(fun(boost::function(boost::bind(&dump_system, boost::ref(s)))), "dump_system"); + s.add(fun(boost::function(boost::bind(&dump_object, _1, boost::ref(s)))), "dump_object"); + s.add(fun(boost::function(boost::bind(&is_type, boost::ref(s), _2, _1))), "is_type"); - s.register_function(boost::shared_ptr(new Dynamic_Proxy_Function(boost::bind(&bind_function, _1))), + s.add(Proxy_Function(new Dynamic_Proxy_Function(boost::bind(&bind_function, _1))), "bind"); - register_function(s, &shared_ptr_clone, "clone"); - register_function(s, &ptr_assign, "="); + s.add(fun(&shared_ptr_clone), "clone"); + s.add(fun(&ptr_assign), "="); - s.register_function(boost::shared_ptr(new Dynamic_Proxy_Function(boost::bind(&call_exists, _1))), + s.add(Proxy_Function(new Dynamic_Proxy_Function(boost::bind(&call_exists, _1))), "call_exists"); - register_function(s, &type_match, "type_match"); + s.add(fun(&type_match), "type_match"); } }; } diff --git a/include/chaiscript/dispatchkit/bootstrap_stl.hpp b/include/chaiscript/dispatchkit/bootstrap_stl.hpp index c90c1ec..4a3f0ce 100644 --- a/include/chaiscript/dispatchkit/bootstrap_stl.hpp +++ b/include/chaiscript/dispatchkit/bootstrap_stl.hpp @@ -17,7 +17,7 @@ #include "register_function.hpp" -namespace dispatchkit +namespace chaiscript { /** * Input_Range, based on the D concept of ranges. @@ -76,24 +76,22 @@ namespace dispatchkit template void bootstrap_input_range(Dispatch_Engine &system, const std::string &type) { - system.register_type >(type+"_Range"); - system.register_type(type+"_Iterator"); + system.add(type_ >(), type + "_Range"); + system.add(type_(), type+"_Iterator"); - system.register_function(build_constructor, ContainerType &>(), "range"); - system.register_function(build_constructor, - typename ContainerType::iterator>(), "range"); + system.add(constructor (ContainerType &)>(), "range"); + system.add(constructor (typename ContainerType::iterator)>(), "range"); typedef std::pair ItrPair; - system.register_function(build_constructor, - const ItrPair &>(), "range"); - system.register_type(type+"_Iterator_Pair"); + system.add(constructor (const ItrPair &)>(), "range"); + system.add(type_(), type+"_Iterator_Pair"); - register_function(system, &Input_Range::empty, "empty"); - register_function(system, &Input_Range::pop_front, "pop_front"); - register_function(system, &Input_Range::front, "front"); - system.register_function(build_constructor, const Input_Range &>(), "clone"); + system.add(fun(&Input_Range::empty), "empty"); + system.add(fun(&Input_Range::pop_front), "pop_front"); + system.add(fun(&Input_Range::front), "front"); + system.add(constructor (const Input_Range &)>(), "clone"); } /** @@ -117,10 +115,10 @@ namespace dispatchkit //In the interest of runtime safety for the system, we prefer the at() method for [] access, //to throw an exception in an out of bounds condition. - system.register_function( - boost::function(indexoper(&ContainerType::at)), "[]"); - system.register_function( - boost::function(indexoper(&ContainerType::operator[])), "at"); + system.add( + fun(boost::function(indexoper(&ContainerType::at))), "[]"); + system.add( + fun(boost::function(indexoper(&ContainerType::operator[]))), "at"); } @@ -144,9 +142,9 @@ namespace dispatchkit { bootstrap_assignable(system, type); - register_function(system, &ContainerType::size, "size"); - register_function(system, &ContainerType::max_size, "max_size"); - register_function(system, &ContainerType::empty, "empty"); + system.add(fun(&ContainerType::size), "size"); + system.add(fun(&ContainerType::max_size), "max_size"); + system.add(fun(&ContainerType::empty), "empty"); } /** @@ -167,7 +165,7 @@ namespace dispatchkit template void bootstrap_default_constructible(Dispatch_Engine &system, const std::string &type) { - system.register_function(build_constructor(), type); + system.add(constructor(), type); } /** @@ -224,8 +222,8 @@ namespace dispatchkit insert_name = "insert_at"; } - register_function(system, &insert_at, insert_name); - register_function(system, &erase_at, "erase_at"); + system.add(fun(&insert_at), insert_name); + system.add(fun(&erase_at), "erase_at"); } /** @@ -240,7 +238,7 @@ namespace dispatchkit typedef typename ContainerType::reference (ContainerType::*backptr)(); - register_function(system, (backptr(&ContainerType::back)), "back"); + system.add(fun(backptr(&ContainerType::back)), "back"); std::string push_back_name; if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value)) @@ -250,8 +248,8 @@ namespace dispatchkit push_back_name = "push_back"; } - register_function(system, &ContainerType::push_back, push_back_name); - register_function(system, &ContainerType::pop_back, "pop_back"); + system.add(fun(&ContainerType::push_back), push_back_name); + system.add(fun(&ContainerType::pop_back), "pop_back"); } /** @@ -261,7 +259,7 @@ namespace dispatchkit template void bootstrap_vector(Dispatch_Engine &system, const std::string &type) { - system.register_type(type); + system.add(type_(), type); bootstrap_random_access_container(system, type); bootstrap_back_insertion_sequence(system, type); } @@ -284,15 +282,15 @@ namespace dispatchkit template void bootstrap_pair(Dispatch_Engine &system, const std::string &type) { - system.register_type(type); + system.add(type_(), type); - register_member(system, &PairType::first, "first"); - register_member(system, &PairType::second, "second"); + system.add(fun(&PairType::first), "first"); + system.add(fun(&PairType::second), "second"); - system.register_function(build_constructor(), type); - system.register_function(build_constructor(), type); - system.register_function(build_constructor(), "clone"); - system.register_function(build_constructor(), type); + system.add(constructor(), type); + system.add(constructor(), type); + system.add(constructor(), "clone"); + system.add(constructor(), type); } @@ -315,7 +313,7 @@ namespace dispatchkit void bootstrap_unique_associative_container(Dispatch_Engine &system, const std::string &type) { bootstrap_associative_container(system, type); - register_function(system, &ContainerType::count, "count"); + system.add(fun(&ContainerType::count), "count"); } /** @@ -330,7 +328,7 @@ namespace dispatchkit bootstrap_reversible_container(system, type); bootstrap_associative_container(system, type); - register_function(system, eq_range(&ContainerType::equal_range), "equal_range"); + system.add(fun(eq_range(&ContainerType::equal_range)), "equal_range"); } /** @@ -351,8 +349,8 @@ namespace dispatchkit template void bootstrap_map(Dispatch_Engine &system, const std::string &type) { - system.register_type(type); - register_function(system, &MapType::operator[], "[]"); + system.add(type_(), type); + system.add(fun(&MapType::operator[]), "[]"); bootstrap_unique_sorted_associative_container(system, type); bootstrap_pair_associative_container(system, type); } @@ -364,19 +362,19 @@ namespace dispatchkit template void bootstrap_string(Dispatch_Engine &system, const std::string &type) { - system.register_type(type); + system.add(type_(), type); add_oper_add(system); add_oper_add_equals(system); add_opers_comparison(system); bootstrap_random_access_container(system, type); bootstrap_sequence(system, type); typedef typename String::size_type (String::*find_func)(const String &, typename String::size_type) const; - register_function(system, find_func(&String::find), "find"); - register_function(system, find_func(&String::rfind), "rfind"); - register_function(system, find_func(&String::find_first_of), "find_first_of"); - register_function(system, find_func(&String::find_last_of), "find_last_of"); - register_function(system, find_func(&String::find_first_not_of), "find_first_not_of"); - register_function(system, find_func(&String::find_last_not_of), "find_last_not_of"); + system.add(fun(find_func(&String::find)), "find"); + system.add(fun(find_func(&String::rfind)), "rfind"); + system.add(fun(find_func(&String::find_first_of)), "find_first_of"); + system.add(fun(find_func(&String::find_last_of)), "find_last_of"); + system.add(fun(find_func(&String::find_first_not_of)), "find_first_not_of"); + system.add(fun(find_func(&String::find_last_not_of)), "find_last_not_of"); } } diff --git a/include/chaiscript/dispatchkit/boxed_value.hpp b/include/chaiscript/dispatchkit/boxed_value.hpp index d187525..f8239d2 100644 --- a/include/chaiscript/dispatchkit/boxed_value.hpp +++ b/include/chaiscript/dispatchkit/boxed_value.hpp @@ -17,7 +17,7 @@ #include #include -namespace dispatchkit +namespace chaiscript { /** * Boxed_Value is the main tool of the dispatchkit. It allows @@ -148,6 +148,12 @@ namespace dispatchkit return data; } + template + boost::shared_ptr get(T *t) + { + return get(boost::ref(*t)); + } + template boost::shared_ptr get(boost::reference_wrapper obj) { @@ -670,6 +676,12 @@ namespace dispatchkit return Boxed_POD_Value(ob); } }; + + template + Boxed_Value var(T t) + { + return Boxed_Value(t); + } } #endif diff --git a/include/chaiscript/dispatchkit/dispatchkit.hpp b/include/chaiscript/dispatchkit/dispatchkit.hpp index 138b235..c25ca73 100644 --- a/include/chaiscript/dispatchkit/dispatchkit.hpp +++ b/include/chaiscript/dispatchkit/dispatchkit.hpp @@ -23,22 +23,22 @@ #include "proxy_functions.hpp" #include "proxy_constructors.hpp" -namespace dispatchkit +namespace chaiscript { /** * A Proxy_Function implementation that is able to take * a vector of Proxy_Functions and perform a dispatch on them. It is * used specifically in the case of dealing with Function object variables */ - class Dispatch_Function : public Proxy_Function + class Dispatch_Function : public Proxy_Function_Base { public: - Dispatch_Function(const std::vector > > &t_funcs) + Dispatch_Function(const std::vector > &t_funcs) : m_funcs(t_funcs) { } - virtual bool operator==(const Proxy_Function &) const + virtual bool operator==(const Proxy_Function_Base &) const { return false; } @@ -57,7 +57,7 @@ namespace dispatchkit virtual bool types_match(const std::vector &types) const { - typedef std::vector > > function_vec; + typedef std::vector > function_vec; function_vec::const_iterator begin = m_funcs.begin(); function_vec::const_iterator end = m_funcs.end(); @@ -81,7 +81,7 @@ namespace dispatchkit } private: - std::vector > > m_funcs; + std::vector > m_funcs; }; @@ -92,7 +92,7 @@ namespace dispatchkit class Dispatch_Engine { public: - typedef std::map Type_Name_Map; + typedef std::map Type_Name_Map; typedef std::map Scope; typedef std::deque Stack; @@ -105,48 +105,37 @@ namespace dispatchkit /** * Add a new named Proxy_Function to the system */ - bool register_function(const boost::shared_ptr &f, const std::string &name) + bool add(const Proxy_Function &f, const std::string &name) { return add_function(f, name); } - /** - * Add a generic, named boost::function() to the system - */ - template - bool register_function(const Function &func, const std::string &name) - { - return add_function(boost::shared_ptr(new Proxy_Function_Impl(func)), name); - } - /** * Set the value of an object, by name. If the object * is not available in the current scope it is created */ - template - void set_object(const std::string &name, const Class &obj) + void add(const Boxed_Value &obj, const std::string &name) + { + for (int i = m_scopes.size()-1; i >= 0; --i) { - for (int i = m_scopes.size()-1; i >= 0; --i) + std::map::const_iterator itr = m_scopes[i].find(name); + if (itr != m_scopes[i].end()) { - std::map::const_iterator itr = m_scopes[i].find(name); - if (itr != m_scopes[i].end()) - { - m_scopes[i][name] = Boxed_Value(obj); - return; - } + m_scopes[i][name] = Boxed_Value(obj); + return; } - - add_object(name, obj); } + add_object(name, obj); + } + /** * Adds a named object to the current scope */ - template - void add_object(const std::string &name, const Class &obj) - { - m_scopes.back()[name] = Boxed_Value(obj); - } + void add_object(const std::string &name, const Boxed_Value &obj) + { + m_scopes.back()[name] = Boxed_Value(obj); + } /** * Adds a new scope to the stack @@ -209,24 +198,23 @@ namespace dispatchkit } } - std::vector >::mapped_type> > funcs = get_function_impl(name, false); + std::vector::mapped_type> > funcs = get_function_impl(name, false); if (funcs.empty()) { throw std::range_error("Object not known: " + name); } else { - return Boxed_Value(boost::shared_ptr(new Dispatch_Function(funcs))); + return Boxed_Value(Proxy_Function(new Dispatch_Function(funcs))); } } /** * Registers a new named type */ - template - void register_type(const std::string &name) - { - m_types.insert(std::make_pair(name, Get_Type_Info::get())); - } + void add(const Type_Info &ti, const std::string &name) + { + m_types.insert(std::make_pair(name, ti)); + } /** * Returns the type info for a named type @@ -274,7 +262,7 @@ namespace dispatchkit /** * Return a function by name */ - std::vector >::mapped_type> > + std::vector::mapped_type> > get_function(const std::string &t_name) const { return get_function_impl(t_name, true); @@ -283,9 +271,9 @@ namespace dispatchkit /** * Get a vector of all registered functions */ - std::vector > > get_functions() const + std::vector > get_functions() const { - return std::vector > >(m_functions.begin(), m_functions.end()); + return std::vector >(m_functions.begin(), m_functions.end()); } private: @@ -294,10 +282,10 @@ namespace dispatchkit * Looks for all registered global functions and optionally for an object * in scope with the same name */ - std::vector >::mapped_type> > + std::vector::mapped_type> > get_function_impl(const std::string &t_name, bool include_objects) const { - std::vector >::mapped_type> > funcs; + std::vector::mapped_type> > funcs; if (include_objects) { @@ -305,14 +293,14 @@ namespace dispatchkit funcs.insert(funcs.end(), std::make_pair( t_name, - boxed_cast >::mapped_type>(get_object(t_name))) + boxed_cast::mapped_type>(get_object(t_name))) ); } catch (const bad_boxed_cast &) { } catch (const std::range_error &) { } } - std::pair >::const_iterator, std::multimap >::const_iterator> range + std::pair::const_iterator, std::multimap::const_iterator> range = m_functions.equal_range(t_name); funcs.insert(funcs.end(), range.first, range.second); @@ -324,9 +312,9 @@ namespace dispatchkit * true if the function was added, false if a function with the * same signature and name already exists. */ - bool add_function(const boost::shared_ptr &f, const std::string &t_name) + bool add_function(const Proxy_Function &f, const std::string &t_name) { - std::pair >::const_iterator, std::multimap >::const_iterator> range + std::pair::const_iterator, std::multimap::const_iterator> range = m_functions.equal_range(t_name); while (range.first != range.second) @@ -344,7 +332,7 @@ namespace dispatchkit std::deque m_scopes; - std::multimap > m_functions; + std::multimap m_functions; Type_Name_Map m_types; Boxed_Value m_place_holder; }; @@ -368,7 +356,7 @@ namespace dispatchkit /** * Dump function to stdout */ - void dump_function(const std::pair > &f, const Dispatch_Engine &e) + void dump_function(const std::pair &f, const Dispatch_Engine &e) { std::vector params = f.second->get_param_types(); std::string annotation = f.second->annotation(); @@ -412,10 +400,10 @@ namespace dispatchkit } std::cout << std::endl; - std::vector > > funcs = s.get_functions(); + std::vector > funcs = s.get_functions(); std::cout << "Functions: " << std::endl; - for (std::vector > >::const_iterator itr = funcs.begin(); + for (std::vector >::const_iterator itr = funcs.begin(); itr != funcs.end(); ++itr) { diff --git a/include/chaiscript/dispatchkit/function_call.hpp b/include/chaiscript/dispatchkit/function_call.hpp index e00d197..bfb47c0 100644 --- a/include/chaiscript/dispatchkit/function_call.hpp +++ b/include/chaiscript/dispatchkit/function_call.hpp @@ -21,7 +21,7 @@ #include #include "proxy_functions.hpp" -namespace dispatchkit +namespace chaiscript { /** * Internal helper class for handling the return @@ -35,7 +35,7 @@ namespace dispatchkit { } - Ret call(const std::vector > > &t_funcs, + Ret call(const std::vector > &t_funcs, const std::vector ¶ms) { return boxed_cast(dispatch(t_funcs, params)); @@ -53,7 +53,7 @@ namespace dispatchkit { } - void call(const std::vector > > &t_funcs, + void call(const std::vector > &t_funcs, const std::vector ¶ms) { dispatch(t_funcs, params); @@ -65,7 +65,7 @@ namespace dispatchkit #define BOOST_PP_FILENAME_1 #include BOOST_PP_ITERATE() -namespace dispatchkit +namespace chaiscript { /** * Build a function caller that knows how to dispatch on a set of functions @@ -77,7 +77,7 @@ namespace dispatchkit */ template boost::function - build_function_caller(const std::vector > > &funcs) + functor(const std::vector > &funcs) { FunctionType *p; return build_function_caller_helper(p, funcs); @@ -88,7 +88,7 @@ namespace dispatchkit * useful in the case that a function is being pass out from scripting back * into code * example: - * void my_function(boost::shared_ptr f) + * void my_function(Proxy_Function f) * { * boost::function local_f = * build_function_caller(f); @@ -98,11 +98,11 @@ namespace dispatchkit */ template boost::function - build_function_caller(boost::shared_ptr func) + functor(Proxy_Function func) { - std::vector > > funcs; + std::vector > funcs; funcs.push_back(std::make_pair(std::string(), func)); - return build_function_caller(funcs); + return functor(funcs); } /** @@ -111,37 +111,24 @@ namespace dispatchkit */ template boost::function - build_function_caller(const Boxed_Value &bv) + functor(const Boxed_Value &bv) { - return build_function_caller(boxed_cast >(bv)); + return functor(boxed_cast(bv)); } - /** - * Helper for calling script code as if it were native C++ code - * example: - * boost::function f = build_functor(chai, "func(x, y){x+y}"); - * \return a boost::function representing the passed in script - * \param[in] e ScriptEngine to build the script execution from - * \param[in] script Script code to build a function from - */ - template - boost::function build_functor(ScriptEngine &e, const std::string &script) - { - return build_function_caller(e.evaluate_string(script)); - } } # endif #else # define n BOOST_PP_ITERATION() -namespace dispatchkit +namespace chaiscript { /** * used internally for unwrapping a function call's types */ template - Ret function_caller(const std::vector > > &funcs + Ret function_caller(const std::vector > &funcs BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_BINARY_PARAMS(n, Param, p) ) { std::vector params; @@ -156,7 +143,7 @@ namespace dispatchkit */ template boost::function - build_function_caller_helper(Ret (BOOST_PP_ENUM_PARAMS(n, Param)), const std::vector > > &funcs) + build_function_caller_helper(Ret (BOOST_PP_ENUM_PARAMS(n, Param)), const std::vector > &funcs) { return boost::bind(&function_caller, funcs BOOST_PP_ENUM_TRAILING(n, curry, ~)); diff --git a/include/chaiscript/dispatchkit/proxy_constructors.hpp b/include/chaiscript/dispatchkit/proxy_constructors.hpp index 9613c4a..376f377 100644 --- a/include/chaiscript/dispatchkit/proxy_constructors.hpp +++ b/include/chaiscript/dispatchkit/proxy_constructors.hpp @@ -19,17 +19,28 @@ #define BOOST_PP_FILENAME_1 #include BOOST_PP_ITERATE() # endif + +namespace chaiscript +{ + template + Proxy_Function constructor() + { + T *f; + return (build_constructor_(f)); + } +} + #else # define n BOOST_PP_ITERATION() -namespace dispatchkit +namespace chaiscript { /** * A constructor function, used for creating a new object * of a given type with a given set of params */ template - boost::shared_ptr constructor( BOOST_PP_ENUM_BINARY_PARAMS(n, Param, p) ) + boost::shared_ptr constructor_( BOOST_PP_ENUM_BINARY_PARAMS(n, Param, p) ) { return boost::shared_ptr(new Class( BOOST_PP_ENUM_PARAMS(n, p) )); } @@ -41,10 +52,10 @@ namespace dispatchkit * \todo See if it is possible to make this not be a variadic function */ template - boost::function (BOOST_PP_ENUM_PARAMS(n, Param))> build_constructor() + Proxy_Function build_constructor_(Class (*f)(BOOST_PP_ENUM_PARAMS(n, Param))) { - typedef boost::shared_ptr (*func)(BOOST_PP_ENUM_PARAMS(n, Param)); - return boost::function (BOOST_PP_ENUM_PARAMS(n, Param))>(func(&(constructor))); + typedef boost::shared_ptr (sig)(BOOST_PP_ENUM_PARAMS(n, Param)); + return Proxy_Function(new Proxy_Function_Impl(&(constructor_))); } } diff --git a/include/chaiscript/dispatchkit/proxy_functions.hpp b/include/chaiscript/dispatchkit/proxy_functions.hpp index 4566768..00bef73 100644 --- a/include/chaiscript/dispatchkit/proxy_functions.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions.hpp @@ -7,9 +7,9 @@ #include #define gettypeinfo(z,n,text) ti.push_back(Get_Type_Info::get()); -#define casthelper(z,n,text) ,dispatchkit::boxed_cast< Param ## n >(params[n]) +#define casthelper(z,n,text) ,chaiscript::boxed_cast< Param ## n >(params[n]) #define comparetype(z,n,text) && ((Get_Type_Info::get() == params[n].get_type_info())) -#define trycast(z,n,text) dispatchkit::boxed_cast(params[n]); +#define trycast(z,n,text) chaiscript::boxed_cast(params[n]); #ifndef BOOST_PP_IS_ITERATING @@ -26,7 +26,7 @@ #include #include -namespace dispatchkit +namespace chaiscript { /** * Used internally for handling a return value from a Proxy_Function call @@ -52,18 +52,6 @@ namespace dispatchkit } }; - /** - * Used internally for handling a return value from a Proxy_Function call - */ - template - struct Handle_Return - { - Boxed_Value operator()(const boost::function &f) - { - return Boxed_Value(boost::ref(*f())); - } - }; - /** * Used internally for handling a return value from a Proxy_Function call */ @@ -107,7 +95,7 @@ namespace dispatchkit * * example usage: * Boxed_Value retval = dispatch(dispatchengine.get_function("+"), - * dispatchkit::Param_List_Builder() << 5 << 6); + * chaiscript::Param_List_Builder() << 5 << 6); */ struct Param_List_Builder { @@ -154,7 +142,7 @@ namespace dispatchkit #define BOOST_PP_FILENAME_1 #include BOOST_PP_ITERATE() -namespace dispatchkit +namespace chaiscript { /** * Pure virtual base class for all Proxy_Function implementations @@ -164,17 +152,19 @@ namespace dispatchkit * Dispatch_Engine only knows how to work with Proxy_Function, no other * function classes. */ - class Proxy_Function + class Proxy_Function_Base { public: - virtual ~Proxy_Function() {} + virtual ~Proxy_Function_Base() {} virtual Boxed_Value operator()(const std::vector ¶ms) = 0; virtual std::vector get_param_types() const = 0; - virtual bool operator==(const Proxy_Function &) const = 0; + virtual bool operator==(const Proxy_Function_Base &) const = 0; virtual bool types_match(const std::vector &types) const = 0; virtual std::string annotation() const = 0; }; + typedef boost::shared_ptr Proxy_Function; + /** * Exception thrown if a function's guard fails to execute */ @@ -193,19 +183,19 @@ namespace dispatchkit * A Proxy_Function implementation that is not type safe, the called function * is expecting a vector that it works with how it chooses. */ - class Dynamic_Proxy_Function : public Proxy_Function + class Dynamic_Proxy_Function : public Proxy_Function_Base { public: Dynamic_Proxy_Function( const boost::function &)> &t_f, int t_arity=-1, const std::string &t_description = "", - const boost::shared_ptr &t_guard = boost::shared_ptr()) + const Proxy_Function &t_guard = Proxy_Function()) : m_f(t_f), m_arity(t_arity), m_description(t_description), m_guard(t_guard) { } - virtual bool operator==(const Proxy_Function &) const + virtual bool operator==(const Proxy_Function_Base &) const { return false; } @@ -279,7 +269,7 @@ namespace dispatchkit boost::function &)> m_f; int m_arity; std::string m_description; - boost::shared_ptr m_guard; + Proxy_Function m_guard; }; /** @@ -296,16 +286,16 @@ namespace dispatchkit * at runtime, when call() is executed. * it is used for bind(function, param1, _, param2) style calls */ - class Bound_Function : public Proxy_Function + class Bound_Function : public Proxy_Function_Base { public: - Bound_Function(const boost::shared_ptr &t_f, + Bound_Function(const Proxy_Function &t_f, const std::vector &t_args) : m_f(t_f), m_args(t_args) { } - virtual bool operator==(const Proxy_Function &) const + virtual bool operator==(const Proxy_Function_Base &) const { return false; } @@ -372,7 +362,7 @@ namespace dispatchkit } private: - boost::shared_ptr m_f; + Proxy_Function m_f; std::vector m_args; }; @@ -382,17 +372,17 @@ namespace dispatchkit * type checking of Boxed_Value parameters, in a type safe manner */ template - class Proxy_Function_Impl : public Proxy_Function + class Proxy_Function_Impl : public Proxy_Function_Base { public: - Proxy_Function_Impl(const Func &f) + Proxy_Function_Impl(const boost::function &f) : m_f(f) { } virtual ~Proxy_Function_Impl() {} - virtual bool operator==(const Proxy_Function &t_func) const + virtual bool operator==(const Proxy_Function_Base &t_func) const { try { dynamic_cast &>(t_func); @@ -409,12 +399,14 @@ namespace dispatchkit virtual std::vector get_param_types() const { - return build_param_type_list(m_f); + Func *f; + return build_param_type_list(f); } virtual bool types_match(const std::vector &types) const { - return compare_types(m_f, types); + Func *f; + return compare_types(f, types); } virtual std::string annotation() const @@ -423,7 +415,7 @@ namespace dispatchkit } private: - Func m_f; + boost::function m_f; }; /** @@ -447,10 +439,10 @@ namespace dispatchkit * each function against the set of parameters, in order, until a matching * function is found or throw dispatch_error if no matching function is found */ - Boxed_Value dispatch(const std::vector > > &funcs, + Boxed_Value dispatch(const std::vector > &funcs, const std::vector &plist) { - for (std::vector > >::const_iterator itr = funcs.begin(); + for (std::vector >::const_iterator itr = funcs.begin(); itr != funcs.end(); ++itr) { @@ -473,14 +465,14 @@ namespace dispatchkit #else # define n BOOST_PP_ITERATION() -namespace dispatchkit +namespace chaiscript { /** * Used by Proxy_Function_Impl to return a list of all param types * it contains. */ template - std::vector build_param_type_list(const boost::function &) + std::vector build_param_type_list(Ret (*)(BOOST_PP_ENUM_PARAMS(n, Param))) { std::vector ti; ti.push_back(Get_Type_Info::get()); @@ -514,7 +506,7 @@ namespace dispatchkit * registration of two functions with the exact same signatures */ template - bool compare_types(const boost::function &, + bool compare_types(Ret (*)(BOOST_PP_ENUM_PARAMS(n, Param)), const std::vector ¶ms) { if (params.size() != n) diff --git a/include/chaiscript/dispatchkit/register_function.hpp b/include/chaiscript/dispatchkit/register_function.hpp index b026863..425d242 100644 --- a/include/chaiscript/dispatchkit/register_function.hpp +++ b/include/chaiscript/dispatchkit/register_function.hpp @@ -14,8 +14,15 @@ #include #include -namespace dispatchkit +namespace chaiscript { + template + Proxy_Function fun(const boost::function &f) + { + return Proxy_Function(new Proxy_Function_Impl(f)); + } + + /** * Helper function for register_member function */ @@ -31,10 +38,11 @@ namespace dispatchkit * for example, the case of std::pair<>::first and std::pair<>::second */ template - void register_member(Dispatch_Engine &s, T Class::* m, const std::string &name) + Proxy_Function fun(T Class::* m) { - s.register_function(boost::function(boost::bind(&get_member, m, _1)), name); + return fun(boost::function(boost::bind(&get_member, m, _1))); } + } #define BOOST_PP_ITERATION_LIMITS ( 0, 10 ) @@ -45,33 +53,33 @@ namespace dispatchkit #else # define n BOOST_PP_ITERATION() -namespace dispatchkit +namespace chaiscript { /** * Register a global function of n parameters with name */ template - void register_function(Dispatch_Engine &s, Ret (*f)(BOOST_PP_ENUM_PARAMS(n, Param)), const std::string &name) + Proxy_Function fun(Ret (*f)(BOOST_PP_ENUM_PARAMS(n, Param))) { - s.register_function(boost::function(f), name); + return fun(boost::function(f)); } /** * Register a class method of n parameters with name */ template - void register_function(Dispatch_Engine &s, Ret (Class::*f)(BOOST_PP_ENUM_PARAMS(n, Param)), const std::string &name) + Proxy_Function fun(Ret (Class::*f)(BOOST_PP_ENUM_PARAMS(n, Param))) { - s.register_function(boost::function(f), name); + return fun(boost::function(f)); } /** * Register a const class method of n parameters with name */ template - void register_function(Dispatch_Engine &s, Ret (Class::*f)(BOOST_PP_ENUM_PARAMS(n, Param))const, const std::string &name) + Proxy_Function fun(Ret (Class::*f)(BOOST_PP_ENUM_PARAMS(n, Param))const) { - s.register_function(boost::function(f), name); + return fun(boost::function(f)); } } diff --git a/include/chaiscript/dispatchkit/type_info.hpp b/include/chaiscript/dispatchkit/type_info.hpp index 56f8252..8688ec9 100644 --- a/include/chaiscript/dispatchkit/type_info.hpp +++ b/include/chaiscript/dispatchkit/type_info.hpp @@ -16,7 +16,7 @@ #include #include -namespace dispatchkit +namespace chaiscript { /** * compile time deduced information about a type @@ -115,6 +115,22 @@ namespace dispatchkit &typeid(typename boost::remove_const::type>::type>::type)); } }; + + + template + Type_Info type_(T) + { + return Get_Type_Info::get(); + } + + + template + Type_Info type_() + { + return Get_Type_Info::get(); + } + + } #endif diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index 0fbab8f..5f32134 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -26,6 +26,27 @@ namespace chaiscript build_eval_system(); } + /** + * Adds an object to the system: type, function, object + */ + template + void add(const T &t, const std::string &name) + { + engine.add(t, name); + } + /** + * Helper for calling script code as if it were native C++ code + * example: + * boost::function f = build_functor(chai, "func(x, y){x+y}"); + * \return a boost::function representing the passed in script + * \param[in] script Script code to build a function from + */ + template + boost::function functor(const std::string &script) + { + return chaiscript::functor(evaluate_string(script)); + } + /** * Returns the current evaluation engine */ @@ -46,9 +67,9 @@ namespace chaiscript /** * Evaluates the given boxed string, used during eval() inside of a script */ - const dispatchkit::Boxed_Value eval(const std::vector &vals) { + const Boxed_Value eval(const std::vector &vals) { std::string val; - val = dispatchkit::boxed_cast(vals[0]); + val = boxed_cast(vals[0]); return evaluate_string(val); } @@ -79,14 +100,14 @@ namespace chaiscript * Builds all the requirements for ChaiScript, including its evaluator and a run of its prelude. */ void build_eval_system() { - dispatchkit::Bootstrap::bootstrap(engine); - dispatchkit::bootstrap_vector >(engine, "Vector"); - dispatchkit::bootstrap_string(engine, "string"); - dispatchkit::bootstrap_map >(engine, "Map"); - dispatchkit::bootstrap_pair >(engine, "Pair"); + Bootstrap::bootstrap(engine); + bootstrap_vector >(engine, "Vector"); + bootstrap_string(engine, "string"); + bootstrap_map >(engine, "Map"); + bootstrap_pair >(engine, "Pair"); - engine.register_function(boost::shared_ptr( - new dispatchkit::Dynamic_Proxy_Function(boost::bind(&ChaiScript_System::eval, boost::ref(*this), _1), 1)), "eval"); + engine.add(Proxy_Function( + new Dynamic_Proxy_Function(boost::bind(&ChaiScript_System::eval, boost::ref(*this), _1), 1)), "eval"); evaluate_string(chaiscript_prelude, "standard prelude"); } @@ -94,9 +115,9 @@ namespace chaiscript /** * Evaluates the given string in by parsing it and running the results through the evaluator */ - dispatchkit::Boxed_Value evaluate_string(const std::string &input, const char *filename = "__EVAL__") { + Boxed_Value evaluate_string(const std::string &input, const char *filename = "__EVAL__") { //debug_print(tokens); - dispatchkit::Boxed_Value value; + Boxed_Value value; parser.clear_match_stack(); try { @@ -115,12 +136,12 @@ namespace chaiscript /** * Loads the file specified by filename, evaluates it, and returns the result */ - dispatchkit::Boxed_Value evaluate_file(const char *filename) { + Boxed_Value evaluate_file(const char *filename) { return evaluate_string(load_file(filename), filename); } }; - typedef ChaiScript_System ChaiScript_Engine; + typedef ChaiScript_System ChaiScript_Engine; } #endif /* CHAISCRIPT_ENGINE_HPP_ */ diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index 2de3ffa..1bb0126 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -15,14 +15,14 @@ namespace chaiscript * Helper function that will set up the scope around a function call, including handling the named function parameters */ template - const dispatchkit::Boxed_Value eval_function (Eval_System &ss, TokenPtr node, const std::vector ¶m_names, const std::vector &vals) { + const Boxed_Value eval_function (Eval_System &ss, TokenPtr node, const std::vector ¶m_names, const std::vector &vals) { ss.new_scope(); for (unsigned int i = 0; i < param_names.size(); ++i) { ss.add_object(param_names[i], vals[i]); } - dispatchkit::Boxed_Value retval; + Boxed_Value retval; try { retval = eval_token(ss, node); @@ -42,8 +42,8 @@ namespace chaiscript * Evaluates the top-level file node */ template - dispatchkit::Boxed_Value eval_file(Eval_System &ss, TokenPtr node) { - dispatchkit::Boxed_Value retval; + Boxed_Value eval_file(Eval_System &ss, TokenPtr node) { + Boxed_Value retval; unsigned int i; for (i = 0; i < node->children.size(); ++i) { retval = eval_token(ss, node->children[i]); @@ -55,13 +55,13 @@ namespace chaiscript * Evaluates a variable or function name identifier */ template - dispatchkit::Boxed_Value eval_id(Eval_System &ss, TokenPtr node) { + Boxed_Value eval_id(Eval_System &ss, TokenPtr node) { if (node->text == "true") { - return dispatchkit::Boxed_Value(true); + return Boxed_Value(true); } else if (node->text == "false") { - return dispatchkit::Boxed_Value(false); + return Boxed_Value(false); } else { try { @@ -77,68 +77,68 @@ namespace chaiscript * Evaluates a floating point number */ template - dispatchkit::Boxed_Value eval_float(Eval_System &, TokenPtr node) { - return dispatchkit::Boxed_Value(double(atof(node->text.c_str()))); + Boxed_Value eval_float(Eval_System &, TokenPtr node) { + return Boxed_Value(double(atof(node->text.c_str()))); } /** * Evaluates an integer */ template - dispatchkit::Boxed_Value eval_int(Eval_System &, TokenPtr node) { - return dispatchkit::Boxed_Value(atoi(node->text.c_str())); + Boxed_Value eval_int(Eval_System &, TokenPtr node) { + return Boxed_Value(atoi(node->text.c_str())); } /** * Evaluates a quoted string */ template - dispatchkit::Boxed_Value eval_quoted_string(Eval_System &, TokenPtr node) { - return dispatchkit::Boxed_Value(node->text); + Boxed_Value eval_quoted_string(Eval_System &, TokenPtr node) { + return Boxed_Value(node->text); } /** * Evaluates a char group */ template - dispatchkit::Boxed_Value eval_single_quoted_string(Eval_System &, TokenPtr node) { - return dispatchkit::Boxed_Value(node->text); + Boxed_Value eval_single_quoted_string(Eval_System &, TokenPtr node) { + return Boxed_Value(node->text); } /** * Evaluates a string of equations in reverse order so that the right-most side has precedence */ template - dispatchkit::Boxed_Value eval_equation(Eval_System &ss, TokenPtr node) { - dispatchkit::Boxed_Value retval; + Boxed_Value eval_equation(Eval_System &ss, TokenPtr node) { + Boxed_Value retval; unsigned int i; retval = eval_token(ss, node->children.back()); if (node->children.size() > 1) { for (i = node->children.size()-3; ((int)i) >= 0; i -= 2) { if (node->children[i+1]->text == "=") { - dispatchkit::Boxed_Value lhs = eval_token(ss, node->children[i]); + Boxed_Value lhs = eval_token(ss, node->children[i]); try { if (lhs.is_unknown()) { - retval = dispatch(ss.get_function("clone"), dispatchkit::Param_List_Builder() << retval); + retval = dispatch(ss.get_function("clone"), Param_List_Builder() << retval); } - dispatchkit::Param_List_Builder plb; + Param_List_Builder plb; plb << lhs; plb << retval; try { retval = dispatch(ss.get_function(node->children[i+1]->text), plb); } - catch(const dispatchkit::dispatch_error &){ + catch(const dispatch_error &){ throw Eval_Error("Mismatched types in equation", node->children[i+1]); } } - catch(const dispatchkit::dispatch_error &){ + catch(const dispatch_error &){ throw Eval_Error("Can not clone right hand side of equation", node->children[i+1]); } } else if (node->children[i+1]->text == ":=") { - dispatchkit::Boxed_Value lhs = eval_token(ss, node->children[i]); - if (lhs.is_unknown() || dispatchkit::Bootstrap::type_match(lhs, retval)) { + Boxed_Value lhs = eval_token(ss, node->children[i]); + if (lhs.is_unknown() || Bootstrap::type_match(lhs, retval)) { lhs.assign(retval); } else { @@ -146,13 +146,13 @@ namespace chaiscript } } else { - dispatchkit::Param_List_Builder plb; + Param_List_Builder plb; plb << eval_token(ss, node->children[i]); plb << retval; try { retval = dispatch(ss.get_function(node->children[i+1]->text), plb); } - catch(const dispatchkit::dispatch_error &){ + catch(const dispatch_error &){ throw Eval_Error("Can not find appropriate '" + node->children[i+1]->text + "'", node->children[i+1]); } } @@ -165,8 +165,8 @@ namespace chaiscript * Evaluates a variable declaration */ template - dispatchkit::Boxed_Value eval_var_decl(Eval_System &ss, TokenPtr node) { - ss.add_object(node->children[0]->text, dispatchkit::Boxed_Value()); + Boxed_Value eval_var_decl(Eval_System &ss, TokenPtr node) { + ss.add_object(node->children[0]->text, Boxed_Value()); return ss.get_object(node->children[0]->text); } @@ -174,8 +174,8 @@ namespace chaiscript * Evaluates binary boolean operators. Respects short-circuiting rules. */ template - dispatchkit::Boxed_Value eval_expression(Eval_System &ss, TokenPtr node) { - dispatchkit::Boxed_Value retval; + Boxed_Value eval_expression(Eval_System &ss, TokenPtr node) { + Boxed_Value retval; unsigned int i; retval = eval_token(ss, node->children[0]); @@ -183,9 +183,9 @@ namespace chaiscript for (i = 1; i < node->children.size(); i += 2) { bool lhs; try { - lhs = dispatchkit::boxed_cast(retval); + lhs = boxed_cast(retval); } - catch (const dispatchkit::bad_boxed_cast &) { + catch (const bad_boxed_cast &) { throw Eval_Error("Condition not boolean", node); } if (node->children[i]->text == "&&") { @@ -193,12 +193,12 @@ namespace chaiscript retval = eval_token(ss, node->children[i+1]); } else { - retval = dispatchkit::Boxed_Value(false); + retval = Boxed_Value(false); } } else if (node->children[i]->text == "||") { if (lhs) { - retval = dispatchkit::Boxed_Value(true); + retval = Boxed_Value(true); } else { retval = eval_token(ss, node->children[i+1]); @@ -213,21 +213,21 @@ namespace chaiscript * Evaluates comparison, additions, and multiplications and their relatives */ template - dispatchkit::Boxed_Value eval_comp_add_mul(Eval_System &ss, TokenPtr node) { - dispatchkit::Boxed_Value retval; + Boxed_Value eval_comp_add_mul(Eval_System &ss, TokenPtr node) { + Boxed_Value retval; unsigned int i; retval = eval_token(ss, node->children[0]); if (node->children.size() > 1) { for (i = 1; i < node->children.size(); i += 2) { - dispatchkit::Param_List_Builder plb; + Param_List_Builder plb; plb << retval; plb << eval_token(ss, node->children[i + 1]); try { retval = dispatch(ss.get_function(node->children[i]->text), plb); } - catch(const dispatchkit::dispatch_error &){ + catch(const dispatch_error &){ throw Eval_Error("Can not find appropriate '" + node->children[i]->text + "'", node->children[i]); } } @@ -240,13 +240,13 @@ namespace chaiscript * Evaluates an array lookup */ template - dispatchkit::Boxed_Value eval_array_call(Eval_System &ss, TokenPtr node) { - dispatchkit::Boxed_Value retval; + Boxed_Value eval_array_call(Eval_System &ss, TokenPtr node) { + Boxed_Value retval; unsigned int i; retval = eval_token(ss, node->children[0]); for (i = 1; i < node->children.size(); ++i) { - dispatchkit::Param_List_Builder plb; + Param_List_Builder plb; plb << retval; plb << eval_token(ss, node->children[i]); try { @@ -255,7 +255,7 @@ namespace chaiscript catch(std::out_of_range &) { throw Eval_Error("Out of bounds exception", node); } - catch(const dispatchkit::dispatch_error &){ + catch(const dispatch_error &){ throw Eval_Error("Can not find appropriate array lookup '[]' " + node->children[i]->text, node->children[i]); } } @@ -267,13 +267,13 @@ namespace chaiscript * Evaluates a unary negation */ template - dispatchkit::Boxed_Value eval_negate(Eval_System &ss, TokenPtr node) { - dispatchkit::Boxed_Value retval; + Boxed_Value eval_negate(Eval_System &ss, TokenPtr node) { + Boxed_Value retval; retval = eval_token(ss, node->children[0]); - dispatchkit::Param_List_Builder plb; + Param_List_Builder plb; plb << retval; - plb << dispatchkit::Boxed_Value(-1.0); + plb << Boxed_Value(-1.0); try { return dispatch(ss.get_function("*"), plb); @@ -287,29 +287,29 @@ namespace chaiscript * Evaluates a unary boolean not */ template - dispatchkit::Boxed_Value eval_not(Eval_System &ss, TokenPtr node) { - dispatchkit::Boxed_Value retval; + Boxed_Value eval_not(Eval_System &ss, TokenPtr node) { + Boxed_Value retval; bool cond; try { retval = eval_token(ss, node->children[0]); - cond = dispatchkit::boxed_cast(retval); + cond = boxed_cast(retval); } - catch (const dispatchkit::bad_boxed_cast &) { + catch (const bad_boxed_cast &) { throw Eval_Error("Boolean not('!') condition not boolean", node->children[0]); } - return dispatchkit::Boxed_Value(!cond); + return Boxed_Value(!cond); } /** * Evaluates any unary prefix */ template - dispatchkit::Boxed_Value eval_prefix(Eval_System &ss, TokenPtr node) { - dispatchkit::Boxed_Value retval; + Boxed_Value eval_prefix(Eval_System &ss, TokenPtr node) { + Boxed_Value retval; retval = eval_token(ss, node->children[1]); - dispatchkit::Param_List_Builder plb; + Param_List_Builder plb; plb << retval; try { @@ -324,25 +324,25 @@ namespace chaiscript * Evaluates (and generates) an inline array initialization */ template - dispatchkit::Boxed_Value eval_inline_array(Eval_System &ss, TokenPtr node) { - dispatchkit::Boxed_Value retval; + Boxed_Value eval_inline_array(Eval_System &ss, TokenPtr node) { + Boxed_Value retval; unsigned int i; try { - retval = dispatch(ss.get_function("Vector"), dispatchkit::Param_List_Builder()); + retval = dispatch(ss.get_function("Vector"), Param_List_Builder()); if (node->children.size() > 0) { for (i = 0; i < node->children[0]->children.size(); ++i) { try { - dispatchkit::Boxed_Value tmp = eval_token(ss, node->children[0]->children[i]); - dispatch(ss.get_function("push_back"), dispatchkit::Param_List_Builder() << retval << tmp); + Boxed_Value tmp = eval_token(ss, node->children[0]->children[i]); + dispatch(ss.get_function("push_back"), Param_List_Builder() << retval << tmp); } - catch (const dispatchkit::dispatch_error &) { + catch (const dispatch_error &) { throw Eval_Error("Can not find appropriate 'push_back'", node->children[0]->children[i]); } } } } - catch (const dispatchkit::dispatch_error &) { + catch (const dispatch_error &) { throw Eval_Error("Can not find appropriate 'Vector()'", node); } @@ -353,13 +353,13 @@ namespace chaiscript * Evaluates (and generates) an inline range initialization */ template - dispatchkit::Boxed_Value eval_inline_range(Eval_System &ss, TokenPtr node) { + Boxed_Value eval_inline_range(Eval_System &ss, TokenPtr node) { try { - return dispatch(ss.get_function("generate_range"), dispatchkit::Param_List_Builder() + return dispatch(ss.get_function("generate_range"), Param_List_Builder() << eval_token(ss, node->children[0]->children[0]->children[0]) << eval_token(ss, node->children[0]->children[0]->children[1])); } - catch (const dispatchkit::dispatch_error &) { + catch (const dispatch_error &) { throw Eval_Error("Unable to generate range vector", node); } } @@ -368,24 +368,24 @@ namespace chaiscript * Evaluates (and generates) an inline map initialization */ template - dispatchkit::Boxed_Value eval_inline_map(Eval_System &ss, TokenPtr node) { - dispatchkit::Boxed_Value retval; + Boxed_Value eval_inline_map(Eval_System &ss, TokenPtr node) { + Boxed_Value retval; unsigned int i; try { - retval = dispatch(ss.get_function("Map"), dispatchkit::Param_List_Builder()); + retval = dispatch(ss.get_function("Map"), Param_List_Builder()); for (i = 0; i < node->children[0]->children.size(); ++i) { try { - dispatchkit::Boxed_Value key = eval_token(ss, node->children[0]->children[i]->children[0]); - dispatchkit::Boxed_Value slot = dispatch(ss.get_function("[]"), dispatchkit::Param_List_Builder() << retval << key); - dispatch(ss.get_function("="), dispatchkit::Param_List_Builder() << slot << eval_token(ss, node->children[0]->children[i]->children[1])); + Boxed_Value key = eval_token(ss, node->children[0]->children[i]->children[0]); + Boxed_Value slot = dispatch(ss.get_function("[]"), Param_List_Builder() << retval << key); + dispatch(ss.get_function("="), Param_List_Builder() << slot << eval_token(ss, node->children[0]->children[i]->children[1])); } - catch (const dispatchkit::dispatch_error &) { + catch (const dispatch_error &) { throw Eval_Error("Can not find appropriate '=' for map init", node->children[0]->children[i]); } } } - catch (const dispatchkit::dispatch_error &) { + catch (const dispatch_error &) { throw Eval_Error("Can not find appropriate 'Map()'", node); } @@ -396,21 +396,21 @@ namespace chaiscript * Evaluates a function call, starting with its arguments. Handles resetting the scope to the previous one after the call. */ template - dispatchkit::Boxed_Value eval_fun_call(Eval_System &ss, TokenPtr node) { - dispatchkit::Boxed_Value retval; - dispatchkit::Param_List_Builder plb; - dispatchkit::Dispatch_Engine::Stack prev_stack = ss.get_stack(); - dispatchkit::Dispatch_Engine::Stack new_stack; + Boxed_Value eval_fun_call(Eval_System &ss, TokenPtr node) { + Boxed_Value retval; + Param_List_Builder plb; + Dispatch_Engine::Stack prev_stack = ss.get_stack(); + Dispatch_Engine::Stack new_stack; unsigned int i; - new_stack.push_back(dispatchkit::Dispatch_Engine::Scope()); + new_stack.push_back(Dispatch_Engine::Scope()); if ((node->children.size() > 1) && (node->children[1]->identifier == Token_Type::Arg_List)) { for (i = 0; i < node->children[1]->children.size(); ++i) { plb << eval_token(ss, node->children[1]->children[i]); } } - dispatchkit::Boxed_Value fn; + Boxed_Value fn; try { fn = eval_token(ss, node->children[0]); } @@ -420,10 +420,10 @@ namespace chaiscript } try { ss.set_stack(new_stack); - retval = (*dispatchkit::boxed_cast >(fn))(plb); + retval = (*boxed_cast(fn))(plb); ss.set_stack(prev_stack); } - catch(const dispatchkit::dispatch_error &e){ + catch(const dispatch_error &e){ ss.set_stack(prev_stack); throw Eval_Error(std::string(e.what()) + " with function '" + node->children[0]->text + "'", node->children[0]); } @@ -443,21 +443,21 @@ namespace chaiscript * Evaluates a method/attributes invocation */ template - dispatchkit::Boxed_Value eval_dot_access(Eval_System &ss, TokenPtr node) { - dispatchkit::Boxed_Value retval; - std::vector > > fn; - dispatchkit::Dispatch_Engine::Stack prev_stack = ss.get_stack(); - dispatchkit::Dispatch_Engine::Stack new_stack; + Boxed_Value eval_dot_access(Eval_System &ss, TokenPtr node) { + Boxed_Value retval; + std::vector > fn; + Dispatch_Engine::Stack prev_stack = ss.get_stack(); + Dispatch_Engine::Stack new_stack; unsigned int i, j; - new_stack.push_back(dispatchkit::Dispatch_Engine::Scope()); + new_stack.push_back(Dispatch_Engine::Scope()); //todo: Please extract a single way of doing function calls between this and eval_fun_call retval = eval_token(ss, node->children[0]); if (node->children.size() > 1) { for (i = 1; i < node->children.size(); ++i) { - dispatchkit::Param_List_Builder plb; + Param_List_Builder plb; plb << retval; if (node->children[i]->children.size() > 1) { @@ -480,7 +480,7 @@ namespace chaiscript retval = dispatch(fn, plb); ss.set_stack(prev_stack); } - catch(const dispatchkit::dispatch_error &e){ + catch(const dispatch_error &e){ ss.set_stack(prev_stack); throw Eval_Error(std::string(e.what()) + " with function '" + fun_name + "'", node->children[i]); } @@ -502,16 +502,16 @@ namespace chaiscript * Evaluates an if/elseif/else block */ template - dispatchkit::Boxed_Value eval_if(Eval_System &ss, TokenPtr node) { - dispatchkit::Boxed_Value retval; + Boxed_Value eval_if(Eval_System &ss, TokenPtr node) { + Boxed_Value retval; unsigned int i; retval = eval_token(ss, node->children[0]); bool cond; try { - cond = dispatchkit::boxed_cast(retval); + cond = boxed_cast(retval); } - catch (const dispatchkit::bad_boxed_cast &) { + catch (const bad_boxed_cast &) { throw Eval_Error("If condition not boolean", node->children[0]); } if (cond) { @@ -528,9 +528,9 @@ namespace chaiscript else if (node->children[i]->text == "else if") { retval = eval_token(ss, node->children[i+1]); try { - cond = dispatchkit::boxed_cast(retval); + cond = boxed_cast(retval); } - catch (const dispatchkit::bad_boxed_cast &) { + catch (const bad_boxed_cast &) { throw Eval_Error("'else if' condition not boolean", node->children[i+1]); } if (cond) { @@ -549,21 +549,21 @@ namespace chaiscript * Evaluates a while block */ template - dispatchkit::Boxed_Value eval_while(Eval_System &ss, TokenPtr node) { + Boxed_Value eval_while(Eval_System &ss, TokenPtr node) { bool cond; try { - cond = dispatchkit::boxed_cast(eval_token(ss, node->children[0])); + cond = boxed_cast(eval_token(ss, node->children[0])); } - catch (const dispatchkit::bad_boxed_cast &) { + catch (const bad_boxed_cast &) { throw Eval_Error("While condition not boolean", node->children[0]); } while (cond) { try { eval_token(ss, node->children[1]); try { - cond = dispatchkit::boxed_cast(eval_token(ss, node->children[0])); + cond = boxed_cast(eval_token(ss, node->children[0])); } - catch (const dispatchkit::bad_boxed_cast &) { + catch (const bad_boxed_cast &) { throw Eval_Error("While condition not boolean", node->children[0]); } } @@ -571,26 +571,26 @@ namespace chaiscript cond = false; } } - return dispatchkit::Boxed_Value(); + return Boxed_Value(); } /** * Evaluates a for block, including the for's conditions, from left to right */ template - dispatchkit::Boxed_Value eval_for(Eval_System &ss, TokenPtr node) { + Boxed_Value eval_for(Eval_System &ss, TokenPtr node) { bool cond; try { if (node->children.size() == 4) { eval_token(ss, node->children[0]); - cond = dispatchkit::boxed_cast(eval_token(ss, node->children[1])); + cond = boxed_cast(eval_token(ss, node->children[1])); } else { - cond = dispatchkit::boxed_cast(eval_token(ss, node->children[0])); + cond = boxed_cast(eval_token(ss, node->children[0])); } } - catch (const dispatchkit::bad_boxed_cast &) { + catch (const bad_boxed_cast &) { throw Eval_Error("For condition not boolean", node); } while (cond) { @@ -598,35 +598,35 @@ namespace chaiscript if (node->children.size() == 4) { eval_token(ss, node->children[3]); eval_token(ss, node->children[2]); - cond = dispatchkit::boxed_cast(eval_token(ss, node->children[1])); + cond = boxed_cast(eval_token(ss, node->children[1])); } else { eval_token(ss, node->children[2]); eval_token(ss, node->children[1]); - cond = dispatchkit::boxed_cast(eval_token(ss, node->children[0])); + cond = boxed_cast(eval_token(ss, node->children[0])); } } - catch (const dispatchkit::bad_boxed_cast &) { + catch (const bad_boxed_cast &) { throw Eval_Error("For condition not boolean", node); } catch (Break_Loop &) { cond = false; } } - return dispatchkit::Boxed_Value(); + return Boxed_Value(); } /** * Evaluates a function definition */ template - dispatchkit::Boxed_Value eval_def(Eval_System &ss, TokenPtr node) { - dispatchkit::Boxed_Value retval; + Boxed_Value eval_def(Eval_System &ss, TokenPtr node) { + Boxed_Value retval; unsigned int i; std::vector param_names; std::string annotation = node->annotation?node->annotation->text:""; - boost::shared_ptr guard; + boost::shared_ptr guard; size_t numparams = 0; std::string function_name = node->children[0]->text; TokenPtr guardnode; @@ -651,14 +651,14 @@ namespace chaiscript } if (guardnode) { - guard = boost::shared_ptr - (new dispatchkit::Dynamic_Proxy_Function(boost::bind(&eval_function, + guard = boost::shared_ptr + (new Dynamic_Proxy_Function(boost::bind(&eval_function, boost::ref(ss), guardnode, param_names, _1), numparams)); } - ss.register_function(boost::shared_ptr - (new dispatchkit::Dynamic_Proxy_Function(boost::bind(&eval_function, + ss.add(Proxy_Function + (new Dynamic_Proxy_Function(boost::bind(&eval_function, boost::ref(ss), node->children.back(), param_names, _1), numparams, annotation, guard)), function_name); @@ -670,8 +670,8 @@ namespace chaiscript * Evaluates a lambda (anonymous function) */ template - dispatchkit::Boxed_Value eval_lambda(Eval_System &ss, TokenPtr node) { - dispatchkit::Boxed_Value retval; + Boxed_Value eval_lambda(Eval_System &ss, TokenPtr node) { + Boxed_Value retval; unsigned int i; std::vector param_names; @@ -689,8 +689,8 @@ namespace chaiscript numparams = 0; } - return dispatchkit::Boxed_Value(boost::shared_ptr( - new dispatchkit::Dynamic_Proxy_Function( + return Boxed_Value(Proxy_Function( + new Dynamic_Proxy_Function( boost::bind(&eval_function, boost::ref(ss), node->children.back(), param_names, _1), numparams))); } @@ -698,8 +698,8 @@ namespace chaiscript * Evaluates a scoped block. Handles resetting the scope after the block has completed. */ template - dispatchkit::Boxed_Value eval_block(Eval_System &ss, TokenPtr node) { - dispatchkit::Boxed_Value retval; + Boxed_Value eval_block(Eval_System &ss, TokenPtr node) { + Boxed_Value retval; unsigned int i; ss.new_scope(); @@ -726,13 +726,13 @@ namespace chaiscript * Evaluates a return statement */ template - dispatchkit::Boxed_Value eval_return(Eval_System &ss, TokenPtr node) { - dispatchkit::Boxed_Value retval; + Boxed_Value eval_return(Eval_System &ss, TokenPtr node) { + Boxed_Value retval; if (node->children.size() > 0) { retval = eval_token(ss, node->children[0]); } else { - retval = dispatchkit::Boxed_Value(); + retval = Boxed_Value(); } throw Return_Value(retval, node); } @@ -741,7 +741,7 @@ namespace chaiscript * Evaluates a break statement */ template - dispatchkit::Boxed_Value eval_break(Eval_System &, TokenPtr node) { + Boxed_Value eval_break(Eval_System &, TokenPtr node) { throw Break_Loop(node); } @@ -749,7 +749,7 @@ namespace chaiscript * Top-level evaluation dispatch for all AST node types */ template - dispatchkit::Boxed_Value eval_token(Eval_System &ss, TokenPtr node) { + Boxed_Value eval_token(Eval_System &ss, TokenPtr node) { switch (node->identifier) { case (Token_Type::File) : return eval_file(ss, node); @@ -862,7 +862,7 @@ namespace chaiscript break; default : - return dispatchkit::Boxed_Value(); + return Boxed_Value(); } } } diff --git a/src/example.cpp b/src/example.cpp index bf9c433..bb1ab14 100644 --- a/src/example.cpp +++ b/src/example.cpp @@ -27,9 +27,9 @@ struct System std::map > m_callbacks; void add_callback(const std::string &t_name, - boost::shared_ptr t_func) + const chaiscript::Proxy_Function &t_func) { - m_callbacks[t_name] = dispatchkit::build_function_caller(t_func); + m_callbacks[t_name] = chaiscript::functor(t_func); } @@ -47,17 +47,17 @@ struct System int main(int argc, char *argv[]) { + using namespace chaiscript; - - chaiscript::ChaiScript_Engine chai; + ChaiScript_Engine chai; //Create a new system object and share it with the chaiscript engine System system; - chai.get_eval_engine().add_object("system", boost::ref(system)); + chai.add(var(&system), "system"); //Register the two methods of the System structure. - dispatchkit::register_function(chai.get_eval_engine(), &System::add_callback, "add_callback"); - dispatchkit::register_function(chai.get_eval_engine(), &System::do_callbacks, "do_callbacks"); + chai.add(fun(&System::add_callback), "add_callback"); + chai.add(fun(&System::do_callbacks), "do_callbacks"); // Let's use chaiscript to add a new lambda callback to our system. // The function "{ 'Callback1' + x }" is created in chaiscript and passed into our C++ application @@ -75,18 +75,20 @@ int main(int argc, char *argv[]) { // then cast your function to that typedef. typedef void (*PlainLog)(const std::string &); typedef void (*ModuleLog)(const std::string &, const std::string &); - dispatchkit::register_function(chai.get_eval_engine(), PlainLog(&log), "log"); - dispatchkit::register_function(chai.get_eval_engine(), ModuleLog(&log), "log"); + chai.add(fun(PlainLog(&log)), "log"); + chai.add(fun(ModuleLog(&log)), "log"); chai.evaluate_string("log('Test Message')"); chai.evaluate_string("log('Test Module', 'Test Message');"); //Finally, it is possible to register any boost::function as a system function, in this //way, we can, for instance add a bound member function to the system - chai.get_eval_engine().register_function(boost::function(boost::bind(&System::do_callbacks, boost::ref(system), "Bound Test")), "do_callbacks"); + chai.add(fun(boost::function(boost::bind(&System::do_callbacks, boost::ref(system), "Bound Test"))), "do_callbacks"); //Call bound version of do_callbacks chai.evaluate_string("do_callbacks()"); + boost::function caller = chai.functor("fun() { system.do_callbacks(\"From Functor\"); }"); + caller(); } diff --git a/src/main.cpp b/src/main.cpp index b62aa7b..3003394 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,7 +24,7 @@ int main(int argc, char *argv[]) { std::getline(std::cin, input); while (input != "quit") { - dispatchkit::Boxed_Value val; + chaiscript::Boxed_Value val; if (input == "help") { print_help(); @@ -37,7 +37,7 @@ int main(int argc, char *argv[]) { //Then, we try to print the result of the evaluation to the user if (val.get_type_info().m_bare_type_info && *(val.get_type_info().m_bare_type_info) != typeid(void)) { try { - dispatchkit::dispatch(chai.get_eval_engine().get_function("print"), dispatchkit::Param_List_Builder() << val); + chaiscript::dispatch(chai.get_eval_engine().get_function("print"), chaiscript::Param_List_Builder() << val); } catch (...) { //If we can't, do nothing @@ -57,7 +57,7 @@ int main(int argc, char *argv[]) { for (int i = 1; i < argc; ++i) { std::string filename(argv[i]); try { - dispatchkit::Boxed_Value val = chai.evaluate_file(argv[i]); + chaiscript::Boxed_Value val = chai.evaluate_file(argv[i]); } catch (std::exception &e) { std::cout << e.what() << std::endl;