From db6fe9134f18c9d5067963259fd247aa6aa196ca Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Mon, 8 Jun 2009 04:41:13 +0000 Subject: [PATCH] Fix some bootstrapping of types and add more type support --- boxedcpp/bootstrap.hpp | 90 +++++++++++++++++++++++++++--------------- samples/vector.wes | 2 +- 2 files changed, 60 insertions(+), 32 deletions(-) diff --git a/boxedcpp/bootstrap.hpp b/boxedcpp/bootstrap.hpp index bf92573..d05525d 100644 --- a/boxedcpp/bootstrap.hpp +++ b/boxedcpp/bootstrap.hpp @@ -144,6 +144,13 @@ 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) { @@ -212,6 +219,12 @@ void add_basic_constructors(BoxedCPP_System &s, const std::string &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) { @@ -225,53 +238,68 @@ 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("double"); - s.register_type("int"); - s.register_type("char"); - s.register_type("bool"); + 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"); - - s.register_function(build_constructor(), "int"); - - - - add_opers_comparison(s); - add_opers_comparison(s); - add_opers_comparison(s); - add_opers_comparison(s); - - add_oper_assign(s); - add_oper_assign(s); - add_oper_assign(s); 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_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 diff --git a/samples/vector.wes b/samples/vector.wes index a7268d7..88391f1 100644 --- a/samples/vector.wes +++ b/samples/vector.wes @@ -5,7 +5,7 @@ vec.push_back("Hello World") vec.push_back(25.3) -var i = int(0) +var i = 0 var size = int(vec.size()) print("Vector Size: " + size.to_string());