Re-enabled boxedcpp, but commented out trouble area
This commit is contained in:
@@ -14,5 +14,5 @@ if(Boost_FOUND)
|
|||||||
add_executable(langkit_test langkit/main.cpp langkit/langkit_lexer.cpp langkit/langkit_parser.cpp)
|
add_executable(langkit_test langkit/main.cpp langkit/langkit_lexer.cpp langkit/langkit_parser.cpp)
|
||||||
target_link_libraries(langkit_test ${Boost_LIBRARIES})
|
target_link_libraries(langkit_test ${Boost_LIBRARIES})
|
||||||
|
|
||||||
#add_executable(boxedcpp_test boxedcpp/test.cpp)
|
add_executable(boxedcpp_test boxedcpp/test.cpp)
|
||||||
endif()
|
endif()
|
||||||
|
@@ -87,7 +87,7 @@ void dump_type(const Type_Info &type)
|
|||||||
void dump_function(const BoxedCPP_System::Function_Map::value_type &f)
|
void dump_function(const BoxedCPP_System::Function_Map::value_type &f)
|
||||||
{
|
{
|
||||||
std::vector<Type_Info> params = f.second->get_param_types();
|
std::vector<Type_Info> params = f.second->get_param_types();
|
||||||
|
|
||||||
dump_type(params.front());
|
dump_type(params.front());
|
||||||
std::cout << " " << f.first << "(";
|
std::cout << " " << f.first << "(";
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ void dump_function(const BoxedCPP_System::Function_Map::value_type &f)
|
|||||||
{
|
{
|
||||||
dump_type(*itr);
|
dump_type(*itr);
|
||||||
std::cout << ", ";
|
std::cout << ", ";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << ")" << std::endl;
|
std::cout << ")" << std::endl;
|
||||||
}
|
}
|
||||||
@@ -113,7 +113,7 @@ void dump_system(const BoxedCPP_System &s)
|
|||||||
std::cout << itr->first << ": ";
|
std::cout << itr->first << ": ";
|
||||||
dump_type(itr->second);
|
dump_type(itr->second);
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::cout << std::endl; std::vector<BoxedCPP_System::Function_Map::value_type> funcs = s.get_functions();
|
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)
|
++itr)
|
||||||
{
|
{
|
||||||
dump_function(*itr);
|
dump_function(*itr);
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
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<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 (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 (char)>(&to_string<char>), "to_string");
|
||||||
s.register_function(boost::function<std::string (double)>(&to_string<double>), "to_string");
|
s.register_function(boost::function<std::string (double)>(&to_string<double>), "to_string");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -35,7 +35,7 @@ struct Test
|
|||||||
std::cout << "Method called " << md << std::endl;
|
std::cout << "Method called " << md << std::endl;
|
||||||
return int(md);
|
return int(md);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string message;
|
std::string message;
|
||||||
double md;
|
double md;
|
||||||
};
|
};
|
||||||
@@ -52,10 +52,10 @@ int main()
|
|||||||
BoxedCPP_System ss;
|
BoxedCPP_System ss;
|
||||||
bootstrap(ss);
|
bootstrap(ss);
|
||||||
dump_system(ss);
|
dump_system(ss);
|
||||||
|
|
||||||
//Calling a function by name and allowing the built in dispatch mechanism to
|
//Calling a function by name and allowing the built in dispatch mechanism to
|
||||||
//choose the most appropriate version of the function
|
//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
|
//Using the Cast_Helper to unbox the resultant value and output it
|
||||||
std::cout << Cast_Helper<double>()(addresult) << std::endl;
|
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
|
//This time we will not bother saving the result and will instead send it straight out
|
||||||
std::cout << Cast_Helper<double>()(
|
std::cout << Cast_Helper<double>()(
|
||||||
dispatch(ss.get_function("*"), Param_List_Builder() << 2 << addresult)
|
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
|
//Register a new function, this one with typing for us, so we don't have to ubox anything
|
||||||
//right here
|
//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:
|
//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"
|
//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
|
//In this example we don't bother with temporaries and we don't have to know
|
||||||
//anything about types
|
//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));
|
Param_List_Builder() << dispatch(ss.get_function("to_string"), Param_List_Builder() << addresult));
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -96,14 +97,14 @@ int main()
|
|||||||
|
|
||||||
|
|
||||||
std::vector<Boxed_Value> sos;
|
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"));
|
sos.push_back(ss.get_object("d"));
|
||||||
|
|
||||||
boost::shared_ptr<Proxy_Function> method1(ss.get_function("method").front().second);
|
boost::shared_ptr<Proxy_Function> method1(ss.get_function("method").front().second);
|
||||||
(*method1)(sos);
|
(*method1)(sos);
|
||||||
(*method1)(sos);
|
(*method1)(sos);
|
||||||
Boxed_Value o = (*method1)(sos);
|
Boxed_Value o = (*method1)(sos);
|
||||||
|
|
||||||
dispatch(ss.get_function("print"), Param_List_Builder() << ss.get_object("str"));
|
dispatch(ss.get_function("print"), Param_List_Builder() << ss.get_object("str"));
|
||||||
|
|
||||||
//Add new dynamically created object from registered "Test" constructor
|
//Add new dynamically created object from registered "Test" constructor
|
||||||
@@ -121,8 +122,8 @@ int main()
|
|||||||
|
|
||||||
std::string &sr = Cast_Helper<std::string &>()(stringref);
|
std::string &sr = Cast_Helper<std::string &>()(stringref);
|
||||||
sr = "Bob Updated The message";
|
sr = "Bob Updated The message";
|
||||||
|
|
||||||
dispatch(ss.get_function("show_message"), sos3);
|
dispatch(ss.get_function("show_message"), sos3);
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
#include "langkit_lexer.hpp"
|
#include "langkit_lexer.hpp"
|
||||||
|
|
||||||
|
|
||||||
typedef std::vector<TokenPtr>::iterator Token_Iterator;
|
typedef std::vector<TokenPtr>::iterator Token_Iterator;
|
||||||
|
|
||||||
struct Rule {
|
struct Rule {
|
||||||
|
Reference in New Issue
Block a user