Move towards more header only implementation friendly
This commit is contained in:
parent
1eb0964f4e
commit
4edea184de
@ -186,10 +186,8 @@ public:
|
||||
|
||||
Eval_Engine build_eval_system(Lexer &lexer, Rule &parser) {
|
||||
Eval_Engine ss;
|
||||
bootstrap(ss);
|
||||
bootstrap_vector<std::vector<int> >(ss, "VectorInt");
|
||||
Bootstrap::bootstrap(ss);
|
||||
bootstrap_vector<std::vector<Boxed_Value> >(ss, "Vector");
|
||||
//dump_system(ss);
|
||||
|
||||
ss.register_function(boost::shared_ptr<Proxy_Function>(
|
||||
new Dynamic_Proxy_Function(boost::bind(&ChaiScript_System<Eval_Engine>::eval, boost::ref(*this), _1), 1)), "eval");
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define __bootstrap_hpp__
|
||||
|
||||
#include "boxedcpp.hpp"
|
||||
#include "register_function.hpp"
|
||||
#include "bootstrap_pod.hpp"
|
||||
|
||||
template<typename Ret, typename P1, typename P2>
|
||||
Ret add(P1 p1, P2 p2)
|
||||
@ -10,11 +10,6 @@ Ret add(P1 p1, P2 p2)
|
||||
return p1 + p2;
|
||||
}
|
||||
|
||||
Boxed_Value pod_add(Boxed_POD_Value l, Boxed_POD_Value r)
|
||||
{
|
||||
return l + r;
|
||||
}
|
||||
|
||||
|
||||
template<typename Ret, typename P1, typename P2>
|
||||
Ret subtract(P1 p1, P2 p2)
|
||||
@ -22,11 +17,6 @@ Ret subtract(P1 p1, P2 p2)
|
||||
return p1 - p2;
|
||||
}
|
||||
|
||||
Boxed_Value pod_subtract(Boxed_POD_Value l, Boxed_POD_Value r)
|
||||
{
|
||||
return l - r;
|
||||
}
|
||||
|
||||
|
||||
template<typename Ret, typename P1, typename P2>
|
||||
Ret divide(P1 p1, P2 p2)
|
||||
@ -34,11 +24,6 @@ Ret divide(P1 p1, P2 p2)
|
||||
return p1 / p2;
|
||||
}
|
||||
|
||||
Boxed_Value pod_divide(Boxed_POD_Value l, Boxed_POD_Value r)
|
||||
{
|
||||
return l / r;
|
||||
}
|
||||
|
||||
|
||||
template<typename Ret, typename P1, typename P2>
|
||||
Ret multiply(P1 p1, P2 p2)
|
||||
@ -46,11 +31,6 @@ Ret multiply(P1 p1, P2 p2)
|
||||
return p1 * p2;
|
||||
}
|
||||
|
||||
Boxed_Value pod_multiply(Boxed_POD_Value l, Boxed_POD_Value r)
|
||||
{
|
||||
return l * r;
|
||||
}
|
||||
|
||||
|
||||
template<typename P1, typename P2>
|
||||
bool bool_and(P1 p1, P2 p2)
|
||||
@ -88,10 +68,7 @@ bool equals(P1 p1, P2 p2)
|
||||
return p1 == p2;
|
||||
}
|
||||
|
||||
bool pod_equals(Boxed_POD_Value l, Boxed_POD_Value r)
|
||||
{
|
||||
return l == r;
|
||||
}
|
||||
|
||||
|
||||
template<typename P1, typename P2>
|
||||
bool not_equals(P1 p1, P2 p2)
|
||||
@ -99,11 +76,6 @@ bool not_equals(P1 p1, P2 p2)
|
||||
return p1 != p2;
|
||||
}
|
||||
|
||||
bool pod_not_equals(Boxed_POD_Value l, Boxed_POD_Value r)
|
||||
{
|
||||
return l != r;
|
||||
}
|
||||
|
||||
|
||||
template<typename P1, typename P2>
|
||||
bool less_than(P1 p1, P2 p2)
|
||||
@ -111,44 +83,24 @@ bool less_than(P1 p1, P2 p2)
|
||||
return p1 < p2;
|
||||
}
|
||||
|
||||
bool pod_less_than(Boxed_POD_Value l, Boxed_POD_Value r)
|
||||
{
|
||||
return l < r;
|
||||
}
|
||||
|
||||
template<typename P1, typename P2>
|
||||
bool greater_than(P1 p1, P2 p2)
|
||||
{
|
||||
return p1 > p2;
|
||||
}
|
||||
|
||||
bool pod_greater_than(Boxed_POD_Value l, Boxed_POD_Value r)
|
||||
{
|
||||
return l > r;
|
||||
}
|
||||
|
||||
template<typename P1, typename P2>
|
||||
bool less_than_equals(P1 p1, P2 p2)
|
||||
{
|
||||
return p1 <= p2;
|
||||
}
|
||||
|
||||
bool pod_less_than_equals(Boxed_POD_Value l, Boxed_POD_Value r)
|
||||
{
|
||||
return l <= r;
|
||||
}
|
||||
|
||||
template<typename P1, typename P2>
|
||||
bool greater_than_equals(P1 p1, P2 p2)
|
||||
{
|
||||
return p1 >= p2;
|
||||
}
|
||||
|
||||
bool pod_greater_than_equals(Boxed_POD_Value l, Boxed_POD_Value r)
|
||||
{
|
||||
return l >= r;
|
||||
}
|
||||
|
||||
template<typename P1, typename P2>
|
||||
P1 ×equal(P1 &p1, const P2 &p2)
|
||||
{
|
||||
@ -344,24 +296,6 @@ void add_opers_comparison_overload(Dispatch_Engine &s)
|
||||
register_function(s, &greater_than_equals<const T&, const R&>, ">=");
|
||||
}
|
||||
|
||||
void add_opers_comparison_pod(Dispatch_Engine &s)
|
||||
{
|
||||
register_function(s, &pod_equals, "==");
|
||||
register_function(s, &pod_not_equals, "!=");
|
||||
register_function(s, &pod_less_than, "<");
|
||||
register_function(s, &pod_greater_than, ">");
|
||||
register_function(s, &pod_less_than_equals, "<=");
|
||||
register_function(s, &pod_greater_than_equals, ">=");
|
||||
}
|
||||
|
||||
void add_opers_arithmetic_pod(Dispatch_Engine &s)
|
||||
{
|
||||
register_function(s, &pod_add, "+");
|
||||
register_function(s, &pod_subtract, "-");
|
||||
register_function(s, &pod_divide, "/");
|
||||
register_function(s, &pod_multiply, "*");
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void add_opers_comparison(Dispatch_Engine &s)
|
||||
{
|
||||
@ -436,15 +370,7 @@ class bad_boxed_value_cast : public std::bad_cast
|
||||
std::string m_val;
|
||||
};
|
||||
|
||||
Boxed_Value unknown_assign(Boxed_Value lhs, Boxed_Value rhs)
|
||||
{
|
||||
if (lhs.is_unknown())
|
||||
{
|
||||
return (lhs.assign(rhs));
|
||||
} else {
|
||||
throw bad_boxed_value_cast("boxed_value has a set type alread");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Built in to_string operator
|
||||
template<typename Input>
|
||||
@ -475,48 +401,59 @@ void bootstrap_pod_type(Dispatch_Engine &s, const std::string &name)
|
||||
register_function(s, &to_string<T>, "to_string");
|
||||
}
|
||||
|
||||
void print(const std::string &s)
|
||||
struct Bootstrap
|
||||
{
|
||||
std::cout << s << std::endl;
|
||||
}
|
||||
static Boxed_Value unknown_assign(Boxed_Value lhs, Boxed_Value rhs)
|
||||
{
|
||||
if (lhs.is_unknown())
|
||||
{
|
||||
return (lhs.assign(rhs));
|
||||
} else {
|
||||
throw bad_boxed_value_cast("boxed_value has a set type alread");
|
||||
}
|
||||
}
|
||||
|
||||
void bootstrap(Dispatch_Engine &s)
|
||||
{
|
||||
s.register_type<void>("void");
|
||||
static void print(const std::string &s)
|
||||
{
|
||||
std::cout << s << std::endl;
|
||||
}
|
||||
|
||||
s.register_type<std::string>("string");
|
||||
static void bootstrap(Dispatch_Engine &s)
|
||||
{
|
||||
s.register_type<void>("void");
|
||||
|
||||
add_basic_constructors<bool>(s, "bool");
|
||||
add_basic_constructors<std::string>(s, "string");
|
||||
add_oper_assign<std::string>(s);
|
||||
s.register_type<std::string>("string");
|
||||
|
||||
register_function(s, &to_string<const std::string &>, "to_string");
|
||||
register_function(s, &to_string<bool>, "to_string");
|
||||
register_function(s, &unknown_assign, "=");
|
||||
add_basic_constructors<bool>(s, "bool");
|
||||
add_basic_constructors<std::string>(s, "string");
|
||||
add_oper_assign<std::string>(s);
|
||||
|
||||
bootstrap_pod_type<double>(s, "double");
|
||||
bootstrap_pod_type<int>(s, "int");
|
||||
bootstrap_pod_type<size_t>(s, "size_t");
|
||||
bootstrap_pod_type<char>(s, "char");
|
||||
bootstrap_pod_type<int64_t>(s, "int64_t");
|
||||
register_function(s, &to_string<const std::string &>, "to_string");
|
||||
register_function(s, &to_string<bool>, "to_string");
|
||||
register_function(s, &unknown_assign, "=");
|
||||
|
||||
bootstrap_pod_type<double>(s, "double");
|
||||
bootstrap_pod_type<int>(s, "int");
|
||||
bootstrap_pod_type<size_t>(s, "size_t");
|
||||
bootstrap_pod_type<char>(s, "char");
|
||||
bootstrap_pod_type<int64_t>(s, "int64_t");
|
||||
|
||||
|
||||
|
||||
add_opers_comparison_pod(s);
|
||||
add_opers_arithmetic_pod(s);
|
||||
Pod_Bootstrap::add_opers_comparison(s);
|
||||
Pod_Bootstrap::add_opers_arithmetic(s);
|
||||
|
||||
add_oper_add<std::string>(s);
|
||||
add_oper_add_equals <std::string>(s);
|
||||
add_oper_add<std::string>(s);
|
||||
add_oper_add_equals <std::string>(s);
|
||||
|
||||
register_function(s, &print, "print_string");
|
||||
register_function(s, &print, "print_string");
|
||||
|
||||
s.register_function(boost::function<void ()>(boost::bind(&dump_system, boost::ref(s))), "dump_system");
|
||||
s.register_function(boost::function<void (Boxed_Value)>(boost::bind(&dump_object, _1)), "dump_object");
|
||||
s.register_function(boost::function<void ()>(boost::bind(&dump_system, boost::ref(s))), "dump_system");
|
||||
s.register_function(boost::function<void (Boxed_Value)>(boost::bind(&dump_object, _1)), "dump_object");
|
||||
|
||||
|
||||
register_function(s, &bool_and<bool, bool>, "&&");
|
||||
register_function(s, &bool_or<bool, bool>, "||");
|
||||
|
||||
}
|
||||
register_function(s, &bool_and<bool, bool>, "&&");
|
||||
register_function(s, &bool_or<bool, bool>, "||");
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
80
dispatchkit/bootstrap_pod.hpp
Normal file
80
dispatchkit/bootstrap_pod.hpp
Normal file
@ -0,0 +1,80 @@
|
||||
#ifndef __dispatchkit_bootstrap_pod_hpp__
|
||||
#define __dispatchkit_bootstrap_pod_hpp__
|
||||
|
||||
|
||||
#include "register_function.hpp"
|
||||
|
||||
|
||||
struct Pod_Bootstrap
|
||||
{
|
||||
static Boxed_Value add(Boxed_POD_Value l, Boxed_POD_Value r)
|
||||
{
|
||||
return l + r;
|
||||
}
|
||||
|
||||
static Boxed_Value subtract(Boxed_POD_Value l, Boxed_POD_Value r)
|
||||
{
|
||||
return l - r;
|
||||
}
|
||||
|
||||
static Boxed_Value divide(Boxed_POD_Value l, Boxed_POD_Value r)
|
||||
{
|
||||
return l / r;
|
||||
}
|
||||
|
||||
static Boxed_Value multiply(Boxed_POD_Value l, Boxed_POD_Value r)
|
||||
{
|
||||
return l * r;
|
||||
}
|
||||
|
||||
static bool equals(Boxed_POD_Value l, Boxed_POD_Value r)
|
||||
{
|
||||
return l == r;
|
||||
}
|
||||
|
||||
static bool not_equals(Boxed_POD_Value l, Boxed_POD_Value r)
|
||||
{
|
||||
return l != r;
|
||||
}
|
||||
|
||||
static bool less_than(Boxed_POD_Value l, Boxed_POD_Value r)
|
||||
{
|
||||
return l < r;
|
||||
}
|
||||
|
||||
static bool greater_than(Boxed_POD_Value l, Boxed_POD_Value r)
|
||||
{
|
||||
return l > r;
|
||||
}
|
||||
|
||||
static bool less_than_equals(Boxed_POD_Value l, Boxed_POD_Value r)
|
||||
{
|
||||
return l <= r;
|
||||
}
|
||||
|
||||
static bool greater_than_equals(Boxed_POD_Value l, Boxed_POD_Value r)
|
||||
{
|
||||
return l >= r;
|
||||
}
|
||||
|
||||
static void add_opers_comparison(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, ">=");
|
||||
}
|
||||
|
||||
static void add_opers_arithmetic(Dispatch_Engine &s)
|
||||
{
|
||||
register_function(s, &add, "+");
|
||||
register_function(s, &subtract, "-");
|
||||
register_function(s, ÷, "/");
|
||||
register_function(s, &multiply, "*");
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -83,7 +83,7 @@ class Boxed_Value
|
||||
boost::shared_ptr<Data> get(Boxed_Value::Void_Type)
|
||||
{
|
||||
return boost::shared_ptr<Data> (new Data(
|
||||
Get_Type_Info<void>()(),
|
||||
Get_Type_Info<void>::get(),
|
||||
boost::any(),
|
||||
false)
|
||||
);
|
||||
@ -93,7 +93,7 @@ class Boxed_Value
|
||||
boost::shared_ptr<Data> get(boost::shared_ptr<T> obj)
|
||||
{
|
||||
boost::shared_ptr<Data> data(new Data(
|
||||
Get_Type_Info<T>()(),
|
||||
Get_Type_Info<T>::get(),
|
||||
boost::any(obj),
|
||||
false,
|
||||
boost::shared_ptr<Data::Shared_Ptr_Proxy>(new Data::Shared_Ptr_Proxy_Impl<T>()))
|
||||
@ -116,7 +116,7 @@ class Boxed_Value
|
||||
boost::shared_ptr<Data> get(boost::reference_wrapper<T> obj)
|
||||
{
|
||||
boost::shared_ptr<Data> data(new Data(
|
||||
Get_Type_Info<T>()(),
|
||||
Get_Type_Info<T>::get(),
|
||||
boost::any(obj),
|
||||
true)
|
||||
);
|
||||
@ -137,7 +137,7 @@ class Boxed_Value
|
||||
boost::shared_ptr<Data> get(const T& t)
|
||||
{
|
||||
boost::shared_ptr<Data> data(new Data(
|
||||
Get_Type_Info<T>()(),
|
||||
Get_Type_Info<T>::get(),
|
||||
boost::any(boost::shared_ptr<T>(new T(t))),
|
||||
false,
|
||||
boost::shared_ptr<Data::Shared_Ptr_Proxy>(new Data::Shared_Ptr_Proxy_Impl<T>()))
|
||||
|
@ -108,7 +108,7 @@ class Dispatch_Engine
|
||||
template<typename Type>
|
||||
void register_type(const std::string &name)
|
||||
{
|
||||
m_types.insert(std::make_pair(name, Get_Type_Info<Type>()()));
|
||||
m_types.insert(std::make_pair(name, Get_Type_Info<Type>::get()));
|
||||
}
|
||||
|
||||
std::vector<Type_Name_Map::value_type> get_types() const
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <boost/preprocessor.hpp>
|
||||
|
||||
#define gettypeinfo(z,n,text) ti.push_back(Get_Type_Info<Param ## n>()());
|
||||
#define gettypeinfo(z,n,text) ti.push_back(Get_Type_Info<Param ## n>::get());
|
||||
#define casthelper(z,n,text) ,Cast_Helper<Param ## n>()(params[n])
|
||||
|
||||
|
||||
@ -69,7 +69,7 @@ template<typename Ret>
|
||||
std::vector<Type_Info> build_param_type_list(const boost::function<Ret ()> &f)
|
||||
{
|
||||
std::vector<Type_Info> ti;
|
||||
ti.push_back(Get_Type_Info<Ret>()());
|
||||
ti.push_back(Get_Type_Info<Ret>::get());
|
||||
return ti;
|
||||
}
|
||||
|
||||
@ -205,7 +205,7 @@ template<typename Ret, BOOST_PP_ENUM_PARAMS(n, typename Param) >
|
||||
std::vector<Type_Info> build_param_type_list(const boost::function<Ret (BOOST_PP_ENUM_PARAMS(n, Param))> &f)
|
||||
{
|
||||
std::vector<Type_Info> ti;
|
||||
ti.push_back(Get_Type_Info<Ret>()());
|
||||
ti.push_back(Get_Type_Info<Ret>::get());
|
||||
|
||||
BOOST_PP_REPEAT(n, gettypeinfo, ~)
|
||||
|
||||
|
@ -88,7 +88,7 @@ void test(const std::string &p)
|
||||
int main()
|
||||
{
|
||||
Dispatch_Engine ss;
|
||||
bootstrap(ss);
|
||||
Bootstrap::bootstrap(ss);
|
||||
bootstrap_vector<std::vector<int> >(ss, "VectorInt");
|
||||
dump_system(ss);
|
||||
|
||||
|
@ -44,7 +44,7 @@ struct Type_Info
|
||||
template<typename T>
|
||||
struct Get_Type_Info
|
||||
{
|
||||
Type_Info operator()()
|
||||
static Type_Info get()
|
||||
{
|
||||
return Type_Info(boost::is_const<T>::value, boost::is_reference<T>::value, boost::is_pointer<T>::value,
|
||||
boost::is_void<T>::value,
|
||||
@ -56,7 +56,7 @@ struct Get_Type_Info
|
||||
template<typename T>
|
||||
struct Get_Type_Info<boost::shared_ptr<T> >
|
||||
{
|
||||
Type_Info operator()()
|
||||
static Type_Info get()
|
||||
{
|
||||
return Type_Info(boost::is_const<T>::value, boost::is_reference<T>::value, boost::is_pointer<T>::value,
|
||||
boost::is_void<T>::value,
|
||||
@ -68,7 +68,7 @@ struct Get_Type_Info<boost::shared_ptr<T> >
|
||||
template<typename T>
|
||||
struct Get_Type_Info<boost::reference_wrapper<T> >
|
||||
{
|
||||
Type_Info operator()()
|
||||
static Type_Info get()
|
||||
{
|
||||
return Type_Info(boost::is_const<T>::value, boost::is_reference<T>::value, boost::is_pointer<T>::value,
|
||||
boost::is_void<T>::value,
|
||||
|
@ -8,10 +8,8 @@
|
||||
BOOST_AUTO_TEST_CASE( add_operators )
|
||||
{
|
||||
Dispatch_Engine ss;
|
||||
bootstrap(ss);
|
||||
Bootstrap::bootstrap(ss);
|
||||
dump_system(ss);
|
||||
|
||||
BOOST_CHECK_EQUAL(Cast_Helper<int>()(dispatch(ss.get_function("+"), Param_List_Builder() << double(5.1) << double(10.3))), 15.4);
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user