#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 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, 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_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, "*="); } 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); } void bootstrap(BoxedCPP_System &s) { s.register_type("void"); s.register_type("double"); s.register_type("int"); s.register_type("char"); s.register_type("bool"); s.register_type("string"); add_opers_comparison(s); add_opers_comparison(s); add_opers_comparison(s); add_opers_comparison(s); add_opers_comparison_overload(s); add_opers_comparison_overload(s); add_opers_arithmetic(s); add_opers_arithmetic(s); add_opers_arithmetic_overload(s); add_opers_arithmetic_overload(s); add_oper_add(s); register_function(s, &bool_and, "&&"); register_function(s, &bool_or, "||"); register_function(s, &to_string, "to_string"); register_function(s, &to_string, "to_string"); register_function(s, &to_string, "to_string"); register_function(s, &to_string, "to_string"); } #endif