ostream& operator<< (ostream& out, const item& i)
{
if (i.empty())
return out << "empty";
if (isdefault(i))
return out << "default";
#if COMPACT
// TODO: Try to guess the type from the value.
Int n = get<Int>(i);
double x = get<double>(i);
void *p = get<void *>(i);
if (n == BoolTruthValue)
return out << "true";
if (n == BoolFalseValue)
return out << "false";
if (std::abs(n) < 1000000)
return out << n;
if (fabs(x) < 1e30 and fabs(x) > 1e-30)
return out << x;
return out << "<item " << p << ">";
#else
// TODO: Make a data structure mapping typeids to print functions.
else if (i.type() == typeid(Int))
out << "Int, value = " << get<Int>(i);
else if (i.type() == typeid(double))
out << "real, value = " << get<double>(i);
else if (i.type() == typeid(string))
out << "string, value = " << get<string>(i);
else if (i.type() == typeid(callable))
out << *(get<callable *>(i));
else if (i.type() == typeid(vmFrame)) {
out << "frame";
# ifdef DEBUG_FRAME
{
vmFrame *f = get<vmFrame *>(i);
if (f)
out << " " << f->getName();
else
out << " <null>";
}
# endif
}
else
out << "type " << demangle(i.type().name());
#endif