Even more reorganization of namespaces to help with documentation and
clarity.
This commit is contained in:
parent
8bd512a0af
commit
58e5df0a9a
@ -31,7 +31,7 @@ namespace chaiscript
|
||||
P1 &assign_pod(P1 &p1, Boxed_POD_Value v)
|
||||
{
|
||||
|
||||
if (v.m_isfloat)
|
||||
if (v.isfloat)
|
||||
{
|
||||
return (p1 = P1(v.d));
|
||||
} else {
|
||||
@ -42,7 +42,7 @@ namespace chaiscript
|
||||
template<typename P1>
|
||||
P1 construct_pod(Boxed_POD_Value v)
|
||||
{
|
||||
if (v.m_isfloat)
|
||||
if (v.isfloat)
|
||||
{
|
||||
return P1(v.d);
|
||||
} else {
|
||||
@ -53,7 +53,7 @@ namespace chaiscript
|
||||
template<typename P1>
|
||||
P1 &assign_bitwise_and_pod(P1 &p1, Boxed_POD_Value r)
|
||||
{
|
||||
if (!r.m_isfloat)
|
||||
if (!r.isfloat)
|
||||
{
|
||||
return p1 &= P1(r.i);
|
||||
}
|
||||
@ -64,7 +64,7 @@ namespace chaiscript
|
||||
template<typename P1>
|
||||
P1 &assign_xor_pod(P1 &p1, Boxed_POD_Value r)
|
||||
{
|
||||
if (!r.m_isfloat)
|
||||
if (!r.isfloat)
|
||||
{
|
||||
return p1 ^= P1(r.i);
|
||||
}
|
||||
@ -75,7 +75,7 @@ namespace chaiscript
|
||||
template<typename P1>
|
||||
P1 &assign_bitwise_or_pod(P1 &p1, Boxed_POD_Value r)
|
||||
{
|
||||
if (!r.m_isfloat)
|
||||
if (!r.isfloat)
|
||||
{
|
||||
return p1 |= P1(r.i);
|
||||
}
|
||||
@ -86,7 +86,7 @@ namespace chaiscript
|
||||
template<typename P1>
|
||||
P1 &assign_difference_pod(P1 &p1, Boxed_POD_Value r)
|
||||
{
|
||||
if (r.m_isfloat)
|
||||
if (r.isfloat)
|
||||
{
|
||||
return p1 -= P1(r.d);
|
||||
} else {
|
||||
@ -97,7 +97,7 @@ namespace chaiscript
|
||||
template<typename P1>
|
||||
P1 &assign_left_shift_pod(P1 &p1, Boxed_POD_Value r)
|
||||
{
|
||||
if (!r.m_isfloat)
|
||||
if (!r.isfloat)
|
||||
{
|
||||
return p1 <<= P1(r.i);
|
||||
}
|
||||
@ -109,7 +109,7 @@ namespace chaiscript
|
||||
template<typename P1>
|
||||
P1 &assign_product_pod(P1 &p1, Boxed_POD_Value r)
|
||||
{
|
||||
if (r.m_isfloat)
|
||||
if (r.isfloat)
|
||||
{
|
||||
return p1 *= P1(r.d);
|
||||
} else {
|
||||
@ -120,7 +120,7 @@ namespace chaiscript
|
||||
template<typename P1>
|
||||
P1 &assign_quotient_pod(P1 &p1, Boxed_POD_Value r)
|
||||
{
|
||||
if (r.m_isfloat)
|
||||
if (r.isfloat)
|
||||
{
|
||||
return p1 /= P1(r.d);
|
||||
} else {
|
||||
@ -131,7 +131,7 @@ namespace chaiscript
|
||||
template<typename P1>
|
||||
P1 &assign_remainder_pod(P1 &p1, Boxed_POD_Value r)
|
||||
{
|
||||
if (!r.m_isfloat)
|
||||
if (!r.isfloat)
|
||||
{
|
||||
return p1 %= P1(r.i);
|
||||
}
|
||||
@ -143,7 +143,7 @@ namespace chaiscript
|
||||
template<typename P1>
|
||||
P1 &assign_right_shift_pod(P1 &p1, Boxed_POD_Value r)
|
||||
{
|
||||
if (!r.m_isfloat)
|
||||
if (!r.isfloat)
|
||||
{
|
||||
return p1 >>= P1(r.i);
|
||||
}
|
||||
@ -155,7 +155,7 @@ namespace chaiscript
|
||||
template<typename P1>
|
||||
P1 &assign_sum_pod(P1 &p1, Boxed_POD_Value r)
|
||||
{
|
||||
if (r.m_isfloat)
|
||||
if (r.isfloat)
|
||||
{
|
||||
return p1 += P1(r.d);
|
||||
} else {
|
||||
@ -458,7 +458,7 @@ namespace chaiscript
|
||||
|
||||
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()))));
|
||||
}
|
||||
|
||||
@ -480,7 +480,7 @@ namespace chaiscript
|
||||
|
||||
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)
|
||||
{
|
||||
return pf->get_guard();
|
||||
@ -491,7 +491,7 @@ namespace chaiscript
|
||||
|
||||
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->get_guard())
|
||||
@ -509,7 +509,7 @@ namespace chaiscript
|
||||
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");
|
||||
return e;
|
||||
@ -535,7 +535,7 @@ namespace chaiscript
|
||||
|
||||
template<typename FunctionType>
|
||||
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;
|
||||
Vector v = (b->*f)();
|
||||
@ -552,7 +552,7 @@ namespace chaiscript
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
@ -570,14 +570,14 @@ namespace chaiscript
|
||||
m->add(user_type<Proxy_Function>(), "function");
|
||||
m->add(user_type<std::exception>(), "exception");
|
||||
|
||||
m->add(fun(&Proxy_Function_Base::get_arity), "get_arity");
|
||||
m->add(fun(&Proxy_Function_Base::annotation), "get_annotation");
|
||||
m->add(fun(&Proxy_Function_Base::operator()), "call");
|
||||
m->add(fun(&Proxy_Function_Base::operator==), "==");
|
||||
m->add(fun(&dispatch::Proxy_Function_Base::get_arity), "get_arity");
|
||||
m->add(fun(&dispatch::Proxy_Function_Base::annotation), "get_annotation");
|
||||
m->add(fun(&dispatch::Proxy_Function_Base::operator()), "call");
|
||||
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(&Proxy_Function_Base::get_contained_functions)), "get_contained_functions");
|
||||
m->add(fun(return_boxed_value_vector(&dispatch::Proxy_Function_Base::get_param_types)), "get_param_types");
|
||||
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");
|
||||
@ -587,11 +587,11 @@ namespace chaiscript
|
||||
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(user_type<Dynamic_Object>(), "Dynamic_Object");
|
||||
m->add(constructor<Dynamic_Object (const std::string &)>(), "Dynamic_Object");
|
||||
m->add(fun(&Dynamic_Object::get_type_name), "get_type_name");
|
||||
m->add(fun(&Dynamic_Object::get_attrs), "get_attrs");
|
||||
m->add(fun(&Dynamic_Object::get_attr), "get_attr");
|
||||
m->add(user_type<dispatch::Dynamic_Object>(), "Dynamic_Object");
|
||||
m->add(constructor<dispatch::Dynamic_Object (const std::string &)>(), "Dynamic_Object");
|
||||
m->add(fun(&dispatch::Dynamic_Object::get_type_name), "get_type_name");
|
||||
m->add(fun(&dispatch::Dynamic_Object::get_attrs), "get_attrs");
|
||||
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; }");
|
||||
|
||||
@ -648,14 +648,14 @@ namespace chaiscript
|
||||
m->add(fun(&print), "print_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");
|
||||
|
||||
m->add(fun(&shared_ptr_unconst_clone<Proxy_Function_Base>), "clone");
|
||||
m->add(fun(&ptr_assign<boost::remove_const<Proxy_Function_Base>::type>), "=");
|
||||
m->add(fun(&ptr_assign<boost::add_const<Proxy_Function_Base>::type>), "=");
|
||||
m->add(fun(&shared_ptr_unconst_clone<dispatch::Proxy_Function_Base>), "clone");
|
||||
m->add(fun(&ptr_assign<boost::remove_const<dispatch::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");
|
||||
|
||||
m->add(fun(&type_match), "type_match");
|
||||
|
@ -21,205 +21,205 @@ namespace chaiscript
|
||||
* Object which attempts to convert a Boxed_Value into a generic
|
||||
* POD type and provide generic POD type operations
|
||||
*/
|
||||
struct Boxed_POD_Value
|
||||
class Boxed_POD_Value
|
||||
{
|
||||
Boxed_POD_Value(const Boxed_Value &v)
|
||||
: d(0), i(0), m_isfloat(false)
|
||||
{
|
||||
if (v.get_type_info().is_undef())
|
||||
public:
|
||||
Boxed_POD_Value(const Boxed_Value &v)
|
||||
: d(0), i(0), isfloat(false)
|
||||
{
|
||||
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();
|
||||
|
||||
if (inp_ == typeid(double))
|
||||
bool operator==(const Boxed_POD_Value &r) const
|
||||
{
|
||||
d = boxed_cast<double>(v);
|
||||
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 ((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
|
||||
{
|
||||
if (!m_isfloat && !r.m_isfloat)
|
||||
bool operator<(const Boxed_POD_Value &r) const
|
||||
{
|
||||
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
|
||||
{
|
||||
if (!m_isfloat && !r.m_isfloat)
|
||||
bool operator>(const Boxed_POD_Value &r) const
|
||||
{
|
||||
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");
|
||||
}
|
||||
|
||||
Boxed_Value operator^(const Boxed_POD_Value &r) const
|
||||
{
|
||||
if (!m_isfloat && !r.m_isfloat)
|
||||
bool operator>=(const Boxed_POD_Value &r) const
|
||||
{
|
||||
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");
|
||||
}
|
||||
|
||||
Boxed_Value operator|(const Boxed_POD_Value &r) const
|
||||
{
|
||||
if (!m_isfloat && !r.m_isfloat)
|
||||
bool operator<=(const Boxed_POD_Value &r) const
|
||||
{
|
||||
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");
|
||||
}
|
||||
|
||||
Boxed_Value operator/(const Boxed_POD_Value &r) const
|
||||
{
|
||||
if (!m_isfloat && !r.m_isfloat)
|
||||
bool operator!=(const Boxed_POD_Value &r) const
|
||||
{
|
||||
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
|
||||
{
|
||||
if (!m_isfloat && !r.m_isfloat)
|
||||
Boxed_Value operator+(const Boxed_POD_Value &r) const
|
||||
{
|
||||
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
|
||||
{
|
||||
if (!m_isfloat && !r.m_isfloat)
|
||||
Boxed_Value operator-(const Boxed_POD_Value &r) const
|
||||
{
|
||||
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
|
||||
{
|
||||
if (!m_isfloat && !r.m_isfloat)
|
||||
Boxed_Value operator&(const Boxed_POD_Value &r) const
|
||||
{
|
||||
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
|
||||
{
|
||||
if (!m_isfloat && !r.m_isfloat)
|
||||
Boxed_Value operator^(const Boxed_POD_Value &r) const
|
||||
{
|
||||
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 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)
|
||||
Boxed_Value operator|(const Boxed_POD_Value &r) const
|
||||
{
|
||||
return Boxed_Value(t_i);
|
||||
} else {
|
||||
return Boxed_Value(static_cast<int>(t_i));
|
||||
if (!isfloat && !r.isfloat)
|
||||
{
|
||||
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;
|
||||
boost::int64_t i;
|
||||
return Boxed_Value(((isfloat)?d:i) * ((r.isfloat)?r.d:r.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
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -11,270 +11,273 @@
|
||||
|
||||
namespace chaiscript
|
||||
{
|
||||
class Dynamic_Object
|
||||
namespace dispatch
|
||||
{
|
||||
public:
|
||||
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
|
||||
class Dynamic_Object
|
||||
{
|
||||
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)
|
||||
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:
|
||||
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)
|
||||
&& "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
|
||||
{
|
||||
const Dynamic_Object_Function *df = dynamic_cast<const Dynamic_Object_Function *>(&f);
|
||||
if (df)
|
||||
virtual bool operator==(const Proxy_Function_Base &f) const
|
||||
{
|
||||
return df->m_type_name == m_type_name && (*df->m_func) == (*m_func);
|
||||
} else {
|
||||
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> ¶ms) 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)
|
||||
const Dynamic_Object_Function *df = dynamic_cast<const Dynamic_Object_Function *>(&f);
|
||||
if (df)
|
||||
{
|
||||
return bv.get_type_info().bare_equal(*ti);
|
||||
return df->m_type_name == m_type_name && (*df->m_func) == (*m_func);
|
||||
} 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)
|
||||
virtual bool call_match(const std::vector<Boxed_Value> &vals) const
|
||||
{
|
||||
return dynamic_object_typename_match(bvs[0], name, ti);
|
||||
} else {
|
||||
return false;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
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> ¶ms) 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);
|
||||
} 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)
|
||||
&& "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)
|
||||
{
|
||||
std::vector<Type_Info>::const_iterator begin = tl.begin();
|
||||
std::vector<Type_Info>::const_iterator end = tl.end();
|
||||
|
||||
if (begin != end)
|
||||
static std::vector<Type_Info> build_type_list(const std::vector<Type_Info> &tl)
|
||||
{
|
||||
++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
|
||||
{
|
||||
const Dynamic_Object_Constructor *dc = dynamic_cast<const Dynamic_Object_Constructor*>(&f);
|
||||
if (dc)
|
||||
virtual bool operator==(const Proxy_Function_Base &f) const
|
||||
{
|
||||
return dc->m_type_name == m_type_name && (*dc->m_func) == (*m_func);
|
||||
} else {
|
||||
return false;
|
||||
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);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool call_match(const std::vector<Boxed_Value> &vals) const
|
||||
{
|
||||
std::vector<Boxed_Value> new_vals;
|
||||
new_vals.push_back(Boxed_Value(Dynamic_Object(m_type_name)));
|
||||
new_vals.insert(new_vals.end(), vals.begin(), vals.end());
|
||||
virtual bool call_match(const std::vector<Boxed_Value> &vals) const
|
||||
{
|
||||
std::vector<Boxed_Value> new_vals;
|
||||
new_vals.push_back(Boxed_Value(Dynamic_Object(m_type_name)));
|
||||
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
|
||||
{
|
||||
// "this" is not considered part of the arity
|
||||
return m_func->get_arity() - 1;
|
||||
}
|
||||
virtual int get_arity() const
|
||||
{
|
||||
// "this" is not considered part of the arity
|
||||
return m_func->get_arity() - 1;
|
||||
}
|
||||
|
||||
virtual std::string annotation() const
|
||||
{
|
||||
return m_func->annotation();
|
||||
}
|
||||
virtual std::string annotation() const
|
||||
{
|
||||
return m_func->annotation();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual Boxed_Value do_call(const std::vector<Boxed_Value> ¶ms) const
|
||||
{
|
||||
std::vector<Boxed_Value> new_params;
|
||||
chaiscript::Boxed_Value bv = var(Dynamic_Object(m_type_name));
|
||||
new_params.push_back(bv);
|
||||
new_params.insert(new_params.end(), params.begin(), params.end());
|
||||
protected:
|
||||
virtual Boxed_Value do_call(const std::vector<Boxed_Value> ¶ms) const
|
||||
{
|
||||
std::vector<Boxed_Value> new_params;
|
||||
chaiscript::Boxed_Value bv = var(Dynamic_Object(m_type_name));
|
||||
new_params.push_back(bv);
|
||||
new_params.insert(new_params.end(), params.begin(), params.end());
|
||||
|
||||
(*m_func)(new_params);
|
||||
(*m_func)(new_params);
|
||||
|
||||
return bv;
|
||||
}
|
||||
return bv;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_type_name;
|
||||
Proxy_Function m_func;
|
||||
private:
|
||||
std::string m_type_name;
|
||||
Proxy_Function m_func;
|
||||
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -20,37 +20,39 @@
|
||||
|
||||
namespace chaiscript
|
||||
{
|
||||
/**
|
||||
* Build a function caller that knows how to dispatch on a set of functions
|
||||
* example:
|
||||
* boost::function<void (int)> f =
|
||||
* build_function_caller(dispatchkit.get_function("print"));
|
||||
* \returns A boost::function object for dispatching
|
||||
* \param[in] funcs the set of functions to dispatch on.
|
||||
*/
|
||||
template<typename FunctionType>
|
||||
boost::function<FunctionType>
|
||||
namespace dispatch
|
||||
{
|
||||
/**
|
||||
* Build a function caller that knows how to dispatch on a set of functions
|
||||
* example:
|
||||
* boost::function<void (int)> f =
|
||||
* build_function_caller(dispatchkit.get_function("print"));
|
||||
* \returns A boost::function object for dispatching
|
||||
* \param[in] funcs the set of functions to dispatch on.
|
||||
*/
|
||||
template<typename FunctionType>
|
||||
boost::function<FunctionType>
|
||||
functor(const std::vector<Const_Proxy_Function> &funcs)
|
||||
{
|
||||
FunctionType *p=0;
|
||||
return detail::build_function_caller_helper(p, funcs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a function caller for a particular Proxy_Function object
|
||||
* useful in the case that a function is being pass out from scripting back
|
||||
* into code
|
||||
* example:
|
||||
* void my_function(Proxy_Function f)
|
||||
* {
|
||||
* boost::function<void (int)> local_f =
|
||||
* build_function_caller(f);
|
||||
* }
|
||||
* \returns A boost::function object for dispatching
|
||||
* \param[in] func A function to execute.
|
||||
*/
|
||||
template<typename FunctionType>
|
||||
boost::function<FunctionType>
|
||||
/**
|
||||
* Build a function caller for a particular Proxy_Function object
|
||||
* useful in the case that a function is being pass out from scripting back
|
||||
* into code
|
||||
* example:
|
||||
* void my_function(Proxy_Function f)
|
||||
* {
|
||||
* boost::function<void (int)> local_f =
|
||||
* build_function_caller(f);
|
||||
* }
|
||||
* \returns A boost::function object for dispatching
|
||||
* \param[in] func A function to execute.
|
||||
*/
|
||||
template<typename FunctionType>
|
||||
boost::function<FunctionType>
|
||||
functor(Const_Proxy_Function func)
|
||||
{
|
||||
std::vector<Const_Proxy_Function> funcs;
|
||||
@ -58,76 +60,76 @@ namespace chaiscript
|
||||
return functor<FunctionType>(funcs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for automatically unboxing a Boxed_Value that contains a function object
|
||||
* and creating a typesafe C++ function caller from it.
|
||||
*/
|
||||
template<typename FunctionType>
|
||||
boost::function<FunctionType>
|
||||
/**
|
||||
* Helper for automatically unboxing a Boxed_Value that contains a function object
|
||||
* and creating a typesafe C++ function caller from it.
|
||||
*/
|
||||
template<typename FunctionType>
|
||||
boost::function<FunctionType>
|
||||
functor(const Boxed_Value &bv)
|
||||
{
|
||||
return functor<FunctionType>(boxed_cast<Const_Proxy_Function >(bv));
|
||||
}
|
||||
}
|
||||
|
||||
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>
|
||||
struct Cast_Helper<const boost::function<Signature> &>
|
||||
{
|
||||
typedef boost::function<Signature> Result_Type;
|
||||
|
||||
|
||||
static Result_Type cast(const Boxed_Value &ob)
|
||||
{
|
||||
if (ob.get_type_info().bare_equal(user_type<Const_Proxy_Function>()))
|
||||
{
|
||||
return functor<Signature>(ob);
|
||||
return dispatch::functor<Signature>(ob);
|
||||
} else {
|
||||
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>
|
||||
struct Cast_Helper<boost::function<Signature> >
|
||||
{
|
||||
typedef boost::function<Signature> Result_Type;
|
||||
|
||||
|
||||
static Result_Type cast(const Boxed_Value &ob)
|
||||
{
|
||||
if (ob.get_type_info().bare_equal(user_type<Const_Proxy_Function>()))
|
||||
{
|
||||
return functor<Signature>(ob);
|
||||
return dispatch::functor<Signature>(ob);
|
||||
} else {
|
||||
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>
|
||||
struct Cast_Helper<const boost::function<Signature> >
|
||||
{
|
||||
typedef boost::function<Signature> Result_Type;
|
||||
|
||||
|
||||
static Result_Type cast(const Boxed_Value &ob)
|
||||
{
|
||||
if (ob.get_type_info().bare_equal(user_type<Const_Proxy_Function>()))
|
||||
{
|
||||
return functor<Signature>(ob);
|
||||
return dispatch::functor<Signature>(ob);
|
||||
} else {
|
||||
return Cast_Helper_Inner<const boost::function<Signature> >::cast(ob);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -23,35 +23,38 @@
|
||||
|
||||
namespace chaiscript
|
||||
{
|
||||
namespace detail
|
||||
namespace dispatch
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
/**
|
||||
* Internal helper class for handling the return
|
||||
* value of a build_function_caller
|
||||
*/
|
||||
template<typename Ret>
|
||||
struct Function_Caller_Ret
|
||||
{
|
||||
static Ret call(const std::vector<Const_Proxy_Function> &t_funcs,
|
||||
const std::vector<Boxed_Value> ¶ms)
|
||||
/**
|
||||
* Internal helper class for handling the return
|
||||
* value of a build_function_caller
|
||||
*/
|
||||
template<typename Ret>
|
||||
struct Function_Caller_Ret
|
||||
{
|
||||
return boxed_cast<Ret>(dispatch(t_funcs, params));
|
||||
}
|
||||
};
|
||||
static Ret call(const std::vector<Const_Proxy_Function> &t_funcs,
|
||||
const std::vector<Boxed_Value> ¶ms)
|
||||
{
|
||||
return boxed_cast<Ret>(dispatch::dispatch(t_funcs, params));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Specialization for void return types
|
||||
*/
|
||||
template<>
|
||||
struct Function_Caller_Ret<void>
|
||||
{
|
||||
static void call(const std::vector<Const_Proxy_Function> &t_funcs,
|
||||
const std::vector<Boxed_Value> ¶ms)
|
||||
/**
|
||||
* Specialization for void return types
|
||||
*/
|
||||
template<>
|
||||
struct Function_Caller_Ret<void>
|
||||
{
|
||||
dispatch(t_funcs, params);
|
||||
}
|
||||
};
|
||||
static void call(const std::vector<Const_Proxy_Function> &t_funcs,
|
||||
const std::vector<Boxed_Value> ¶ms)
|
||||
{
|
||||
dispatch::dispatch(t_funcs, params);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,47 +68,49 @@ namespace chaiscript
|
||||
|
||||
namespace chaiscript
|
||||
{
|
||||
namespace detail
|
||||
namespace dispatch
|
||||
{
|
||||
/**
|
||||
* used internally for unwrapping a function call's types
|
||||
*/
|
||||
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
|
||||
BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_BINARY_PARAMS(n, Param, p) )
|
||||
{
|
||||
std::vector<Boxed_Value> params;
|
||||
|
||||
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)
|
||||
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) >
|
||||
Ret function_caller(const std::vector<Const_Proxy_Function> &funcs
|
||||
BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_BINARY_PARAMS(n, Param, p) )
|
||||
{
|
||||
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]);
|
||||
std::vector<Boxed_Value> params;
|
||||
|
||||
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
|
||||
BOOST_PP_REPEAT(n, addparam, ~)
|
||||
|
||||
return Function_Caller_Ret<Ret>::call(funcs, params);
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -26,7 +26,7 @@ namespace chaiscript
|
||||
Proxy_Function constructor()
|
||||
{
|
||||
T *f = 0;
|
||||
return (detail::build_constructor_(f));
|
||||
return (dispatch::detail::build_constructor_(f));
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,30 +35,33 @@ namespace chaiscript
|
||||
|
||||
namespace chaiscript
|
||||
{
|
||||
namespace detail
|
||||
namespace dispatch
|
||||
{
|
||||
/**
|
||||
* A constructor function, used for creating a new object
|
||||
* of a given type with a given set of params
|
||||
*/
|
||||
template<typename Class BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param) >
|
||||
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) ));
|
||||
}
|
||||
namespace detail
|
||||
{
|
||||
/**
|
||||
* A constructor function, used for creating a new object
|
||||
* of a given type with a given set of params
|
||||
*/
|
||||
template<typename Class BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param) >
|
||||
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
|
||||
* example:
|
||||
* 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
|
||||
*/
|
||||
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)))
|
||||
{
|
||||
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)>))));
|
||||
}
|
||||
/**
|
||||
* Helper function for build a constructor function
|
||||
* example:
|
||||
* 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
|
||||
*/
|
||||
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)))
|
||||
{
|
||||
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)>))));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#undef n
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -18,61 +18,63 @@
|
||||
|
||||
namespace chaiscript
|
||||
{
|
||||
namespace detail
|
||||
namespace dispatch
|
||||
{
|
||||
template<bool Object, bool MemFn>
|
||||
struct Fun_Helper
|
||||
{
|
||||
template<typename T>
|
||||
static Proxy_Function go(T t)
|
||||
namespace detail
|
||||
{
|
||||
template<bool Object, bool MemFn>
|
||||
struct Fun_Helper
|
||||
{
|
||||
return Proxy_Function(
|
||||
new Proxy_Function_Impl<
|
||||
template<typename T>
|
||||
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> (
|
||||
boost::function<
|
||||
typename boost::function_types::function_type<boost::function_types::components<T> >::type
|
||||
>(t)));
|
||||
}
|
||||
};
|
||||
typename boost::function_types::function_type<boost::function_types::components<T> >::type
|
||||
>(t)));
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Fun_Helper<false, true>
|
||||
{
|
||||
template<typename T>
|
||||
static Proxy_Function go(T t)
|
||||
template<>
|
||||
struct Fun_Helper<false, true>
|
||||
{
|
||||
return Proxy_Function(
|
||||
new Proxy_Function_Impl<
|
||||
template<typename T>
|
||||
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> (
|
||||
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))));
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<>
|
||||
struct Fun_Helper<true, false>
|
||||
{
|
||||
template<typename T, typename Class>
|
||||
static Proxy_Function go(T Class::* m)
|
||||
{
|
||||
return Proxy_Function(new Attribute_Access<T, Class>(m));
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Fun_Helper<true, false>
|
||||
{
|
||||
template<typename T, typename Class>
|
||||
static Proxy_Function go(T Class::* m)
|
||||
{
|
||||
return Proxy_Function(new Attribute_Access<T, Class>(m));
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
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>
|
||||
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>
|
||||
|
@ -99,7 +99,7 @@ namespace chaiscript
|
||||
return to_string();
|
||||
}
|
||||
|
||||
virtual Boxed_Value eval(Dispatch_Engine &) {
|
||||
virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &) {
|
||||
Boxed_Value bv;
|
||||
throw std::runtime_error("Undispatched ast_node (internal error)");
|
||||
}
|
||||
|
@ -235,7 +235,7 @@ namespace chaiscript
|
||||
std::vector<std::string> m_modulepaths;
|
||||
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
|
||||
*/
|
||||
Dispatch_Engine &get_eval_engine() {
|
||||
chaiscript::detail::Dispatch_Engine &get_eval_engine() {
|
||||
return m_engine;
|
||||
}
|
||||
|
||||
@ -335,13 +335,13 @@ namespace chaiscript
|
||||
|
||||
add(Bootstrap::bootstrap());
|
||||
|
||||
m_engine.add(fun(&Dispatch_Engine::dump_system, boost::ref(m_engine)), "dump_system");
|
||||
m_engine.add(fun(&Dispatch_Engine::dump_object, boost::ref(m_engine)), "dump_object");
|
||||
m_engine.add(fun(&Dispatch_Engine::is_type, boost::ref(m_engine)), "is_type");
|
||||
m_engine.add(fun(&Dispatch_Engine::type_name, boost::ref(m_engine)), "type_name");
|
||||
m_engine.add(fun(&Dispatch_Engine::function_exists, boost::ref(m_engine)), "function_exists");
|
||||
m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::dump_system, boost::ref(m_engine)), "dump_system");
|
||||
m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::dump_object, boost::ref(m_engine)), "dump_object");
|
||||
m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::is_type, boost::ref(m_engine)), "is_type");
|
||||
m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::type_name, boost::ref(m_engine)), "type_name");
|
||||
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&);
|
||||
@ -392,7 +392,7 @@ namespace chaiscript
|
||||
struct State
|
||||
{
|
||||
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;
|
||||
};
|
||||
|
||||
@ -532,7 +532,7 @@ namespace chaiscript
|
||||
template<typename FunctionType>
|
||||
boost::function<FunctionType> functor(const std::string &t_script)
|
||||
{
|
||||
return chaiscript::functor<FunctionType>(eval(t_script));
|
||||
return chaiscript::dispatch::functor<FunctionType>(eval(t_script));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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) :
|
||||
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 Boxed_Value eval(Dispatch_Engine &t_ss){
|
||||
virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
|
||||
Boxed_Value retval;
|
||||
|
||||
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) :
|
||||
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 Boxed_Value eval(Dispatch_Engine &){
|
||||
virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &){
|
||||
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) :
|
||||
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 Boxed_Value eval(Dispatch_Engine &){
|
||||
virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &){
|
||||
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) :
|
||||
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 Boxed_Value eval(Dispatch_Engine &t_ss){
|
||||
virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
|
||||
if (this->text == "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) :
|
||||
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 Boxed_Value eval(Dispatch_Engine &t_ss){
|
||||
Param_List_Builder plb;
|
||||
virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
|
||||
dispatch::Param_List_Builder plb;
|
||||
|
||||
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) {
|
||||
@ -178,8 +178,8 @@ namespace chaiscript
|
||||
}
|
||||
}
|
||||
|
||||
Dispatch_Engine::Stack prev_stack = t_ss.get_stack();
|
||||
Dispatch_Engine::Stack new_stack = t_ss.new_stack();
|
||||
chaiscript::detail::Dispatch_Engine::Stack prev_stack = t_ss.get_stack();
|
||||
chaiscript::detail::Dispatch_Engine::Stack new_stack = t_ss.new_stack();
|
||||
|
||||
try {
|
||||
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) :
|
||||
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 Boxed_Value eval(Dispatch_Engine &t_ss){
|
||||
Param_List_Builder plb;
|
||||
virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
|
||||
dispatch::Param_List_Builder plb;
|
||||
|
||||
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) {
|
||||
@ -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) :
|
||||
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 Boxed_Value eval(Dispatch_Engine &t_ss){
|
||||
virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
|
||||
Boxed_Value retval;
|
||||
try {
|
||||
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) :
|
||||
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 Boxed_Value eval(Dispatch_Engine &t_ss){
|
||||
virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
|
||||
try {
|
||||
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) :
|
||||
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 Boxed_Value eval(Dispatch_Engine &t_ss){
|
||||
virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
|
||||
Boxed_Value retval;
|
||||
|
||||
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) :
|
||||
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 Boxed_Value eval(Dispatch_Engine &t_ss){
|
||||
virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
|
||||
Boxed_Value retval;
|
||||
try {
|
||||
retval = this->children[0]->eval(t_ss);
|
||||
@ -439,7 +439,7 @@ namespace chaiscript
|
||||
|
||||
if (this->children.size() > 1) {
|
||||
for (size_t i = 2; i < this->children.size(); i+=2) {
|
||||
Param_List_Builder plb;
|
||||
dispatch::Param_List_Builder plb;
|
||||
plb << retval;
|
||||
|
||||
if (this->children[i]->children.size() > 1) {
|
||||
@ -462,8 +462,8 @@ namespace chaiscript
|
||||
fun_name = this->children[i]->text;
|
||||
}
|
||||
|
||||
Dispatch_Engine::Stack prev_stack = t_ss.get_stack();
|
||||
Dispatch_Engine::Stack new_stack = t_ss.new_stack();
|
||||
chaiscript::detail::Dispatch_Engine::Stack prev_stack = t_ss.get_stack();
|
||||
chaiscript::detail::Dispatch_Engine::Stack new_stack = t_ss.new_stack();
|
||||
|
||||
try {
|
||||
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) :
|
||||
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 Boxed_Value eval(Dispatch_Engine &){
|
||||
virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &){
|
||||
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) :
|
||||
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 Boxed_Value eval(Dispatch_Engine &){
|
||||
virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &){
|
||||
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) :
|
||||
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 Boxed_Value eval(Dispatch_Engine &t_ss){
|
||||
virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
|
||||
std::vector<std::string> t_param_names;
|
||||
size_t numparams = 0;
|
||||
|
||||
@ -550,8 +550,8 @@ namespace chaiscript
|
||||
numparams = 0;
|
||||
}
|
||||
|
||||
return Boxed_Value(Proxy_Function(new Dynamic_Proxy_Function
|
||||
(boost::bind(&eval_function<Dispatch_Engine>, boost::ref(t_ss), this->children.back(), t_param_names, _1),
|
||||
return Boxed_Value(Proxy_Function(new dispatch::Dynamic_Proxy_Function
|
||||
(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())));
|
||||
}
|
||||
|
||||
@ -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) :
|
||||
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 Boxed_Value eval(Dispatch_Engine &t_ss){
|
||||
virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
|
||||
size_t num_children = this->children.size();
|
||||
|
||||
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) :
|
||||
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 Boxed_Value eval(Dispatch_Engine &t_ss){
|
||||
virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
|
||||
std::vector<std::string> t_param_names;
|
||||
size_t numparams = 0;
|
||||
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) {
|
||||
guard = boost::shared_ptr<Dynamic_Proxy_Function>
|
||||
(new Dynamic_Proxy_Function(boost::bind(&eval_function<Dispatch_Engine>,
|
||||
guard = boost::shared_ptr<dispatch::Dynamic_Proxy_Function>
|
||||
(new dispatch::Dynamic_Proxy_Function(boost::bind(&eval_function<chaiscript::detail::Dispatch_Engine>,
|
||||
boost::ref(t_ss), 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_annotation = this->annotation?this->annotation->text:"";
|
||||
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(),
|
||||
t_param_names, _1), static_cast<int>(numparams), this->children.back(),
|
||||
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) :
|
||||
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 Boxed_Value eval(Dispatch_Engine &t_ss){
|
||||
virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
|
||||
bool cond;
|
||||
|
||||
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) :
|
||||
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 Boxed_Value eval(Dispatch_Engine &t_ss){
|
||||
virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
|
||||
bool cond;
|
||||
try {
|
||||
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) :
|
||||
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 Boxed_Value eval(Dispatch_Engine &t_ss){
|
||||
virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
|
||||
bool cond;
|
||||
|
||||
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) :
|
||||
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 Boxed_Value eval(Dispatch_Engine &t_ss){
|
||||
virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
|
||||
std::vector<Boxed_Value> vec;
|
||||
if (this->children.size() > 0) {
|
||||
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) :
|
||||
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 Boxed_Value eval(Dispatch_Engine &t_ss){
|
||||
virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
|
||||
try {
|
||||
std::map<std::string, Boxed_Value> retval;
|
||||
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) :
|
||||
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 Boxed_Value eval(Dispatch_Engine &t_ss){
|
||||
virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
|
||||
if (this->children.size() > 0) {
|
||||
try {
|
||||
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) :
|
||||
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 Boxed_Value eval(Dispatch_Engine &t_ss) {
|
||||
virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss) {
|
||||
const size_t size = this->children.size();
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
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) :
|
||||
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 Boxed_Value eval(Dispatch_Engine &t_ss){
|
||||
virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
|
||||
try {
|
||||
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) :
|
||||
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 Boxed_Value eval(Dispatch_Engine &){
|
||||
virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &){
|
||||
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) :
|
||||
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 Boxed_Value eval(Dispatch_Engine &t_ss){
|
||||
virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
|
||||
try {
|
||||
return t_ss.call_function("generate_range",
|
||||
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) :
|
||||
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 Boxed_Value eval(Dispatch_Engine &t_ss){
|
||||
virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
|
||||
Boxed_Value retval;
|
||||
|
||||
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) :
|
||||
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 Boxed_Value eval(Dispatch_Engine &t_ss){
|
||||
virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
|
||||
|
||||
std::vector<std::string> t_param_names;
|
||||
AST_NodePtr guardnode;
|
||||
@ -1327,10 +1327,10 @@ namespace chaiscript
|
||||
|
||||
size_t numparams = t_param_names.size();
|
||||
|
||||
boost::shared_ptr<Dynamic_Proxy_Function> guard;
|
||||
boost::shared_ptr<dispatch::Dynamic_Proxy_Function> guard;
|
||||
if (guardnode) {
|
||||
guard = boost::shared_ptr<Dynamic_Proxy_Function>
|
||||
(new Dynamic_Proxy_Function(boost::bind(&eval_function<Dispatch_Engine>,
|
||||
guard = boost::shared_ptr<dispatch::Dynamic_Proxy_Function>
|
||||
(new dispatch::Dynamic_Proxy_Function(boost::bind(&eval_function<chaiscript::detail::Dispatch_Engine>,
|
||||
boost::ref(t_ss), 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;
|
||||
if (function_name == class_name) {
|
||||
t_ss.add(Proxy_Function
|
||||
(new detail::Dynamic_Object_Constructor(class_name, Proxy_Function
|
||||
(new Dynamic_Proxy_Function(boost::bind(&eval_function<Dispatch_Engine>,
|
||||
(new dispatch::detail::Dynamic_Object_Constructor(class_name, Proxy_Function
|
||||
(new dispatch::Dynamic_Proxy_Function(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(),
|
||||
l_annotation, guard)))), function_name);
|
||||
@ -1356,8 +1356,8 @@ namespace chaiscript
|
||||
// No biggie, the type name is just not known
|
||||
}
|
||||
t_ss.add(Proxy_Function
|
||||
(new detail::Dynamic_Object_Function(class_name, Proxy_Function
|
||||
(new Dynamic_Proxy_Function(boost::bind(&eval_function<Dispatch_Engine>,
|
||||
(new dispatch::detail::Dynamic_Object_Function(class_name, Proxy_Function
|
||||
(new dispatch::Dynamic_Proxy_Function(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(),
|
||||
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) :
|
||||
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 Boxed_Value eval(Dispatch_Engine &t_ss){
|
||||
virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
|
||||
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);
|
||||
|
||||
}
|
||||
@ -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) :
|
||||
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 Boxed_Value eval(Dispatch_Engine &t_ss){
|
||||
virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
|
||||
Boxed_Value retval;
|
||||
try {
|
||||
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) :
|
||||
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 Boxed_Value eval(Dispatch_Engine &t_ss){
|
||||
virtual Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_ss){
|
||||
Boxed_Value retval;
|
||||
|
||||
try {
|
||||
|
@ -45,7 +45,7 @@ struct System
|
||||
void add_callback(const std::string &t_name,
|
||||
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");
|
||||
|
||||
//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 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(chaiscript::Proxy_Function(new dispatch::detail::Dynamic_Object_Function("TestType", fun(&hello_world))), "hello_world");
|
||||
chai.add(chaiscript::Proxy_Function(new dispatch::detail::Dynamic_Object_Constructor("TestType", fun(&hello_constructor))), "TestType");
|
||||
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("x.attr = \"hi\"");
|
||||
|
@ -55,7 +55,7 @@ void version(int){
|
||||
bool throws_exception(const chaiscript::Proxy_Function &f)
|
||||
{
|
||||
try {
|
||||
chaiscript::functor<void ()>(f)();
|
||||
chaiscript::dispatch::functor<void ()>(f)();
|
||||
} catch (...) {
|
||||
return true;
|
||||
}
|
||||
|
@ -14,7 +14,8 @@
|
||||
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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->get_parse_tree())
|
||||
|
@ -19,7 +19,7 @@ int main()
|
||||
|
||||
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");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user