Further namespace reorganization and cleanup to limit to the user the

most important aspect of the API and make documenation easier.
This commit is contained in:
Jason Turner
2011-03-24 09:23:05 -06:00
parent 637164e457
commit cd8bead54a
10 changed files with 2156 additions and 2136 deletions

View File

@@ -49,7 +49,7 @@ namespace chaiscript
try { try {
// 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(boxed_dynamic_cast<Type>(bv)); return detail::Cast_Helper<Type>::cast(detail::boxed_dynamic_cast<Type>(bv));
} catch (const boost::bad_any_cast &) { } catch (const boost::bad_any_cast &) {
throw exception::bad_boxed_cast(bv.get_type_info(), typeid(Type)); throw exception::bad_boxed_cast(bv.get_type_info(), typeid(Type));
} }

View File

@@ -201,7 +201,7 @@ namespace chaiscript
protected: protected:
virtual Boxed_Value do_call(const std::vector<Boxed_Value> &params) const virtual Boxed_Value do_call(const std::vector<Boxed_Value> &params) const
{ {
return dispatch(m_funcs.begin(), m_funcs.end(), params); return detail::dispatch(m_funcs.begin(), m_funcs.end(), params);
} }
private: private:
@@ -647,7 +647,7 @@ namespace chaiscript
{ {
std::vector<Proxy_Function> functions = get_function(t_name); std::vector<Proxy_Function> functions = get_function(t_name);
return dispatch(functions.begin(), functions.end(), params); return detail::dispatch(functions.begin(), functions.end(), params);
} }
Boxed_Value call_function(const std::string &t_name) const Boxed_Value call_function(const std::string &t_name) const

View File

@@ -254,29 +254,31 @@ namespace chaiscript
return detail::Dynamic_Conversions::create<Base, Derived>(); return detail::Dynamic_Conversions::create<Base, Derived>();
} }
template<typename Base, typename Derived> namespace detail
bool dynamic_cast_converts()
{ {
return dynamic_cast_converts(user_type<Base>(), user_type<Derived>()); template<typename Base, typename Derived>
} bool dynamic_cast_converts()
{
return dynamic_cast_converts(user_type<Base>(), user_type<Derived>());
}
static bool dynamic_cast_converts(const Type_Info &base, const Type_Info &derived) static bool dynamic_cast_converts(const Type_Info &base, const Type_Info &derived)
{ {
return detail::Dynamic_Conversions::get().has_conversion(base, derived); return detail::Dynamic_Conversions::get().has_conversion(base, derived);
}
template<typename Base>
Boxed_Value boxed_dynamic_cast(const Boxed_Value &derived)
{
try {
return detail::Dynamic_Conversions::get().get_conversion(user_type<Base>(), derived.get_type_info())->convert(derived);
} catch (const std::out_of_range &) {
throw exception::bad_boxed_dynamic_cast(derived.get_type_info(), typeid(Base), "No known conversion");
} catch (const std::bad_cast &) {
throw exception::bad_boxed_dynamic_cast(derived.get_type_info(), typeid(Base), "Unable to perform dynamic_cast operation");
} }
}
template<typename Base>
Boxed_Value boxed_dynamic_cast(const Boxed_Value &derived)
{
try {
return detail::Dynamic_Conversions::get().get_conversion(user_type<Base>(), derived.get_type_info())->convert(derived);
} catch (const std::out_of_range &) {
throw exception::bad_boxed_dynamic_cast(derived.get_type_info(), typeid(Base), "No known conversion");
} catch (const std::bad_cast &) {
throw exception::bad_boxed_dynamic_cast(derived.get_type_info(), typeid(Base), "Unable to perform dynamic_cast operation");
}
}
}
} }

View File

@@ -139,7 +139,7 @@ namespace chaiscript
|| (!bv.get_type_info().is_undef() || (!bv.get_type_info().is_undef()
&& (ti.bare_equal(user_type<Boxed_POD_Value>()) && (ti.bare_equal(user_type<Boxed_POD_Value>())
|| ti.bare_equal(bv.get_type_info()) || ti.bare_equal(bv.get_type_info())
|| dynamic_cast_converts(ti, bv.get_type_info()) || detail::dynamic_cast_converts(ti, bv.get_type_info())
|| bv.get_type_info().bare_equal(user_type<boost::shared_ptr<const Proxy_Function_Base> >()) || bv.get_type_info().bare_equal(user_type<boost::shared_ptr<const Proxy_Function_Base> >())
) )
) )
@@ -594,46 +594,49 @@ namespace chaiscript
}; };
} }
/** namespace detail
* Take a vector of functions and a vector of parameters. Attempt to execute
* each function against the set of parameters, in order, until a matching
* function is found or throw dispatch_error if no matching function is found
*/
template<typename InItr>
Boxed_Value dispatch(InItr begin, InItr end,
const std::vector<Boxed_Value> &plist)
{ {
while (begin != end) /**
{ * Take a vector of functions and a vector of parameters. Attempt to execute
try { * each function against the set of parameters, in order, until a matching
if ((*begin)->filter(plist)) * function is found or throw dispatch_error if no matching function is found
*/
template<typename InItr>
Boxed_Value dispatch(InItr begin, InItr end,
const std::vector<Boxed_Value> &plist)
{
while (begin != end)
{ {
return (*(*begin))(plist); try {
if ((*begin)->filter(plist))
{
return (*(*begin))(plist);
}
} catch (const exception::bad_boxed_cast &) {
//parameter failed to cast, try again
} catch (const exception::arity_error &) {
//invalid num params, try again
} catch (const exception::guard_error &) {
//guard failed to allow the function to execute,
//try again
}
++begin;
} }
} catch (const exception::bad_boxed_cast &) {
//parameter failed to cast, try again throw exception::dispatch_error(plist.empty()?false:plist[0].is_const());
} catch (const exception::arity_error &) {
//invalid num params, try again
} catch (const exception::guard_error &) {
//guard failed to allow the function to execute,
//try again
} }
++begin;
}
throw exception::dispatch_error(plist.empty()?false:plist[0].is_const()); /**
} * Take a vector of functions and a vector of parameters. Attempt to execute
* each function against the set of parameters, in order, until a matching
/** * function is found or throw dispatch_error if no matching function is found
* Take a vector of functions and a vector of parameters. Attempt to execute */
* each function against the set of parameters, in order, until a matching template<typename Funcs>
* function is found or throw dispatch_error if no matching function is found Boxed_Value dispatch(const Funcs &funcs,
*/ const std::vector<Boxed_Value> &plist)
template<typename Funcs> {
Boxed_Value dispatch(const Funcs &funcs, return dispatch(funcs.begin(), funcs.end(), plist);
const std::vector<Boxed_Value> &plist) }
{
return dispatch(funcs.begin(), funcs.end(), plist);
} }
} }

View File

