Merge branch 'performance_evaluations' into performance_test
This commit is contained in:
commit
dc3ef087e2
@ -207,7 +207,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
static void println(const std::string &s)
|
static void println(const std::string &s)
|
||||||
{
|
{
|
||||||
std::cout << s << std::endl;
|
std::cout << s << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -443,7 +443,7 @@ namespace chaiscript
|
|||||||
operators::assign<bool>(m);
|
operators::assign<bool>(m);
|
||||||
operators::equal<bool>(m);
|
operators::equal<bool>(m);
|
||||||
|
|
||||||
m->add(fun(&to_string<const std::string &>), "to_string");
|
m->add(fun<std::string (const std::string &t_ss)>([](const std::string &s) -> std::string { return s; }), "to_string");
|
||||||
m->add(fun(&Bootstrap::bool_to_string), "to_string");
|
m->add(fun(&Bootstrap::bool_to_string), "to_string");
|
||||||
m->add(fun(&unknown_assign), "=");
|
m->add(fun(&unknown_assign), "=");
|
||||||
m->add(fun(&throw_exception), "throw");
|
m->add(fun(&throw_exception), "throw");
|
||||||
|
@ -89,13 +89,13 @@ namespace chaiscript
|
|||||||
if (t_conversions && t_conversions->convertable_type<Type>())
|
if (t_conversions && t_conversions->convertable_type<Type>())
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
// std::cout << "trying an up conversion " << typeid(Type).name() << std::endl;
|
// std::cout << "trying an up conversion " << typeid(Type).name() << '\n';
|
||||||
// We will not catch any bad_boxed_dynamic_cast that is thrown, let the user get it
|
// We will not catch any bad_boxed_dynamic_cast that is thrown, let the user get it
|
||||||
// either way, we are not responsible if it doesn't work
|
// either way, we are not responsible if it doesn't work
|
||||||
return detail::Cast_Helper<Type>::cast(t_conversions->boxed_type_conversion<Type>(bv), t_conversions);
|
return detail::Cast_Helper<Type>::cast(t_conversions->boxed_type_conversion<Type>(bv), t_conversions);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
try {
|
try {
|
||||||
// std::cout << "trying a down conversion " << typeid(Type).name() << std::endl;
|
// std::cout << "trying a down conversion " << typeid(Type).name() << '\n';
|
||||||
// try going the other way - down the inheritance graph
|
// try going the other way - down the inheritance graph
|
||||||
return detail::Cast_Helper<Type>::cast(t_conversions->boxed_type_down_conversion<Type>(bv), t_conversions);
|
return detail::Cast_Helper<Type>::cast(t_conversions->boxed_type_down_conversion<Type>(bv), t_conversions);
|
||||||
} catch (const chaiscript::detail::exception::bad_any_cast &) {
|
} catch (const chaiscript::detail::exception::bad_any_cast &) {
|
||||||
|
@ -443,17 +443,13 @@ namespace chaiscript
|
|||||||
|
|
||||||
|
|
||||||
/// Adds a named object to the current scope
|
/// Adds a named object to the current scope
|
||||||
|
/// \warning This version does not check the validity of the name
|
||||||
|
/// it is meant for internal use only
|
||||||
void add_object(const std::string &name, const Boxed_Value &obj) const
|
void add_object(const std::string &name, const Boxed_Value &obj) const
|
||||||
{
|
{
|
||||||
auto &stack = get_stack_data();
|
if (!get_stack_data().back().insert(std::make_pair(name, obj)).second)
|
||||||
validate_object_name(name);
|
|
||||||
|
|
||||||
auto &scope = stack.back();
|
|
||||||
if (scope.find(name) != scope.end())
|
|
||||||
{
|
{
|
||||||
throw chaiscript::exception::name_conflict_error(name);
|
throw chaiscript::exception::name_conflict_error(name);
|
||||||
} else {
|
|
||||||
scope.insert(std::make_pair(name, obj));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -796,7 +792,7 @@ namespace chaiscript
|
|||||||
/// Dump object info to stdout
|
/// Dump object info to stdout
|
||||||
void dump_object(const Boxed_Value &o) const
|
void dump_object(const Boxed_Value &o) const
|
||||||
{
|
{
|
||||||
std::cout << (o.is_const()?"const ":"") << type_name(o) << std::endl;
|
std::cout << (o.is_const()?"const ":"") << type_name(o) << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Dump type info to stdout
|
/// Dump type info to stdout
|
||||||
@ -830,7 +826,7 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << ") " << std::endl;
|
std::cout << ") \n";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if a call can be made that consists of the first parameter
|
/// Returns true if a call can be made that consists of the first parameter
|
||||||
@ -850,7 +846,7 @@ namespace chaiscript
|
|||||||
/// Dump all system info to stdout
|
/// Dump all system info to stdout
|
||||||
void dump_system() const
|
void dump_system() const
|
||||||
{
|
{
|
||||||
std::cout << "Registered Types: " << std::endl;
|
std::cout << "Registered Types: \n";
|
||||||
std::vector<std::pair<std::string, Type_Info> > types = get_types();
|
std::vector<std::pair<std::string, Type_Info> > types = get_types();
|
||||||
for (std::vector<std::pair<std::string, Type_Info> >::const_iterator itr = types.begin();
|
for (std::vector<std::pair<std::string, Type_Info> >::const_iterator itr = types.begin();
|
||||||
itr != types.end();
|
itr != types.end();
|
||||||
@ -858,20 +854,20 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
std::cout << itr->first << ": ";
|
std::cout << itr->first << ": ";
|
||||||
std::cout << itr->second.bare_name();
|
std::cout << itr->second.bare_name();
|
||||||
std::cout << std::endl;
|
std::cout << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << std::endl;
|
std::cout << '\n';
|
||||||
std::vector<std::pair<std::string, Proxy_Function > > funcs = get_functions();
|
std::vector<std::pair<std::string, Proxy_Function > > funcs = get_functions();
|
||||||
|
|
||||||
std::cout << "Functions: " << std::endl;
|
std::cout << "Functions: \n";
|
||||||
for (std::vector<std::pair<std::string, Proxy_Function > >::const_iterator itr = funcs.begin();
|
for (std::vector<std::pair<std::string, Proxy_Function > >::const_iterator itr = funcs.begin();
|
||||||
itr != funcs.end();
|
itr != funcs.end();
|
||||||
++itr)
|
++itr)
|
||||||
{
|
{
|
||||||
dump_function(*itr);
|
dump_function(*itr);
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
std::cout << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
/// return true if the Boxed_Value matches the registered type by name
|
/// return true if the Boxed_Value matches the registered type by name
|
||||||
|
@ -429,11 +429,7 @@ namespace chaiscript
|
|||||||
static_assert(std::is_convertible<From, To>::value, "Types are not automatically convertible");
|
static_assert(std::is_convertible<From, To>::value, "Types are not automatically convertible");
|
||||||
auto func = [](const Boxed_Value &t_bv) -> Boxed_Value {
|
auto func = [](const Boxed_Value &t_bv) -> Boxed_Value {
|
||||||
// not even attempting to call boxed_cast so that we don't get caught in some call recursion
|
// not even attempting to call boxed_cast so that we don't get caught in some call recursion
|
||||||
std::cout << " Type conversion to : " << typeid(To).name() << " from " << typeid(From).name() << std::endl;
|
|
||||||
auto &&from = detail::Cast_Helper<From>::cast(t_bv, nullptr);
|
auto &&from = detail::Cast_Helper<From>::cast(t_bv, nullptr);
|
||||||
std::cout << "Ptr" << static_cast<const void *>(from) << std::endl;
|
|
||||||
std::cout << "Ptr" << from << std::endl;
|
|
||||||
|
|
||||||
To to(from);
|
To to(from);
|
||||||
return chaiscript::Boxed_Value(to);
|
return chaiscript::Boxed_Value(to);
|
||||||
};
|
};
|
||||||
|
@ -118,19 +118,19 @@ namespace chaiscript
|
|||||||
|
|
||||||
ss << what();
|
ss << what();
|
||||||
if (call_stack.size() > 0) {
|
if (call_stack.size() > 0) {
|
||||||
ss << "during evaluation at (" << fname(call_stack[0]) << " " << startpos(call_stack[0]) << ")" << std::endl;
|
ss << "during evaluation at (" << fname(call_stack[0]) << " " << startpos(call_stack[0]) << ")\n";
|
||||||
ss << std::endl << detail << std::endl;
|
ss << '\n' << detail << '\n';
|
||||||
ss << " " << fname(call_stack[0]) << " (" << startpos(call_stack[0]) << ") '" << pretty(call_stack[0]) << "'";
|
ss << " " << fname(call_stack[0]) << " (" << startpos(call_stack[0]) << ") '" << pretty(call_stack[0]) << "'";
|
||||||
for (size_t j = 1; j < call_stack.size(); ++j) {
|
for (size_t j = 1; j < call_stack.size(); ++j) {
|
||||||
if (id(call_stack[j]) != chaiscript::AST_Node_Type::Block
|
if (id(call_stack[j]) != chaiscript::AST_Node_Type::Block
|
||||||
&& id(call_stack[j]) != chaiscript::AST_Node_Type::File)
|
&& id(call_stack[j]) != chaiscript::AST_Node_Type::File)
|
||||||
{
|
{
|
||||||
ss << std::endl;
|
ss << '\n';
|
||||||
ss << " from " << fname(call_stack[j]) << " (" << startpos(call_stack[j]) << ") '" << pretty(call_stack[j]) << "'";
|
ss << " from " << fname(call_stack[j]) << " (" << startpos(call_stack[j]) << ") '" << pretty(call_stack[j]) << "'";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ss << std::endl;
|
ss << '\n';
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,13 +264,13 @@ namespace chaiscript
|
|||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
if (t_functions.size() == 1)
|
if (t_functions.size() == 1)
|
||||||
{
|
{
|
||||||
ss << " Expected: " << format_types(t_functions[0], t_dot_notation, t_ss) << std::endl;
|
ss << " Expected: " << format_types(t_functions[0], t_dot_notation, t_ss) << '\n';
|
||||||
} else {
|
} else {
|
||||||
ss << " " << t_functions.size() << " overloads available:" << std::endl;
|
ss << " " << t_functions.size() << " overloads available:\n";
|
||||||
|
|
||||||
for (const auto & t_function : t_functions)
|
for (const auto & t_function : t_functions)
|
||||||
{
|
{
|
||||||
ss << " " << format_types((t_function), t_dot_notation, t_ss) << std::endl;
|
ss << " " << format_types((t_function), t_dot_notation, t_ss) << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -430,7 +430,7 @@ namespace chaiscript
|
|||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
|
|
||||||
oss << t_prepend << "(" << ast_node_type_to_string(this->identifier) << ") "
|
oss << t_prepend << "(" << ast_node_type_to_string(this->identifier) << ") "
|
||||||
<< this->text << " : " << this->start.line << ", " << this->start.column << std::endl;
|
<< this->text << " : " << this->start.line << ", " << this->start.column << '\n';
|
||||||
|
|
||||||
for (size_t j = 0; j < this->children.size(); ++j) {
|
for (size_t j = 0; j < this->children.size(); ++j) {
|
||||||
oss << this->children[j]->to_string(t_prepend + " ");
|
oss << this->children[j]->to_string(t_prepend + " ");
|
||||||
|
@ -735,11 +735,11 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
const auto name = elem + prefix + t_module_name + postfix;
|
const auto name = elem + prefix + t_module_name + postfix;
|
||||||
// std::cerr << "trying location: " << name << std::endl;
|
// std::cerr << "trying location: " << name << '\n';
|
||||||
load_module(version_stripped_name, name);
|
load_module(version_stripped_name, name);
|
||||||
return name;
|
return name;
|
||||||
} catch (const chaiscript::exception::load_module_error &e) {
|
} catch (const chaiscript::exception::load_module_error &e) {
|
||||||
// std::cerr << "error: " << e.what() << std::endl;
|
// std::cerr << "error: " << e.what() << '\n';
|
||||||
errors.push_back(e);
|
errors.push_back(e);
|
||||||
// Try next set
|
// Try next set
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ namespace chaiscript
|
|||||||
/// Prints the parsed ast_nodes as a tree
|
/// Prints the parsed ast_nodes as a tree
|
||||||
/*
|
/*
|
||||||
void debug_print(AST_NodePtr t, std::string prepend = "") {
|
void debug_print(AST_NodePtr t, std::string prepend = "") {
|
||||||
std::cout << prepend << "(" << ast_node_type_to_string(t->identifier) << ") " << t->text << " : " << t->start.line << ", " << t->start.column << std::endl;
|
std::cout << prepend << "(" << ast_node_type_to_string(t->identifier) << ") " << t->text << " : " << t->start.line << ", " << t->start.column << '\n';
|
||||||
for (unsigned int j = 0; j < t->children.size(); ++j) {
|
for (unsigned int j = 0; j < t->children.size(); ++j) {
|
||||||
debug_print(t->children[j], prepend + " ");
|
debug_print(t->children[j], prepend + " ");
|
||||||
}
|
}
|
||||||
|
@ -13,12 +13,12 @@
|
|||||||
|
|
||||||
void log(const std::string &msg)
|
void log(const std::string &msg)
|
||||||
{
|
{
|
||||||
std::cout << "[" << time(nullptr) << "] " << msg << std::endl;
|
std::cout << "[" << time(nullptr) << "] " << msg << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
void log(const std::string &module, const std::string &msg)
|
void log(const std::string &module, const std::string &msg)
|
||||||
{
|
{
|
||||||
std::cout << "[" << time(nullptr) << "] <" << module << "> " << msg << std::endl;
|
std::cout << "[" << time(nullptr) << "] <" << module << "> " << msg << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
void bound_log(const std::string &msg)
|
void bound_log(const std::string &msg)
|
||||||
@ -28,12 +28,12 @@ void bound_log(const std::string &msg)
|
|||||||
|
|
||||||
void hello_world(const chaiscript::Boxed_Value & /*o*/)
|
void hello_world(const chaiscript::Boxed_Value & /*o*/)
|
||||||
{
|
{
|
||||||
std::cout << "Hello World" << std::endl;
|
std::cout << "Hello World\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void hello_constructor(const chaiscript::Boxed_Value & /*o*/)
|
void hello_constructor(const chaiscript::Boxed_Value & /*o*/)
|
||||||
{
|
{
|
||||||
std::cout << "Hello Constructor" << std::endl;
|
std::cout << "Hello Constructor\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ struct System
|
|||||||
|
|
||||||
void take_shared_ptr(const std::shared_ptr<const std::string> &p)
|
void take_shared_ptr(const std::shared_ptr<const std::string> &p)
|
||||||
{
|
{
|
||||||
std::cout << *p << std::endl;
|
std::cout << *p << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int /*argc*/, char * /*argv*/[]) {
|
int main(int /*argc*/, char * /*argv*/[]) {
|
||||||
@ -122,7 +122,7 @@ int main(int /*argc*/, char * /*argv*/[]) {
|
|||||||
//the templated version of eval:
|
//the templated version of eval:
|
||||||
int i = chai.eval<int>("5+5");
|
int i = chai.eval<int>("5+5");
|
||||||
|
|
||||||
std::cout << "5+5: " << i << std::endl;
|
std::cout << "5+5: " << i << '\n';
|
||||||
|
|
||||||
//Add a new variable
|
//Add a new variable
|
||||||
chai("var scripti = 15");
|
chai("var scripti = 15");
|
||||||
@ -130,9 +130,9 @@ int main(int /*argc*/, char * /*argv*/[]) {
|
|||||||
//We can even get a handle to the variables in the system
|
//We can even get a handle to the variables in the system
|
||||||
int &scripti = chai.eval<int &>("scripti");
|
int &scripti = chai.eval<int &>("scripti");
|
||||||
|
|
||||||
std::cout << "scripti: " << scripti << std::endl;
|
std::cout << "scripti: " << scripti << '\n';
|
||||||
scripti *= 2;
|
scripti *= 2;
|
||||||
std::cout << "scripti (updated): " << scripti << std::endl;
|
std::cout << "scripti (updated): " << scripti << '\n';
|
||||||
chai("print(\"Scripti from chai: \" + to_string(scripti))");
|
chai("print(\"Scripti from chai: \" + to_string(scripti))");
|
||||||
|
|
||||||
//To do: Add examples of handling Boxed_Values directly when needed
|
//To do: Add examples of handling Boxed_Values directly when needed
|
||||||
|
@ -54,7 +54,7 @@ class test
|
|||||||
chaiscript::Boxed_Value val = chai.eval_file(sFile);
|
chaiscript::Boxed_Value val = chai.eval_file(sFile);
|
||||||
}
|
}
|
||||||
catch (std::exception &e) {
|
catch (std::exception &e) {
|
||||||
std::cout << e.what() << std::endl;
|
std::cout << e.what() << '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
42
src/main.cpp
42
src/main.cpp
@ -136,24 +136,24 @@ std::vector<std::string> default_search_paths()
|
|||||||
|
|
||||||
void help(int n) {
|
void help(int n) {
|
||||||
if ( n >= 0 ) {
|
if ( n >= 0 ) {
|
||||||
std::cout << "ChaiScript evaluator. To evaluate an expression, type it and press <enter>." << std::endl;
|
std::cout << "ChaiScript evaluator. To evaluate an expression, type it and press <enter>.\n";
|
||||||
std::cout << "Additionally, you can inspect the runtime system using:" << std::endl;
|
std::cout << "Additionally, you can inspect the runtime system using:\n";
|
||||||
std::cout << " dump_system() - outputs all functions registered to the system" << std::endl;
|
std::cout << " dump_system() - outputs all functions registered to the system\n";
|
||||||
std::cout << " dump_object(x) - dumps information about the given symbol" << std::endl;
|
std::cout << " dump_object(x) - dumps information about the given symbol\n";
|
||||||
} else {
|
} else {
|
||||||
std::cout << "usage : chai [option]+" << std::endl;
|
std::cout << "usage : chai [option]+\n";
|
||||||
std::cout << "option:" << std::endl;
|
std::cout << "option:" << '\n';
|
||||||
std::cout << " -h | --help" << std::endl;
|
std::cout << " -h | --help" << '\n';
|
||||||
std::cout << " -i | --interactive" << std::endl;
|
std::cout << " -i | --interactive" << '\n';
|
||||||
std::cout << " -c | --command cmd" << std::endl;
|
std::cout << " -c | --command cmd" << '\n';
|
||||||
std::cout << " -v | --version" << std::endl;
|
std::cout << " -v | --version" << '\n';
|
||||||
std::cout << " - --stdin" << std::endl;
|
std::cout << " - --stdin" << '\n';
|
||||||
std::cout << " filepath" << std::endl;
|
std::cout << " filepath" << '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void version(int){
|
void version(int){
|
||||||
std::cout << "chai: compiled " << __TIME__ << " " << __DATE__ << std::endl;
|
std::cout << "chai: compiled " << __TIME__ << " " << __DATE__ << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
bool throws_exception(const std::function<void ()> &f)
|
bool throws_exception(const std::function<void ()> &f)
|
||||||
@ -231,7 +231,7 @@ void interactive(chaiscript::ChaiScript& chai)
|
|||||||
//Then, we try to print the result of the evaluation to the user
|
//Then, we try to print the result of the evaluation to the user
|
||||||
if (!val.get_type_info().bare_equal(chaiscript::user_type<void>())) {
|
if (!val.get_type_info().bare_equal(chaiscript::user_type<void>())) {
|
||||||
try {
|
try {
|
||||||
std::cout << chai.eval<std::function<std::string (const chaiscript::Boxed_Value &bv)> >("to_string")(val) << std::endl;
|
std::cout << chai.eval<std::function<std::string (const chaiscript::Boxed_Value &bv)> >("to_string")(val) << '\n';
|
||||||
}
|
}
|
||||||
catch (...) {} //If we can't, do nothing
|
catch (...) {} //If we can't, do nothing
|
||||||
}
|
}
|
||||||
@ -241,11 +241,11 @@ void interactive(chaiscript::ChaiScript& chai)
|
|||||||
if (ee.call_stack.size() > 0) {
|
if (ee.call_stack.size() > 0) {
|
||||||
std::cout << "during evaluation at (" << ee.call_stack[0]->start.line << ", " << ee.call_stack[0]->start.column << ")";
|
std::cout << "during evaluation at (" << ee.call_stack[0]->start.line << ", " << ee.call_stack[0]->start.column << ")";
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
std::cout << '\n';
|
||||||
}
|
}
|
||||||
catch (const std::exception &e) {
|
catch (const std::exception &e) {
|
||||||
std::cout << e.what();
|
std::cout << e.what();
|
||||||
std::cout << std::endl;
|
std::cout << '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -305,7 +305,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if ( arg == "-c" || arg == "--command" ) {
|
if ( arg == "-c" || arg == "--command" ) {
|
||||||
if ( (i+1) >= argc ) {
|
if ( (i+1) >= argc ) {
|
||||||
std::cout << "insufficient input following " << arg << std::endl;
|
std::cout << "insufficient input following " << arg << '\n';
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
} else {
|
} else {
|
||||||
arg = argv[++i];
|
arg = argv[++i];
|
||||||
@ -323,7 +323,7 @@ int main(int argc, char *argv[])
|
|||||||
} else if ( arg == "-i" || arg == "--interactive" ) {
|
} else if ( arg == "-i" || arg == "--interactive" ) {
|
||||||
mode = eInteractive ;
|
mode = eInteractive ;
|
||||||
} else if ( arg.find('-') == 0 ) {
|
} else if ( arg.find('-') == 0 ) {
|
||||||
std::cout << "unrecognised argument " << arg << std::endl;
|
std::cout << "unrecognised argument " << arg << '\n';
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
} else {
|
} else {
|
||||||
mode = eFile;
|
mode = eFile;
|
||||||
@ -335,16 +335,16 @@ int main(int argc, char *argv[])
|
|||||||
case eInteractive : interactive(chai); break;
|
case eInteractive : interactive(chai); break;
|
||||||
case eCommand : val = chai.eval(arg); break;
|
case eCommand : val = chai.eval(arg); break;
|
||||||
case eFile : val = chai.eval_file(arg); break;
|
case eFile : val = chai.eval_file(arg); break;
|
||||||
default : std::cout << "Unrecognized execution mode" << std::endl; return EXIT_FAILURE;
|
default : std::cout << "Unrecognized execution mode\n"; return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const chaiscript::exception::eval_error &ee) {
|
catch (const chaiscript::exception::eval_error &ee) {
|
||||||
std::cout << ee.pretty_print();
|
std::cout << ee.pretty_print();
|
||||||
std::cout << std::endl;
|
std::cout << '\n';
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
catch (std::exception &e) {
|
catch (std::exception &e) {
|
||||||
std::cout << e.what() << std::endl;
|
std::cout << e.what() << '\n';
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,16 +15,16 @@ bool run_test_type_conversion(const Boxed_Value &bv, bool expectedpass)
|
|||||||
use(ret);
|
use(ret);
|
||||||
} catch (const chaiscript::exception::bad_boxed_cast &/*e*/) {
|
} catch (const chaiscript::exception::bad_boxed_cast &/*e*/) {
|
||||||
if (expectedpass) {
|
if (expectedpass) {
|
||||||
// std::cerr << "Failure in run_test_type_conversion: " << e.what() << std::endl;
|
// std::cerr << "Failure in run_test_type_conversion: " << e.what() << '\n';
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
std::cerr << "Unexpected standard exception when attempting cast_conversion: " << e.what() << std::endl;
|
std::cerr << "Unexpected standard exception when attempting cast_conversion: " << e.what() << '\n';
|
||||||
return false;
|
return false;
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
std::cerr << "Unexpected unknown exception when attempting cast_conversion." << std::endl;
|
std::cerr << "Unexpected unknown exception when attempting cast_conversion.\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ bool test_type_conversion(const Boxed_Value &bv, bool expectedpass)
|
|||||||
<< (bv.is_const()?(std::string("const ")):(std::string())) << bv.get_type_info().name()
|
<< (bv.is_const()?(std::string("const ")):(std::string())) << bv.get_type_info().name()
|
||||||
<< " To: "
|
<< " To: "
|
||||||
<< (std::is_const<To>::value?(std::string("const ")):(std::string())) << typeid(To).name()
|
<< (std::is_const<To>::value?(std::string("const ")):(std::string())) << typeid(To).name()
|
||||||
<< " test was expected to " << ((expectedpass)?(std::string("succeed")):(std::string("fail"))) << " but did not" << std::endl;
|
<< " test was expected to " << ((expectedpass)?(std::string("succeed")):(std::string("fail"))) << " but did not\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -264,21 +264,21 @@ bool pointer_test(const T& default_value, const T& new_value)
|
|||||||
|
|
||||||
|
|
||||||
if (p != (*result) ) {
|
if (p != (*result) ) {
|
||||||
std::cerr << "Pointer passed in different than one returned" << std::endl;
|
std::cerr << "Pointer passed in different than one returned\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*p != *(*result) ) {
|
if (*p != *(*result) ) {
|
||||||
std::cerr << "Somehow dereferenced pointer values are not the same?" << std::endl;
|
std::cerr << "Somehow dereferenced pointer values are not the same?\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (const exception::bad_boxed_cast &) {
|
} catch (const exception::bad_boxed_cast &) {
|
||||||
std::cerr << "Bad boxed cast performing ** to ** test" << std::endl;
|
std::cerr << "Bad boxed cast performing ** to ** test\n";
|
||||||
return false;
|
return false;
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
std::cerr << "Unknown exception performing ** to ** test" << std::endl;
|
std::cerr << "Unknown exception performing ** to ** test\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ void assert_equal(const LHS &lhs, const RHS &rhs)
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
std::cout << "Got: " << lhs << " expected " << rhs << std::endl;
|
std::cout << "Got: " << lhs << " expected " << rhs << '\n';
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ int test_generic()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "test_generic failed" << std::endl;
|
std::cout << "test_generic failed\n";
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ int test_1()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "test_1 failed" << std::endl;
|
std::cout << "test_1 failed\n";
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ int test_2()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "test_2 failed" << std::endl;
|
std::cout << "test_2 failed\n";
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,22 +61,22 @@ int test_5()
|
|||||||
try {
|
try {
|
||||||
chai.eval("throw(runtime_error(\"error\"))", chaiscript::exception_specification<int, double, float, const std::string &, const std::exception &>());
|
chai.eval("throw(runtime_error(\"error\"))", chaiscript::exception_specification<int, double, float, const std::string &, const std::exception &>());
|
||||||
} catch (const double) {
|
} catch (const double) {
|
||||||
std::cout << "test_5 failed with double" << std::endl;
|
std::cout << "test_5 failed with double\n";
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
} catch (int) {
|
} catch (int) {
|
||||||
std::cout << "test_5 failed with int" << std::endl;
|
std::cout << "test_5 failed with int\n";
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
} catch (float) {
|
} catch (float) {
|
||||||
std::cout << "test_5 failed with float" << std::endl;
|
std::cout << "test_5 failed with float\n";
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
} catch (const std::string &) {
|
} catch (const std::string &) {
|
||||||
std::cout << "test_5 failed with string" << std::endl;
|
std::cout << "test_5 failed with string\n";
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
} catch (const std::exception &) {
|
} catch (const std::exception &) {
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "test_5 failed" << std::endl;
|
std::cout << "test_5 failed\n";
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,22 +87,22 @@ int test_unhandled()
|
|||||||
try {
|
try {
|
||||||
chai.eval("throw(\"error\")", chaiscript::exception_specification<int, double, float, const std::exception &>());
|
chai.eval("throw(\"error\")", chaiscript::exception_specification<int, double, float, const std::exception &>());
|
||||||
} catch (double) {
|
} catch (double) {
|
||||||
std::cout << "test_unhandled failed with double" << std::endl;
|
std::cout << "test_unhandled failed with double\n";
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
} catch (int) {
|
} catch (int) {
|
||||||
std::cout << "test_unhandled failed with int" << std::endl;
|
std::cout << "test_unhandled failed with int\n";
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
} catch (float) {
|
} catch (float) {
|
||||||
std::cout << "test_unhandled failed with float" << std::endl;
|
std::cout << "test_unhandled failed with float\n";
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
} catch (const std::exception &) {
|
} catch (const std::exception &) {
|
||||||
std::cout << "test_unhandled failed with std::exception" << std::endl;
|
std::cout << "test_unhandled failed with std::exception\n";
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
} catch (const chaiscript::Boxed_Value &) {
|
} catch (const chaiscript::Boxed_Value &) {
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "test_unhandled failed" << std::endl;
|
std::cout << "test_unhandled failed\n";
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ bool test_literal(T val, const std::string &str)
|
|||||||
{
|
{
|
||||||
chaiscript::ChaiScript chai;
|
chaiscript::ChaiScript chai;
|
||||||
T val2 = chai.eval<T>(str);
|
T val2 = chai.eval<T>(str);
|
||||||
std::cout << "Comparing : " << val << " " << val2 << std::endl;
|
std::cout << "Comparing : " << val << " " << val2 << '\n';
|
||||||
return val == val2;
|
return val == val2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ int main()
|
|||||||
test_type(chaiscript::user_type<const int *>(), true, true, false, false, false);
|
test_type(chaiscript::user_type<const int *>(), true, true, false, false, false);
|
||||||
test_type(chaiscript::Type_Info(), false, false, false, false, true);
|
test_type(chaiscript::Type_Info(), false, false, false, false, true);
|
||||||
|
|
||||||
std::cout << "Size of Type_Info " << sizeof(chaiscript::Type_Info) << std::endl;
|
std::cout << "Size of Type_Info " << sizeof(chaiscript::Type_Info) << '\n';
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user