scmno****@osdn*****
scmno****@osdn*****
Fri Feb 9 05:33:02 JST 2018
changeset 9ffd83cfe025 in quipu/quipu details: http://hg.osdn.jp/view/quipu/quipu?cmd=changeset;node=9ffd83cfe025 user: Agustina Arzille <avarz****@riseu*****> date: Thu Feb 08 17:32:47 2018 -0300 description: Refactor of several files diffstat: arith.h | 3 +- array.cpp | 17 ++-- cons.cpp | 1 + floatp.cpp | 8 +- integer.cpp | 191 +++++++++++++++++++++++++++-------------------------------- io.cpp | 10 +-- table.cpp | 12 +- tree.cpp | 65 ++++++++++---------- 8 files changed, 145 insertions(+), 162 deletions(-) diffs (truncated from 667 to 300 lines): diff -r 4016b4f5f428 -r 9ffd83cfe025 arith.h --- a/arith.h Wed Feb 07 17:55:02 2018 -0300 +++ b/arith.h Thu Feb 08 17:32:47 2018 -0300 @@ -157,8 +157,9 @@ QP_EXPORT int lfrounds (char *__dst, int __len, int __base, int *__expp); -struct num_info +class num_info { +public: int type; int sign; int base; diff -r 4016b4f5f428 -r 9ffd83cfe025 array.cpp --- a/array.cpp Wed Feb 07 17:55:02 2018 -0300 +++ b/array.cpp Thu Feb 08 17:32:47 2018 -0300 @@ -73,7 +73,7 @@ } static inline object* -array_ref (interpreter *interp, object ax, object iv) +array_ref (interpreter *interp, object ax, object iv, const char *caller) { if (qp_unlikely (!int_p (iv))) interp->raise2 ("type-error", "get:array: index is not an integer"); @@ -81,7 +81,7 @@ array *ap = as_array (ax); int idx = get_idx (ap, as_int (iv)); if (qp_unlikely (idx < 0 || idx >= ap->len)) - interp->raise_oob ("get:array", idx, ap->len); + interp->raise_oob (caller, idx, ap->len); return (&ap->data[idx]); } @@ -91,8 +91,10 @@ { if (qp_unlikely (dfl != UNBOUND)) interp->raise_nargs ("get:array", 2, 2, 3); + else if (!int_p (iv)) + interp->raise2 ("type-error", "get:array: index is not an integer"); - qp_return (*array_ref (interp, ax, iv)); + qp_return (*array_ref (interp, ax, iv, "get:array")); } object nput_a (interpreter *interp, object ax, @@ -100,8 +102,10 @@ { if (qp_unlikely (as_varobj(ax)->flags & FLAGS_CONST)) interp->raise_const ("nput:array"); + else if (!int_p (iv)) + interp->raise2 ("type-error", "nput:array: index is not an integer"); - qp_return (*array_ref(interp, ax, iv) = val); + qp_return (*array_ref(interp, ax, iv, "nput:array") = val); } object subseq_a (interpreter *interp, @@ -152,10 +156,7 @@ object *objp = interp->push (intobj (0)); for (int i = 0; i < as_array(obj)->len; ++i) - { - *objp = xaref (obj, i); - ret = mix_hash (ret, xhash (interp, *objp)); - } + ret = mix_hash (ret, xhash (interp, *objp = xaref (obj, i))); interp->popn (); return (ret); diff -r 4016b4f5f428 -r 9ffd83cfe025 cons.cpp --- a/cons.cpp Wed Feb 07 17:55:02 2018 -0300 +++ b/cons.cpp Thu Feb 08 17:32:47 2018 -0300 @@ -143,6 +143,7 @@ if (!xcons_p (*pt = xcdr (*pt))) { ret = mix_hash (ret, xhash (interp, *pt)); + ret = mix_hash (ret, CONS_HASH_SEED); break; } } diff -r 4016b4f5f428 -r 9ffd83cfe025 floatp.cpp --- a/floatp.cpp Wed Feb 07 17:55:02 2018 -0300 +++ b/floatp.cpp Thu Feb 08 17:32:47 2018 -0300 @@ -133,7 +133,7 @@ } #ifdef QP_ARCH_WIDE -# define QP_LFLT(ptr, sign) \ +# define make_bigfloat(ptr, sign) \ ptrtype ((ptr), typecode::BIGFLOAT) | (sign ? SIGN_BIT : 0) # define F_ABS(val) val @@ -147,7 +147,7 @@ } static inline object -QP_LFLT (bigfloat *fp, int sign) +make_bigfloat (bigfloat *fp, int sign) { if (sign) fp->len = -fp->len; @@ -199,7 +199,7 @@ tx.flags = ty.flags = 0; \ \ return (alt##_FF (interp, \ - QP_LFLT (&tx, s1), QP_LFLT (&ty, s2))); \ + make_bigfloat (&tx, s1), make_bigfloat (&ty, s2))); \ } \ \ qp_return (fltobj (interp, ret)) @@ -435,7 +435,7 @@ } else do_bigfloat: - interp->retval = QP_LFLT (src, sign); + interp->retval = make_bigfloat (src, sign); gcregister (interp, src); return (interp->retval); diff -r 4016b4f5f428 -r 9ffd83cfe025 integer.cpp --- a/integer.cpp Wed Feb 07 17:55:02 2018 -0300 +++ b/integer.cpp Thu Feb 08 17:32:47 2018 -0300 @@ -518,39 +518,36 @@ qp_return (ret_I (interp, ret, 0)); } } - else - { - if (s2 != 0) - { // -X & -Y == ((X - 1) | (Y - 1)). - limb_t *xp = (limb_t *)QP_TALLOC (interp, (xl + yl) * sizeof (*xp)); - limb_t *yp = xp + xl; - if (xl > yl) - { - swap (xp, yp); - swap (xl, yl); - } - - uisub1 (xp, v1->data, xl, 1); - uisub1 (yp, v2->data, yl, 1); - - ret = bigint::alloc_raw (yl + 1); - ret->len = yl; - memcpy (ret->data + xl, yp + xl, (yl - xl) * sizeof (limb_t)); - - for (i = 0; i < xl; ++i) - ret->data[i] = xp[i] | yp[i]; - - limb_t cy = uiadd1 (ret->data, ret->data, ret->len, 1); - ret->data[ret->len] = cy; - ret->len += cy != 0; - - qp_return (ret_I (interp, ret, 1)); - } - else - { // Compute -X & Y. - swap (v1, v2); + else if (s2 != 0) + { // -X & -Y == ((X - 1) | (Y - 1)). + limb_t *xp = (limb_t *)QP_TALLOC (interp, (xl + yl) * sizeof (*xp)); + limb_t *yp = xp + xl; + if (xl > yl) + { + swap (xp, yp); swap (xl, yl); } + + uisub1 (xp, v1->data, xl, 1); + uisub1 (yp, v2->data, yl, 1); + + ret = bigint::alloc_raw (yl + 1); + ret->len = yl; + memcpy (ret->data + xl, yp + xl, (yl - xl) * sizeof (limb_t)); + + for (i = 0; i < xl; ++i) + ret->data[i] = xp[i] | yp[i]; + + limb_t cy = uiadd1 (ret->data, ret->data, ret->len, 1); + ret->data[ret->len] = cy; + ret->len += cy != 0; + + qp_return (ret_I (interp, ret, 1)); + } + else + { // Compute -X & Y. + swap (v1, v2); + swap (xl, yl); } // At this point Y is negative and 1-extended. X is positive. @@ -613,35 +610,32 @@ qp_return (ret_I (interp, ret, 0)); } } + else if (s2 != 0) + { // -X | -Y == ((X - 1) & (Y - 1)). + len = min (xl, yl); + limb_t *xp = (limb_t *)QP_TALLOC (interp, len * 2 * sizeof (*xp)); + limb_t *yp = xp + len; + + uisub1 (xp, v1->data, len, 1); + uisub1 (yp, v2->data, len, 1); + for (i = len - 1; i >= 0; --i) + if ((xp[i] & yp[i]) != 0) + break; + + if (i < 0) + return (intobj (1)); + + ret = bigint::alloc_raw (len = i + 1); + uiaddn (ret->data, xp, yp, len); + ret->data[ret->len = len] = 0; + uiadd1 (ret->data, ret->data, ret->len + 1, 1); + ret->len += ret->data[ret->len]; + qp_return (ret_I (interp, ret, 1)); + } else { - if (s2 != 0) - { // -X | -Y == ((X - 1) & (Y - 1)). - len = min (xl, yl); - limb_t *xp = (limb_t *)QP_TALLOC (interp, len * 2 * sizeof (*xp)); - limb_t *yp = xp + len; - - uisub1 (xp, v1->data, len, 1); - uisub1 (yp, v2->data, len, 1); - for (i = len - 1; i >= 0; --i) - if ((xp[i] & yp[i]) != 0) - break; - - if (i < 0) - return (intobj (1)); - - ret = bigint::alloc_raw (len = i + 1); - uiaddn (ret->data, xp, yp, len); - ret->data[ret->len = len] = 0; - uiadd1 (ret->data, ret->data, ret->len + 1, 1); - ret->len += ret->data[ret->len]; - qp_return (ret_I (interp, ret, 1)); - } - else - { - swap (v1, v2); - swap (xl, yl); - } + swap (v1, v2); + swap (xl, yl); } limb_t *xp = (limb_t *)QP_TALLOC (interp, yl * sizeof (*xp)); @@ -709,36 +703,33 @@ ret->len = xl; } } + else if (s2 != 0) + { + limb_t *xp = (limb_t *)QP_TALLOC (interp, (xl + yl) * sizeof (*xp)); + limb_t *yp = xp + xl; + + uisub1 (xp, v1->data, xl, 1); + uisub1 (yp, v2->data, yl, 1); + + if (xl > yl) + { + swap (xl, yl); + swap (xp, yp); + } + + ret = bigint::alloc_raw (yl); + memcpy (ret->data + xl, yp + xl, (yl - xl) * sizeof (limb_t)); + for (i = 0; i < xl; ++i) + ret->data[i] = xp[i] ^ yp[i]; + + ret->len = yl; + uitrim (ret->data, ret->len); + qp_return (ret_I (interp, ret, 0)); + } else { - if (s2 != 0) - { - limb_t *xp = (limb_t *)QP_TALLOC (interp, (xl + yl) * sizeof (*xp)); - limb_t *yp = xp + xl; - - uisub1 (xp, v1->data, xl, 1); - uisub1 (yp, v2->data, yl, 1); - - if (xl > yl) - { - swap (xl, yl); - swap (xp, yp); - } - - ret = bigint::alloc_raw (yl); - memcpy (ret->data + xl, yp + xl, (yl - xl) * sizeof (limb_t)); - for (i = 0; i < xl; ++i) - ret->data[i] = xp[i] ^ yp[i]; -