diff --git a/boxedcpp/bootstrap_stl.hpp b/boxedcpp/bootstrap_stl.hpp index b6e5562..aab67df 100644 --- a/boxedcpp/bootstrap_stl.hpp +++ b/boxedcpp/bootstrap_stl.hpp @@ -4,32 +4,36 @@ #include "boxedcpp.hpp" template -void bootstrap_reversible_container(BoxedCPP_System &system) +void bootstrap_reversible_container(BoxedCPP_System &system, const std::string &type) { } template -void bootstrap_random_access_container(BoxedCPP_System &system) +void bootstrap_random_access_container(BoxedCPP_System &system, const std::string &type) { - bootstrap_reversible_container(system); + bootstrap_reversible_container(system, type); typedef typename ContainerType::reference(ContainerType::*indexoper)(size_t); system.register_function( boost::function(indexoper(&ContainerType::operator[])), "[]"); + system.register_function( + boost::function(indexoper(&ContainerType::at)), "at"); } template -void bootstrap_assignable(BoxedCPP_System &system) +void bootstrap_assignable(BoxedCPP_System &system, const std::string &type) { + /* system.register_function( boost::function(&Assignable::operator=), "="); + */ } template -void bootstrap_container(BoxedCPP_System &system) +void bootstrap_container(BoxedCPP_System &system, const std::string &type) { - bootstrap_assignable(system); + bootstrap_assignable(system, type); system.register_function( boost::function(&ContainerType::size), "size"); @@ -38,27 +42,28 @@ void bootstrap_container(BoxedCPP_System &system) } template -void bootstrap_forward_container(BoxedCPP_System &system) +void bootstrap_forward_container(BoxedCPP_System &system, const std::string &type) { - bootstrap_container(system); + bootstrap_container(system, type); } template -void bootstrap_default_constructible(BoxedCPP_System &system) +void bootstrap_default_constructible(BoxedCPP_System &system, const std::string &type) { + system.register_function(build_constructor(), type); } template -void bootstrap_sequence(BoxedCPP_System &system) +void bootstrap_sequence(BoxedCPP_System &system, const std::string &type) { - bootstrap_forward_container(system); - bootstrap_default_constructible(system); + bootstrap_forward_container(system, type); + bootstrap_default_constructible(system, type); } template -void bootstrap_back_insertion_sequence(BoxedCPP_System &system) +void bootstrap_back_insertion_sequence(BoxedCPP_System &system, const std::string &type) { - bootstrap_sequence(system); + bootstrap_sequence(system, type); typedef typename SequenceType::reference (SequenceType::*backptr)(); @@ -69,10 +74,11 @@ void bootstrap_back_insertion_sequence(BoxedCPP_System &system) } template -void bootstrap_vector(BoxedCPP_System &system) +void bootstrap_vector(BoxedCPP_System &system, const std::string &type) { - bootstrap_random_access_container(system); - bootstrap_back_insertion_sequence(system); + system.register_type(type); + bootstrap_random_access_container(system, type); + bootstrap_back_insertion_sequence(system, type); } #endif diff --git a/boxedcpp/boxed_value.hpp b/boxedcpp/boxed_value.hpp index 755f2b3..7d3c92f 100644 --- a/boxedcpp/boxed_value.hpp +++ b/boxedcpp/boxed_value.hpp @@ -89,6 +89,20 @@ struct Cast_Helper } }; +template +struct Cast_Helper +{ + const Result *operator()(Boxed_Value ob) + { + if (ob.is_ref()) + { + return (boost::any_cast >(ob.get())).get_pointer(); + } else { + return (boost::any_cast >(ob.get())).get(); + } + } +}; + template struct Cast_Helper { diff --git a/boxedcpp/test.cpp b/boxedcpp/test.cpp index 02b313c..431c811 100644 --- a/boxedcpp/test.cpp +++ b/boxedcpp/test.cpp @@ -90,7 +90,7 @@ int main() { BoxedCPP_System ss; bootstrap(ss); - bootstrap_vector >(ss); + bootstrap_vector >(ss, "VectorInt"); dump_system(ss); //Calling a function by name and allowing the built in dispatch mechanism to diff --git a/wesley/main.cpp b/wesley/main.cpp index f6d79a9..d39c17d 100644 --- a/wesley/main.cpp +++ b/wesley/main.cpp @@ -430,14 +430,15 @@ Lexer build_lexer() { BoxedCPP_System build_eval_system() { BoxedCPP_System ss; bootstrap(ss); - bootstrap_vector >(ss); - //dump_system(ss); + bootstrap_vector >(ss, "VectorInt"); +// dump_system(ss); //Register a new function, this one with typing for us, so we don't have to ubox anything //right here register_function(ss, &print, "print"); register_function(ss, &print, "print"); register_function(ss, &print, "print"); + register_function(ss, &print, "print"); register_function(ss, &concat_string, "concat_string"); register_function(ss, &print, "print"); @@ -516,7 +517,11 @@ int main(int argc, char *argv[]) { Boxed_Value val = evaluate_string(lexer, parser, ss, input, "__EVAL__"); if (*(val.get_type_info().m_bare_type_info) != typeid(void)) { std::cout << "result: "; - dispatch(ss.get_function("print"), Param_List_Builder() << val); + try { + dispatch(ss.get_function("print"), Param_List_Builder() << val); + } catch (const std::runtime_error &e) { + std::cout << "unhandled type: " << val.get_type_info().m_type_info->name() << std::endl; + } } std::cout << "eval> "; std::getline(std::cin, input);