Get chaiscript compiling with LLVM/clang. Resulting code crashes, however.
This commit is contained in:
parent
a39d70dbca
commit
22c2be835a
@ -156,8 +156,8 @@ namespace chaiscript
|
|||||||
detail::Get_Type_Info<T>::get(),
|
detail::Get_Type_Info<T>::get(),
|
||||||
boost::any(obj),
|
boost::any(obj),
|
||||||
false,
|
false,
|
||||||
&Data::unique<T>,
|
boost::function<bool (boost::any *)>(&Data::unique<T>),
|
||||||
&Data::is_null<T>)
|
boost::function<bool (boost::any *)>(&Data::is_null<T>))
|
||||||
);
|
);
|
||||||
|
|
||||||
std::map<Object_Cache_Key, Data>::iterator itr
|
std::map<Object_Cache_Key, Data>::iterator itr
|
||||||
@ -219,8 +219,8 @@ namespace chaiscript
|
|||||||
detail::Get_Type_Info<T>::get(),
|
detail::Get_Type_Info<T>::get(),
|
||||||
boost::any(boost::shared_ptr<T>(new T(t))),
|
boost::any(boost::shared_ptr<T>(new T(t))),
|
||||||
false,
|
false,
|
||||||
&Data::unique<T>,
|
boost::function<bool (boost::any *)>(&Data::unique<T>),
|
||||||
&Data::is_null<T>)
|
boost::function<bool (boost::any *)>(&Data::is_null<T>))
|
||||||
);
|
);
|
||||||
|
|
||||||
boost::shared_ptr<T> *ptr = boost::any_cast<boost::shared_ptr<T> >(&data->m_obj);
|
boost::shared_ptr<T> *ptr = boost::any_cast<boost::shared_ptr<T> >(&data->m_obj);
|
||||||
|
@ -287,8 +287,9 @@ namespace chaiscript
|
|||||||
Bound_Function(const Const_Proxy_Function &t_f,
|
Bound_Function(const Const_Proxy_Function &t_f,
|
||||||
const std::vector<Boxed_Value> &t_args)
|
const std::vector<Boxed_Value> &t_args)
|
||||||
: Proxy_Function_Base(std::vector<Type_Info>()),
|
: Proxy_Function_Base(std::vector<Type_Info>()),
|
||||||
m_f(t_f), m_args(t_args), m_arity(m_f->get_arity()<0?-1:(m_f->get_arity() - m_args.size()))
|
m_f(t_f), m_args(t_args), m_arity(m_f->get_arity()<0?-1:(m_f->get_arity() - static_cast<int>(m_args.size())))
|
||||||
{
|
{
|
||||||
|
assert(m_f->get_arity() >= static_cast<int>(m_args.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool operator==(const Proxy_Function_Base &) const
|
virtual bool operator==(const Proxy_Function_Base &) const
|
||||||
|
184
src/main.cpp
184
src/main.cpp
@ -18,10 +18,10 @@
|
|||||||
#include <chaiscript/chaiscript.hpp>
|
#include <chaiscript/chaiscript.hpp>
|
||||||
|
|
||||||
void print_help() {
|
void print_help() {
|
||||||
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>." << std::endl;
|
||||||
std::cout << "Additionally, you can inspect the runtime system using:" << std::endl;
|
std::cout << "Additionally, you can inspect the runtime system using:" << std::endl;
|
||||||
std::cout << " dump_system() - outputs all functions registered to the system" << std::endl;
|
std::cout << " dump_system() - outputs all functions registered to the system" << std::endl;
|
||||||
std::cout << " dump_object(x) - dumps information about the given symbol" << std::endl;
|
std::cout << " dump_object(x) - dumps information about the given symbol" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -39,125 +39,129 @@ bool throws_exception(const chaiscript::Proxy_Function &f)
|
|||||||
|
|
||||||
std::string get_next_command() {
|
std::string get_next_command() {
|
||||||
#ifdef READLINE_AVAILABLE
|
#ifdef READLINE_AVAILABLE
|
||||||
char *input_raw;
|
char *input_raw;
|
||||||
input_raw = readline("eval> ");
|
input_raw = readline("eval> ");
|
||||||
add_history(input_raw);
|
add_history(input_raw);
|
||||||
return std::string(input_raw);
|
return std::string(input_raw);
|
||||||
#else
|
#else
|
||||||
std::string retval;
|
std::string retval;
|
||||||
std::cout << "eval> ";
|
std::cout << "eval> ";
|
||||||
std::getline(std::cin, retval);
|
std::getline(std::cin, retval);
|
||||||
return retval;
|
return retval;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void myexit(int return_val) {
|
||||||
|
exit(return_val);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
std::string input;
|
std::string input;
|
||||||
|
|
||||||
std::vector<std::string> usepaths;
|
std::vector<std::string> usepaths;
|
||||||
std::vector<std::string> modulepaths;
|
std::vector<std::string> modulepaths;
|
||||||
|
|
||||||
|
|
||||||
// Disable deprecation warning for getenv call.
|
// Disable deprecation warning for getenv call.
|
||||||
#ifdef BOOST_MSVC
|
#ifdef BOOST_MSVC
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma warning(disable : 4996)
|
#pragma warning(disable : 4996)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const char *usepath = getenv("CHAI_USE_PATH");
|
const char *usepath = getenv("CHAI_USE_PATH");
|
||||||
const char *modulepath = getenv("CHAI_MODULE_PATH");
|
const char *modulepath = getenv("CHAI_MODULE_PATH");
|
||||||
|
|
||||||
#ifdef BOOST_MSVC
|
#ifdef BOOST_MSVC
|
||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
usepaths.push_back("");
|
|
||||||
|
|
||||||
if (usepath)
|
usepaths.push_back("");
|
||||||
{
|
|
||||||
usepaths.push_back(usepath);
|
|
||||||
}
|
|
||||||
|
|
||||||
modulepaths.push_back("");
|
if (usepath)
|
||||||
|
{
|
||||||
|
usepaths.push_back(usepath);
|
||||||
|
}
|
||||||
|
|
||||||
if (modulepath)
|
modulepaths.push_back("");
|
||||||
{
|
|
||||||
modulepaths.push_back(modulepath);
|
if (modulepath)
|
||||||
}
|
{
|
||||||
|
modulepaths.push_back(modulepath);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
chaiscript::ChaiScript chai(modulepaths,usepaths);
|
chaiscript::ChaiScript chai(modulepaths,usepaths);
|
||||||
|
|
||||||
chai.add(chaiscript::fun(&exit), "exit");
|
chai.add(chaiscript::fun(&myexit), "exit");
|
||||||
chai.add(chaiscript::fun(&throws_exception), "throws_exception");
|
chai.add(chaiscript::fun(&throws_exception), "throws_exception");
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
#ifdef READLINE_AVAILABLE
|
#ifdef READLINE_AVAILABLE
|
||||||
using_history();
|
using_history();
|
||||||
#endif
|
#endif
|
||||||
input = get_next_command();
|
input = get_next_command();
|
||||||
while (input != "quit") {
|
while (input != "quit") {
|
||||||
|
|
||||||
chaiscript::Boxed_Value val;
|
chaiscript::Boxed_Value val;
|
||||||
|
|
||||||
if (input == "help") {
|
if (input == "help") {
|
||||||
print_help();
|
print_help();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
try {
|
try {
|
||||||
//First, we evaluate it
|
//First, we evaluate it
|
||||||
val = chai.eval(input);
|
val = chai.eval(input);
|
||||||
|
|
||||||
//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 {
|
|
||||||
chaiscript::dispatch(chai.get_eval_engine().get_function("print"), chaiscript::Param_List_Builder() << val);
|
|
||||||
}
|
|
||||||
catch (...) {
|
|
||||||
//If we can't, do nothing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (chaiscript::Eval_Error &ee) {
|
|
||||||
std::cout << ee.what();
|
|
||||||
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 << std::endl;
|
|
||||||
}
|
|
||||||
catch (std::exception &e) {
|
|
||||||
std::cout << e.what();
|
|
||||||
std::cout << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
input = get_next_command();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
for (int i = 1; i < argc; ++i) {
|
|
||||||
try {
|
try {
|
||||||
chaiscript::Boxed_Value val = chai.eval_file(argv[i]);
|
chaiscript::dispatch(chai.get_eval_engine().get_function("print"), chaiscript::Param_List_Builder() << val);
|
||||||
}
|
}
|
||||||
catch (chaiscript::Eval_Error &ee) {
|
catch (...) {
|
||||||
std::cout << ee.what();
|
//If we can't, do nothing
|
||||||
if (ee.call_stack.size() > 0) {
|
|
||||||
std::cout << "during evaluation at (" << ee.call_stack[0]->filename << " " << ee.call_stack[0]->start.line << ", " << ee.call_stack[0]->start.column << ")";
|
|
||||||
for (unsigned int j = 1; j < ee.call_stack.size(); ++j) {
|
|
||||||
std::cout << std::endl;
|
|
||||||
std::cout << " from " << ee.call_stack[j]->filename << " (" << ee.call_stack[j]->start.line << ", " << ee.call_stack[j]->start.column << ")";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::cout << std::endl;
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
catch (std::exception &e) {
|
|
||||||
std::cout << e.what() << std::endl;
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
catch (chaiscript::Eval_Error &ee) {
|
||||||
|
std::cout << ee.what();
|
||||||
|
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 << std::endl;
|
||||||
|
}
|
||||||
|
catch (std::exception &e) {
|
||||||
|
std::cout << e.what();
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
input = get_next_command();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (int i = 1; i < argc; ++i) {
|
||||||
|
try {
|
||||||
|
chaiscript::Boxed_Value val = chai.eval_file(argv[i]);
|
||||||
|
}
|
||||||
|
catch (chaiscript::Eval_Error &ee) {
|
||||||
|
std::cout << ee.what();
|
||||||
|
if (ee.call_stack.size() > 0) {
|
||||||
|
std::cout << "during evaluation at (" << ee.call_stack[0]->filename << " " << ee.call_stack[0]->start.line << ", " << ee.call_stack[0]->start.column << ")";
|
||||||
|
for (unsigned int j = 1; j < ee.call_stack.size(); ++j) {
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << " from " << ee.call_stack[j]->filename << " (" << ee.call_stack[j]->start.line << ", " << ee.call_stack[j]->start.column << ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
catch (std::exception &e) {
|
||||||
|
std::cout << e.what() << std::endl;
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user