@@ -108,59 +108,65 @@ namespace chaiscript
/** namespace exception
* Errors generated during parsing or evaluation {
*/ /**
struct Eval_Error : public std::runtime_error { * Errors generated during parsing or evaluation
std::string reason; */
File_Position start_position; struct eval_error : public std::runtime_error {
File_Position end_position; std::string reason;
std::string filename; File_Position start_position;
std::vector<AST_NodePtr> call_stack; File_Position end_position;
std::string filename;
std::vector<AST_NodePtr> call_stack;
Eval_Error(const std::string &t_why, const File_Position &t_where, const std::string &t_fname) : eval_error(const std::string &t_why, const File_Position &t_where, const std::string &t_fname) throw() :
std::runtime_error("Error: \"" + t_why + "\" " + std::runtime_error("Error: \"" + t_why + "\" " +
(t_fname != "__EVAL__" ? ("in '" + t_fname + "' ") : "during evaluation ") + (t_fname != "__EVAL__" ? ("in '" + t_fname + "' ") : "during evaluation ") +
+ "at (" + boost::lexical_cast<std::string>(t_where.line) + ", " + + "at (" + boost::lexical_cast<std::string>(t_where.line) + ", " +
boost::lexical_cast<std::string>(t_where.column) + ")"), boost::lexical_cast<std::string>(t_where.column) + ")"),
reason(t_why), start_position(t_where), end_position(t_where), filename(t_fname) reason(t_why), start_position(t_where), end_position(t_where), filename(t_fname)
{ } { }
Eval_Error(const std::string &t_why) eval_error(const std::string &t_why) throw()
: std::runtime_error("Error: \"" + t_why + "\" "), : std::runtime_error("Error: \"" + t_why + "\" "),
reason(t_why) reason(t_why)
{} {}
virtual ~Eval_Error() throw() {} virtual ~eval_error() throw() {}
}; };
/** /**
* Errors generated when loading a file * Errors generated when loading a file
*/ */
struct File_Not_Found_Error : public std::runtime_error { struct file_not_found_error : public std::runtime_error {
File_Not_Found_Error(const std::string &t_filename) file_not_found_error(const std::string &t_filename) throw()
: std::runtime_error("File Not Found: " + t_filename) : std::runtime_error("File Not Found: " + t_filename)
{ } { }
virtual ~File_Not_Found_Error() throw() {} virtual ~file_not_found_error() throw() {}
}; };
}
/** namespace detail
* Special type for returned values {
*/ /**
struct Return_Value { * Special type for returned values
Boxed_Value retval; */
struct Return_Value {
Boxed_Value retval;
Return_Value(const Boxed_Value &t_return_value) : retval(t_return_value) { } Return_Value(const Boxed_Value &t_return_value) : retval(t_return_value) { }
}; };
/** /**
* Special type indicating a call to 'break' * Special type indicating a call to 'break'
*/ */
struct Break_Loop { struct Break_Loop {
Break_Loop() { } Break_Loop() { }
}; };
}
} }
#endif /* _CHAISCRIPT_COMMON_HPP */ #endif /* _CHAISCRIPT_COMMON_HPP */

View File

