changed the dump format of large integers and fixed-point decimals

This commit is contained in:
hyunghwan.chung 2019-01-10 06:26:32 +00:00
parent c62a0ce3c5
commit 05a3c4eefd

View File

@ -414,30 +414,45 @@ static int print_object (moo_t* moo, moo_bitmask_t mask, moo_oop_t oop, outbfmt_
MOO_ASSERT (moo, MOO_OOP_IS_POINTER(oop));
c = (moo_oop_class_t)MOO_OBJ_GET_CLASS(oop); /*MOO_CLASSOF(moo, oop);*/
if (c == moo->_large_negative_integer)
if (c == moo->_large_negative_integer || c == moo->_large_positive_integer)
{
moo_oow_t i;
if (outbfmt(moo, mask, "-16r") <= -1) return -1;
for (i = MOO_OBJ_GET_SIZE(oop); i > 0;)
{
if (outbfmt(moo, mask, "%0*lX", (int)(MOO_SIZEOF(moo_liw_t) * 2), (unsigned long int)(MOO_OBJ_GET_LIWORD_SLOT(oop)[--i])) <= -1) return -1;
}
}
else if (c == moo->_large_positive_integer)
{
moo_oow_t i;
if (outbfmt(moo, mask, "16r") <= -1) return -1;
for (i = MOO_OBJ_GET_SIZE(oop); i > 0;)
{
if (outbfmt(moo, mask, "%0*lX", (int)(MOO_SIZEOF(moo_liw_t) * 2), (unsigned long int)(MOO_OBJ_GET_LIWORD_SLOT(oop)[--i])) <= -1) return -1;
}
if (!moo_inttostr(moo, oop, 10 | MOO_INTTOSTR_NONEWOBJ)) return -1;
if (outbfmt(moo, mask, "%.*js", moo->inttostr.xbuf.len, moo->inttostr.xbuf.ptr) <= -1) return -1;
}
else if (c == moo->_fixed_point_decimal)
{
/* TODO: change this to a proper output.... */
if (print_object(moo, mask, ((moo_oop_fpdec_t)oop)->value, outbfmt) <= -1) return -1;
if (outbfmt(moo, mask, "s") <= -1) return -1;
if (print_object(moo, mask, ((moo_oop_fpdec_t)oop)->scale, outbfmt) <= -1) return -1;
moo_ooch_t* ptr;
moo_oow_t len;
moo_ooi_t scale;
if (!moo_inttostr(moo, ((moo_oop_fpdec_t)oop)->value, 10 | MOO_INTTOSTR_NONEWOBJ)) return -1;
ptr = moo->inttostr.xbuf.ptr;
len = moo->inttostr.xbuf.len;
if (ptr[0] == '-')
{
if (outbfmt(moo, mask, "-") <= -1) return -1;
ptr++;
len--;
}
scale = MOO_OOP_TO_SMOOI(((moo_oop_fpdec_t)oop)->scale);
if (scale >= len)
{
moo_oow_t i;
if (outbfmt(moo, mask, "0.") <= -1) return -1;
for (i = len; i < scale; i++)
{
if (outbfmt(moo, mask, "0") <= -1) return -1;
}
if (outbfmt(moo, mask, "%.*js", len, ptr) <= -1) return -1;
}
else
{
if (outbfmt(moo, mask, "%.*js.%.*js", len - scale, &ptr[0], scale, &ptr[len - scale]) <= -1) return -1;
}
}
else if (MOO_OBJ_GET_FLAGS_TYPE(oop) == MOO_OBJ_TYPE_CHAR)
{