Fix multi-file compilation issues
This commit is contained in:
@@ -43,6 +43,8 @@ namespace chaiscript
|
||||
Lambda, Block, Def, While, If, For, Inline_Array, Inline_Map, Return, File, Prefix, Break, Map_Pair, Value_Range,
|
||||
Inline_Range, Annotation, Try, Catch, Finally, Method, Attr_Decl }; };
|
||||
|
||||
namespace
|
||||
{
|
||||
/**
|
||||
* Helper lookup to get the name of each node type
|
||||
*/
|
||||
@@ -54,6 +56,7 @@ namespace chaiscript
|
||||
|
||||
return token_types[tokentype];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience type for file positions
|
||||
|
@@ -483,18 +483,6 @@ namespace chaiscript
|
||||
return boost::lexical_cast<std::string>(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Boolean specialization of internal to_string function
|
||||
*/
|
||||
template<> std::string to_string(bool b)
|
||||
{
|
||||
if (b)
|
||||
{
|
||||
return "true";
|
||||
} else {
|
||||
return "false";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal function for converting from a string to a value
|
||||
@@ -540,12 +528,12 @@ namespace chaiscript
|
||||
|
||||
/**
|
||||
* Specific version of shared_ptr_clone just for Proxy_Functions
|
||||
* probably not necessary, probably could just use the version above,
|
||||
* but here we are.
|
||||
*/
|
||||
Proxy_Function proxy_function_clone(const Const_Proxy_Function &f)
|
||||
template<typename Type>
|
||||
boost::shared_ptr<typename boost::remove_const<Type>::type>
|
||||
shared_ptr_unconst_clone(const boost::shared_ptr<typename boost::add_const<Type>::type> &p)
|
||||
{
|
||||
return boost::const_pointer_cast<Proxy_Function_Base>(f);
|
||||
return boost::const_pointer_cast<typename boost::remove_const<Type>::type>(p);
|
||||
}
|
||||
|
||||
|
||||
@@ -671,6 +659,19 @@ namespace chaiscript
|
||||
return e.what();
|
||||
}
|
||||
|
||||
/**
|
||||
* Boolean specialization of internal to_string function
|
||||
*/
|
||||
static std::string bool_to_string(bool b)
|
||||
{
|
||||
if (b)
|
||||
{
|
||||
return "true";
|
||||
} else {
|
||||
return "false";
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
/**
|
||||
* perform all common bootstrap functions for std::string, void and POD types
|
||||
@@ -701,7 +702,7 @@ namespace chaiscript
|
||||
oper_assign<bool>(m);
|
||||
|
||||
m->add(fun(&to_string<const std::string &>), "internal_to_string");
|
||||
m->add(fun(&to_string<bool>), "internal_to_string");
|
||||
m->add(fun(&Bootstrap::bool_to_string), "internal_to_string");
|
||||
m->add(fun(&unknown_assign), "=");
|
||||
m->add(fun(&throw_exception), "throw");
|
||||
m->add(fun(&what), "what");
|
||||
@@ -723,7 +724,7 @@ namespace chaiscript
|
||||
m->add(Proxy_Function(new Dynamic_Proxy_Function(boost::bind(&bind_function, _1))),
|
||||
"bind");
|
||||
|
||||
m->add(fun(&proxy_function_clone), "clone");
|
||||
m->add(fun(&shared_ptr_unconst_clone<Proxy_Function_Base>), "clone");
|
||||
m->add(fun(&ptr_assign<Proxy_Function_Base>), "=");
|
||||
|
||||
m->add(Proxy_Function(new Dynamic_Proxy_Function(boost::bind(&call_exists, _1))),
|
||||
|
@@ -495,6 +495,100 @@ namespace chaiscript
|
||||
return dispatch(range.first, range.second, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump object info to stdout
|
||||
*/
|
||||
void dump_object(Boxed_Value o) const
|
||||
{
|
||||
Type_Info ti = o.get_type_info();
|
||||
std::cout << (ti.is_const()?"const ":"") << get_type_name(ti) << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump type info to stdout
|
||||
*/
|
||||
void dump_type(const Type_Info &type) const
|
||||
{
|
||||
std::cout << (type.is_const()?"const ":"") << get_type_name(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump function to stdout
|
||||
*/
|
||||
void dump_function(const std::pair<const std::string, Proxy_Function > &f) const
|
||||
{
|
||||
std::vector<Type_Info> params = f.second->get_param_types();
|
||||
std::string annotation = f.second->annotation();
|
||||
|
||||
if (annotation.size() > 0) {
|
||||
std::cout << annotation;
|
||||
}
|
||||
dump_type(params.front());
|
||||
std::cout << " " << f.first << "(";
|
||||
|
||||
for (std::vector<Type_Info>::const_iterator itr = params.begin() + 1;
|
||||
itr != params.end();
|
||||
)
|
||||
{
|
||||
dump_type(*itr);
|
||||
++itr;
|
||||
|
||||
if (itr != params.end())
|
||||
{
|
||||
std::cout << ", ";
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << ") " << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump all system info to stdout
|
||||
*/
|
||||
void dump_system() const
|
||||
{
|
||||
std::cout << "Registered Types: " << std::endl;
|
||||
std::vector<std::pair<std::string, Type_Info> > types = get_types();
|
||||
for (std::vector<std::pair<std::string, Type_Info> >::const_iterator itr = types.begin();
|
||||
itr != types.end();
|
||||
++itr)
|
||||
{
|
||||
std::cout << itr->first << ": ";
|
||||
std::cout << itr->second.bare_name();
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
std::vector<std::pair<std::string, Proxy_Function > > funcs = get_functions();
|
||||
|
||||
std::cout << "Functions: " << std::endl;
|
||||
for (std::vector<std::pair<std::string, Proxy_Function > >::const_iterator itr = funcs.begin();
|
||||
itr != funcs.end();
|
||||
++itr)
|
||||
{
|
||||
dump_function(*itr);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* return true if the Boxed_Value matches the registered type by name
|
||||
*/
|
||||
bool is_type(const std::string &user_typename, Boxed_Value r) const
|
||||
{
|
||||
try {
|
||||
return get_type(user_typename) == r.get_type_info();
|
||||
} catch (const std::range_error &) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::string type_name(Boxed_Value obj) const
|
||||
{
|
||||
return get_type_name(obj.get_type_info());
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
/**
|
||||
* Returns the current stack
|
||||
@@ -585,99 +679,6 @@ namespace chaiscript
|
||||
std::set<std::string> m_reserved_words;
|
||||
};
|
||||
|
||||
/**
|
||||
* Dump object info to stdout
|
||||
*/
|
||||
void dump_object(Boxed_Value o, const Dispatch_Engine &e)
|
||||
{
|
||||
Type_Info ti = o.get_type_info();
|
||||
std::cout << (ti.is_const()?"const ":"") << e.get_type_name(ti) << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump type info to stdout
|
||||
*/
|
||||
void dump_type(const Type_Info &type, const Dispatch_Engine &e)
|
||||
{
|
||||
std::cout << (type.is_const()?"const ":"") << e.get_type_name(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump function to stdout
|
||||
*/
|
||||
void dump_function(const std::pair<const std::string, Proxy_Function > &f, const Dispatch_Engine &e)
|
||||
{
|
||||
std::vector<Type_Info> params = f.second->get_param_types();
|
||||
std::string annotation = f.second->annotation();
|
||||
|
||||
if (annotation.size() > 0) {
|
||||
std::cout << annotation;
|
||||
}
|
||||
dump_type(params.front(), e);
|
||||
std::cout << " " << f.first << "(";
|
||||
|
||||
for (std::vector<Type_Info>::const_iterator itr = params.begin() + 1;
|
||||
itr != params.end();
|
||||
)
|
||||
{
|
||||
dump_type(*itr, e);
|
||||
++itr;
|
||||
|
||||
if (itr != params.end())
|
||||
{
|
||||
std::cout << ", ";
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << ") " << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump all system info to stdout
|
||||
*/
|
||||
void dump_system(const Dispatch_Engine &s)
|
||||
{
|
||||
std::cout << "Registered Types: " << std::endl;
|
||||
std::vector<std::pair<std::string, Type_Info> > types = s.get_types();
|
||||
for (std::vector<std::pair<std::string, Type_Info> >::const_iterator itr = types.begin();
|
||||
itr != types.end();
|
||||
++itr)
|
||||
{
|
||||
std::cout << itr->first << ": ";
|
||||
std::cout << itr->second.bare_name();
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
std::vector<std::pair<std::string, Proxy_Function > > funcs = s.get_functions();
|
||||
|
||||
std::cout << "Functions: " << std::endl;
|
||||
for (std::vector<std::pair<std::string, Proxy_Function > >::const_iterator itr = funcs.begin();
|
||||
itr != funcs.end();
|
||||
++itr)
|
||||
{
|
||||
dump_function(*itr, s);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* return true if the Boxed_Value matches the registered type by name
|
||||
*/
|
||||
bool is_type(const Dispatch_Engine &e, const std::string &user_typename, Boxed_Value r)
|
||||
{
|
||||
try {
|
||||
return e.get_type(user_typename) == r.get_type_info();
|
||||
} catch (const std::range_error &) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::string type_name(const Dispatch_Engine &e, Boxed_Value obj)
|
||||
{
|
||||
return e.get_type_name(obj.get_type_info());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -34,7 +34,9 @@ namespace chaiscript
|
||||
std::map<std::string, Boxed_Value> m_attrs;
|
||||
};
|
||||
|
||||
Boxed_Value dynamic_object_attribute(const std::string &t_type_name, const std::string &t_attr_name,
|
||||
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)
|
||||
@@ -44,27 +46,7 @@ namespace chaiscript
|
||||
|
||||
return t_do.get_attr(t_attr_name);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
try {
|
||||
const Dynamic_Object &d = boxed_cast<const Dynamic_Object &>(bvs[0]);
|
||||
return name == "Dynamic_Object" || d.get_type_name() == name;
|
||||
} catch (const std::bad_cast &) {
|
||||
if (ti)
|
||||
{
|
||||
return bvs[0].get_type_info().bare_equal(*ti);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* A Proxy_Function implementation designed for calling a function
|
||||
@@ -129,6 +111,27 @@ namespace chaiscript
|
||||
}
|
||||
|
||||
private:
|
||||
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)
|
||||
{
|
||||
try {
|
||||
const Dynamic_Object &d = boxed_cast<const Dynamic_Object &>(bvs[0]);
|
||||
return name == "Dynamic_Object" || d.get_type_name() == name;
|
||||
} catch (const std::bad_cast &) {
|
||||
if (ti)
|
||||
{
|
||||
return bvs[0].get_type_info().bare_equal(*ti);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::string m_type_name;
|
||||
Proxy_Function m_func;
|
||||
boost::optional<Type_Info> m_ti;
|
||||
|
@@ -458,7 +458,8 @@ namespace chaiscript
|
||||
* each function against the set of parameters, in order, until a matching
|
||||
* function is found or throw dispatch_error if no matching function is found
|
||||
*/
|
||||
Boxed_Value dispatch(const std::vector<std::pair<std::string, Proxy_Function> > &funcs,
|
||||
template<typename Funcs>
|
||||
Boxed_Value dispatch(const Funcs &funcs,
|
||||
const std::vector<Boxed_Value> &plist)
|
||||
{
|
||||
return dispatch(funcs.begin(), funcs.end(), plist);
|
||||
|
@@ -450,12 +450,12 @@ namespace chaiscript
|
||||
|
||||
add(Bootstrap::bootstrap());
|
||||
|
||||
engine.add(fun(boost::function<void ()>(boost::bind(&dump_system, boost::ref(engine)))), "dump_system");
|
||||
engine.add(fun(boost::function<void (Boxed_Value)>(boost::bind(&dump_object, _1, boost::ref(engine)))), "dump_object");
|
||||
engine.add(fun(boost::function<bool (Boxed_Value, const std::string &)>(boost::bind(&is_type, boost::ref(engine), _2, _1))),
|
||||
engine.add(fun(boost::function<void ()>(boost::bind(&Eval_Engine::dump_system, boost::ref(engine)))), "dump_system");
|
||||
engine.add(fun(boost::function<void (Boxed_Value)>(boost::bind(&Eval_Engine::dump_object, boost::ref(engine), _1))), "dump_object");
|
||||
engine.add(fun(boost::function<bool (Boxed_Value, const std::string &)>(boost::bind(&Eval_Engine::is_type, boost::ref(engine), _2, _1))),
|
||||
"is_type");
|
||||
|
||||
engine.add(fun(boost::function<std::string (Boxed_Value)>(boost::bind(&chaiscript::type_name, boost::ref(engine), _1))),
|
||||
engine.add(fun(boost::function<std::string (Boxed_Value)>(boost::bind(&Eval_Engine::type_name, boost::ref(engine), _1))),
|
||||
"type_name");
|
||||
engine.add(fun(boost::function<bool (const std::string &)>(boost::bind(&Eval_Engine::function_exists, boost::ref(engine), _1))),
|
||||
"function_exists");
|
||||
|
@@ -246,7 +246,7 @@ namespace chaiscript
|
||||
template <typename Eval_System>
|
||||
Boxed_Value eval_attr_decl(Eval_System &ss, const TokenPtr &node) {
|
||||
try {
|
||||
ss.add(fun(boost::function<Boxed_Value (Dynamic_Object &)>(boost::bind(&dynamic_object_attribute, node->children[0]->text,
|
||||
ss.add(fun(boost::function<Boxed_Value (Dynamic_Object &)>(boost::bind(&Dynamic_Object_Attribute::func, node->children[0]->text,
|
||||
node->children[1]->text, _1))), node->children[1]->text);
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user