@@ -28,193 +28,199 @@
namespace chaiscript namespace chaiscript
{ {
struct load_module_error : std::runtime_error namespace exception
{ {
load_module_error(const std::string &t_reason) throw() struct load_module_error : std::runtime_error
: std::runtime_error(t_reason)
{ {
} load_module_error(const std::string &t_reason) throw()
: std::runtime_error(t_reason)
{
}
virtual ~load_module_error() throw() virtual ~load_module_error() throw()
{ {
} }
}; };
}
namespace detail
{
#ifdef _POSIX_VERSION #ifdef _POSIX_VERSION
struct Loadable_Module struct Loadable_Module
{
struct DLModule
{ {
DLModule(const std::string &t_filename) struct DLModule
: m_data(dlopen(t_filename.c_str(), RTLD_NOW))
{ {
if (!m_data) DLModule(const std::string &t_filename)
: m_data(dlopen(t_filename.c_str(), RTLD_NOW))
{
if (!m_data)
{ {
throw load_module_error(dlerror()); throw exception::load_module_error(dlerror());
} }
} }
DLModule(const DLModule &); // Explicitly unimplemented copy constructor DLModule(const DLModule &); // Explicitly unimplemented copy constructor
DLModule &operator=(const DLModule &); // Explicitly unimplemented assignment operator DLModule &operator=(const DLModule &); // Explicitly unimplemented assignment operator
~DLModule() ~DLModule()
{ {
dlclose(m_data); dlclose(m_data);
} }
void *m_data; void *m_data;
}; };
template<typename T> template<typename T>
struct DLSym struct DLSym
{ {
DLSym(DLModule &t_mod, const std::string &t_symbol) DLSym(DLModule &t_mod, const std::string &t_symbol)
: m_symbol(reinterpret_cast<T>(dlsym(t_mod.m_data, t_symbol.c_str()))) : m_symbol(reinterpret_cast<T>(dlsym(t_mod.m_data, t_symbol.c_str())))
{
if (!m_symbol)
{ {
throw load_module_error(dlerror()); if (!m_symbol)
{
throw exception::load_module_error(dlerror());
}
} }
}
T m_symbol; T m_symbol;
}; };
Loadable_Module(const std::string &t_module_name, const std::string &t_filename) Loadable_Module(const std::string &t_module_name, const std::string &t_filename)
: m_dlmodule(t_filename), m_func(m_dlmodule, "create_chaiscript_module_" + t_module_name), : m_dlmodule(t_filename), m_func(m_dlmodule, "create_chaiscript_module_" + t_module_name),
m_moduleptr(m_func.m_symbol()) m_moduleptr(m_func.m_symbol())
{ {
} }
DLModule m_dlmodule; DLModule m_dlmodule;
DLSym<Create_Module_Func> m_func; DLSym<Create_Module_Func> m_func;
ModulePtr m_moduleptr; ModulePtr m_moduleptr;
}; };
#else #else
#ifdef WIN32 #ifdef WIN32
struct Loadable_Module struct Loadable_Module
{
template<typename T>
static std::wstring towstring(const T &t_str)
{ {
return std::wstring(t_str.begin(), t_str.end()); template<typename T>
} static std::wstring towstring(const T &t_str)
{
return std::wstring(t_str.begin(), t_str.end());
}
template<typename T> template<typename T>
static std::string tostring(const T &t_str) static std::string tostring(const T &t_str)
{ {
return std::string(t_str.begin(), t_str.end()); return std::string(t_str.begin(), t_str.end());
} }
#ifdef _UNICODE #ifdef _UNICODE
template<typename T> template<typename T>
static std::wstring toproperstring(const T &t_str) static std::wstring toproperstring(const T &t_str)
{ {
return towstring(t_str); return towstring(t_str);
} }
#else #else
template<typename T> template<typename T>
static std::string toproperstring(const T &t_str) static std::string toproperstring(const T &t_str)
{ {
return tostring(t_str); return tostring(t_str);
} }
#endif #endif
static std::string GetErrorMessage(DWORD t_err) static std::string GetErrorMessage(DWORD t_err)
{ {
#ifdef _UNICODE #ifdef _UNICODE
typedef LPWSTR StringType; typedef LPWSTR StringType;
std::wstring retval = L"Unknown Error"; std::wstring retval = L"Unknown Error";
#else #else
typedef LPSTR StringType; typedef LPSTR StringType;
std::string retval = "Unknown Error"; std::string retval = "Unknown Error";
#endif #endif
StringType lpMsgBuf = 0; StringType lpMsgBuf = 0;
FormatMessage( FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, NULL,
t_err, t_err,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(StringType)&lpMsgBuf, (StringType)&lpMsgBuf,
0, NULL ); 0, NULL );
if (lpMsgBuf) if (lpMsgBuf)
{ {
retval = lpMsgBuf; retval = lpMsgBuf;
}
LocalFree(lpMsgBuf);
return tostring(retval);
} }
LocalFree(lpMsgBuf); struct DLModule
return tostring(retval);
}
struct DLModule
{
DLModule(const std::string &t_filename)
: m_data(LoadLibrary(toproperstring(t_filename).c_str()))
{ {
if (!m_data) DLModule(const std::string &t_filename)
: m_data(LoadLibrary(toproperstring(t_filename).c_str()))
{
if (!m_data)
{ {
throw load_module_error(GetErrorMessage(GetLastError())); throw exception::load_module_error(GetErrorMessage(GetLastError()));
} }
} }
~DLModule() ~DLModule()
{ {
FreeLibrary(m_data); FreeLibrary(m_data);
} }
HMODULE m_data; HMODULE m_data;
}; };
template<typename T> template<typename T>
struct DLSym struct DLSym
{ {
DLSym(DLModule &t_mod, const std::string &t_symbol) DLSym(DLModule &t_mod, const std::string &t_symbol)
: m_symbol(reinterpret_cast<T>(GetProcAddress(t_mod.m_data, t_symbol.c_str()))) : m_symbol(reinterpret_cast<T>(GetProcAddress(t_mod.m_data, t_symbol.c_str())))
{
if (!m_symbol)
{ {
throw load_module_error(GetErrorMessage(GetLastError())); if (!m_symbol)
{
throw exception::load_module_error(GetErrorMessage(GetLastError()));
}
} }
}
T m_symbol; T m_symbol;
}; };
Loadable_Module(const std::string &t_module_name, const std::string &t_filename) Loadable_Module(const std::string &t_module_name, const std::string &t_filename)
: m_dlmodule(t_filename), m_func(m_dlmodule, "create_chaiscript_module_" + t_module_name), : m_dlmodule(t_filename), m_func(m_dlmodule, "create_chaiscript_module_" + t_module_name),
m_moduleptr(m_func.m_symbol()) m_moduleptr(m_func.m_symbol())
{ {
} }
DLModule m_dlmodule; DLModule m_dlmodule;
DLSym<Create_Module_Func> m_func; DLSym<Create_Module_Func> m_func;
ModulePtr m_moduleptr; ModulePtr m_moduleptr;
}; };
#else #else
struct Loadable_Module struct Loadable_Module
{
Loadable_Module(const std::string &, const std::string &)
{ {
throw load_module_error("Loadable module support not available for your platform"); Loadable_Module(const std::string &, const std::string &)
} {
throw exception::load_module_error("Loadable module support not available for your platform");
}
ModulePtr get() ModulePtr get()
{ {
throw load_module_error("Loadable module support not available for your platform"); throw exception::load_module_error("Loadable module support not available for your platform");
} }
}; };
#endif #endif
#endif #endif
typedef boost::shared_ptr<Loadable_Module> Loadable_Module_Ptr; typedef boost::shared_ptr<Loadable_Module> Loadable_Module_Ptr;
}
class ChaiScript { class ChaiScript {
#ifndef CHAISCRIPT_NO_THREADS #ifndef CHAISCRIPT_NO_THREADS
@@ -223,7 +229,7 @@ namespace chaiscript
#endif #endif
std::set<std::string> m_used_files; std::set<std::string> m_used_files;
std::map<std::string, Loadable_Module_Ptr> m_loaded_modules; std::map<std::string, detail::Loadable_Module_Ptr> m_loaded_modules;
std::set<std::string> m_active_loaded_modules; std::set<std::string> m_active_loaded_modules;
std::vector<std::string> m_modulepaths; std::vector<std::string> m_modulepaths;
@@ -238,7 +244,7 @@ namespace chaiscript
Boxed_Value do_eval(const std::string &t_input, const std::string &t_filename = "__EVAL__", bool /* t_internal*/ = false) Boxed_Value do_eval(const std::string &t_input, const std::string &t_filename = "__EVAL__", bool /* t_internal*/ = false)
{ {
try { try {
ChaiScript_Parser parser; parser::ChaiScript_Parser parser;
if (parser.parse(t_input, t_filename)) { if (parser.parse(t_input, t_filename)) {
//parser.show_match_stack(); //parser.show_match_stack();
return parser.ast()->eval(m_engine); return parser.ast()->eval(m_engine);
@@ -246,7 +252,7 @@ namespace chaiscript
return Boxed_Value(); return Boxed_Value();
} }
} }
catch (const Return_Value &rv) { catch (const detail::Return_Value &rv) {
return rv.retval; return rv.retval;
} }
} }
@@ -287,10 +293,10 @@ namespace chaiscript
#endif #endif
eval_file(appendedpath); eval_file(appendedpath);
} }
} catch (const File_Not_Found_Error &) { } catch (const exception::file_not_found_error &) {
if (i == m_usepaths.size() - 1) if (i == m_usepaths.size() - 1)
{ {
throw File_Not_Found_Error(t_filename); throw exception::file_not_found_error(t_filename);
} }
// failed to load, try the next path // failed to load, try the next path
@@ -305,6 +311,56 @@ namespace chaiscript
return m_engine; return m_engine;
} }
/**
* Builds all the requirements for ChaiScript, including its evaluator and a run of its prelude.
*/
void build_eval_system() {
using namespace bootstrap;
m_engine.add_reserved_word("def");
m_engine.add_reserved_word("fun");
m_engine.add_reserved_word("while");
m_engine.add_reserved_word("for");
m_engine.add_reserved_word("if");
m_engine.add_reserved_word("else");
m_engine.add_reserved_word("&&");
m_engine.add_reserved_word("||");
m_engine.add_reserved_word(",");
m_engine.add_reserved_word(":=");
m_engine.add_reserved_word("var");
m_engine.add_reserved_word("return");
m_engine.add_reserved_word("break");
m_engine.add_reserved_word("true");
m_engine.add_reserved_word("false");
m_engine.add_reserved_word("_");
add(Bootstrap::bootstrap());
m_engine.add(fun(&Dispatch_Engine::dump_system, boost::ref(m_engine)), "dump_system");
m_engine.add(fun(&Dispatch_Engine::dump_object, boost::ref(m_engine)), "dump_object");
m_engine.add(fun(&Dispatch_Engine::is_type, boost::ref(m_engine)), "is_type");
m_engine.add(fun(&Dispatch_Engine::type_name, boost::ref(m_engine)), "type_name");
m_engine.add(fun(&Dispatch_Engine::function_exists, boost::ref(m_engine)), "function_exists");
m_engine.add(fun(&Dispatch_Engine::get_type_name, boost::ref(m_engine)), "name");
typedef void (ChaiScript::*load_mod_1)(const std::string&);
typedef void (ChaiScript::*load_mod_2)(const std::string&, const std::string&);
m_engine.add(fun(static_cast<load_mod_1>(&ChaiScript::load_module), this), "load_module");
m_engine.add(fun(static_cast<load_mod_2>(&ChaiScript::load_module), this), "load_module");
add(standard_library::vector_type<std::vector<Boxed_Value> >("Vector"));
add(standard_library::string_type<std::string>("string"));
add(standard_library::map_type<std::map<std::string, Boxed_Value> >("Map"));
add(standard_library::pair_type<std::pair<Boxed_Value, Boxed_Value > >("Pair"));
m_engine.add(fun(&ChaiScript::use, this), "use");
m_engine.add(fun(&ChaiScript::internal_eval, this), "eval");
m_engine.add(fun(&ChaiScript::internal_eval_ast, this), "eval");
do_eval(chaiscript_prelude, "standard prelude");
}
public: public:
ChaiScript(const std::vector<std::string> &t_modulepaths = std::vector<std::string>(), ChaiScript(const std::vector<std::string> &t_modulepaths = std::vector<std::string>(),
@@ -398,7 +454,7 @@ namespace chaiscript
*/ */
void load_module(const std::string &t_module_name) void load_module(const std::string &t_module_name)
{ {
std::vector<load_module_error> errors; std::vector<exception::load_module_error> errors;
std::vector<std::string> prefixes; std::vector<std::string> prefixes;
prefixes.push_back("lib"); prefixes.push_back("lib");
@@ -419,7 +475,7 @@ namespace chaiscript
std::string name = m_modulepaths[i] + prefixes[j] + t_module_name + postfixes[k]; std::string name = m_modulepaths[i] + prefixes[j] + t_module_name + postfixes[k];
load_module(t_module_name, name); load_module(t_module_name, name);
return; return;
} catch (const load_module_error &e) { } catch (const exception::load_module_error &e) {
errors.push_back(e); errors.push_back(e);
// Try next set // Try next set
} }
@@ -429,7 +485,7 @@ namespace chaiscript
std::string errstring; std::string errstring;
for (std::vector<load_module_error>::const_iterator itr = errors.begin(); for (std::vector<exception::load_module_error>::const_iterator itr = errors.begin();
itr != errors.end(); itr != errors.end();
++itr) ++itr)
{ {
@@ -441,7 +497,7 @@ namespace chaiscript
errstring += itr->what(); errstring += itr->what();
} }
throw load_module_error("Unable to find module: " + t_module_name + " Errors: " + errstring); throw exception::load_module_error("Unable to find module: " + t_module_name + " Errors: " + errstring);
} }
/** /**
@@ -455,7 +511,7 @@ namespace chaiscript
if (m_loaded_modules.count(t_module_name) == 0) if (m_loaded_modules.count(t_module_name) == 0)
{ {
Loadable_Module_Ptr lm(new Loadable_Module(t_module_name, t_filename)); detail::Loadable_Module_Ptr lm(new detail::Loadable_Module(t_module_name, t_filename));
m_loaded_modules[t_module_name] = lm; m_loaded_modules[t_module_name] = lm;
m_active_loaded_modules.insert(t_module_name); m_active_loaded_modules.insert(t_module_name);
add(lm->m_moduleptr); add(lm->m_moduleptr);
@@ -495,7 +551,7 @@ namespace chaiscript
std::ifstream infile(t_filename.c_str(), std::ios::in | std::ios::ate | std::ios::binary ); std::ifstream infile(t_filename.c_str(), std::ios::in | std::ios::ate | std::ios::binary );
if (!infile.is_open()) { if (!infile.is_open()) {
throw File_Not_Found_Error(t_filename); throw exception::file_not_found_error(t_filename);
} }
std::streampos size = infile.tellg(); std::streampos size = infile.tellg();
@@ -513,56 +569,6 @@ namespace chaiscript
} }
} }
/**
* Builds all the requirements for ChaiScript, including its evaluator and a run of its prelude.
*/
void build_eval_system() {
using namespace bootstrap;
m_engine.add_reserved_word("def");
m_engine.add_reserved_word("fun");
m_engine.add_reserved_word("while");
m_engine.add_reserved_word("for");
m_engine.add_reserved_word("if");
m_engine.add_reserved_word("else");
m_engine.add_reserved_word("&&");
m_engine.add_reserved_word("||");
m_engine.add_reserved_word(",");
m_engine.add_reserved_word(":=");
m_engine.add_reserved_word("var");
m_engine.add_reserved_word("return");
m_engine.add_reserved_word("break");
m_engine.add_reserved_word("true");
m_engine.add_reserved_word("false");
m_engine.add_reserved_word("_");
add(Bootstrap::bootstrap());
m_engine.add(fun(&Dispatch_Engine::dump_system, boost::ref(m_engine)), "dump_system");
m_engine.add(fun(&Dispatch_Engine::dump_object, boost::ref(m_engine)), "dump_object");
m_engine.add(fun(&Dispatch_Engine::is_type, boost::ref(m_engine)), "is_type");
m_engine.add(fun(&Dispatch_Engine::type_name, boost::ref(m_engine)), "type_name");
m_engine.add(fun(&Dispatch_Engine::function_exists, boost::ref(m_engine)), "function_exists");
m_engine.add(fun(&Dispatch_Engine::get_type_name, boost::ref(m_engine)), "name");
typedef void (ChaiScript::*load_mod_1)(const std::string&);
typedef void (ChaiScript::*load_mod_2)(const std::string&, const std::string&);
m_engine.add(fun(static_cast<load_mod_1>(&ChaiScript::load_module), this), "load_module");
m_engine.add(fun(static_cast<load_mod_2>(&ChaiScript::load_module), this), "load_module");
add(standard_library::vector_type<std::vector<Boxed_Value> >("Vector"));
add(standard_library::string_type<std::string>("string"));
add(standard_library::map_type<std::map<std::string, Boxed_Value> >("Map"));
add(standard_library::pair_type<std::pair<Boxed_Value, Boxed_Value > >("Pair"));
m_engine.add(fun(&ChaiScript::use, this), "use");
m_engine.add(fun(&ChaiScript::internal_eval, this), "eval");
m_engine.add(fun(&ChaiScript::internal_eval_ast, this), "eval");
do_eval(chaiscript_prelude, "standard prelude");
}
template<typename T> template<typename T>
T eval(const std::string &t_input) T eval(const std::string &t_input)

