Even more reorganization of namespaces to help with documentation and

clarity.
This commit is contained in:
Jason Turner 2011-03-25 15:42:18 -06:00
parent 8bd512a0af
commit 58e5df0a9a
16 changed files with 1777 additions and 1749 deletions

View File

@ -31,7 +31,7 @@ namespace chaiscript
P1 &assign_pod(P1 &p1, Boxed_POD_Value v) P1 &assign_pod(P1 &p1, Boxed_POD_Value v)
{ {
if (v.m_isfloat) if (v.isfloat)
{ {
return (p1 = P1(v.d)); return (p1 = P1(v.d));
} else { } else {
@ -42,7 +42,7 @@ namespace chaiscript
template<typename P1> template<typename P1>
P1 construct_pod(Boxed_POD_Value v) P1 construct_pod(Boxed_POD_Value v)
{ {
if (v.m_isfloat) if (v.isfloat)
{ {
return P1(v.d); return P1(v.d);
} else { } else {
@ -53,7 +53,7 @@ namespace chaiscript
template<typename P1> template<typename P1>
P1 &assign_bitwise_and_pod(P1 &p1, Boxed_POD_Value r) P1 &assign_bitwise_and_pod(P1 &p1, Boxed_POD_Value r)
{ {
if (!r.m_isfloat) if (!r.isfloat)
{ {
return p1 &= P1(r.i); return p1 &= P1(r.i);
} }
@ -64,7 +64,7 @@ namespace chaiscript
template<typename P1> template<typename P1>
P1 &assign_xor_pod(P1 &p1, Boxed_POD_Value r) P1 &assign_xor_pod(P1 &p1, Boxed_POD_Value r)
{ {
if (!r.m_isfloat) if (!r.isfloat)
{ {
return p1 ^= P1(r.i); return p1 ^= P1(r.i);
} }
@ -75,7 +75,7 @@ namespace chaiscript
template<typename P1> template<typename P1>
P1 &assign_bitwise_or_pod(P1 &p1, Boxed_POD_Value r) P1 &assign_bitwise_or_pod(P1 &p1, Boxed_POD_Value r)
{ {
if (!r.m_isfloat) if (!r.isfloat)
{ {
return p1 |= P1(r.i); return p1 |= P1(r.i);
} }
@ -86,7 +86,7 @@ namespace chaiscript
template<typename P1> template<typename P1>
P1 &assign_difference_pod(P1 &p1, Boxed_POD_Value r) P1 &assign_difference_pod(P1 &p1, Boxed_POD_Value r)
{ {
if (r.m_isfloat) if (r.isfloat)
{ {
return p1 -= P1(r.d); return p1 -= P1(r.d);
} else { } else {
@ -97,7 +97,7 @@ namespace chaiscript
template<typename P1> template<typename P1>
P1 &assign_left_shift_pod(P1 &p1, Boxed_POD_Value r) P1 &assign_left_shift_pod(P1 &p1, Boxed_POD_Value r)
{ {
if (!r.m_isfloat) if (!r.isfloat)
{ {
return p1 <<= P1(r.i); return p1 <<= P1(r.i);
} }
@ -109,7 +109,7 @@ namespace chaiscript
template<typename P1> template<typename P1>
P1 &assign_product_pod(P1 &p1, Boxed_POD_Value r) P1 &assign_product_pod(P1 &p1, Boxed_POD_Value r)
{ {
if (r.m_isfloat) if (r.isfloat)
{ {
return p1 *= P1(r.d); return p1 *= P1(r.d);
} else { } else {
@ -120,7 +120,7 @@ namespace chaiscript
template<typename P1> template<typename P1>
P1 &assign_quotient_pod(P1 &p1, Boxed_POD_Value r) P1 &assign_quotient_pod(P1 &p1, Boxed_POD_Value r)
{ {
if (r.m_isfloat) if (r.isfloat)
{ {
return p1 /= P1(r.d); return p1 /= P1(r.d);
} else { } else {
@ -131,7 +131,7 @@ namespace chaiscript
template<typename P1> template<typename P1>
P1 &assign_remainder_pod(P1 &p1, Boxed_POD_Value r) P1 &assign_remainder_pod(P1 &p1, Boxed_POD_Value r)
{ {
if (!r.m_isfloat) if (!r.isfloat)
{ {
return p1 %= P1(r.i); return p1 %= P1(r.i);
} }
@ -143,7 +143,7 @@ namespace chaiscript
template<typename P1> template<typename P1>
P1 &assign_right_shift_pod(P1 &p1, Boxed_POD_Value r) P1 &assign_right_shift_pod(P1 &p1, Boxed_POD_Value r)
{ {
if (!r.m_isfloat) if (!r.isfloat)
{ {
return p1 >>= P1(r.i); return p1 >>= P1(r.i);
} }
@ -155,7 +155,7 @@ namespace chaiscript
template<typename P1> template<typename P1>
P1 &assign_sum_pod(P1 &p1, Boxed_POD_Value r) P1 &assign_sum_pod(P1 &p1, Boxed_POD_Value r)
{ {
if (r.m_isfloat) if (r.isfloat)
{ {
return p1 += P1(r.d); return p1 += P1(r.d);
} else { } else {
@ -458,7 +458,7 @@ namespace chaiscript
Const_Proxy_Function f = boxed_cast<Const_Proxy_Function>(params[0]); Const_Proxy_Function f = boxed_cast<Const_Proxy_Function>(params[0]);
return Boxed_Value(Const_Proxy_Function(new Bound_Function(f, return Boxed_Value(Const_Proxy_Function(new dispatch::Bound_Function(f,
std::vector<Boxed_Value>(params.begin() + 1, params.end())))); std::vector<Boxed_Value>(params.begin() + 1, params.end()))));
} }
@ -480,7 +480,7 @@ namespace chaiscript
static bool has_guard(const Const_Proxy_Function &t_pf) static bool has_guard(const Const_Proxy_Function &t_pf)
{ {
boost::shared_ptr<const Dynamic_Proxy_Function> pf = boost::dynamic_pointer_cast<const Dynamic_Proxy_Function>(t_pf); boost::shared_ptr<const dispatch::Dynamic_Proxy_Function> pf = boost::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(t_pf);
if (pf) if (pf)
{ {
return pf->get_guard(); return pf->get_guard();
@ -491,7 +491,7 @@ namespace chaiscript
static Const_Proxy_Function get_guard(const Const_Proxy_Function &t_pf) static Const_Proxy_Function get_guard(const Const_Proxy_Function &t_pf)
{ {
boost::shared_ptr<const Dynamic_Proxy_Function> pf = boost::dynamic_pointer_cast<const Dynamic_Proxy_Function>(t_pf); boost::shared_ptr<const dispatch::Dynamic_Proxy_Function> pf = boost::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(t_pf);
if (pf) if (pf)
{ {
if (pf->get_guard()) if (pf->get_guard())
@ -509,7 +509,7 @@ namespace chaiscript
throw bv; throw bv;
} }
static boost::shared_ptr<Dispatch_Engine> bootstrap2(boost::shared_ptr<Dispatch_Engine> e = boost::shared_ptr<Dispatch_Engine> (new Dispatch_Engine())) static boost::shared_ptr<chaiscript::detail::Dispatch_Engine> bootstrap2(boost::shared_ptr<chaiscript::detail::Dispatch_Engine> e = boost::shared_ptr<chaiscript::detail::Dispatch_Engine> (new chaiscript::detail::Dispatch_Engine()))
{ {
e->add(user_type<void>(), "void"); e->add(user_type<void>(), "void");
return e; return e;
@ -535,7 +535,7 @@ namespace chaiscript
template<typename FunctionType> template<typename FunctionType>
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 Proxy_Function_Base *b) const dispatch::Proxy_Function_Base *b)
{ {
typedef typename boost::function_types::result_type<FunctionType>::type Vector; typedef typename boost::function_types::result_type<FunctionType>::type Vector;
Vector v = (b->*f)(); Vector v = (b->*f)();
@ -552,7 +552,7 @@ namespace chaiscript
} }
template<typename Function> template<typename Function>
static boost::function<std::vector<Boxed_Value> (const Proxy_Function_Base*)> return_boxed_value_vector(const Function &f) static boost::function<std::vector<Boxed_Value> (const dispatch::Proxy_Function_Base*)> return_boxed_value_vector(const Function &f)
{ {
return boost::bind(&do_return_boxed_value_vector<Function>, f, _1); return boost::bind(&do_return_boxed_value_vector<Function>, f, _1);
} }
@ -570,14 +570,14 @@ namespace chaiscript
m->add(user_type<Proxy_Function>(), "function"); m->add(user_type<Proxy_Function>(), "function");
m->add(user_type<std::exception>(), "exception"); m->add(user_type<std::exception>(), "exception");
m->add(fun(&Proxy_Function_Base::get_arity), "get_arity"); m->add(fun(&dispatch::Proxy_Function_Base::get_arity), "get_arity");
m->add(fun(&Proxy_Function_Base::annotation), "get_annotation"); m->add(fun(&dispatch::Proxy_Function_Base::annotation), "get_annotation");
m->add(fun(&Proxy_Function_Base::operator()), "call"); m->add(fun(&dispatch::Proxy_Function_Base::operator()), "call");
m->add(fun(&Proxy_Function_Base::operator==), "=="); m->add(fun(&dispatch::Proxy_Function_Base::operator==), "==");
m->add(fun(return_boxed_value_vector(&Proxy_Function_Base::get_param_types)), "get_param_types"); m->add(fun(return_boxed_value_vector(&dispatch::Proxy_Function_Base::get_param_types)), "get_param_types");
m->add(fun(return_boxed_value_vector(&Proxy_Function_Base::get_contained_functions)), "get_contained_functions"); m->add(fun(return_boxed_value_vector(&dispatch::Proxy_Function_Base::get_contained_functions)), "get_contained_functions");
m->add(user_type<std::runtime_error>(), "runtime_error"); m->add(user_type<std::runtime_error>(), "runtime_error");
@ -587,11 +587,11 @@ namespace chaiscript
m->add(constructor<std::runtime_error (const std::string &)>(), "runtime_error"); m->add(constructor<std::runtime_error (const std::string &)>(), "runtime_error");
m->add(fun(boost::function<std::string (const std::runtime_error &)>(&what)), "what"); m->add(fun(boost::function<std::string (const std::runtime_error &)>(&what)), "what");
m->add(user_type<Dynamic_Object>(), "Dynamic_Object"); m->add(user_type<dispatch::Dynamic_Object>(), "Dynamic_Object");
m->add(constructor<Dynamic_Object (const std::string &)>(), "Dynamic_Object"); m->add(constructor<dispatch::Dynamic_Object (const std::string &)>(), "Dynamic_Object");
m->add(fun(&Dynamic_Object::get_type_name), "get_type_name"); m->add(fun(&dispatch::Dynamic_Object::get_type_name), "get_type_name");
m->add(fun(&Dynamic_Object::get_attrs), "get_attrs"); m->add(fun(&dispatch::Dynamic_Object::get_attrs), "get_attrs");
m->add(fun(&Dynamic_Object::get_attr), "get_attr"); m->add(fun(&dispatch::Dynamic_Object::get_attr), "get_attr");
m->eval("def Dynamic_Object::clone() { var new_o := Dynamic_Object(this.get_type_name()); for_each(this.get_attrs(), bind(fun(new_o, x) { new_o.get_attr(x.first) = x.second; }, new_o, _) ); return new_o; }"); m->eval("def Dynamic_Object::clone() { var new_o := Dynamic_Object(this.get_type_name()); for_each(this.get_attrs(), bind(fun(new_o, x) { new_o.get_attr(x.first) = x.second; }, new_o, _) ); return new_o; }");
@ -648,14 +648,14 @@ namespace chaiscript
m->add(fun(&print), "print_string"); m->add(fun(&print), "print_string");
m->add(fun(&println), "println_string"); m->add(fun(&println), "println_string");
m->add(Proxy_Function(new Dynamic_Proxy_Function(boost::bind(&bind_function, _1))), m->add(Proxy_Function(new dispatch::Dynamic_Proxy_Function(boost::bind(&bind_function, _1))),
"bind"); "bind");
m->add(fun(&shared_ptr_unconst_clone<Proxy_Function_Base>), "clone"); m->add(fun(&shared_ptr_unconst_clone<dispatch::Proxy_Function_Base>), "clone");
m->add(fun(&ptr_assign<boost::remove_const<Proxy_Function_Base>::type>), "="); m->add(fun(&ptr_assign<boost::remove_const<dispatch::Proxy_Function_Base>::type>), "=");
m->add(fun(&ptr_assign<boost::add_const<Proxy_Function_Base>::type>), "="); m->add(fun(&ptr_assign<boost::add_const<dispatch::Proxy_Function_Base>::type>), "=");
m->add(Proxy_Function(new Dynamic_Proxy_Function(boost::bind(&call_exists, _1))), m->add(Proxy_Function(new dispatch::Dynamic_Proxy_Function(boost::bind(&call_exists, _1))),
"call_exists"); "call_exists");
m->add(fun(&type_match), "type_match"); m->add(fun(&type_match), "type_match");

View File

@ -21,205 +21,205 @@ namespace chaiscript
* Object which attempts to convert a Boxed_Value into a generic * Object which attempts to convert a Boxed_Value into a generic
* POD type and provide generic POD type operations * POD type and provide generic POD type operations
*/ */
struct Boxed_POD_Value class Boxed_POD_Value
{ {
Boxed_POD_Value(const Boxed_Value &v) public:
: d(0), i(0), m_isfloat(false) Boxed_POD_Value(const Boxed_Value &v)
{ : d(0), i(0), isfloat(false)
if (v.get_type_info().is_undef())
{ {
throw boost::bad_any_cast(); if (v.get_type_info().is_undef())
{
throw boost::bad_any_cast();
}
const Type_Info &inp_ = v.get_type_info();
if (inp_ == typeid(double))
{
d = boxed_cast<double>(v);
isfloat = true;
} else if (inp_ == typeid(float)) {
d = boxed_cast<float>(v);
isfloat = true;
} else if (inp_ == typeid(bool)) {
i = boxed_cast<bool>(v);
} else if (inp_ == typeid(char)) {
i = boxed_cast<char>(v);
} else if (inp_ == typeid(int)) {
i = boxed_cast<int>(v);
} else if (inp_ == typeid(unsigned int)) {
i = boxed_cast<unsigned int>(v);
} else if (inp_ == typeid(long)) {
i = boxed_cast<long>(v);
} else if (inp_ == typeid(unsigned long)) {
i = boxed_cast<unsigned long>(v);
} else if (inp_ == typeid(boost::int8_t)) {
i = boxed_cast<boost::int8_t>(v);
} else if (inp_ == typeid(boost::int16_t)) {
i = boxed_cast<boost::int16_t>(v);
} else if (inp_ == typeid(boost::int32_t)) {
i = boxed_cast<boost::int32_t>(v);
} else if (inp_ == typeid(boost::int64_t)) {
i = boxed_cast<boost::int64_t>(v);
} else if (inp_ == typeid(boost::uint8_t)) {
i = boxed_cast<boost::uint8_t>(v);
} else if (inp_ == typeid(boost::uint16_t)) {
i = boxed_cast<boost::uint16_t>(v);
} else if (inp_ == typeid(boost::uint32_t)) {
i = boxed_cast<boost::uint32_t>(v);
} else {
throw boost::bad_any_cast();
}
} }
const Type_Info &inp_ = v.get_type_info(); bool operator==(const Boxed_POD_Value &r) const
if (inp_ == typeid(double))
{ {
d = boxed_cast<double>(v); return ((isfloat)?d:i) == ((r.isfloat)?r.d:r.i);
m_isfloat = true;
} else if (inp_ == typeid(float)) {
d = boxed_cast<float>(v);
m_isfloat = true;
} else if (inp_ == typeid(bool)) {
i = boxed_cast<bool>(v);
} else if (inp_ == typeid(char)) {
i = boxed_cast<char>(v);
} else if (inp_ == typeid(int)) {
i = boxed_cast<int>(v);
} else if (inp_ == typeid(unsigned int)) {
i = boxed_cast<unsigned int>(v);
} else if (inp_ == typeid(long)) {
i = boxed_cast<long>(v);
} else if (inp_ == typeid(unsigned long)) {
i = boxed_cast<unsigned long>(v);
} else if (inp_ == typeid(boost::int8_t)) {
i = boxed_cast<boost::int8_t>(v);
} else if (inp_ == typeid(boost::int16_t)) {
i = boxed_cast<boost::int16_t>(v);
} else if (inp_ == typeid(boost::int32_t)) {
i = boxed_cast<boost::int32_t>(v);
} else if (inp_ == typeid(boost::int64_t)) {
i = boxed_cast<boost::int64_t>(v);
} else if (inp_ == typeid(boost::uint8_t)) {
i = boxed_cast<boost::uint8_t>(v);
} else if (inp_ == typeid(boost::uint16_t)) {
i = boxed_cast<boost::uint16_t>(v);
} else if (inp_ == typeid(boost::uint32_t)) {
i = boxed_cast<boost::uint32_t>(v);
} else {
throw boost::bad_any_cast();
}
}
bool operator==(const Boxed_POD_Value &r) const
{
return ((m_isfloat)?d:i) == ((r.m_isfloat)?r.d:r.i);
}
bool operator<(const Boxed_POD_Value &r) const
{
return ((m_isfloat)?d:i) < ((r.m_isfloat)?r.d:r.i);
}
bool operator>(const Boxed_POD_Value &r) const
{
return ((m_isfloat)?d:i) > ((r.m_isfloat)?r.d:r.i);
}
bool operator>=(const Boxed_POD_Value &r) const
{
return ((m_isfloat)?d:i) >= ((r.m_isfloat)?r.d:r.i);
}
bool operator<=(const Boxed_POD_Value &r) const
{
return ((m_isfloat)?d:i) <= ((r.m_isfloat)?r.d:r.i);
}
bool operator!=(const Boxed_POD_Value &r) const
{
return ((m_isfloat)?d:i) != ((r.m_isfloat)?r.d:r.i);
}
Boxed_Value operator+(const Boxed_POD_Value &r) const
{
if (!m_isfloat && !r.m_isfloat)
{
return smart_size(i + r.i);
} }
return Boxed_Value(((m_isfloat)?d:i) + ((r.m_isfloat)?r.d:r.i)); bool operator<(const Boxed_POD_Value &r) const
}
Boxed_Value operator-(const Boxed_POD_Value &r) const
{
if (!m_isfloat && !r.m_isfloat)
{ {
return smart_size(i - r.i); return ((isfloat)?d:i) < ((r.isfloat)?r.d:r.i);
} }
return Boxed_Value(((m_isfloat)?d:i) - ((r.m_isfloat)?r.d:r.i)); bool operator>(const Boxed_POD_Value &r) const
}
Boxed_Value operator&(const Boxed_POD_Value &r) const
{
if (!m_isfloat && !r.m_isfloat)
{ {
return Boxed_Value(i & r.i); return ((isfloat)?d:i) > ((r.isfloat)?r.d:r.i);
} }
throw exception::bad_boxed_cast("& only valid for integer types"); bool operator>=(const Boxed_POD_Value &r) const
}
Boxed_Value operator^(const Boxed_POD_Value &r) const
{
if (!m_isfloat && !r.m_isfloat)
{ {
return Boxed_Value(i ^ r.i); return ((isfloat)?d:i) >= ((r.isfloat)?r.d:r.i);
} }
throw exception::bad_boxed_cast("^ only valid for integer types"); bool operator<=(const Boxed_POD_Value &r) const
}
Boxed_Value operator|(const Boxed_POD_Value &r) const
{
if (!m_isfloat && !r.m_isfloat)
{ {
return Boxed_Value(i | r.i); return ((isfloat)?d:i) <= ((r.isfloat)?r.d:r.i);
} }
throw exception::bad_boxed_cast("| only valid for integer types"); bool operator!=(const Boxed_POD_Value &r) const
}
Boxed_Value operator/(const Boxed_POD_Value &r) const
{
if (!m_isfloat && !r.m_isfloat)
{ {
return smart_size(i / r.i); return ((isfloat)?d:i) != ((r.isfloat)?r.d:r.i);
} }
return Boxed_Value(((m_isfloat)?d:i) / ((r.m_isfloat)?r.d:r.i)); Boxed_Value operator+(const Boxed_POD_Value &r) const
}
Boxed_Value operator<<(const Boxed_POD_Value &r) const
{
if (!m_isfloat && !r.m_isfloat)
{ {
return smart_size(i << r.i); if (!isfloat && !r.isfloat)
{
return smart_size(i + r.i);
}
return Boxed_Value(((isfloat)?d:i) + ((r.isfloat)?r.d:r.i));
} }
throw exception::bad_boxed_cast("<< only valid for integer types"); Boxed_Value operator-(const Boxed_POD_Value &r) const
}
Boxed_Value operator*(const Boxed_POD_Value &r) const
{
if (!m_isfloat && !r.m_isfloat)
{ {
return smart_size(i * r.i); if (!isfloat && !r.isfloat)
{
return smart_size(i - r.i);
}
return Boxed_Value(((isfloat)?d:i) - ((r.isfloat)?r.d:r.i));
} }
return Boxed_Value(((m_isfloat)?d:i) * ((r.m_isfloat)?r.d:r.i)); Boxed_Value operator&(const Boxed_POD_Value &r) const
}
Boxed_Value operator%(const Boxed_POD_Value &r) const
{
if (!m_isfloat && !r.m_isfloat)
{ {
return smart_size(i % r.i); if (!isfloat && !r.isfloat)
{
return Boxed_Value(i & r.i);
}
throw exception::bad_boxed_cast("& only valid for integer types");
} }
throw exception::bad_boxed_cast("% only valid for integer types"); Boxed_Value operator^(const Boxed_POD_Value &r) const
}
Boxed_Value operator>>(const Boxed_POD_Value &r) const
{
if (!m_isfloat && !r.m_isfloat)
{ {
return smart_size(i >> r.i); if (!isfloat && !r.isfloat)
{
return Boxed_Value(i ^ r.i);
}
throw exception::bad_boxed_cast("^ only valid for integer types");
} }
throw exception::bad_boxed_cast(">> only valid for integer types"); Boxed_Value operator|(const Boxed_POD_Value &r) const
}
Boxed_Value smart_size(boost::int64_t t_i) const
{
if (t_i < boost::integer_traits<int>::const_min
|| t_i > boost::integer_traits<int>::const_max)
{ {
return Boxed_Value(t_i); if (!isfloat && !r.isfloat)
} else { {
return Boxed_Value(static_cast<int>(t_i)); return Boxed_Value(i | r.i);
}
throw exception::bad_boxed_cast("| only valid for integer types");
}
Boxed_Value operator/(const Boxed_POD_Value &r) const
{
if (!isfloat && !r.isfloat)
{
return smart_size(i / r.i);
}
return Boxed_Value(((isfloat)?d:i) / ((r.isfloat)?r.d:r.i));
}
Boxed_Value operator<<(const Boxed_POD_Value &r) const
{
if (!isfloat && !r.isfloat)
{
return smart_size(i << r.i);
}
throw exception::bad_boxed_cast("<< only valid for integer types");
} }
}
Boxed_Value operator*(const Boxed_POD_Value &r) const
{
if (!isfloat && !r.isfloat)
{
return smart_size(i * r.i);
}
double d; return Boxed_Value(((isfloat)?d:i) * ((r.isfloat)?r.d:r.i));
boost::int64_t i; }
bool m_isfloat;
Boxed_Value operator%(const Boxed_POD_Value &r) const
{
if (!isfloat && !r.isfloat)
{
return smart_size(i % r.i);
}
throw exception::bad_boxed_cast("% only valid for integer types");
}
Boxed_Value operator>>(const Boxed_POD_Value &r) const
{
if (!isfloat && !r.isfloat)
{
return smart_size(i >> r.i);
}
throw exception::bad_boxed_cast(">> only valid for integer types");
}
Boxed_Value smart_size(boost::int64_t t_i) const
{
if (t_i < boost::integer_traits<int>::const_min
|| t_i > boost::integer_traits<int>::const_max)
{
return Boxed_Value(t_i);
} else {
return Boxed_Value(static_cast<int>(t_i));
}
}
double d;
boost::int64_t i;
bool isfloat;
}; };
namespace detail namespace detail

File diff suppressed because it is too large Load Diff

View File

@ -11,270 +11,273 @@
namespace chaiscript namespace chaiscript
{ {
class Dynamic_Object namespace dispatch
{ {
public: class Dynamic_Object
Dynamic_Object(const std::string &t_type_name)
: m_type_name(t_type_name)
{
}
std::string get_type_name() const
{
return m_type_name;
}
Boxed_Value get_attr(const std::string &t_attr_name)
{
return m_attrs[t_attr_name];
}
std::map<std::string, Boxed_Value> get_attrs()
{
return m_attrs;
}
private:
std::string m_type_name;
std::map<std::string, Boxed_Value> m_attrs;
};
namespace detail
{
struct Dynamic_Object_Attribute
{
static Boxed_Value func(const std::string &t_type_name, const std::string &t_attr_name,
Dynamic_Object &t_do)
{
if (t_do.get_type_name() != t_type_name)
{
throw exception::bad_boxed_cast("Dynamic object type mismatch");
}
return t_do.get_attr(t_attr_name);
}
};
/**
* A Proxy_Function implementation designed for calling a function
* that is automatically guarded based on the first param based on the
* param's type name
*/
class Dynamic_Object_Function : public Proxy_Function_Base
{ {
public: public:
Dynamic_Object_Function( Dynamic_Object(const std::string &t_type_name)
const std::string &t_type_name, : m_type_name(t_type_name)
const Proxy_Function &t_func, {
const boost::optional<Type_Info> &t_ti = boost::optional<Type_Info>()) }
: Proxy_Function_Base(build_param_types(t_func->get_param_types(), t_ti)),
m_type_name(t_type_name), m_func(t_func), m_ti(t_ti) std::string get_type_name() const
{
return m_type_name;
}
Boxed_Value get_attr(const std::string &t_attr_name)
{
return m_attrs[t_attr_name];
}
std::map<std::string, Boxed_Value> get_attrs()
{
return m_attrs;
}
private:
std::string m_type_name;
std::map<std::string, Boxed_Value> m_attrs;
};
namespace detail
{
struct Dynamic_Object_Attribute
{
static Boxed_Value func(const std::string &t_type_name, const std::string &t_attr_name,
Dynamic_Object &t_do)
{
if (t_do.get_type_name() != t_type_name)
{
throw exception::bad_boxed_cast("Dynamic object type mismatch");
}
return t_do.get_attr(t_attr_name);
}
};
/**
* A Proxy_Function implementation designed for calling a function
* that is automatically guarded based on the first param based on the
* param's type name
*/
class Dynamic_Object_Function : public Proxy_Function_Base
{
public:
Dynamic_Object_Function(
const std::string &t_type_name,
const Proxy_Function &t_func,
const boost::optional<Type_Info> &t_ti = boost::optional<Type_Info>())
: Proxy_Function_Base(build_param_types(t_func->get_param_types(), t_ti)),
m_type_name(t_type_name), m_func(t_func), m_ti(t_ti)
{ {
assert( (t_func->get_arity() > 0 || t_func->get_arity() < 0) assert( (t_func->get_arity() > 0 || t_func->get_arity() < 0)
&& "Programming error, Dynamic_Object_Function must have at least one parameter (this)"); && "Programming error, Dynamic_Object_Function must have at least one parameter (this)");
} }
virtual ~Dynamic_Object_Function() {} virtual ~Dynamic_Object_Function() {}
virtual bool operator==(const Proxy_Function_Base &f) const virtual bool operator==(const Proxy_Function_Base &f) const
{
const Dynamic_Object_Function *df = dynamic_cast<const Dynamic_Object_Function *>(&f);
if (df)
{ {
return df->m_type_name == m_type_name && (*df->m_func) == (*m_func); const Dynamic_Object_Function *df = dynamic_cast<const Dynamic_Object_Function *>(&f);
} else { if (df)
return false;
}
}
virtual bool call_match(const std::vector<Boxed_Value> &vals) const
{
if (dynamic_object_typename_match(vals, m_type_name, m_ti))
{
return m_func->call_match(vals);
} else {
return false;
}
}
virtual std::vector<Const_Proxy_Function> get_contained_functions() const
{
std::vector<Const_Proxy_Function> fs;
fs.push_back(m_func);
return fs;
}
virtual int get_arity() const
{
return m_func->get_arity();
}
virtual std::string annotation() const
{
return m_func->annotation();
}
protected:
virtual Boxed_Value do_call(const std::vector<Boxed_Value> &params) const
{
if (dynamic_object_typename_match(params, m_type_name, m_ti))
{
return (*m_func)(params);
} else {
throw exception::guard_error();
}
}
virtual bool compare_first_type(const Boxed_Value &bv) const
{
return dynamic_object_typename_match(bv, m_type_name, m_ti);
}
private:
static std::vector<Type_Info> build_param_types(
const std::vector<Type_Info> &t_inner_types, boost::optional<Type_Info> t_objectti)
{
if (t_objectti)
{
std::vector<Type_Info> types(t_inner_types);
assert(types.size() > 1);
assert(types[1].bare_equal(user_type<Boxed_Value>()));
types[1] = *t_objectti;
return types;
} else {
return t_inner_types;
}
}
static bool dynamic_object_typename_match(const Boxed_Value &bv, const std::string &name,
const boost::optional<Type_Info> &ti)
{
static Type_Info doti = user_type<Dynamic_Object>();
if (bv.get_type_info().bare_equal(doti))
{
try {
const Dynamic_Object &d = boxed_cast<const Dynamic_Object &>(bv);
return name == "Dynamic_Object" || d.get_type_name() == name;
} catch (const std::bad_cast &) {
return false;
}
} else {
if (ti)
{ {
return bv.get_type_info().bare_equal(*ti); return df->m_type_name == m_type_name && (*df->m_func) == (*m_func);
} else { } else {
return false; return false;
} }
} }
} virtual bool call_match(const std::vector<Boxed_Value> &vals) const
static bool dynamic_object_typename_match(const std::vector<Boxed_Value> &bvs, const std::string &name,
const boost::optional<Type_Info> &ti)
{
if (bvs.size() > 0)
{ {
return dynamic_object_typename_match(bvs[0], name, ti); if (dynamic_object_typename_match(vals, m_type_name, m_ti))
} else { {
return false; return m_func->call_match(vals);
} else {
return false;
}
}
virtual std::vector<Const_Proxy_Function> get_contained_functions() const
{
std::vector<Const_Proxy_Function> fs;
fs.push_back(m_func);
return fs;
} }
}
std::string m_type_name;
Proxy_Function m_func;
boost::optional<Type_Info> m_ti;
};
/** virtual int get_arity() const
* A Proxy_Function implementation designed for creating a new {
* Dynamic_Object return m_func->get_arity();
* that is automatically guarded based on the first param based on the }
* param's type name
*/ virtual std::string annotation() const
class Dynamic_Object_Constructor : public Proxy_Function_Base {
{ return m_func->annotation();
public: }
Dynamic_Object_Constructor(
const std::string &t_type_name,
const Proxy_Function &t_func) protected:
: Proxy_Function_Base(build_type_list(t_func->get_param_types())), virtual Boxed_Value do_call(const std::vector<Boxed_Value> &params) const
m_type_name(t_type_name), m_func(t_func) {
if (dynamic_object_typename_match(params, m_type_name, m_ti))
{
return (*m_func)(params);
} else {
throw exception::guard_error();
}
}
virtual bool compare_first_type(const Boxed_Value &bv) const
{
return dynamic_object_typename_match(bv, m_type_name, m_ti);
}
private:
static std::vector<Type_Info> build_param_types(
const std::vector<Type_Info> &t_inner_types, boost::optional<Type_Info> t_objectti)
{
if (t_objectti)
{
std::vector<Type_Info> types(t_inner_types);
assert(types.size() > 1);
assert(types[1].bare_equal(user_type<Boxed_Value>()));
types[1] = *t_objectti;
return types;
} else {
return t_inner_types;
}
}
static bool dynamic_object_typename_match(const Boxed_Value &bv, const std::string &name,
const boost::optional<Type_Info> &ti)
{
static Type_Info doti = user_type<Dynamic_Object>();
if (bv.get_type_info().bare_equal(doti))
{
try {
const Dynamic_Object &d = boxed_cast<const Dynamic_Object &>(bv);
return name == "Dynamic_Object" || d.get_type_name() == name;
} catch (const std::bad_cast &) {
return false;
}
} else {
if (ti)
{
return bv.get_type_info().bare_equal(*ti);
} else {
return false;
}
}
}
static bool dynamic_object_typename_match(const std::vector<Boxed_Value> &bvs, const std::string &name,
const boost::optional<Type_Info> &ti)
{
if (bvs.size() > 0)
{
return dynamic_object_typename_match(bvs[0], name, ti);
} else {
return false;
}
}
std::string m_type_name;
Proxy_Function m_func;
boost::optional<Type_Info> m_ti;
};
/**
* A Proxy_Function implementation designed for creating a new
* Dynamic_Object
* that is automatically guarded based on the first param based on the
* param's type name
*/
class Dynamic_Object_Constructor : public Proxy_Function_Base
{
public:
Dynamic_Object_Constructor(
const std::string &t_type_name,
const Proxy_Function &t_func)
: Proxy_Function_Base(build_type_list(t_func->get_param_types())),
m_type_name(t_type_name), m_func(t_func)
{ {
assert( (t_func->get_arity() > 0 || t_func->get_arity() < 0) assert( (t_func->get_arity() > 0 || t_func->get_arity() < 0)
&& "Programming error, Dynamic_Object_Function must have at least one parameter (this)"); && "Programming error, Dynamic_Object_Function must have at least one parameter (this)");
} }
static std::vector<Type_Info> build_type_list(const std::vector<Type_Info> &tl) static std::vector<Type_Info> build_type_list(const std::vector<Type_Info> &tl)
{
std::vector<Type_Info>::const_iterator begin = tl.begin();
std::vector<Type_Info>::const_iterator end = tl.end();
if (begin != end)
{ {
++begin; std::vector<Type_Info>::const_iterator begin = tl.begin();
std::vector<Type_Info>::const_iterator end = tl.end();
if (begin != end)
{
++begin;
}
return std::vector<Type_Info>(begin, end);
} }
return std::vector<Type_Info>(begin, end); virtual ~Dynamic_Object_Constructor() {}
}
virtual ~Dynamic_Object_Constructor() {} virtual bool operator==(const Proxy_Function_Base &f) const
virtual bool operator==(const Proxy_Function_Base &f) const
{
const Dynamic_Object_Constructor *dc = dynamic_cast<const Dynamic_Object_Constructor*>(&f);
if (dc)
{ {
return dc->m_type_name == m_type_name && (*dc->m_func) == (*m_func); const Dynamic_Object_Constructor *dc = dynamic_cast<const Dynamic_Object_Constructor*>(&f);
} else { if (dc)
return false; {
return dc->m_type_name == m_type_name && (*dc->m_func) == (*m_func);
} else {
return false;
}
} }
}
virtual bool call_match(const std::vector<Boxed_Value> &vals) const virtual bool call_match(const std::vector<Boxed_Value> &vals) const
{ {
std::vector<Boxed_Value> new_vals; std::vector<Boxed_Value> new_vals;
new_vals.push_back(Boxed_Value(Dynamic_Object(m_type_name))); new_vals.push_back(Boxed_Value(Dynamic_Object(m_type_name)));
new_vals.insert(new_vals.end(), vals.begin(), vals.end()); new_vals.insert(new_vals.end(), vals.begin(), vals.end());
return m_func->call_match(new_vals); return m_func->call_match(new_vals);
} }
virtual int get_arity() const virtual int get_arity() const
{ {
// "this" is not considered part of the arity // "this" is not considered part of the arity
return m_func->get_arity() - 1; return m_func->get_arity() - 1;
} }
virtual std::string annotation() const virtual std::string annotation() const
{ {
return m_func->annotation(); return m_func->annotation();
} }
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
{ {
std::vector<Boxed_Value> new_params; std::vector<Boxed_Value> new_params;
chaiscript::Boxed_Value bv = var(Dynamic_Object(m_type_name)); chaiscript::Boxed_Value bv = var(Dynamic_Object(m_type_name));
new_params.push_back(bv); new_params.push_back(bv);
new_params.insert(new_params.end(), params.begin(), params.end()); new_params.insert(new_params.end(), params.begin(), params.end());
(*m_func)(new_params); (*m_func)(new_params);
return bv; return bv;
} }
private: private:
std::string m_type_name; std::string m_type_name;
Proxy_Function m_func; Proxy_Function m_func;
}; };
}
} }
} }
#endif #endif

View File

@ -20,37 +20,39 @@
namespace chaiscript namespace chaiscript
{ {
/** namespace dispatch
* Build a function caller that knows how to dispatch on a set of functions {
* example: /**
* boost::function<void (int)> f = * Build a function caller that knows how to dispatch on a set of functions
* build_function_caller(dispatchkit.get_function("print")); * example:
* \returns A boost::function object for dispatching * boost::function<void (int)> f =
* \param[in] funcs the set of functions to dispatch on. * build_function_caller(dispatchkit.get_function("print"));
*/ * \returns A boost::function object for dispatching
template<typename FunctionType> * \param[in] funcs the set of functions to dispatch on.
boost::function<FunctionType> */
template<typename FunctionType>
boost::function<FunctionType>
functor(const std::vector<Const_Proxy_Function> &funcs) functor(const std::vector<Const_Proxy_Function> &funcs)
{ {
FunctionType *p=0; FunctionType *p=0;
return detail::build_function_caller_helper(p, funcs); return detail::build_function_caller_helper(p, funcs);
} }
/** /**
* Build a function caller for a particular Proxy_Function object * Build a function caller for a particular Proxy_Function object
* useful in the case that a function is being pass out from scripting back * useful in the case that a function is being pass out from scripting back
* into code * into code
* example: * example:
* void my_function(Proxy_Function f) * void my_function(Proxy_Function f)
* { * {
* boost::function<void (int)> local_f = * boost::function<void (int)> local_f =
* build_function_caller(f); * build_function_caller(f);
* } * }
* \returns A boost::function object for dispatching * \returns A boost::function object for dispatching
* \param[in] func A function to execute. * \param[in] func A function to execute.
*/ */
template<typename FunctionType> template<typename FunctionType>
boost::function<FunctionType> boost::function<FunctionType>
functor(Const_Proxy_Function func) functor(Const_Proxy_Function func)
{ {
std::vector<Const_Proxy_Function> funcs; std::vector<Const_Proxy_Function> funcs;
@ -58,76 +60,76 @@ namespace chaiscript
return functor<FunctionType>(funcs); return functor<FunctionType>(funcs);
} }
/** /**
* Helper for automatically unboxing a Boxed_Value that contains a function object * Helper for automatically unboxing a Boxed_Value that contains a function object
* and creating a typesafe C++ function caller from it. * and creating a typesafe C++ function caller from it.
*/ */
template<typename FunctionType> template<typename FunctionType>
boost::function<FunctionType> boost::function<FunctionType>
functor(const Boxed_Value &bv) functor(const Boxed_Value &bv)
{ {
return functor<FunctionType>(boxed_cast<Const_Proxy_Function >(bv)); return functor<FunctionType>(boxed_cast<Const_Proxy_Function >(bv));
} }
}
namespace detail{ namespace detail{
/** /**
* Cast helper to handle automatic casting to const boost::function & * Cast helper to handle automatic casting to const boost::function &
*/ */
template<typename Signature> template<typename Signature>
struct Cast_Helper<const boost::function<Signature> &> struct Cast_Helper<const boost::function<Signature> &>
{ {
typedef boost::function<Signature> Result_Type; typedef boost::function<Signature> Result_Type;
static Result_Type cast(const Boxed_Value &ob) static Result_Type cast(const Boxed_Value &ob)
{ {
if (ob.get_type_info().bare_equal(user_type<Const_Proxy_Function>())) if (ob.get_type_info().bare_equal(user_type<Const_Proxy_Function>()))
{ {
return functor<Signature>(ob); return dispatch::functor<Signature>(ob);
} else { } else {
return Cast_Helper_Inner<const boost::function<Signature> &>::cast(ob); return Cast_Helper_Inner<const boost::function<Signature> &>::cast(ob);
} }
} }
}; };
/** /**
* Cast helper to handle automatic casting to boost::function * Cast helper to handle automatic casting to boost::function
*/ */
template<typename Signature> template<typename Signature>
struct Cast_Helper<boost::function<Signature> > struct Cast_Helper<boost::function<Signature> >
{ {
typedef boost::function<Signature> Result_Type; typedef boost::function<Signature> Result_Type;
static Result_Type cast(const Boxed_Value &ob) static Result_Type cast(const Boxed_Value &ob)
{ {
if (ob.get_type_info().bare_equal(user_type<Const_Proxy_Function>())) if (ob.get_type_info().bare_equal(user_type<Const_Proxy_Function>()))
{ {
return functor<Signature>(ob); return dispatch::functor<Signature>(ob);
} else { } else {
return Cast_Helper_Inner<boost::function<Signature> >::cast(ob); return Cast_Helper_Inner<boost::function<Signature> >::cast(ob);
} }
} }
}; };
/** /**
* Cast helper to handle automatic casting to const boost::function * Cast helper to handle automatic casting to const boost::function
*/ */
template<typename Signature> template<typename Signature>
struct Cast_Helper<const boost::function<Signature> > struct Cast_Helper<const boost::function<Signature> >
{ {
typedef boost::function<Signature> Result_Type; typedef boost::function<Signature> Result_Type;
static Result_Type cast(const Boxed_Value &ob) static Result_Type cast(const Boxed_Value &ob)
{ {
if (ob.get_type_info().bare_equal(user_type<Const_Proxy_Function>())) if (ob.get_type_info().bare_equal(user_type<Const_Proxy_Function>()))
{ {
return functor<Signature>(ob); return dispatch::functor<Signature>(ob);
} else { } else {
return Cast_Helper_Inner<const boost::function<Signature> >::cast(ob); return Cast_Helper_Inner<const boost::function<Signature> >::cast(ob);
} }
} }
}; };
} }
} }
#endif #endif

View File

@ -23,35 +23,38 @@
namespace chaiscript namespace chaiscript
{ {
namespace detail namespace dispatch
{ {
namespace detail
{
/** /**
* Internal helper class for handling the return * Internal helper class for handling the return
* value of a build_function_caller * value of a build_function_caller
*/ */
template<typename Ret> template<typename Ret>
struct Function_Caller_Ret struct Function_Caller_Ret
{
static Ret call(const std::vector<Const_Proxy_Function> &t_funcs,
const std::vector<Boxed_Value> &params)
{ {
return boxed_cast<Ret>(dispatch(t_funcs, params)); static Ret call(const std::vector<Const_Proxy_Function> &t_funcs,
} const std::vector<Boxed_Value> &params)
}; {
return boxed_cast<Ret>(dispatch::dispatch(t_funcs, params));
}
};
/** /**
* Specialization for void return types * Specialization for void return types
*/ */
template<> template<>
struct Function_Caller_Ret<void> struct Function_Caller_Ret<void>
{
static void call(const std::vector<Const_Proxy_Function> &t_funcs,
const std::vector<Boxed_Value> &params)
{ {
dispatch(t_funcs, params); static void call(const std::vector<Const_Proxy_Function> &t_funcs,
} const std::vector<Boxed_Value> &params)
}; {
dispatch::dispatch(t_funcs, params);
}
};
}
} }
} }
@ -65,47 +68,49 @@ namespace chaiscript
namespace chaiscript namespace chaiscript
{ {
namespace detail namespace dispatch
{ {
/** namespace detail
* used internally for unwrapping a function call's types {
*/ /**
template<typename Ret BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param) > * used internally for unwrapping a function call's types
Ret function_caller(const std::vector<Const_Proxy_Function> &funcs */
BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_BINARY_PARAMS(n, Param, p) ) template<typename Ret BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param) >
{ Ret function_caller(const std::vector<Const_Proxy_Function> &funcs
std::vector<Boxed_Value> params; BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_BINARY_PARAMS(n, Param, p) )
BOOST_PP_REPEAT(n, addparam, ~)
return Function_Caller_Ret<Ret>::call(funcs, params);
}
/**
* used internally for unwrapping a function call's types
*/
template<typename Ret BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param) >
boost::function<Ret (BOOST_PP_ENUM_PARAMS(n, Param)) >
build_function_caller_helper(Ret (BOOST_PP_ENUM_PARAMS(n, Param)), const std::vector<Const_Proxy_Function> &funcs)
{
if (funcs.size() == 1)
{ {
boost::shared_ptr<const Proxy_Function_Impl<Ret (BOOST_PP_ENUM_PARAMS(n, Param))> > pfi = std::vector<Boxed_Value> params;
boost::dynamic_pointer_cast<const Proxy_Function_Impl<Ret (BOOST_PP_ENUM_PARAMS(n, Param))> >
(funcs[0]);
if (pfi) BOOST_PP_REPEAT(n, addparam, ~)
{
return pfi->internal_function(); return Function_Caller_Ret<Ret>::call(funcs, params);
}
// looks like this either wasn't a Proxy_Function_Impl or the types didn't match
// we cannot make any other guesses or assumptions really, so continuing
} }
return boost::bind(&function_caller<Ret BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, Param)>, funcs /**
BOOST_PP_ENUM_TRAILING(n, curry, ~)); * used internally for unwrapping a function call's types
} */
template<typename Ret BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param) >
boost::function<Ret (BOOST_PP_ENUM_PARAMS(n, Param)) >
build_function_caller_helper(Ret (BOOST_PP_ENUM_PARAMS(n, Param)), const std::vector<Const_Proxy_Function> &funcs)
{
if (funcs.size() == 1)
{
boost::shared_ptr<const Proxy_Function_Impl<Ret (BOOST_PP_ENUM_PARAMS(n, Param))> > pfi =
boost::dynamic_pointer_cast<const Proxy_Function_Impl<Ret (BOOST_PP_ENUM_PARAMS(n, Param))> >
(funcs[0]);
if (pfi)
{
return pfi->internal_function();
}
// looks like this either wasn't a Proxy_Function_Impl or the types didn't match
// we cannot make any other guesses or assumptions really, so continuing
}
return boost::bind(&function_caller<Ret BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, Param)>, funcs
BOOST_PP_ENUM_TRAILING(n, curry, ~));
}
}
} }
} }
#undef n #undef n

View File

@ -26,7 +26,7 @@ namespace chaiscript
Proxy_Function constructor() Proxy_Function constructor()
{ {
T *f = 0; T *f = 0;
return (detail::build_constructor_(f)); return (dispatch::detail::build_constructor_(f));
} }
} }
@ -35,30 +35,33 @@ namespace chaiscript
namespace chaiscript namespace chaiscript
{ {
namespace detail namespace dispatch
{ {
/** namespace detail
* A constructor function, used for creating a new object {
* of a given type with a given set of params /**
*/ * A constructor function, used for creating a new object
template<typename Class BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param) > * of a given type with a given set of params
boost::shared_ptr<Class> constructor_( BOOST_PP_ENUM_BINARY_PARAMS(n, Param, p) ) */
{ template<typename Class BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param) >
return boost::shared_ptr<Class>(new Class( BOOST_PP_ENUM_PARAMS(n, p) )); boost::shared_ptr<Class> constructor_( BOOST_PP_ENUM_BINARY_PARAMS(n, Param, p) )
} {
return boost::shared_ptr<Class>(new Class( BOOST_PP_ENUM_PARAMS(n, p) ));
}
/** /**
* Helper function for build a constructor function * Helper function for build a constructor function
* example: * example:
* dispatchengine.register_function(build_constructor<MyClass, int, const std::string&>, "MyClass"); * dispatchengine.register_function(build_constructor<MyClass, int, const std::string&>, "MyClass");
* \todo See if it is possible to make this not be a variadic function * \todo See if it is possible to make this not be a variadic function
*/ */
template<typename Class BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param) > template<typename Class BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param) >
Proxy_Function build_constructor_(Class (*)(BOOST_PP_ENUM_PARAMS(n, Param))) Proxy_Function build_constructor_(Class (*)(BOOST_PP_ENUM_PARAMS(n, Param)))
{ {
typedef boost::shared_ptr<Class> (sig)(BOOST_PP_ENUM_PARAMS(n, Param)); typedef boost::shared_ptr<Class> (sig)(BOOST_PP_ENUM_PARAMS(n, Param));
return Proxy_Function(new Proxy_Function_Impl<sig>(boost::function<sig>(&(constructor_<Class BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, Param)>)))); return Proxy_Function(new Proxy_Function_Impl<sig>(boost::function<sig>(&(constructor_<Class BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, Param)>))));
} }
}
} }
} }
#undef n #undef n

File diff suppressed because it is too large Load Diff

View File

@ -18,61 +18,63 @@
namespace chaiscript namespace chaiscript
{ {
namespace detail namespace dispatch
{ {
template<bool Object, bool MemFn> namespace detail
struct Fun_Helper {
{ template<bool Object, bool MemFn>
template<typename T> struct Fun_Helper
static Proxy_Function go(T t)
{ {
return Proxy_Function( template<typename T>
new Proxy_Function_Impl< static Proxy_Function go(T t)
{
return Proxy_Function(
new Proxy_Function_Impl<
typename boost::function_types::function_type<boost::function_types::components<T> >::type> ( typename boost::function_types::function_type<boost::function_types::components<T> >::type> (
boost::function< boost::function<
typename boost::function_types::function_type<boost::function_types::components<T> >::type typename boost::function_types::function_type<boost::function_types::components<T> >::type
>(t))); >(t)));
} }
}; };
template<> template<>
struct Fun_Helper<false, true> struct Fun_Helper<false, true>
{
template<typename T>
static Proxy_Function go(T t)
{ {
return Proxy_Function( template<typename T>
new Proxy_Function_Impl< static Proxy_Function go(T t)
{
return Proxy_Function(
new Proxy_Function_Impl<
typename boost::function_types::function_type<boost::function_types::components<T> >::type> ( typename boost::function_types::function_type<boost::function_types::components<T> >::type> (
boost::function< boost::function<
typename boost::function_types::function_type<boost::function_types::components<T> >::type typename boost::function_types::function_type<boost::function_types::components<T> >::type
>(boost::mem_fn(t)))); >(boost::mem_fn(t))));
} }
}; };
template<> template<>
struct Fun_Helper<true, false> struct Fun_Helper<true, false>
{ {
template<typename T, typename Class> template<typename T, typename Class>
static Proxy_Function go(T Class::* m) static Proxy_Function go(T Class::* m)
{ {
return Proxy_Function(new Attribute_Access<T, Class>(m)); return Proxy_Function(new Attribute_Access<T, Class>(m));
} }
}; };
}
} }
template<typename T> template<typename T>
Proxy_Function fun(const boost::function<T> &f) Proxy_Function fun(const boost::function<T> &f)
{ {
return Proxy_Function(new Proxy_Function_Impl<T>(f)); return Proxy_Function(new dispatch::Proxy_Function_Impl<T>(f));
} }
template<typename T> template<typename T>
Proxy_Function fun(T t) Proxy_Function fun(T t)
{ {
return detail::Fun_Helper<boost::function_types::is_member_object_pointer<T>::value, boost::function_types::is_member_function_pointer<T>::value>::go(t); return dispatch::detail::Fun_Helper<boost::function_types::is_member_object_pointer<T>::value, boost::function_types::is_member_function_pointer<T>::value>::go(t);
} }
template<typename T, typename Q> template<typename T, typename Q>

View File

@ -99,7 +99,7 @@ namespace chaiscript
return to_string(); return to_string();
} }
virtual Boxed_Value eval(Dispatch_Engine &) { virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &) {
Boxed_Value bv; Boxed_Value bv;
throw std::runtime_error("Undispatched ast_node (internal error)"); throw std::runtime_error("Undispatched ast_node (internal error)");
} }

View File

@ -235,7 +235,7 @@ namespace chaiscript
std::vector<std::string> m_modulepaths; std::vector<std::string> m_modulepaths;
std::vector<std::string> m_usepaths; std::vector<std::string> m_usepaths;
Dispatch_Engine m_engine; chaiscript::detail::Dispatch_Engine m_engine;
/** /**
@ -307,7 +307,7 @@ namespace chaiscript
/** /**
* Returns the current evaluation m_engine * Returns the current evaluation m_engine
*/ */
Dispatch_Engine &get_eval_engine() { chaiscript::detail::Dispatch_Engine &get_eval_engine() {
return m_engine; return m_engine;
} }
@ -335,13 +335,13 @@ namespace chaiscript
add(Bootstrap::bootstrap()); add(Bootstrap::bootstrap());
m_engine.add(fun(&Dispatch_Engine::dump_system, boost::ref(m_engine)), "dump_system"); m_engine.add(fun(&chaiscript::detail::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(&chaiscript::detail::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(&chaiscript::detail::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(&chaiscript::detail::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(&chaiscript::detail::Dispatch_Engine::function_exists, boost::ref(m_engine)), "function_exists");
m_engine.add(fun(&Dispatch_Engine::get_type_name, boost::ref(m_engine)), "name"); m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_type_name, boost::ref(m_engine)), "name");
typedef void (ChaiScript::*load_mod_1)(const std::string&); typedef void (ChaiScript::*load_mod_1)(const std::string&);
@ -392,7 +392,7 @@ namespace chaiscript
struct State struct State
{ {
std::set<std::string> used_files; std::set<std::string> used_files;
Dispatch_Engine::State engine_state; chaiscript::detail::Dispatch_Engine::State engine_state;
std::set<std::string> active_loaded_modules; std::set<std::string> active_loaded_modules;
}; };
@ -532,7 +532,7 @@ namespace chaiscript
template<typename FunctionType> template<typename FunctionType>
boost::function<FunctionType> functor(const std::string &t_script) boost::function<FunctionType> functor(const std::string &t_script)
{ {
return chaiscript::functor<FunctionType>(eval(t_script)); return chaiscript::dispatch::functor<FunctionType>(eval(t_script));
} }
/** /**

View File

@ -49,7 +49,7 @@ namespace chaiscript
Binary_Operator_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Bitwise_Xor, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Binary_Operator_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Bitwise_Xor, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
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 ~Binary_Operator_AST_Node() {} virtual ~Binary_Operator_AST_Node() {}
virtual Boxed_Value eval(Dispatch_Engine &t_ss){ virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
Boxed_Value retval; Boxed_Value retval;
try { try {
@ -91,7 +91,7 @@ namespace chaiscript
Int_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Int, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Int_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Int, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
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 ~Int_AST_Node() {} virtual ~Int_AST_Node() {}
virtual Boxed_Value eval(Dispatch_Engine &){ virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &){
return const_var(int(atoi(this->text.c_str()))); return const_var(int(atoi(this->text.c_str())));
} }
@ -102,7 +102,7 @@ namespace chaiscript
Float_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Float, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Float_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Float, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
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 ~Float_AST_Node() {} virtual ~Float_AST_Node() {}
virtual Boxed_Value eval(Dispatch_Engine &){ virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &){
return const_var(double(atof(this->text.c_str()))); return const_var(double(atof(this->text.c_str())));
} }
@ -113,7 +113,7 @@ namespace chaiscript
Id_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Id, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Id_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Id, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
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 ~Id_AST_Node() {} virtual ~Id_AST_Node() {}
virtual Boxed_Value eval(Dispatch_Engine &t_ss){ virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
if (this->text == "true") { if (this->text == "true") {
return const_var(true); return const_var(true);
} }
@ -163,8 +163,8 @@ namespace chaiscript
Fun_Call_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Fun_Call, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Fun_Call_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Fun_Call, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
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(Dispatch_Engine &t_ss){ virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
Param_List_Builder plb; dispatch::Param_List_Builder plb;
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) {
@ -178,8 +178,8 @@ namespace chaiscript
} }
} }
Dispatch_Engine::Stack prev_stack = t_ss.get_stack(); chaiscript::detail::Dispatch_Engine::Stack prev_stack = t_ss.get_stack();
Dispatch_Engine::Stack new_stack = t_ss.new_stack(); chaiscript::detail::Dispatch_Engine::Stack new_stack = t_ss.new_stack();
try { try {
Boxed_Value fn = this->children[0]->eval(t_ss); Boxed_Value fn = this->children[0]->eval(t_ss);
@ -218,8 +218,8 @@ namespace chaiscript
Inplace_Fun_Call_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Inplace_Fun_Call, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Inplace_Fun_Call_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Inplace_Fun_Call, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
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(Dispatch_Engine &t_ss){ virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
Param_List_Builder plb; dispatch::Param_List_Builder plb;
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) {
@ -277,7 +277,7 @@ namespace chaiscript
Equation_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Equation, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Equation_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Equation, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
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 ~Equation_AST_Node() {} virtual ~Equation_AST_Node() {}
virtual Boxed_Value eval(Dispatch_Engine &t_ss){ virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
Boxed_Value retval; Boxed_Value retval;
try { try {
retval = this->children.back()->eval(t_ss); retval = this->children.back()->eval(t_ss);
@ -353,7 +353,7 @@ namespace chaiscript
Var_Decl_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Var_Decl, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Var_Decl_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Var_Decl, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
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 ~Var_Decl_AST_Node() {} virtual ~Var_Decl_AST_Node() {}
virtual Boxed_Value eval(Dispatch_Engine &t_ss){ virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
try { try {
t_ss.add_object(this->children[0]->text, Boxed_Value()); t_ss.add_object(this->children[0]->text, Boxed_Value());
} }
@ -391,7 +391,7 @@ namespace chaiscript
Array_Call_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Array_Call, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Array_Call_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Array_Call, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
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 ~Array_Call_AST_Node() {} virtual ~Array_Call_AST_Node() {}
virtual Boxed_Value eval(Dispatch_Engine &t_ss){ virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
Boxed_Value retval; Boxed_Value retval;
try { try {
@ -427,7 +427,7 @@ namespace chaiscript
Dot_Access_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Dot_Access, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Dot_Access_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Dot_Access, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
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 ~Dot_Access_AST_Node() {} virtual ~Dot_Access_AST_Node() {}
virtual Boxed_Value eval(Dispatch_Engine &t_ss){ virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
Boxed_Value retval; Boxed_Value retval;
try { try {
retval = this->children[0]->eval(t_ss); retval = this->children[0]->eval(t_ss);
@ -439,7 +439,7 @@ 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) {
Param_List_Builder plb; dispatch::Param_List_Builder plb;
plb << retval; plb << retval;
if (this->children[i]->children.size() > 1) { if (this->children[i]->children.size() > 1) {
@ -462,8 +462,8 @@ namespace chaiscript
fun_name = this->children[i]->text; fun_name = this->children[i]->text;
} }
Dispatch_Engine::Stack prev_stack = t_ss.get_stack(); chaiscript::detail::Dispatch_Engine::Stack prev_stack = t_ss.get_stack();
Dispatch_Engine::Stack new_stack = t_ss.new_stack(); chaiscript::detail::Dispatch_Engine::Stack new_stack = t_ss.new_stack();
try { try {
t_ss.set_stack(new_stack); t_ss.set_stack(new_stack);
@ -512,7 +512,7 @@ namespace chaiscript
Quoted_String_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Quoted_String, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Quoted_String_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Quoted_String, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
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 ~Quoted_String_AST_Node() {} virtual ~Quoted_String_AST_Node() {}
virtual Boxed_Value eval(Dispatch_Engine &){ virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &){
return const_var(this->text); return const_var(this->text);
} }
@ -523,7 +523,7 @@ namespace chaiscript
Single_Quoted_String_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Single_Quoted_String, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Single_Quoted_String_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Single_Quoted_String, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
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 ~Single_Quoted_String_AST_Node() {} virtual ~Single_Quoted_String_AST_Node() {}
virtual Boxed_Value eval(Dispatch_Engine &){ virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &){
return const_var(char(this->text[0])); return const_var(char(this->text[0]));
} }
@ -534,7 +534,7 @@ namespace chaiscript
Lambda_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Lambda, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Lambda_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Lambda, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
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 ~Lambda_AST_Node() {} virtual ~Lambda_AST_Node() {}
virtual Boxed_Value eval(Dispatch_Engine &t_ss){ virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
std::vector<std::string> t_param_names; std::vector<std::string> t_param_names;
size_t numparams = 0; size_t numparams = 0;
@ -550,8 +550,8 @@ namespace chaiscript
numparams = 0; numparams = 0;
} }
return Boxed_Value(Proxy_Function(new Dynamic_Proxy_Function return Boxed_Value(Proxy_Function(new dispatch::Dynamic_Proxy_Function
(boost::bind(&eval_function<Dispatch_Engine>, boost::ref(t_ss), this->children.back(), t_param_names, _1), (boost::bind(&eval_function<chaiscript::detail::Dispatch_Engine>, boost::ref(t_ss), this->children.back(), t_param_names, _1),
static_cast<int>(numparams), this->children.back()))); static_cast<int>(numparams), this->children.back())));
} }
@ -562,7 +562,7 @@ namespace chaiscript
Block_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Block, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Block_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Block, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
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 ~Block_AST_Node() {} virtual ~Block_AST_Node() {}
virtual Boxed_Value eval(Dispatch_Engine &t_ss){ virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
size_t num_children = this->children.size(); size_t num_children = this->children.size();
t_ss.new_scope(); t_ss.new_scope();
@ -602,7 +602,7 @@ namespace chaiscript
Def_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Def, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Def_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Def, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
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 ~Def_AST_Node() {} virtual ~Def_AST_Node() {}
virtual Boxed_Value eval(Dispatch_Engine &t_ss){ virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
std::vector<std::string> t_param_names; std::vector<std::string> t_param_names;
size_t numparams = 0; size_t numparams = 0;
AST_NodePtr guardnode; AST_NodePtr guardnode;
@ -626,10 +626,10 @@ namespace chaiscript
} }
} }
boost::shared_ptr<Dynamic_Proxy_Function> guard; boost::shared_ptr<dispatch::Dynamic_Proxy_Function> guard;
if (guardnode) { if (guardnode) {
guard = boost::shared_ptr<Dynamic_Proxy_Function> guard = boost::shared_ptr<dispatch::Dynamic_Proxy_Function>
(new Dynamic_Proxy_Function(boost::bind(&eval_function<Dispatch_Engine>, (new dispatch::Dynamic_Proxy_Function(boost::bind(&eval_function<chaiscript::detail::Dispatch_Engine>,
boost::ref(t_ss), guardnode, boost::ref(t_ss), guardnode,
t_param_names, _1), static_cast<int>(numparams), guardnode)); t_param_names, _1), static_cast<int>(numparams), guardnode));
} }
@ -638,7 +638,7 @@ namespace chaiscript
const std::string & l_function_name = this->children[0]->text; const std::string & l_function_name = this->children[0]->text;
const std::string & l_annotation = this->annotation?this->annotation->text:""; const std::string & l_annotation = this->annotation?this->annotation->text:"";
t_ss.add(Proxy_Function t_ss.add(Proxy_Function
(new Dynamic_Proxy_Function(boost::bind(&eval_function<Dispatch_Engine>, (new dispatch::Dynamic_Proxy_Function(boost::bind(&eval_function<chaiscript::detail::Dispatch_Engine>,
boost::ref(t_ss), this->children.back(), boost::ref(t_ss), this->children.back(),
t_param_names, _1), static_cast<int>(numparams), this->children.back(), t_param_names, _1), static_cast<int>(numparams), this->children.back(),
l_annotation, guard)), l_function_name); l_annotation, guard)), l_function_name);
@ -656,7 +656,7 @@ namespace chaiscript
While_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::While, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : While_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::While, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
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 ~While_AST_Node() {} virtual ~While_AST_Node() {}
virtual Boxed_Value eval(Dispatch_Engine &t_ss){ virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
bool cond; bool cond;
t_ss.new_scope(); t_ss.new_scope();
@ -711,7 +711,7 @@ namespace chaiscript
If_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::If, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : If_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::If, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
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 ~If_AST_Node() {} virtual ~If_AST_Node() {}
virtual Boxed_Value eval(Dispatch_Engine &t_ss){ virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
bool cond; bool cond;
try { try {
cond = boxed_cast<bool>(this->children[0]->eval(t_ss)); cond = boxed_cast<bool>(this->children[0]->eval(t_ss));
@ -782,7 +782,7 @@ namespace chaiscript
For_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::For, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : For_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::For, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
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 ~For_AST_Node() {} virtual ~For_AST_Node() {}
virtual Boxed_Value eval(Dispatch_Engine &t_ss){ virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
bool cond; bool cond;
t_ss.new_scope(); t_ss.new_scope();
@ -893,7 +893,7 @@ namespace chaiscript
Inline_Array_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Inline_Array, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Inline_Array_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Inline_Array, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
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 ~Inline_Array_AST_Node() {} virtual ~Inline_Array_AST_Node() {}
virtual Boxed_Value eval(Dispatch_Engine &t_ss){ virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
std::vector<Boxed_Value> vec; std::vector<Boxed_Value> vec;
if (this->children.size() > 0) { if (this->children.size() > 0) {
for (size_t i = 0; i < this->children[0]->children.size(); ++i) { for (size_t i = 0; i < this->children[0]->children.size(); ++i) {
@ -917,7 +917,7 @@ namespace chaiscript
Inline_Map_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Inline_Map, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Inline_Map_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Inline_Map, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
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 ~Inline_Map_AST_Node() {} virtual ~Inline_Map_AST_Node() {}
virtual Boxed_Value eval(Dispatch_Engine &t_ss){ virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
try { try {
std::map<std::string, Boxed_Value> retval; std::map<std::string, Boxed_Value> retval;
for (size_t i = 0; i < this->children[0]->children.size(); ++i) { for (size_t i = 0; i < this->children[0]->children.size(); ++i) {
@ -944,7 +944,7 @@ namespace chaiscript
Return_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Return, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Return_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Return, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
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 ~Return_AST_Node() {} virtual ~Return_AST_Node() {}
virtual Boxed_Value eval(Dispatch_Engine &t_ss){ virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
if (this->children.size() > 0) { if (this->children.size() > 0) {
try { try {
throw detail::Return_Value(this->children[0]->eval(t_ss)); throw detail::Return_Value(this->children[0]->eval(t_ss));
@ -966,7 +966,7 @@ namespace chaiscript
File_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::File, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : File_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::File, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
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 ~File_AST_Node() {} virtual ~File_AST_Node() {}
virtual Boxed_Value eval(Dispatch_Engine &t_ss) { virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss) {
const size_t size = this->children.size(); const size_t size = this->children.size();
for (size_t i = 0; i < size; ++i) { for (size_t i = 0; i < size; ++i) {
try { try {
@ -989,7 +989,7 @@ namespace chaiscript
Prefix_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Prefix, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Prefix_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Prefix, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
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 ~Prefix_AST_Node() {} virtual ~Prefix_AST_Node() {}
virtual Boxed_Value eval(Dispatch_Engine &t_ss){ virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
try { try {
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));
} }
@ -1005,7 +1005,7 @@ namespace chaiscript
Break_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Break, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Break_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Break, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
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(chaiscript::detail::Dispatch_Engine &){
throw detail::Break_Loop(); throw detail::Break_Loop();
} }
}; };
@ -1029,7 +1029,7 @@ namespace chaiscript
Inline_Range_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Inline_Range, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Inline_Range_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Inline_Range, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
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 ~Inline_Range_AST_Node() {} virtual ~Inline_Range_AST_Node() {}
virtual Boxed_Value eval(Dispatch_Engine &t_ss){ virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
try { try {
return t_ss.call_function("generate_range", return t_ss.call_function("generate_range",
this->children[0]->children[0]->children[0]->eval(t_ss), this->children[0]->children[0]->children[0]->eval(t_ss),
@ -1058,7 +1058,7 @@ namespace chaiscript
Try_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Try, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Try_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Try, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
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 ~Try_AST_Node() {} virtual ~Try_AST_Node() {}
virtual Boxed_Value eval(Dispatch_Engine &t_ss){ virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
Boxed_Value retval; Boxed_Value retval;
t_ss.new_scope(); t_ss.new_scope();
@ -1300,7 +1300,7 @@ namespace chaiscript
Method_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Method, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Method_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Method, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
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 ~Method_AST_Node() {} virtual ~Method_AST_Node() {}
virtual Boxed_Value eval(Dispatch_Engine &t_ss){ virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
std::vector<std::string> t_param_names; std::vector<std::string> t_param_names;
AST_NodePtr guardnode; AST_NodePtr guardnode;
@ -1327,10 +1327,10 @@ namespace chaiscript
size_t numparams = t_param_names.size(); size_t numparams = t_param_names.size();
boost::shared_ptr<Dynamic_Proxy_Function> guard; boost::shared_ptr<dispatch::Dynamic_Proxy_Function> guard;
if (guardnode) { if (guardnode) {
guard = boost::shared_ptr<Dynamic_Proxy_Function> guard = boost::shared_ptr<dispatch::Dynamic_Proxy_Function>
(new Dynamic_Proxy_Function(boost::bind(&eval_function<Dispatch_Engine>, (new dispatch::Dynamic_Proxy_Function(boost::bind(&eval_function<chaiscript::detail::Dispatch_Engine>,
boost::ref(t_ss), guardnode, boost::ref(t_ss), guardnode,
t_param_names, _1), static_cast<int>(numparams), guardnode)); t_param_names, _1), static_cast<int>(numparams), guardnode));
} }
@ -1341,8 +1341,8 @@ namespace chaiscript
const std::string & function_name = this->children[1]->text; const std::string & function_name = this->children[1]->text;
if (function_name == class_name) { if (function_name == class_name) {
t_ss.add(Proxy_Function t_ss.add(Proxy_Function
(new detail::Dynamic_Object_Constructor(class_name, Proxy_Function (new dispatch::detail::Dynamic_Object_Constructor(class_name, Proxy_Function
(new Dynamic_Proxy_Function(boost::bind(&eval_function<Dispatch_Engine>, (new dispatch::Dynamic_Proxy_Function(boost::bind(&eval_function<chaiscript::detail::Dispatch_Engine>,
boost::ref(t_ss), this->children.back(), boost::ref(t_ss), this->children.back(),
t_param_names, _1), static_cast<int>(numparams), this->children.back(), t_param_names, _1), static_cast<int>(numparams), this->children.back(),
l_annotation, guard)))), function_name); l_annotation, guard)))), function_name);
@ -1356,8 +1356,8 @@ namespace chaiscript
// No biggie, the type name is just not known // No biggie, the type name is just not known
} }
t_ss.add(Proxy_Function t_ss.add(Proxy_Function
(new detail::Dynamic_Object_Function(class_name, Proxy_Function (new dispatch::detail::Dynamic_Object_Function(class_name, Proxy_Function
(new Dynamic_Proxy_Function(boost::bind(&eval_function<Dispatch_Engine>, (new dispatch::Dynamic_Proxy_Function(boost::bind(&eval_function<chaiscript::detail::Dispatch_Engine>,
boost::ref(t_ss), this->children.back(), boost::ref(t_ss), this->children.back(),
t_param_names, _1), static_cast<int>(numparams), this->children.back(), t_param_names, _1), static_cast<int>(numparams), this->children.back(),
l_annotation, guard)), ti)), function_name); l_annotation, guard)), ti)), function_name);
@ -1377,9 +1377,9 @@ namespace chaiscript
Attr_Decl_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Attr_Decl, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Attr_Decl_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Attr_Decl, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
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 ~Attr_Decl_AST_Node() {} virtual ~Attr_Decl_AST_Node() {}
virtual Boxed_Value eval(Dispatch_Engine &t_ss){ virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
try { try {
t_ss.add(fun(boost::function<Boxed_Value (Dynamic_Object &)>(boost::bind(&detail::Dynamic_Object_Attribute::func, this->children[0]->text, t_ss.add(fun(boost::function<Boxed_Value (dispatch::Dynamic_Object &)>(boost::bind(&dispatch::detail::Dynamic_Object_Attribute::func, this->children[0]->text,
this->children[1]->text, _1))), this->children[1]->text); this->children[1]->text, _1))), this->children[1]->text);
} }
@ -1431,7 +1431,7 @@ namespace chaiscript
Logical_And_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Logical_And, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Logical_And_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Logical_And, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
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 ~Logical_And_AST_Node() {} virtual ~Logical_And_AST_Node() {}
virtual Boxed_Value eval(Dispatch_Engine &t_ss){ virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
Boxed_Value retval; Boxed_Value retval;
try { try {
retval = this->children[0]->eval(t_ss); retval = this->children[0]->eval(t_ss);
@ -1473,7 +1473,7 @@ namespace chaiscript
Logical_Or_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Logical_Or, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Logical_Or_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Logical_Or, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
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 ~Logical_Or_AST_Node() {} virtual ~Logical_Or_AST_Node() {}
virtual Boxed_Value eval(Dispatch_Engine &t_ss){ virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
Boxed_Value retval; Boxed_Value retval;
try { try {

View File

@ -45,7 +45,7 @@ struct System
void add_callback(const std::string &t_name, void add_callback(const std::string &t_name,
const chaiscript::Proxy_Function &t_func) const chaiscript::Proxy_Function &t_func)
{ {
m_callbacks[t_name] = chaiscript::functor<std::string (const std::string &)>(t_func); m_callbacks[t_name] = chaiscript::dispatch::functor<std::string (const std::string &)>(t_func);
} }
@ -163,9 +163,9 @@ int main(int /*argc*/, char * /*argv*/[]) {
chai.add(fun(&bound_log, std::string("Msg")), "BoundFun"); chai.add(fun(&bound_log, std::string("Msg")), "BoundFun");
//Dynamic objects test //Dynamic objects test
chai.add(chaiscript::Proxy_Function(new detail::Dynamic_Object_Function("TestType", fun(&hello_world))), "hello_world"); chai.add(chaiscript::Proxy_Function(new dispatch::detail::Dynamic_Object_Function("TestType", fun(&hello_world))), "hello_world");
chai.add(chaiscript::Proxy_Function(new detail::Dynamic_Object_Constructor("TestType", fun(&hello_constructor))), "TestType"); chai.add(chaiscript::Proxy_Function(new dispatch::detail::Dynamic_Object_Constructor("TestType", fun(&hello_constructor))), "TestType");
chai.add(fun(boost::function<Boxed_Value (Dynamic_Object &)>(boost::bind(&detail::Dynamic_Object_Attribute::func, "TestType", "attr", _1))), "attr"); chai.add(fun(boost::function<Boxed_Value (dispatch::Dynamic_Object &)>(boost::bind(&dispatch::detail::Dynamic_Object_Attribute::func, "TestType", "attr", _1))), "attr");
chai.eval("var x = TestType()"); chai.eval("var x = TestType()");
// chai.eval("x.attr = \"hi\""); // chai.eval("x.attr = \"hi\"");

View File

@ -55,7 +55,7 @@ void version(int){
bool throws_exception(const chaiscript::Proxy_Function &f) bool throws_exception(const chaiscript::Proxy_Function &f)
{ {
try { try {
chaiscript::functor<void ()>(f)(); chaiscript::dispatch::functor<void ()>(f)();
} catch (...) { } catch (...) {
return true; return true;
} }

View File

@ -14,7 +14,8 @@
bool has_parse_tree(const chaiscript::Const_Proxy_Function &t_pf) bool has_parse_tree(const chaiscript::Const_Proxy_Function &t_pf)
{ {
boost::shared_ptr<const chaiscript::Dynamic_Proxy_Function> pf = boost::dynamic_pointer_cast<const chaiscript::Dynamic_Proxy_Function>(t_pf); boost::shared_ptr<const chaiscript::dispatch::Dynamic_Proxy_Function> pf
= boost::dynamic_pointer_cast<const chaiscript::dispatch::Dynamic_Proxy_Function>(t_pf);
if (pf) if (pf)
{ {
return pf->get_parse_tree(); return pf->get_parse_tree();
@ -25,7 +26,8 @@ bool has_parse_tree(const chaiscript::Const_Proxy_Function &t_pf)
chaiscript::AST_NodePtr get_parse_tree(const chaiscript::Const_Proxy_Function &t_pf) chaiscript::AST_NodePtr get_parse_tree(const chaiscript::Const_Proxy_Function &t_pf)
{ {
boost::shared_ptr<const chaiscript::Dynamic_Proxy_Function> pf = boost::dynamic_pointer_cast<const chaiscript::Dynamic_Proxy_Function>(t_pf); boost::shared_ptr<const chaiscript::dispatch::Dynamic_Proxy_Function> pf
= boost::dynamic_pointer_cast<const chaiscript::dispatch::Dynamic_Proxy_Function>(t_pf);
if (pf) if (pf)
{ {
if (pf->get_parse_tree()) if (pf->get_parse_tree())

View File

@ -19,7 +19,7 @@ int main()
chai("attr bob::z; def bob::bob() { this.z = 10 }; var x = bob()"); chai("attr bob::z; def bob::bob() { this.z = 10 }; var x = bob()");
chaiscript::Dynamic_Object &mydo = chai.eval<chaiscript::Dynamic_Object &>("x"); chaiscript::dispatch::Dynamic_Object &mydo = chai.eval<chaiscript::dispatch::Dynamic_Object &>("x");
assert_equal(mydo.get_type_name(), "bob"); assert_equal(mydo.get_type_name(), "bob");