Merge branch '2011-09-09-CxScript' of https://github.com/ChaiScript/ChaiScript into 2011-09-09-CxScript
Conflicts: include/chaiscript/language/chaiscript_parser.hpp
This commit is contained in:
@@ -348,17 +348,13 @@ namespace chaiscript
|
|||||||
static std::vector<Boxed_Value> do_return_boxed_value_vector(FunctionType f,
|
static std::vector<Boxed_Value> do_return_boxed_value_vector(FunctionType f,
|
||||||
const dispatch::Proxy_Function_Base *b)
|
const dispatch::Proxy_Function_Base *b)
|
||||||
{
|
{
|
||||||
typedef decltype(std::mem_fn(f)) MemFunType;
|
auto v = (b->*f)();
|
||||||
typedef typename MemFunType::result_type Vector;
|
|
||||||
|
|
||||||
Vector v = (b->*f)();
|
|
||||||
|
|
||||||
std::vector<Boxed_Value> vbv;
|
std::vector<Boxed_Value> vbv;
|
||||||
for (typename Vector::const_iterator itr = v.begin();
|
|
||||||
itr != v.end();
|
for (const auto &o: v)
|
||||||
++itr)
|
|
||||||
{
|
{
|
||||||
vbv.push_back(const_var(*itr));
|
vbv.push_back(const_var(o));
|
||||||
}
|
}
|
||||||
|
|
||||||
return vbv;
|
return vbv;
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ namespace chaiscript
|
|||||||
return detail::Cast_Helper<Type>::cast(bv);
|
return detail::Cast_Helper<Type>::cast(bv);
|
||||||
} catch (const chaiscript::detail::exception::bad_any_cast &) {
|
} catch (const chaiscript::detail::exception::bad_any_cast &) {
|
||||||
|
|
||||||
|
|
||||||
#ifdef CHAISCRIPT_MSVC
|
#ifdef CHAISCRIPT_MSVC
|
||||||
//Thank you MSVC, yes we know that a constant value is being used in the if
|
//Thank you MSVC, yes we know that a constant value is being used in the if
|
||||||
// statment in THIS VERSION of the template instantiation
|
// statment in THIS VERSION of the template instantiation
|
||||||
|
|||||||
@@ -688,10 +688,9 @@ namespace chaiscript
|
|||||||
/**
|
/**
|
||||||
* Dump object info to stdout
|
* Dump object info to stdout
|
||||||
*/
|
*/
|
||||||
void dump_object(Boxed_Value o) const
|
void dump_object(const Boxed_Value &o) const
|
||||||
{
|
{
|
||||||
Type_Info ti = o.get_type_info();
|
std::cout << (o.is_const()?"const ":"") << type_name(o) << std::endl;
|
||||||
std::cout << (ti.is_const()?"const ":"") << get_type_name(ti) << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -783,7 +782,7 @@ namespace chaiscript
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string type_name(Boxed_Value obj) const
|
std::string type_name(const Boxed_Value &obj) const
|
||||||
{
|
{
|
||||||
return get_type_name(obj.get_type_info());
|
return get_type_name(obj.get_type_info());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,9 +111,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
virtual std::vector<Const_Proxy_Function> get_contained_functions() const
|
virtual std::vector<Const_Proxy_Function> get_contained_functions() const
|
||||||
{
|
{
|
||||||
std::vector<Const_Proxy_Function> fs;
|
return {m_func};
|
||||||
fs.push_back(m_func);
|
|
||||||
return fs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -28,37 +28,6 @@ namespace chaiscript
|
|||||||
|
|
||||||
namespace dispatch
|
namespace dispatch
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Helper for building a list of parameters for calling a Proxy_Function
|
|
||||||
* it does automatic conversion to Boxed_Value types via operator<<
|
|
||||||
*
|
|
||||||
* example usage:
|
|
||||||
* Boxed_Value retval = dispatch(dispatchengine.get_function("+"),
|
|
||||||
* chaiscript::Param_List_Builder() << 5 << 6);
|
|
||||||
*/
|
|
||||||
struct Param_List_Builder
|
|
||||||
{
|
|
||||||
Param_List_Builder &operator<<(const Boxed_Value &so)
|
|
||||||
{
|
|
||||||
objects.push_back(so);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
Param_List_Builder &operator<<(T t)
|
|
||||||
{
|
|
||||||
objects.push_back(Boxed_Value(t));
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator const std::vector<Boxed_Value> &() const
|
|
||||||
{
|
|
||||||
return objects;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<Boxed_Value> objects;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pure virtual base class for all Proxy_Function implementations
|
* Pure virtual base class for all Proxy_Function implementations
|
||||||
* Proxy_Functions are a type erasure of type safe C++
|
* Proxy_Functions are a type erasure of type safe C++
|
||||||
@@ -82,7 +51,7 @@ namespace chaiscript
|
|||||||
/// if the function is variadic or takes no arguments (arity of 0 or -1), the returned
|
/// if the function is variadic or takes no arguments (arity of 0 or -1), the returned
|
||||||
/// value containes exactly 1 Type_Info object: the return type
|
/// value containes exactly 1 Type_Info object: the return type
|
||||||
/// \returns the types of all parameters.
|
/// \returns the types of all parameters.
|
||||||
std::vector<Type_Info> get_param_types() const { return m_types; }
|
const std::vector<Type_Info> &get_param_types() const { return m_types; }
|
||||||
|
|
||||||
virtual bool operator==(const Proxy_Function_Base &) const = 0;
|
virtual bool operator==(const Proxy_Function_Base &) const = 0;
|
||||||
virtual bool call_match(const std::vector<Boxed_Value> &vals) const = 0;
|
virtual bool call_match(const std::vector<Boxed_Value> &vals) const = 0;
|
||||||
@@ -293,7 +262,7 @@ namespace chaiscript
|
|||||||
// For the return type
|
// For the return type
|
||||||
types.push_back(chaiscript::detail::Get_Type_Info<Boxed_Value>::get());
|
types.push_back(chaiscript::detail::Get_Type_Info<Boxed_Value>::get());
|
||||||
|
|
||||||
if (arity >= 0)
|
if (arity > 0)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < arity; ++i)
|
for (int i = 0; i < arity; ++i)
|
||||||
{
|
{
|
||||||
@@ -409,6 +378,7 @@ namespace chaiscript
|
|||||||
const std::vector<Boxed_Value> &t_args)
|
const std::vector<Boxed_Value> &t_args)
|
||||||
{
|
{
|
||||||
assert(t_f->get_arity() < 0 || t_f->get_arity() == static_cast<int>(t_args.size()));
|
assert(t_f->get_arity() < 0 || t_f->get_arity() == static_cast<int>(t_args.size()));
|
||||||
|
|
||||||
if (t_f->get_arity() < 0) { return std::vector<Type_Info>(); }
|
if (t_f->get_arity() < 0) { return std::vector<Type_Info>(); }
|
||||||
|
|
||||||
std::vector<Type_Info> types = t_f->get_param_types();
|
std::vector<Type_Info> types = t_f->get_param_types();
|
||||||
@@ -450,8 +420,8 @@ namespace chaiscript
|
|||||||
Proxy_Function_Impl(const std::function<Func> &f)
|
Proxy_Function_Impl(const std::function<Func> &f)
|
||||||
: Proxy_Function_Base(detail::build_param_type_list(static_cast<Func *>(0))),
|
: Proxy_Function_Base(detail::build_param_type_list(static_cast<Func *>(0))),
|
||||||
m_f(f), m_dummy_func(0)
|
m_f(f), m_dummy_func(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~Proxy_Function_Impl() {}
|
virtual ~Proxy_Function_Impl() {}
|
||||||
|
|
||||||
@@ -461,13 +431,11 @@ namespace chaiscript
|
|||||||
return pimpl != 0;
|
return pimpl != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual int get_arity() const
|
virtual int get_arity() const
|
||||||
{
|
{
|
||||||
return static_cast<int>(m_types.size()) - 1;
|
return static_cast<int>(m_types.size()) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual bool call_match(const std::vector<Boxed_Value> &vals) const
|
virtual bool call_match(const std::vector<Boxed_Value> &vals) const
|
||||||
{
|
{
|
||||||
if (int(vals.size()) != get_arity())
|
if (int(vals.size()) != get_arity())
|
||||||
@@ -509,8 +477,8 @@ namespace chaiscript
|
|||||||
Attribute_Access(T Class::* t_attr)
|
Attribute_Access(T Class::* t_attr)
|
||||||
: Proxy_Function_Base(param_types()),
|
: Proxy_Function_Base(param_types()),
|
||||||
m_attr(t_attr)
|
m_attr(t_attr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~Attribute_Access() {}
|
virtual ~Attribute_Access() {}
|
||||||
|
|
||||||
@@ -518,6 +486,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
const Attribute_Access<T, Class> * aa
|
const Attribute_Access<T, Class> * aa
|
||||||
= dynamic_cast<const Attribute_Access<T, Class> *>(&t_func);
|
= dynamic_cast<const Attribute_Access<T, Class> *>(&t_func);
|
||||||
|
|
||||||
if (aa) {
|
if (aa) {
|
||||||
return m_attr == aa->m_attr;
|
return m_attr == aa->m_attr;
|
||||||
} else {
|
} else {
|
||||||
@@ -568,11 +537,9 @@ namespace chaiscript
|
|||||||
private:
|
private:
|
||||||
static std::vector<Type_Info> param_types()
|
static std::vector<Type_Info> param_types()
|
||||||
{
|
{
|
||||||
std::vector<Type_Info> v;
|
return {user_type<T>(), user_type<Class>()};
|
||||||
v.push_back(user_type<T>());
|
|
||||||
v.push_back(user_type<Class>());
|
|
||||||
return v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
T Class::* m_attr;
|
T Class::* m_attr;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -587,17 +554,14 @@ namespace chaiscript
|
|||||||
class dispatch_error : public std::runtime_error
|
class dispatch_error : public std::runtime_error
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
dispatch_error() noexcept
|
dispatch_error(const std::vector<Boxed_Value> &t_bvs)
|
||||||
: std::runtime_error("No matching function to dispatch to")
|
: std::runtime_error("Error with function dispatch"), parameters(t_bvs)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch_error(bool is_const) noexcept
|
|
||||||
: std::runtime_error(std::string("No matching function to dispatch to") + (is_const?", parameter is const":""))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~dispatch_error() noexcept {}
|
virtual ~dispatch_error() noexcept {}
|
||||||
|
|
||||||
|
std::vector<Boxed_Value> parameters;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -610,7 +574,7 @@ namespace chaiscript
|
|||||||
* function is found or throw dispatch_error if no matching function is found
|
* function is found or throw dispatch_error if no matching function is found
|
||||||
*/
|
*/
|
||||||
template<typename InItr>
|
template<typename InItr>
|
||||||
Boxed_Value dispatch(InItr begin, InItr end,
|
Boxed_Value dispatch(InItr begin, const InItr &end,
|
||||||
const std::vector<Boxed_Value> &plist)
|
const std::vector<Boxed_Value> &plist)
|
||||||
{
|
{
|
||||||
while (begin != end)
|
while (begin != end)
|
||||||
@@ -631,7 +595,7 @@ namespace chaiscript
|
|||||||
++begin;
|
++begin;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw exception::dispatch_error(plist.empty()?false:plist[0].is_const());
|
throw exception::dispatch_error(plist);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace chaiscript
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
struct Bare_Type
|
struct Bare_Type
|
||||||
{
|
{
|
||||||
typedef typename std::remove_const<typename std::remove_pointer<typename std::remove_reference<T>::type>::type>::type type;
|
typedef typename std::remove_cv<typename std::remove_pointer<typename std::remove_reference<T>::type>::type>::type type;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,10 +70,23 @@ namespace chaiscript
|
|||||||
std::string filename;
|
std::string filename;
|
||||||
std::vector<AST_NodePtr> call_stack;
|
std::vector<AST_NodePtr> call_stack;
|
||||||
|
|
||||||
|
eval_error(const std::string &t_why, const File_Position &t_where, const std::string &t_fname,
|
||||||
|
const std::vector<Boxed_Value> &t_parameters, const chaiscript::detail::Dispatch_Engine &t_ss) noexcept :
|
||||||
|
std::runtime_error(format(t_why, t_where, t_fname, t_parameters, t_ss)),
|
||||||
|
reason(t_why), start_position(t_where), end_position(t_where), filename(t_fname)
|
||||||
|
{}
|
||||||
|
|
||||||
|
eval_error(const std::string &t_why,
|
||||||
|
const std::vector<Boxed_Value> &t_parameters, const chaiscript::detail::Dispatch_Engine &t_ss) noexcept :
|
||||||
|
std::runtime_error(format(t_why, t_parameters, t_ss)),
|
||||||
|
reason(t_why)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
eval_error(const std::string &t_why, const File_Position &t_where, const std::string &t_fname) noexcept :
|
eval_error(const std::string &t_why, const File_Position &t_where, const std::string &t_fname) noexcept :
|
||||||
std::runtime_error(format(t_why, t_where, t_fname)),
|
std::runtime_error(format(t_why, t_where, t_fname)),
|
||||||
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) noexcept
|
eval_error(const std::string &t_why) noexcept
|
||||||
: std::runtime_error("Error: \"" + t_why + "\" "),
|
: std::runtime_error("Error: \"" + t_why + "\" "),
|
||||||
@@ -83,13 +96,101 @@ namespace chaiscript
|
|||||||
virtual ~eval_error() noexcept {}
|
virtual ~eval_error() noexcept {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static std::string format_why(const std::string &t_why)
|
||||||
|
{
|
||||||
|
return "Error: \"" + t_why + "\"";
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string format_parameters(const std::vector<Boxed_Value> &t_parameters,
|
||||||
|
const chaiscript::detail::Dispatch_Engine &t_ss)
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "With parameters: (";
|
||||||
|
|
||||||
|
if (!t_parameters.empty())
|
||||||
|
{
|
||||||
|
std::string paramstr;
|
||||||
|
|
||||||
|
for (const Boxed_Value &bv: t_parameters)
|
||||||
|
{
|
||||||
|
paramstr += (bv.is_const()?"const ":"");
|
||||||
|
paramstr += t_ss.type_name(bv);
|
||||||
|
paramstr += ", ";
|
||||||
|
}
|
||||||
|
|
||||||
|
ss << paramstr.substr(0, paramstr.size() - 2);
|
||||||
|
}
|
||||||
|
ss << ")";
|
||||||
|
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string format_filename(const std::string &t_fname)
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
|
||||||
|
if (t_fname != "__EVAL__")
|
||||||
|
{
|
||||||
|
ss << "in '" << t_fname << "' ";
|
||||||
|
} else {
|
||||||
|
ss << "during evaluation ";
|
||||||
|
}
|
||||||
|
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string format_location(const File_Position &t_where)
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "at (" << t_where.line << ", " << t_where.column << ")";
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string format(const std::string &t_why, const File_Position &t_where, const std::string &t_fname,
|
||||||
|
const std::vector<Boxed_Value> &t_parameters, const chaiscript::detail::Dispatch_Engine &t_ss)
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
|
||||||
|
ss << format_why(t_why);
|
||||||
|
ss << " ";
|
||||||
|
|
||||||
|
ss << format_parameters(t_parameters, t_ss);
|
||||||
|
ss << " ";
|
||||||
|
|
||||||
|
ss << format_filename(t_fname);
|
||||||
|
ss << " ";
|
||||||
|
|
||||||
|
ss << format_location(t_where);
|
||||||
|
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string format(const std::string &t_why,
|
||||||
|
const std::vector<Boxed_Value> &t_parameters, const chaiscript::detail::Dispatch_Engine &t_ss)
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
|
||||||
|
ss << format_why(t_why);
|
||||||
|
ss << " ";
|
||||||
|
|
||||||
|
ss << format_parameters(t_parameters, t_ss);
|
||||||
|
ss << " ";
|
||||||
|
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
static std::string format(const std::string &t_why, const File_Position &t_where, const std::string &t_fname)
|
static std::string format(const std::string &t_why, const File_Position &t_where, const std::string &t_fname)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "Error: \"" << t_why << "\" " <<
|
|
||||||
(t_fname != "__EVAL__" ? ("in '" + t_fname + "' ") : "during evaluation ") <<
|
ss << format_why(t_why);
|
||||||
"at (" << t_where.line << ", " <<
|
ss << " ";
|
||||||
t_where.column + ")";
|
|
||||||
|
ss << format_filename(t_fname);
|
||||||
|
ss << " ";
|
||||||
|
|
||||||
|
ss << format_location(t_where);
|
||||||
|
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -67,8 +67,8 @@ namespace chaiscript
|
|||||||
return t_ss.call_function(t_oper_string, t_lhs, t_rhs);
|
return t_ss.call_function(t_oper_string, t_lhs, t_rhs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(const exception::dispatch_error &){
|
catch(const exception::dispatch_error &e){
|
||||||
throw exception::eval_error("Can not find appropriate '" + t_oper_string + "'");
|
throw exception::eval_error("Can not find appropriate '" + t_oper_string + "' operator.", e.parameters, t_ss);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -182,11 +182,11 @@ 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 ~Fun_Call_AST_Node() {}
|
virtual ~Fun_Call_AST_Node() {}
|
||||||
virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){
|
virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){
|
||||||
dispatch::Param_List_Builder plb;
|
std::vector<Boxed_Value> params;
|
||||||
|
|
||||||
if ((this->children.size() > 1) && (this->children[1]->identifier == AST_Node_Type::Arg_List)) {
|
if ((this->children.size() > 1) && (this->children[1]->identifier == AST_Node_Type::Arg_List)) {
|
||||||
for (size_t i = 0; i < this->children[1]->children.size(); ++i) {
|
for (size_t i = 0; i < this->children[1]->children.size(); ++i) {
|
||||||
plb << this->children[1]->children[i]->eval(t_ss);
|
params.push_back(this->children[1]->children[i]->eval(t_ss));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,13 +198,13 @@ namespace chaiscript
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
t_ss.set_stack(new_stack);
|
t_ss.set_stack(new_stack);
|
||||||
const Boxed_Value &retval = (*boxed_cast<const Const_Proxy_Function &>(fn))(plb);
|
const Boxed_Value &retval = (*boxed_cast<const Const_Proxy_Function &>(fn))(params);
|
||||||
t_ss.set_stack(prev_stack);
|
t_ss.set_stack(prev_stack);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
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 exception::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 + "'", e.parameters, t_ss);
|
||||||
}
|
}
|
||||||
catch(detail::Return_Value &rv) {
|
catch(detail::Return_Value &rv) {
|
||||||
t_ss.set_stack(prev_stack);
|
t_ss.set_stack(prev_stack);
|
||||||
@@ -230,19 +230,19 @@ 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 ~Inplace_Fun_Call_AST_Node() {}
|
virtual ~Inplace_Fun_Call_AST_Node() {}
|
||||||
virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){
|
virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){
|
||||||
dispatch::Param_List_Builder plb;
|
std::vector<Boxed_Value> params;
|
||||||
|
|
||||||
if ((this->children.size() > 1) && (this->children[1]->identifier == AST_Node_Type::Arg_List)) {
|
if ((this->children.size() > 1) && (this->children[1]->identifier == AST_Node_Type::Arg_List)) {
|
||||||
for (size_t i = 0; i < this->children[1]->children.size(); ++i) {
|
for (size_t i = 0; i < this->children[1]->children.size(); ++i) {
|
||||||
plb << this->children[1]->children[i]->eval(t_ss);
|
params.push_back(this->children[1]->children[i]->eval(t_ss));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return (*boxed_cast<const Const_Proxy_Function &>(this->children[0]->eval(t_ss)))(plb);
|
return (*boxed_cast<const Const_Proxy_Function &>(this->children[0]->eval(t_ss)))(params);
|
||||||
}
|
}
|
||||||
catch(const exception::dispatch_error &e){
|
catch(const exception::dispatch_error &e){
|
||||||
throw exception::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 + "'", e.parameters, t_ss);
|
||||||
}
|
}
|
||||||
catch(detail::Return_Value &rv) {
|
catch(detail::Return_Value &rv) {
|
||||||
return rv.retval;
|
return rv.retval;
|
||||||
@@ -312,19 +312,19 @@ namespace chaiscript
|
|||||||
try {
|
try {
|
||||||
retval = t_ss.call_function(this->children[1]->text, lhs, retval);
|
retval = t_ss.call_function(this->children[1]->text, lhs, retval);
|
||||||
}
|
}
|
||||||
catch(const exception::dispatch_error &){
|
catch(const exception::dispatch_error &e){
|
||||||
throw exception::eval_error(std::string("Mismatched types in equation") + (lhs.is_const()?", lhs is const.":"."));
|
throw exception::eval_error("Unable to find appropriate'" + this->children[1]->text + "' operator.", e.parameters, t_ss);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(const exception::dispatch_error &){
|
catch(const exception::dispatch_error &e){
|
||||||
throw exception::eval_error("Can not clone right hand side of equation");
|
throw exception::eval_error("Missing clone or copy constructor for right hand side of equation", e.parameters, t_ss);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
try {
|
try {
|
||||||
retval = t_ss.call_function(this->children[1]->text, lhs, retval);
|
retval = t_ss.call_function(this->children[1]->text, lhs, retval);
|
||||||
} catch(const exception::dispatch_error &){
|
} catch(const exception::dispatch_error &e){
|
||||||
throw exception::eval_error("Can not find appropriate '" + this->children[1]->text + "'");
|
throw exception::eval_error("Unable to find appropriate'" + this->children[1]->text + "' operator.", e.parameters, t_ss);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -439,8 +439,8 @@ namespace chaiscript
|
|||||||
catch(std::out_of_range &) {
|
catch(std::out_of_range &) {
|
||||||
throw exception::eval_error("Out of bounds exception");
|
throw exception::eval_error("Out of bounds exception");
|
||||||
}
|
}
|
||||||
catch(const exception::dispatch_error &){
|
catch(const exception::dispatch_error &e){
|
||||||
throw exception::eval_error("Can not find appropriate array lookup '[]' ");
|
throw exception::eval_error("Can not find appropriate array lookup operator '[]'.", e.parameters, t_ss );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -458,12 +458,12 @@ namespace chaiscript
|
|||||||
|
|
||||||
if (this->children.size() > 1) {
|
if (this->children.size() > 1) {
|
||||||
for (size_t i = 2; i < this->children.size(); i+=2) {
|
for (size_t i = 2; i < this->children.size(); i+=2) {
|
||||||
dispatch::Param_List_Builder plb;
|
std::vector<Boxed_Value> params;
|
||||||
plb << retval;
|
params.push_back(retval);
|
||||||
|
|
||||||
if (this->children[i]->children.size() > 1) {
|
if (this->children[i]->children.size() > 1) {
|
||||||
for (size_t j = 0; j < this->children[i]->children[1]->children.size(); ++j) {
|
for (size_t j = 0; j < this->children[i]->children[1]->children.size(); ++j) {
|
||||||
plb << this->children[i]->children[1]->children[j]->eval(t_ss);
|
params.push_back(this->children[i]->children[1]->children[j]->eval(t_ss));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -480,12 +480,12 @@ namespace chaiscript
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
t_ss.set_stack(new_stack);
|
t_ss.set_stack(new_stack);
|
||||||
retval = t_ss.call_function(fun_name, plb);
|
retval = t_ss.call_function(fun_name, params);
|
||||||
t_ss.set_stack(prev_stack);
|
t_ss.set_stack(prev_stack);
|
||||||
}
|
}
|
||||||
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 exception::eval_error(std::string(e.what()) + " for function: " + fun_name);
|
throw exception::eval_error(std::string(e.what()) + " for function: " + fun_name, e.parameters, t_ss);
|
||||||
}
|
}
|
||||||
catch(detail::Return_Value &rv) {
|
catch(detail::Return_Value &rv) {
|
||||||
t_ss.set_stack(prev_stack);
|
t_ss.set_stack(prev_stack);
|
||||||
@@ -503,8 +503,8 @@ namespace chaiscript
|
|||||||
catch(std::out_of_range &) {
|
catch(std::out_of_range &) {
|
||||||
throw exception::eval_error("Out of bounds exception");
|
throw exception::eval_error("Out of bounds exception");
|
||||||
}
|
}
|
||||||
catch(const exception::dispatch_error &){
|
catch(const exception::dispatch_error &e){
|
||||||
throw exception::eval_error("Can not find appropriate array lookup '[]' ");
|
throw exception::eval_error("Can not find appropriate array lookup operator '[]'.", e.parameters, t_ss);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -819,8 +819,8 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
return const_var(retval);
|
return const_var(retval);
|
||||||
}
|
}
|
||||||
catch (const exception::dispatch_error &) {
|
catch (const exception::dispatch_error &e) {
|
||||||
throw exception::eval_error("Can not find appropriate 'Map()'");
|
throw exception::eval_error("Can not find appropriate copy constructor or clone while inserting into Map.", e.parameters, t_ss);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -896,8 +896,8 @@ namespace chaiscript
|
|||||||
} else {
|
} else {
|
||||||
return t_ss.call_function(this->children[0]->text, bv);
|
return t_ss.call_function(this->children[0]->text, bv);
|
||||||
}
|
}
|
||||||
} catch (const exception::dispatch_error &) {
|
} catch (const exception::dispatch_error &e) {
|
||||||
throw exception::eval_error("Error with prefix operator evaluation: " + children[0]->text);
|
throw exception::eval_error("Error with prefix operator evaluation: '" + children[0]->text + "'", e.parameters, t_ss);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -938,8 +938,8 @@ namespace chaiscript
|
|||||||
this->children[0]->children[0]->children[0]->eval(t_ss),
|
this->children[0]->children[0]->children[0]->eval(t_ss),
|
||||||
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 &e) {
|
||||||
throw exception::eval_error("Unable to generate range vector");
|
throw exception::eval_error("Unable to generate range vector, while calling 'generate_range'", e.parameters, t_ss);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1587,7 +1587,7 @@ namespace chaiscript
|
|||||||
throw exception::eval_error("Incomplete expression", File_Position(m_line, m_col), *m_filename);
|
throw exception::eval_error("Incomplete expression", File_Position(m_line, m_col), *m_filename);
|
||||||
}
|
}
|
||||||
if (!Char(')')) {
|
if (!Char(')')) {
|
||||||
throw exception::eval_error("Missing closing parenthesis", File_Position(m_line, m_col), *m_filename);
|
throw exception::eval_error("Missing closing parenthesis ')'", File_Position(m_line, m_col), *m_filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return retval;
|
return retval;
|
||||||
@@ -1605,7 +1605,7 @@ namespace chaiscript
|
|||||||
retval = true;
|
retval = true;
|
||||||
Container_Arg_List();
|
Container_Arg_List();
|
||||||
if (!Char('}')) {
|
if (!Char('}')) {
|
||||||
throw exception::eval_error("Missing closing curly bracket", File_Position(m_line, m_col), *m_filename);
|
throw exception::eval_error("Missing closing brace '}' in container initializer", File_Position(m_line, m_col), *m_filename);
|
||||||
}
|
}
|
||||||
if ((prev_stack_top != m_match_stack.size()) && (m_match_stack.back()->children.size() > 0)) {
|
if ((prev_stack_top != m_match_stack.size()) && (m_match_stack.back()->children.size() > 0)) {
|
||||||
if (m_match_stack.back()->children[0]->identifier == AST_Node_Type::Value_Range) {
|
if (m_match_stack.back()->children[0]->identifier == AST_Node_Type::Value_Range) {
|
||||||
|
|||||||
1
unittests/scoping.chai
Normal file
1
unittests/scoping.chai
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{ { { { assert_true(true); assert_true(true); } } } }
|
||||||
@@ -23,7 +23,7 @@ def assert_true(f)
|
|||||||
{
|
{
|
||||||
if (!f)
|
if (!f)
|
||||||
{
|
{
|
||||||
print("assert_false failure");
|
print("assert_true failure");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user