View File

@@ -28,10 +28,10 @@ namespace chaiscript
Boxed_Value retval(t_node->eval(t_ss)); Boxed_Value retval(t_node->eval(t_ss));
t_ss.pop_scope(); t_ss.pop_scope();
return retval; return retval;
} catch (const Return_Value &rv) { } catch (const detail::Return_Value &rv) {
t_ss.pop_scope(); t_ss.pop_scope();
return rv.retval; return rv.retval;
} catch (Eval_Error &ee) { } catch (exception::eval_error &ee) {
ee.call_stack.push_back(t_node); ee.call_stack.push_back(t_node);
t_ss.pop_scope(); t_ss.pop_scope();
throw; throw;
@@ -55,7 +55,7 @@ namespace chaiscript
try { try {
retval = this->children[0]->eval(t_ss); retval = this->children[0]->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]); ee.call_stack.push_back(this->children[0]);
throw; throw;
} }
@@ -65,9 +65,9 @@ namespace chaiscript
retval = t_ss.call_function(this->children[i]->text, retval, this->children[i+1]->eval(t_ss)); retval = t_ss.call_function(this->children[i]->text, retval, this->children[i+1]->eval(t_ss));
} }
catch(const exception::dispatch_error &){ catch(const exception::dispatch_error &){
throw Eval_Error("Can not find appropriate '" + this->children[i]->text + "'"); throw exception::eval_error("Can not find appropriate '" + this->children[i]->text + "'");
} }
catch(Eval_Error &ee) { catch(exception::eval_error &ee) {
ee.call_stack.push_back(this->children[i+1]); ee.call_stack.push_back(this->children[i+1]);
throw; throw;
} }
@@ -131,7 +131,7 @@ namespace chaiscript
return t_ss.get_object(this->text); return t_ss.get_object(this->text);
} }
catch (std::exception &) { catch (std::exception &) {
throw Eval_Error("Can not find object: " + this->text); throw exception::eval_error("Can not find object: " + this->text);
} }
} }
} }
@@ -171,7 +171,7 @@ namespace chaiscript
try { try {
plb << this->children[1]->children[i]->eval(t_ss); plb << this->children[1]->children[i]->eval(t_ss);
} }
catch(Eval_Error &ee) { catch(exception::eval_error &ee) {
ee.call_stack.push_back(this->children[1]->children[i]); ee.call_stack.push_back(this->children[1]->children[i]);
throw; throw;
} }
@@ -192,9 +192,9 @@ namespace chaiscript
} }
catch(const exception::dispatch_error &e){ catch(const exception::dispatch_error &e){
t_ss.set_stack(prev_stack); t_ss.set_stack(prev_stack);
throw Eval_Error(std::string(e.what()) + " with function '" + this->children[0]->text + "'"); throw exception::eval_error(std::string(e.what()) + " with function '" + this->children[0]->text + "'");
} }
catch(Return_Value &rv) { catch(detail::Return_Value &rv) {
t_ss.set_stack(prev_stack); t_ss.set_stack(prev_stack);
return rv.retval; return rv.retval;
} }
@@ -203,10 +203,10 @@ namespace chaiscript
throw; throw;
} }
} }
catch(Eval_Error &ee) { catch(exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]); ee.call_stack.push_back(this->children[0]);
t_ss.set_stack(prev_stack); t_ss.set_stack(prev_stack);
throw Eval_Error(ee.reason); throw exception::eval_error(ee.reason);
} }
} }
@@ -226,7 +226,7 @@ namespace chaiscript
try { try {
plb << this->children[1]->children[i]->eval(t_ss); plb << this->children[1]->children[i]->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[1]->children[i]); ee.call_stack.push_back(this->children[1]->children[i]);
throw; throw;
} }
@@ -240,18 +240,18 @@ namespace chaiscript
return (*boxed_cast<Const_Proxy_Function >(fn))(plb); return (*boxed_cast<Const_Proxy_Function >(fn))(plb);
} }
catch(const exception::dispatch_error &e){ catch(const exception::dispatch_error &e){
throw Eval_Error(std::string(e.what()) + " with function '" + this->children[0]->text + "'"); throw exception::eval_error(std::string(e.what()) + " with function '" + this->children[0]->text + "'");
} }
catch(Return_Value &rv) { catch(detail::Return_Value &rv) {
return rv.retval; return rv.retval;
} }
catch(...) { catch(...) {
throw; throw;
} }
} }
catch(Eval_Error &ee) { catch(exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]); ee.call_stack.push_back(this->children[0]);
throw Eval_Error(ee.reason); throw exception::eval_error(ee.reason);
} }
} }
@@ -282,7 +282,7 @@ namespace chaiscript
try { try {
retval = this->children.back()->eval(t_ss); retval = this->children.back()->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children.back()); ee.call_stack.push_back(this->children.back());
throw; throw;
} }
@@ -303,14 +303,14 @@ namespace chaiscript
retval = t_ss.call_function(this->children[i+1]->text, lhs, retval); retval = t_ss.call_function(this->children[i+1]->text, lhs, retval);
} }
catch(const exception::dispatch_error &){ catch(const exception::dispatch_error &){
throw Eval_Error(std::string("Mismatched types in equation") + (lhs.is_const()?", lhs is const.":".")); throw exception::eval_error(std::string("Mismatched types in equation") + (lhs.is_const()?", lhs is const.":"."));
} }
} }
catch(const exception::dispatch_error &){ catch(const exception::dispatch_error &){
throw Eval_Error("Can not clone right hand side of equation"); throw exception::eval_error("Can not clone right hand side of equation");
} }
} }
catch(Eval_Error &ee) { catch(exception::eval_error &ee) {
ee.call_stack.push_back(this->children[i]); ee.call_stack.push_back(this->children[i]);
throw; throw;
} }
@@ -322,10 +322,10 @@ namespace chaiscript
lhs.assign(retval); lhs.assign(retval);
} }
else { else {
throw Eval_Error("Mismatched types in equation"); throw exception::eval_error("Mismatched types in equation");
} }
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[i]); ee.call_stack.push_back(this->children[i]);
throw; throw;
} }
@@ -335,9 +335,9 @@ namespace chaiscript
retval = t_ss.call_function(this->children[i+1]->text, this->children[i]->eval(t_ss), retval); retval = t_ss.call_function(this->children[i+1]->text, this->children[i]->eval(t_ss), retval);
} }
catch(const exception::dispatch_error &){ catch(const exception::dispatch_error &){
throw Eval_Error("Can not find appropriate '" + this->children[i+1]->text + "'"); throw exception::eval_error("Can not find appropriate '" + this->children[i+1]->text + "'");
} }
catch(Eval_Error &ee) { catch(exception::eval_error &ee) {
ee.call_stack.push_back(this->children[i]); ee.call_stack.push_back(this->children[i]);
throw; throw;
} }
@@ -358,7 +358,7 @@ namespace chaiscript
t_ss.add_object(this->children[0]->text, Boxed_Value()); t_ss.add_object(this->children[0]->text, Boxed_Value());
} }
catch (const exception::reserved_word_error &) { catch (const exception::reserved_word_error &) {
throw Eval_Error("Reserved word used as variable '" + this->children[0]->text + "'"); throw exception::eval_error("Reserved word used as variable '" + this->children[0]->text + "'");
} }
return t_ss.get_object(this->children[0]->text); return t_ss.get_object(this->children[0]->text);
} }
@@ -397,7 +397,7 @@ namespace chaiscript
try { try {
retval = this->children[0]->eval(t_ss); retval = this->children[0]->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]); ee.call_stack.push_back(this->children[0]);
throw; throw;
} }
@@ -407,12 +407,12 @@ namespace chaiscript
retval = t_ss.call_function("[]", retval, this->children[i]->eval(t_ss)); retval = t_ss.call_function("[]", retval, this->children[i]->eval(t_ss));
} }
catch(std::out_of_range &) { catch(std::out_of_range &) {
throw Eval_Error("Out of bounds exception"); throw exception::eval_error("Out of bounds exception");
} }
catch(const exception::dispatch_error &){ catch(const exception::dispatch_error &){
throw Eval_Error("Can not find appropriate array lookup '[]' "); throw exception::eval_error("Can not find appropriate array lookup '[]' ");
} }
catch(Eval_Error &ee) { catch(exception::eval_error &ee) {
ee.call_stack.push_back(this->children[i]); ee.call_stack.push_back(this->children[i]);
throw; throw;
} }
@@ -432,7 +432,7 @@ namespace chaiscript
try { try {
retval = this->children[0]->eval(t_ss); retval = this->children[0]->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]); ee.call_stack.push_back(this->children[0]);
throw; throw;
} }
@@ -447,7 +447,7 @@ namespace chaiscript
try { try {
plb << this->children[i]->children[1]->children[j]->eval(t_ss); plb << this->children[i]->children[1]->children[j]->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[i]->children[1]->children[j]); ee.call_stack.push_back(this->children[i]->children[1]->children[j]);
throw; throw;
} }
@@ -472,9 +472,9 @@ namespace chaiscript
} }
catch(const exception::dispatch_error &e){ catch(const exception::dispatch_error &e){
t_ss.set_stack(prev_stack); t_ss.set_stack(prev_stack);
throw Eval_Error(std::string(e.what())); throw exception::eval_error(std::string(e.what()));
} }
catch(Return_Value &rv) { catch(detail::Return_Value &rv) {
t_ss.set_stack(prev_stack); t_ss.set_stack(prev_stack);
retval = rv.retval; retval = rv.retval;
} }
@@ -488,12 +488,12 @@ namespace chaiscript
retval = t_ss.call_function("[]", retval, this->children[i]->children[j]->eval(t_ss)); retval = t_ss.call_function("[]", retval, this->children[i]->children[j]->eval(t_ss));
} }
catch(std::out_of_range &) { catch(std::out_of_range &) {
throw Eval_Error("Out of bounds exception"); throw exception::eval_error("Out of bounds exception");
} }
catch(const exception::dispatch_error &){ catch(const exception::dispatch_error &){
throw Eval_Error("Can not find appropriate array lookup '[]' "); throw exception::eval_error("Can not find appropriate array lookup '[]' ");
} }
catch(Eval_Error &ee) { catch(exception::eval_error &ee) {
ee.call_stack.push_back(this->children[i]->children[j]); ee.call_stack.push_back(this->children[i]->children[j]);
throw; throw;
} }
@@ -576,11 +576,11 @@ namespace chaiscript
return retval; return retval;
} }
} }
catch (const chaiscript::Return_Value &) { catch (const chaiscript::detail::Return_Value &) {
t_ss.pop_scope(); t_ss.pop_scope();
throw; throw;
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[i]); ee.call_stack.push_back(this->children[i]);
t_ss.pop_scope(); t_ss.pop_scope();
throw; throw;
@@ -644,7 +644,7 @@ namespace chaiscript
l_annotation, guard)), l_function_name); l_annotation, guard)), l_function_name);
} }
catch (const exception::reserved_word_error &e) { catch (const exception::reserved_word_error &e) {
throw Eval_Error("Reserved word used as function name '" + e.word() + "'"); throw exception::eval_error("Reserved word used as function name '" + e.word() + "'");
} }
return Boxed_Value(); return Boxed_Value();
} }
@@ -666,9 +666,9 @@ namespace chaiscript
} }
catch (const exception::bad_boxed_cast &) { catch (const exception::bad_boxed_cast &) {
t_ss.pop_scope(); t_ss.pop_scope();
throw Eval_Error("While condition not boolean"); throw exception::eval_error("While condition not boolean");
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]); ee.call_stack.push_back(this->children[0]);
t_ss.pop_scope(); t_ss.pop_scope();
throw; throw;
@@ -678,7 +678,7 @@ namespace chaiscript
try { try {
this->children[1]->eval(t_ss); this->children[1]->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[1]); ee.call_stack.push_back(this->children[1]);
throw; throw;
} }
@@ -688,15 +688,15 @@ namespace chaiscript
} }
catch (const exception::bad_boxed_cast &) { catch (const exception::bad_boxed_cast &) {
t_ss.pop_scope(); t_ss.pop_scope();
throw Eval_Error("While condition not boolean"); throw exception::eval_error("While condition not boolean");
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]); ee.call_stack.push_back(this->children[0]);
t_ss.pop_scope(); t_ss.pop_scope();
throw; throw;
} }
} }
catch (Break_Loop &) { catch (detail::Break_Loop &) {
cond = false; cond = false;
} }
} }
@@ -717,9 +717,9 @@ namespace chaiscript
cond = boxed_cast<bool>(this->children[0]->eval(t_ss)); cond = boxed_cast<bool>(this->children[0]->eval(t_ss));
} }
catch (const exception::bad_boxed_cast &) { catch (const exception::bad_boxed_cast &) {
throw Eval_Error("If condition not boolean"); throw exception::eval_error("If condition not boolean");
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]); ee.call_stack.push_back(this->children[0]);
throw; throw;
} }
@@ -728,7 +728,7 @@ namespace chaiscript
try { try {
return this->children[1]->eval(t_ss); return this->children[1]->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[1]); ee.call_stack.push_back(this->children[1]);
throw; throw;
} }
@@ -741,7 +741,7 @@ namespace chaiscript
try { try {
return this->children[i+1]->eval(t_ss); return this->children[i+1]->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[i+1]); ee.call_stack.push_back(this->children[i+1]);
throw; throw;
} }
@@ -751,9 +751,9 @@ namespace chaiscript
cond = boxed_cast<bool>(this->children[i+1]->eval(t_ss)); cond = boxed_cast<bool>(this->children[i+1]->eval(t_ss));
} }
catch (const exception::bad_boxed_cast &) { catch (const exception::bad_boxed_cast &) {
throw Eval_Error("'else if' condition not boolean"); throw exception::eval_error("'else if' condition not boolean");
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[i+1]); ee.call_stack.push_back(this->children[i+1]);
throw; throw;
} }
@@ -761,7 +761,7 @@ namespace chaiscript
try { try {
return this->children[i+2]->eval(t_ss); return this->children[i+2]->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[i+2]); ee.call_stack.push_back(this->children[i+2]);
throw; throw;
} }
@@ -792,7 +792,7 @@ namespace chaiscript
try { try {
this->children[0]->eval(t_ss); this->children[0]->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]); ee.call_stack.push_back(this->children[0]);
throw; throw;
} }
@@ -800,7 +800,7 @@ namespace chaiscript
try { try {
cond = boxed_cast<bool>(this->children[1]->eval(t_ss)); cond = boxed_cast<bool>(this->children[1]->eval(t_ss));
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[1]); ee.call_stack.push_back(this->children[1]);
throw; throw;
} }
@@ -809,7 +809,7 @@ namespace chaiscript
try { try {
cond = boxed_cast<bool>(this->children[0]->eval(t_ss)); cond = boxed_cast<bool>(this->children[0]->eval(t_ss));
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]); ee.call_stack.push_back(this->children[0]);
t_ss.pop_scope(); t_ss.pop_scope();
throw; throw;
@@ -818,7 +818,7 @@ namespace chaiscript
} }
catch (const exception::bad_boxed_cast &) { catch (const exception::bad_boxed_cast &) {
t_ss.pop_scope(); t_ss.pop_scope();
throw Eval_Error("For condition not boolean"); throw exception::eval_error("For condition not boolean");
} }
while (cond) { while (cond) {
try { try {
@@ -826,7 +826,7 @@ namespace chaiscript
try { try {
this->children[3]->eval(t_ss); this->children[3]->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[3]); ee.call_stack.push_back(this->children[3]);
throw; throw;
} }
@@ -834,7 +834,7 @@ namespace chaiscript
try { try {
this->children[2]->eval(t_ss); this->children[2]->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[2]); ee.call_stack.push_back(this->children[2]);
throw; throw;
} }
@@ -842,7 +842,7 @@ namespace chaiscript
try { try {
cond = boxed_cast<bool>(this->children[1]->eval(t_ss)); cond = boxed_cast<bool>(this->children[1]->eval(t_ss));
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[1]); ee.call_stack.push_back(this->children[1]);
throw; throw;
} }
@@ -851,7 +851,7 @@ namespace chaiscript
try { try {
this->children[2]->eval(t_ss); this->children[2]->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[2]); ee.call_stack.push_back(this->children[2]);
throw; throw;
} }
@@ -859,7 +859,7 @@ namespace chaiscript
try { try {
this->children[1]->eval(t_ss); this->children[1]->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[1]); ee.call_stack.push_back(this->children[1]);
throw; throw;
} }
@@ -867,7 +867,7 @@ namespace chaiscript
try { try {
cond = boxed_cast<bool>(this->children[0]->eval(t_ss)); cond = boxed_cast<bool>(this->children[0]->eval(t_ss));
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]); ee.call_stack.push_back(this->children[0]);
t_ss.pop_scope(); t_ss.pop_scope();
throw; throw;
@@ -876,9 +876,9 @@ namespace chaiscript
} }
catch (const exception::bad_boxed_cast &) { catch (const exception::bad_boxed_cast &) {
t_ss.pop_scope(); t_ss.pop_scope();
throw Eval_Error("For condition not boolean"); throw exception::eval_error("For condition not boolean");
} }
catch (Break_Loop &) { catch (detail::Break_Loop &) {
cond = false; cond = false;
} }
} }
@@ -900,7 +900,7 @@ namespace chaiscript
try { try {
vec.push_back(this->children[0]->children[i]->eval(t_ss)); vec.push_back(this->children[0]->children[i]->eval(t_ss));
} }
catch(Eval_Error &ee) { catch(exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]->children[i]); ee.call_stack.push_back(this->children[0]->children[i]);
throw; throw;
} }
@@ -925,7 +925,7 @@ namespace chaiscript
retval[boxed_cast<std::string>(this->children[0]->children[i]->children[0]->eval(t_ss))] retval[boxed_cast<std::string>(this->children[0]->children[i]->children[0]->eval(t_ss))]
= t_ss.call_function("clone", this->children[0]->children[i]->children[1]->eval(t_ss)); = t_ss.call_function("clone", this->children[0]->children[i]->children[1]->eval(t_ss));
} }
catch(Eval_Error &ee) { catch(exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]->children[i]); ee.call_stack.push_back(this->children[0]->children[i]);
throw; throw;
} }
@@ -933,7 +933,7 @@ namespace chaiscript
return const_var(retval); return const_var(retval);
} }
catch (const exception::dispatch_error &) { catch (const exception::dispatch_error &) {
throw Eval_Error("Can not find appropriate 'Map()'"); throw exception::eval_error("Can not find appropriate 'Map()'");
} }
} }
@@ -947,15 +947,15 @@ namespace chaiscript
virtual Boxed_Value eval(Dispatch_Engine &t_ss){ virtual Boxed_Value eval(Dispatch_Engine &t_ss){
if (this->children.size() > 0) { if (this->children.size() > 0) {
try { try {
throw Return_Value(this->children[0]->eval(t_ss)); throw detail::Return_Value(this->children[0]->eval(t_ss));
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]); ee.call_stack.push_back(this->children[0]);
throw; throw;
} }
} }
else { else {
throw Return_Value(Boxed_Value()); throw detail::Return_Value(Boxed_Value());
} }
} }
@@ -975,7 +975,7 @@ namespace chaiscript
return retval; return retval;
} }
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[i]); ee.call_stack.push_back(this->children[i]);
throw; throw;
} }
@@ -994,7 +994,7 @@ namespace chaiscript
return t_ss.call_function(this->children[0]->text, this->children[1]->eval(t_ss)); return t_ss.call_function(this->children[0]->text, this->children[1]->eval(t_ss));
} }
catch(std::exception &){ catch(std::exception &){
throw Eval_Error("Can not find appropriate unary '" + this->children[0]->text + "'"); throw exception::eval_error("Can not find appropriate unary '" + this->children[0]->text + "'");
} }
} }
@@ -1006,7 +1006,7 @@ namespace chaiscript
AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { }
virtual ~Break_AST_Node() {} virtual ~Break_AST_Node() {}
virtual Boxed_Value eval(Dispatch_Engine &){ virtual Boxed_Value eval(Dispatch_Engine &){
throw Break_Loop(); throw detail::Break_Loop();
} }
}; };
@@ -1036,9 +1036,9 @@ namespace chaiscript
this->children[0]->children[0]->children[1]->eval(t_ss)); this->children[0]->children[0]->children[1]->eval(t_ss));
} }
catch (const exception::dispatch_error &) { catch (const exception::dispatch_error &) {
throw Eval_Error("Unable to generate range vector"); throw exception::eval_error("Unable to generate range vector");
} }
catch(Eval_Error &ee) { catch(exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]->children[0]); ee.call_stack.push_back(this->children[0]->children[0]);
throw; throw;
} }
@@ -1065,13 +1065,13 @@ namespace chaiscript
try { try {
retval = this->children[0]->eval(t_ss); retval = this->children[0]->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]); ee.call_stack.push_back(this->children[0]);
if (this->children.back()->identifier == AST_Node_Type::Finally) { if (this->children.back()->identifier == AST_Node_Type::Finally) {
try { try {
this->children.back()->children[0]->eval(t_ss); this->children.back()->children[0]->eval(t_ss);
} }
catch (Eval_Error &ee2) { catch (exception::eval_error &ee2) {
ee2.call_stack.push_back(this->children.back()->children[0]); ee2.call_stack.push_back(this->children.back()->children[0]);
t_ss.pop_scope(); t_ss.pop_scope();
throw; throw;
@@ -1096,7 +1096,7 @@ namespace chaiscript
try { try {
retval = catch_block->children[0]->eval(t_ss); retval = catch_block->children[0]->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(catch_block->children[0]); ee.call_stack.push_back(catch_block->children[0]);
throw; throw;
} }
@@ -1108,7 +1108,7 @@ namespace chaiscript
try { try {
retval = catch_block->children[1]->eval(t_ss); retval = catch_block->children[1]->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(catch_block->children[1]); ee.call_stack.push_back(catch_block->children[1]);
throw; throw;
} }
@@ -1127,20 +1127,20 @@ namespace chaiscript
try { try {
this->children.back()->children[0]->eval(t_ss); this->children.back()->children[0]->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children.back()->children[0]); ee.call_stack.push_back(this->children.back()->children[0]);
t_ss.pop_scope(); t_ss.pop_scope();
throw; throw;
} }
} }
t_ss.pop_scope(); t_ss.pop_scope();
throw Eval_Error("Guard condition not boolean"); throw exception::eval_error("Guard condition not boolean");
} }
if (guard) { if (guard) {
try { try {
retval = catch_block->children[2]->eval(t_ss); retval = catch_block->children[2]->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(catch_block->children[2]); ee.call_stack.push_back(catch_block->children[2]);
throw; throw;
} }
@@ -1153,14 +1153,14 @@ namespace chaiscript
try { try {
this->children.back()->children[0]->eval(t_ss); this->children.back()->children[0]->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children.back()->children[0]); ee.call_stack.push_back(this->children.back()->children[0]);
t_ss.pop_scope(); t_ss.pop_scope();
throw; throw;
} }
} }
t_ss.pop_scope(); t_ss.pop_scope();
throw Eval_Error("Internal error: catch block size unrecognized"); throw exception::eval_error("Internal error: catch block size unrecognized");
} }
} }
} }
@@ -1174,7 +1174,7 @@ namespace chaiscript
try { try {
retval = catch_block->children[0]->eval(t_ss); retval = catch_block->children[0]->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(catch_block->children[0]); ee.call_stack.push_back(catch_block->children[0]);
throw; throw;
} }
@@ -1187,7 +1187,7 @@ namespace chaiscript
try { try {
retval = catch_block->children[1]->eval(t_ss); retval = catch_block->children[1]->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(catch_block->children[1]); ee.call_stack.push_back(catch_block->children[1]);
throw; throw;
} }
@@ -1207,7 +1207,7 @@ namespace chaiscript
try { try {
this->children.back()->children[0]->eval(t_ss); this->children.back()->children[0]->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children.back()->children[0]); ee.call_stack.push_back(this->children.back()->children[0]);
t_ss.pop_scope(); t_ss.pop_scope();
throw; throw;
@@ -1215,9 +1215,9 @@ namespace chaiscript
} }
t_ss.pop_scope(); t_ss.pop_scope();
throw Eval_Error("Guard condition not boolean"); throw exception::eval_error("Guard condition not boolean");
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(catch_block->children[1]); ee.call_stack.push_back(catch_block->children[1]);
throw; throw;
} }
@@ -1225,7 +1225,7 @@ namespace chaiscript
try { try {
retval = catch_block->children[2]->eval(t_ss); retval = catch_block->children[2]->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(catch_block->children[2]); ee.call_stack.push_back(catch_block->children[2]);
throw; throw;
} }
@@ -1237,14 +1237,14 @@ namespace chaiscript
try { try {
this->children.back()->children[0]->eval(t_ss); this->children.back()->children[0]->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children.back()->children[0]); ee.call_stack.push_back(this->children.back()->children[0]);
t_ss.pop_scope(); t_ss.pop_scope();
throw; throw;
} }
} }
t_ss.pop_scope(); t_ss.pop_scope();
throw Eval_Error("Internal error: catch block size unrecognized"); throw exception::eval_error("Internal error: catch block size unrecognized");
} }
} }
} }
@@ -1253,7 +1253,7 @@ namespace chaiscript
try { try {
this->children.back()->children[0]->eval(t_ss); this->children.back()->children[0]->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children.back()->children[0]); ee.call_stack.push_back(this->children.back()->children[0]);
t_ss.pop_scope(); t_ss.pop_scope();
throw; throw;
@@ -1267,7 +1267,7 @@ namespace chaiscript
try { try {
retval = this->children.back()->children[0]->eval(t_ss); retval = this->children.back()->children[0]->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children.back()->children[0]); ee.call_stack.push_back(this->children.back()->children[0]);
t_ss.pop_scope(); t_ss.pop_scope();
throw; throw;
@@ -1365,7 +1365,7 @@ namespace chaiscript
} }
} }
catch (const exception::reserved_word_error &e) { catch (const exception::reserved_word_error &e) {
throw Eval_Error("Reserved word used as method name '" + e.word() + "'"); throw exception::eval_error("Reserved word used as method name '" + e.word() + "'");
} }
return Boxed_Value(); return Boxed_Value();
} }
@@ -1384,7 +1384,7 @@ namespace chaiscript
} }
catch (const exception::reserved_word_error &) { catch (const exception::reserved_word_error &) {
throw Eval_Error("Reserved word used as attribute '" + this->children[1]->text + "'"); throw exception::eval_error("Reserved word used as attribute '" + this->children[1]->text + "'");
} }
return Boxed_Value(); return Boxed_Value();
} }
@@ -1436,7 +1436,7 @@ namespace chaiscript
try { try {
retval = this->children[0]->eval(t_ss); retval = this->children[0]->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]); ee.call_stack.push_back(this->children[0]);
throw; throw;
} }
@@ -1448,13 +1448,13 @@ namespace chaiscript
lhs = boxed_cast<bool>(retval); lhs = boxed_cast<bool>(retval);
} }
catch (const exception::bad_boxed_cast &) { catch (const exception::bad_boxed_cast &) {
throw Eval_Error("Condition not boolean"); throw exception::eval_error("Condition not boolean");
} }
if (lhs) { if (lhs) {
try { try {
retval = this->children[i+1]->eval(t_ss); retval = this->children[i+1]->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[i+1]); ee.call_stack.push_back(this->children[i+1]);
throw; throw;
} }
@@ -1479,7 +1479,7 @@ namespace chaiscript
try { try {
retval = this->children[0]->eval(t_ss); retval = this->children[0]->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]); ee.call_stack.push_back(this->children[0]);
throw; throw;
} }
@@ -1491,7 +1491,7 @@ namespace chaiscript
lhs = boxed_cast<bool>(retval); lhs = boxed_cast<bool>(retval);
} }
catch (const exception::bad_boxed_cast &) { catch (const exception::bad_boxed_cast &) {
throw Eval_Error("Condition not boolean"); throw exception::eval_error("Condition not boolean");
} }
if (lhs) { if (lhs) {
retval = Boxed_Value(true); retval = Boxed_Value(true);
@@ -1500,7 +1500,7 @@ namespace chaiscript
try { try {
retval = this->children[i+1]->eval(t_ss); retval = this->children[i+1]->eval(t_ss);
} }
catch (Eval_Error &ee) { catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[i+1]); ee.call_stack.push_back(this->children[i+1]);
throw; throw;
} }

