#ifndef __bootstrap_hpp #define __bootstrap_hpp__ #include "boxedcpp.hpp" #include "register_function.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 bool bool_and(P1 p1, P2 p2) { return p1 && p2; } template bool bool_or(P1 p1, P2 p2) { return p1 || p2; } template P1 &assign(P1 &p1, const P2 &p2) { return (p1 = p2); } template bool equals(P1 p1, P2 p2) { return p1 == p2; } template bool not_equals(P1 p1, P2 p2) { return p1 != p2; } template bool less_than(P1 p1, P2 p2) { return p1 < p2; } template bool greater_than(P1 p1, P2 p2) { return p1 > p2; } template bool less_than_equals(P1 p1, P2 p2) { return p1 <= p2; } template bool greater_than_equals(P1 p1, P2 p2) { return p1 >= p2; } template P1 ×equal(P1 &p1, const P2 &p2) { return (p1 *= p2); } template P1 ÷sequal(P1 &p1, const P2 &p2) { return (p1 /= p2); } template P1 &addsequal(P1 &p1, const P2 &p2) { return (p1 += p2); } template P1 &subtractsequal(P1 &p1, const P2 &p2) { return (p1 -= p2); } //Add canonical forms of operators template void add_oper_equals(BoxedCPP_System &s) { register_function(s, &equals, "="); } template void add_oper_add(BoxedCPP_System &s) { register_function(s, &add, "+"); } template void add_oper_subtract(BoxedCPP_System &s) { register_function(s, &subtract, "-"); } template void add_oper_divide(BoxedCPP_System &s) { register_function(s, ÷, "-"); } template void add_oper_multiply(BoxedCPP_System &s) { register_function(s, &multiply, "*"); } template void add_oper_not_equals(BoxedCPP_System &s) { register_function(s, ¬_equals, "!="); } template void add_oper_assign_overload(BoxedCPP_System &s) { register_function(s, &assign, "="); } template void add_oper_assign(BoxedCPP_System &s) { register_function(s, &assign, "="); } template void add_oper_less_than(BoxedCPP_System &s) { register_function(s, &less_than, "<"); } template void add_oper_greater_than(BoxedCPP_System &s) { register_function(s, &greater_than, ">"); } template void add_oper_less_than_equals(BoxedCPP_System &s) { register_function(s, &less_than_equals, "<="); } template void add_oper_greater_than_equals(BoxedCPP_System &s) { register_function(s, &greater_than_equals, ">="); } template void add_opers_comparison_overload(BoxedCPP_System &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, ">="); } template void add_opers_comparison(BoxedCPP_System &s) { add_opers_comparison_overload(s); } template void add_opers_arithmetic_overload(BoxedCPP_System &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, "+="); } template void add_basic_constructors(BoxedCPP_System &s, const std::string &type) { s.register_function(build_constructor(), type); s.register_function(build_constructor(), type); } template void add_constructor_overload(BoxedCPP_System &s, const std::string &type) { s.register_function(build_constructor(), type); } template void add_opers_arithmetic(BoxedCPP_System &s) { add_opers_arithmetic_overload(s); } //Built in to_string operator template std::string to_string(Input i) { return boost::lexical_cast(i); } std::string to_string(bool b) { if (b) { return "true"; } else { return "false"; } } template void bootstrap_pod_type(BoxedCPP_System &s, const std::string &name) { s.register_type(name); add_basic_constructors(s, name); add_oper_assign(s); add_opers_arithmetic(s); add_opers_comparison(s); register_function(s, &to_string, "to_string"); add_constructor_overload(s, name); add_constructor_overload(s, name); add_constructor_overload(s, name); /* add_opers_comparison_overload(s); add_opers_comparison_overload(s); add_opers_comparison_overload(s); */ } void bootstrap(BoxedCPP_System &s) { s.register_type("void"); s.register_type("string"); add_basic_constructors(s, "double"); add_basic_constructors(s, "int"); add_basic_constructors(s, "char"); add_basic_constructors(s, "bool"); add_basic_constructors(s, "string"); add_oper_assign(s); register_function(s, &to_string, "to_string"); bootstrap_pod_type(s, "double"); bootstrap_pod_type(s, "int"); bootstrap_pod_type(s, "size_t"); bootstrap_pod_type(s, "char"); add_opers_arithmetic_overload(s); add_opers_arithmetic_overload(s); add_opers_arithmetic_overload(s); add_opers_arithmetic_overload(s); add_opers_comparison_overload(s); add_opers_comparison_overload(s); add_oper_add(s); register_function(s, &bool_and, "&&"); register_function(s, &bool_or, "||"); } #endif