dump_system() looks nice now, lots of little updates. Annotations are displayed as well, but they do not work for the prelude, I don't know why. Any attempt to add them invalidates the function definition in question. sensors.chai does work, however
This commit is contained in:
parent
a8d74cea6f
commit
90aa53bdc6
@ -9,10 +9,10 @@
|
||||
//by C++, so CODE_STRING, takes two expressions and adds in the missing comma
|
||||
#define CODE_STRING(x, y) #x ", " #y
|
||||
|
||||
#define chaiscript_prelude CODE_STRING(\
|
||||
#define chaiscript_prelude CODE_STRING( \n\n \
|
||||
def to_string(x) : call_exists(first, x) && call_exists(second, x) { \
|
||||
"<" + x.first.to_string() + ", " + x.second.to_string() + ">"; \
|
||||
} \
|
||||
} \n \n \
|
||||
def to_string(x) : call_exists(range, x) && !x.is_type("string"){ \
|
||||
"[" + x.join(", ") + "]"; \
|
||||
} \
|
||||
|
@ -532,6 +532,8 @@ namespace dispatchkit
|
||||
{
|
||||
s.register_type<void>("void");
|
||||
s.register_type<bool>("bool");
|
||||
s.register_type<Boxed_Value>("Object");
|
||||
s.register_type<Boxed_POD_Value>("PODObject");
|
||||
s.register_type<Proxy_Function>("function");
|
||||
|
||||
add_basic_constructors<bool>(s, "bool");
|
||||
@ -556,7 +558,7 @@ namespace dispatchkit
|
||||
register_function(s, &println, "println_string");
|
||||
|
||||
s.register_function(boost::function<void ()>(boost::bind(&dump_system, boost::ref(s))), "dump_system");
|
||||
s.register_function(boost::function<void (Boxed_Value)>(boost::bind(&dump_object, _1)), "dump_object");
|
||||
s.register_function(boost::function<void (Boxed_Value)>(boost::bind(&dump_object, _1, boost::ref(s))), "dump_object");
|
||||
s.register_function(boost::function<bool (Boxed_Value, const std::string &)>(boost::bind(&is_type, boost::ref(s), _2, _1)),
|
||||
"is_type");
|
||||
|
||||
|
@ -55,11 +55,19 @@ namespace dispatchkit
|
||||
template<typename ContainerType>
|
||||
void bootstrap_input_range(Dispatch_Engine &system, const std::string &type)
|
||||
{
|
||||
system.register_type<Input_Range<ContainerType> >(type+"_Range");
|
||||
system.register_type<typename ContainerType::iterator>(type+"_Iterator");
|
||||
|
||||
system.register_function(build_constructor<Input_Range<ContainerType>, ContainerType &>(), "range");
|
||||
system.register_function(build_constructor<Input_Range<ContainerType>,
|
||||
typename ContainerType::iterator>(), "range");
|
||||
|
||||
typedef std::pair<typename ContainerType::iterator, typename ContainerType::iterator> ItrPair;
|
||||
|
||||
system.register_function(build_constructor<Input_Range<ContainerType>,
|
||||
const std::pair<typename ContainerType::iterator, typename ContainerType::iterator> &>(), "range");
|
||||
const ItrPair &>(), "range");
|
||||
system.register_type<ItrPair>(type+"_Iterator_Pair");
|
||||
|
||||
|
||||
|
||||
register_function(system, &Input_Range<ContainerType>::empty, "empty");
|
||||
@ -158,6 +166,8 @@ namespace dispatchkit
|
||||
template<typename PairType>
|
||||
void bootstrap_pair(Dispatch_Engine &system, const std::string &type)
|
||||
{
|
||||
system.register_type<PairType>(type);
|
||||
|
||||
register_member(system, &PairType::first, "first");
|
||||
register_member(system, &PairType::second, "second");
|
||||
|
||||
|
@ -63,6 +63,11 @@ namespace dispatchkit
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual std::string annotation() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::pair<std::string, boost::shared_ptr<Proxy_Function> > > m_funcs;
|
||||
};
|
||||
@ -186,6 +191,21 @@ namespace dispatchkit
|
||||
}
|
||||
}
|
||||
|
||||
std::string get_type_name(const Type_Info &ti) const
|
||||
{
|
||||
for (Type_Name_Map::const_iterator itr = m_types.begin();
|
||||
itr != m_types.end();
|
||||
++itr)
|
||||
{
|
||||
if (itr->second.m_bare_type_info == ti.m_bare_type_info)
|
||||
{
|
||||
return itr->first;
|
||||
}
|
||||
}
|
||||
|
||||
return ti.m_bare_type_info->name();
|
||||
}
|
||||
|
||||
std::vector<Type_Name_Map::value_type> get_types() const
|
||||
{
|
||||
return std::vector<Type_Name_Map::value_type>(m_types.begin(), m_types.end());
|
||||
@ -253,32 +273,38 @@ namespace dispatchkit
|
||||
Boxed_Value m_place_holder;
|
||||
};
|
||||
|
||||
void dump_object(Boxed_Value o)
|
||||
void dump_object(Boxed_Value o, const Dispatch_Engine &e)
|
||||
{
|
||||
std::cout << o.get_type_info().m_type_info->name() << std::endl;
|
||||
std::cout << e.get_type_name(o.get_type_info()) << std::endl;
|
||||
}
|
||||
|
||||
void dump_type(const Type_Info &type)
|
||||
void dump_type(const Type_Info &type, const Dispatch_Engine &e)
|
||||
{
|
||||
std::cout << type.m_bare_type_info->name();
|
||||
std::cout << e.get_type_name(type);
|
||||
}
|
||||
|
||||
void dump_function(const Dispatch_Engine::Function_Map::value_type &f)
|
||||
void dump_function(const Dispatch_Engine::Function_Map::value_type &f, const Dispatch_Engine &e)
|
||||
{
|
||||
std::vector<Type_Info> params = f.second->get_param_types();
|
||||
|
||||
dump_type(params.front());
|
||||
dump_type(params.front(), e);
|
||||
std::cout << " " << f.first << "(";
|
||||
|
||||
for (std::vector<Type_Info>::const_iterator itr = params.begin() + 1;
|
||||
itr != params.end();
|
||||
++itr)
|
||||
)
|
||||
{
|
||||
dump_type(*itr);
|
||||
std::cout << ", ";
|
||||
dump_type(*itr, e);
|
||||
++itr;
|
||||
|
||||
if (itr != params.end())
|
||||
{
|
||||
std::cout << ", ";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::cout << ")" << std::endl;
|
||||
std::cout << ") " << f.second->annotation() << std::endl;
|
||||
}
|
||||
|
||||
void dump_system(const Dispatch_Engine &s)
|
||||
@ -290,7 +316,7 @@ namespace dispatchkit
|
||||
++itr)
|
||||
{
|
||||
std::cout << itr->first << ": ";
|
||||
dump_type(itr->second);
|
||||
std::cout << itr->second.m_bare_type_info->name();
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
@ -302,7 +328,7 @@ namespace dispatchkit
|
||||
itr != funcs.end();
|
||||
++itr)
|
||||
{
|
||||
dump_function(*itr);
|
||||
dump_function(*itr, s);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
@ -122,6 +122,7 @@ namespace dispatchkit
|
||||
virtual std::vector<Type_Info> get_param_types() const = 0;
|
||||
virtual bool operator==(const Proxy_Function &) const = 0;
|
||||
virtual bool types_match(const std::vector<Boxed_Value> &types) const = 0;
|
||||
virtual std::string annotation() const = 0;
|
||||
};
|
||||
|
||||
class guard_error : public std::runtime_error
|
||||
@ -179,7 +180,26 @@ namespace dispatchkit
|
||||
|
||||
virtual std::vector<Type_Info> get_param_types() const
|
||||
{
|
||||
return build_param_type_list(m_f);
|
||||
std::vector<Type_Info> types;
|
||||
|
||||
types.push_back(Get_Type_Info<Boxed_Value>::get());
|
||||
|
||||
if (m_arity >= 0)
|
||||
{
|
||||
for (int i = 0; i < m_arity; ++i)
|
||||
{
|
||||
types.push_back(Get_Type_Info<Boxed_Value>::get());
|
||||
}
|
||||
} else {
|
||||
types.push_back(Get_Type_Info<std::vector<Boxed_Value> >::get());
|
||||
}
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
virtual std::string annotation() const
|
||||
{
|
||||
return m_description;
|
||||
}
|
||||
|
||||
private:
|
||||
@ -280,6 +300,12 @@ namespace dispatchkit
|
||||
return std::vector<Type_Info>();
|
||||
}
|
||||
|
||||
virtual std::string annotation() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
boost::shared_ptr<Proxy_Function> m_f;
|
||||
std::vector<Boxed_Value> m_args;
|
||||
@ -321,6 +347,12 @@ namespace dispatchkit
|
||||
return compare_types(m_f, types);
|
||||
}
|
||||
|
||||
virtual std::string annotation() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
Func m_f;
|
||||
};
|
||||
|
@ -56,6 +56,8 @@ def update_state(state)
|
||||
update_cpu_state(state, file, "cpu1");
|
||||
}
|
||||
|
||||
dump_system()
|
||||
|
||||
var global_state = Map()
|
||||
|
||||
initialize_cpu_sensor(global_state, "cpu", sensor_manager);
|
||||
|
Loading…
x
Reference in New Issue
Block a user