File diff suppressed because it is too large Load Diff

View File

@@ -107,14 +107,14 @@ void interactive(chaiscript::ChaiScript& chai)
catch (...) {} //If we can't, do nothing catch (...) {} //If we can't, do nothing
} }
} }
catch (chaiscript::Eval_Error &ee) { catch (const chaiscript::exception::eval_error &ee) {
std::cout << ee.what(); std::cout << ee.what();
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 << std::endl;
} }
catch (std::exception &e) { catch (const std::exception &e) {
std::cout << e.what(); std::cout << e.what();
std::cout << std::endl; std::cout << std::endl;
} }
@@ -205,7 +205,7 @@ int main(int argc, char *argv[])
case eFile : val = chai.eval_file(arg); break; case eFile : val = chai.eval_file(arg); break;
} }
} }
catch (chaiscript::Eval_Error &ee) { catch (const chaiscript::exception::eval_error &ee) {
std::cout << ee.what(); std::cout << ee.what();
if (ee.call_stack.size() > 0) { 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 << ")"; std::cout << "during evaluation at (" << *(ee.call_stack[0]->filename) << " " << ee.call_stack[0]->start.line << ", " << ee.call_stack[0]->start.column << ")";

View File

@@ -71,8 +71,8 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_reflect
); );
CHAISCRIPT_CLASS( m, CHAISCRIPT_CLASS( m,
chaiscript::ChaiScript_Parser, chaiscript::parser::ChaiScript_Parser,
(chaiscript::ChaiScript_Parser ()), (chaiscript::parser::ChaiScript_Parser ()),
((parse)) ((parse))
((ast)) ((ast))
); );