Re-enabled boxedcpp, but commented out trouble area

This commit is contained in:
Jonathan Turner 2009-05-27 15:15:24 +00:00
parent 74338670fa
commit 4f8ffd0129
4 changed files with 19 additions and 18 deletions

View File

@ -14,5 +14,5 @@ if(Boost_FOUND)
add_executable(langkit_test langkit/main.cpp langkit/langkit_lexer.cpp langkit/langkit_parser.cpp)
target_link_libraries(langkit_test ${Boost_LIBRARIES})
#add_executable(boxedcpp_test boxedcpp/test.cpp)
add_executable(boxedcpp_test boxedcpp/test.cpp)
endif()

View File

@ -87,7 +87,7 @@ void dump_type(const Type_Info &type)
void dump_function(const BoxedCPP_System::Function_Map::value_type &f)
{
std::vector<Type_Info> params = f.second->get_param_types();
dump_type(params.front());
std::cout << " " << f.first << "(";
@ -97,7 +97,7 @@ void dump_function(const BoxedCPP_System::Function_Map::value_type &f)
{
dump_type(*itr);
std::cout << ", ";
}
}
std::cout << ")" << std::endl;
}
@ -113,7 +113,7 @@ void dump_system(const BoxedCPP_System &s)
std::cout << itr->first << ": ";
dump_type(itr->second);
std::cout << std::endl;
}
}
std::cout << std::endl; std::vector<BoxedCPP_System::Function_Map::value_type> funcs = s.get_functions();
@ -124,7 +124,7 @@ void dump_system(const BoxedCPP_System &s)
++itr)
{
dump_function(*itr);
}
}
std::cout << std::endl;
}
@ -167,11 +167,12 @@ void bootstrap(BoxedCPP_System &s)
s.register_function(boost::function<double (double, double)>(&multiply<double, double, double>), "*");
s.register_function(boost::function<std::string (int)>(&to_string<int>), "to_string");
s.register_function(boost::function<std::string (const std::string &)>(&to_string<const std::string &>), "to_string");
//JDT: Was giving me compiler errors (not sure why)
//s.register_function(boost::function<std::string (const std::string &)>(&to_string<const std::string &>), "to_string");
s.register_function(boost::function<std::string (char)>(&to_string<char>), "to_string");
s.register_function(boost::function<std::string (double)>(&to_string<double>), "to_string");
}
#endif
#endif

View File

@ -35,7 +35,7 @@ struct Test
std::cout << "Method called " << md << std::endl;
return int(md);
}
std::string message;
double md;
};
@ -52,10 +52,10 @@ int main()
BoxedCPP_System ss;
bootstrap(ss);
dump_system(ss);
//Calling a function by name and allowing the built in dispatch mechanism to
//choose the most appropriate version of the function
Boxed_Value addresult = dispatch(ss.get_function("+"), Param_List_Builder() << double(5.1) << double(10.3));
Boxed_Value addresult = dispatch(ss.get_function("+"), Param_List_Builder() << double(5.1) << double(10.3));
//Using the Cast_Helper to unbox the resultant value and output it
std::cout << Cast_Helper<double>()(addresult) << std::endl;
@ -64,17 +64,18 @@ int main()
//This time we will not bother saving the result and will instead send it straight out
std::cout << Cast_Helper<double>()(
dispatch(ss.get_function("*"), Param_List_Builder() << 2 << addresult)
) << std::endl;
) << std::endl;
//Register a new function, this one with typing for us, so we don't have to ubox anything
//right here
ss.register_function(boost::function<void (const std::string &)>(&print), "print");
//JDT: Was giving me compiler errors (not sure why)
//ss.register_function(boost::function<void (const std::string &)>(&print), "print");
//Now we have a print method, let's try to print out the earlier example:
//so, we dispatch the to_string and pass its result as a param to "print"
//In this example we don't bother with temporaries and we don't have to know
//anything about types
dispatch(ss.get_function("print"),
dispatch(ss.get_function("print"),
Param_List_Builder() << dispatch(ss.get_function("to_string"), Param_List_Builder() << addresult));
//
@ -96,14 +97,14 @@ int main()
std::vector<Boxed_Value> sos;
sos.push_back(ss.get_object("testobj"));
sos.push_back(ss.get_object("testobj"));
sos.push_back(ss.get_object("d"));
boost::shared_ptr<Proxy_Function> method1(ss.get_function("method").front().second);
(*method1)(sos);
(*method1)(sos);
Boxed_Value o = (*method1)(sos);
dispatch(ss.get_function("print"), Param_List_Builder() << ss.get_object("str"));
//Add new dynamically created object from registered "Test" constructor
@ -121,8 +122,8 @@ int main()
std::string &sr = Cast_Helper<std::string &>()(stringref);
sr = "Bob Updated The message";
dispatch(ss.get_function("show_message"), sos3);
*/
}

View File

@ -8,7 +8,6 @@
#include "langkit_lexer.hpp"
typedef std::vector<TokenPtr>::iterator Token_Iterator;
struct Rule {