diff --git a/boxedcpp/bootstrap.hpp b/boxedcpp/bootstrap.hpp new file mode 100644 index 00000000..ebd0d793 --- /dev/null +++ b/boxedcpp/bootstrap.hpp @@ -0,0 +1,85 @@ +#ifndef __bootstrap_hpp +#define __bootstrap_hpp__ + +#include "boxedcpp.hpp" + +template +Ret add(P1 p1, P2 p2) +{ + return p1 + p2; +} + +template +Ret subtract(P1 p1, P2 p2) +{ + return p1 - p2; +} + +template +Ret divide(P1 p1, P2 p2) +{ + return p1 - p2; +} + + +template +Ret multiply(P1 p1, P2 p2) +{ + return p1 * p2; +} + +template +P1 ×equal(P1 &p1, P2 p2) +{ + return (p1 *= p2); +} + +template +std::string to_string(Input i) +{ + return boost::lexical_cast(i); +} + +void bootstrap(BoxedCPP_System &s) +{ + s.register_type("void"); + s.register_type("double"); + s.register_type("int"); + s.register_type("char"); + s.register_type("string"); + + s.register_function(boost::function(&add), "+"); + + s.register_function(boost::function(&add), "+"); + s.register_function(boost::function(&add), "+"); + s.register_function(boost::function(&add), "+"); + s.register_function(boost::function(&add), "+"); + + s.register_function(boost::function(&subtract), "-"); + s.register_function(boost::function(&subtract), "-"); + s.register_function(boost::function(&subtract), "-"); + s.register_function(boost::function(&subtract), "-"); + + s.register_function(boost::function), "/"); + s.register_function(boost::function), "/"); + s.register_function(boost::function), "/"); + s.register_function(boost::function), "/"); + + s.register_function(boost::function(&multiply), "*"); + s.register_function(boost::function(&multiply), "*"); + s.register_function(boost::function(&multiply), "*"); + s.register_function(boost::function(&multiply), "*"); + + s.register_function(boost::function(&to_string), "to_string"); + s.register_function(boost::function(&to_string), "to_string"); + s.register_function(boost::function(&to_string), "to_string"); + s.register_function(boost::function(&to_string), "to_string"); + + s.register_function(boost::function(×equal), "*="); + s.register_function(boost::function(×equal), "*="); + s.register_function(boost::function(×equal), "*="); + s.register_function(boost::function(×equal), "*="); + +} + +#endif diff --git a/boxedcpp/boxedcpp.hpp b/boxedcpp/boxedcpp.hpp index 48297ebc..facd578a 100644 --- a/boxedcpp/boxedcpp.hpp +++ b/boxedcpp/boxedcpp.hpp @@ -130,88 +130,6 @@ void dump_system(const BoxedCPP_System &s) std::cout << std::endl; } -template -Ret add(P1 p1, P2 p2) -{ - return p1 + p2; -} -template -Ret subtract(P1 p1, P2 p2) -{ - return p1 - p2; -} - -template -Ret divide(P1 p1, P2 p2) -{ - return p1 - p2; -} - - -template -Ret multiply(P1 p1, P2 p2) -{ - return p1 * p2; -} - -template -P1 ×equal(P1 &p1, P2 p2) -{ - return (p1 *= p2); -} - -template -std::string to_string(Input i) -{ - return boost::lexical_cast(i); -} - -void bootstrap(BoxedCPP_System &s) -{ - s.register_type("void"); - s.register_type("double"); - s.register_type("int"); - s.register_type("char"); - s.register_type("string"); - - s.register_function(boost::function(&add), "+"); - - s.register_function(boost::function(&add), "+"); - s.register_function(boost::function(&add), "+"); - s.register_function(boost::function(&add), "+"); - s.register_function(boost::function(&add), "+"); - - s.register_function(boost::function(&subtract), "-"); - s.register_function(boost::function(&subtract), "-"); - s.register_function(boost::function(&subtract), "-"); - s.register_function(boost::function(&subtract), "-"); - - s.register_function(boost::function), "/"); - s.register_function(boost::function), "/"); - s.register_function(boost::function), "/"); - s.register_function(boost::function), "/"); - - s.register_function(boost::function(&multiply), "*"); - s.register_function(boost::function(&multiply), "*"); - s.register_function(boost::function(&multiply), "*"); - s.register_function(boost::function(&multiply), "*"); - - s.register_function(boost::function(&to_string), "to_string"); - s.register_function(boost::function(&to_string), "to_string"); - s.register_function(boost::function(&to_string), "to_string"); - s.register_function(boost::function(&to_string), "to_string"); - - s.register_function(boost::function(×equal), "*="); - s.register_function(boost::function(×equal), "*="); - s.register_function(boost::function(×equal), "*="); - s.register_function(boost::function(×equal), "*="); - - - - - - -} #endif diff --git a/boxedcpp/test.cpp b/boxedcpp/test.cpp index 6ff7217e..4a7cbb06 100644 --- a/boxedcpp/test.cpp +++ b/boxedcpp/test.cpp @@ -5,6 +5,7 @@ #include #include "boxedcpp.hpp" +#include "bootstrap.hpp" struct Test { diff --git a/boxedcpp/unittest.cpp b/boxedcpp/unittest.cpp index ec2aafa3..c382206f 100644 --- a/boxedcpp/unittest.cpp +++ b/boxedcpp/unittest.cpp @@ -1,4 +1,5 @@ #include "boxedcpp.hpp" +#include "bootstrap.hpp" #define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE boxedcpp_unittests