Merge branch 'develop' of github.com:ChaiScript/ChaiScript into typed_function_ordering

This commit is contained in:
Jason Turner
2015-08-26 18:47:43 -06:00
3 changed files with 45 additions and 16 deletions

View File

@@ -562,13 +562,14 @@ namespace chaiscript
"eval_error", "eval_error",
{ }, { },
{ {fun(&chaiscript::exception::eval_error::reason), "reason"}, { {fun(&chaiscript::exception::eval_error::reason), "reason"},
{fun(std::function<std::vector<Boxed_Value> (const chaiscript::exception::eval_error &t_eval_error)>([](const chaiscript::exception::eval_error &t_eval_error) -> std::vector<Boxed_Value> { {fun(&chaiscript::exception::eval_error::pretty_print), "pretty_print"},
std::vector<Boxed_Value> retval; {fun(std::function<std::vector<Boxed_Value> (const chaiscript::exception::eval_error &t_eval_error)>([](const chaiscript::exception::eval_error &t_eval_error) -> std::vector<Boxed_Value> {
std::transform(t_eval_error.call_stack.begin(), t_eval_error.call_stack.end(), std::vector<Boxed_Value> retval;
std::back_inserter(retval), std::transform(t_eval_error.call_stack.begin(), t_eval_error.call_stack.end(),
&chaiscript::var<std::shared_ptr<const chaiscript::AST_Node>>); std::back_inserter(retval),
return retval; &chaiscript::var<std::shared_ptr<const chaiscript::AST_Node>>);
})), "call_stack"} } return retval;
})), "call_stack"} }
); );

View File

@@ -36,7 +36,9 @@
#else #else
#ifdef CHAISCRIPT_WINDOWS #ifdef CHAISCRIPT_WINDOWS
#define VC_EXTRA_LEAN #define VC_EXTRA_LEAN
#if !defined(WIN32_LEAN_AND_MEAN)
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h> #include <windows.h>
#endif #endif
#endif #endif
@@ -284,14 +286,7 @@ namespace chaiscript
const Boxed_Value internal_eval_ast(const AST_NodePtr &t_ast)
{
try {
return t_ast->eval(m_engine);
} catch (const exception::eval_error &t_ee) {
throw Boxed_Value(t_ee);
}
}
/// Evaluates the given file and looks in the 'use' paths /// Evaluates the given file and looks in the 'use' paths
const Boxed_Value internal_eval_file(const std::string &t_filename) { const Boxed_Value internal_eval_file(const std::string &t_filename) {
@@ -396,7 +391,8 @@ namespace chaiscript
m_engine.add(fun([this](const std::string &t_file){ return use(t_file); }), "use"); m_engine.add(fun([this](const std::string &t_file){ return use(t_file); }), "use");
m_engine.add(fun([this](const std::string &t_file){ return internal_eval_file(t_file); }), "eval_file"); m_engine.add(fun([this](const std::string &t_file){ return internal_eval_file(t_file); }), "eval_file");
m_engine.add(fun([this](const std::string &t_str){ return internal_eval(t_str); }), "eval"); m_engine.add(fun([this](const std::string &t_str){ return internal_eval(t_str); }), "eval");
m_engine.add(fun([this](const AST_NodePtr &t_ast){ return internal_eval_ast(t_ast); }), "eval"); m_engine.add(fun([this](const AST_NodePtr &t_ast){ return eval(t_ast); }), "eval");
m_engine.add(fun(&parse), "parse");
m_engine.add(fun(&ChaiScript::version_major), "version_major"); m_engine.add(fun(&ChaiScript::version_major), "version_major");
m_engine.add(fun(&ChaiScript::version_minor), "version_minor"); m_engine.add(fun(&ChaiScript::version_minor), "version_minor");
@@ -517,6 +513,28 @@ namespace chaiscript
build_eval_system(ModulePtr()); build_eval_system(ModulePtr());
} }
const Boxed_Value eval(const AST_NodePtr &t_ast)
{
try {
return t_ast->eval(m_engine);
} catch (const exception::eval_error &t_ee) {
throw Boxed_Value(t_ee);
}
}
static AST_NodePtr parse(const std::string &t_input)
{
parser::ChaiScript_Parser parser;
if (parser.parse(t_input, "PARSE")) {
//parser.show_match_stack();
return parser.optimized_ast();
} else {
throw chaiscript::exception::eval_error("Unknown error while parsing");
}
}
static int version_major() static int version_major()
{ {
return chaiscript::version_major; return chaiscript::version_major;

View File

@@ -0,0 +1,10 @@
auto p = parse("5 + 4");
try {
assert_equal(eval(p), 9)
} catch (e) {
print(e.pretty_print());
assert_true(false);
}