diff --git a/lib/bigint.c b/lib/bigint.c index 107edda..4b731c1 100644 --- a/lib/bigint.c +++ b/lib/bigint.c @@ -36,7 +36,7 @@ * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL @@ -53,25 +53,25 @@ * Author: Paulo César Pereira de Andrade */ -/* - * Copyright 1994 - 1996 LongView Technologies L.L.C. $Revision: 1.5 $ +/* + * Copyright 1994 - 1996 LongView Technologies L.L.C. $Revision: 1.5 $ * Copyright (c) 2006, Sun Microsystems, Inc. All rights reserved. -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Sun Microsystems nor the names of its contributors may be used to endorse or promote products derived + * Neither the name of Sun Microsystems nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT -NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT +NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE */ @@ -98,7 +98,7 @@ static char* _digitc_array[] = }; /* exponent table for pow2 between 1 and 32 inclusive. */ -static moo_uint8_t _exp_tab[32] = +static moo_uint8_t _exp_tab[32] = { 0, 1, 0, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 4, @@ -106,15 +106,15 @@ static moo_uint8_t _exp_tab[32] = 0, 0, 0, 0, 0, 0, 0, 5 }; -static const moo_uint8_t debruijn_32[32] = +static const moo_uint8_t debruijn_32[32] = { 0, 1, 28, 2, 29, 14, 24, 3, - 30, 22, 20, 15, 25, 17, 4, 8, + 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9 }; -static const moo_uint8_t debruijn_64[64] = +static const moo_uint8_t debruijn_64[64] = { 0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28, @@ -213,11 +213,11 @@ static MOO_INLINE int smooi_mul_overflow (moo_t* moo, moo_ooi_t a, moo_ooi_t b, ub = (b >= 0)? b: -b; ua = (a >= 0)? a: -a; - /* though this fomula basically works for unsigned types in principle, + /* though this fomula basically works for unsigned types in principle, * the values used here are all absolute values and they fall in * a safe range to apply this fomula. the safe range is guaranteed because * the sources are supposed to be smoois. */ - return ub != 0 && ua > MOO_TYPE_MAX(moo_ooi_t) / ub; + return ub != 0 && ua > MOO_TYPE_MAX(moo_ooi_t) / ub; #endif } #endif @@ -304,6 +304,11 @@ static MOO_INLINE int bigint_to_oow_noseterr (moo_t* moo, moo_oop_t num, moo_oow *w = MAKE_WORD(MOO_OBJ_GET_HALFWORD_VAL(num, 0), MOO_OBJ_GET_HALFWORD_VAL(num, 1)); return (MOO_POINTER_IS_NBIGINT(moo, num))? -1: 1; } + if (MOO_OBJ_GET_SIZE(num) == 1) + { + *w = MOO_OBJ_GET_HALFWORD_VAL(num, 0); + return (MOO_POINTER_IS_NBIGINT(moo, num))? -1: 1; + } #else # error UNSUPPORTED LIW BIT SIZE #endif @@ -313,7 +318,7 @@ static MOO_INLINE int bigint_to_oow_noseterr (moo_t* moo, moo_oop_t num, moo_oow static MOO_INLINE int integer_to_oow_noseterr (moo_t* moo, moo_oop_t x, moo_oow_t* w) { - /* return value + /* return value * 1 - a positive number including 0 that can fit into moo_oow_t * -1 - a negative number whose absolute value can fit into moo_oow_t * 0 - number too large or too small @@ -360,7 +365,7 @@ int moo_inttooow_noseterr (moo_t* moo, moo_oop_t x, moo_oow_t* w) } /* 0 -> too big, too small, or not an integer */ - return moo_isbigint(moo, x)? bigint_to_oow_noseterr(moo, x, w): 0; + return moo_isbigint(moo, x)? bigint_to_oow_noseterr(moo, x, w): 0; } int moo_inttooow (moo_t* moo, moo_oop_t x, moo_oow_t* w) @@ -413,7 +418,7 @@ int moo_inttoooi_noseterr (moo_t* moo, moo_oop_t x, moo_ooi_t* i) { MOO_STATIC_ASSERT (MOO_TYPE_MAX(moo_ooi_t) + MOO_TYPE_MIN(moo_ooi_t) == -1); /* assume 2's complement */ if (w > (moo_oow_t)MOO_TYPE_MAX(moo_ooi_t) + 1) return 0; /* too small */ - *i = -w; /* negate back */ + *i = (w <= (moo_oow_t)MOO_TYPE_MAX(moo_ooi_t))? -(moo_ooi_t)w: MOO_TYPE_MIN(moo_ooi_t); /* negate back */ } else if (n > 0) { @@ -449,11 +454,11 @@ int moo_inttoooi (moo_t* moo, moo_oop_t x, moo_ooi_t* i) moo_seterrnum (moo, MOO_ERANGE); return 0; /* too small */ } - *i = -w; /* negate back */ + *i = (w <= (moo_oow_t)MOO_TYPE_MAX(moo_ooi_t))? -(moo_ooi_t)w: MOO_TYPE_MIN(moo_ooi_t); /* negate back */ } else if (n > 0) { - if (w > MOO_TYPE_MAX(moo_ooi_t)) + if (w > MOO_TYPE_MAX(moo_ooi_t)) { moo_seterrnum (moo, MOO_ERANGE); return 0; /* too big */ @@ -498,13 +503,13 @@ static MOO_INLINE int bigint_to_uintmax_noseterr (moo_t* moo, moo_oop_t num, moo #if (MOO_SIZEOF_UINTMAX_T >= MOO_SIZEOF_OOW_T * 4) case 3: - *w = ((moo_uintmax_t)MOO_OBJ_GET_WORD_VAL(num, 0) << (MOO_LIW_BITS * 2)) | + *w = ((moo_uintmax_t)MOO_OBJ_GET_WORD_VAL(num, 0) << (MOO_LIW_BITS * 2)) | ((moo_uintmax_t)MOO_OBJ_GET_WORD_VAL(num, 1) << (MOO_LIW_BITS * 1)) | ((moo_uintmax_t)MOO_OBJ_GET_WORD_VAL(num, 2)) goto done; case 4: - *w = ((moo_uintmax_t)MOO_OBJ_GET_WORD_VAL(num, 0) << (MOO_LIW_BITS * 3)) | + *w = ((moo_uintmax_t)MOO_OBJ_GET_WORD_VAL(num, 0) << (MOO_LIW_BITS * 3)) | ((moo_uintmax_t)MOO_OBJ_GET_WORD_VAL(num, 1) << (MOO_LIW_BITS * 2)) | ((moo_uintmax_t)MOO_OBJ_GET_WORD_VAL(num, 2) << (MOO_LIW_BITS * 1)) | ((moo_uintmax_t)MOO_OBJ_GET_WORD_VAL(num, 3)) @@ -520,35 +525,35 @@ static MOO_INLINE int bigint_to_uintmax_noseterr (moo_t* moo, moo_oop_t num, moo switch (MOO_OBJ_GET_SIZE(num)) { case 2: - *w = ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 0) << MOO_LIW_BITS) | + *w = ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 0) << MOO_LIW_BITS) | ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 1)); goto done; case 4: - *w = ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 0) << MOO_LIW_BITS * 3) | - ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 1) << MOO_LIW_BITS * 2) | - ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 2) << MOO_LIW_BITS * 1) | + *w = ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 0) << (MOO_LIW_BITS * 3)) | + ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 1) << (MOO_LIW_BITS * 2)) | + ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 2) << (MOO_LIW_BITS * 1)) | ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 3)); goto done; #if (MOO_SIZEOF_UINTMAX_T >= MOO_SIZEOF_OOW_T * 4) case 6: - *w = ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 0) << MOO_LIW_BITS * 5) | - ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 1) << MOO_LIW_BITS * 4) | - ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 2) << MOO_LIW_BITS * 3) | - ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 3) << MOO_LIW_BITS * 2) | - ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 4) << MOO_LIW_BITS * 1) | + *w = ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 0) << (MOO_LIW_BITS * 5)) | + ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 1) << (MOO_LIW_BITS * 4)) | + ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 2) << (MOO_LIW_BITS * 3)) | + ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 3) << (MOO_LIW_BITS * 2)) | + ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 4) << (MOO_LIW_BITS * 1)) | ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 5)); goto done; case 8: - *w = ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 0) << MOO_LIW_BITS * 7) | - ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 1) << MOO_LIW_BITS * 6) | - ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 2) << MOO_LIW_BITS * 5) | - ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 3) << MOO_LIW_BITS * 4) | - ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 4) << MOO_LIW_BITS * 3) | - ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 5) << MOO_LIW_BITS * 2) | - ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 6) << MOO_LIW_BITS * 1) | + *w = ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 0) << (MOO_LIW_BITS * 7)) | + ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 1) << (MOO_LIW_BITS * 6)) | + ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 2) << (MOO_LIW_BITS * 5)) | + ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 3) << (MOO_LIW_BITS * 4)) | + ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 4) << (MOO_LIW_BITS * 3)) | + ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 5) << (MOO_LIW_BITS * 2)) | + ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 6) << (MOO_LIW_BITS * 1)) | ((moo_uintmax_t)MOO_OBJ_GET_HALFWORD_VAL(num, 7)); goto done; #endif @@ -607,7 +612,7 @@ int moo_inttouintmax (moo_t* moo, moo_oop_t x, moo_uintmax_t* w) } } - if (moo_isbigint(moo, x)) + if (moo_isbigint(moo, x)) { int n; if ((n = bigint_to_uintmax_noseterr(moo, x, w)) <= 0) moo_seterrnum (moo, MOO_ERANGE); @@ -621,12 +626,12 @@ int moo_inttouintmax (moo_t* moo, moo_oop_t x, moo_uintmax_t* w) int moo_inttointmax_noseterr (moo_t* moo, moo_oop_t x, moo_intmax_t* i) { if (MOO_OOP_IS_SMOOI(x)) - { + { *i = MOO_OOP_TO_SMOOI(x); return (*i < 0)? -1: 1; } - if (moo_isbigint(moo, x)) + if (moo_isbigint(moo, x)) { int n; moo_uintmax_t w; @@ -637,7 +642,7 @@ int moo_inttointmax_noseterr (moo_t* moo, moo_oop_t x, moo_intmax_t* i) /* negative number negated to a positve number */ MOO_STATIC_ASSERT (MOO_TYPE_MAX(moo_intmax_t) + MOO_TYPE_MIN(moo_intmax_t) == -1); /* assume 2's complement */ if (w > (moo_uintmax_t)MOO_TYPE_MAX(moo_intmax_t) + 1) return 0; /* not convertable - too small */ - *i = -w; /* negate it back */ + *i = (w <= (moo_uintmax_t)MOO_TYPE_MAX(moo_intmax_t))? -(moo_intmax_t)w: MOO_TYPE_MIN(moo_intmax_t); /* negate back */ } else if (n > 0) { @@ -648,7 +653,6 @@ int moo_inttointmax_noseterr (moo_t* moo, moo_oop_t x, moo_intmax_t* i) return n; } - moo_seterrbfmt (moo, MOO_EINVAL, "not an integer - %O", x); return 0; /* not convertable - not an integer */ } @@ -660,7 +664,7 @@ int moo_inttointmax (moo_t* moo, moo_oop_t x, moo_intmax_t* i) return (*i < 0)? -1: 1; } - if (moo_isbigint(moo, x)) + if (moo_isbigint(moo, x)) { int n; moo_uintmax_t w; @@ -675,13 +679,13 @@ int moo_inttointmax (moo_t* moo, moo_oop_t x, moo_intmax_t* i) moo_seterrnum (moo, MOO_ERANGE); return 0; /* not convertable. too small */ } - *i = -w; /* negate it back */ + *i = (w <= (moo_uintmax_t)MOO_TYPE_MAX(moo_intmax_t))? -(moo_intmax_t)w: MOO_TYPE_MIN(moo_intmax_t); /* negate back */ } else if (n > 0) { - if (w > MOO_TYPE_MAX(moo_intmax_t)) + if (w > MOO_TYPE_MAX(moo_intmax_t)) { - moo_seterrnum (moo, MOO_ERANGE); + moo_seterrnum (moo, MOO_ERANGE); return 0; /* not convertable. too big */ } *i = w; @@ -763,14 +767,14 @@ static MOO_INLINE moo_oop_t make_bloated_bigint_with_ooi (moo_t* moo, moo_ooi_t moo_oow_t w; moo_oop_t z; - MOO_ASSERT (moo, extra <= MOO_OBJ_SIZE_MAX - 1); + MOO_ASSERT (moo, extra <= MOO_OBJ_SIZE_MAX - 1); MOO_STATIC_ASSERT (MOO_SIZEOF(moo_oow_t) == MOO_SIZEOF(moo_liw_t)); if (i >= 0) { w = i; z = moo_instantiate(moo, moo->_large_positive_integer, MOO_NULL, 1 + extra); } - + else { w = (i == MOO_TYPE_MIN(moo_ooi_t))? ((moo_oow_t)MOO_TYPE_MAX(moo_ooi_t) + 1): -i; @@ -786,7 +790,7 @@ static MOO_INLINE moo_oop_t make_bloated_bigint_with_ooi (moo_t* moo, moo_ooi_t moo_oow_t w; moo_oop_t z; - MOO_ASSERT (moo, extra <= MOO_OBJ_SIZE_MAX - 2); + MOO_ASSERT (moo, extra <= MOO_OBJ_SIZE_MAX - 2); if (i >= 0) { w = i; @@ -1097,7 +1101,7 @@ static MOO_INLINE int is_less_unsigned_array (const moo_liw_t* x, moo_oow_t xs, static MOO_INLINE int is_less_unsigned (moo_oop_t x, moo_oop_t y) { return is_less_unsigned_array ( - MOO_OBJ_GET_LIWORD_SLOT(x), MOO_OBJ_GET_SIZE(x), + MOO_OBJ_GET_LIWORD_SLOT(x), MOO_OBJ_GET_SIZE(x), MOO_OBJ_GET_LIWORD_SLOT(y), MOO_OBJ_GET_SIZE(y)); } @@ -1135,7 +1139,7 @@ static MOO_INLINE int is_greater_unsigned_array (const moo_liw_t* x, moo_oow_t x static MOO_INLINE int is_greater_unsigned (moo_oop_t x, moo_oop_t y) { return is_greater_unsigned_array( - MOO_OBJ_GET_LIWORD_SLOT(x), MOO_OBJ_GET_SIZE(x), + MOO_OBJ_GET_LIWORD_SLOT(x), MOO_OBJ_GET_SIZE(x), MOO_OBJ_GET_LIWORD_SLOT(y), MOO_OBJ_GET_SIZE(y)); } @@ -1164,7 +1168,7 @@ static MOO_INLINE int is_equal_unsigned_array (const moo_liw_t* x, moo_oow_t xs, static MOO_INLINE int is_equal_unsigned (moo_oop_t x, moo_oop_t y) { return is_equal_unsigned_array( - MOO_OBJ_GET_LIWORD_SLOT(x), MOO_OBJ_GET_SIZE(x), + MOO_OBJ_GET_LIWORD_SLOT(x), MOO_OBJ_GET_SIZE(x), MOO_OBJ_GET_LIWORD_SLOT(y), MOO_OBJ_GET_SIZE(y)); } @@ -1184,7 +1188,7 @@ static void complement2_unsigned_array (moo_t* moo, const moo_liw_t* x, moo_oow_ /* get 2's complement (~x + 1) */ - carry = 1; + carry = 1; for (i = 0; i < xs; i++) { w = (moo_lidw_t)(~x[i]) + carry; @@ -1197,9 +1201,9 @@ static void complement2_unsigned_array (moo_t* moo, const moo_liw_t* x, moo_oow_ * 1 here and it actually requires 1 more slot. Let't take this 8-bit * zero for instance: * 2r00000000 -> 2r11111111 + 1 => 2r0000000100000000 - * + * * this function is not designed to handle such a case. - * in fact, 0 is a small integer and it must not stand a change + * in fact, 0 is a small integer and it must not stand a change * to be given to this function */ MOO_ASSERT (moo, carry == 0); } @@ -1360,14 +1364,14 @@ static MOO_INLINE moo_oow_t subtract_unsigned_array (moo_t* moo, const moo_liw_t } else { - z[i] = (borrowed_word + (moo_lidw_t)x[i]) - w; + z[i] = (borrowed_word + (moo_lidw_t)x[i]) - w; borrow = 1; } } for (; i < xs; i++) { - if (x[i] >= borrow) + if (x[i] >= borrow) { z[i] = x[i] - (moo_liw_t)borrow; borrow = 0; @@ -1480,7 +1484,7 @@ static MOO_INLINE void multiply_unsigned_array (const moo_liw_t* x, moo_oow_t xs } /* KARATSUBA MULTIPLICATION - * + * * c = |a| * |b| * * Let B represent the radix(2^DIGIT_BITS) @@ -1508,7 +1512,7 @@ static MOO_INLINE void multiply_unsigned_array (const moo_liw_t* x, moo_oow_t xs * -------------------------------------------------------------------- * (A6FE * 10000) + (((1BC * 178) - (985A + A6FE)) * 100) + 9B5A = * (A6FE << (8 * 2)) + (((1BC * 178) - (985A + A6FE)) << (8 * 1)) = - * A6FE0000 + 14CC800 + 9B5A = 9848635A + * A6FE0000 + 14CC800 + 9B5A = 9848635A * -------------------------------------------------------------------- * * 0xABCD9876 * 0xEFEFABAB => 0xA105C97C9755A8D2 @@ -1536,7 +1540,7 @@ static MOO_INLINE void multiply_unsigned_array (const moo_liw_t* x, moo_oow_t xs * X * B^2n => X << (MOO_LIW_BITS * n * 2) * -------------------------------------------------------------------- */ - + #if defined(MOO_BUILD_DEBUG) #define CANNOT_KARATSUBA(moo,xs,ys) \ ((xs) < (moo)->option.karatsuba_cutoff || (ys) < (moo)->option.karatsuba_cutoff || \ @@ -1556,7 +1560,7 @@ static MOO_INLINE moo_oow_t multiply_unsigned_array_karatsuba (moo_t* moo, const moo_lidw_t ndigits_xh, ndigits_xl; moo_lidw_t ndigits_yh, ndigits_yl; moo_liw_t* tmp[2] = { MOO_NULL, MOO_NULL}; - moo_liw_t* zsp; + moo_liw_t* zsp; moo_oow_t tmplen[2]; moo_oow_t xlen, zcapa; @@ -1606,7 +1610,7 @@ static MOO_INLINE moo_oow_t multiply_unsigned_array_karatsuba (moo_t* moo, const /* make a temporary buffer for (b0 + b1) and (a1 * b1) */ tmplen[0] = ndigits_xh + ndigits_yh; - tmplen[1] = ndigits_yl + ndigits_yh + 1; + tmplen[1] = ndigits_yl + ndigits_yh + 1; if (tmplen[1] < tmplen[0]) tmplen[1] = tmplen[0]; tmp[1] = (moo_liw_t*)moo_callocmem(moo, MOO_SIZEOF(moo_liw_t) * tmplen[1]); /* TODO: should i use the object memory? if not, reuse the buffer and minimize memory allocation */ if (MOO_UNLIKELY(!tmp[1])) goto oops; @@ -1632,7 +1636,7 @@ static MOO_INLINE moo_oow_t multiply_unsigned_array_karatsuba (moo_t* moo, const multiply_unsigned_array (tmp[0], tmplen[0], tmp[1], tmplen[1], zsp); xlen = count_effective(zsp, tmplen[0] + tmplen[1]); } - else + else { xlen = multiply_unsigned_array_karatsuba(moo, tmp[0], tmplen[0], tmp[1], tmplen[1], zsp); if (xlen == 0) goto oops; @@ -1693,7 +1697,7 @@ oops: moo_lidw_t ndigits_xh, ndigits_xl; moo_lidw_t ndigits_yh, ndigits_yl; moo_liw_t* tmp[3] = { MOO_NULL, MOO_NULL, MOO_NULL }; - moo_liw_t* zsp; + moo_liw_t* zsp; moo_oow_t tmplen[3]; moo_oow_t xlen, zcapa; @@ -1742,7 +1746,7 @@ oops: MOO_ASSERT (moo, ndigits_yl >= ndigits_yh); /* make a temporary buffer for (b0 + b1) and (a1 * b1) */ - tmplen[0] = ndigits_yl + ndigits_yh + 1; + tmplen[0] = ndigits_yl + ndigits_yh + 1; tmplen[1] = ndigits_xh + ndigits_yh; if (tmplen[1] < tmplen[0]) tmplen[1] = tmplen[0]; tmp[1] = (moo_liw_t*)moo_callocmem(moo, MOO_SIZEOF(moo_liw_t) * tmplen[1]); @@ -1760,7 +1764,7 @@ oops: tmplen[1] = add_unsigned_array (y, ndigits_yl, y + nshifts, ndigits_yh, tmp[1]); /* tmp[2] = (a0 + a1) * (b0 + b1) */ - tmplen[2] = tmplen[0] + tmplen[1]; + tmplen[2] = tmplen[0] + tmplen[1]; tmp[2] = moo_callocmem(moo, MOO_SIZEOF(moo_liw_t) * tmplen[2]); if (!tmp[2]) goto oops; if (CANNOT_KARATSUBA(moo, tmplen[0], tmplen[1])) @@ -1768,7 +1772,7 @@ oops: multiply_unsigned_array (tmp[0], tmplen[0], tmp[1], tmplen[1], tmp[2]); xlen = count_effective(tmp[2], tmplen[2]); } - else + else { xlen = multiply_unsigned_array_karatsuba(moo, tmp[0], tmplen[0], tmp[1], tmplen[1], tmp[2]); if (xlen == 0) goto oops; @@ -1905,22 +1909,22 @@ static MOO_INLINE void rshift_unsigned_array (moo_liw_t* x, moo_oow_t xs, moo_oo static void divide_unsigned_array (moo_t* moo, const moo_liw_t* x, moo_oow_t xs, const moo_liw_t* y, moo_oow_t ys, moo_liw_t* q, moo_liw_t* r) { -/* TODO: this function needs to be rewritten for performance improvement. +/* TODO: this function needs to be rewritten for performance improvement. * the binary long division is extremely slow for a big number */ /* Perform binary long division. * http://en.wikipedia.org/wiki/Division_algorithm * --------------------------------------------------------------------- * Q := 0 initialize quotient and remainder to zero - * R := 0 + * R := 0 * for i = n-1...0 do where n is number of bits in N - * R := R << 1 left-shift R by 1 bit + * R := R << 1 left-shift R by 1 bit * R(0) := X(i) set the least-significant bit of R equal to bit i of the numerator * if R >= Y then - * R = R - Y + * R = R - Y * Q(i) := 1 * end - * end + * end */ moo_oow_t rs, rrs, i , j; @@ -1942,10 +1946,10 @@ static void divide_unsigned_array (moo_t* moo, const moo_liw_t* x, moo_oow_t xs, { --j; - /* the value of the remainder 'r' may get bigger than the + /* the value of the remainder 'r' may get bigger than the * divisor 'y' temporarily until subtraction is performed * below. so ys + 1(kept in rrs) is needed for shifting here. */ - lshift_unsigned_array (r, rrs, 1); + lshift_unsigned_array (r, rrs, 1); MOO_SETBITS (moo_liw_t, r[0], 0, 1, MOO_GETBITS(moo_liw_t, x[i], j, 1)); rs = count_effective(r, rrs); @@ -1993,7 +1997,7 @@ static void divide_unsigned_array2 (moo_t* moo, const moo_liw_t* x, moo_oow_t xs moo_liw_t d, y1, y2; /* the caller must ensure: - * - q can hold 'xs + 1' words and r can hold 'ys' words. + * - q can hold 'xs + 1' words and r can hold 'ys' words. * - q and r are set to all zeros. */ MOO_ASSERT (moo, xs >= ys); @@ -2118,7 +2122,7 @@ static void divide_unsigned_array2 (moo_t* moo, const moo_liw_t* x, moo_oow_t xs } } - /* split quotient and remainder held in q to q and r respectively + /* split quotient and remainder held in q to q and r respectively * q [<--- quotient ---->|<-- remainder -->] * index |xs xs-1 ... ys+1 ys|ys-1 ys-2 ... 1 0| */ @@ -2135,7 +2139,7 @@ static void divide_unsigned_array3 (moo_t* moo, const moo_liw_t* x, moo_oow_t xs moo_liw_t* qq, y1, y2; /* the caller must ensure: - * - q can hold 'xs + 1' words and r can hold 'ys' words. + * - q can hold 'xs + 1' words and r can hold 'ys' words. * - q and r are set to all zeros. */ MOO_ASSERT (moo, xs >= ys); @@ -2321,7 +2325,7 @@ static moo_oop_t subtract_unsigned_integers (moo_t* moo, moo_oop_t x, moo_oop_t moo_popvolats (moo, 2); if (MOO_UNLIKELY(!z)) return MOO_NULL; - subtract_unsigned_array (moo, + subtract_unsigned_array (moo, MOO_OBJ_GET_LIWORD_SLOT(x), MOO_OBJ_GET_SIZE(x), MOO_OBJ_GET_LIWORD_SLOT(y), MOO_OBJ_GET_SIZE(y), MOO_OBJ_GET_LIWORD_SLOT(z)); @@ -2400,7 +2404,7 @@ static moo_oop_t divide_unsigned_integers (moo_t* moo, moo_oop_t x, moo_oop_t y, } /* the caller must ensure that x >= y */ - MOO_ASSERT (moo, !is_less_unsigned(x, y)); + MOO_ASSERT (moo, !is_less_unsigned(x, y)); moo_pushvolat (moo, &x); moo_pushvolat (moo, &y); @@ -2414,7 +2418,7 @@ static moo_oop_t divide_unsigned_integers (moo_t* moo, moo_oop_t x, moo_oop_t y, #else qq = moo_instantiate(moo, moo->_large_positive_integer, MOO_NULL, MOO_OBJ_GET_SIZE(x)); #endif - if (!qq) + if (!qq) { moo_popvolats (moo, 2); return MOO_NULL; @@ -2423,7 +2427,7 @@ static moo_oop_t divide_unsigned_integers (moo_t* moo, moo_oop_t x, moo_oop_t y, moo_pushvolat (moo, &qq); #if defined(USE_DIVIDE_UNSIGNED_ARRAY3) rr = moo_instantiate(moo, moo->_large_positive_integer, MOO_NULL, MOO_OBJ_GET_SIZE(y)); -#elif defined(USE_DIVIDE_UNSIGNED_ARRAY2) +#elif defined(USE_DIVIDE_UNSIGNED_ARRAY2) rr = moo_instantiate(moo, moo->_large_positive_integer, MOO_NULL, MOO_OBJ_GET_SIZE(y)); #else rr = moo_instantiate(moo, moo->_large_positive_integer, MOO_NULL, MOO_OBJ_GET_SIZE(y) + 1); @@ -2538,7 +2542,7 @@ moo_oop_t moo_addints (moo_t* moo, moo_oop_t x, moo_oop_t y) { int neg; /* both are positive or negative */ - neg = (MOO_POINTER_IS_NBIGINT(moo, x)); + neg = (MOO_POINTER_IS_NBIGINT(moo, x)); z = add_unsigned_integers(moo, x, y); if (MOO_UNLIKELY(!z)) return MOO_NULL; if (neg) MOO_OBJ_SET_CLASS(z, moo->_large_negative_integer); @@ -2580,7 +2584,7 @@ moo_oop_t moo_subints (moo_t* moo, moo_oop_t x, moo_oop_t y) if (!moo_isbigint(moo,y)) goto oops_einval; v = MOO_OOP_TO_SMOOI(x); - if (v == 0) + if (v == 0) { /* switch the sign to the opposite and return it */ return clone_bigint_negated(moo, y, MOO_OBJ_GET_SIZE(y)); @@ -2611,7 +2615,7 @@ moo_oop_t moo_subints (moo_t* moo, moo_oop_t x, moo_oop_t y) if (MOO_OBJ_GET_CLASS(x) != MOO_OBJ_GET_CLASS(y)) { - neg = (MOO_POINTER_IS_NBIGINT(moo, x)); + neg = (MOO_POINTER_IS_NBIGINT(moo, x)); z = add_unsigned_integers(moo, x, y); if (MOO_UNLIKELY(!z)) return MOO_NULL; if (neg) MOO_OBJ_SET_CLASS(z, moo->_large_negative_integer); @@ -2628,7 +2632,7 @@ moo_oop_t moo_subints (moo_t* moo, moo_oop_t x, moo_oop_t y) } else { - neg = (MOO_POINTER_IS_NBIGINT(moo, x)); + neg = (MOO_POINTER_IS_NBIGINT(moo, x)); z = subtract_unsigned_integers (moo, x, y); /* take x's sign */ if (MOO_UNLIKELY(!z)) return MOO_NULL; if (neg) MOO_OBJ_SET_CLASS(z, moo->_large_negative_integer); @@ -2774,20 +2778,20 @@ moo_oop_t moo_divints (moo_t* moo, moo_oop_t x, moo_oop_t y, int modulo, moo_oop /* In C89, integer division with a negative number is * implementation dependent. In C99, it truncates towards zero. - * + * * http://python-history.blogspot.kr/2010/08/why-pythons-integer-division-floors.html - * The integer division operation (//) and its sibling, + * The integer division operation (//) and its sibling, * the modulo operation (%), go together and satisfy a nice * mathematical relationship (all variables are integers): * a/b = q with remainder r * such that * b*q + r = a and 0 <= r < b (assuming- a and b are >= 0). - * + * * If you want the relationship to extend for negative a * (keeping b positive), you have two choices: if you truncate q * towards zero, r will become negative, so that the invariant * changes to 0 <= abs(r) < abs(b). otherwise, you can floor q - * towards negative infinity, and the invariant remains 0 <= r < b. + * towards negative infinity, and the invariant remains 0 <= r < b. */ q = xv / yv; @@ -2808,7 +2812,7 @@ moo_oop_t moo_divints (moo_t* moo, moo_oop_t x, moo_oop_t y, int modulo, moo_oop -7 -3 2 -1 */ - /* r must be floored. that is, it rounds away from zero + /* r must be floored. that is, it rounds away from zero * and towards negative infinity */ if (IS_SIGN_DIFF(yv, ri)) { @@ -2830,7 +2834,7 @@ moo_oop_t moo_divints (moo_t* moo, moo_oop_t x, moo_oop_t y, int modulo, moo_oop 7 -3 -2 1 -7 -3 2 -1 */ - if (xv && IS_SIGN_DIFF(xv, ri)) + if (xv && IS_SIGN_DIFF(xv, ri)) { /* if the dividend has a different sign from r, * change the sign of r to the dividend's sign. @@ -2853,7 +2857,7 @@ moo_oop_t moo_divints (moo_t* moo, moo_oop_t x, moo_oop_t y, int modulo, moo_oop return MOO_SMOOI_TO_OOP((moo_ooi_t)q); } - else + else { moo_oop_t r; @@ -2863,7 +2867,7 @@ moo_oop_t moo_divints (moo_t* moo, moo_oop_t x, moo_oop_t y, int modulo, moo_oop if (!moo_isbigint(moo,y)) goto oops_einval; - /* divide a small integer by a big integer. + /* divide a small integer by a big integer. * the dividend is guaranteed to be greater than the divisor * if both are positive. */ @@ -2995,10 +2999,10 @@ moo_oop_t moo_divints (moo_t* moo, moo_oop_t x, moo_oop_t y, int modulo, moo_oop moo_popvolats (moo, 2); if (MOO_UNLIKELY(!z)) return MOO_NULL; - if (x_neg_sign) + if (x_neg_sign) { - /* the class on r must be set before normalize_bigint() + /* the class on r must be set before normalize_bigint() * because it can get changed to a small integer */ MOO_OBJ_SET_CLASS(r, moo->_large_negative_integer); } @@ -3100,7 +3104,7 @@ moo_oop_t moo_bitatint (moo_t* moo, moo_oop_t x, moo_oop_t y) if (v2 < 0) return MOO_SMOOI_TO_OOP(0); if (v1 >= 0) { - /* the absolute value may be composed of up to + /* the absolute value may be composed of up to * MOO_SMOOI_BITS - 1 bits as there is a sign bit.*/ if (v2 >= MOO_SMOOI_BITS - 1) return MOO_SMOOI_TO_OOP(0); v3 = ((moo_oow_t)v1 >> v2) & 1; @@ -3119,9 +3123,9 @@ moo_oop_t moo_bitatint (moo_t* moo, moo_oop_t x, moo_oop_t y) if (MOO_POINTER_IS_NBIGINT(moo, y)) return MOO_SMOOI_TO_OOP(0); /* y is definitely >= MOO_SMOOI_BITS */ - if (MOO_OOP_TO_SMOOI(x) >= 0) + if (MOO_OOP_TO_SMOOI(x) >= 0) return MOO_SMOOI_TO_OOP(0); - else + else return MOO_SMOOI_TO_OOP(1); } else if (MOO_OOP_IS_SMOOI(y)) @@ -3426,20 +3430,20 @@ moo_oop_t moo_bitandints (moo_t* moo, moo_oop_t x, moo_oop_t y) MOO_ASSERT (moo, carry == 0); /* handle the longer part in x than y - * + * * For example, * x => + 1010 1100 * y => - 0011 - * - * If y is extended to the same length as x, - * it is a negative 0000 0001. + * + * If y is extended to the same length as x, + * it is a negative 0000 0001. * 2's complement is performed on this imaginary extension. * the result is '1111 1101' (1111 1100 + 1). - * + * * when y is shorter and negative, the lacking part can be * treated as all 1s in the 2's complement format. - * - * the remaining part in x can be just copied to the + * + * the remaining part in x can be just copied to the * final result 'z'. */ for (; i < xs; i++) @@ -3651,7 +3655,7 @@ moo_oop_t moo_bitorints (moo_t* moo, moo_oop_t x, moo_oop_t y) * extended to the width of x. but those 1s are inverted to * 0s when another 2's complement is performed over the final * result after the jump to 'adjust_to_negative'. - * setting zs to 'xs + 1' and performing the following loop is + * setting zs to 'xs + 1' and performing the following loop is * redundant. for (; i < xs; i++) { @@ -4074,8 +4078,8 @@ static MOO_INLINE moo_oop_t rshift_negative_bigint_and_normalize (moo_t* moo, mo MOO_ASSERT (moo, MOO_POINTER_IS_NBIGINT(moo, x)); MOO_ASSERT (moo, MOO_POINTER_IS_NBIGINT(moo, y)); - /* for convenience in subtraction below. - * it could be MOO_TYPE_MAX(moo_oow_t) + /* for convenience in subtraction below. + * it could be MOO_TYPE_MAX(moo_oow_t) * if make_bigint_with_intmax() or something * similar were used instead of MOO_SMOOI_TO_OOP().*/ shift = MOO_SMOOI_MAX; @@ -4094,7 +4098,7 @@ static MOO_INLINE moo_oop_t rshift_negative_bigint_and_normalize (moo_t* moo, mo sign = integer_to_oow_noseterr(moo, y, &shift); if (sign == 0) shift = MOO_SMOOI_MAX; - else + else { if (shift == 0) { @@ -4118,19 +4122,19 @@ static MOO_INLINE moo_oop_t rshift_negative_bigint_and_normalize (moo_t* moo, mo MOO_ASSERT (moo, v < 0); /* normal right shift of a small negative integer */ - if (shift >= MOO_OOI_BITS - 1) + if (shift >= MOO_OOI_BITS - 1) { /* when y is still a large integer, this condition is met - * met as MOO_SMOOI_MAX > MOO_OOI_BITS. so i can simly + * met as MOO_SMOOI_MAX > MOO_OOI_BITS. so i can simly * terminate the loop after this */ return MOO_SMOOI_TO_OOP(-1); } - else + else { v = (moo_ooi_t)(((moo_oow_t)v >> shift) | MOO_HBMASK(moo_oow_t, shift)); - if (MOO_IN_SMOOI_RANGE(v)) + if (MOO_IN_SMOOI_RANGE(v)) return MOO_SMOOI_TO_OOP(v); - else + else return make_bigint_with_ooi (moo, v); } } @@ -4159,8 +4163,8 @@ static MOO_INLINE moo_oop_t rshift_positive_bigint_and_normalize (moo_t* moo, mo moo_popvolat (moo); if (MOO_UNLIKELY(!z)) return MOO_NULL; - /* for convenience in subtraction below. - * it could be MOO_TYPE_MAX(moo_oow_t) + /* for convenience in subtraction below. + * it could be MOO_TYPE_MAX(moo_oow_t) * if make_bigint_with_intmax() or something * similar were used instead of MOO_SMOOI_TO_OOP().*/ shift = MOO_SMOOI_MAX; @@ -4168,7 +4172,7 @@ static MOO_INLINE moo_oop_t rshift_positive_bigint_and_normalize (moo_t* moo, mo { rshift_unsigned_array (MOO_OBJ_GET_LIWORD_SLOT(z), zs, shift); if (count_effective(MOO_OBJ_GET_LIWORD_SLOT(z), zs) == 1 && - MOO_OBJ_GET_LIWORD_VAL(z, 0) == 0) + MOO_OBJ_GET_LIWORD_VAL(z, 0) == 0) { /* if z is 0, i don't have to go on */ break; @@ -4182,7 +4186,7 @@ static MOO_INLINE moo_oop_t rshift_positive_bigint_and_normalize (moo_t* moo, mo sign = integer_to_oow_noseterr(moo, y, &shift); if (sign == 0) shift = MOO_SMOOI_MAX; - else + else { if (shift == 0) break; MOO_ASSERT (moo, sign <= -1); @@ -4204,12 +4208,12 @@ static MOO_INLINE moo_oop_t lshift_bigint_and_normalize (moo_t* moo, moo_oop_t x /* this loop is very inefficient as shifting is repeated * with lshift_unsigned_array(). however, this part of the * code is not likey to be useful because the amount of - * memory available is certainly not enough to support + * memory available is certainly not enough to support * huge shifts greater than MOO_TYPE_MAX(moo_oow_t) */ shift = MOO_SMOOI_MAX; do { - /* for convenience only in subtraction below. + /* for convenience only in subtraction below. * should it be between MOO_SMOOI_MAX and MOO_TYPE_MAX(moo_oow_t), * the second parameter to moo_subints() can't be composed * using MOO_SMOOI_TO_OOP() */ @@ -4237,7 +4241,7 @@ static MOO_INLINE moo_oop_t lshift_bigint_and_normalize (moo_t* moo, moo_oop_t x if (sign == 0) shift = MOO_SMOOI_MAX; else { - if (shift == 0) + if (shift == 0) { MOO_ASSERT (moo, is_normalized_integer (moo, x)); return x; @@ -4266,10 +4270,10 @@ moo_oop_t moo_bitshiftint (moo_t* moo, moo_oop_t x, moo_oop_t y) v1 = MOO_OOP_TO_SMOOI(x); v2 = MOO_OOP_TO_SMOOI(y); - if (v1 == 0 || v2 == 0) + if (v1 == 0 || v2 == 0) { /* return without cloning as x is a small integer */ - return x; + return x; } if (v2 > 0) @@ -4310,12 +4314,12 @@ moo_oop_t moo_bitshiftint (moo_t* moo, moo_oop_t x, moo_oop_t y) * 11111111 (-1) 7 * 11111111 (-1) 8 */ - + if (v2 >= MOO_OOI_BITS - 1) v = -1; - else + else { /* MOO_HBMASK_SAFE(moo_oow_t, v2 + 1) could also be - * used as a mask. but the sign bit is shifted in. + * used as a mask. but the sign bit is shifted in. * so, masking up to 'v2' bits is sufficient */ v = (moo_ooi_t)(((moo_oow_t)v1 >> v2) | MOO_HBMASK(moo_oow_t, v2)); } @@ -4376,7 +4380,7 @@ moo_oop_t moo_bitshiftint (moo_t* moo, moo_oop_t x, moo_oop_t y) shift = v; goto bigint_and_positive_oow; } - else + else { sign = -1; negy = 1; @@ -4403,7 +4407,7 @@ moo_oop_t moo_bitshiftint (moo_t* moo, moo_oop_t x, moo_oop_t y) /* right shift */ #if defined(MOO_LIMIT_OBJ_SIZE) /* the maximum number of bit shifts are guaranteed to be - * small enough to fit into the moo_oow_t type. so i can + * small enough to fit into the moo_oow_t type. so i can * easily assume that all bits are shifted out */ MOO_ASSERT (moo, MOO_OBJ_SIZE_BITS_MAX <= MOO_TYPE_MAX(moo_oow_t)); return (negx)? MOO_SMOOI_TO_OOP(-1): MOO_SMOOI_TO_OOP(0); @@ -4419,8 +4423,8 @@ moo_oop_t moo_bitshiftint (moo_t* moo, moo_oop_t x, moo_oop_t y) /* left shift */ #if defined(MOO_LIMIT_OBJ_SIZE) /* the maximum number of bit shifts are guaranteed to be - * small enough to fit into the moo_oow_t type. so i can - * simply return a failure here becuase it's surely too + * small enough to fit into the moo_oow_t type. so i can + * simply return a failure here becuase it's surely too * large after shifting */ MOO_ASSERT (moo, MOO_TYPE_MAX(moo_oow_t) >= MOO_OBJ_SIZE_BITS_MAX); moo_seterrnum (moo, MOO_EOOMEM); /* is it a soft failure or a hard failure? is this error code proper? */ @@ -4444,7 +4448,7 @@ moo_oop_t moo_bitshiftint (moo_t* moo, moo_oop_t x, moo_oop_t y) lshift_unsigned_array (MOO_OBJ_GET_LIWORD_SLOT(z), MOO_OBJ_GET_SIZE(z), shift); } - else + else { /* right shift */ bigint_and_negative_oow: @@ -4494,7 +4498,7 @@ moo_oop_t moo_strtoint (moo_t* moo, const moo_ooch_t* str, moo_oow_t len, int ra moo_oow_t hwlen, outlen; moo_oop_t res; - if (radix < 0) + if (radix < 0) { /* when radix is less than 0, it treats it as if '-' is preceeding */ sign = -1; @@ -4509,16 +4513,16 @@ moo_oop_t moo_strtoint (moo_t* moo, const moo_ooch_t* str, moo_oow_t len, int ra if (ptr < end) { if (*ptr == '+') ptr++; - else if (*ptr == '-') + else if (*ptr == '-') { - ptr++; + ptr++; sign = -1; } } if (ptr >= end) goto oops_einval; /* no digits */ - while (ptr < end && *ptr == '0') + while (ptr < end && *ptr == '0') { /* skip leading zeros */ ptr++; @@ -4544,11 +4548,11 @@ moo_oop_t moo_strtoint (moo_t* moo, const moo_ooch_t* str, moo_oow_t len, int ra exp = _exp_tab[radix - 1]; /* bytes */ - outlen = ((moo_oow_t)(end - str) * exp + 7) / 8; + outlen = ((moo_oow_t)(end - str) * exp + 7) / 8; /* number of moo_liw_t */ outlen = (outlen + MOO_SIZEOF(hw[0]) - 1) / MOO_SIZEOF(hw[0]); - if (outlen > MOO_COUNTOF(hw)) + if (outlen > MOO_COUNTOF(hw)) { /* TODO: reuse this buffer? */ hwp = (moo_liw_t*)moo_allocmem(moo, outlen * MOO_SIZEOF(hw[0])); @@ -4597,7 +4601,7 @@ moo_oop_t moo_strtoint (moo_t* moo, const moo_ooch_t* str, moo_oow_t len, int ra multiplier = (moo_liw_t)moo->bigint[radix].multiplier; outlen = (end - str) / safe_ndigits + 1; - if (outlen > MOO_COUNTOF(hw)) + if (outlen > MOO_COUNTOF(hw)) { hwp = moo_allocmem(moo, outlen * MOO_SIZEOF(moo_liw_t)); if (!hwp) return MOO_NULL; @@ -4613,7 +4617,7 @@ moo_oop_t moo_strtoint (moo_t* moo, const moo_ooch_t* str, moo_oow_t len, int ra r1 = 0; for (dg = 0; dg < safe_ndigits; dg++) { - if (ptr >= end) + if (ptr >= end) { multiplier = 1; for (i = 0; i < dg; i++) multiplier *= radix; @@ -4656,14 +4660,14 @@ moo_oop_t moo_strtoint (moo_t* moo, const moo_ooch_t* str, moo_oow_t len, int ra MOO_ASSERT (moo, hwlen >= 1); #if (MOO_LIW_BITS == MOO_OOW_BITS) - if (hwlen == 1) + if (hwlen == 1) { w = hwp[0]; MOO_ASSERT (moo, -MOO_SMOOI_MAX == MOO_SMOOI_MIN); if (w <= MOO_SMOOI_MAX) return MOO_SMOOI_TO_OOP((moo_ooi_t)w * sign); } #elif (MOO_LIW_BITS == MOO_OOHW_BITS) - if (hwlen == 1) + if (hwlen == 1) { MOO_ASSERT (moo, hwp[0] <= MOO_SMOOI_MAX); return MOO_SMOOI_TO_OOP((moo_ooi_t)hwp[0] * sign); @@ -4730,11 +4734,11 @@ moo_oop_t moo_eqints (moo_t* moo, moo_oop_t x, moo_oop_t y) { return (MOO_OOP_TO_SMOOI(x) == MOO_OOP_TO_SMOOI(y))? moo->_true: moo->_false; } - else if (MOO_OOP_IS_SMOOI(x) || MOO_OOP_IS_SMOOI(y)) + else if (MOO_OOP_IS_SMOOI(x) || MOO_OOP_IS_SMOOI(y)) { return moo->_false; } - else + else { if (!moo_isbigint(moo, x) || !moo_isbigint(moo, y)) goto oops_einval; return is_equal(moo, x, y)? moo->_true: moo->_false; @@ -4751,11 +4755,11 @@ moo_oop_t moo_neints (moo_t* moo, moo_oop_t x, moo_oop_t y) { return (MOO_OOP_TO_SMOOI(x) != MOO_OOP_TO_SMOOI(y))? moo->_true: moo->_false; } - else if (MOO_OOP_IS_SMOOI(x) || MOO_OOP_IS_SMOOI(y)) + else if (MOO_OOP_IS_SMOOI(x) || MOO_OOP_IS_SMOOI(y)) { return moo->_true; } - else + else { if (!moo_isbigint(moo, x) || !moo_isbigint(moo, y)) goto oops_einval; return !is_equal(moo, x, y)? moo->_true: moo->_false; @@ -4777,12 +4781,12 @@ moo_oop_t moo_gtints (moo_t* moo, moo_oop_t x, moo_oop_t y) if (!moo_isbigint(moo, y)) goto oops_einval; return (MOO_POINTER_IS_NBIGINT(moo, y))? moo->_true: moo->_false; } - else if (MOO_OOP_IS_SMOOI(y)) + else if (MOO_OOP_IS_SMOOI(y)) { if (!moo_isbigint(moo, x)) goto oops_einval; return (MOO_POINTER_IS_PBIGINT(moo, x))? moo->_true: moo->_false; } - else + else { if (!moo_isbigint(moo, x) || !moo_isbigint(moo, y)) goto oops_einval; return is_greater(moo, x, y)? moo->_true: moo->_false; @@ -4804,12 +4808,12 @@ moo_oop_t moo_geints (moo_t* moo, moo_oop_t x, moo_oop_t y) if (!moo_isbigint(moo, y)) goto oops_einval; return (MOO_POINTER_IS_NBIGINT(moo, y))? moo->_true: moo->_false; } - else if (MOO_OOP_IS_SMOOI(y)) + else if (MOO_OOP_IS_SMOOI(y)) { if (!moo_isbigint(moo, x)) goto oops_einval; return (MOO_POINTER_IS_PBIGINT(moo, x))? moo->_true: moo->_false; } - else + else { if (!moo_isbigint(moo, x) || !moo_isbigint(moo, y)) goto oops_einval; return (is_greater(moo, x, y) || is_equal(moo, x, y))? moo->_true: moo->_false; @@ -4831,12 +4835,12 @@ moo_oop_t moo_ltints (moo_t* moo, moo_oop_t x, moo_oop_t y) if (!moo_isbigint(moo, y)) goto oops_einval; return (MOO_POINTER_IS_PBIGINT(moo, y))? moo->_true: moo->_false; } - else if (MOO_OOP_IS_SMOOI(y)) + else if (MOO_OOP_IS_SMOOI(y)) { if (!moo_isbigint(moo, x)) goto oops_einval; return (MOO_POINTER_IS_NBIGINT(moo, x))? moo->_true: moo->_false; } - else + else { if (!moo_isbigint(moo, x) || !moo_isbigint(moo, y)) goto oops_einval; return is_less(moo, x, y)? moo->_true: moo->_false; @@ -4858,12 +4862,12 @@ moo_oop_t moo_leints (moo_t* moo, moo_oop_t x, moo_oop_t y) if (!moo_isbigint(moo, y)) goto oops_einval; return (MOO_POINTER_IS_PBIGINT(moo, y))? moo->_true: moo->_false; } - else if (MOO_OOP_IS_SMOOI(y)) + else if (MOO_OOP_IS_SMOOI(y)) { if (!moo_isbigint(moo, x)) goto oops_einval; return (MOO_POINTER_IS_NBIGINT(moo, x))? moo->_true: moo->_false; } - else + else { if (!moo_isbigint(moo, x) || !moo_isbigint(moo, y)) goto oops_einval; return (is_less(moo, x, y) || is_equal(moo, x, y))? moo->_true: moo->_false; @@ -4880,7 +4884,7 @@ moo_oop_t moo_sqrtint (moo_t* moo, moo_oop_t x) moo_oop_t a, b, m, m2, t; int neg; - if (!moo_isint(moo, x)) + if (!moo_isint(moo, x)) { moo_seterrbfmt (moo, MOO_EINVAL, "parameter not integer - %O", x); return MOO_NULL; @@ -4959,7 +4963,7 @@ moo_oop_t moo_absint (moo_t* moo, moo_oop_t x) { moo_ooi_t v; v = MOO_OOP_TO_SMOOI(x); - if (v < 0) + if (v < 0) { v = -v; x = MOO_SMOOI_TO_OOP(v); @@ -5062,7 +5066,7 @@ moo_oop_t moo_inttostr (moo_t* moo, moo_oop_t num, int flagged_radix) * mutli-word conversion begins now */ as = MOO_OBJ_GET_SIZE(num); - reqcapa = as * MOO_LIW_BITS + 1; + reqcapa = as * MOO_LIW_BITS + 1; if (moo->inttostr.xbuf.capa < reqcapa) { xbuf = (moo_ooch_t*)moo_reallocmem(moo, moo->inttostr.xbuf.ptr, reqcapa * MOO_SIZEOF(*xbuf)); @@ -5082,7 +5086,7 @@ moo_oop_t moo_inttostr (moo_t* moo, moo_oop_t num, int flagged_radix) moo->inttostr.t.capa = as; moo->inttostr.t.ptr = t; } - else + else { t = moo->inttostr.t.ptr; } diff --git a/lib/chr.c b/lib/chr.c index 66d563e..262d5d0 100644 --- a/lib/chr.c +++ b/lib/chr.c @@ -109,7 +109,7 @@ int moo_is_uch_blank (moo_uch_t c) moo_uch_t moo_to_uch_upper (moo_uch_t c) { moo_uchu_t uc = (moo_uchu_t)c; - if (uc >= 0 && uc <= UCH_CASE_MAX) + if (uc >= 0 && uc <= UCH_CASE_MAX) { uch_case_page_t* page; page = uch_case_map[UCH_CASE_MAP_INDEX(uc)]; @@ -121,7 +121,7 @@ moo_uch_t moo_to_uch_upper (moo_uch_t c) moo_uch_t moo_to_uch_lower (moo_uch_t c) { moo_uchu_t uc = (moo_uchu_t)c; - if (uc >= 0 && uc <= UCH_CASE_MAX) + if (uc >= 0 && uc <= UCH_CASE_MAX) { uch_case_page_t* page; page = uch_case_map[UCH_CASE_MAP_INDEX(uc)]; @@ -186,16 +186,16 @@ moo_bch_t moo_to_bch_lower (moo_bch_t c) /* ----------------------------------------------------------------------- */ /* - * See http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c + * See http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c */ -struct interval +struct interval { int first; int last; }; /* auxiliary function for binary search in interval table */ -static int bisearch(moo_uch_t ucs, const struct interval *table, int max) +static int bisearch(moo_uch_t ucs, const struct interval *table, int max) { int min = 0; int mid; @@ -320,7 +320,7 @@ int moo_get_ucwidth (moo_uch_t uc) (uc >= 0xff00 && uc <= 0xff60) || /* Fullwidth Forms */ (uc >= 0xffe0 && uc <= 0xffe6) #if (MOO_SIZEOF_UCH_T > 2) - || + || (uc >= 0x20000 && uc <= 0x2fffd) || (uc >= 0x30000 && uc <= 0x3fffd) #endif @@ -330,5 +330,5 @@ int moo_get_ucwidth (moo_uch_t uc) } } - return 1; + return 1; } diff --git a/lib/comp.c b/lib/comp.c index 74d2a4e..98b7b9a 100644 --- a/lib/comp.c +++ b/lib/comp.c @@ -93,14 +93,14 @@ struct var_info_t var_type_t type; /* not used for VAR_GLOBAL */ - moo_ooi_t pos; + moo_ooi_t pos; - /* useful if type is VAR_CLASS(class variable). + /* useful if type is VAR_CLASS(class variable). * note it may be set to MOO_NULL to indicate the self class when * the current class being compiled has not been instantiated. */ - moo_oop_class_t cls; + moo_oop_class_t cls; - union + union { moo_oop_association_t gbl; /* used for VAR_GLOBAL only */ moo_oop_t lit; /* used for VAR_LITERAL only */ @@ -333,8 +333,8 @@ static MOO_INLINE int is_binselchar (moo_ooci_t c) case '*': case '+': case '-': - case '/': - case '%': + case '/': + case '%': case '<': case '>': case '=': @@ -371,7 +371,7 @@ static MOO_INLINE int is_closing_char (moo_ooci_t c) case '\"': case '\'': return 1; - + default: return 0; } @@ -380,7 +380,7 @@ static MOO_INLINE int is_closing_char (moo_ooci_t c) static MOO_INLINE int is_word (const moo_oocs_t* oocs, voca_id_t id) { - return oocs->len == vocas[id].len && + return oocs->len == vocas[id].len && moo_equal_oochars(oocs->ptr, vocas[id].str, vocas[id].len); } @@ -390,7 +390,7 @@ static int is_reserved_word (const moo_oocs_t* ucs, moo_iotok_type_t* token_type { voca_id_t voca_id; moo_iotok_type_t token_type; - } rw[] = + } rw[] = { { VOCA_SELF, MOO_IOTOK_SELF }, { VOCA_SUPER, MOO_IOTOK_SUPER }, @@ -418,7 +418,7 @@ static int is_reserved_word (const moo_oocs_t* ucs, moo_iotok_type_t* token_type for (i = 0; i < MOO_COUNTOF(rw); i++) { - if (is_word(ucs, rw[i].voca_id)) + if (is_word(ucs, rw[i].voca_id)) { if (token_type) *token_type = rw[i].token_type; return 1; @@ -433,7 +433,7 @@ static int is_restricted_word (const moo_oocs_t* ucs) { /* not fully reserved. but restricted in a certain context */ - static int rw[] = + static int rw[] = { VOCA_CLASS, VOCA_EXTEND, @@ -498,7 +498,7 @@ static int copy_string_to (moo_t* moo, const moo_oocs_t* src, moo_oocs_t* dst, m static int find_word_in_string (const moo_oocs_t* haystack, const moo_oocs_t* name, moo_oow_t* xindex) { /* this function is inefficient. but considering the typical number - * of arguments and temporary variables, the inefficiency can be + * of arguments and temporary variables, the inefficiency can be * ignored in my opinion. the overhead to maintain the reverse lookup * table from a name to an index should be greater than this simple * inefficient lookup */ @@ -519,7 +519,7 @@ static int find_word_in_string (const moo_oocs_t* haystack, const moo_oocs_t* na if (t >= e || name->ptr[i] != *t) goto unmatched; t++; } - if (t >= e || is_spacechar(*t)) + if (t >= e || is_spacechar(*t)) { if (xindex) *xindex = index; return 0; @@ -577,7 +577,7 @@ static int find_oop_in_oopbuf (moo_t* moo, moo_oopbuf_t* oopbuf, moo_oow_t start for (i = start; i < oopbuf->count; i += step) { - if (oopbuf->ptr[i] == item) + if (oopbuf->ptr[i] == item) { if (index) *index = i; return 0; @@ -612,9 +612,9 @@ static int add_oop_to_oopbuf_nodup (moo_t* moo, moo_oopbuf_t* oopbuf, moo_oop_t { moo_oow_t i; - for (i = 0; i < oopbuf->count; i++) + for (i = 0; i < oopbuf->count; i++) { - if (oopbuf->ptr[i] == item) + if (oopbuf->ptr[i] == item) { *index = i; return 0; /* the same item exists */ @@ -676,7 +676,7 @@ static int string_to_smooi (moo_t* moo, moo_oocs_t* str, int radixed, moo_ooi_t* while (ptr < end && (v = ZDIGIT_TO_NUM(*ptr, base)) < base) { value = value * base + v; - if (value < old_value) + if (value < old_value) { /* overflow must have occurred */ moo_seterrnum (moo, MOO_ERANGE); @@ -694,7 +694,7 @@ static int string_to_smooi (moo_t* moo, moo_oocs_t* str, int radixed, moo_ooi_t* } MOO_ASSERT (moo, -MOO_SMOOI_MAX == MOO_SMOOI_MIN); - if (value > MOO_SMOOI_MAX) + if (value > MOO_SMOOI_MAX) { moo_seterrnum (moo, MOO_ERANGE); return -1; @@ -819,7 +819,7 @@ static moo_oop_t string_to_fpdec (moo_t* moo, moo_oocs_t* str, int prescaled) { v = moo_strtoint(moo, &str->ptr[pos], len, base); } - if (!v) + if (!v) { const moo_ooch_t* oldmsg = moo_backuperrmsg(moo); moo_seterrbfmt (moo, moo_geterrnum(moo), "unable to convert to fpdec %.*js - %js", str->len, str->ptr, oldmsg); @@ -842,12 +842,12 @@ static moo_oop_t string_to_error (moo_t* moo, moo_oocs_t* str, moo_ioloc_t* loc) * i just skip all non-digit letters for simplicity sake. */ while (ptr < end) { - if (is_digitchar(*ptr)) + if (is_digitchar(*ptr)) { moo_oow_t xnum; xnum = num * 10 + (*ptr - '0'); - if (xnum < num || xnum > MOO_ERROR_MAX) + if (xnum < num || xnum > MOO_ERROR_MAX) { /* overflowed */ moo_setsynerr (moo, MOO_SYNERR_ERRLITINVAL, loc, str); @@ -875,7 +875,7 @@ static moo_oop_t string_to_ptr (moo_t* moo, moo_oocs_t* str, moo_ioloc_t* loc) * i just skip all non-digit letters for simplicity sake. */ while (ptr < end) { - if (is_xdigitchar(*ptr)) + if (is_xdigitchar(*ptr)) { moo_oow_t xnum; @@ -923,7 +923,7 @@ static void fini_oow_pool (moo_t* moo, moo_oow_pool_t* pool) chunk = next; } - /* this doesn't reinitialize the pool. call init_oow_pool() + /* this doesn't reinitialize the pool. call init_oow_pool() * to reuse it */ } @@ -1009,7 +1009,7 @@ static MOO_INLINE moo_oocs_t* get_cunit_fqn (moo_t* moo) return (moo_oocs_t*)((moo_uint8_t*)moo->c->cunit + offset[moo->c->cunit->cunit_type]); } /* --------------------------------------------------------------------- - * Tokenizer + * Tokenizer * --------------------------------------------------------------------- */ #define GET_CHAR(moo) \ @@ -1111,12 +1111,12 @@ static int get_char (moo_t* moo) return 0; } - if (moo->c->curinp->b.state == -1) + if (moo->c->curinp->b.state == -1) { moo->c->curinp->b.state = 0; return -1; } - else if (moo->c->curinp->b.state == 1) + else if (moo->c->curinp->b.state == 1) { moo->c->curinp->b.state = 0; goto return_eof; @@ -1126,7 +1126,7 @@ static int get_char (moo_t* moo) { n = moo->c->impl(moo, MOO_IO_READ, moo->c->curinp); if (n <= -1) return -1; - + if (n == 0) { return_eof: @@ -1137,7 +1137,7 @@ static int get_char (moo_t* moo) moo->c->lxc = moo->c->curinp->lxc; /* indicate that EOF has been read. lxc.c is also set to EOF. */ - return 0; + return 0; } moo->c->curinp->b.pos = 0; @@ -1150,11 +1150,11 @@ static int get_char (moo_t* moo) * to be read is still in the buffer (moo->c->curinp->buf). * moo->cu->curinp->colm has been incremented when the previous * character has been read. */ - if (moo->c->curinp->line > 1 && + if (moo->c->curinp->line > 1 && moo->c->curinp->colm == 2 && - moo->c->curinp->nl != moo->c->curinp->lxc.c) + moo->c->curinp->nl != moo->c->curinp->lxc.c) { - /* most likely, it's the second character in '\r\n' or '\n\r' + /* most likely, it's the second character in '\r\n' or '\n\r' * sequence. let's not update the line and column number. */ /*moo->c->curinp->colm = 1;*/ } @@ -1196,9 +1196,9 @@ static int skip_comment (moo_t* moo) if ((moo->c->pragma_flags & MOO_PRAGMA_QC) && c == '"') { /* skip up to the closing " */ - do + do { - GET_CHAR_TO (moo, c); + GET_CHAR_TO (moo, c); if (c == MOO_OOCI_EOF) goto unterminated; } while (c != '"'); @@ -1213,7 +1213,7 @@ static int skip_comment (moo_t* moo) GET_CHAR_TO (moo, c); if (c == '/') { - do + do { GET_CHAR_TO (moo, c); if (c == MOO_OOCI_EOF) @@ -1226,14 +1226,14 @@ static int skip_comment (moo_t* moo) GET_CHAR (moo); /* keep the first meaningful character in lxc */ break; } - } + } while (1); - return 1; /* single line comment led by // */ + return 1; /* single line comment led by // */ } else if (c == '*') { - do + do { GET_CHAR_TO (moo, c); if (c == MOO_OOCI_EOF) goto unterminated; @@ -1251,12 +1251,12 @@ static int skip_comment (moo_t* moo) break; } } - } + } while (1); return 1; /* multi-line comment enclosed in /x and x/ where x is * */ } - + goto not_comment; } else if (c == '#') @@ -1269,7 +1269,7 @@ static int skip_comment (moo_t* moo) GET_CHAR_TO (moo, c); if (c != '!') goto not_comment; - do + do { GET_CHAR_TO (moo, c); if (c == MOO_OOCI_EOF) @@ -1282,12 +1282,12 @@ static int skip_comment (moo_t* moo) GET_CHAR (moo); /* keep the first meaningful character in lxc */ break; } - } + } while (1); return 1; /* single line comment led by #! */ } - else + else { /* not comment. but no next character has been consumed. * no need to unget a character */ @@ -1330,9 +1330,9 @@ static int get_ident (moo_t* moo, moo_ooci_t char_read_ahead) { ADD_TOKEN_CHAR (moo, c); GET_CHAR_TO (moo, c); - } + } - if (c == ':') + if (c == ':') { #if 0 read_more_kwsym: @@ -1340,12 +1340,12 @@ static int get_ident (moo_t* moo, moo_ooci_t char_read_ahead) SET_TOKEN_TYPE (moo, MOO_IOTOK_KEYWORD); GET_CHAR_TO (moo, c); - if (moo->c->in_array && is_leadidentchar(c)) + if (moo->c->in_array && is_leadidentchar(c)) { /* when reading an array literal, read as many characters as * would compose a normal keyword symbol literal. * for example, in #(a #b:c: x:y:) x:y: is not preceded - * by #. in an array literal, it should still be treated as + * by #. in an array literal, it should still be treated as * a symbol. */ do { @@ -1364,7 +1364,7 @@ static int get_ident (moo_t* moo, moo_ooci_t char_read_ahead) } else { - unget_char (moo, &moo->c->lxc); + unget_char (moo, &moo->c->lxc); } #else moo_iolxc_t lc = moo->c->lxc; @@ -1374,14 +1374,14 @@ static int get_ident (moo_t* moo, moo_ooci_t char_read_ahead) if (c == '=' || c == '{') { /* := or :{ appeared after an identifier */ - unget_char (moo, &moo->c->lxc); + unget_char (moo, &moo->c->lxc); unget_char (moo, &lc); } else { ADD_TOKEN_CHAR (moo, lc.c); SET_TOKEN_TYPE (moo, MOO_IOTOK_KEYWORD); - unget_char (moo, &moo->c->lxc); + unget_char (moo, &moo->c->lxc); } #endif } @@ -1411,19 +1411,19 @@ static int get_ident (moo_t* moo, moo_ooci_t char_read_ahead) while (is_identchar(c)); if (c == '.') goto read_more_seg; - unget_char (moo, &moo->c->lxc); + unget_char (moo, &moo->c->lxc); } else { - unget_char (moo, &moo->c->lxc); + unget_char (moo, &moo->c->lxc); /* unget the period itself */ - unget_char (moo, &period); + unget_char (moo, &period); } } else { - unget_char (moo, &moo->c->lxc); + unget_char (moo, &moo->c->lxc); } if (is_reserved_word(TOKEN_NAME(moo), &token_type)) @@ -1438,7 +1438,7 @@ static int get_ident (moo_t* moo, moo_ooci_t char_read_ahead) static int get_numlit (moo_t* moo, int negated) { - /* + /* * number-literal := number | ("-" number) * number := integer | float | scaledDecimal * integer := decimal-integer | radix-integer @@ -1464,7 +1464,7 @@ static int get_numlit (moo_t* moo, int negated) SET_TOKEN_TYPE (moo, MOO_IOTOK_INTLIT); /*TODO: support a complex numeric literal */ - do + do { /* collect the potential radix specifier */ if (!radix_overflowed) @@ -1495,13 +1495,13 @@ static int get_numlit (moo_t* moo, int negated) } else continue; } - } + } while (is_digitchar(c)); if (c == 'p') { /* fixed-point decimal with the scale specified. - * 5p99 -> 99.0000, 5p99.12 -> 99.12000 + * 5p99 -> 99.0000, 5p99.12 -> 99.12000 * treat the radix value as the scale */ if (radix_overflowed || radix < 1 || radix > MOO_SMOOI_MAX) @@ -1542,7 +1542,7 @@ static int get_numlit (moo_t* moo, int negated) GET_CHAR_TO (moo, c); if (xscale > 0 && c == '.') goto fixed_point; - if (c == '_') + if (c == '_') { moo_iolxc_t underscore; underscore = moo->c->lxc; @@ -1579,7 +1579,7 @@ static int get_numlit (moo_t* moo, int negated) { unget_char (moo, &moo->c->lxc); unget_char (moo, &period); - if (xscale <= 0) + if (xscale <= 0) { /* * restore the token type. it's not prefixed with 'p' like 20p. * the number is followed by a terminating period rather than a decimal point. */ @@ -1633,13 +1633,13 @@ static int get_numlit (moo_t* moo, int negated) static int get_charlit (moo_t* moo) { - /* + /* * character-literal := "$" character * character := normal-character | "'" */ moo_ooci_t c = moo->c->lxc.c; /* even a new-line or white space would be taken */ - if (c == MOO_OOCI_EOF) + if (c == MOO_OOCI_EOF) { moo_setsynerr (moo, MOO_SYNERR_CLTNT, LEXER_LOC(moo), MOO_NULL); return -1; @@ -1654,7 +1654,7 @@ static int get_charlit (moo_t* moo) static int get_strlit (moo_t* moo, int byte_only) { - /* + /* * string-literal := single-quote string-character* single-quote * string-character := normal-character | (single-quote single-quote) * single-quote := "'" @@ -1671,27 +1671,27 @@ static int get_strlit (moo_t* moo, int byte_only) if (c != oc) { - do + do { - do + do { in_strlit: if (byte_only) CHECK_BYTE_RANGE_FOR_BYTE_ARRAY (c); ADD_TOKEN_CHAR (moo, c); GET_CHAR_TO (moo, c); - if (c == MOO_OOCI_EOF) + if (c == MOO_OOCI_EOF) { /* string not closed */ moo_setsynerr (moo, MOO_SYNERR_STRNC, TOKEN_LOC(moo) /*&moo->c->lxc.l*/, MOO_NULL); return -1; } - } + } while (c != oc); /* 'c' must be a single quote at this point*/ GET_CHAR_TO (moo, c); - } + } while (c == oc); /* if the next character is a single quote, it becomes a literal single quote character. */ } else @@ -1736,9 +1736,9 @@ static int get_string (moo_t* moo, moo_ooch_t end_char, moo_ooch_t esc_char, int { c_acc = c_acc * 8 + c - '0'; digit_count++; - if (digit_count >= escaped) + if (digit_count >= escaped) { - /* should i limit the max to 0xFF/0377 regardless of byte_only? + /* should i limit the max to 0xFF/0377 regardless of byte_only? * if (c_acc > 0377) c_acc = 0377;*/ if (byte_only) CHECK_BYTE_RANGE_FOR_BYTE_ARRAY (c_acc); @@ -1762,7 +1762,7 @@ static int get_string (moo_t* moo, moo_ooch_t end_char, moo_ooch_t esc_char, int { c_acc = c_acc * 16 + c - '0'; digit_count++; - if (digit_count >= escaped) + if (digit_count >= escaped) { if (byte_only) CHECK_BYTE_RANGE_FOR_BYTE_ARRAY (c_acc); ADD_TOKEN_CHAR (moo, c_acc); @@ -1774,7 +1774,7 @@ static int get_string (moo_t* moo, moo_ooch_t end_char, moo_ooch_t esc_char, int { c_acc = c_acc * 16 + c - 'A' + 10; digit_count++; - if (digit_count >= escaped) + if (digit_count >= escaped) { if (byte_only) CHECK_BYTE_RANGE_FOR_BYTE_ARRAY (c_acc); ADD_TOKEN_CHAR (moo, c_acc); @@ -1786,7 +1786,7 @@ static int get_string (moo_t* moo, moo_ooch_t end_char, moo_ooch_t esc_char, int { c_acc = c_acc * 16 + c - 'a' + 10; digit_count++; - if (digit_count >= escaped) + if (digit_count >= escaped) { if (byte_only) CHECK_BYTE_RANGE_FOR_BYTE_ARRAY (c_acc); ADD_TOKEN_CHAR (moo, c_acc); @@ -1797,12 +1797,12 @@ static int get_string (moo_t* moo, moo_ooch_t end_char, moo_ooch_t esc_char, int else { /* \x, \u, \U not followed by a hexadecimal digit */ - if (digit_count == 0) + if (digit_count == 0) { static moo_ooch_t esc_char_tab[] = { '\0', '\0', 'x', '\0', 'u', '\0', '\0', '\0', 'U' }; ADD_TOKEN_CHAR (moo, esc_char_tab[escaped]); } - else + else { if (byte_only) CHECK_BYTE_RANGE_FOR_BYTE_ARRAY (c_acc); ADD_TOKEN_CHAR (moo, c_acc); @@ -1832,7 +1832,7 @@ static int get_string (moo_t* moo, moo_ooch_t end_char, moo_ooch_t esc_char, int else if (c == 'b') c = '\b'; else if (c == 'v') c = '\v'; else if (c == 'a') c = '\a'; - else if (c >= '0' && c <= '7' && !regex) + else if (c >= '0' && c <= '7' && !regex) { /* i don't support the octal notation for a regular expression. * it conflicts with the backreference notation between \1 and \7 inclusive. */ @@ -1841,33 +1841,33 @@ static int get_string (moo_t* moo, moo_ooch_t end_char, moo_ooch_t esc_char, int c_acc = c - '0'; continue; } - else if (c == 'x') + else if (c == 'x') { escaped = 2; digit_count = 0; c_acc = 0; continue; } - else if (!byte_only && c == 'u' && MOO_SIZEOF(moo_ooch_t) >= 2) + else if (!byte_only && c == 'u' && MOO_SIZEOF(moo_ooch_t) >= 2) { escaped = 4; digit_count = 0; c_acc = 0; continue; } - else if (!byte_only && c == 'U' && MOO_SIZEOF(moo_ooch_t) >= 4) + else if (!byte_only && c == 'U' && MOO_SIZEOF(moo_ooch_t) >= 4) { escaped = 8; digit_count = 0; c_acc = 0; continue; } - else if (regex) + else if (regex) { /* if the following character doesn't compose a proper - * escape sequence, keep the escape character. - * an unhandled escape sequence can be handled - * outside this function since the escape character + * escape sequence, keep the escape character. + * an unhandled escape sequence can be handled + * outside this function since the escape character * is preserved.*/ ADD_TOKEN_CHAR (moo, esc_char); } @@ -1890,7 +1890,7 @@ static int get_string (moo_t* moo, moo_ooch_t end_char, moo_ooch_t esc_char, int static int get_binsel (moo_t* moo) { - /* + /* * binary-selector := binary-selector-character+ */ moo_ooci_t oc; @@ -1904,7 +1904,7 @@ static int get_binsel (moo_t* moo) #if 1 /* up to 2 characters only */ - if (is_binselchar (moo->c->lxc.c)) + if (is_binselchar (moo->c->lxc.c)) { ADD_TOKEN_CHAR (moo, moo->c->lxc.c); } @@ -1914,7 +1914,7 @@ static int get_binsel (moo_t* moo) } #else /* or up to any occurrences */ - while (is_binselchar(moo->c->lxc.c)) + while (is_binselchar(moo->c->lxc.c)) { ADD_TOKEN_CHAR (moo, c); GET_CHAR (moo); @@ -1934,13 +1934,13 @@ static int get_token (moo_t* moo) retry: GET_CHAR (moo); - do + do { /* skip spaces */ while (is_spacechar(moo->c->lxc.c)) GET_CHAR (moo); /* the first character after the last space is in moo->c->lxc */ if ((n = skip_comment(moo)) <= -1) return -1; - } + } while (n >= 1); /* clear the token name, reset its location */ @@ -1978,7 +1978,7 @@ retry: SET_TOKEN_TYPE (moo, MOO_IOTOK_COLON); ADD_TOKEN_CHAR (moo, c); GET_CHAR_TO (moo, c); - if (c == '=') + if (c == '=') { SET_TOKEN_TYPE (moo, MOO_IOTOK_ASSIGN); ADD_TOKEN_CHAR (moo, c); @@ -2015,7 +2015,7 @@ retry: case '[': SET_TOKEN_TYPE (moo, MOO_IOTOK_LBRACK); goto single_char_token; - case ']': + case ']': SET_TOKEN_TYPE (moo, MOO_IOTOK_RBRACK); goto single_char_token; case '(': @@ -2034,7 +2034,7 @@ retry: SET_TOKEN_TYPE (moo, MOO_IOTOK_SEMICOLON); goto single_char_token; - case '#': + case '#': ADD_TOKEN_CHAR (moo, c); GET_CHAR_TO (moo, c); switch (c) @@ -2067,14 +2067,14 @@ retry: } else { - /* NOTE the double hashes not followed by (, [, or { is + /* NOTE the double hashes not followed by (, [, or { is * meaningless at this moment. however, i return - * it as a token so that the compiler anyway + * it as a token so that the compiler anyway * will fail eventually */ unget_char (moo, &moo->c->lxc); } break; - + case '(': /* #( - array literal */ ADD_TOKEN_CHAR (moo, c); @@ -2092,7 +2092,7 @@ retry: ADD_TOKEN_CHAR (moo, c); SET_TOKEN_TYPE (moo, MOO_IOTOK_HASHBRACE); break; - + case '\'': /* #'XXXX' - quoted symbol literal */ if (get_strlit(moo, 0) <= -1) return -1; /* reuse the string literal tokenizer */ @@ -2162,27 +2162,27 @@ retry: default: /* symbol-literal := "#" symbol-body * symbol-body := identifier | keyword+ | binary-selector | string-literal - */ + */ /* unquoted symbol literal */ if (is_binselchar(c)) { - do + do { ADD_TOKEN_CHAR (moo, c); GET_CHAR_TO (moo, c); - } + } while (is_binselchar(c)); unget_char (moo, &moo->c->lxc); } - else if (is_leadidentchar(c)) + else if (is_leadidentchar(c)) { - do + do { ADD_TOKEN_CHAR (moo, c); GET_CHAR_TO (moo, c); - } + } while (is_identchar(c)); if (c == ':') @@ -2194,11 +2194,11 @@ retry: if (is_leadidentchar(c)) { - do + do { ADD_TOKEN_CHAR (moo, c); GET_CHAR_TO (moo, c); - } + } while (is_identchar(c)); if (c == ':') goto read_more_word; @@ -2242,13 +2242,13 @@ retry: } else { - unget_char (moo, &moo->c->lxc); - unget_char (moo, &period); + unget_char (moo, &moo->c->lxc); + unget_char (moo, &period); } } else { - unget_char (moo, &moo->c->lxc); + unget_char (moo, &moo->c->lxc); } } else @@ -2340,20 +2340,20 @@ retry: */ default: - if (is_leadidentchar(c)) + if (is_leadidentchar(c)) { if (get_ident(moo, MOO_OOCI_EOF) <= -1) return -1; } - else if (is_digitchar(c)) + else if (is_digitchar(c)) { if (get_numlit(moo, 0) <= -1) return -1; } - else if (is_binselchar(c)) + else if (is_binselchar(c)) { /* binary selector */ if (get_binsel(moo) <= -1) return -1; } - else + else { moo->c->ilchr = (moo_ooch_t)c; moo_setsynerr (moo, MOO_SYNERR_ILCHR, LEXER_LOC(moo), &moo->c->ilchr_ucs); @@ -2423,7 +2423,7 @@ static int begin_include (moo_t* moo) /*arg->nl = '\0';*/ arg->includer = moo->c->curinp; - if (moo->c->impl(moo, MOO_IO_OPEN, arg) <= -1) + if (moo->c->impl(moo, MOO_IO_OPEN, arg) <= -1) { moo_setsynerr (moo, MOO_SYNERR_INCLUDE, TOKEN_LOC(moo), TOKEN_NAME(moo)); goto oops; @@ -2441,13 +2441,13 @@ static int begin_include (moo_t* moo) moo->c->curinp = arg; /* moo->c->depth.incl++; */ - /* read in the first character in the included file. + /* read in the first character in the included file. * so the next call to get_token() sees the character read * from this file. */ - if (get_token(moo) <= -1) + if (get_token(moo) <= -1) { - end_include (moo); - /* i don't jump to oops since i've called + end_include (moo); + /* i don't jump to oops since i've called * end_include() which frees moo->c->curinp/arg */ return -1; } @@ -2473,8 +2473,8 @@ static int end_include (moo_t* moo) /* if closing has failed, still destroy the * sio structure first as normal and return - * the failure below. this way, the caller - * does not call MOO_IO_CLOSE on + * the failure below. this way, the caller + * does not call MOO_IO_CLOSE on * moo->c->curinp again. */ cur = moo->c->curinp; @@ -2500,9 +2500,9 @@ static int end_include (moo_t* moo) static MOO_INLINE int add_literal (moo_t* moo, moo_oop_t lit, moo_oow_t* index) { - /* - * this removes redundancy of symbols, characters, and small integers. - * more complex redundacy check may be done somewhere else like + /* + * this removes redundancy of symbols, characters, and small integers. + * more complex redundacy check may be done somewhere else like * in add_string_literal(). */ moo_method_data_t* md = get_cunit_method_data(moo); @@ -2515,13 +2515,13 @@ static int add_string_literal (moo_t* moo, const moo_oocs_t* str, moo_oow_t* ind moo_oop_t lit; moo_oow_t i; - for (i = 0; i < md->literals.count; i++) + for (i = 0; i < md->literals.count; i++) { lit = md->literals.ptr[i]; - if (MOO_CLASSOF(moo, lit) == moo->_string && + if (MOO_CLASSOF(moo, lit) == moo->_string && MOO_OBJ_GET_SIZE(lit) == str->len && - moo_equal_oochars(MOO_OBJ_GET_CHAR_SLOT(lit), str->ptr, str->len)) + moo_equal_oochars(MOO_OBJ_GET_CHAR_SLOT(lit), str->ptr, str->len)) { *index = i; return 0; @@ -2603,7 +2603,7 @@ static MOO_INLINE int emit_byte_instruction (moo_t* moo, moo_oob_t code, const m } md->code.ptr[md->code.len] = code; - if (srcloc) + if (srcloc) { if (srcloc->file == md->start_loc.file && srcloc->line >= md->start_loc.line) { @@ -2707,7 +2707,7 @@ write_short: return 0; write_long: - if (param_1 > MAX_CODE_PARAM) + if (param_1 > MAX_CODE_PARAM) { moo_seterrnum (moo, MOO_ERANGE); return -1; @@ -2765,7 +2765,7 @@ write_short: return 0; write_long: - if (param_1 > MAX_CODE_PARAM || param_2 > MAX_CODE_PARAM) + if (param_1 > MAX_CODE_PARAM || param_2 > MAX_CODE_PARAM) { moo_seterrnum (moo, MOO_ERANGE); return -1; @@ -2777,7 +2777,7 @@ write_long: emit_byte_instruction(moo, (param_2 >> 8) & 0xFF, srcloc) <= -1 || emit_byte_instruction(moo, param_2 & 0xFF, srcloc) <= -1) return -1; #else - + if (emit_byte_instruction(moo, bc, srcloc) <= -1 || emit_byte_instruction(moo, param_1, srcloc) <= -1 || emit_byte_instruction(moo, param_2, srcloc) <= -1) return -1; @@ -2875,7 +2875,7 @@ static int patch_forward_jump_instruction (moo_t* moo, moo_oow_t jip, moo_oow_t else { /* jip - jump instruction pointer, jt - jump target * - * + * * when this jump instruction is executed, the instruction pointer advances * to the next instruction. so the actual jump size gets offset by the size * of this jump instruction. MOO_BCODE_LONG_PARAM_SIZE + 1 is the size of @@ -2942,7 +2942,7 @@ static int update_loop_jumps (moo_t* moo, moo_oow_pool_t* pool, moo_oow_t jt) for (j = 0; j < MOO_COUNTOF(pool->static_chunk.buf) && i < pool->count; j++) { if (chunk->buf[j].v != INVALID_IP && - patch_forward_jump_instruction(moo, chunk->buf[j].v, jt) <= -1) + patch_forward_jump_instruction(moo, chunk->buf[j].v, jt) <= -1) { moo_setsynerrbfmt (moo, MOO_SYNERR_INSTFLOOD, &chunk->buf[j].loc, MOO_NULL, "unable to patch conditional loop jump"); return -1; @@ -2966,7 +2966,7 @@ static void adjust_loop_jumps_for_elimination (moo_t* moo, moo_oow_pool_t* pool, { if (chunk->buf[j].v != INVALID_IP) { - if (chunk->buf[j].v >= start && chunk->buf[j].v <= end) + if (chunk->buf[j].v >= start && chunk->buf[j].v <= end) { /* invalidate the instruction position */ chunk->buf[j].v = INVALID_IP; @@ -3018,7 +3018,7 @@ static MOO_INLINE void adjust_all_gotos_for_elimination (moo_t* moo, moo_oow_t s { if (_goto->ip >= start && _goto->ip <= end) { - /* invalidate this entry since the goto instruction itself is getting eliminated. + /* invalidate this entry since the goto instruction itself is getting eliminated. * i don't kill this node. the resolver must skip this node. */ _goto->ip = INVALID_IP; } @@ -3088,7 +3088,7 @@ static MOO_INLINE int inject_break_to_loop (moo_t* moo, const moo_ioloc_t* srclo static MOO_INLINE int inject_continue_to_loop (moo_t* moo, const moo_ioloc_t* srcloc) { moo_method_data_t* md = get_cunit_method_data(moo); - /* used for a do-while loop. jump forward because the conditional + /* used for a do-while loop. jump forward because the conditional * is at the end of the do-while loop */ if (add_to_oow_pool(moo, &md->loop->continue_ip_pool, md->code.len, srcloc) <= -1 || emit_single_param_instruction(moo, BCODE_JUMP_FORWARD, MAX_CODE_JUMP, srcloc) <= -1) return -1; @@ -3186,7 +3186,7 @@ static MOO_INLINE int add_class_level_variable (moo_t* moo, var_type_t var_type, MOO_ASSERT (moo, moo->c->cunit->cunit_type == MOO_CUNIT_CLASS); n = copy_string_to(moo, name, &cc->var[var_type].str, &cc->var[var_type].str_capa, 1, ' '); - if (n >= 0) + if (n >= 0) { static moo_oow_t varlim[] = { @@ -3237,11 +3237,11 @@ static int set_class_level_variable_initv (moo_t* moo, var_type_t var_type, moo_ cc->var[var_type].initv_capa = newcapa; } - if (var_index >= cc->var[var_type].initv_count) + if (var_index >= cc->var[var_type].initv_count) { moo_oow_t i; - for (i = cc->var[var_type].initv_count; i < var_index; i++) + for (i = cc->var[var_type].initv_count; i < var_index; i++) { cc->var[var_type].initv[i].v = MOO_NULL; cc->var[var_type].initv[i].flags = 0; @@ -3282,7 +3282,7 @@ static moo_ooi_t find_class_level_variable (moo_t* moo, moo_oop_class_t self, co { MOO_ASSERT (moo, MOO_CLASSOF(moo, self) == moo->_class); - /* [NOTE] + /* [NOTE] * the loop here assumes that the class has the following * fields in the order shown below: * instvars @@ -3302,7 +3302,7 @@ static moo_ooi_t find_class_level_variable (moo_t* moo, moo_oop_class_t self, co MOO_ASSERT (moo, super == cc->super_oop); /* 'self' may be MOO_NULL if MOO_NULL has been given for it. - * the caller must take good care when interpreting the meaning of + * the caller must take good care when interpreting the meaning of * this field */ var->cls = self; goto done; @@ -3332,7 +3332,7 @@ static moo_ooi_t find_class_level_variable (moo_t* moo, moo_oop_class_t self, co { MOO_ASSERT (moo, MOO_CLASSOF(moo, super) == moo->_class); - /* [NOTE] + /* [NOTE] * the loop here assumes that the class has the following * fields in the order shown below: * instvars @@ -3350,9 +3350,9 @@ static moo_ooi_t find_class_level_variable (moo_t* moo, moo_oop_class_t self, co { /* class variables reside in the class where the definition is found. * that means a class variable is found in the definition of - * a superclass, the superclass is the placeholder of the + * a superclass, the superclass is the placeholder of the * class variable. on the other hand, instance variables and - * class instance variables live in the current class being + * class instance variables live in the current class being * compiled as they are inherited. */ var->cls = (index == VAR_CLASS)? (moo_oop_class_t)super: self; super = ((moo_oop_class_t)super)->superclass; @@ -3377,7 +3377,7 @@ done: switch (index) { case VAR_INSTANCE: - /* each class has the number of named instance variables + /* each class has the number of named instance variables * accumulated for inheritance. the position found in the * local variable string can be adjusted by adding the * number in the superclass */ @@ -3394,8 +3394,8 @@ done: /* [NOTE] * no adjustment is needed. * a class object is composed of three parts. - * fixed-part | classinst-variables | class-variabes - * the position returned here doesn't consider + * fixed-part | classinst-variables | class-variabes + * the position returned here doesn't consider * class instance variables that can be potentially * placed before the class variables. */ break; @@ -3538,7 +3538,7 @@ static moo_oop_nsdic_t add_namespace (moo_t* moo, moo_oop_nsdic_t dic, const moo ass = moo_putatdic(moo, (moo_oop_dic_t)dic, (moo_oop_t)sym, (moo_oop_t)nsdic); if (!ass) goto oops; - nsdic = (moo_oop_nsdic_t)ass->value; + nsdic = (moo_oop_nsdic_t)ass->value; MOO_STORE_OOP (moo, &nsdic->nsup, (moo_oop_t)dic); MOO_STORE_OOP (moo, (moo_oop_t*)&nsdic->name, (moo_oop_t)sym); @@ -3675,7 +3675,7 @@ static int preprocess_dotted_name (moo_t* moo, int flags, moo_oop_nsdic_t topdic { /* A pool dictionary is treated as if it's a name space. * However, the pool dictionary can only act as a name space - * if it's the second last segment. A pool dictionary + * if it's the second last segment. A pool dictionary * cannot be nested in another pool dictionary */ dic = (moo_oop_nsdic_t)ass->value; pooldic_gotten = 1; @@ -3696,7 +3696,7 @@ static int preprocess_dotted_name (moo_t* moo, int flags, moo_oop_nsdic_t topdic * if Planet doesn't exist */ goto wrong_name; } - + /* When definining a new class, add a missing namespace */ t = add_namespace(moo, dic, &seg); if (!t) return -1; @@ -3948,7 +3948,7 @@ if super is variable-nonpointer, no instance variable is allowed. GET_TOKEN (moo); /* [NOTE] default value assignment. only a literal is allowed. - * the initial values for instance variables and + * the initial values for instance variables and * class instance variables are set to read-only. * I may change this if i get the actual initial * value assignment upon instantiation to employ @@ -4034,7 +4034,7 @@ static int compile_class_level_imports (moo_t* moo) dcl_type = IMPORT_POOLDIC; GET_TOKEN (moo); } - else + else #endif if (TOKEN_TYPE(moo) == MOO_IOTOK_COMMA || TOKEN_TYPE(moo) == MOO_IOTOK_EOF || TOKEN_TYPE(moo) == MOO_IOTOK_RPAREN) { @@ -4075,7 +4075,7 @@ static int compile_class_level_imports (moo_t* moo) { last = *TOKEN_NAME(moo); /* it falls back to the name space of the class */ - ns_oop = cc->ns_oop; + ns_oop = cc->ns_oop; } else if (TOKEN_TYPE(moo) == MOO_IOTOK_COMMA || TOKEN_TYPE(moo) == MOO_IOTOK_EOF || TOKEN_TYPE(moo) == MOO_IOTOK_PERIOD) { @@ -4131,7 +4131,7 @@ static int compile_unary_method_name (moo_t* moo) { do { - if (TOKEN_TYPE(moo) != MOO_IOTOK_IDENT) + if (TOKEN_TYPE(moo) != MOO_IOTOK_IDENT) { /* wrong argument name. identifier is expected */ moo_setsynerr (moo, MOO_SYNERR_IDENT, TOKEN_LOC(moo), TOKEN_NAME(moo)); @@ -4146,7 +4146,7 @@ static int compile_unary_method_name (moo_t* moo) if (add_temporary_variable(moo, TOKEN_NAME(moo)) <= -1) return -1; md->tmpr_nargs++; - GET_TOKEN (moo); + GET_TOKEN (moo); if (TOKEN_TYPE(moo) == MOO_IOTOK_RPAREN) break; @@ -4157,7 +4157,7 @@ static int compile_unary_method_name (moo_t* moo) } GET_TOKEN (moo); - } + } while (1); } @@ -4179,7 +4179,7 @@ static int compile_binary_method_name (moo_t* moo) GET_TOKEN (moo); /* collect the argument name */ - if (TOKEN_TYPE(moo) != MOO_IOTOK_IDENT) + if (TOKEN_TYPE(moo) != MOO_IOTOK_IDENT) { /* wrong argument name. identifier expected */ moo_setsynerr (moo, MOO_SYNERR_IDENT, TOKEN_LOC(moo), TOKEN_NAME(moo)); @@ -4213,12 +4213,12 @@ static int compile_keyword_method_name (moo_t* moo) MOO_ASSERT (moo, md->name.len == 0); MOO_ASSERT (moo, md->tmpr_nargs == 0); - do + do { if (add_method_name_fragment(moo, TOKEN_NAME(moo)) <= -1) return -1; GET_TOKEN (moo); - if (TOKEN_TYPE(moo) != MOO_IOTOK_IDENT) + if (TOKEN_TYPE(moo) != MOO_IOTOK_IDENT) { /* wrong argument name. identifier is expected */ moo_setsynerr (moo, MOO_SYNERR_IDENT, TOKEN_LOC(moo), TOKEN_NAME(moo)); @@ -4235,7 +4235,7 @@ static int compile_keyword_method_name (moo_t* moo) md->tmpr_nargs++; GET_TOKEN (moo); - } + } while (TOKEN_TYPE(moo) == MOO_IOTOK_KEYWORD); return 0; @@ -4243,7 +4243,7 @@ static int compile_keyword_method_name (moo_t* moo) static int compile_method_name (moo_t* moo) { - /* + /* * method-name := unary-method-name | binary-method-name | keyword-method-name * unary-method-name := unary-selector * binary-method-name := binary-selector selector-argument @@ -4280,7 +4280,7 @@ static int compile_method_name (moo_t* moo) if (n <= -1) return -1; - if (method_exists_noseterr(moo, &md->name)) + if (method_exists_noseterr(moo, &md->name)) { moo_setsynerr (moo, MOO_SYNERR_MTHNAMEDUPL, &md->name_loc, &md->name); return -1; @@ -4294,7 +4294,7 @@ static int compile_method_name (moo_t* moo) } MOO_ASSERT (moo, md->tmpr_nargs < MAX_CODE_NARGS); - /* the total number of temporaries is equal to the number of + /* the total number of temporaries is equal to the number of * arguments after having processed the message pattern. it's because * moo treats arguments the same as temporaries */ md->tmpr_count = md->tmpr_nargs; @@ -4303,13 +4303,13 @@ static int compile_method_name (moo_t* moo) static int compile_method_temporaries (moo_t* moo) { - /* + /* * method-temporaries := "|" variable-list "|" * variable-list := identifier* */ moo_method_data_t* md = get_cunit_method_data(moo); - if (!is_token_binary_selector(moo, VOCA_VBAR)) + if (!is_token_binary_selector(moo, VOCA_VBAR)) { /* return without doing anything if | is not found. * this is not an error condition */ @@ -4317,11 +4317,11 @@ static int compile_method_temporaries (moo_t* moo) } GET_TOKEN (moo); - while (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT) + while (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT) { - /* a temporary variable name may get the same as a class level variable name + /* a temporary variable name may get the same as a class level variable name * or even a class name in such as case, it shadows the class level variable - * name or the class name. however, it can't be the same as another temporary + * name or the class name. however, it can't be the same as another temporary * variable */ if (find_temporary_variable(moo, TOKEN_NAME(moo), MOO_NULL) >= 0) { @@ -4341,7 +4341,7 @@ static int compile_method_temporaries (moo_t* moo) GET_TOKEN (moo); } - if (!is_token_binary_selector(moo, VOCA_VBAR)) + if (!is_token_binary_selector(moo, VOCA_VBAR)) { moo_setsynerr (moo, MOO_SYNERR_VBAR, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; @@ -4353,7 +4353,7 @@ static int compile_method_temporaries (moo_t* moo) static int compile_method_pragma (moo_t* moo) { - /* + /* * method-pragma := "<" "primitive:" integer ">" | * "<" "primitive:" symbol ">" | * "<" "exception" ">" | @@ -4363,7 +4363,7 @@ static int compile_method_pragma (moo_t* moo) moo_ooi_t pfnum; const moo_ooch_t* ptr, * end; - if (!is_token_binary_selector(moo, VOCA_LT)) + if (!is_token_binary_selector(moo, VOCA_LT)) { /* return if < is not seen. it is not an error condition */ return 0; @@ -4372,7 +4372,7 @@ static int compile_method_pragma (moo_t* moo) GET_TOKEN (moo); if (is_token_keyword(moo, VOCA_PRIMITIVE_COLON)) { - GET_TOKEN (moo); + GET_TOKEN (moo); switch (TOKEN_TYPE(moo)) { case MOO_IOTOK_INTLIT: @@ -4380,7 +4380,7 @@ static int compile_method_pragma (moo_t* moo) ptr = TOKEN_NAME_PTR(moo); end = ptr + TOKEN_NAME_LEN(moo); pfnum = 0; - while (ptr < end && is_digitchar(*ptr)) + while (ptr < end && is_digitchar(*ptr)) { pfnum = pfnum * 10 + (*ptr - '0'); if (!MOO_OOI_IN_METHOD_PREAMBLE_INDEX_RANGE(pfnum)) @@ -4410,7 +4410,7 @@ static int compile_method_pragma (moo_t* moo) pfbase = moo_getpfnum(moo, tptr, tlen, &pfnum); if (!pfbase) { - /* a built-in primitive function is not found + /* a built-in primitive function is not found * check if it is a primitive function identifier */ moo_oow_t lit_idx; @@ -4434,7 +4434,7 @@ static int compile_method_pragma (moo_t* moo) if (cc->mth.tmpr_nargs < pfbase->minargs || cc->mth.tmpr_nargs > pfbase->maxargs) { - MOO_DEBUG5 (moo, "Unsupported argument count in primitive method definition of %.*js - %zd-%zd expected, %zd specified\n", + MOO_DEBUG5 (moo, "Unsupported argument count in primitive method definition of %.*js - %zd-%zd expected, %zd specified\n", tlen, tptr, pfbase->minargs, pfbase->maxargs, cc->mth.tmpr_nargs); moo_setsynerr (moo, MOO_SYNERR_PFARGDEFINVAL, &cc->mth.name_loc, &cc->mth.name); return -1; @@ -4446,7 +4446,7 @@ static int compile_method_pragma (moo_t* moo) * so the index to the symbol registered should be very small like 0 */ MOO_ASSERT (moo, MOO_OOI_IN_METHOD_PREAMBLE_INDEX_RANGE(lit_idx)); - cc->mth.pftype = PFTYPE_NAMED; + cc->mth.pftype = PFTYPE_NAMED; cc->mth.pfnum = lit_idx; } else if (!MOO_OOI_IN_METHOD_PREAMBLE_INDEX_RANGE(pfnum)) @@ -4458,13 +4458,13 @@ static int compile_method_pragma (moo_t* moo) { if (cc->mth.tmpr_nargs < pfbase->minargs || cc->mth.tmpr_nargs > pfbase->maxargs) { - MOO_DEBUG5 (moo, "Unsupported argument count in primitive method definition of %.*js - %zd-%zd expected, %zd specified\n", + MOO_DEBUG5 (moo, "Unsupported argument count in primitive method definition of %.*js - %zd-%zd expected, %zd specified\n", tlen, tptr, pfbase->minargs, pfbase->maxargs, cc->mth.tmpr_nargs); moo_setsynerr (moo, MOO_SYNERR_PFARGDEFINVAL, &cc->mth.name_loc, &cc->mth.name); return -1; } - cc->mth.pftype = PFTYPE_NUMBERED; + cc->mth.pftype = PFTYPE_NUMBERED; cc->mth.pfnum = pfnum; } @@ -4479,7 +4479,7 @@ static int compile_method_pragma (moo_t* moo) } else if (is_token_word(moo, VOCA_EXCEPTION)) { -/* TODO: exception handler is supposed to be used by BlockContext on:do:. +/* TODO: exception handler is supposed to be used by BlockContext on:do:. * it needs to check the number of arguments at least */ cc->mth.pftype = PFTYPE_EXCEPTION; } @@ -4494,7 +4494,7 @@ static int compile_method_pragma (moo_t* moo) } GET_TOKEN (moo); - if (!is_token_binary_selector(moo, VOCA_GT)) + if (!is_token_binary_selector(moo, VOCA_GT)) { moo_setsynerr (moo, MOO_SYNERR_GT, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; @@ -4540,7 +4540,7 @@ static int validate_class_level_variable (moo_t* moo, var_info_t* var, const moo /* increment the position by the number of class instance variables * as the class variables are placed after the class instance variables */ - var->pos += MOO_CLASS_NAMED_INSTVARS + + var->pos += MOO_CLASS_NAMED_INSTVARS + MOO_CLASS_SELFSPEC_CLASSINSTVARS(MOO_OOP_TO_SMOOI(var->cls->selfspec)); break; @@ -4565,7 +4565,7 @@ static moo_oow_t is_dotted_ident_prefixed (const moo_oocs_t* name, int voca_id) static MOO_INLINE int find_dotted_ident (moo_t* moo, const moo_oocs_t* name, const moo_ioloc_t* name_loc, var_info_t* var) { /* if a name is dotted, - * + * * self.XXX - instance variable * A.B.C - namespace or pool dictionary related reference. * self.B.C - B.C under the current class where B is not an instance variable @@ -4635,7 +4635,7 @@ static MOO_INLINE int find_dotted_ident (moo_t* moo, const moo_oocs_t* name, con if (cc->in_class_body) { - /* [NOTE] + /* [NOTE] * cls.ns_oop is set when the class name is enountered. * cls.super_oop is set when the parent class name is enountered. * cls.super_oop may still be MOO_NULL even if cls.ns_oop is not. @@ -4648,7 +4648,7 @@ static MOO_INLINE int find_dotted_ident (moo_t* moo, const moo_oocs_t* name, con if (find_class_level_variable(moo, cc->self_oop, &last, var) >= 0) { - /* if the current class has not been instantiated, + /* if the current class has not been instantiated, * no validation nor adjustment of the var->pos field is performed */ if (cc->self_oop && validate_class_level_variable(moo, var, name, name_loc) <= -1) return -1; return 0; @@ -4684,7 +4684,7 @@ static MOO_INLINE int find_dotted_ident (moo_t* moo, const moo_oocs_t* name, con case MOO_CUNIT_POOLDIC: /* a pooldic definition cannot contain subdictionaries. * the pooldic is a terminal point and the items inside - * are final nodes. if self is followed by more than 1 + * are final nodes. if self is followed by more than 1 * subsegments, it's an error. */ goto varinacc; @@ -4828,7 +4828,7 @@ static MOO_INLINE int find_undotted_ident (moo_t* moo, const moo_oocs_t* name, c if (cc->ns_oop) { ass = moo_lookupdic_noseterr(moo, (moo_oop_dic_t)cc->ns_oop, name); /* in the current name space */ - if (!ass && cc->ns_oop != moo->sysdic) + if (!ass && cc->ns_oop != moo->sysdic) ass = moo_lookupdic_noseterr(moo, (moo_oop_dic_t)moo->sysdic, name); /* in the top-level system dictionary */ } else @@ -4858,7 +4858,7 @@ static MOO_INLINE int find_undotted_ident (moo_t* moo, const moo_oocs_t* name, c } ass = ass2; - if (!ass) + if (!ass) { moo_setsynerr (moo, MOO_SYNERR_VARUNDCL, name_loc, name); return -1; @@ -4889,7 +4889,7 @@ static MOO_INLINE int find_undotted_ident (moo_t* moo, const moo_oocs_t* name, c if (ifce->ns_oop) { ass = moo_lookupdic_noseterr(moo, (moo_oop_dic_t)ifce->ns_oop, name); /* in the current name space */ - if (!ass && ifce->ns_oop != moo->sysdic) + if (!ass && ifce->ns_oop != moo->sysdic) ass = moo_lookupdic_noseterr(moo, (moo_oop_dic_t)moo->sysdic, name); /* in the top-level system dictionary */ } else @@ -4930,7 +4930,7 @@ static int get_variable_info (moo_t* moo, const moo_oocs_t* name, const moo_iolo * i assume the functions above don't taint the var-type field when it's meaningless. */ if (var->pos > MAX_CODE_INDEX) { - /* the assignee is not usable because its index is too large + /* the assignee is not usable because its index is too large * to be expressed in byte-codes. */ moo_setsynerr (moo, MOO_SYNERR_VARUNUSE, name_loc, name); return -1; @@ -4941,13 +4941,13 @@ static int get_variable_info (moo_t* moo, const moo_oocs_t* name, const moo_iolo static int compile_block_temporaries (moo_t* moo) { - /* + /* * block-temporaries := "|" variable-list "|" * variable-list := identifier* */ moo_method_data_t* md = get_cunit_method_data(moo); - if (!is_token_binary_selector(moo, VOCA_VBAR)) + if (!is_token_binary_selector(moo, VOCA_VBAR)) { /* return without doing anything if | is not found. * this is not an error condition */ @@ -4955,7 +4955,7 @@ static int compile_block_temporaries (moo_t* moo) } GET_TOKEN (moo); - while (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT) + while (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT) { if (find_temporary_variable(moo, TOKEN_NAME(moo), MOO_NULL) >= 0) { @@ -4967,14 +4967,14 @@ static int compile_block_temporaries (moo_t* moo) md->tmpr_count++; if (md->tmpr_count > MAX_CODE_NTMPRS) { - moo_setsynerr (moo, MOO_SYNERR_TMPRFLOOD, TOKEN_LOC(moo), TOKEN_NAME(moo)); + moo_setsynerr (moo, MOO_SYNERR_TMPRFLOOD, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } GET_TOKEN (moo); } - if (!is_token_binary_selector(moo, VOCA_VBAR)) + if (!is_token_binary_selector(moo, VOCA_VBAR)) { moo_setsynerr (moo, MOO_SYNERR_VBAR, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; @@ -5026,12 +5026,12 @@ static int compile_block_expression (moo_t* moo) /* this function expects [ not to be consumed away */ MOO_ASSERT (moo, TOKEN_TYPE(moo) == MOO_IOTOK_LBRACK); - if (md->loop) + if (md->loop) { /* this [] block is placed inside the {} loop. - * this counter is used to check if 'break' or 'countinue' is + * this counter is used to check if 'break' or 'countinue' is * placed inside [], which is prohibited. */ - md->loop->blkcount++; + md->loop->blkcount++; } block_loc = *TOKEN_LOC(moo); GET_TOKEN (moo); @@ -5041,16 +5041,16 @@ static int compile_block_expression (moo_t* moo) MOO_ASSERT (moo, md->blk_depth > 0); MOO_ASSERT (moo, md->blk_tmprcnt[md->blk_depth - 1] == saved_tmpr_count); - if (TOKEN_TYPE(moo) == MOO_IOTOK_COLON) + if (TOKEN_TYPE(moo) == MOO_IOTOK_COLON) { colon_loc = moo->c->tok.loc; /* block temporary variables - argument to blocks */ - do + do { GET_TOKEN (moo); - if (TOKEN_TYPE(moo) != MOO_IOTOK_IDENT) + if (TOKEN_TYPE(moo) != MOO_IOTOK_IDENT) { /* wrong argument name. identifier expected */ moo_setsynerr (moo, MOO_SYNERR_IDENT, TOKEN_LOC(moo), TOKEN_NAME(moo)); @@ -5068,12 +5068,12 @@ static int compile_block_expression (moo_t* moo) md->tmpr_count++; if (md->tmpr_count > MAX_CODE_NARGS) { - moo_setsynerr (moo, MOO_SYNERR_BLKARGFLOOD, TOKEN_LOC(moo), TOKEN_NAME(moo)); + moo_setsynerr (moo, MOO_SYNERR_BLKARGFLOOD, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } GET_TOKEN (moo); - } + } while (TOKEN_TYPE(moo) == MOO_IOTOK_COLON); if (!is_token_binary_selector(moo, VOCA_VBAR)) @@ -5092,7 +5092,7 @@ static int compile_block_expression (moo_t* moo) * block arguments, evaluation which is done by message passing * limits the number of arguments that can be passed. so the * check is implemented */ - moo_setsynerr (moo, MOO_SYNERR_BLKARGFLOOD, &colon_loc, MOO_NULL); + moo_setsynerr (moo, MOO_SYNERR_BLKARGFLOOD, &colon_loc, MOO_NULL); return -1; } @@ -5103,7 +5103,7 @@ static int compile_block_expression (moo_t* moo) block_tmpr_count = md->tmpr_count - saved_tmpr_count; if (block_tmpr_count > MAX_CODE_NBLKTMPRS) { - moo_setsynerr (moo, MOO_SYNERR_BLKTMPRFLOOD, &tmpr_loc, MOO_NULL); + moo_setsynerr (moo, MOO_SYNERR_BLKTMPRFLOOD, &tmpr_loc, MOO_NULL); return -1; } @@ -5116,13 +5116,13 @@ static int compile_block_expression (moo_t* moo) /* insert dummy instructions before replacing them with a jump instruction */ jump_inst_pos = md->code.len; - /* specifying MAX_CODE_JUMP causes emit_single_param_instruction() to + /* specifying MAX_CODE_JUMP causes emit_single_param_instruction() to * produce the long jump instruction (BCODE_JUMP_FORWARD) */ if (emit_single_param_instruction(moo, BCODE_JUMP_FORWARD, MAX_CODE_JUMP, &block_loc) <= -1) return -1; /* compile statements inside a block */ code_start = md->code.len; - if (emit_byte_instruction(moo, BCODE_PUSH_NIL, TOKEN_LOC(moo)) <= -1) return -1; + if (emit_byte_instruction(moo, BCODE_PUSH_NIL, TOKEN_LOC(moo)) <= -1) return -1; if (TOKEN_TYPE(moo) != MOO_IOTOK_RBRACK) { @@ -5147,7 +5147,7 @@ static int compile_block_expression (moo_t* moo) { /* compile_block_statement() processed non-statement item like a jump label. */ MOO_ASSERT (moo, md->_label != MOO_NULL); - if (TOKEN_TYPE(moo) == MOO_IOTOK_RBRACK) + if (TOKEN_TYPE(moo) == MOO_IOTOK_RBRACK) { /* the last label inside [] must be followed by a valid statement */ moo_oocs_t labname; @@ -5159,14 +5159,14 @@ static int compile_block_expression (moo_t* moo) } else if (n == 7777) { - /* goto statement - + /* goto statement - * the goto statement looks like a normal statement, but it never pushes a value. * so no pop_stacktop instruction needs to get injected */ - if (TOKEN_TYPE(moo) == MOO_IOTOK_RBRACK) + if (TOKEN_TYPE(moo) == MOO_IOTOK_RBRACK) { /* eliminate BCODE_POP_STACKTOP produced in the else block below * becuase the non-statement item is the last item before the closing bracket */ - if (pop_stacktop_pos != INVALID_IP) + if (pop_stacktop_pos != INVALID_IP) { eliminate_instructions (moo, pop_stacktop_pos, pop_stacktop_pos); pop_stacktop_pos = INVALID_IP; @@ -5190,7 +5190,7 @@ static int compile_block_expression (moo_t* moo) pop_stacktop_pos = md->code.len; if (emit_byte_instruction(moo, BCODE_POP_STACKTOP, TOKEN_LOC(moo)) <= -1) return -1; - if (TOKEN_TYPE(moo) == MOO_IOTOK_RBRACK) + if (TOKEN_TYPE(moo) == MOO_IOTOK_RBRACK) { eliminate_instructions(moo, pop_stacktop_pos, pop_stacktop_pos); pop_stacktop_pos = INVALID_IP; @@ -5199,7 +5199,7 @@ static int compile_block_expression (moo_t* moo) else if (TOKEN_TYPE(moo) == MOO_IOTOK_PERIOD) { GET_TOKEN (moo); - if (TOKEN_TYPE(moo) == MOO_IOTOK_RBRACK) + if (TOKEN_TYPE(moo) == MOO_IOTOK_RBRACK) { eliminate_instructions(moo, pop_stacktop_pos, pop_stacktop_pos); pop_stacktop_pos = INVALID_IP; @@ -5227,7 +5227,7 @@ static int compile_block_expression (moo_t* moo) if (emit_byte_instruction(moo, BCODE_RETURN_FROM_BLOCK, TOKEN_LOC(moo)) <= -1) return -1; - if (patch_forward_jump_instruction(moo, jump_inst_pos, md->code.len) <= -1) + if (patch_forward_jump_instruction(moo, jump_inst_pos, md->code.len) <= -1) { moo_setsynerrbfmt (moo, MOO_SYNERR_INSTFLOOD, &block_loc, MOO_NULL, "unable to patch block jump"); return -1; @@ -5237,7 +5237,7 @@ static int compile_block_expression (moo_t* moo) md->tmprs.len = saved_tmprs_len; md->tmpr_count = saved_tmpr_count; - if (md->loop) + if (md->loop) { MOO_ASSERT (moo, md->loop->blkcount > 0); md->loop->blkcount--; @@ -5314,14 +5314,14 @@ static int read_byte_array_literal (moo_t* moo, int rdonly, moo_oop_t* xlit) /* accept a character literal inside a byte array literal */ tmp = TOKEN_NAME_PTR(moo)[0]; } - + else if (string_to_smooi(moo, TOKEN_NAME(moo), TOKEN_TYPE(moo) == MOO_IOTOK_RADINTLIT, &tmp) <= -1) { /* the token reader reads a valid token. no other errors * than the range error must not occur */ MOO_ASSERT (moo, moo->errnum == MOO_ERANGE); - /* if the token is out of the SMOOI range, it's too big or + /* if the token is out of the SMOOI range, it's too big or * to small to be a byte */ moo_setsynerr (moo, MOO_SYNERR_BYTERANGE, TOKEN_LOC(moo), TOKEN_NAME(moo)); goto oops; @@ -5572,7 +5572,7 @@ static int _compile_array_expression (moo_t* moo, int closer_token, int bcode_ma } GET_TOKEN (moo); - } + } while (1); /* TODO: devise a double_param MAKE_ARRAY to increase the number of elementes supported... */ @@ -5663,7 +5663,7 @@ static int compile_expression_primary (moo_t* moo, const moo_oocs_t* ident, cons *to_super = 0; - if (ident) + if (ident) { /* the caller has read the identifier and the next word */ handle_ident: @@ -5704,10 +5704,10 @@ static int compile_expression_primary (moo_t* moo, const moo_oocs_t* ident, cons break; case VAR_CLASS: - /* get_variable_info must not set var.cls to MOO_NULL + /* get_variable_info must not set var.cls to MOO_NULL * because the class object pointer should be available * when a method definition is compiled */ - MOO_ASSERT (moo, var.cls != MOO_NULL); + MOO_ASSERT (moo, var.cls != MOO_NULL); if (add_literal(moo, (moo_oop_t)var.cls, &index) <= -1 || emit_double_param_instruction(moo, BCODE_PUSH_OBJVAR_0, var.pos, index, ident_loc) <= -1) return -1; @@ -5718,7 +5718,7 @@ static int compile_expression_primary (moo_t* moo, const moo_oocs_t* ident, cons * the association object pointed to by a system dictionary * is stored into the literal frame. so the system dictionary * must not migrate the value of the association to a new - * association when it rehashes the entire dictionary. + * association when it rehashes the entire dictionary. * If the association entry is deleted from the dictionary, * the code compiled before deletion will still access * the deleted association @@ -5754,7 +5754,7 @@ static int compile_expression_primary (moo_t* moo, const moo_oocs_t* ident, cons case MOO_IOTOK_SUPER: if (moo->c->cunit->cunit_type == MOO_CUNIT_INTERFACE) { - /* i don't allow super in an interface method + /* i don't allow super in an interface method * message sending to super requires the owning class * of an active method. a method taken by a class from * an interface points to the interface in the owner field. @@ -5963,7 +5963,7 @@ static int compile_expression_primary (moo_t* moo, const moo_oocs_t* ident, cons return 0; } -static moo_oob_t send_message_cmd[] = +static moo_oob_t send_message_cmd[] = { BCODE_SEND_MESSAGE_0, BCODE_SEND_MESSAGE_TO_SUPER_0 @@ -6000,7 +6000,7 @@ static int compile_unary_message (moo_t* moo, int to_super) /* this argument is not a real block. but change the block id * to prevent 'goto' from jumping out of the argument expression */ cur_blk_id = md->blk_id; - md->blk_id = md->blk_idseq++; + md->blk_id = md->blk_idseq++; n = compile_method_expression(moo, 0); md->blk_id = cur_blk_id; if (n <= -1) return -1; @@ -6067,14 +6067,14 @@ static int compile_binary_message (moo_t* moo, int to_super) /* this argument expression is not a real block. but change the block id * to prevent 'goto' from jumping out of the argument expression */ cur_blk_id = md->blk_id; - md->blk_id = md->blk_idseq++; + md->blk_id = md->blk_idseq++; n = compile_expression_primary(moo, MOO_NULL, MOO_NULL, 0, &to_super2); md->blk_id = cur_blk_id; if (n <= -1) goto oops; if (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT && compile_unary_message(moo, to_super2) <= -1) goto oops; - /* update the pointer to the cloned selector now + /* update the pointer to the cloned selector now * to be free from reallocation risk for the recursive call * to compile_expression_primary(). */ binsel.ptr = &md->binsels.ptr[binsel_offset]; @@ -6115,7 +6115,7 @@ static int compile_keyword_message (moo_t* moo, int to_super) saved_kwsel_len = md->kwsels.len; /* TODO: optimization for ifTrue: ifFalse: whileTrue: whileFalse .. */ - do + do { kw = *TOKEN_NAME(moo); if (clone_keyword(moo, &kw, &kw_offset) <= -1) goto oops; @@ -6125,7 +6125,7 @@ static int compile_keyword_message (moo_t* moo, int to_super) /* this argument expression is not a real block. but change the block id * to prevent 'goto' from jumping out of the argument expression */ cur_blk_id = md->blk_id; - md->blk_id = md->blk_idseq++; + md->blk_id = md->blk_idseq++; n = compile_expression_primary(moo, MOO_NULL, MOO_NULL, 0, &to_super2); md->blk_id = cur_blk_id; if (n <= -1) goto oops; @@ -6135,16 +6135,16 @@ static int compile_keyword_message (moo_t* moo, int to_super) kw.ptr = &md->kwsels.ptr[kw_offset]; if (nargs >= MAX_CODE_NARGS) { - /* 'kw' points to only one segment of the full keyword message. + /* 'kw' points to only one segment of the full keyword message. * if it parses an expression like 'aBlock value: 10 with: 20', * 'kw' may point to 'value:' or 'with:'. */ - moo_setsynerr (moo, MOO_SYNERR_ARGFLOOD, &saved_kwsel_loc, &kw); + moo_setsynerr (moo, MOO_SYNERR_ARGFLOOD, &saved_kwsel_loc, &kw); goto oops; } nargs++; - } + } while (TOKEN_TYPE(moo) == MOO_IOTOK_KEYWORD) /* loop */; kwsel.ptr = &md->kwsels.ptr[saved_kwsel_len]; @@ -6165,11 +6165,11 @@ static int compile_message_expression (moo_t* moo, int to_super) { /* * message-expression := single-message cascaded-message - * single-message := + * single-message := * (unary-message+ binary-message* keyword-message?) | * (binary-message+ keyword-message?) | * keyword-message - * + * * keyword-message := (keyword keyword-argument)+ * keyword-argument := expression-primary unary-message* binary-message* * binary-message := binary-selector binary-argument @@ -6186,7 +6186,7 @@ static int compile_message_expression (moo_t* moo, int to_super) switch (TOKEN_TYPE(moo)) { case MOO_IOTOK_IDENT: - /* insert NOOP to change to DUP_STACKTOP if there is a + /* insert NOOP to change to DUP_STACKTOP if there is a * cascaded message */ noop_pos = md->code.len; if (emit_byte_instruction(moo, BCODE_NOOP, TOKEN_LOC(moo)) <= -1) return -1; @@ -6222,7 +6222,7 @@ static int compile_message_expression (moo_t* moo, int to_super) noop_pos = md->code.len; if (emit_byte_instruction(moo, BCODE_NOOP, TOKEN_LOC(moo)) <= -1) return -1; - /* don't pass to_super. pass 0 as it can't be the + /* don't pass to_super. pass 0 as it can't be the * first message after 'super' */ if (compile_keyword_message(moo, 0/*to_super*/) <= -1) return -1; } @@ -6243,7 +6243,7 @@ static int compile_message_expression (moo_t* moo, int to_super) noop_pos = md->code.len; if (emit_byte_instruction(moo, BCODE_NOOP, TOKEN_LOC(moo)) <= -1) return -1; - /* don't pass to_super. pass 0 as it can't be the + /* don't pass to_super. pass 0 as it can't be the * first message after 'super' */ if (compile_keyword_message(moo, 0/*to_super*/) <= -1) return -1; } @@ -6267,7 +6267,7 @@ static int compile_message_expression (moo_t* moo, int to_super) if (emit_byte_instruction(moo, BCODE_POP_STACKTOP, TOKEN_LOC(moo)) <= -1) return -1; GET_TOKEN(moo); } - else + else { MOO_ASSERT (moo, md->code.len > noop_pos); /*MOO_MEMMOVE (&md->code.ptr[noop_pos], &md->code.ptr[noop_pos + 1], md->code.len - noop_pos - 1); @@ -6322,14 +6322,14 @@ start_over: * identifer if it encounters an assignment operator after an identifer. * i only allow a basic expression after a logical operator. * the basic expression doesn't include an assignment expression - * if it is not in the parenthesis. so i nullify the following 2 variables + * if it is not in the parenthesis. so i nullify the following 2 variables * * a := 30 > 20 and 10 > 20 is equavelent to a := (30 > 20 and 10 > 20). * * you will encounter a syntax error for the following expression as the * expression end after y. * a := 30 > 20 and y := 10 > 20 - * + * * a := 30 > 20 and (y := 10 > 20) is perfectly valid. */ ident = MOO_NULL; @@ -6342,7 +6342,7 @@ start_over: { for (j = 0; j < MOO_COUNTOF(jumptoend.static_chunk.buf) && i < jumptoend.count; j++) { - if (patch_forward_jump_instruction (moo, jumptoend_chunk->buf[j].v, md->code.len) <= -1) + if (patch_forward_jump_instruction (moo, jumptoend_chunk->buf[j].v, md->code.len) <= -1) { /* the logical expression is too large to patch the jump instruction */ moo_setsynerrbfmt (moo, MOO_SYNERR_INSTFLOOD, &expr_loc, MOO_NULL, "unable to patch logical operator jump"); @@ -6390,7 +6390,7 @@ static int compile_braced_block (moo_t* moo) if (n <= -1) return -1; if (n == 8888) { - if (TOKEN_TYPE(moo) == MOO_IOTOK_RBRACE) + if (TOKEN_TYPE(moo) == MOO_IOTOK_RBRACE) { /* non-statement followed by the closing brace. * if there is a statement above the non-statement item, the POP_STACKSTOP is produced. @@ -6402,7 +6402,7 @@ static int compile_braced_block (moo_t* moo) else if (n == 7777) { /* goto statement */ - if (TOKEN_TYPE(moo) == MOO_IOTOK_RBRACE) + if (TOKEN_TYPE(moo) == MOO_IOTOK_RBRACE) { if (pop_stacktop_pos > 0) eliminate_instructions (moo, pop_stacktop_pos, pop_stacktop_pos); break; @@ -6484,19 +6484,19 @@ static int compile_braced_block (moo_t* moo) else if (n == 7777) { /* goto statement */ - if (TOKEN_TYPE(moo) == MOO_IOTOK_RBRACE) + if (TOKEN_TYPE(moo) == MOO_IOTOK_RBRACE) { /* jumping somewhere inside {} is different from inside []. * [] needs to leave a return value when leaving the block. * {} doesn't need to because {} can only be used as part of 'if', 'while', 'until', 'do'. * that means, the last evaluated value inside {} before exit is used * as a lvalue but the jump target can't be break into an assignment statement. - * + * * a : 3. - * a := if (1) { goto L30 }. // if jump to L30 is made inside {}, assignment to 'a' is skipped. + * a := if (1) { goto L30 }. // if jump to L30 is made inside {}, assignment to 'a' is skipped. * // so the evaluation result of the 'if' statement goes unused. * L30: b := a + 1. // therefore, 'a' holds 3. - * + * * it is not allowed to place label inside "b := a + 1". * so the pop_stacktop produced must not be eliminated. */ @@ -6527,7 +6527,7 @@ static int compile_braced_block (moo_t* moo) else if (TOKEN_TYPE(moo) == MOO_IOTOK_PERIOD) { GET_TOKEN (moo); - if (TOKEN_TYPE(moo) == MOO_IOTOK_RBRACE) + if (TOKEN_TYPE(moo) == MOO_IOTOK_RBRACE) { eliminate_instructions(moo, pop_stacktop_pos, pop_stacktop_pos); pop_stacktop_pos = INVALID_IP; @@ -6573,7 +6573,7 @@ static int compile_conditional (moo_t* moo) GET_TOKEN (moo); - /* a weird expression like this is also allowed for the call to compile_method_expression() + /* a weird expression like this is also allowed for the call to compile_method_expression() * if (if (a == 10) { ^20 }) { ^40 }. */ if (compile_method_expression(moo, 0) <= -1) return -1; @@ -6625,7 +6625,7 @@ static int compile_if_expression (moo_t* moo) precondpos = md->code.len; if (jumptonext != INVALID_IP && - patch_forward_jump_instruction(moo, jumptonext, precondpos) <= -1) + patch_forward_jump_instruction(moo, jumptonext, precondpos) <= -1) { moo_setsynerrbfmt (moo, MOO_SYNERR_INSTFLOOD, &brace_loc, MOO_NULL, "unable to patch conditional branching jump"); goto oops; @@ -6635,7 +6635,7 @@ static int compile_if_expression (moo_t* moo) postcondpos = md->code.len; /* remember position of the jmpop_forward_if_false instruction to be generated */ - jumptonext = md->code.len; + jumptonext = md->code.len; /* BCODE_JMPOP_FORWARD_IF_FALSE is always a long jump instruction. * just specify MAX_CODE_JUMP for consistency with short jump variants */ if (emit_single_param_instruction(moo, jmpop_inst, MAX_CODE_JUMP, &if_loc) <= -1) goto oops; @@ -6649,7 +6649,7 @@ static int compile_if_expression (moo_t* moo) /* [NOTE] * it checks by comparing 'la' and 'b' if there has been a label found inside a braced block. - * the code below doesn't eliminate instructions emitted of a braced block containing one or + * the code below doesn't eliminate instructions emitted of a braced block containing one or * more labels. * * the check is suboptimal and primitive. an optimizing compiler needs to check if the actual @@ -6668,7 +6668,7 @@ static int compile_if_expression (moo_t* moo) eliminate_instructions (moo, precondpos, precondpos); postcondpos = precondpos; - if (endoftrueblock == INVALID_IP) + if (endoftrueblock == INVALID_IP) { /* update the end position of the first true block */ endoftrueblock = md->code.len; @@ -6719,7 +6719,7 @@ static int compile_if_expression (moo_t* moo) while (1); if (jumptonext != INVALID_IP && - patch_forward_jump_instruction(moo, jumptonext, md->code.len) <= -1) + patch_forward_jump_instruction(moo, jumptonext, md->code.len) <= -1) { moo_setsynerrbfmt (moo, MOO_SYNERR_INSTFLOOD, &brace_loc, MOO_NULL, "unable to patch conditional branching jump"); goto oops; @@ -6750,7 +6750,7 @@ static int compile_if_expression (moo_t* moo) { for (j = 0; j < MOO_COUNTOF(jumptoend.static_chunk.buf) && i < jumptoend.count; j++) { - if (patch_forward_jump_instruction(moo, jumptoend_chunk->buf[j].v, md->code.len) <= -1) + if (patch_forward_jump_instruction(moo, jumptoend_chunk->buf[j].v, md->code.len) <= -1) { moo_setsynerrbfmt (moo, MOO_SYNERR_INSTFLOOD, &jumptoend_chunk->buf[j].loc, MOO_NULL, "unable to patch conditional branching jump"); goto oops; @@ -6800,7 +6800,7 @@ static int compile_while_expression (moo_t* moo) /* or compile_until_expression inst2 = BCODE_PUSH_FALSE; } - /* simple optimization - + /* simple optimization - * if the conditional is known to be true, emit the absolute jump instruction. * if it is known to be false, kill all generated instructions. */ if (md->code.ptr[precondpos] == inst1) @@ -6815,7 +6815,7 @@ static int compile_while_expression (moo_t* moo) /* or compile_until_expression /* the conditional is always false for while, or false for until */ cond_style = -1; } -/* TODO: at least check some other literals for optimization. +/* TODO: at least check some other literals for optimization. * most literal values must be evaluate to true. */ } @@ -6854,9 +6854,9 @@ static int compile_while_expression (moo_t* moo) /* or compile_until_expression } /* emit an instruction to jump back to the condition */ - if (emit_backward_jump_instruction(moo, BCODE_JUMP_BACKWARD, md->code.len - precondpos, &closing_brace_loc) <= -1) + if (emit_backward_jump_instruction(moo, BCODE_JUMP_BACKWARD, md->code.len - precondpos, &closing_brace_loc) <= -1) { - if (moo->errnum == MOO_ERANGE) + if (moo->errnum == MOO_ERANGE) { /* the jump offset is out of the representable range by the offset * portion of the jump instruction */ @@ -6867,14 +6867,14 @@ static int compile_while_expression (moo_t* moo) /* or compile_until_expression if (cond_style != 1) { - if (patch_forward_jump_instruction(moo, postcondpos, md->code.len) <= -1) + if (patch_forward_jump_instruction(moo, postcondpos, md->code.len) <= -1) { moo_setsynerrbfmt (moo, MOO_SYNERR_INSTFLOOD, &brace_loc, MOO_NULL, "unable to patch conditional loop jump"); goto oops; } } - if (la == lb && cond_style == -1) + if (la == lb && cond_style == -1) { /* optimization - get rid of instructions generated for the while * loop including the conditional as the condition was false */ @@ -6913,7 +6913,7 @@ static int compile_do_while_expression (moo_t* moo) GET_TOKEN (moo); /* get { */ prebbpos = md->code.len; - /* remember information about this loop. + /* remember information about this loop. * position of the conditional is not known yet.*/ if (push_loop(moo, MOO_LOOP_DO_WHILE, prebbpos) <= -1) goto oops; loop_pushed = 1; @@ -6955,14 +6955,14 @@ static int compile_do_while_expression (moo_t* moo) /* cannnot destroy the loop information because of pending jump updates * for break. but need to unlink it as the conditional is not really * part of the loop body */ - loop = unlink_loop (moo); + loop = unlink_loop (moo); if (compile_conditional (moo) <= -1) goto oops; postcondpos = md->code.len; jbinst = (is_until_loop? BCODE_JMPOP_BACKWARD_IF_FALSE: BCODE_JMPOP_BACKWARD_IF_TRUE); if (precondpos + 1 == postcondpos) { - /* simple optimization - + /* simple optimization - * if the conditional is known to be true, emit the absolute jump instruction. * if it is known to be false, kill all generated instructions. */ if (md->code.ptr[precondpos] == (is_until_loop? BCODE_PUSH_FALSE: BCODE_PUSH_TRUE)) @@ -6981,9 +6981,9 @@ static int compile_do_while_expression (moo_t* moo) } } - if (emit_backward_jump_instruction(moo, jbinst, md->code.len - prebbpos, TOKEN_LOC(moo)) <= -1) + if (emit_backward_jump_instruction(moo, jbinst, md->code.len - prebbpos, TOKEN_LOC(moo)) <= -1) { - if (moo->errnum == MOO_ERANGE) + if (moo->errnum == MOO_ERANGE) { /* the jump offset is out of the representable range by the offset * portion of the jump instruction */ @@ -7007,7 +7007,7 @@ skip_emitting_jump_backward: return 0; oops: - if (loop_pushed) + if (loop_pushed) { if (loop) free_loop (moo, loop); else pop_loop (moo); @@ -7063,7 +7063,7 @@ static int compile_method_expression (moo_t* moo, int pop) assignee_dotted = (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT_DOTTED); GET_TOKEN (moo); - if (TOKEN_TYPE(moo) == MOO_IOTOK_ASSIGN) + if (TOKEN_TYPE(moo) == MOO_IOTOK_ASSIGN) { /* assignment expression */ var_info_t var; @@ -7075,7 +7075,7 @@ static int compile_method_expression (moo_t* moo, int pop) if (compile_method_expression(moo, 0) <= -1) goto oops; /* compile_method_expression() is called after clone_assignee(). - * clone_assignee() may reallocate a single buffer that holds + * clone_assignee() may reallocate a single buffer that holds * a series of assigness names. this pointer based operation is * fragile as it can change. use the offset of the cloned * assignee to update the actual pointer after the recursive @@ -7137,7 +7137,7 @@ static int compile_method_expression (moo_t* moo, int pop) goto oops; } } - else + else { /* what is held in assignee is not an assignee any more. * potentially it is a variable or object reference @@ -7146,7 +7146,7 @@ static int compile_method_expression (moo_t* moo, int pop) if (compile_basic_expression(moo, &assignee, &assignee_loc, assignee_dotted) <= -1) goto oops; } } - else + else { assignee.len = 0; if (compile_basic_expression(moo, MOO_NULL, MOO_NULL, 0) <= -1) goto oops; @@ -7188,7 +7188,7 @@ static MOO_INLINE int resolve_goto_label (moo_t* moo, moo_goto_t* _goto) in 'label: goto label', _goto->ip and _label->ip are the same. */ - if (patch_forward_jump_instruction(moo, _goto->ip, _label->ip) <= -1) + if (patch_forward_jump_instruction(moo, _goto->ip, _label->ip) <= -1) { moo_setsynerrbfmt (moo, MOO_SYNERR_INSTFLOOD, &_goto->loc, MOO_NULL, "unable to patch unconditional jump"); return -1; @@ -7280,7 +7280,7 @@ static int compile_goto_statement (moo_t* moo) nptr[target->len] = '\0'; _goto->ip = md->code.len; - if (emit_single_param_instruction(moo, BCODE_JUMP_FORWARD, MAX_CODE_JUMP, TOKEN_LOC(moo)) <= -1) + if (emit_single_param_instruction(moo, BCODE_JUMP_FORWARD, MAX_CODE_JUMP, TOKEN_LOC(moo)) <= -1) { moo_freemem (moo, _goto); return -1; @@ -7301,7 +7301,7 @@ static int compile_special_statement (moo_t* moo) moo_method_data_t* md = get_cunit_method_data(moo); moo_ioloc_t start_loc = *TOKEN_LOC(moo); - if (TOKEN_TYPE(moo) == MOO_IOTOK_RETURN) + if (TOKEN_TYPE(moo) == MOO_IOTOK_RETURN) { /* ^ - return - return to the sender of the origin */ GET_TOKEN (moo); @@ -7398,13 +7398,13 @@ static int compile_method_statement (moo_t* moo) if (n == 9999) { - /* the second parameter to compile_method_expression() indicates + /* the second parameter to compile_method_expression() indicates * that the stack top will eventually be popped off. the compiler - * can optimize some instruction sequencese. for example, two - * consecutive store and pop intructions can be transformed to - * a more specialized single pop-and-store instruction. - * the compile_method_expression() function emits POP_INTO_XXX - * instructions if the second parameter is 1 whenever possible and + * can optimize some instruction sequencese. for example, two + * consecutive store and pop intructions can be transformed to + * a more specialized single pop-and-store instruction. + * the compile_method_expression() function emits POP_INTO_XXX + * instructions if the second parameter is 1 whenever possible and * STORE_INTO_XXX if it's 0.*/ moo_oow_t preexprpos; @@ -7473,7 +7473,7 @@ static int compile_method_statements (moo_t* moo) else { /* a proper statement or a goto statement(if n == 7777) has been processed */ - if (TOKEN_TYPE(moo) == MOO_IOTOK_PERIOD) + if (TOKEN_TYPE(moo) == MOO_IOTOK_PERIOD) { /* period after a statement */ GET_TOKEN (moo); @@ -7495,7 +7495,7 @@ static int compile_method_statements (moo_t* moo) while (1); } - /* arrange to return the receiver if execution reached + /* arrange to return the receiver if execution reached * the end of the method without explicit return */ return emit_byte_instruction(moo, BCODE_RETURN_RECEIVER, TOKEN_LOC(moo)); } @@ -7636,7 +7636,7 @@ static moo_ooi_t compute_preamble (moo_t* moo, moo_method_data_t* md) preamble_code = MOO_METHOD_PREAMBLE_EXCEPTION; preamble_index = 0; } - else + else { MOO_ASSERT (moo, md->pftype == PFTYPE_ENSURE); preamble_code = MOO_METHOD_PREAMBLE_ENSURE; @@ -7660,12 +7660,12 @@ static void add_method_info_to_dbgi (moo_t* moo, moo_method_data_t* md, moo_oow_ file_name = md->start_loc.file; if (!file_name) file_name = &_nul; - if (moo_addfiletodbgi(moo, file_name, file_offset) <= -1) + if (moo_addfiletodbgi(moo, file_name, file_offset) <= -1) { /* TODO: warning */ *file_offset = 0; } - else if (*file_offset > MOO_SMOOI_MAX) + else if (*file_offset > MOO_SMOOI_MAX) { /* TODO: warning */ *file_offset = 0; @@ -7699,7 +7699,7 @@ static int add_compiled_method_to_class (moo_t* moo) if (!name) goto oops; moo_pushvolat (moo, (moo_oop_t*)&name); tmp_count++; - /* The variadic data part passed to moo_instantiate() is not GC-safe. + /* The variadic data part passed to moo_instantiate() is not GC-safe. * let's delay initialization of variadic data a bit. */ mth = (moo_oop_method_t)moo_instantiatewithtrailer(moo, moo->_method, cc->mth.literals.count, cc->mth.code.ptr, cc->mth.code.len); if (!mth) goto oops; @@ -7721,7 +7721,7 @@ static int add_compiled_method_to_class (moo_t* moo) mth->tmpr_count = MOO_SMOOI_TO_OOP(cc->mth.tmpr_count); mth->tmpr_nargs = MOO_SMOOI_TO_OOP(cc->mth.tmpr_nargs); - if (moo->dbgi) + if (moo->dbgi) { moo_oow_t file_offset; moo_oow_t method_offset; @@ -7737,7 +7737,7 @@ static int add_compiled_method_to_class (moo_t* moo) if (cc->mth.type == MOO_METHOD_DUAL) { if (!moo_putatdic(moo, cc->self_oop->mthdic[MOO_METHOD_INSTANCE], (moo_oop_t)name, (moo_oop_t)mth)) goto oops; - if (!moo_putatdic(moo, cc->self_oop->mthdic[MOO_METHOD_CLASS], (moo_oop_t)name, (moo_oop_t)mth)) + if (!moo_putatdic(moo, cc->self_oop->mthdic[MOO_METHOD_CLASS], (moo_oop_t)name, (moo_oop_t)mth)) { /* 'name' is a symbol created of cc->mth.name. so use it as a key for deletion */ moo_deletedic (moo, cc->self_oop->mthdic[MOO_METHOD_INSTANCE], &cc->mth.name); @@ -7774,11 +7774,11 @@ static int add_compiled_method_to_interface (moo_t* moo) if (!name) goto oops; moo_pushvolat (moo, (moo_oop_t*)&name); tmp_count++; - /* The variadic data part passed to moo_instantiate() is not GC-safe. + /* The variadic data part passed to moo_instantiate() is not GC-safe. * let's delay initialization of variadic data a bit. */ mth = (moo_oop_method_t)moo_instantiatewithtrailer(moo, moo->_method, ifce->mth.literals.count, ifce->mth.code.ptr, ifce->mth.code.len); if (!mth) goto oops; - + for (i = 0; i < ifce->mth.literals.count; i++) { /* let's do the variadic data initialization here - fill the literal frame */ @@ -7799,7 +7799,7 @@ static int add_compiled_method_to_interface (moo_t* moo) mth->tmpr_count = MOO_SMOOI_TO_OOP(ifce->mth.tmpr_count); mth->tmpr_nargs = MOO_SMOOI_TO_OOP(ifce->mth.tmpr_nargs); - if (moo->dbgi) + if (moo->dbgi) { moo_oow_t file_offset; moo_oow_t method_offset; @@ -7815,7 +7815,7 @@ static int add_compiled_method_to_interface (moo_t* moo) if (ifce->mth.type == MOO_METHOD_DUAL) { if (!moo_putatdic(moo, ifce->self_oop->mthdic[MOO_METHOD_INSTANCE], (moo_oop_t)name, (moo_oop_t)mth)) goto oops; - if (!moo_putatdic(moo, ifce->self_oop->mthdic[MOO_METHOD_CLASS], (moo_oop_t)name, (moo_oop_t)mth)) + if (!moo_putatdic(moo, ifce->self_oop->mthdic[MOO_METHOD_CLASS], (moo_oop_t)name, (moo_oop_t)mth)) { /* 'name' is a symbol created of ifce->mth.name. so use it as a key for deletion */ moo_deletedic (moo, ifce->self_oop->mthdic[MOO_METHOD_INSTANCE], &ifce->mth.name); @@ -7867,7 +7867,7 @@ static int add_method_signature (moo_t* moo) if (ifce->mth.type == MOO_METHOD_DUAL) { if (!moo_putatdic(moo, ifce->self_oop->mthdic[MOO_METHOD_INSTANCE], (moo_oop_t)name, (moo_oop_t)mth)) goto oops; - if (!moo_putatdic(moo, ifce->self_oop->mthdic[MOO_METHOD_CLASS], (moo_oop_t)name, (moo_oop_t)mth)) + if (!moo_putatdic(moo, ifce->self_oop->mthdic[MOO_METHOD_CLASS], (moo_oop_t)name, (moo_oop_t)mth)) { /* 'name' is a symbol created of ifce->mth.name. so use it as a key for deletion */ moo_deletedic (moo, ifce->self_oop->mthdic[MOO_METHOD_INSTANCE], &ifce->mth.name); @@ -7910,7 +7910,7 @@ static void clear_method_data (moo_t* moo, moo_method_data_t* mth) /* this must not happen as loop data are cleared in functions that handle loop expressions(). * but let me have this here just in case */ - while (mth->loop) pop_loop (moo); + while (mth->loop) pop_loop (moo); while (mth->_label) { @@ -8148,7 +8148,7 @@ static int resolve_primitive_method (moo_t* moo) pfbase = moo_getpfnum(moo, &cc->modname.ptr[savedlen], cc->modname.len - savedlen, &pfnum); if (!pfbase) { - MOO_DEBUG2 (moo, "Cannot find intrinsic primitive function - %.*js\n", + MOO_DEBUG2 (moo, "Cannot find intrinsic primitive function - %.*js\n", cc->modname.len - savedlen, &cc->modname.ptr[savedlen]); moo_setsynerr (moo, MOO_SYNERR_PFIDINVAL, &cc->mth.name_loc, &cc->mth.name); cc->modname.len = savedlen; @@ -8157,7 +8157,7 @@ static int resolve_primitive_method (moo_t* moo) if (cc->mth.tmpr_nargs < pfbase->minargs || cc->mth.tmpr_nargs > pfbase->maxargs) { - MOO_DEBUG5 (moo, "Unsupported argument count in primitive method definition of %.*js - %zd-%zd expected, %zd specified\n", + MOO_DEBUG5 (moo, "Unsupported argument count in primitive method definition of %.*js - %zd-%zd expected, %zd specified\n", cc->modname.len - savedlen, &cc->modname.ptr[savedlen], pfbase->minargs, pfbase->maxargs, cc->mth.tmpr_nargs); moo_setsynerr (moo, MOO_SYNERR_PFARGDEFINVAL, &cc->mth.name_loc, &cc->mth.name); @@ -8168,7 +8168,7 @@ static int resolve_primitive_method (moo_t* moo) cc->modname.len = savedlen; MOO_ASSERT (moo, MOO_OOI_IN_METHOD_PREAMBLE_INDEX_RANGE(pfnum)); - cc->mth.pftype = PFTYPE_NUMBERED; + cc->mth.pftype = PFTYPE_NUMBERED; cc->mth.pfnum = pfnum; } else @@ -8199,7 +8199,7 @@ static int resolve_primitive_method (moo_t* moo) pfbase = moo_querymodpf(moo, &cc->modname.ptr[savedlen], cc->modname.len - savedlen, MOO_NULL); if (!pfbase) { - MOO_DEBUG2 (moo, "Cannot find module primitive function - %.*js\n", + MOO_DEBUG2 (moo, "Cannot find module primitive function - %.*js\n", cc->modname.len - savedlen, &cc->modname.ptr[savedlen]); moo_setsynerr (moo, MOO_SYNERR_PFIDINVAL, &cc->mth.name_loc, &cc->mth.name); cc->modname.len = savedlen; @@ -8208,7 +8208,7 @@ static int resolve_primitive_method (moo_t* moo) if (cc->mth.tmpr_nargs < pfbase->minargs || cc->mth.tmpr_nargs > pfbase->maxargs) { - MOO_DEBUG5 (moo, "Unsupported argument count in primitive method definition of %.*js - %zd-%zd expected, %zd specified\n", + MOO_DEBUG5 (moo, "Unsupported argument count in primitive method definition of %.*js - %zd-%zd expected, %zd specified\n", cc->modname.len - savedlen, &cc->modname.ptr[savedlen], pfbase->minargs, pfbase->maxargs, cc->mth.tmpr_nargs); moo_setsynerr (moo, MOO_SYNERR_PFARGDEFINVAL, &cc->mth.name_loc, &cc->mth.name); @@ -8222,7 +8222,7 @@ static int resolve_primitive_method (moo_t* moo) MOO_ASSERT (moo, MOO_OOI_IN_METHOD_PREAMBLE_INDEX_RANGE(litidx)); /* external named primitive containing a period. */ - cc->mth.pftype = PFTYPE_NAMED; + cc->mth.pftype = PFTYPE_NAMED; cc->mth.pfnum = litidx; } @@ -8453,7 +8453,7 @@ static int make_getters_and_setters (moo_t* moo) /* hack to simulate a parameter. note i don't manipulate tmprs or tmprs_capa * because there is no method body code to process. i simply generate a setter * method */ - cc->mth.tmpr_count = 1; + cc->mth.tmpr_count = 1; cc->mth.tmpr_nargs = 1; MOO_ASSERT (moo, var_info.type == var_type); @@ -8483,7 +8483,7 @@ static int make_default_initial_values (moo_t* moo, var_type_t var_type) else { super_initv_count = 0; - + } initv_count += super_initv_count; @@ -8494,9 +8494,9 @@ static int make_default_initial_values (moo_t* moo, var_type_t var_type) /* [NOTE] * if some elements at the back of a class definition are lacking default values, - * initv_count is less than total_count. + * initv_count is less than total_count. * in the following case(no inheritance for simplicity): - * class ... { var a, b := 10, c. } + * class ... { var a, b := 10, c. } * initv_count is 1 whereas total_count is 3. */ MOO_ASSERT (moo, initv_count <= cc->var[var_type].total_count); @@ -8507,7 +8507,7 @@ static int make_default_initial_values (moo_t* moo, var_type_t var_type) { /* handle default values defined in the superclass chain. * i merge them into a single array for convenience and - * efficiency of object instantiation by moo_instantiate(). + * efficiency of object instantiation by moo_instantiate(). * it can avoid looking up superclasses upon instantiaion */ moo_oop_oop_t initv; @@ -8517,7 +8517,7 @@ static int make_default_initial_values (moo_t* moo, var_type_t var_type) MOO_ASSERT (moo, MOO_CLASSOF(moo, initv) == moo->_array); for (i = 0; i < super_initv_count; i++) { - if (MOO_OBJ_GET_OOP_VAL(initv, i)) + if (MOO_OBJ_GET_OOP_VAL(initv, i)) MOO_STORE_OOP (moo, MOO_OBJ_GET_OOP_PTR(tmp, j), MOO_OBJ_GET_OOP_VAL(initv, i)); j++; } @@ -8694,7 +8694,7 @@ static int make_defined_class (moo_t* moo) j = cc->var[VAR_CLASSINST].total_count; MOO_ASSERT (moo, MOO_CLASS_NAMED_INSTVARS + j + initv_count <= MOO_OBJ_GET_SIZE(cc->self_oop)); - for (i = 0; i < initv_count; i++) + for (i = 0; i < initv_count; i++) { MOO_STORE_OOP (moo, &cc->self_oop->cvar[j], cc->var[VAR_CLASS].initv[i].v); j++; @@ -8712,7 +8712,7 @@ static int make_defined_class (moo_t* moo) if (just_made) { - /* register the class to the system dictionary. kernel classes have + /* register the class to the system dictionary. kernel classes have * been registered at the ignition phase. */ if (!moo_putatdic(moo, (moo_oop_dic_t)cc->ns_oop, (moo_oop_t)cc->self_oop->name, (moo_oop_t)cc->self_oop)) return -1; MOO_STORE_OOP (moo, (moo_oop_t*)&cc->self_oop->nsup, (moo_oop_t)cc->ns_oop); @@ -8754,7 +8754,7 @@ static int process_class_modifiers (moo_t* moo, moo_ioloc_t* type_loc) do { int permit_non_pointer_instsize = 0; - + if (is_token_symbol(moo, VOCA_BYTE_S)) { /* class(#byte) */ @@ -8870,13 +8870,13 @@ static int process_class_modifiers (moo_t* moo, moo_ioloc_t* type_loc) return -1; } - if (string_to_smooi(moo, TOKEN_NAME(moo), TOKEN_TYPE(moo) == MOO_IOTOK_RADINTLIT, &tmp) <= -1 || + if (string_to_smooi(moo, TOKEN_NAME(moo), TOKEN_TYPE(moo) == MOO_IOTOK_RADINTLIT, &tmp) <= -1 || tmp < 0 || tmp > MOO_MAX_NAMED_INSTVARS) { /* the class type size has nothing to do with the name instance variables * in the semantics. but it is stored into the named-instvar bits in the * spec field of a class. so i check it against MOO_MAX_NAMED_INSTVARS. */ - moo_setsynerr (moo, MOO_SYNERR_NPINSTSIZEINVAL, TOKEN_LOC(moo), TOKEN_NAME(moo)); + moo_setsynerr (moo, MOO_SYNERR_NPINSTSIZEINVAL, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } @@ -8967,10 +8967,10 @@ static int process_class_superclass (moo_t* moo) if (get_variable_info(moo, &cc->superfqn, &cc->superfqn_loc, superfqn_is_dotted, &var) <= -1) return -1; if (var.type != VAR_GLOBAL) goto unknown_superclass; - if (MOO_CLASSOF(moo, var.u.gbl->value) == moo->_class && + if (MOO_CLASSOF(moo, var.u.gbl->value) == moo->_class && MOO_OBJ_GET_FLAGS_KERNEL(var.u.gbl->value) != MOO_OBJ_FLAGS_KERNEL_IMMATURE) { - /* the value found must be a class and it must not be an incomplete internal class object. + /* the value found must be a class and it must not be an incomplete internal class object. * 0(non-kernel object) * 1(incomplete kernel object), * 2(complete kernel object) */ @@ -8992,7 +8992,7 @@ static int process_class_superclass (moo_t* moo) if (MOO_CLASS_SELFSPEC_FLAGS(MOO_OOP_TO_SMOOI(((moo_oop_class_t)cc->super_oop)->selfspec)) & MOO_CLASS_SELFSPEC_FLAG_FINAL) { /* cannot inherit a #final class */ - if (cc->self_oop == MOO_NULL) /* self_oop is not null if it's a predefined kernel class. */ + if (cc->self_oop == MOO_NULL) /* self_oop is not null if it's a predefined kernel class. */ { /* the restriction applies to non-kernel classes only */ moo_setsynerrbfmt (moo, MOO_SYNERR_INHERITBANNED, &cc->fqn_loc, &cc->fqn, @@ -9035,7 +9035,7 @@ static int process_class_module_import (moo_t* moo) if (TOKEN_NAME_LEN(moo) <= 0 || TOKEN_NAME_LEN(moo) > MOO_MOD_NAME_LEN_MAX || moo_find_oochar(TOKEN_NAME_PTR(moo), TOKEN_NAME_LEN(moo), '-') ) { - /* check for a bad module name. + /* check for a bad module name. * also disallow a dash in the name - i like converting * a period to a dash when mapping the module name to an * actual module file. disallowing a dash lowers confusion @@ -9152,7 +9152,7 @@ static int ciim_on_each_method (moo_t* moo, moo_oop_dic_t dic, moo_oop_associati { /* duplicate interface method name found */ moo_setsynerrbfmt (moo, MOO_SYNERR_MTHNAMEDUPL, MOO_NULL, MOO_NULL, - "%.*js defined in multiple interfaces for %.*js - %.*js, %.*js", + "%.*js defined in multiple interfaces for %.*js - %.*js, %.*js", name.len, name.ptr, MOO_OBJ_GET_SIZE(ciim->_class->name), MOO_OBJ_GET_CHAR_SLOT(ciim->_class->name), MOO_OBJ_GET_SIZE(im->owner->name), MOO_OBJ_GET_CHAR_SLOT(im->owner->name), @@ -9165,7 +9165,7 @@ static int ciim_on_each_method (moo_t* moo, moo_oop_dic_t dic, moo_oop_associati if (add_oop_to_oopbuf(moo, &ciim->cc->ifce_mths[ciim->mth_type], (moo_oop_t)mth) <= -1) { const moo_ooch_t* oldmsg = moo_backuperrmsg(moo); - moo_seterrbfmt (moo, moo_geterrnum(moo), "unable to take interface method %.*js>>%.*js to %.*js - %js", + moo_seterrbfmt (moo, moo_geterrnum(moo), "unable to take interface method %.*js>>%.*js to %.*js - %js", MOO_OBJ_GET_SIZE(ciim->ifce->name), MOO_OBJ_GET_CHAR_SLOT(ciim->ifce->name), name.len, name.ptr, MOO_OBJ_GET_SIZE(ciim->_class->name), MOO_OBJ_GET_CHAR_SLOT(ciim->_class->name), @@ -9179,7 +9179,7 @@ static int ciim_on_each_method (moo_t* moo, moo_oop_dic_t dic, moo_oop_associati MOO_ASSERT (moo, MOO_CLASSOF(moo, ass->value) == moo->_methsig); - moo_setsynerrbfmt (moo, MOO_SYNERR_CLASSNCIFCE, MOO_NULL, MOO_NULL, + moo_setsynerrbfmt (moo, MOO_SYNERR_CLASSNCIFCE, MOO_NULL, MOO_NULL, "%.*js not implementing %.*js>>%.*js", MOO_OBJ_GET_SIZE(ciim->_class->name), MOO_OBJ_GET_CHAR_SLOT(ciim->_class->name), MOO_OBJ_GET_SIZE(ciim->ifce->name), MOO_OBJ_GET_CHAR_SLOT(ciim->ifce->name), @@ -9189,7 +9189,7 @@ static int ciim_on_each_method (moo_t* moo, moo_oop_dic_t dic, moo_oop_associati } else { - /* TODO: + /* TODO: * if the method is found in the class chain, also check if the method found * has been taken from the interface. if so, multiple interfaces are defining * the method. it's an error */ @@ -9205,7 +9205,7 @@ static int ciim_on_each_method (moo_t* moo, moo_oop_dic_t dic, moo_oop_associati if (MOO_METHOD_GET_PREAMBLE_FLAGS(MOO_OOP_TO_SMOOI(mth->preamble)) != MOO_METHOD_GET_PREAMBLE_FLAGS(MOO_OOP_TO_SMOOI(sig->preamble))) { modifier_conflict: - moo_setsynerrbfmt (moo, MOO_SYNERR_CLASSNCIFCE, MOO_NULL, MOO_NULL, + moo_setsynerrbfmt (moo, MOO_SYNERR_CLASSNCIFCE, MOO_NULL, MOO_NULL, "%.*js>>%.*js modifiers conficting with %.*js>>%.*js", MOO_OBJ_GET_SIZE(ciim->_class->name), MOO_OBJ_GET_CHAR_SLOT(ciim->_class->name), name.len, name.ptr, @@ -9218,7 +9218,7 @@ static int ciim_on_each_method (moo_t* moo, moo_oop_dic_t dic, moo_oop_associati if (mth->tmpr_nargs != sig->tmpr_nargs) /* don't need MOO_OOP_TO_SMOOI */ { param_conflict: - moo_setsynerrbfmt (moo, MOO_SYNERR_CLASSNCIFCE, MOO_NULL, MOO_NULL, + moo_setsynerrbfmt (moo, MOO_SYNERR_CLASSNCIFCE, MOO_NULL, MOO_NULL, "%.*js>>%.*js parameters conflicting with %.*js>>%.*js", MOO_OBJ_GET_SIZE(ciim->_class->name), MOO_OBJ_GET_CHAR_SLOT(ciim->_class->name), name.len, name.ptr, @@ -9294,7 +9294,7 @@ static int check_class_interface_conformance (moo_t* moo) { const moo_ooch_t* oldmsg = moo_backuperrmsg(moo); mth = (moo_oop_method_t)cc->ifce_mths[j].ptr[i]; /* in case gc has been triggered in moo_putatdic */ - moo_seterrbfmt (moo, moo_geterrnum(moo), "unable to put interface method %.*js>>%.*js to %.*js - %js", + moo_seterrbfmt (moo, moo_geterrnum(moo), "unable to put interface method %.*js>>%.*js to %.*js - %js", MOO_OBJ_GET_SIZE(mth->owner->name), MOO_OBJ_GET_CHAR_SLOT(mth->owner->name), MOO_OBJ_GET_SIZE(mth->name), MOO_OBJ_GET_CHAR_SLOT(mth->name), MOO_OBJ_GET_SIZE(cc->self_oop->name), MOO_OBJ_GET_CHAR_SLOT(cc->self_oop->name), @@ -9310,7 +9310,7 @@ static int check_class_interface_conformance (moo_t* moo) static int __compile_class_definition (moo_t* moo, int class_type) { - /* + /* * class-definition := class class-modifier? class-name super-class-spec interface-spec? (class-body | class-module-import) * * class-modifier := "(" (#byte | #character | #word | #pointer)? ")" @@ -9319,7 +9319,7 @@ static int __compile_class_definition (moo_t* moo, int class_type) * interface-name-list := interface-name | interface-name "," inteface-name-list * class-body := "{" variable-definition* method-definition* "}" * class-module-import := from "module-name-string" - * + * * TOOD: add | |, |+ |, |* | * variable-definition := (#var | #variable) variable-modifier? variable-list "." * variable-modifier := "(" (#class | #classinst)? ")" @@ -9366,7 +9366,7 @@ static int __compile_class_definition (moo_t* moo, int class_type) } #endif - /* [NOTE] TOKEN_NAME(moo) doesn't contain the full name if it's nested + /* [NOTE] TOKEN_NAME(moo) doesn't contain the full name if it's nested * inside a class. it is merely a name that appeared in the source * code. * TODO: compose the full name by traversing the namespace chain. */ @@ -9391,7 +9391,7 @@ static int __compile_class_definition (moo_t* moo, int class_type) { cc->ns_oop = moo->sysdic; } - GET_TOKEN (moo); + GET_TOKEN (moo); if (class_type == CLASS_TYPE_EXTEND) { @@ -9405,7 +9405,7 @@ static int __compile_class_definition (moo_t* moo, int class_type) MOO_OBJ_GET_FLAGS_KERNEL(ass->value) != MOO_OBJ_FLAGS_KERNEL_IMMATURE) { /* the value must be a class object. - * and it must be either a user-defined(0) or completed kernel built-in(2). + * and it must be either a user-defined(0) or completed kernel built-in(2). * an incomplete kernel built-in class object(1) can not be extended */ cc->self_oop = (moo_oop_class_t)ass->value; } @@ -9418,7 +9418,7 @@ static int __compile_class_definition (moo_t* moo, int class_type) cc->super_oop = cc->self_oop->superclass; MOO_ASSERT (moo, cc->super_oop == moo->_nil || MOO_CLASSOF(moo, cc->super_oop) == moo->_class); - + if (TOKEN_TYPE(moo) == MOO_IOTOK_LBRACK) { if (process_class_interfaces(moo) <= -1) return -1; @@ -9431,11 +9431,11 @@ static int __compile_class_definition (moo_t* moo, int class_type) ass = moo_lookupdic_noseterr(moo, (moo_oop_dic_t)cc->ns_oop, &cc->name); if (ass) { - if (MOO_CLASSOF(moo, ass->value) != moo->_class || + if (MOO_CLASSOF(moo, ass->value) != moo->_class || MOO_OBJ_GET_FLAGS_KERNEL(ass->value) == MOO_OBJ_FLAGS_KERNEL_MATURE) { - /* the object found with the name is not a class object - * or the the class object found is a fully defined kernel + /* the object found with the name is not a class object + * or the the class object found is a fully defined kernel * class object */ moo_setsynerrbfmt (moo, MOO_SYNERR_NAMEDUPL, &cc->fqn_loc, &cc->name, "duplicate class name"); return -1; @@ -9482,7 +9482,7 @@ static int __compile_class_definition (moo_t* moo, int class_type) spec = MOO_OOP_TO_SMOOI(c->spec); self_spec = MOO_OOP_TO_SMOOI(c->selfspec); - /* [NOTE] class variables are not inherited. + /* [NOTE] class variables are not inherited. * so no data about them are not transferred over */ if ((cc->flags & CLASS_INDEXED) && cc->indexed_type != MOO_OBJ_TYPE_OOP) @@ -9491,8 +9491,8 @@ static int __compile_class_definition (moo_t* moo, int class_type) if (MOO_CLASS_SPEC_INDEXED_TYPE(spec) == MOO_OBJ_TYPE_OOP && MOO_CLASS_SPEC_NAMED_INSTVARS(spec) > 0) { /* a non-pointer object cannot inherit from a pointer object with instance variables */ - moo_setsynerrbfmt (moo, MOO_SYNERR_INHERITBANNED, &cc->fqn_loc, &cc->fqn, - "the non-pointer class %.*js cannot inherit from a pointer class defined with instance variables", + moo_setsynerrbfmt (moo, MOO_SYNERR_INHERITBANNED, &cc->fqn_loc, &cc->fqn, + "the non-pointer class %.*js cannot inherit from a pointer class defined with instance variables", cc->fqn.len, cc->fqn.ptr); return -1; } @@ -9504,7 +9504,7 @@ static int __compile_class_definition (moo_t* moo, int class_type) if (cc->non_pointer_instsize < MOO_CLASS_SPEC_NAMED_INSTVARS(spec)) { moo_setsynerrbfmt (moo, MOO_SYNERR_NPINSTSIZEINVAL, &type_loc, MOO_NULL, - "the instance size(%zu) for the non-pointer class %.*js must not be less than the size(%zu) defined in the superclass ", + "the instance size(%zu) for the non-pointer class %.*js must not be less than the size(%zu) defined in the superclass ", cc->non_pointer_instsize, cc->fqn.len, cc->fqn.ptr, (moo_oow_t)MOO_CLASS_SPEC_NAMED_INSTVARS(spec)); return -1; } @@ -9528,12 +9528,12 @@ static int __compile_class_definition (moo_t* moo, int class_type) file_name = cc->fqn_loc.file; if (!file_name) file_name = &_nul; - if (moo_addfiletodbgi(moo, file_name, &file_offset) <= -1) + if (moo_addfiletodbgi(moo, file_name, &file_offset) <= -1) { /* TODO: warning */ file_offset = 0; } - else if (file_offset > MOO_SMOOI_MAX) + else if (file_offset > MOO_SMOOI_MAX) { /* TODO: warning */ file_offset = 0; @@ -9551,7 +9551,7 @@ static int __compile_class_definition (moo_t* moo, int class_type) moo_oop_char_t pds; /* when a class is extended, a new variable cannot be added */ - if (is_token_word(moo, VOCA_VAR) || is_token_word(moo, VOCA_VARIABLE) || + if (is_token_word(moo, VOCA_VAR) || is_token_word(moo, VOCA_VARIABLE) || is_token_binary_selector(moo, VOCA_VBAR) || is_token_binary_selector(moo, VOCA_VBAR_PLUS) || is_token_binary_selector(moo, VOCA_VBAR_ASTER)) @@ -9602,7 +9602,7 @@ static int __compile_class_definition (moo_t* moo, int class_type) { last = tok; /* it falls back to the name space of the class */ - ns_oop = cc->ns_oop; + ns_oop = cc->ns_oop; } if (import_pooldic(moo, cc, ns_oop, &last, &tok, &loc) <= -1) return -1; @@ -9660,7 +9660,7 @@ static int __compile_class_definition (moo_t* moo, int class_type) * even if the modname field is set in the class object itself * by make_define_class(), i pass the module name in the compiler * memory(not part of the object memory) to moo_importmod(). - * no big overhead as it's already available. but Accessing + * no big overhead as it's already available. but Accessing * this extra module name, i'm free from GC headache */ if (moo_importmod(moo, cc->self_oop, cc->modname.ptr, cc->modname.len) <= -1) { @@ -9889,7 +9889,7 @@ static int __compile_interface_definition (moo_t* moo) } #endif - /* [NOTE] TOKEN_NAME(moo) doesn't contain the full name if it's nested + /* [NOTE] TOKEN_NAME(moo) doesn't contain the full name if it's nested * inside a class. it is merely a name that appeared in the source * code. * TODO: compose the full name by traversing the namespace chain. */ @@ -9915,7 +9915,7 @@ static int __compile_interface_definition (moo_t* moo) { ifce->ns_oop = moo->sysdic; } - GET_TOKEN (moo); + GET_TOKEN (moo); MOO_INFO2 (moo, "Defining an interface %.*js\n", ifce->fqn.len, ifce->fqn.ptr); @@ -9936,7 +9936,7 @@ static int __compile_interface_definition (moo_t* moo) GET_TOKEN (moo); /* an interface cannot have variables */ - if (is_token_word(moo, VOCA_VAR) || is_token_word(moo, VOCA_VARIABLE) || + if (is_token_word(moo, VOCA_VAR) || is_token_word(moo, VOCA_VARIABLE) || is_token_binary_selector(moo, VOCA_VBAR) || is_token_binary_selector(moo, VOCA_VBAR_PLUS) || is_token_binary_selector(moo, VOCA_VBAR_ASTER)) @@ -9953,12 +9953,12 @@ static int __compile_interface_definition (moo_t* moo) file_name = ifce->fqn_loc.file; if (!file_name) file_name = &_nul; - if (moo_addfiletodbgi(moo, file_name, &file_offset) <= -1) + if (moo_addfiletodbgi(moo, file_name, &file_offset) <= -1) { /* TODO: warning */ file_offset = 0; } - else if (file_offset > MOO_SMOOI_MAX) + else if (file_offset > MOO_SMOOI_MAX) { /* TODO: warning */ file_offset = 0; @@ -10189,9 +10189,9 @@ static int __compile_pooldic_definition (moo_t* moo) } #endif - /* [NOTE] TOKEN_NAME(moo) doesn't contain the full name if it's nested + /* [NOTE] TOKEN_NAME(moo) doesn't contain the full name if it's nested * inside a class. it is merely a name that appeared in the source - * code. + * code. * TODO: compose the full name by traversing the namespace chain. */ if (set_pooldic_fqn(moo, pd, TOKEN_NAME(moo)) <= -1) goto oops; pd->fqn_loc = moo->c->tok.loc; @@ -10452,7 +10452,7 @@ static int compile_pragma_definition (moo_t* moo) { /* #pragma push() - saves the pragma flags and keep the existing flags */ /* #pragma push(reset) - saves the pragma flags and reset the flags to 0 */ - + } else if (is_token_word(moo, VOCA_POP)) { @@ -10505,13 +10505,13 @@ static int compile_pragma_definition (moo_t* moo) if (TOKEN_TYPE(moo) == MOO_IOTOK_PERIOD) goto done; } while (TOKEN_TYPE(moo) == MOO_IOTOK_COMMA); - + if (TOKEN_TYPE(moo) != MOO_IOTOK_PERIOD) { moo_setsynerr (moo, MOO_SYNERR_PERIOD, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - + done: GET_TOKEN (moo); return 0; @@ -10568,7 +10568,7 @@ static int compile_stream (moo_t* moo) { /* #main */ /* TODO: implement this */ - + } #endif else @@ -10633,7 +10633,7 @@ static void gc_cunit_chain (moo_t* moo) moo_cunit_class_t* cc; cc = (moo_cunit_class_t*)cunit; - if (cc->self_oop) + if (cc->self_oop) cc->self_oop = (moo_oop_class_t)moo_updateoopforgc(moo, (moo_oop_t)cc->self_oop); if (cc->super_oop) @@ -10673,7 +10673,7 @@ static void gc_cunit_chain (moo_t* moo) moo_cunit_interface_t* ifce; ifce = (moo_cunit_interface_t*)cunit; - if (ifce->self_oop) + if (ifce->self_oop) ifce->self_oop = (moo_oop_interface_t)moo_updateoopforgc(moo, (moo_oop_t)ifce->self_oop); if (ifce->ns_oop) @@ -10860,7 +10860,7 @@ static MOO_INLINE int _compile (moo_t* moo, moo_ioimpl_t io) if (!cbp) return -1; moo->c = moo_callocmem (moo, MOO_SIZEOF(*moo->c)); - if (!moo->c) + if (!moo->c) { moo_deregevtcb (moo, cbp); return -1; @@ -10878,12 +10878,12 @@ static MOO_INLINE int _compile (moo_t* moo, moo_ioimpl_t io) /* reset pragma flags */ moo->c->pragma_flags = 0; - + /* initialize some key fields */ moo->c->impl = io; moo->c->nungots = 0; - /* The name field and the includer field are MOO_NULL + /* The name field and the includer field are MOO_NULL * for the main stream */ MOO_MEMSET (&moo->c->arg, 0, MOO_SIZEOF(moo->c->arg)); moo->c->arg.line = 1; @@ -10907,7 +10907,7 @@ static MOO_INLINE int _compile (moo_t* moo, moo_ioimpl_t io) oops: /* an error occurred and control has reached here - * probably, some included files might not have been + * probably, some included files might not have been * closed. close them */ while (moo->c->curinp != &moo->c->arg) { diff --git a/lib/debug.c b/lib/debug.c index 14af148..f6f5ff3 100644 --- a/lib/debug.c +++ b/lib/debug.c @@ -126,7 +126,7 @@ int moo_addfiletodbgi (moo_t* moo, const moo_ooch_t* file_name, moo_oow_t* start moo_oow_t name_len, name_bytes, name_bytes_aligned, req_bytes; moo_dbgi_file_t* di; - if (!moo->dbgi) + if (!moo->dbgi) { if (start_offset) *start_offset = 0; return 0; /* debug information is disabled*/ @@ -139,7 +139,7 @@ int moo_addfiletodbgi (moo_t* moo, const moo_ooch_t* file_name, moo_oow_t* start do { di = (moo_dbgi_file_t*)&((moo_uint8_t*)moo->dbgi)[offset]; - if (moo_comp_oocstr((moo_ooch_t*)(di + 1), file_name) == 0) + if (moo_comp_oocstr((moo_ooch_t*)(di + 1), file_name) == 0) { if (start_offset) *start_offset = offset; return 0; @@ -183,7 +183,7 @@ int moo_addclasstodbgi (moo_t* moo, const moo_ooch_t* class_name, moo_oow_t file do { di = (moo_dbgi_class_t*)&((moo_uint8_t*)moo->dbgi)[offset]; - if (moo_comp_oocstr((moo_ooch_t*)(di + 1), class_name) == 0 && di->_file == file_offset && di->_line == file_line) + if (moo_comp_oocstr((moo_ooch_t*)(di + 1), class_name) == 0 && di->_file == file_offset && di->_line == file_line) { if (start_offset) *start_offset = offset; return 0; diff --git a/lib/decode.c b/lib/decode.c index 262af84..213d709 100644 --- a/lib/decode.c +++ b/lib/decode.c @@ -52,9 +52,9 @@ int moo_decode (moo_t* moo, moo_oop_method_t mth, const moo_oocs_t* classfqn) moo_ooi_t ip = 0, cdlen; /* byte code length is limited by the compiler. so moo_ooi_t is good enough */ moo_ooi_t fetched_instruction_pointer; moo_oow_t b1, b2; - + cdptr = MOO_METHOD_GET_CODE_BYTE(mth); - cdlen = MOO_METHOD_GET_CODE_SIZE(mth); + cdlen = MOO_METHOD_GET_CODE_SIZE(mth); if (classfqn) MOO_LOG3 (moo, DECODE_LOG_MASK, "%.*js>>%O\n", classfqn->len, classfqn->ptr, mth->name); @@ -427,7 +427,7 @@ int moo_decode (moo_t* moo, moo_oop_method_t mth, const moo_oocs_t* classfqn) /* -------------------------------------------------------- */ case BCODE_SEND_MESSAGE_X: case BCODE_SEND_MESSAGE_TO_SUPER_X: - /* b1 -> number of arguments + /* b1 -> number of arguments * b2 -> selector index stored in the literal frame */ FETCH_PARAM_CODE_TO (moo, b1); FETCH_PARAM_CODE_TO (moo, b2); @@ -446,7 +446,7 @@ int moo_decode (moo_t* moo, moo_oop_method_t mth, const moo_oocs_t* classfqn) handle_send_message: LOG_INST_3 (moo, "send_message%hs %zu @%zu", (((bcode >> 2) & 1)? "_to_super": ""), b1, b2); - break; + break; /* -------------------------------------------------------- */ diff --git a/lib/dic.c b/lib/dic.c index 6413741..fc3c80c 100644 --- a/lib/dic.c +++ b/lib/dic.c @@ -43,13 +43,13 @@ static moo_oop_oop_t expand_bucket (moo_t* moo, moo_oop_oop_t oldbuc) else if (oldsz < 400000) newsz = oldsz + (oldsz / 16); else if (oldsz < 800000) newsz = oldsz + (oldsz / 32); else if (oldsz < 1600000) newsz = oldsz + (oldsz / 64); - else + else { moo_oow_t inc, inc_max; inc = oldsz / 128; inc_max = MOO_OBJ_SIZE_MAX - oldsz; - if (inc > inc_max) + if (inc > inc_max) { if (inc_max > 0) inc = inc_max; else @@ -62,7 +62,7 @@ static moo_oop_oop_t expand_bucket (moo_t* moo, moo_oop_oop_t oldbuc) } moo_pushvolat (moo, (moo_oop_t*)&oldbuc); - newbuc = (moo_oop_oop_t)moo_instantiate(moo, moo->_array, MOO_NULL, newsz); + newbuc = (moo_oop_oop_t)moo_instantiate(moo, moo->_array, MOO_NULL, newsz); moo_popvolat (moo); if (!newbuc) return MOO_NULL; @@ -105,15 +105,15 @@ static moo_oop_association_t find_or_upsert (moo_t* moo, moo_oop_dic_t dic, moo_ index = hv % MOO_OBJ_GET_SIZE(dic->bucket); /* find */ - while ((moo_oop_t)(ass = (moo_oop_association_t)MOO_OBJ_GET_OOP_VAL(dic->bucket, index)) != moo->_nil) + while ((moo_oop_t)(ass = (moo_oop_association_t)MOO_OBJ_GET_OOP_VAL(dic->bucket, index)) != moo->_nil) { MOO_ASSERT (moo, MOO_CLASSOF(moo,ass) == moo->_association); /*MOO_ASSERT (moo, MOO_CLASSOF(moo,ass->key) == moo->_symbol);*/ MOO_ASSERT (moo, MOO_OBJ_IS_CHAR_POINTER(ass->key)); - if (MOO_OBJ_GET_CLASS(key) == MOO_OBJ_GET_CLASS(ass->key) && + if (MOO_OBJ_GET_CLASS(key) == MOO_OBJ_GET_CLASS(ass->key) && MOO_OBJ_GET_SIZE(key) == MOO_OBJ_GET_SIZE(ass->key) && - moo_equal_oochars(MOO_OBJ_GET_CHAR_SLOT(key), MOO_OBJ_GET_CHAR_SLOT(ass->key), MOO_OBJ_GET_SIZE(key))) + moo_equal_oochars(MOO_OBJ_GET_CHAR_SLOT(key), MOO_OBJ_GET_CHAR_SLOT(ass->key), MOO_OBJ_GET_SIZE(key))) { /* the value of MOO_NULL indicates no insertion or update. */ if (value) MOO_STORE_OOP (moo, &ass->value, value); /* update */ @@ -136,7 +136,7 @@ static moo_oop_association_t find_or_upsert (moo_t* moo, moo_oop_dic_t dic, moo_ tally = MOO_OOP_TO_SMOOI(dic->tally); if (tally >= MOO_SMOOI_MAX) { - /* this built-in dictionary is not allowed to hold more than + /* this built-in dictionary is not allowed to hold more than * MOO_SMOOI_MAX items for efficiency sake */ moo_seterrnum (moo, MOO_EDFULL); return MOO_NULL; @@ -148,7 +148,7 @@ static moo_oop_association_t find_or_upsert (moo_t* moo, moo_oop_dic_t dic, moo_ /* no conversion to moo_oow_t is necessary for tally + 1. * the maximum value of tally is checked to be MOO_SMOOI_MAX - 1. - * tally + 1 can produce at most MOO_SMOOI_MAX. above all, + * tally + 1 can produce at most MOO_SMOOI_MAX. above all, * MOO_SMOOI_MAX is way smaller than MOO_TYPE_MAX(moo_ooi_t). */ if (tally + 1 >= MOO_OBJ_GET_SIZE(dic->bucket)) { @@ -170,11 +170,11 @@ static moo_oop_association_t find_or_upsert (moo_t* moo, moo_oop_dic_t dic, moo_ /* recalculate the index for the expanded bucket */ index = hv % MOO_OBJ_GET_SIZE(dic->bucket); - while (MOO_OBJ_GET_OOP_VAL(dic->bucket, index) != moo->_nil) + while (MOO_OBJ_GET_OOP_VAL(dic->bucket, index) != moo->_nil) index = (index + 1) % MOO_OBJ_GET_SIZE(dic->bucket); } - /* create a new assocation of a key and a value since + /* create a new assocation of a key and a value since * the key isn't found in the root dictionary */ ass = (moo_oop_association_t)moo_instantiate(moo, moo->_association, MOO_NULL, 0); if (!ass) goto oops; @@ -209,14 +209,14 @@ moo_oop_association_t moo_lookupdic_noseterr (moo_t* moo, moo_oop_dic_t dic, con index = moo_hash_oochars(name->ptr, name->len) % MOO_OBJ_GET_SIZE(dic->bucket); - while ((moo_oop_t)(ass = (moo_oop_association_t)MOO_OBJ_GET_OOP_VAL(dic->bucket, index)) != moo->_nil) + while ((moo_oop_t)(ass = (moo_oop_association_t)MOO_OBJ_GET_OOP_VAL(dic->bucket, index)) != moo->_nil) { MOO_ASSERT (moo, MOO_CLASSOF(moo,ass) == moo->_association); /*MOO_ASSERT (moo, MOO_CLASSOF(moo,ass->key) == moo->_symbol);*/ MOO_ASSERT (moo, MOO_OBJ_IS_CHAR_POINTER(ass->key)); if (name->len == MOO_OBJ_GET_SIZE(ass->key) && - moo_equal_oochars(name->ptr, MOO_OBJ_GET_CHAR_SLOT(ass->key), name->len)) + moo_equal_oochars(name->ptr, MOO_OBJ_GET_CHAR_SLOT(ass->key), name->len)) { return ass; } @@ -226,8 +226,8 @@ moo_oop_association_t moo_lookupdic_noseterr (moo_t* moo, moo_oop_dic_t dic, con /* when value is MOO_NULL, perform no insertion */ - /* moo_seterrXXX() is not called here. the dictionary lookup is very frequent - * and so is lookup failure. for instance, moo_findmethod() calls this over + /* moo_seterrXXX() is not called here. the dictionary lookup is very frequent + * and so is lookup failure. for instance, moo_findmethod() calls this over * a class chain. there might be a failure at each class level. it's waste to * set the error information whenever the failure occurs. * the caller of this function must set the error information upon failure */ @@ -293,14 +293,14 @@ int moo_deletedic (moo_t* moo, moo_oop_dic_t dic, const moo_oocs_t* name) index = hv % bs; /* find */ - while ((moo_oop_t)(ass = (moo_oop_association_t)MOO_OBJ_GET_OOP_VAL(dic->bucket, index)) != moo->_nil) + while ((moo_oop_t)(ass = (moo_oop_association_t)MOO_OBJ_GET_OOP_VAL(dic->bucket, index)) != moo->_nil) { MOO_ASSERT (moo, MOO_CLASSOF(moo,ass) == moo->_association); /*MOO_ASSERT (moo, MOO_CLASSOF(moo,ass->key) == moo->_symbol);*/ MOO_ASSERT (moo, MOO_OBJ_IS_CHAR_POINTER(ass->key)); if (name->len == MOO_OBJ_GET_SIZE(ass->key) && - moo_equal_oochars(name->ptr, MOO_OBJ_GET_CHAR_SLOT(ass->key), name->len)) + moo_equal_oochars(name->ptr, MOO_OBJ_GET_CHAR_SLOT(ass->key), name->len)) { goto found; } diff --git a/lib/err.c b/lib/err.c index 649b8a0..b125269 100644 --- a/lib/err.c +++ b/lib/err.c @@ -68,7 +68,7 @@ static moo_ooch_t* errstr[] = errstr_8, errstr_9, errstr_10, errstr_11, errstr_12, errstr_13, errstr_14, errstr_15, errstr_16, errstr_17, errstr_18, errstr_19, errstr_20, errstr_21, errstr_22, errstr_23, errstr_24, errstr_25, errstr_26, errstr_27, errstr_28, errstr_29, errstr_30, errstr_31, - errstr_32, errstr_33 + errstr_32, errstr_33 }; #if defined(MOO_INCLUDE_COMPILER) @@ -165,12 +165,12 @@ static moo_ooch_t* synerrstr[] = synerrstr_56, synerrstr_57, synerrstr_58, synerrstr_59, synerrstr_60, synerrstr_61, synerrstr_62, synerrstr_63, synerrstr_64, synerrstr_65, synerrstr_66, synerrstr_67, synerrstr_68, synerrstr_69, synerrstr_70, synerrstr_71, synerrstr_72, synerrstr_73, synerrstr_74, synerrstr_75, synerrstr_76, synerrstr_77, synerrstr_78, synerrstr_79, - synerrstr_80 + synerrstr_80 }; #endif /* END: GENERATED WITH generr.moo */ -/* -------------------------------------------------------------------------- +/* -------------------------------------------------------------------------- * ERROR NUMBER TO STRING CONVERSION * -------------------------------------------------------------------------- */ const moo_ooch_t* moo_errnum_to_errstr (moo_errnum_t errnum) @@ -187,7 +187,7 @@ static const moo_ooch_t* synerr_to_errstr (moo_synerrnum_t errnum) } #endif -/* -------------------------------------------------------------------------- +/* -------------------------------------------------------------------------- * ERROR NUMBER/MESSAGE HANDLING * -------------------------------------------------------------------------- */ const moo_ooch_t* moo_geterrstr (moo_t* moo) @@ -216,8 +216,8 @@ const moo_ooch_t* moo_backuperrmsg (moo_t* moo) void moo_seterrnum (moo_t* moo, moo_errnum_t errnum) { if (moo->shuterr) return; - moo->errnum = errnum; - moo->errmsg.len = 0; + moo->errnum = errnum; + moo->errmsg.len = 0; } @@ -375,11 +375,11 @@ void moo_seterrbfmtwithsyserr (moo_t* moo, int syserr_type, int syserr_code, con va_list ap; if (moo->shuterr) return; - + if (moo->vmprim.syserrstrb) { errnum = moo->vmprim.syserrstrb(moo, syserr_type, syserr_code, moo->errmsg.tmpbuf.bch, MOO_COUNTOF(moo->errmsg.tmpbuf.bch)); - + va_start (ap, fmt); moo_seterrbfmtv (moo, errnum, fmt, ap); va_end (ap); @@ -432,7 +432,7 @@ void moo_seterrufmtwithsyserr (moo_t* moo, int syserr_type, int syserr_code, con va_list ap; if (moo->shuterr) return; - + if (moo->vmprim.syserrstrb) { errnum = moo->vmprim.syserrstrb(moo, syserr_type, syserr_code, moo->errmsg.tmpbuf.bch, MOO_COUNTOF(moo->errmsg.tmpbuf.bch)); @@ -490,7 +490,7 @@ void moo_setsynerrbfmt (moo_t* moo, moo_synerrnum_t num, const moo_ioloc_t* loc, if (moo->shuterr) return; - if (msgfmt) + if (msgfmt) { va_list ap; int i, selen; @@ -504,14 +504,14 @@ void moo_setsynerrbfmt (moo_t* moo, moo_synerrnum_t num, const moo_ioloc_t* loc, for (i = 0; i < selen; i++) moo->errmsg.buf[i] = syntax_error[i]; moo->errmsg.buf[MOO_COUNTOF(moo->errmsg.buf) - 1] = '\0'; } - else + else { moo_seterrbfmt (moo, MOO_ESYNERR, "%hs%js", syntax_error, synerr_to_errstr(num)); } moo->c->synerr.num = num; /* The SCO compiler complains of this ternary operation saying: - * error: operands have incompatible types: op ":" + * error: operands have incompatible types: op ":" * it seems to complain of type mismatch between *loc and * moo->c->tok.loc due to 'const' prefixed to loc. */ /*moo->c->synerr.loc = loc? *loc: moo->c->tok.loc;*/ @@ -523,10 +523,10 @@ void moo_setsynerrbfmt (moo_t* moo, moo_synerrnum_t num, const moo_ioloc_t* loc, { moo->c->synerr.loc = moo->c->tok.loc; } - + if (tgt) { - if (tgt->len >= MOO_COUNTOF(moo->c->synerr_tgtbuf) && + if (tgt->len >= MOO_COUNTOF(moo->c->synerr_tgtbuf) && moo_copyoocharstosbuf(moo, tgt->ptr, tgt->len, MOO_SBUF_ID_SYNERR) >= 0) { moo->c->synerr.tgt.ptr = moo->sbuf[MOO_SBUF_ID_SYNERR].ptr; @@ -540,7 +540,7 @@ void moo_setsynerrbfmt (moo_t* moo, moo_synerrnum_t num, const moo_ioloc_t* loc, moo_copy_oochars (moo->c->synerr.tgt.ptr, tgt->ptr, moo->c->synerr.tgt.len); } } - else + else { moo->c->synerr.tgt.ptr = MOO_NULL; moo->c->synerr.tgt.len = 0; @@ -553,7 +553,7 @@ void moo_setsynerrufmt (moo_t* moo, moo_synerrnum_t num, const moo_ioloc_t* loc, if (moo->shuterr) return; - if (msgfmt) + if (msgfmt) { va_list ap; int i, selen; @@ -567,14 +567,14 @@ void moo_setsynerrufmt (moo_t* moo, moo_synerrnum_t num, const moo_ioloc_t* loc, for (i = 0; i < selen; i++) moo->errmsg.buf[i] = syntax_error[i]; moo->errmsg.buf[MOO_COUNTOF(moo->errmsg.buf) - 1] = '\0'; } - else + else { moo_seterrbfmt (moo, MOO_ESYNERR, "%hs%js", syntax_error, synerr_to_errstr(num)); } moo->c->synerr.num = num; /* The SCO compiler complains of this ternary operation saying: - * error: operands have incompatible types: op ":" + * error: operands have incompatible types: op ":" * it seems to complain of type mismatch between *loc and * moo->c->tok.loc due to 'const' prefixed to loc. */ /*moo->c->synerr.loc = loc? *loc: moo->c->tok.loc;*/ @@ -589,7 +589,7 @@ void moo_setsynerrufmt (moo_t* moo, moo_synerrnum_t num, const moo_ioloc_t* loc, if (tgt) { - if (tgt->len >= MOO_COUNTOF(moo->c->synerr_tgtbuf) && + if (tgt->len >= MOO_COUNTOF(moo->c->synerr_tgtbuf) && moo_copyoocharstosbuf(moo, tgt->ptr, tgt->len, MOO_SBUF_ID_SYNERR) >= 0) { moo->c->synerr.tgt.ptr = moo->sbuf[MOO_SBUF_ID_SYNERR].ptr; @@ -603,7 +603,7 @@ void moo_setsynerrufmt (moo_t* moo, moo_synerrnum_t num, const moo_ioloc_t* loc, moo_copy_oochars (moo->c->synerr.tgt.ptr, tgt->ptr, moo->c->synerr.tgt.len); } } - else + else { moo->c->synerr.tgt.ptr = MOO_NULL; moo->c->synerr.tgt.len = 0; diff --git a/lib/exec.c b/lib/exec.c index 7f5f1e2..2bf54d2 100644 --- a/lib/exec.c +++ b/lib/exec.c @@ -40,7 +40,7 @@ static const char* io_type_str[] = static MOO_INLINE const char* proc_state_to_string (int state) { - static const moo_bch_t* str[] = + static const moo_bch_t* str[] = { "TERMINATED", "SUSPENDED", @@ -142,7 +142,7 @@ static int send_message (moo_t* moo, moo_oop_char_t selector, moo_ooi_t nargs, i static MOO_INLINE int vm_startup (moo_t* moo) { moo_oow_t i; - + MOO_DEBUG0 (moo, "VM started up\n"); for (i = 0; i < moo->sem_io_map_capa; i++) @@ -163,18 +163,18 @@ static MOO_INLINE void vm_cleanup (moo_t* moo) { moo_oow_t i; -/* TODO: clean up semaphores being waited on +/* TODO: clean up semaphores being waited on MOO_ASSERT (moo, moo->sem_io_wait_count == 0); */ if (moo->processor->total_count != MOO_SMOOI_TO_OOP(0)) { /* the stock kernel code is supposed to stop all processes. * if the code reaches here, the kernel code must be buggy */ - MOO_LOG3 (moo, MOO_LOG_WARN, "Warning - non-zero number of processes upon VM clean-up - total: %zd runnable: %zd suspended: %zd\n", + MOO_LOG3 (moo, MOO_LOG_WARN, "Warning - non-zero number of processes upon VM clean-up - total: %zd runnable: %zd suspended: %zd\n", (moo_ooi_t)MOO_OOP_TO_SMOOI(moo->processor->total_count), (moo_ooi_t)MOO_OOP_TO_SMOOI(moo->processor->runnable.count), (moo_ooi_t)MOO_OOP_TO_SMOOI(moo->processor->suspended.count)); - + MOO_LOG0 (moo, MOO_LOG_WARN, "Warning - terminating all residue processes\n"); terminate_all_processes (moo); } @@ -204,7 +204,7 @@ static MOO_INLINE void vm_cleanup (moo_t* moo) MOO_ASSERT (moo, moo->sem_io_map[i] <= -1); } - else + else { i++; } @@ -215,7 +215,7 @@ static MOO_INLINE void vm_cleanup (moo_t* moo) moo->vmprim.vm_gettime (moo, &moo->exec_end_time); /* raw time. no adjustment */ moo->vmprim.vm_cleanup (moo); - + moo->sem_gcfin = (moo_oop_semaphore_t)moo->_nil; moo->sem_gcfin_sigreq = 0; @@ -234,7 +234,7 @@ static MOO_INLINE void vm_gettime (moo_t* moo, moo_ntime_t* now) { moo->vmprim.vm_gettime (moo, now); /* in vm_startup(), moo->exec_start_time has been set to the time of - * that moment. time returned here get offset by moo->exec_start_time and + * that moment. time returned here get offset by moo->exec_start_time and * thus becomes relative to it. this way, it is kept small such that it * can be represented in a small integer with leaving almost zero chance * of overflow. */ @@ -410,9 +410,9 @@ static MOO_INLINE void wake_process (moo_t* moo, moo_oop_process_t proc) proc->state = MOO_SMOOI_TO_OOP(PROC_STATE_RUNNING); MOO_STORE_OOP (moo, (moo_oop_t*)&moo->processor->active, (moo_oop_t)proc); - /* load the stack pointer from 'proc'. + /* load the stack pointer from 'proc'. * moo->processor->active points to 'proc' now. */ - LOAD_ACTIVE_SP(moo); + LOAD_ACTIVE_SP(moo); /* activate the suspended context of the new process */ SWITCH_ACTIVE_CONTEXT (moo, proc->current_context); @@ -462,7 +462,7 @@ static MOO_INLINE void switch_to_next_runnable_process (moo_t* moo) static MOO_INLINE void chain_into_processor (moo_t* moo, moo_oop_process_t proc, int new_state) { - /* the process is not scheduled at all. + /* the process is not scheduled at all. * link it to the processor's process list. */ moo_ooi_t runnable_count; moo_ooi_t suspended_count; @@ -474,7 +474,7 @@ static MOO_INLINE void chain_into_processor (moo_t* moo, moo_oop_process_t proc, MOO_ASSERT (moo, new_state == PROC_STATE_RUNNABLE || new_state == PROC_STATE_RUNNING); #if defined(MOO_DEBUG_VM_PROCESSOR) - MOO_LOG3 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, + MOO_LOG3 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - process[%zd] %hs->%hs in chain_into_processor\n", MOO_OOP_TO_SMOOI(proc->id), proc_state_to_string(MOO_OOP_TO_SMOOI(proc->state)), @@ -561,7 +561,7 @@ static MOO_INLINE void chain_into_semaphore (moo_t* moo, moo_oop_process_t proc, /* append a process to the process list of a semaphore or a semaphore group */ /* a process chained to a semaphore cannot get chained to - * a semaphore again. a process can get chained to a single semaphore + * a semaphore again. a process can get chained to a single semaphore * or a single semaphore group only */ if ((moo_oop_t)proc->sem != moo->_nil) return; /* ignore it if it happens anyway. TODO: is it desirable???? */ @@ -596,11 +596,11 @@ static MOO_INLINE void unchain_from_semaphore (moo_t* moo, moo_oop_process_t pro MOO_OFFSETOF(moo_semaphore_group_t,waiting)); /* proc->sem may be one of a semaphore or a semaphore group. - * i assume that 'waiting' is defined to the same position - * in both Semaphore and SemaphoreGroup. there is no need to + * i assume that 'waiting' is defined to the same position + * in both Semaphore and SemaphoreGroup. there is no need to * write different code for each class. */ sem = (moo_oop_semaphore_t)proc->sem; /* semgrp = (moo_oop_semaphore_group_t)proc->sem */ - MOO_DELETE_FROM_OOP_LIST (moo, &sem->waiting, proc, sem_wait); + MOO_DELETE_FROM_OOP_LIST (moo, &sem->waiting, proc, sem_wait); proc->sem_wait.prev = (moo_oop_process_t)moo->_nil; proc->sem_wait.next = (moo_oop_process_t)moo->_nil; @@ -654,7 +654,7 @@ static void dump_process_info (moo_t* moo, moo_bitmask_t log_mask) /* dump process IDs waiting for input signaling */ MOO_LOG0 (moo, log_mask, "(wpi"); sem = moo->sem_io_tuple[index].sem[MOO_SEMAPHORE_IO_TYPE_INPUT]; - if (sem) + if (sem) { moo_oop_process_t wp; /* waiting process */ for (wp = sem->waiting.first; (moo_oop_t)wp != moo->_nil; wp = wp->sem_wait.next) @@ -670,7 +670,7 @@ static void dump_process_info (moo_t* moo, moo_bitmask_t log_mask) /* dump process IDs waitingt for output signaling */ MOO_LOG0 (moo, log_mask, ",wpo"); sem = moo->sem_io_tuple[index].sem[MOO_SEMAPHORE_IO_TYPE_OUTPUT]; - if (sem) + if (sem) { moo_oop_process_t wp; /* waiting process */ for (wp = sem->waiting.first; (moo_oop_t)wp != moo->_nil; wp = wp->sem_wait.next) @@ -719,8 +719,8 @@ static void terminate_process (moo_t* moo, moo_oop_process_t proc) MOO_ASSERT (moo, moo->processor->active == moo->nil_process); if (MOO_LOG_ENABLED(moo, MOO_LOG_IC | MOO_LOG_DEBUG)) { - MOO_LOG5 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, - "No runnable process after termination of process %zd - total %zd runnable/running %zd suspended %zd - sem_io_wait_count %zu\n", + MOO_LOG5 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, + "No runnable process after termination of process %zd - total %zd runnable/running %zd suspended %zd - sem_io_wait_count %zu\n", MOO_OOP_TO_SMOOI(proc->id), MOO_OOP_TO_SMOOI(moo->processor->total_count), MOO_OOP_TO_SMOOI(moo->processor->runnable.count), @@ -767,7 +767,7 @@ static void terminate_process (moo_t* moo, moo_oop_process_t proc) MOO_DEBUG1 (moo, "terminate_process(sg) - lowered sem_io_wait_count to %zu\n", moo->sem_io_wait_count); } } - else + else { MOO_ASSERT (moo, MOO_CLASSOF(moo, proc->sem) == moo->_semaphore); if (((moo_oop_semaphore_t)proc->sem)->subtype == MOO_SMOOI_TO_OOP(MOO_SEMAPHORE_SUBTYPE_IO)) @@ -775,7 +775,7 @@ static void terminate_process (moo_t* moo, moo_oop_process_t proc) MOO_ASSERT (moo, moo->sem_io_wait_count > 0); moo->sem_io_wait_count--; MOO_DEBUG3 (moo, "terminate_process(s) - lowered sem_io_wait_count to %zu for IO semaphore at index %zd handle %zd\n", - moo->sem_io_wait_count, + moo->sem_io_wait_count, MOO_OOP_TO_SMOOI(((moo_oop_semaphore_t)proc->sem)->u.io.index), MOO_OOP_TO_SMOOI(((moo_oop_semaphore_t)proc->sem)->u.io.handle) ); @@ -827,7 +827,7 @@ static void resume_process (moo_t* moo, moo_oop_process_t proc) /* don't switch to this process. just change the state to RUNNABLE. * process switching should be triggerd by the process scheduler. */ - chain_into_processor (moo, proc, PROC_STATE_RUNNABLE); + chain_into_processor (moo, proc, PROC_STATE_RUNNABLE); /*MOO_STORE_OOP (moo, &proc->current_context = proc->initial_context);*/ } #if 0 @@ -865,7 +865,7 @@ static void suspend_process (moo_t* moo, moo_oop_process_t proc) sleep_active_process (moo, PROC_STATE_RUNNABLE); unchain_from_processor (moo, proc, PROC_STATE_SUSPENDED); - /* the last running/runnable process has been unchained + /* the last running/runnable process has been unchained * from the processor and set to SUSPENDED. the active * process must be the nil process */ MOO_ASSERT (moo, moo->processor->active == moo->nil_process); @@ -882,7 +882,7 @@ static void suspend_process (moo_t* moo, moo_oop_process_t proc) * switch_to_process() has changed the active process. */ unchain_from_processor (moo, proc, PROC_STATE_SUSPENDED); MOO_ASSERT (moo, moo->processor->active != moo->nil_process); - switch_to_process (moo, nrp, PROC_STATE_SUSPENDED); + switch_to_process (moo, nrp, PROC_STATE_SUSPENDED); } } else @@ -902,10 +902,10 @@ static void yield_process (moo_t* moo, moo_oop_process_t proc) MOO_ASSERT (moo, proc == moo->processor->active); - nrp = find_next_runnable_process (moo); + nrp = find_next_runnable_process (moo); /* if there are more than 1 runnable processes, the next * runnable process must be different from proc */ - if (nrp != proc) + if (nrp != proc) { #if defined(MOO_DEBUG_VM_PROCESSOR) MOO_LOG2 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - process[%zd] %hs->RUNNABLE in yield_process\n", MOO_OOP_TO_SMOOI(proc->id), proc_state_to_string(MOO_OOP_TO_SMOOI(proc->state))); @@ -967,17 +967,17 @@ static moo_oop_process_t signal_semaphore (moo_t* moo, moo_oop_semaphore_t sem) * ------------------------------------------------------------ * the waiting process has been suspended after a waiting * primitive function in Semaphore or SemaphoreGroup. - * the top of the stack of the process must hold the temporary + * the top of the stack of the process must hold the temporary * return value set by await_semaphore() or await_semaphore_group(). - * change the return value forcibly to the actual signaled + * change the return value forcibly to the actual signaled * semaphore */ MOO_ASSERT (moo, MOO_OOP_TO_SMOOI(proc->sp) < (moo_ooi_t)(MOO_OBJ_GET_SIZE(proc) - MOO_PROCESS_NAMED_INSTVARS)); sp = MOO_OOP_TO_SMOOI(proc->sp); MOO_STORE_OOP (moo, &proc->stack[sp], (moo_oop_t)sem); - /* i should decrement the counter as long as the group being + /* i should decrement the counter as long as the group being * signaled contains an IO semaphore */ - if (MOO_OOP_TO_SMOOI(sg->sem_io_count) > 0) + if (MOO_OOP_TO_SMOOI(sg->sem_io_count) > 0) { MOO_ASSERT (moo, moo->sem_io_wait_count > 0); moo->sem_io_wait_count--; @@ -987,14 +987,14 @@ static moo_oop_process_t signal_semaphore (moo_t* moo, moo_oop_semaphore_t sem) } } - /* if the semaphore belongs to a semaphore group and the control reaches + /* if the semaphore belongs to a semaphore group and the control reaches * here, no process is waiting on the semaphore group. however, a process * may still be waiting on the semaphore. If a process waits on a semaphore - * group and another process wait on a semaphore that belongs to the - * semaphore group, the process waiting on the group always wins. - * + * group and another process wait on a semaphore that belongs to the + * semaphore group, the process waiting on the group always wins. + * * TODO: implement a fair scheduling policy. or do i simply have to disallow individual wait on a semaphore belonging to a group? - * + * * if it doesn't belong to a sempahore group, i'm free from the starvation issue. */ if ((moo_oop_t)sem->waiting.first == moo->_nil) @@ -1023,12 +1023,12 @@ static moo_oop_process_t signal_semaphore (moo_t* moo, moo_oop_semaphore_t sem) /* [NOTE] no GC must occur as 'proc' isn't protected with moo_pushvolat(). */ - /* detach a process from a semaphore's waiting list and + /* detach a process from a semaphore's waiting list and * make it runnable */ unchain_from_semaphore (moo, proc); resume_process (moo, proc); - if (sem->subtype == MOO_SMOOI_TO_OOP(MOO_SEMAPHORE_SUBTYPE_IO)) + if (sem->subtype == MOO_SMOOI_TO_OOP(MOO_SEMAPHORE_SUBTYPE_IO)) { MOO_ASSERT (moo, moo->sem_io_wait_count > 0); moo->sem_io_wait_count--; @@ -1082,14 +1082,14 @@ static MOO_INLINE void await_semaphore (moo_t* moo, moo_oop_semaphore_t sem) proc = moo->processor->active; /* suspend the active process */ - suspend_process (moo, proc); + suspend_process (moo, proc); /* link the suspended process to the semaphore's process list */ - chain_into_semaphore (moo, proc, sem); + chain_into_semaphore (moo, proc, sem); MOO_ASSERT (moo, sem->waiting.last == proc); - if (sem->subtype == MOO_SMOOI_TO_OOP(MOO_SEMAPHORE_SUBTYPE_IO)) + if (sem->subtype == MOO_SMOOI_TO_OOP(MOO_SEMAPHORE_SUBTYPE_IO)) { moo->sem_io_wait_count++; MOO_DEBUG3 (moo, "await_semaphore - raised sem_io_wait_count to %zu for IO semaphore at index %zd handle %zd\n", @@ -1142,26 +1142,26 @@ static MOO_INLINE moo_oop_t await_semaphore_group (moo_t* moo, moo_oop_semaphore proc = moo->processor->active; /* suspend the active process */ - suspend_process (moo, proc); + suspend_process (moo, proc); /* link the suspended process to the semaphore group's process list */ - chain_into_semaphore (moo, proc, (moo_oop_semaphore_t)semgrp); + chain_into_semaphore (moo, proc, (moo_oop_semaphore_t)semgrp); MOO_ASSERT (moo, semgrp->waiting.last == proc); - if (MOO_OOP_TO_SMOOI(semgrp->sem_io_count) > 0) + if (MOO_OOP_TO_SMOOI(semgrp->sem_io_count) > 0) { /* there might be more than 1 IO semaphores in the group * but i increment moo->sem_io_wait_count by 1 only */ - moo->sem_io_wait_count++; + moo->sem_io_wait_count++; MOO_DEBUG1 (moo, "await_semaphore_group - raised sem_io_wait_count to %zu\n", moo->sem_io_wait_count); } - /* the current process will get suspended after the caller (mostly a + /* the current process will get suspended after the caller (mostly a * a primitive function handler) is over as it's added to a suspened * process list above */ MOO_ASSERT (moo, moo->processor->active != proc); - return moo->_nil; + return moo->_nil; } static void sift_up_sem_heap (moo_t* moo, moo_ooi_t index) @@ -1296,7 +1296,7 @@ static void delete_from_sem_heap (moo_t* moo, moo_ooi_t index) lastsem->u.timed.index = MOO_SMOOI_TO_OOP(index); moo->sem_heap[index] = lastsem; - if (SEM_HEAP_EARLIER_THAN(moo, lastsem, sem)) + if (SEM_HEAP_EARLIER_THAN(moo, lastsem, sem)) sift_up_sem_heap (moo, index); else sift_down_sem_heap (moo, index); @@ -1338,7 +1338,7 @@ static int add_sem_to_sem_io_tuple (moo_t* moo, moo_oop_semaphore_t sem, moo_ooi moo_seterrbfmt (moo, MOO_EINVAL, "handle %zd out of supported range", io_handle); return -1; } - + if (io_handle >= moo->sem_io_map_capa) { moo_oow_t new_capa, i; @@ -1348,7 +1348,7 @@ static int add_sem_to_sem_io_tuple (moo_t* moo, moo_oop_semaphore_t sem, moo_ooi new_capa = MOO_ALIGN_POW2(io_handle + 1, SEM_IO_MAP_ALIGN); tmp = moo_reallocmem (moo, moo->sem_io_map, MOO_SIZEOF(*tmp) * new_capa); - if (!tmp) + if (!tmp) { const moo_ooch_t* oldmsg = moo_backuperrmsg(moo); moo_seterrbfmt (moo, moo->errnum, "handle %zd out of supported range - %js", oldmsg); @@ -1367,7 +1367,7 @@ static int add_sem_to_sem_io_tuple (moo_t* moo, moo_oop_semaphore_t sem, moo_ooi /* this handle is not in any tuples. add it to a new tuple */ if (moo->sem_io_tuple_count >= SEM_IO_TUPLE_MAX) { - moo_seterrbfmt (moo, MOO_ESEMFLOOD, "too many IO semaphore tuples"); + moo_seterrbfmt (moo, MOO_ESEMFLOOD, "too many IO semaphore tuples"); return -1; } @@ -1387,13 +1387,13 @@ static int add_sem_to_sem_io_tuple (moo_t* moo, moo_oop_semaphore_t sem, moo_ooi } /* this condition must be true assuming SEM_IO_TUPLE_MAX <= MOO_SMOOI_MAX */ - MOO_ASSERT (moo, moo->sem_io_tuple_count <= MOO_SMOOI_MAX); + MOO_ASSERT (moo, moo->sem_io_tuple_count <= MOO_SMOOI_MAX); index = moo->sem_io_tuple_count; tuple_added = 1; /* safe to initialize before vm_muxadd() because - * moo->sem_io_tuple_count has not been incremented. + * moo->sem_io_tuple_count has not been incremented. * still no impact even if it fails. */ moo->sem_io_tuple[index].sem[MOO_SEMAPHORE_IO_TYPE_INPUT] = MOO_NULL; moo->sem_io_tuple[index].sem[MOO_SEMAPHORE_IO_TYPE_OUTPUT] = MOO_NULL; @@ -1422,7 +1422,7 @@ static int add_sem_to_sem_io_tuple (moo_t* moo, moo_oop_semaphore_t sem, moo_ooi moo_popvolat (moo); } - if (n <= -1) + if (n <= -1) { MOO_LOG3 (moo, MOO_LOG_WARN, "Failed to add IO semaphore at index %zd for %hs on handle %zd\n", index, io_type_str[io_type], io_handle); return -1; @@ -1440,7 +1440,7 @@ static int add_sem_to_sem_io_tuple (moo_t* moo, moo_oop_semaphore_t sem, moo_ooi moo->sem_io_tuple[index].sem[io_type] = sem; moo->sem_io_count++; - if (tuple_added) + if (tuple_added) { moo->sem_io_tuple_count++; moo->sem_io_map[io_handle] = index; @@ -1487,14 +1487,14 @@ static int delete_sem_from_sem_io_tuple (moo_t* moo, moo_oop_semaphore_t sem, in moo_pushvolat (moo, (moo_oop_t*)&sem); x = new_mask? moo->vmprim.vm_muxmod(moo, io_handle, new_mask): - moo->vmprim.vm_muxdel(moo, io_handle); + moo->vmprim.vm_muxdel(moo, io_handle); moo_popvolat (moo); - if (x <= -1) + if (x <= -1) { MOO_LOG3 (moo, MOO_LOG_WARN, "Failed to delete IO semaphore at index %zd handle %zd for %hs\n", index, io_handle, io_type_str[io_type]); if (!force) return -1; - /* [NOTE] + /* [NOTE] * this means there could be some issue handling the file handles. * the file handle might have been closed before reaching here. * assuming the callback works correctly, it's not likely that the @@ -1536,7 +1536,7 @@ static int delete_sem_from_sem_io_tuple (moo_t* moo, moo_oop_semaphore_t sem, in /* migrate the last item to the deleted slot to compact the gap */ moo->sem_io_tuple[index] = moo->sem_io_tuple[moo->sem_io_tuple_count]; - if (moo->sem_io_tuple[index].sem[MOO_SEMAPHORE_IO_TYPE_INPUT]) + if (moo->sem_io_tuple[index].sem[MOO_SEMAPHORE_IO_TYPE_INPUT]) moo->sem_io_tuple[index].sem[MOO_SEMAPHORE_IO_TYPE_INPUT]->u.io.index = MOO_SMOOI_TO_OOP(index); if (moo->sem_io_tuple[index].sem[MOO_SEMAPHORE_IO_TYPE_OUTPUT]) moo->sem_io_tuple[index].sem[MOO_SEMAPHORE_IO_TYPE_OUTPUT]->u.io.index = MOO_SMOOI_TO_OOP(index); @@ -1560,10 +1560,10 @@ static void _signal_io_semaphore (moo_t* moo, moo_oop_semaphore_t sem) if (moo->processor->active == moo->nil_process && (moo_oop_t)proc != moo->_nil) { - /* this is the only runnable process. + /* this is the only runnable process. * switch the process to the running state. * it uses wake_process() instead of - * switch_to_process() as there is no running + * switch_to_process() as there is no running * process at this moment */ MOO_ASSERT (moo, proc->state == MOO_SMOOI_TO_OOP(PROC_STATE_RUNNABLE)); MOO_ASSERT (moo, proc == moo->processor->runnable.first); @@ -1628,7 +1628,7 @@ void moo_releaseiohandle (moo_t* moo, moo_ooi_t io_handle) { MOO_ASSERT(moo, moo->sem_io_tuple[index].handle == io_handle); sem = moo->sem_io_tuple[index].sem[MOO_SEMAPHORE_IO_TYPE_INPUT]; - if (sem) + if (sem) { MOO_ASSERT(moo, sem->subtype == MOO_SMOOI_TO_OOP(MOO_SEMAPHORE_SUBTYPE_IO)); delete_sem_from_sem_io_tuple (moo, sem, 0); @@ -1646,7 +1646,7 @@ void moo_releaseiohandle (moo_t* moo, moo_ooi_t io_handle) { MOO_ASSERT(moo, moo->sem_io_tuple[index].handle == io_handle); sem = moo->sem_io_tuple[index].sem[MOO_SEMAPHORE_IO_TYPE_OUTPUT]; - if (sem) + if (sem) { MOO_ASSERT(moo, sem->subtype == MOO_SMOOI_TO_OOP(MOO_SEMAPHORE_SUBTYPE_IO)); delete_sem_from_sem_io_tuple (moo, sem, 0); @@ -1693,7 +1693,7 @@ static MOO_INLINE int activate_new_method (moo_t* moo, moo_oop_method_t mth, moo if (actual_nargs > nargs) { - /* more arguments than the method specification have been passed in. + /* more arguments than the method specification have been passed in. * it must be a variadic or liberal unary method. othewise, the compiler is buggy */ MOO_ASSERT (moo, MOO_METHOD_GET_PREAMBLE_FLAGS(MOO_OOP_TO_SMOOI(mth->preamble)) & (MOO_METHOD_PREAMBLE_FLAG_VARIADIC | MOO_METHOD_PREAMBLE_FLAG_LIBERAL)); actual_ntmprs = ntmprs + (actual_nargs - nargs); @@ -1705,7 +1705,7 @@ static MOO_INLINE int activate_new_method (moo_t* moo, moo_oop_method_t mth, moo moo_popvolat (moo); if (MOO_UNLIKELY(!ctx)) return -1; - MOO_STORE_OOP (moo, (moo_oop_t*)&ctx->sender, (moo_oop_t)moo->active_context); + MOO_STORE_OOP (moo, (moo_oop_t*)&ctx->sender, (moo_oop_t)moo->active_context); ctx->ip = MOO_SMOOI_TO_OOP(0); /* ctx->sp will be set further down */ @@ -1722,7 +1722,7 @@ static MOO_INLINE int activate_new_method (moo_t* moo, moo_oop_method_t mth, moo * +---------------------+ * | tmp1 (arg1) | slot[0] * | tmp2 (arg2) | slot[1] - * | tmp3 | slot[2] + * | tmp3 | slot[2] * | tmp4 | slot[3] * | tmp5 | slot[4] * +---------------------+ @@ -1734,10 +1734,10 @@ static MOO_INLINE int activate_new_method (moo_t* moo, moo_oop_method_t mth, moo ctx->home = moo->_nil;*/ MOO_STORE_OOP (moo, (moo_oop_t*)&ctx->origin, (moo_oop_t)ctx); /* point to self */ - /* + /* * Assume this message sending expression: * obj1 do: #this with: #that with: #it - * + * * It would be compiled to these logical byte-code sequences shown below: * push obj1 * push #this @@ -1746,9 +1746,9 @@ static MOO_INLINE int activate_new_method (moo_t* moo, moo_oop_method_t mth, moo * send #do:with: * * After three pushes, the stack looks like this. - * + * * | #it | <- sp - * | #that | sp - 1 + * | #that | sp - 1 * | #this | sp - 2 * | obj1 | sp - nargs * @@ -1789,7 +1789,7 @@ static MOO_INLINE int activate_new_method (moo_t* moo, moo_oop_method_t mth, moo MOO_ASSERT (moo, moo->sp >= -1); - /* the stack pointer in a context is a stack pointer of a process + /* the stack pointer in a context is a stack pointer of a process * before it is activated. this stack pointer is stored to the context * so that it is used to restore the process stack pointer upon returning * from a method context. */ @@ -1809,13 +1809,13 @@ static MOO_INLINE moo_oop_method_t find_method_in_class (moo_t* moo, moo_oop_cla mthdic = _class->mthdic[mth_type]; /* if a kernel class is not defined in the bootstrapping code, - * the method dictionary is still nil. you must define all the initial + * the method dictionary is still nil. you must define all the initial * kernel classes properly before you can use this function */ - MOO_ASSERT (moo, (moo_oop_t)mthdic != moo->_nil); + MOO_ASSERT (moo, (moo_oop_t)mthdic != moo->_nil); MOO_ASSERT (moo, MOO_CLASSOF(moo, mthdic) == moo->_method_dictionary); ass = (moo_oop_association_t)moo_lookupdic_noseterr(moo, mthdic, name); - if (ass) + if (ass) { /* found the method */ MOO_ASSERT (moo, MOO_CLASSOF(moo, ass->value) == moo->_method); @@ -1876,7 +1876,7 @@ moo_oop_method_t moo_findmethod_noseterr (moo_t* moo, moo_oop_t receiver, moo_oo if (_class == moo->_class) { /* receiver is a class object (an instance of Class) */ - c = (moo_oop_class_t)receiver; + c = (moo_oop_class_t)receiver; mth_type = MOO_METHOD_CLASS; } else @@ -1887,7 +1887,7 @@ moo_oop_method_t moo_findmethod_noseterr (moo_t* moo, moo_oop_t receiver, moo_oo } MOO_ASSERT (moo, (moo_oop_t)c != moo->_nil); - if (in_super) + if (in_super) { MOO_ASSERT (moo, moo->active_method != MOO_NULL); MOO_ASSERT (moo, moo->active_method->owner != MOO_NULL); @@ -1910,7 +1910,7 @@ moo_oop_method_t moo_findmethod_noseterr (moo_t* moo, moo_oop_t receiver, moo_oo /*mcidx = ((moo_oow_t)c + (moo_oow_t)selector) % MOO_METHOD_CACHE_SIZE; */ mcidx = ((moo_oow_t)_class ^ (moo_oow_t)selector) & (MOO_METHOD_CACHE_SIZE - 1); mcitm = &moo->method_cache[mth_type][mcidx]; - + if (mcitm->receiver_class == c && mcitm->selector == selector /*&& mcitm->method_type == mth_type*/) { /* cache hit */ @@ -1922,7 +1922,7 @@ moo_oop_method_t moo_findmethod_noseterr (moo_t* moo, moo_oop_t receiver, moo_oo /* [IMPORT] the method lookup logic should be the same as ciim_on_each_method() in comp.c */ mth = find_method_in_class_chain(moo, c, mth_type, &message); - if (mth) + if (mth) { #if defined(MOO_PROFILE_VM) moo->stat.method_cache_misses++; @@ -1939,7 +1939,7 @@ not_found: { /* the object is an instance of Class. find the method * in an instance method dictionary of Class also */ - + /*mcidx = MOO_HASH_INIT; mcidx = MOO_HASH_VALUE(mcidx, (moo_oow_t)_class); mcidx = MOO_HASH_VALUE(mcidx, (moo_oow_t)selector); @@ -1952,13 +1952,13 @@ not_found: { /* cache hit */ #if defined(MOO_PROFILE_VM) - moo->stat.method_cache_hits++; + moo->stat.method_cache_hits++; #endif return mcitm->method; } - + mth = find_method_in_class(moo, _class, MOO_METHOD_INSTANCE, &message); - if (mth) + if (mth) { #if defined(MOO_PROFILE_VM) moo->stat.method_cache_misses++; @@ -2017,7 +2017,7 @@ static int start_initial_process_and_context (moo_t* moo, const moo_oocs_t* objn #if defined(INVOKE_DIRECTLY) ass = moo_lookupsysdic(moo, objname); - if (!ass || MOO_CLASSOF(moo, ass->value) != moo->_class) + if (!ass || MOO_CLASSOF(moo, ass->value) != moo->_class) { MOO_LOG2 (moo, MOO_LOG_DEBUG, "Cannot find a class '%.*js'", objname->len, objname->ptr); return -1; @@ -2033,7 +2033,7 @@ static int start_initial_process_and_context (moo_t* moo, const moo_oocs_t* objn } mth = moo_findmethod(moo, moo, ass->value, sym_startup, 0); - if (!mth) + if (!mth) { MOO_LOG4 (moo, MOO_LOG_DEBUG, "Cannot find a startup method %.*js>>%.*js", objname->len, objname->ptr, mthname->len, mthname->ptr); return -1; @@ -2041,7 +2041,7 @@ static int start_initial_process_and_context (moo_t* moo, const moo_oocs_t* objn if (MOO_OOP_TO_SMOOI(mth->tmpr_nargs) > 0) { - /* this method expects more than 0 arguments. + /* this method expects more than 0 arguments. * i can't use it as a start-up method. TODO: overcome this problem - accept parameters.... */ @@ -2066,7 +2066,7 @@ TODO: overcome this problem - accept parameters.... } mth = moo_findmethod(moo, (moo_oop_t)moo->_system, (moo_oop_char_t)sym_startup, 0); - if (!mth) + if (!mth) { MOO_LOG0 (moo, MOO_LOG_DEBUG, "Cannot find the startup method in the system class"); goto oops; @@ -2114,7 +2114,7 @@ TODO: overcome this problem - accept parameters.... /* [NOTE] * the receiver field and the sender field of ctx are nils. - * especially, the fact that the sender field is nil is used by + * especially, the fact that the sender field is nil is used by * the main execution loop for breaking out of the loop */ MOO_ASSERT (moo, moo->active_context == MOO_NULL); @@ -2131,7 +2131,7 @@ TODO: overcome this problem - accept parameters.... * let's forcefully set active_context to ctx directly. */ moo->active_context = ctx; - proc = start_initial_process(moo, ctx); + proc = start_initial_process(moo, ctx); moo_popvolats (moo, tmp_count); tmp_count = 0; if (MOO_UNLIKELY(!proc)) goto oops; @@ -2194,7 +2194,7 @@ static void log_char_object (moo_t* moo, moo_bitmask_t mask, moo_oop_char_t msg) start_over: while (rem > 0) { - if (*ptr == '\0') + if (*ptr == '\0') { n = moo_logbfmt (moo, mask, "%jc", *ptr); MOO_ASSERT (moo, n == 1); @@ -2205,9 +2205,9 @@ start_over: n = moo_logbfmt (moo, mask, "%.*js", rem, ptr); if (n <= -1) break; - if (n == 0) + if (n == 0) { - /* to skip the unprinted character. + /* to skip the unprinted character. * actually, this check is not needed because of '\0' skipped * at the beginning of the loop */ n = moo_logbfmt (moo, mask, "%jc", *ptr); @@ -2315,7 +2315,7 @@ static moo_pfrc_t pf_hash (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) } } - /* moo_hashxxx() functions should limit the return value to fall + /* moo_hashxxx() functions should limit the return value to fall * in the range between 0 and MOO_SMOOI_MAX inclusive */ MOO_ASSERT (moo, hv >= 0 && hv <= MOO_SMOOI_MAX); @@ -2404,7 +2404,7 @@ static moo_pfrc_t pf_context_find_exception_handler (moo_t* moo, moo_mod_t* mod, preamble = MOO_OOP_TO_SMOOI(((moo_oop_method_t)rcv->method_or_nargs)->preamble); if (MOO_METHOD_GET_PREAMBLE_CODE(preamble) == MOO_METHOD_PREAMBLE_EXCEPTION) { - /* context + /* context * on: ... do: ...*/ moo_oow_t size, i; @@ -2413,9 +2413,9 @@ static moo_pfrc_t pf_context_find_exception_handler (moo_t* moo, moo_mod_t* mod, { /* [NOTE] the following loop scans all parameters to the on:do: method. * if the on:do: method contains local temporary variables, - * you must change this function to skip scanning local variables. + * you must change this function to skip scanning local variables. * the current on:do: method has 1 local variable declared. - * as local variables are placed after method arguments and + * as local variables are placed after method arguments and * the loop increments 'i' by 2, the last element is naturally * get excluded from inspection. */ @@ -2514,7 +2514,7 @@ static moo_pfrc_t pf_method_get_ip_source_line (moo_t* moo, moo_mod_t* mod, moo_ ipv = MOO_OOP_TO_SMOOI(ip); code_loc_ptr = (moo_oow_t*)((moo_uint8_t*)(di + 1) + di->code_loc_start); - if (ipv < di->code_loc_len && code_loc_ptr[ipv] <= MOO_SMOOI_MAX) + if (ipv < di->code_loc_len && code_loc_ptr[ipv] <= MOO_SMOOI_MAX) { retv = moo_oowtoint(moo, code_loc_ptr[ipv]); if (MOO_UNLIKELY(!retv)) return MOO_PF_FAILURE; @@ -2589,7 +2589,7 @@ static moo_pfrc_t __block_value (moo_t* moo, moo_oop_block_t rcv_block, moo_ooi_ /* | sum | * sum := [ :n | (n < 2) ifTrue: [1] ifFalse: [ n + (sum value: (n - 1))] ]. * (sum value: 10). - * + * * For the code above, sum is a block context and it is sent value: inside * itself. Let me simply clone a block context to allow reentrancy like this * while the block context is active @@ -2628,7 +2628,7 @@ static moo_pfrc_t __block_value (moo_t* moo, moo_oop_block_t rcv_block, moo_ooi_ /* create a new block context based on the receiver block(rcv_block) */ moo_pushvolat (moo, (moo_oop_t*)&rcv_block); - blkctx = (moo_oop_context_t)moo_instantiate(moo, moo->_block_context, MOO_NULL, local_ntmprs); + blkctx = (moo_oop_context_t)moo_instantiate(moo, moo->_block_context, MOO_NULL, local_ntmprs); moo_popvolat (moo); if (MOO_UNLIKELY(!blkctx)) return MOO_PF_FAILURE; @@ -2648,7 +2648,7 @@ static moo_pfrc_t __block_value (moo_t* moo, moo_oop_block_t rcv_block, moo_ooi_ MOO_ASSERT (moo, nargs == 1); xarg = (moo_oop_oop_t)MOO_STACK_GETTOP(moo); MOO_ASSERT (moo, MOO_OBJ_IS_OOP_POINTER(xarg)); - MOO_ASSERT (moo, MOO_OBJ_GET_SIZE(xarg) == num_first_arg_elems); + MOO_ASSERT (moo, MOO_OBJ_GET_SIZE(xarg) == num_first_arg_elems); for (i = 0; i < num_first_arg_elems; i++) { MOO_STORE_OOP (moo, &blkctx->stack[i], MOO_OBJ_GET_OOP_VAL(xarg, i)); @@ -2713,7 +2713,7 @@ static MOO_INLINE moo_pfrc_t __block_new_process (moo_t* moo, moo_mod_t* mod, mo xarg = MOO_STACK_GETARG(moo, nargs, 0); if (!MOO_OBJ_IS_OOP_POINTER(xarg)) { - /* the only optional argument must be an OOP-indexable + /* the only optional argument must be an OOP-indexable * object like an array */ moo_seterrnum (moo, MOO_EINVAL); return MOO_PF_FAILURE; @@ -2744,7 +2744,7 @@ static MOO_INLINE moo_pfrc_t __block_new_process (moo_t* moo, moo_mod_t* mod, mo proc = make_process(moo, blkctx, proc_flags); if (MOO_UNLIKELY(!proc)) return MOO_PF_FAILURE; /* hard failure */ /* TOOD: can't this be treated as a soft failure? throw an exception instead?? */ - /* __block_value() has popped all arguments and the receiver. + /* __block_value() has popped all arguments and the receiver. * PUSH the return value instead of changing the stack top */ MOO_STACK_PUSH (moo, (moo_oop_t)proc); return MOO_PF_SUCCESS; @@ -2868,11 +2868,11 @@ static moo_pfrc_t pf_semaphore_signal (moo_t* moo, moo_mod_t* mod, moo_ooi_t nar moo_ntime_t now, ft; sem = (moo_oop_semaphore_t)MOO_STACK_GETRCV(moo, nargs); - MOO_PF_CHECK_RCV (moo, moo_iskindof(moo, (moo_oop_t)sem, moo->_semaphore)); + MOO_PF_CHECK_RCV (moo, moo_iskindof(moo, (moo_oop_t)sem, moo->_semaphore)); if (nargs <= 0) { - /* signal_semaphore() may change the active process though the + /* signal_semaphore() may change the active process though the * implementation as of this writing makes runnable the process waiting * on the signal to be processed. it is safer to set the return value * before calling signal_sempahore() */ @@ -2938,11 +2938,11 @@ static moo_pfrc_t pf_semaphore_signal (moo_t* moo, moo_mod_t* mod, moo_ooi_t nar * that can fit into a SmallInteger, even after some additions. */ vm_gettime (moo, &now); MOO_ADD_NTIME_SNS (&ft, &now, MOO_OOP_TO_SMOOI(sec), MOO_OOP_TO_SMOOI(nsec)); - if (ft.sec < 0 || ft.sec > MOO_SMOOI_MAX) + if (ft.sec < 0 || ft.sec > MOO_SMOOI_MAX) { /* soft error - cannot represent the expiry time in a small integer. */ - MOO_LOG3 (moo, MOO_LOG_PRIMITIVE | MOO_LOG_ERROR, - "Error(%hs) - time (%ld) out of range(0 - %zd) when adding a timed semaphore\n", + MOO_LOG3 (moo, MOO_LOG_PRIMITIVE | MOO_LOG_ERROR, + "Error(%hs) - time (%ld) out of range(0 - %zd) when adding a timed semaphore\n", __PRIMITIVE_NAME__, (unsigned long int)ft.sec, (moo_ooi_t)MOO_SMOOI_MAX); moo_seterrnum (moo, MOO_ERANGE); @@ -2964,7 +2964,7 @@ static moo_pfrc_t pf_semaphore_signal_on_gcfin (moo_t* moo, moo_mod_t* mod, moo_ moo_oop_semaphore_t sem; sem = (moo_oop_semaphore_t)MOO_STACK_GETRCV(moo, nargs); - MOO_PF_CHECK_RCV (moo, moo_iskindof(moo, (moo_oop_t)sem, moo->_semaphore)); + MOO_PF_CHECK_RCV (moo, moo_iskindof(moo, (moo_oop_t)sem, moo->_semaphore)); /* TODO: should i prevent overwriting? */ moo->sem_gcfin = sem; @@ -2979,7 +2979,7 @@ static moo_pfrc_t __semaphore_signal_on_io (moo_t* moo, moo_ooi_t nargs, moo_sem moo_oop_t fd; sem = (moo_oop_semaphore_t)MOO_STACK_GETRCV(moo, nargs); - MOO_PF_CHECK_RCV (moo, moo_iskindof(moo, (moo_oop_t)sem, moo->_semaphore)); + MOO_PF_CHECK_RCV (moo, moo_iskindof(moo, (moo_oop_t)sem, moo->_semaphore)); fd = MOO_STACK_GETARG(moo, nargs, 0); @@ -3010,7 +3010,7 @@ static moo_pfrc_t __semaphore_signal_on_io (moo_t* moo, moo_ooi_t nargs, moo_sem return MOO_PF_FAILURE; } - if (add_sem_to_sem_io_tuple(moo, sem, MOO_OOP_TO_SMOOI(fd), io_type) <= -1) + if (add_sem_to_sem_io_tuple(moo, sem, MOO_OOP_TO_SMOOI(fd), io_type) <= -1) { const moo_ooch_t* oldmsg = moo_backuperrmsg(moo); moo_seterrbfmt (moo, moo->errnum, "unable to add the handle %zd to the multiplexer for %hs - %js", MOO_OOP_TO_SMOOI(fd), io_type_str[io_type], oldmsg); @@ -3036,14 +3036,14 @@ static moo_pfrc_t pf_semaphore_wait (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs moo_oop_t rcv; rcv = MOO_STACK_GETRCV(moo, nargs); - MOO_PF_CHECK_RCV (moo, moo_iskindof(moo, rcv, moo->_semaphore)); + MOO_PF_CHECK_RCV (moo, moo_iskindof(moo, rcv, moo->_semaphore)); if (!can_await_semaphore(moo, (moo_oop_semaphore_t)rcv)) { moo_seterrbfmt (moo, MOO_EPERM, "not allowed to wait on a semaphore that belongs to a semaphore group"); return MOO_PF_FAILURE; } - + /* i must set the return value before calling await_semaphore(). * await_semaphore() may switch the active process and the stack * manipulation macros target at the active process. i'm not supposed @@ -3061,7 +3061,7 @@ static moo_pfrc_t pf_semaphore_unsignal (moo_t* moo, moo_mod_t* mod, moo_ooi_t n moo_oop_semaphore_t sem; sem = (moo_oop_semaphore_t)MOO_STACK_GETRCV(moo, nargs); - MOO_PF_CHECK_RCV (moo, moo_iskindof(moo, (moo_oop_t)sem, moo->_semaphore)); + MOO_PF_CHECK_RCV (moo, moo_iskindof(moo, (moo_oop_t)sem, moo->_semaphore)); if (sem == moo->sem_gcfin) { @@ -3102,7 +3102,7 @@ static moo_pfrc_t pf_semaphore_unsignal (moo_t* moo, moo_mod_t* mod, moo_ooi_t n for (wp = sem->waiting.first; (moo_oop_t)wp != moo->_nil; wp = wp->sem_wait.next) { MOO_ASSERT (moo, moo->sem_io_wait_count > 0); - moo->sem_io_wait_count--; + moo->sem_io_wait_count--; } } MOO_ASSERT (moo, sem->subtype == moo->_nil); @@ -3119,7 +3119,7 @@ static moo_pfrc_t pf_semaphore_group_add_semaphore (moo_t* moo, moo_mod_t* mod, moo_oop_semaphore_t sem; sg = (moo_oop_semaphore_group_t)MOO_STACK_GETRCV(moo, nargs); - MOO_PF_CHECK_RCV (moo, moo_iskindof(moo, (moo_oop_t)sg, moo->_semaphore_group)); + MOO_PF_CHECK_RCV (moo, moo_iskindof(moo, (moo_oop_t)sg, moo->_semaphore_group)); sem = (moo_oop_semaphore_t)MOO_STACK_GETARG(moo, nargs, 0); MOO_PF_CHECK_ARGS (moo, nargs, moo_iskindof(moo, (moo_oop_t)sem, moo->_semaphore)); @@ -3142,7 +3142,7 @@ static moo_pfrc_t pf_semaphore_group_add_semaphore (moo_t* moo, moo_mod_t* mod, if (sem->subtype == MOO_SMOOI_TO_OOP(MOO_SEMAPHORE_SUBTYPE_IO)) { /* the semaphore being added is associated with I/O operation. */ - MOO_ASSERT (moo, MOO_OOP_IS_SMOOI(sem->u.io.index) && + MOO_ASSERT (moo, MOO_OOP_IS_SMOOI(sem->u.io.index) && MOO_OOP_TO_SMOOI(sem->u.io.index) >= 0 && MOO_OOP_TO_SMOOI(sem->u.io.index) < moo->sem_io_tuple_count); @@ -3155,7 +3155,7 @@ static moo_pfrc_t pf_semaphore_group_add_semaphore (moo_t* moo, moo_mod_t* mod, { /* the first IO semaphore is being added to the semaphore group. * but there are already processes waiting on the semaphore group. - * + * * for instance, * [Process 1] * sg := SemaphoreGroup new. @@ -3188,7 +3188,7 @@ static moo_pfrc_t pf_semaphore_group_add_semaphore (moo_t* moo, moo_mod_t* mod, moo_seterrbfmt (moo, MOO_EPERM, "not allowed to relocate a semaphore to a different group"); return MOO_PF_FAILURE; } - + return MOO_PF_SUCCESS; } @@ -3199,7 +3199,7 @@ static moo_pfrc_t pf_semaphore_group_remove_semaphore (moo_t* moo, moo_mod_t* mo moo_ooi_t count; rcv = (moo_oop_semaphore_group_t)MOO_STACK_GETRCV(moo, nargs); - MOO_PF_CHECK_RCV (moo, moo_iskindof(moo, (moo_oop_t)rcv, moo->_semaphore_group)); + MOO_PF_CHECK_RCV (moo, moo_iskindof(moo, (moo_oop_t)rcv, moo->_semaphore_group)); sem = (moo_oop_semaphore_t)MOO_STACK_GETARG(moo, nargs, 0); MOO_PF_CHECK_ARGS (moo, nargs, moo_iskindof(moo, (moo_oop_t)sem, moo->_semaphore)); @@ -3214,14 +3214,14 @@ static moo_pfrc_t pf_semaphore_group_remove_semaphore (moo_t* moo, moo_mod_t* mo /* there is a process waiting on this semaphore group. * i don't allow a semaphore to be removed from the group. * i want to dodge potential problems arising when removal is allowed. - * + * * for instance, consider this psuedo code. * sg addSemaphore: s * [ sg wait ] fork. * [ sg wait ] fork. * [ sg wait ] fork. * sg removeSemaphore: s. - * + * */ moo_seterrbfmt (moo, MOO_EPERM, "not allowed to remove a semaphore from a group being waited on"); return MOO_PF_FAILURE; @@ -3233,7 +3233,7 @@ static moo_pfrc_t pf_semaphore_group_remove_semaphore (moo_t* moo, moo_mod_t* mo sem->grm.prev = (moo_oop_semaphore_t)moo->_nil; sem->grm.next = (moo_oop_semaphore_t)moo->_nil; sem->group = (moo_oop_semaphore_group_t)moo->_nil; - + count = MOO_OOP_TO_SMOOI(rcv->sem_count); MOO_ASSERT (moo, count > 0); count--; @@ -3277,14 +3277,14 @@ static moo_pfrc_t pf_semaphore_group_wait (moo_t* moo, moo_mod_t* mod, moo_ooi_t moo_oop_t rcv, sem; rcv = MOO_STACK_GETRCV(moo, nargs); - MOO_PF_CHECK_RCV (moo, moo_iskindof(moo, rcv, moo->_semaphore_group)); + MOO_PF_CHECK_RCV (moo, moo_iskindof(moo, rcv, moo->_semaphore_group)); /* i must set the return value before calling await_semaphore_group(). * MOO_STACK_SETRETTORCV() manipulates the stack of the currently active * process(moo->processor->active). moo->processor->active may become - * moo->nil_process if the current active process must get suspended. + * moo->nil_process if the current active process must get suspended. * it is safer to set the return value of the calling method here. - * but the arguments and the receiver information will be lost from + * but the arguments and the receiver information will be lost from * the stack from this moment on. */ MOO_STACK_SETRETTORCV (moo, nargs); @@ -3323,7 +3323,7 @@ static moo_pfrc_t pf_system_return_value_to_context (moo_t* moo, moo_mod_t* mod, * test complex chains of method contexts and block contexts */ if (MOO_CLASSOF(moo, ctx) == moo->_method_context) { - /* when returning to a method context, load the sp register with + /* when returning to a method context, load the sp register with * the value stored in the context */ moo->sp = MOO_OOP_TO_SMOOI(((moo_oop_context_t)ctx)->sp); } @@ -3955,7 +3955,7 @@ static moo_pfrc_t pf_character_eq (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) rcv = MOO_STACK_GETRCV(moo, nargs); arg = MOO_STACK_GETARG(moo, nargs, 0); - + MOO_PF_CHECK_RCV (moo, MOO_OOP_IS_CHAR(rcv)); /*res = (MOO_OOP_IS_CHAR(arg) && MOO_OOP_TO_CHAR(rcv) == MOO_OOP_TO_CHAR(arg))? moo->_true: moo->_false;*/ @@ -3989,12 +3989,12 @@ static moo_pfrc_t pf_character_lt (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) rcv = MOO_STACK_GETRCV(moo, nargs); arg = MOO_STACK_GETARG(moo, nargs, 0); - + MOO_PF_CHECK_RCV (moo, MOO_OOP_IS_CHAR(rcv)); MOO_PF_CHECK_ARGS (moo, nargs, MOO_OOP_IS_CHAR(arg)); res = (MOO_OOP_TO_CHAR(rcv) < MOO_OOP_TO_CHAR(arg))? moo->_true: moo->_false; - + MOO_STACK_SETRET (moo, nargs, res); return MOO_PF_SUCCESS; } @@ -4028,7 +4028,7 @@ static moo_pfrc_t pf_character_le (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) MOO_PF_CHECK_RCV (moo, MOO_OOP_IS_CHAR(rcv)); MOO_PF_CHECK_ARGS (moo, nargs, MOO_OOP_IS_CHAR(arg)); - + res = (MOO_OOP_TO_CHAR(rcv) <= MOO_OOP_TO_CHAR(arg))? moo->_true: moo->_false; MOO_STACK_SETRET (moo, nargs, res); @@ -4043,7 +4043,7 @@ static moo_pfrc_t pf_character_ge (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) rcv = MOO_STACK_GETRCV(moo, nargs); arg = MOO_STACK_GETARG(moo, nargs, 0); - + MOO_PF_CHECK_RCV (moo, MOO_OOP_IS_CHAR(rcv)); MOO_PF_CHECK_ARGS (moo, nargs, MOO_OOP_IS_CHAR(arg)); @@ -4165,7 +4165,7 @@ static moo_pfrc_t pf_error_as_string (moo_t* moo, moo_mod_t* mod, moo_ooi_t narg ec = MOO_OOP_TO_ERROR(rcv); MOO_ASSERT (moo, MOO_IN_SMOOI_RANGE(ec)); -/* TODO: error string will be mostly the same.. do i really have to call makestring every time? +/* TODO: error string will be mostly the same.. do i really have to call makestring every time? * cache the error string object created? */ s = moo_errnum_to_errstr(ec); ss = moo_makestring (moo, s, moo_count_oocstr(s)); @@ -4259,14 +4259,14 @@ static moo_pfrc_t pf_system_log (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) /* TODO: enhance this primitive */ level = MOO_STACK_GETARG(moo, nargs, 0); - if (!MOO_OOP_IS_SMOOI(level)) mask = MOO_LOG_APP | MOO_LOG_INFO; + if (!MOO_OOP_IS_SMOOI(level)) mask = MOO_LOG_APP | MOO_LOG_INFO; else mask = MOO_LOG_APP | MOO_OOP_TO_SMOOI(level); for (k = 1; k < nargs; k++) { msg = MOO_STACK_GETARG(moo, nargs, k); - if (msg == moo->_nil || msg == moo->_true || msg == moo->_false) + if (msg == moo->_nil || msg == moo->_true || msg == moo->_false) { goto dump_object; } @@ -4518,10 +4518,10 @@ moo_pfbase_t* moo_getpfnum (moo_t* moo, const moo_ooch_t* ptr, moo_oow_t len, mo { mid = base + (lim >> 1); /* moo_comp_oochars_bcstr() is not aware of multibyte encoding. - * so the names above should be composed of the single byte + * so the names above should be composed of the single byte * characters only */ n = moo_comp_oochars_bcstr(ptr, len, pftab[mid].name); - if (n == 0) + if (n == 0) { MOO_ASSERT (moo, MOO_OOI_IN_METHOD_PREAMBLE_INDEX_RANGE(mid)); /* this must never be so big */ *pfnum = mid; @@ -4542,7 +4542,7 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs) #if defined(MOO_DEBUG_VM_EXEC) /* set it to a fake value */ - moo->last_inst_pointer = 0; + moo->last_inst_pointer = 0; #endif preamble = MOO_OOP_TO_SMOOI(method->preamble); @@ -4562,7 +4562,7 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs) { /* TODO: better to throw a moo exception so that the caller can catch it??? */ arg_count_mismatch: - MOO_LOG3 (moo, MOO_LOG_IC | MOO_LOG_FATAL, + MOO_LOG3 (moo, MOO_LOG_IC | MOO_LOG_FATAL, "Fatal error - Argument count mismatch for a non-variadic method [%O] - %zd expected, %zu given\n", method->name, MOO_OOP_TO_SMOOI(method->tmpr_nargs), nargs); moo_seterrnum (moo, MOO_EINVAL); @@ -4579,7 +4579,7 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs) break; /* [NOTE] this is useless becuase it returns a caller's context - * as the callee's context has not been created yet. + * as the callee's context has not been created yet. case MOO_METHOD_PREAMBLE_RETURN_CONTEXT: LOG_INST0 (moo, "preamble_return_context"); MOO_STACK_POPS (moo, nargs); @@ -4623,7 +4623,7 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs) MOO_STACK_SETTOP (moo, moo->_false); break; - case MOO_METHOD_PREAMBLE_RETURN_INDEX: + case MOO_METHOD_PREAMBLE_RETURN_INDEX: /* preamble_index field is used to store a positive integer */ LOG_INST1 (moo, "preamble_return_index %zd", MOO_METHOD_GET_PREAMBLE_INDEX(preamble)); MOO_STACK_POPS (moo, nargs); @@ -4654,13 +4654,13 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs) if (rcv == (moo_oop_oop_t)moo->active_context) { /* the active context object doesn't keep - * the most up-to-date information in the + * the most up-to-date information in the * 'ip' and 'sp' field. commit these fields - * when the object to be accessed is + * when the object to be accessed is * the active context. this manual commit * is required because this premable handling * skips activation of a new method context - * that would commit these fields. + * that would commit these fields. */ STORE_ACTIVE_IP (moo); STORE_ACTIVE_SP (moo); @@ -4697,7 +4697,7 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs) moo_pushvolat (moo, (moo_oop_t*)&method); n = pftab[pfnum].pfbase.handler(moo, MOO_NULL, nargs); /* builtin numbered primitive. the second parameter is MOO_NULL */ moo_popvolat (moo); - if (n <= MOO_PF_HARD_FAILURE) + if (n <= MOO_PF_HARD_FAILURE) { MOO_LOG3 (moo, MOO_LOG_DEBUG, "Hard failure indicated by primitive function %p - %hs - return code %d\n", @@ -4742,11 +4742,11 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs) MOO_ASSERT (moo, MOO_CLASSOF(moo,pfname) == moo->_symbol); /* merge two SmallIntegers to get a full pointer from the cached data */ - /*w = (moo_oow_t)MOO_OOP_TO_SMOOI(method->preamble_data[0]) << (MOO_OOW_BITS / 2) | + /*w = (moo_oow_t)MOO_OOP_TO_SMOOI(method->preamble_data[0]) << (MOO_OOW_BITS / 2) | (moo_oow_t)MOO_OOP_TO_SMOOI(method->preamble_data[1]); pfbase = (moo_pfbase_t*)w;*/ pfbase = MOO_OOP_TO_SMPTR(method->preamble_data[1]); - if (pfbase) + if (pfbase) { mod = MOO_OOP_TO_SMPTR(method->preamble_data[0]); goto exec_handler; /* skip moo_querymodpf() */ @@ -4790,9 +4790,9 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs) n = pfbase->handler(moo, mod, nargs); moo_popvolat (moo); - if (n <= MOO_PF_HARD_FAILURE) + if (n <= MOO_PF_HARD_FAILURE) { - MOO_LOG4 (moo, MOO_LOG_DEBUG, + MOO_LOG4 (moo, MOO_LOG_DEBUG, "Hard failure indicated by primitive function %p - %.*js - return code %d\n", pfbase->handler, MOO_OBJ_GET_SIZE(pfname), MOO_OBJ_GET_CHAR_SLOT(pfname), n); return -1; /* hard primitive failure */ @@ -4807,7 +4807,7 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs) else { /* no handler found */ - MOO_LOG2 (moo, MOO_LOG_DEBUG, + MOO_LOG2 (moo, MOO_LOG_DEBUG, "Soft failure for non-existent primitive function - %.*js\n", MOO_OBJ_GET_SIZE(pfname), MOO_OBJ_GET_CHAR_SLOT(pfname)); } @@ -4858,7 +4858,7 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs) } MOO_LOG3 (moo, MOO_LOG_DEBUG, "Sending primitiveFailed - %O>>%.*js\n", method->owner, MOO_OBJ_GET_SIZE(method->name), MOO_OBJ_GET_CHAR_SLOT(method->name)); - /* + /* * | arg1 | <---- stack_base + 3 * | arg0 | <---- stack_base + 2 * | receiver | <---- stack_base + 1 @@ -4910,15 +4910,15 @@ static int send_message (moo_t* moo, moo_oop_char_t selector, moo_ooi_t nargs, i #endif method = moo_findmethod_noseterr(moo, receiver, selector, to_super); - if (!method) + if (!method) { method = moo_findmethod_noseterr(moo, receiver, moo->does_not_understand_sym, 0); if (!method) { /* this must not happen as long as doesNotUnderstand: is implemented under Apex. * this check should indicate a very serious internal problem */ - MOO_LOG4 (moo, MOO_LOG_IC | MOO_LOG_FATAL, - "Fatal error - unable to find a fallback method [%O>>%.*js] for receiver [%O]\n", + MOO_LOG4 (moo, MOO_LOG_IC | MOO_LOG_FATAL, + "Fatal error - unable to find a fallback method [%O>>%.*js] for receiver [%O]\n", MOO_CLASSOF(moo, receiver), MOO_OBJ_GET_SIZE(moo->does_not_understand_sym), MOO_OBJ_GET_CHAR_SLOT(moo->does_not_understand_sym), receiver); moo_seterrbfmt (moo, MOO_EMSGSND, "unable to find a fallback method - %O>>%.*js", @@ -4927,7 +4927,7 @@ static int send_message (moo_t* moo, moo_oop_char_t selector, moo_ooi_t nargs, i } else { - /* manipulate the stack as if 'receier doesNotUnderstand: selector' + /* manipulate the stack as if 'receier doesNotUnderstand: selector' * has been called. */ /* TODO: if i manipulate the stack this way here, the stack trace for the last call is kind of lost. * how can i preserve it gracefully? */ @@ -4975,15 +4975,15 @@ static MOO_INLINE int switch_process_if_needed (moo_t* moo) * wake_process() below. */ delete_from_sem_heap (moo, 0); /* moo->sem_heap_count is decremented in delete_from_sem_heap() */ - /* if no process is waiting on the semaphore, + /* if no process is waiting on the semaphore, * signal_semaphore() returns moo->_nil. */ if (moo->processor->active == moo->nil_process && (moo_oop_t)proc != moo->_nil) { - /* this is the only runnable process. + /* this is the only runnable process. * switch the process to the running state. * it uses wake_process() instead of - * switch_to_process() as there is no running + * switch_to_process() as there is no running * process at this moment */ #if defined(MOO_DEBUG_VM_PROCESSOR) && (MOO_DEBUG_VM_PROCESSOR >= 2) @@ -5010,11 +5010,11 @@ static MOO_INLINE int switch_process_if_needed (moo_t* moo) /* no running process but io semaphore being waited on */ vm_muxwait (moo, &ft); - /* exit early if a process has been woken up. + /* exit early if a process has been woken up. * the break in the else part further down will get hit * eventually even if the following line doesn't exist. * having the following line causes to skip firing the - * timed semaphore that would expire between now and the + * timed semaphore that would expire between now and the * moment the next inspection occurs. */ if (moo->processor->active != moo->nil_process) goto switch_to_next; } @@ -5034,7 +5034,7 @@ static MOO_INLINE int switch_process_if_needed (moo_t* moo) } vm_gettime (moo, &now); } - else + else { /* there is a running process. go on */ break; @@ -5043,7 +5043,7 @@ static MOO_INLINE int switch_process_if_needed (moo_t* moo) while (moo->sem_heap_count > 0 && !moo->abort_req); } - if (moo->sem_io_wait_count > 0) + if (moo->sem_io_wait_count > 0) { if (moo->processor->active == moo->nil_process) { @@ -5057,7 +5057,7 @@ static MOO_INLINE int switch_process_if_needed (moo_t* moo) if (moo->processor->suspended.count == MOO_SMOOI_TO_OOP(0)) { /* no suspended process. the program is buggy or is probably being - * terminated forcibly. + * terminated forcibly. * the default signal handler may lead to this situation. */ moo->abort_req = 1; } @@ -5079,13 +5079,13 @@ static MOO_INLINE int switch_process_if_needed (moo_t* moo) /* [NOTE] the check with the multiplexer may happen too frequently * because this is called everytime process switching is requested. - * the actual callback implementation should try to avoid invoking + * the actual callback implementation should try to avoid invoking * actual system calls too frequently for less overhead. */ vm_muxwait (moo, MOO_NULL); } } - if ((moo_oop_t)moo->sem_gcfin != moo->_nil) + if ((moo_oop_t)moo->sem_gcfin != moo->_nil) { moo_oop_process_t proc; @@ -5106,8 +5106,8 @@ static MOO_INLINE int switch_process_if_needed (moo_t* moo) } else { - /* the gcfin semaphore signalling is not requested and there are - * no runnable processes nor no waiting semaphores. if there is + /* the gcfin semaphore signalling is not requested and there are + * no runnable processes nor no waiting semaphores. if there is * process waiting on the gcfin semaphore, i will just schedule * it to run by calling signal_semaphore() on moo->sem_gcfin. */ @@ -5117,14 +5117,14 @@ static MOO_INLINE int switch_process_if_needed (moo_t* moo) /* there is no active process. in most cases, the only process left * should be the gc finalizer process started in the System>>startup. * if there are other suspended processes at this point, the processes - * are not likely to run again. - * - * imagine the following single line program that creates a process + * are not likely to run again. + * + * imagine the following single line program that creates a process * but never start it. * * method(#class) main { | p | p := [] newProcess. } * - * the gc finalizer process and the process assigned to p exist. + * the gc finalizer process and the process assigned to p exist. * when the code reaches here, the 'p' process still is alive * despite no active process nor no process waiting on timers * and semaphores. so when the entire program terminates, there @@ -5132,14 +5132,14 @@ static MOO_INLINE int switch_process_if_needed (moo_t* moo) * to schedule. */ - MOO_LOG4 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, + MOO_LOG4 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "Signaled GCFIN semaphore without gcfin signal request - total %zd runnable/running %zd suspended %zd - sem_io_wait_count %zu\n", MOO_OOP_TO_SMOOI(moo->processor->total_count), MOO_OOP_TO_SMOOI(moo->processor->runnable.count), MOO_OOP_TO_SMOOI(moo->processor->suspended.count), moo->sem_io_wait_count); proc = signal_semaphore(moo, moo->sem_gcfin); - if ((moo_oop_t)proc != moo->_nil) + if ((moo_oop_t)proc != moo->_nil) { MOO_ASSERT (moo, proc->state == MOO_SMOOI_TO_OOP(PROC_STATE_RUNNABLE)); MOO_ASSERT (moo, proc == moo->processor->runnable.first); @@ -5167,7 +5167,7 @@ static MOO_INLINE int switch_process_if_needed (moo_t* moo) }*/ #endif - if (moo->processor->active == moo->nil_process) + if (moo->processor->active == moo->nil_process) { /* no more waiting semaphore and no more process */ MOO_ASSERT (moo, moo->processor->runnable.count = MOO_SMOOI_TO_OOP(0)); @@ -5176,7 +5176,7 @@ static MOO_INLINE int switch_process_if_needed (moo_t* moo) { /* there exist suspended processes while no processes are runnable. * most likely, the running program contains process/semaphore related bugs */ - MOO_LOG1 (moo, MOO_LOG_IC | MOO_LOG_WARN, + MOO_LOG1 (moo, MOO_LOG_IC | MOO_LOG_WARN, "%zd suspended process(es) found - check your program\n", MOO_OOP_TO_SMOOI(moo->processor->suspended.count)); } @@ -5190,7 +5190,7 @@ switch_to_next: if (moo->switch_proc) { #endif - if (!moo->proc_switched) + if (!moo->proc_switched) { switch_to_next_runnable_process (moo); moo->proc_switched = 0; @@ -5212,7 +5212,7 @@ static MOO_INLINE int do_return (moo_t* moo, moo_oob_t bcode, moo_oop_t return_v * instruction (RETURN_RECEIVER or RETURN_RECEIVER) * if a context returns into this context again, * it'll be able to return as well again. - * + * * Consider a program like this: * * #class MyObject(Object) @@ -5224,19 +5224,19 @@ static MOO_INLINE int do_return (moo_t* moo, moo_oob_t bcode, moo_oop_t return_v * t1 dump. * t2 := [ g1 := 50. g2 := 100. ^g1 + g2 ]. * (t1 < 100) ifFalse: [ ^self ]. - * t1 := t1 + 1. + * t1 := t1 + 1. * ^self xxxx. * } * #method(#class) main * { * t1 := 1. * self xxxx. - * t2 := t2 value. + * t2 := t2 value. * t2 dump. * } * } * - * the 'xxxx' method invoked by 'self xxxx' has + * the 'xxxx' method invoked by 'self xxxx' has * returned even before 't2 value' is executed. * the '^' operator makes the active context to * switch to its 'origin->sender' which is the @@ -5244,16 +5244,16 @@ static MOO_INLINE int do_return (moo_t* moo, moo_oob_t bcode, moo_oop_t return_v * instruction pointer at the 'return' instruction * helps execute another return when the switching * occurs. - * + * * TODO: verify if this really works * */ - moo->ip--; + moo->ip--; #else if (MOO_UNLIKELY(moo->active_context->origin == moo->processor->active->initial_context->origin)) { /* method return from a processified block - * + * * #method(#class) main * { * [^100] newProcess resume. @@ -5262,11 +5262,11 @@ static MOO_INLINE int do_return (moo_t* moo, moo_oob_t bcode, moo_oop_t return_v * '1111' dump. * ^300. * } - * + * * ^100 doesn't terminate a main process as the block * has been processified. on the other hand, ^100 * in the following program causes main to exit. - * + * * #method(#class) main * { * [^100] value. @@ -5286,7 +5286,7 @@ static MOO_INLINE int do_return (moo_t* moo, moo_oob_t bcode, moo_oop_t return_v terminate_process (moo, moo->processor->active); } - else + else { int unwind_protect; moo_oop_context_t unwind_start; @@ -5351,7 +5351,7 @@ static MOO_INLINE int do_return (moo_t* moo, moo_oob_t bcode, moo_oop_t return_v } } - /* the origin must always be a method context for both an active block context + /* the origin must always be a method context for both an active block context * or an active method context */ MOO_ASSERT (moo, MOO_CLASSOF(moo, moo->active_context->origin) == moo->_method_context); @@ -5397,7 +5397,7 @@ static MOO_INLINE int do_return (moo_t* moo, moo_oob_t bcode, moo_oop_t return_v * processified block check has been done against the context before switching */ /* the stack contains the final return value so the stack pointer must be 0. */ - MOO_ASSERT (moo, moo->sp == 0); + MOO_ASSERT (moo, moo->sp == 0); if (moo->option.trait & MOO_TRAIT_AWAIT_PROCS) { @@ -5427,7 +5427,7 @@ static MOO_INLINE void do_return_from_block (moo_t* moo) if (moo->active_context == moo->processor->active->initial_context) { /* the active context to return from is an initial context of - * the active process. this process must have been created + * the active process. this process must have been created * over a block using the newProcess method. let's terminate * the process. */ @@ -5436,10 +5436,10 @@ static MOO_INLINE void do_return_from_block (moo_t* moo) } else { - /* it is a normal block return as the active block context + /* it is a normal block return as the active block context * is not the initial context of a process */ - /* the process stack is shared. the return value + /* the process stack is shared. the return value * doesn't need to get moved. */ SWITCH_ACTIVE_CONTEXT (moo, (moo_oop_context_t)moo->active_context->sender); } @@ -5463,13 +5463,13 @@ static MOO_INLINE int make_block (moo_t* moo) /* the block context object created here is used as a base * object for block context activation. pf_block_value() * clones a block context and activates the cloned context. - * this base block context is created with no stack for + * this base block context is created with no stack for * this reason */ - block = (moo_oop_block_t)moo_instantiate(moo, moo->_block, MOO_NULL, 0); + block = (moo_oop_block_t)moo_instantiate(moo, moo->_block, MOO_NULL, 0); if (MOO_UNLIKELY(!block)) return -1; - /* the long forward jump instruction has the format of - * 11000100 KKKKKKKK or 11000100 KKKKKKKK KKKKKKKK + /* the long forward jump instruction has the format of + * 11000100 KKKKKKKK or 11000100 KKKKKKKK KKKKKKKK * depending on MOO_BCODE_LONG_PARAM_SIZE. change 'ip' to point to * the instruction after the jump. */ block->ip = MOO_SMOOI_TO_OOP(moo->ip + MOO_BCODE_LONG_PARAM_SIZE + 1); @@ -5480,7 +5480,7 @@ static MOO_INLINE int make_block (moo_t* moo) block->ntmprs = MOO_SMOOI_TO_OOP(b2); /* set the home context where it's defined */ - MOO_STORE_OOP (moo, (moo_oop_t*)&block->home, (moo_oop_t)moo->active_context); + MOO_STORE_OOP (moo, (moo_oop_t*)&block->home, (moo_oop_t)moo->active_context); /* push the new block context to the stack of the active context */ MOO_STACK_PUSH (moo, (moo_oop_t)block); @@ -5494,13 +5494,13 @@ static int __execute (moo_t* moo) moo_oop_t return_value; #if defined(HAVE_LABELS_AS_VALUES) - static void* inst_table[256] = + static void* inst_table[256] = { /* import bytecode label addresses */ #include "bct-lab.h" }; -# define BEGIN_DISPATCH_LOOP() __begin_inst_dispatch: +# define BEGIN_DISPATCH_LOOP() __begin_inst_dispatch: # define END_DISPATCH_LOOP() __end_inst_dispatch: # define EXIT_DISPATCH_LOOP() goto __end_inst_dispatch # define NEXT_INST() goto __begin_inst_dispatch @@ -5512,7 +5512,7 @@ static int __execute (moo_t* moo) # define ON_UNKNOWN_INST() case_ ## DEFAULT: #else -# define BEGIN_DISPATCH_LOOP() __begin_inst_dispatch: +# define BEGIN_DISPATCH_LOOP() __begin_inst_dispatch: # define END_DISPATCH_LOOP() __end_inst_dispatch: # define EXIT_DISPATCH_LOOP() goto __end_inst_dispatch # define NEXT_INST() goto __begin_inst_dispatch @@ -5527,7 +5527,7 @@ static int __execute (moo_t* moo) MOO_ASSERT (moo, moo->active_context != MOO_NULL); -/* TODO: initialize semaphore stuffs +/* TODO: initialize semaphore stuffs * sem_heap * sem_io. * sem_list. @@ -5649,8 +5649,8 @@ static int __execute (moo_t* moo) handle_tempvar: #if defined(MOO_USE_CTXTEMPVAR) - /* when CTXTEMPVAR inststructions are used, the above - * instructions are used only for temporary access + /* when CTXTEMPVAR inststructions are used, the above + * instructions are used only for temporary access * outside a block. i can assume that the temporary * variable index is pointing to one of temporaries * in the relevant method context */ @@ -5658,7 +5658,7 @@ static int __execute (moo_t* moo) bx = b1; MOO_ASSERT (moo, MOO_CLASSOF(moo, ctx) == moo->_method_context); #else - /* otherwise, the index may point to a temporaries declared inside a block */ + /* otherwise, the index may point to a temporaries declared inside a block */ if (moo->active_context->home != moo->_nil) { @@ -5673,7 +5673,7 @@ static int __execute (moo_t* moo) do { - /* ntmprs contains the number of defined temporaries + /* ntmprs contains the number of defined temporaries * including those defined in the home context */ home_ntmprs = MOO_OOP_TO_SMOOI(((moo_oop_context_t)home)->ntmprs); if (b1 >= home_ntmprs) break; @@ -5688,7 +5688,7 @@ static int __execute (moo_t* moo) } while (1); - /* bx is the actual index within the actual context + /* bx is the actual index within the actual context * containing the temporary */ bx = b1 - home_ntmprs; } @@ -6050,7 +6050,7 @@ static int __execute (moo_t* moo) /* -------------------------------------------------------- */ ON_INST(BCODE_SEND_MESSAGE_X) ON_INST(BCODE_SEND_MESSAGE_TO_SUPER_X) - /* b1 -> number of arguments + /* b1 -> number of arguments * b2 -> selector index stored in the literal frame */ FETCH_PARAM_CODE_TO (moo, b1); FETCH_PARAM_CODE_TO (moo, b2); @@ -6169,10 +6169,10 @@ static int __execute (moo_t* moo) FETCH_PARAM_CODE_TO (moo, b1); LOG_INST1 (moo, "make_dictionary %zu", b1); - /* Dictionary new: b1 + /* Dictionary new: b1 * doing this allows users to redefine Dictionary whatever way they like. * if i did the followings instead, the internal of Dictionary would get - * tied to the system dictionary implementation. the system dictionary + * tied to the system dictionary implementation. the system dictionary * implementation is flawed in that it accepts only a variable character * object as a key. it's better to invoke 'Dictionary new: ...'. t = (moo_oop_t)moo_makedic (moo, moo->_dictionary, b1 + 10); @@ -6269,7 +6269,7 @@ static int __execute (moo_t* moo) default: /* well, allowing these into a byte array may look a bit awkward. - * mostly i take the low 1 byte of the first unit of the first element + * mostly i take the low 1 byte of the first unit of the first element * and store it at the given position. * note that a byte array literal composed by the compiler itself * treat these differently. */ @@ -6428,7 +6428,7 @@ int moo_invoke (moo_t* moo, const moo_oocs_t* objname, const moo_oocs_t* mthname MOO_ASSERT (moo, moo->initial_context == MOO_NULL); MOO_ASSERT (moo, moo->active_context == MOO_NULL); MOO_ASSERT (moo, moo->active_method == MOO_NULL); - + #if defined(MOO_PROFILE_VM) moo->stat.inst_counter = 0; @@ -6439,7 +6439,7 @@ int moo_invoke (moo_t* moo, const moo_oocs_t* objname, const moo_oocs_t* mthname moo_clearmethodcache (moo); -#if 0 +#if 0 /* unless the system is buggy, moo->proc_map_used should be 0. * the standard library terminates all processes before halting. * @@ -6449,7 +6449,7 @@ int moo_invoke (moo_t* moo, const moo_oocs_t* objname, const moo_oocs_t* mthname if (moo->proc_map_capa > 0 && moo->proc_map_used == 0) { /* rechain the process map. it must be compatible with prepare_to_alloc_pid(). - * by placing the low indiced slot at the beginning of the free list, + * by placing the low indiced slot at the beginning of the free list, * the special processes (main_proc, gcfin_proc, ossig_proc) are allocated * with low process IDs. */ moo_ooi_t i, j; @@ -6498,9 +6498,9 @@ int moo_invoke (moo_t* moo, const moo_oocs_t* objname, const moo_oocs_t* mthname int moo_invoke (moo_t* moo, const moo_oocs_t* objname, const moo_oocs_t* mthname) { /* TODO: .... */ - /* call + /* call * System initializeClasses - * and invoke + * and invoke * objname mthname */ } diff --git a/lib/fmt-imp.h b/lib/fmt-imp.h index d2d5385..d2b2ba1 100644 --- a/lib/fmt-imp.h +++ b/lib/fmt-imp.h @@ -25,7 +25,7 @@ */ static int fmt_uintmax ( - char_t* buf, int size, + char_t* buf, int size, moo_uintmax_t value, int base_and_flags, int prec, char_t fillchar, char_t signchar, const char_t* prefix) { @@ -41,10 +41,10 @@ static int fmt_uintmax ( "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ": "0123456789abcdefghijklmnopqrstuvwxyz"; - if ((base_and_flags & MOO_FMT_INTMAX_NOZERO) && value == 0) + if ((base_and_flags & MOO_FMT_INTMAX_NOZERO) && value == 0) { - p = tmp; - if (base_and_flags & MOO_FMT_INTMAX_ZEROLEAD) + p = tmp; + if (base_and_flags & MOO_FMT_INTMAX_ZEROLEAD) { /* NOZERO emits no digit, ZEROLEAD emits 1 digit. * so it emits '0' */ @@ -63,7 +63,7 @@ static int fmt_uintmax ( moo_uintmax_t v = value; /* store the resulting numeric string into 'tmp' first */ - p = tmp; + p = tmp; do { *p++ = xbasestr[v % base]; @@ -73,11 +73,11 @@ static int fmt_uintmax ( /* reslen is the length of the resulting string without padding. */ reslen = (int)(p - tmp); - + /* precision specified the minum number of digits to produce. - * so if the precision is larger that the digits produced, + * so if the precision is larger that the digits produced, * reslen should be adjusted to precision */ - if (prec > reslen) + if (prec > reslen) { /* if the precision is greater than the actual digits * made from the value, 0 is inserted in front. @@ -86,12 +86,12 @@ static int fmt_uintmax ( preczero = prec - reslen; reslen = prec; } - else + else { preczero = 0; - if ((base_and_flags & MOO_FMT_INTMAX_ZEROLEAD) && value != 0) + if ((base_and_flags & MOO_FMT_INTMAX_ZEROLEAD) && value != 0) { - /* if value is zero, 0 is emitted from it. + /* if value is zero, 0 is emitted from it. * so ZEROLEAD don't need to add another 0. */ preczero++; reslen++; @@ -137,10 +137,10 @@ static int fmt_uintmax ( if (prefix) while (*prefix && bp < be) *bp++ = *prefix++; /* add 0s for precision */ - while (preczero > 0 && bp < be) - { + while (preczero > 0 && bp < be) + { *bp++ = '0'; - preczero--; + preczero--; } /* copy the numeric string to the destination buffer */ @@ -169,10 +169,10 @@ static int fmt_uintmax ( if (prefix) while (*prefix && bp < be) *bp++ = *prefix++; /* add 0s for precision */ - while (preczero > 0 && bp < be) - { + while (preczero > 0 && bp < be) + { *bp++ = '0'; - preczero--; + preczero--; } /* copy the numeric string to the destination buffer */ @@ -194,10 +194,10 @@ static int fmt_uintmax ( if (prefix) while (*prefix && bp < be) *bp++ = *prefix++; /* add 0s for precision */ - while (preczero > 0 && bp < be) - { + while (preczero > 0 && bp < be) + { *bp++ = '0'; - preczero--; + preczero--; } /* copy the numeric string to the destination buffer */ @@ -213,10 +213,10 @@ static int fmt_uintmax ( if (prefix) while (*prefix && bp < be) *bp++ = *prefix++; /* add 0s for precision */ - while (preczero > 0 && bp < be) - { + while (preczero > 0 && bp < be) + { *bp++ = '0'; - preczero--; + preczero--; } /* copy the numeric string to the destination buffer */ diff --git a/lib/fmt.c b/lib/fmt.c index 861175b..69c7698 100644 --- a/lib/fmt.c +++ b/lib/fmt.c @@ -25,7 +25,7 @@ */ /* - * This file contains a formatted output routine derived from kvprintf() + * This file contains a formatted output routine derived from kvprintf() * of FreeBSD. It has been heavily modified and bug-fixed. */ @@ -71,7 +71,7 @@ #include /* for snrintf(). used for floating-point number formatting */ #if defined(_MSC_VER) || defined(__BORLANDC__) || (defined(__WATCOMC__) && (__WATCOMC__ < 1200)) -# define snprintf _snprintf +# define snprintf _snprintf # if !defined(HAVE_SNPRINTF) # define HAVE_SNPRINTF # endif @@ -82,7 +82,7 @@ #endif /* MOO_ENABLE_FLTFMT */ -/* Max number conversion buffer length: +/* Max number conversion buffer length: * moo_intmax_t in base 2, plus NUL byte. */ #define MAXNBUF (MOO_SIZEOF(moo_intmax_t) * MOO_BITS_PER_BYTE + 1) @@ -107,7 +107,7 @@ static struct { moo_uint8_t flag; /* for single occurrence */ moo_uint8_t dflag; /* for double occurrence */ -} lm_tab[26] = +} lm_tab[26] = { { 0, 0 }, /* a */ { 0, 0 }, /* b */ @@ -138,7 +138,7 @@ static struct }; -enum +enum { FLAGC_DOT = (1 << 0), FLAGC_SPACE = (1 << 1), @@ -153,14 +153,14 @@ enum FLAGC_LENMOD = (1 << 10) /* length modifier */ }; -static const moo_bch_t hex2ascii_lower[] = +static const moo_bch_t hex2ascii_lower[] = { '0','1','2','3','4','5','6','7','8','9', 'a','b','c','d','e','f','g','h','i','j','k','l','m', 'n','o','p','q','r','s','t','u','v','w','x','y','z' }; -static const moo_bch_t hex2ascii_upper[] = +static const moo_bch_t hex2ascii_upper[] = { '0','1','2','3','4','5','6','7','8','9', 'A','B','C','D','E','F','G','H','I','J','K','L','M', @@ -187,7 +187,7 @@ static moo_bch_t bch_nullstr[] = { '(','n','u','l','l', ')','\0' }; #include "fmt-imp.h" int moo_fmt_intmax_to_bcstr ( - moo_bch_t* buf, int size, + moo_bch_t* buf, int size, moo_intmax_t value, int base_and_flags, int prec, moo_bch_t fillchar, const moo_bch_t* prefix) { @@ -219,7 +219,7 @@ int moo_fmt_intmax_to_bcstr ( } int moo_fmt_uintmax_to_bcstr ( - moo_bch_t* buf, int size, + moo_bch_t* buf, int size, moo_uintmax_t value, int base_and_flags, int prec, moo_bch_t fillchar, const moo_bch_t* prefix) { @@ -245,7 +245,7 @@ int moo_fmt_uintmax_to_bcstr ( /* ==================== wide-char ===================================== */ int moo_fmt_intmax_to_ucstr ( - moo_uch_t* buf, int size, + moo_uch_t* buf, int size, moo_intmax_t value, int base_and_flags, int prec, moo_uch_t fillchar, const moo_uch_t* prefix) { @@ -277,7 +277,7 @@ int moo_fmt_intmax_to_ucstr ( } int moo_fmt_uintmax_to_ucstr ( - moo_uch_t* buf, int size, + moo_uch_t* buf, int size, moo_uintmax_t value, int base_and_flags, int prec, moo_uch_t fillchar, const moo_uch_t* prefix) { @@ -441,10 +441,10 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap) fmtptr = (const moo_uint8_t*)fmtout->fmt_str; switch (fmtout->fmt_type) { - case MOO_FMTOUT_FMT_TYPE_BCH: + case MOO_FMTOUT_FMT_TYPE_BCH: fmtchsz = MOO_SIZEOF_BCH_T; break; - case MOO_FMTOUT_FMT_TYPE_UCH: + case MOO_FMTOUT_FMT_TYPE_UCH: fmtchsz = MOO_SIZEOF_UCH_T; break; } @@ -477,9 +477,9 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap) { const moo_bch_t* start, * end; start = end = (const moo_bch_t*)fmtptr; - while ((bch = *end++) != '%' || stop) + while ((bch = *end++) != '%' || stop) { - if (bch == '\0') + if (bch == '\0') { PUT_BCS (fmtout, start, end - start - 1); goto done; @@ -495,9 +495,9 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap) { const moo_uch_t* start, * end; start = end = (const moo_uch_t*)fmtptr; - while ((uch = *end++) != '%' || stop) + while ((uch = *end++) != '%' || stop) { - if (uch == '\0') + if (uch == '\0') { PUT_UCS (fmtout, start, end - start - 1); goto done; @@ -510,15 +510,15 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap) goto handle_percent; handle_percent: - padc = ' '; + padc = ' '; width = 0; precision = 0; neg = 0; sign = 0; - lm_flag = 0; lm_dflag = 0; flagc = 0; + lm_flag = 0; lm_dflag = 0; flagc = 0; sprintn = sprintn_lower; reswitch: switch (fmtout->fmt_type) { - case MOO_FMTOUT_FMT_TYPE_BCH: + case MOO_FMTOUT_FMT_TYPE_BCH: uch = *(const moo_bch_t*)fmtptr; break; case MOO_FMTOUT_FMT_TYPE_UCH: @@ -527,7 +527,7 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap) } fmtptr += fmtchsz; - switch (uch) + switch (uch) { case '%': /* %% */ bch = uch; @@ -539,7 +539,7 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap) flagc |= FLAGC_DOT; goto reswitch; - case '#': + case '#': if (flagc & (FLAGC_WIDTH | FLAGC_DOT | FLAGC_LENMOD)) goto invalid_format; flagc |= FLAGC_SHARP; goto reswitch; @@ -572,30 +572,30 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap) goto reswitch; case '*': /* take the length from the parameter */ - if (flagc & FLAGC_DOT) + if (flagc & FLAGC_DOT) { if (flagc & (FLAGC_STAR2 | FLAGC_PRECISION)) goto invalid_format; flagc |= FLAGC_STAR2; precision = va_arg(ap, moo_ooi_t); /* this deviates from the standard printf that accepts 'int' */ - if (precision < 0) + if (precision < 0) { - /* if precision is less than 0, + /* if precision is less than 0, * treat it as if no .precision is specified */ flagc &= ~FLAGC_DOT; precision = 0; } - } - else + } + else { if (flagc & (FLAGC_STAR1 | FLAGC_WIDTH)) goto invalid_format; flagc |= FLAGC_STAR1; width = va_arg(ap, moo_ooi_t); /* it deviates from the standard printf that accepts 'int' */ - if (width < 0) + if (width < 0) { /* - if (flagc & FLAGC_LEFTADJ) + if (flagc & FLAGC_LEFTADJ) flagc &= ~FLAGC_LEFTADJ; else */ @@ -619,12 +619,12 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap) case '5': case '6': case '7': case '8': case '9': { if (flagc & FLAGC_LENMOD) goto invalid_format; - for (n = 0;; fmtptr += fmtchsz) + for (n = 0;; fmtptr += fmtchsz) { n = n * 10 + uch - '0'; switch (fmtout->fmt_type) { - case MOO_FMTOUT_FMT_TYPE_BCH: + case MOO_FMTOUT_FMT_TYPE_BCH: uch = *(const moo_bch_t*)fmtptr; break; case MOO_FMTOUT_FMT_TYPE_UCH: @@ -633,13 +633,13 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap) } if (uch < '0' || uch > '9') break; } - if (flagc & FLAGC_DOT) + if (flagc & FLAGC_DOT) { if (flagc & FLAGC_STAR2) goto invalid_format; precision = n; flagc |= FLAGC_PRECISION; } - else + else { if (flagc & FLAGC_STAR1) goto invalid_format; width = n; @@ -678,7 +678,7 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap) goto invalid_format; } } - else + else { lm_flag |= lm_tab[uch - 'a'].flag; goto reswitch; @@ -686,10 +686,10 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap) break; case 'L': /* long double */ - if (flagc & FLAGC_LENMOD) + if (flagc & FLAGC_LENMOD) { /* conflict with other length modifier */ - goto invalid_format; + goto invalid_format; } flagc |= FLAGC_LENMOD; lm_flag |= LF_LD; @@ -699,7 +699,7 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap) if (flagc & FLAGC_LENMOD) { /* conflict with other length modifier */ - goto invalid_format; + goto invalid_format; } flagc |= FLAGC_LENMOD; lm_flag |= LF_QD; @@ -721,12 +721,12 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap) *(va_arg(ap, short int*)) = fmtout->count; else if (lm_flag & LF_C) /* hh */ *(va_arg(ap, char*)) = fmtout->count; - else if (flagc & FLAGC_LENMOD) + else if (flagc & FLAGC_LENMOD) goto invalid_format; else *(va_arg(ap, int*)) = fmtout->count; break; - + /* signed integer conversions */ case 'd': case 'i': /* signed conversion */ @@ -736,7 +736,7 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap) /* end of signed integer conversions */ /* unsigned integer conversions */ - case 'o': + case 'o': base = 8; goto handle_nosign; case 'u': @@ -764,7 +764,7 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap) case 'c': { /* zeropad must not take effect for 'c' */ - if (flagc & FLAGC_ZEROPAD) padc = ' '; + if (flagc & FLAGC_ZEROPAD) padc = ' '; if (lm_flag & LF_L) goto uppercase_c; #if defined(MOO_OOCH_IS_UCH) if (lm_flag & LF_J) goto uppercase_c; @@ -872,12 +872,12 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap) const moo_uint8_t* bsp; moo_oow_t k_hex_width; - /* zeropad must not take effect for 'k' and 'K' - * + /* zeropad must not take effect for 'k' and 'K' + * * 'h' & 'l' is not used to differentiate moo_bch_t and moo_uch_t - * because 'k' means moo_byte_t. - * 'l', results in uppercase hexadecimal letters. - * 'h' drops the leading \x in the output + * because 'k' means moo_byte_t. + * 'l', results in uppercase hexadecimal letters. + * 'h' drops the leading \x in the output * -------------------------------------------------------- * hk -> \x + non-printable in lowercase hex * k -> all in lowercase hex @@ -922,9 +922,9 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap) if (!(flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (fmtout, padc, width); - while (n--) + while (n--) { - if ((lm_flag & LF_H) && BYTE_PRINTABLE(*bsp)) + if ((lm_flag & LF_H) && BYTE_PRINTABLE(*bsp)) { PUT_BCH (fmtout, *bsp, 1); } @@ -946,7 +946,7 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap) case 'W': { /* unicode string in unicode escape sequence. - * + * * hw -> \uXXXX, \UXXXXXXXX, printable-byte(only in ascii range) * w -> \uXXXX, \UXXXXXXXX * lw -> all in \UXXXXXXXX @@ -960,7 +960,7 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap) if (flagc & FLAGC_DOT) { /* if precision is specifed, it doesn't stop at the value of zero unlike 's' or 'S' */ - for (n = 0; n < precision; n++) + for (n = 0; n < precision; n++) { if ((lm_flag & LF_H) && BYTE_PRINTABLE(usp[n])) uwid = 1; else if (!(lm_flag & LF_L) && usp[n] <= 0xFFFF) uwid = 6; @@ -981,13 +981,13 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap) if (!(flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (fmtout, padc, width); - while (n--) + while (n--) { - if ((lm_flag & LF_H) && BYTE_PRINTABLE(*usp)) + if ((lm_flag & LF_H) && BYTE_PRINTABLE(*usp)) { PUT_OOCH(fmtout, *usp, 1); } - else if (!(lm_flag & LF_L) && *usp <= 0xFFFF) + else if (!(lm_flag & LF_L) && *usp <= 0xFFFF) { moo_uint16_t u16 = *usp; int extra_flags = ((uch) == 'w'? MOO_BYTE_TO_BCSTR_LOWERCASE: 0); @@ -1062,7 +1062,7 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap) { /* moo_flt_t is limited to double or long double */ - /* precedence goes to double if sizeof(double) == sizeof(long double) + /* precedence goes to double if sizeof(double) == sizeof(long double) * for example, %Lf didn't work on some old platforms. * so i prefer the format specifier with no modifier. */ @@ -1126,18 +1126,18 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap) if (flagc & FLAGC_ZEROPAD) fb.fmt.ptr[fmtlen++] = '0'; if (flagc & FLAGC_STAR1) fb.fmt.ptr[fmtlen++] = '*'; - else if (flagc & FLAGC_WIDTH) + else if (flagc & FLAGC_WIDTH) { fmtlen += moo_fmt_uintmax_to_bcstr( - &fb.fmt.ptr[fmtlen], fb.fmt.capa - fmtlen, + &fb.fmt.ptr[fmtlen], fb.fmt.capa - fmtlen, width, 10, -1, '\0', MOO_NULL); } if (flagc & FLAGC_DOT) fb.fmt.ptr[fmtlen++] = '.'; if (flagc & FLAGC_STAR2) fb.fmt.ptr[fmtlen++] = '*'; - else if (flagc & FLAGC_PRECISION) + else if (flagc & FLAGC_PRECISION) { fmtlen += moo_fmt_uintmax_to_bcstr( - &fb.fmt.ptr[fmtlen], fb.fmt.capa - fmtlen, + &fb.fmt.ptr[fmtlen], fb.fmt.capa - fmtlen, precision, 10, -1, '\0', MOO_NULL); } @@ -1154,7 +1154,7 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap) #if defined(HAVE_SNPRINTF) /* nothing special here */ #else - /* best effort to avoid buffer overflow when no snprintf is available. + /* best effort to avoid buffer overflow when no snprintf is available. * i really can't do much if it happens. */ newcapa = precision + width + 32; if (fb.out.capa < newcapa) @@ -1305,14 +1305,14 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap) num = va_arg(ap, int); number: - if (sign && (moo_intmax_t)num < 0) + if (sign && (moo_intmax_t)num < 0) { neg = 1; num = -(moo_intmax_t)num; } nbufp = sprintn(nbuf, num, base, &tmp); - if ((flagc & FLAGC_SHARP) && num != 0) + if ((flagc & FLAGC_SHARP) && num != 0) { if (base == 2 || base == 8) tmp += 2; else if (base == 16) tmp += 3; @@ -1322,7 +1322,7 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap) else if (flagc & FLAGC_SPACE) tmp++; numlen = (int)((const moo_bch_t*)nbufp - (const moo_bch_t*)nbuf); - if ((flagc & FLAGC_DOT) && precision > numlen) + if ((flagc & FLAGC_DOT) && precision > numlen) { /* extra zeros for precision specified */ tmp += (precision - numlen); @@ -1338,19 +1338,19 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap) else if (flagc & FLAGC_SIGN) PUT_OOCH (fmtout, '+', 1); else if (flagc & FLAGC_SPACE) PUT_OOCH (fmtout, ' ', 1); - if ((flagc & FLAGC_SHARP) && num != 0) + if ((flagc & FLAGC_SHARP) && num != 0) { - if (base == 2) + if (base == 2) { PUT_OOCH (fmtout, '2', 1); PUT_OOCH (fmtout, 'r', 1); } - if (base == 8) + if (base == 8) { PUT_OOCH (fmtout, '8', 1); PUT_OOCH (fmtout, 'r', 1); - } - else if (base == 16) + } + else if (base == 16) { PUT_OOCH (fmtout, '1', 1); PUT_OOCH (fmtout, '6', 1); @@ -1507,7 +1507,7 @@ int moo_ufmt_out (moo_fmtout_t* fmtout, const moo_uch_t* fmt, ...) return n; } -/* -------------------------------------------------------------------------- +/* -------------------------------------------------------------------------- * OBJECT OUTPUT * -------------------------------------------------------------------------- */ @@ -1574,7 +1574,7 @@ int moo_fmt_object_ (moo_fmtout_t* fmtout, moo_oop_t oop) for (i = 0; i < MOO_OBJ_GET_SIZE(oop); i++) { ch = MOO_OBJ_GET_CHAR_VAL(oop, i); - if ((ch >= '\0' && ch < ' ') || ch == '\\' || ch == '\"') + if ((ch >= '\0' && ch < ' ') || ch == '\\' || ch == '\"') { escape = 1; break; @@ -1589,7 +1589,7 @@ int moo_fmt_object_ (moo_fmtout_t* fmtout, moo_oop_t oop) for (i = 0; i < MOO_OBJ_GET_SIZE(oop); i++) { ch = MOO_OBJ_GET_CHAR_VAL(oop, i); - if (ch >= '\0' && ch < ' ') + if (ch >= '\0' && ch < ' ') { switch (ch) { @@ -1618,7 +1618,7 @@ int moo_fmt_object_ (moo_fmtout_t* fmtout, moo_oop_t oop) escaped = 'a'; break; default: - /* since it's less than ' ' and greater than or equal to '\0' , + /* since it's less than ' ' and greater than or equal to '\0' , * it should not exceed 0xFF regardless of character mode. %02X should be good enough */ if (moo_bfmt_out(fmtout, "\\x%02X", (moo_oochu_t)ch) <= -1) return -1; continue; @@ -1657,7 +1657,7 @@ int moo_fmt_object_ (moo_fmtout_t* fmtout, moo_oop_t oop) } if (moo_bfmt_out(fmtout, "]") <= -1) return -1; } - + else if (MOO_OBJ_GET_FLAGS_TYPE(oop) == MOO_OBJ_TYPE_HALFWORD) { if (moo_bfmt_out(fmtout, "#[[") <= -1) return -1;; /* TODO: fix this symbol/notation */ @@ -1857,7 +1857,7 @@ int moo_fmt_object_ (moo_fmtout_t* fmtout, moo_oop_t oop) } -/* -------------------------------------------------------------------------- +/* -------------------------------------------------------------------------- * FORMATTED LOG OUTPUT * -------------------------------------------------------------------------- */ @@ -1890,7 +1890,7 @@ redo: moo_ooch_t* tmp; max = MOO_TYPE_MAX(moo_oow_t) - moo->log.len; - if (len > max) + if (len > max) { /* data too big. */ rem += len - max; @@ -1910,7 +1910,7 @@ redo: /* +1 to handle line ending injection more easily */ tmp = moo_reallocmem(moo, moo->log.ptr, (newcapa + 1) * MOO_SIZEOF(*tmp)); - if (!tmp) + if (!tmp) { make_do: if (moo->log.len > 0) @@ -2006,17 +2006,17 @@ moo_ooi_t moo_logbfmtv (moo_t* moo, moo_bitmask_t mask, const moo_bch_t* fmt, va int x; moo_fmtout_t fo; - if (moo->log.default_type_mask & MOO_LOG_ALL_TYPES) + if (moo->log.default_type_mask & MOO_LOG_ALL_TYPES) { /* if a type is given, it's not untyped any more. * mask off the UNTYPED bit */ - mask &= ~MOO_LOG_UNTYPED; + mask &= ~MOO_LOG_UNTYPED; /* if the default_type_mask has the UNTYPED bit on, * it'll get turned back on */ mask |= (moo->log.default_type_mask & MOO_LOG_ALL_TYPES); } - else if (!(mask & MOO_LOG_ALL_TYPES)) + else if (!(mask & MOO_LOG_ALL_TYPES)) { /* no type is set in the given mask and no default type is set. * make it UNTYPED. */ @@ -2061,17 +2061,17 @@ moo_ooi_t moo_logufmtv (moo_t* moo, moo_bitmask_t mask, const moo_uch_t* fmt, va int x; moo_fmtout_t fo; - if (moo->log.default_type_mask & MOO_LOG_ALL_TYPES) + if (moo->log.default_type_mask & MOO_LOG_ALL_TYPES) { /* if a type is given, it's not untyped any more. * mask off the UNTYPED bit */ - mask &= ~MOO_LOG_UNTYPED; + mask &= ~MOO_LOG_UNTYPED; /* if the default_type_mask has the UNTYPED bit on, * it'll get turned back on */ mask |= (moo->log.default_type_mask & MOO_LOG_ALL_TYPES); } - else if (!(mask & MOO_LOG_ALL_TYPES)) + else if (!(mask & MOO_LOG_ALL_TYPES)) { /* no type is set in the given mask and no default type is set. * make it UNTYPED. */ @@ -2221,7 +2221,7 @@ static MOO_INLINE int format_stack_args (moo_fmtout_t* fmtout, moo_ooi_t nargs, moo_ooci_t ch; int flagc, lm_flag; - struct + struct { moo_ooi_t idx; int stop; @@ -2246,7 +2246,7 @@ static MOO_INLINE int format_stack_args (moo_fmtout_t* fmtout, moo_ooi_t nargs, if (!MOO_OOP_IS_POINTER(arg) || MOO_OBJ_GET_FLAGS_TYPE(arg) != MOO_OBJ_TYPE_CHAR) { moo_ooi_t i; - /* if the first argument is not a valid formatting string, + /* if the first argument is not a valid formatting string, * print all arguments as objects */ if (fmtout->putobj(fmtout, arg) <= -1) goto oops; for (i = arg_state.idx; i < nargs; i++) @@ -2271,11 +2271,11 @@ static MOO_INLINE int format_stack_args (moo_fmtout_t* fmtout, moo_ooi_t nargs, GET_NEXT_CHAR_TO (moo, fmtptr, fmtend, ch); if (ch == '%' && !arg_state.stop) break; - if (ch == MOO_OOCI_EOF) + if (ch == MOO_OOCI_EOF) { /* fmt is not advanced when it is length-bounded. * so not fmt - checkpoint - 1 */ - PUT_OOCS (fmtout, checkpoint, fmtptr - checkpoint); + PUT_OOCS (fmtout, checkpoint, fmtptr - checkpoint); goto done; } } @@ -2283,16 +2283,16 @@ static MOO_INLINE int format_stack_args (moo_fmtout_t* fmtout, moo_ooi_t nargs, percent = fmtptr - 1; - padc = ' '; + padc = ' '; width = 0; precision = 0; neg = 0; sign = 0; - lm_flag = 0; flagc = 0; + lm_flag = 0; flagc = 0; radix_flags = MOO_INTTOSTR_NONEWOBJ; reswitch: GET_NEXT_CHAR_TO (moo, fmtptr, fmtend, ch); - switch (ch) + switch (ch) { case '%': /* %% */ ooch = ch; @@ -2304,7 +2304,7 @@ static MOO_INLINE int format_stack_args (moo_fmtout_t* fmtout, moo_ooi_t nargs, flagc |= FLAGC_DOT; goto reswitch; - case '#': + case '#': if (flagc & (FLAGC_WIDTH | FLAGC_DOT | FLAGC_LENMOD)) goto invalid_format; flagc |= FLAGC_SHARP; goto reswitch; @@ -2334,33 +2334,33 @@ static MOO_INLINE int format_stack_args (moo_fmtout_t* fmtout, moo_ooi_t nargs, flagc &= ~FLAGC_ZEROPAD; } } - + goto reswitch; case '*': /* take the length from the parameter */ - if (flagc & FLAGC_DOT) + if (flagc & FLAGC_DOT) { if (flagc & (FLAGC_STAR2 | FLAGC_PRECISION)) goto invalid_format; flagc |= FLAGC_STAR2; GET_NEXT_ARG_TO (moo, nargs, &arg_state, arg); if (moo_inttoooi_noseterr(moo, arg, &precision) <= -1) goto invalid_format; - if (precision < 0) + if (precision < 0) { - /* if precision is less than 0, + /* if precision is less than 0, * treat it as if no .precision is specified */ flagc &= ~FLAGC_DOT; precision = 0; } - } - else + } + else { if (flagc & (FLAGC_STAR1 | FLAGC_WIDTH)) goto invalid_format; flagc |= FLAGC_STAR1; GET_NEXT_ARG_TO (moo, nargs, &arg_state, arg); if (moo_inttoooi_noseterr(moo, arg, &width) <= -1) goto invalid_format; - if (width < 0) + if (width < 0) { flagc |= FLAGC_LEFTADJ; width = -width; @@ -2381,19 +2381,19 @@ static MOO_INLINE int format_stack_args (moo_fmtout_t* fmtout, moo_ooi_t nargs, case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (flagc & FLAGC_LENMOD) goto invalid_format; - for (n = 0;; ++fmtptr) + for (n = 0;; ++fmtptr) { n = n * 10 + ch - '0'; ch = *fmtptr; if (ch < '0' || ch > '9') break; } - if (flagc & FLAGC_DOT) + if (flagc & FLAGC_DOT) { if (flagc & FLAGC_STAR2) goto invalid_format; precision = n; flagc |= FLAGC_PRECISION; } - else + else { if (flagc & FLAGC_STAR1) goto invalid_format; width = n; @@ -2408,14 +2408,14 @@ static MOO_INLINE int format_stack_args (moo_fmtout_t* fmtout, moo_ooi_t nargs, flagc |= FLAGC_LENMOD; lm_flag |= lm_tab[ch - 'a'].flag; goto reswitch; - + /* integer conversions */ case 'd': case 'i': /* signed conversion */ radix = 10; sign = 1; goto print_integer; - case 'o': + case 'o': radix = 8; goto print_integer; case 'u': @@ -2438,7 +2438,7 @@ static MOO_INLINE int format_stack_args (moo_fmtout_t* fmtout, moo_ooi_t nargs, moo_oow_t scale = 0; GET_NEXT_ARG_TO (moo, nargs, &arg_state, arg); - if (MOO_OOP_IS_CHAR(arg)) + if (MOO_OOP_IS_CHAR(arg)) { arg = MOO_SMOOI_TO_OOP(MOO_OOP_TO_CHAR(arg)); } @@ -2449,7 +2449,7 @@ static MOO_INLINE int format_stack_args (moo_fmtout_t* fmtout, moo_ooi_t nargs, arg = fa->value; } - if (!moo_inttostr(moo, arg, 10 | MOO_INTTOSTR_NONEWOBJ)) + if (!moo_inttostr(moo, arg, 10 | MOO_INTTOSTR_NONEWOBJ)) { MOO_LOG1 (moo, MOO_LOG_WARN | MOO_LOG_UNTYPED, "unable to convert %O to string \n", arg); goto invalid_format; @@ -2467,13 +2467,13 @@ static MOO_INLINE int format_stack_args (moo_fmtout_t* fmtout, moo_ooi_t nargs, neg = 1; } - if (!(flagc & FLAGC_DOT)) + if (!(flagc & FLAGC_DOT)) { precision = scale; if (precision <= 0) precision = 1; } - if ((flagc & FLAGC_DOT) && precision < scale) + if ((flagc & FLAGC_DOT) && precision < scale) { moo_oow_t diff = scale - precision; scale = precision; @@ -2500,7 +2500,7 @@ static MOO_INLINE int format_stack_args (moo_fmtout_t* fmtout, moo_ooi_t nargs, else if (flagc & FLAGC_SIGN) extra++; else if (flagc & FLAGC_SPACE) extra++; - if ((flagc & FLAGC_DOT) && precision > scale) + if ((flagc & FLAGC_DOT) && precision > scale) { /* trailing zeros in the fractional part */ extra += precision - scale; @@ -2535,13 +2535,13 @@ static MOO_INLINE int format_stack_args (moo_fmtout_t* fmtout, moo_ooi_t nargs, else { if (nslen > 0) PUT_OOCS (fmtout, nsptr, nslen - scale); - if (precision > 0) + if (precision > 0) { PUT_OOCH (fmtout, '.', 1); if (nslen > 0) PUT_OOCS (fmtout, &nsptr[nslen - scale], scale); } } - if (precision > scale) + if (precision > scale) { /* trailing zeros in the fractional part */ PUT_OOCH (fmtout, '0', precision - scale); @@ -2564,7 +2564,7 @@ static MOO_INLINE int format_stack_args (moo_fmtout_t* fmtout, moo_ooi_t nargs, print_char: /* zeropad must not take effect for 'c' */ - if (flagc & FLAGC_ZEROPAD) padc = ' '; + if (flagc & FLAGC_ZEROPAD) padc = ' '; /* precision 0 doesn't kill the letter */ width--; @@ -2657,7 +2657,7 @@ static MOO_INLINE int format_stack_args (moo_fmtout_t* fmtout, moo_ooi_t nargs, case MOO_OBJ_TYPE_BYTE: bsp = MOO_OBJ_GET_BYTE_SLOT(arg); bsl = MOO_OBJ_GET_SIZE(arg); - + format_byte_in_k: k_hex_width = (lm_flag & (LF_H | LF_L))? 4: 2; @@ -2679,9 +2679,9 @@ static MOO_INLINE int format_stack_args (moo_fmtout_t* fmtout, moo_ooi_t nargs, if (!(flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (fmtout, padc, width); - while (n--) + while (n--) { - if ((lm_flag & LF_H) && BYTE_PRINTABLE(*bsp)) + if ((lm_flag & LF_H) && BYTE_PRINTABLE(*bsp)) { PUT_BCH (fmtout, *bsp, 1); } @@ -2715,7 +2715,7 @@ static MOO_INLINE int format_stack_args (moo_fmtout_t* fmtout, moo_ooi_t nargs, case 'W': { /* unicode string in unicode escape sequence. - * + * * hw -> \uXXXX, \UXXXXXXXX, printable-byte(only in ascii range) * w -> \uXXXX, \UXXXXXXXX * lw -> all in \UXXXXXXXX @@ -2737,7 +2737,7 @@ static MOO_INLINE int format_stack_args (moo_fmtout_t* fmtout, moo_ooi_t nargs, } else n = usl; - for (i = 0; i < n; i++) + for (i = 0; i < n; i++) { if ((lm_flag & LF_H) && BYTE_PRINTABLE(usp[n])) uwid = 1; else if (!(lm_flag & LF_L) && usp[n] <= 0xFFFF) uwid = 6; @@ -2747,13 +2747,13 @@ static MOO_INLINE int format_stack_args (moo_fmtout_t* fmtout, moo_ooi_t nargs, if (!(flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (fmtout, padc, width); - while (n--) + while (n--) { - if ((lm_flag & LF_H) && BYTE_PRINTABLE(*usp)) + if ((lm_flag & LF_H) && BYTE_PRINTABLE(*usp)) { PUT_OOCH(fmtout, *usp, 1); } - else if (!(lm_flag & LF_L) && *usp <= 0xFFFF) + else if (!(lm_flag & LF_L) && *usp <= 0xFFFF) { moo_uint16_t u16 = *usp; int extra_flags = ((ch) == 'w'? MOO_BYTE_TO_BCSTR_LOWERCASE: 0); @@ -2790,7 +2790,7 @@ static MOO_INLINE int format_stack_args (moo_fmtout_t* fmtout, moo_ooi_t nargs, moo_oow_t nslen; GET_NEXT_ARG_TO (moo, nargs, &arg_state, arg); - if (MOO_OOP_IS_CHAR(arg)) + if (MOO_OOP_IS_CHAR(arg)) { arg = MOO_SMOOI_TO_OOP(MOO_OOP_TO_CHAR(arg)); } @@ -2813,7 +2813,7 @@ static MOO_INLINE int format_stack_args (moo_fmtout_t* fmtout, moo_ooi_t nargs, arg = nv; } - if (!moo_inttostr(moo, arg, radix | radix_flags)) + if (!moo_inttostr(moo, arg, radix | radix_flags)) { /*moo_seterrbfmt (moo, MOO_EINVAL, "not a valid number - %O", arg); goto oops;*/ @@ -2825,19 +2825,19 @@ static MOO_INLINE int format_stack_args (moo_fmtout_t* fmtout, moo_ooi_t nargs, nslen = moo->inttostr.xbuf.len; MOO_ASSERT (moo, nslen > 0); - if (nsptr[0] == '-') + if (nsptr[0] == '-') { - /* a negative number was given. i must skip the minus sign + /* a negative number was given. i must skip the minus sign * added by moo_inttostr() for a negative number. */ MOO_ASSERT (moo, (MOO_OOP_IS_SMOOI(arg) && MOO_OOP_TO_SMOOI(arg) < 0) || MOO_OOP_IS_NBIGINT(moo,arg)); nsptr++; - nslen--; - } + nslen--; + } extra = nslen; if (sign && ((MOO_OOP_IS_SMOOI(arg) && MOO_OOP_TO_SMOOI(arg) < 0) || MOO_OOP_IS_NBIGINT(moo,arg))) neg = 1; - if ((flagc & FLAGC_SHARP) && arg != MOO_SMOOI_TO_OOP(0)) + if ((flagc & FLAGC_SHARP) && arg != MOO_SMOOI_TO_OOP(0)) { if (radix == 2 || radix == 8 || radix == 16) extra += 2; } @@ -2845,7 +2845,7 @@ static MOO_INLINE int format_stack_args (moo_fmtout_t* fmtout, moo_ooi_t nargs, else if (flagc & FLAGC_SIGN) extra++; else if (flagc & FLAGC_SPACE) extra++; - if ((flagc & FLAGC_DOT) && precision > nslen) + if ((flagc & FLAGC_DOT) && precision > nslen) { /* extra zeros for precision specified */ extra += (precision - nslen); @@ -2861,19 +2861,19 @@ static MOO_INLINE int format_stack_args (moo_fmtout_t* fmtout, moo_ooi_t nargs, else if (flagc & FLAGC_SIGN) PUT_OOCH (fmtout, '+', 1); else if (flagc & FLAGC_SPACE) PUT_OOCH (fmtout, ' ', 1); - if ((flagc & FLAGC_SHARP) && arg != MOO_SMOOI_TO_OOP(0)) + if ((flagc & FLAGC_SHARP) && arg != MOO_SMOOI_TO_OOP(0)) { - if (radix == 2) + if (radix == 2) { PUT_OOCH (fmtout, '2', 1); PUT_OOCH (fmtout, 'r', 1); } - if (radix == 8) + if (radix == 8) { PUT_OOCH (fmtout, '8', 1); PUT_OOCH (fmtout, 'r', 1); - } - else if (radix == 16) + } + else if (radix == 16) { PUT_OOCH (fmtout, '1', 1); PUT_OOCH (fmtout, '6', 1); @@ -2936,7 +2936,7 @@ int moo_strfmtcallstack (moo_t* moo, moo_ooi_t nargs, int rcv_is_fmtstr) fo.putbchars = sprint_bchars; fo.putuchars = sprint_uchars; fo.putobj = moo_fmt_object_; - /* format_stack_args doesn't use fmt_str and fmt_type. + /* format_stack_args doesn't use fmt_str and fmt_type. * it takes the format string from the stack. */ moo->sprintf.xbuf.len = 0; @@ -2967,9 +2967,9 @@ static int fmt_put_bchars_to_uch_buf (moo_fmtout_t* fmtout, const moo_bch_t* ptr ucslen = b->capa - b->len; n = moo_conv_bchars_to_uchars_with_cmgr(ptr, &bcslen, &b->ptr[b->len], &ucslen, b->moo->_cmgr, 1); b->len += ucslen; - if (n <= -1) + if (n <= -1) { - if (n == -2) + if (n == -2) { return 0; /* buffer full. stop */ } diff --git a/lib/gc.c b/lib/gc.c index 54f3c6c..2d34427 100644 --- a/lib/gc.c +++ b/lib/gc.c @@ -40,11 +40,11 @@ * | +-------- NilObject ......: : * | ^........ nil : * Object ...........................: - * ^ - * | + * ^ + * | * * The class hierarchy is roughly as follows: - * + * * Apex * Class * NilObject @@ -69,9 +69,9 @@ * LargeInteger * LargePositiveInteger * LargeNegativeInteger - * + * * Apex has no instance variables. - * + * */ struct kernel_class_info_t @@ -89,7 +89,7 @@ struct kernel_class_info_t }; typedef struct kernel_class_info_t kernel_class_info_t; -static kernel_class_info_t kernel_classes[] = +static kernel_class_info_t kernel_classes[] = { /* -------------------------------------------------------------- * Apex - proto-object with 1 class variable. @@ -160,7 +160,7 @@ static kernel_class_info_t kernel_classes[] = MOO_OFFSETOF(moo_t, _string) }, { 6, - { 'S','y','m','b','o','l' }, + { 'S','y','m','b','o','l' }, MOO_CLASS_SELFSPEC_FLAG_FINAL | MOO_CLASS_SELFSPEC_FLAG_LIMITED, 0, 0, @@ -212,7 +212,7 @@ static kernel_class_info_t kernel_classes[] = 0, MOO_OBJ_TYPE_OOP, MOO_OFFSETOF(moo_t, _association) }, - + { 9, { 'N','a','m','e','s','p','a','c','e' }, MOO_CLASS_SELFSPEC_FLAG_LIMITED, @@ -427,7 +427,7 @@ static kernel_class_info_t kernel_classes[] = static moo_oow_t move_finalizable_objects (moo_t* moo); -/* ----------------------------------------------------------------------- +/* ----------------------------------------------------------------------- * BOOTSTRAPPER * ----------------------------------------------------------------------- */ @@ -446,7 +446,7 @@ static moo_oop_class_t alloc_kernel_class (moo_t* moo, int class_flags, moo_oow_ if (MOO_CLASS_SPEC_IS_UNCOPYABLE(cspec)) MOO_OBJ_SET_FLAGS_UNCOPYABLE (c, 1); /* class itself is uncopyable */ MOO_OBJ_SET_CLASS (c, (moo_oop_t)moo->_class); - c->spec = MOO_SMOOI_TO_OOP(spec); + c->spec = MOO_SMOOI_TO_OOP(spec); c->selfspec = MOO_SMOOI_TO_OOP(MOO_CLASS_SELFSPEC_MAKE(num_classvars, 0, class_flags)); return c; @@ -466,12 +466,12 @@ static int ignite_1 (moo_t* moo) MOO_ASSERT (moo, moo->_class == MOO_NULL); /* -------------------------------------------------------------- * Class - * The instance of Class can have indexed instance variables + * The instance of Class can have indexed instance variables * which are actually class variables. * -------------------------------------------------------------- */ moo->_class = alloc_kernel_class( - moo, kernel_classes[KCI_CLASS].class_flags, - kernel_classes[KCI_CLASS].class_num_classvars, + moo, kernel_classes[KCI_CLASS].class_flags, + kernel_classes[KCI_CLASS].class_num_classvars, MOO_CLASS_SPEC_MAKE(kernel_classes[KCI_CLASS].class_spec_named_instvars, kernel_classes[KCI_CLASS].class_spec_flags, kernel_classes[KCI_CLASS].class_spec_indexed_type)); @@ -488,7 +488,7 @@ static int ignite_1 (moo_t* moo) tmp = alloc_kernel_class( moo, kernel_classes[i].class_flags, - kernel_classes[i].class_num_classvars, + kernel_classes[i].class_num_classvars, MOO_CLASS_SPEC_MAKE(kernel_classes[i].class_spec_named_instvars, kernel_classes[i].class_spec_flags, kernel_classes[i].class_spec_indexed_type)); @@ -499,7 +499,7 @@ static int ignite_1 (moo_t* moo) MOO_OBJ_SET_CLASS (moo->_nil, (moo_oop_t)moo->_undefined_object); /* an instance of a method class stores byte codes in the trailer space. - * unlike other classes with trailer size set, the size of the trailer + * unlike other classes with trailer size set, the size of the trailer * space is not really determined by the traailer size set in the class. * the compiler determines the actual size of the trailer space depending * on the byte codes generated. i should set the following fields to avoid @@ -520,18 +520,18 @@ static int ignite_2 (moo_t* moo) moo->_false = moo_instantiate(moo, moo->_false_class, MOO_NULL, 0); if (MOO_UNLIKELY(!moo->_true) || MOO_UNLIKELY(!moo->_false)) return -1; - /* Prevent the object instations in the permspace. + /* Prevent the object instations in the permspace. * * 1. The symbol table is big and it may resize after ignition. * the resizing operation will migrate the obejct out of the * permspace. The space taken by the symbol table and the * system dictionary is wasted. I'd rather allocate these - * in the normal space. - * + * in the normal space. + * * 2. For compact_symbol_table() to work properly, moo_gc() must not * scan the symbol table before it executes compact_symbol_table(). - * since moo_gc() scans the entire perspace, it naturally gets to - * moo->symtab, which causes problems in compact_symbol_table(). + * since moo_gc() scans the entire perspace, it naturally gets to + * moo->symtab, which causes problems in compact_symbol_table(). * I may reserve a special space for only the symbol table * to overcome this issue. * @@ -546,8 +546,8 @@ static int ignite_2 (moo_t* moo) moo->symtab->tally = MOO_SMOOI_TO_OOP(0); /* It's important to assign the result of moo_instantiate() to a temporary - * variable first and then assign it to moo->symtab->bucket. - * The pointer 'moo->symtab; can change in moo_instantiate() and the + * variable first and then assign it to moo->symtab->bucket. + * The pointer 'moo->symtab; can change in moo_instantiate() and the * target address of assignment may get set before moo_instantiate() * is called. */ tmp = moo_instantiate(moo, moo->_array, MOO_NULL, moo->option.dfl_symtab_size); @@ -592,7 +592,7 @@ static int ignite_3 (moo_t* moo) static moo_ooch_t str_does_not_understand[] = { 'd', 'o', 'e', 's', 'N', 'o', 't', 'U', 'n', 'd', 'e', 'r', 's', 't', 'a', 'n', 'd', ':' }; static moo_ooch_t str_primitive_failed[] = { 'p', 'r', 'i', 'm', 'i', 't', 'i', 'v', 'e', 'F', 'a', 'i', 'l', 'e', 'd' }; static moo_ooch_t str_unwindto_return[] = { 'u', 'n', 'w', 'i', 'n', 'd', 'T', 'o', ':', 'r', 'e', 't', 'u', 'r', 'n', ':' }; - + moo_oow_t i; moo_oop_t sym; moo_oop_class_t cls; @@ -632,11 +632,11 @@ static int ignite_3 (moo_t* moo) sym = moo_makesymbol(moo, str_does_not_understand, MOO_COUNTOF(str_does_not_understand)); if (!sym) return -1; moo->does_not_understand_sym = (moo_oop_char_t)sym; - + sym = moo_makesymbol(moo, str_primitive_failed, MOO_COUNTOF(str_primitive_failed)); if (!sym) return -1; moo->primitive_failed_sym = (moo_oop_char_t)sym; - + sym = moo_makesymbol(moo, str_unwindto_return, MOO_COUNTOF(str_unwindto_return)); if (!sym) return -1; moo->unwindto_return_sym = (moo_oop_char_t)sym; @@ -669,7 +669,7 @@ oops: return -1; } -/* ----------------------------------------------------------------------- +/* ----------------------------------------------------------------------- * GARBAGE COLLECTOR * ----------------------------------------------------------------------- */ @@ -718,7 +718,7 @@ static void compact_symbol_table (moo_t* moo, moo_oop_t _nil) tmp = MOO_OBJ_GET_OOP_VAL(bucket, y); if (tmp == _nil) break; - /* get the natural hash index for the data in the slot + /* get the natural hash index for the data in the slot * at the current hash index */ MOO_ASSERT (moo, MOO_CLASSOF(moo,tmp) == moo->_symbol); z = moo_hash_oochars(MOO_OBJ_GET_CHAR_SLOT(tmp), MOO_OBJ_GET_SIZE(tmp)) % bucket_size; @@ -751,7 +751,7 @@ moo_oow_t moo_getobjpayloadbytes (moo_t* moo, moo_oop_t oop) if (MOO_OBJ_GET_FLAGS_TRAILER(oop)) { - /* only an OOP object can have the trailer. + /* only an OOP object can have the trailer. * * | _flags | * | _size | <-- if it's 3 @@ -777,7 +777,7 @@ moo_oow_t moo_getobjpayloadbytes (moo_t* moo, moo_oop_t oop) } nbytes = MOO_ALIGN(nbytes, MOO_SIZEOF(moo_oop_t)); - if (MOO_OBJ_GET_FLAGS_HASH(oop) == MOO_OBJ_FLAGS_HASH_STORED) + if (MOO_OBJ_GET_FLAGS_HASH(oop) == MOO_OBJ_FLAGS_HASH_STORED) { MOO_STATIC_ASSERT (MOO_SIZEOF(moo_oop_t) == MOO_SIZEOF(moo_oow_t)); nbytes += MOO_SIZEOF(moo_oow_t); @@ -826,8 +826,8 @@ static MOO_INLINE void gc_ms_mark (moo_t* moo, moo_oop_t oop) * determine that it is an instance of process? */ if (MOO_UNLIKELY(MOO_OBJ_GET_FLAGS_PROC(oop))) { - /* the stack in a process object doesn't need to be - * scanned in full. the slots above the stack pointer + /* the stack in a process object doesn't need to be + * scanned in full. the slots above the stack pointer * are garbages. */ size = MOO_PROCESS_NAMED_INSTVARS + MOO_OOP_TO_SMOOI(((moo_oop_process_t)oop)->sp) + 1; MOO_ASSERT (moo, size <= MOO_OBJ_GET_SIZE(oop)); @@ -876,8 +876,8 @@ static MOO_INLINE void gc_ms_scan_stack (moo_t* moo) * determine that it is an instance of process? */ if (MOO_UNLIKELY(MOO_OBJ_GET_FLAGS_PROC(oop))) { - /* the stack in a process object doesn't need to be - * scanned in full. the slots above the stack pointer + /* the stack in a process object doesn't need to be + * scanned in full. the slots above the stack pointer * are garbages. */ size = MOO_PROCESS_NAMED_INSTVARS + MOO_OOP_TO_SMOOI(((moo_oop_process_t)oop)->sp) + 1; MOO_ASSERT (moo, size <= MOO_OBJ_GET_SIZE(oop)); @@ -976,7 +976,7 @@ static MOO_INLINE void gc_ms_mark_roots (moo_t* moo) if (moo->active_context) gc_ms_mark (moo, (moo_oop_t)moo->active_context); if (moo->active_method) gc_ms_mark (moo, (moo_oop_t)moo->active_method); - moo_rbt_walk (&moo->modtab, call_module_gc, moo); + moo_rbt_walk (&moo->modtab, call_module_gc, moo); for (cb = moo->evtcb_list; cb; cb = cb->next) { @@ -1136,7 +1136,7 @@ static moo_oop_t gc_ss_move_oop (moo_t* moo, moo_oop_t oop) if (MOO_OBJ_GET_FLAGS_MOVED(oop)) { - /* this object has migrated to the new heap. + /* this object has migrated to the new heap. * the class field has been updated to the new object * in the 'else' block below. i can simply return it * without further migration. */ @@ -1151,23 +1151,23 @@ static moo_oop_t gc_ss_move_oop (moo_t* moo, moo_oop_t oop) if (MOO_OBJ_GET_FLAGS_HASH(oop) == MOO_OBJ_FLAGS_HASH_CALLED) { - MOO_STATIC_ASSERT (MOO_SIZEOF(moo_oop_t) == MOO_SIZEOF(moo_oow_t)); - /* don't need explicit alignment since oop and oow have the same size + MOO_STATIC_ASSERT (MOO_SIZEOF(moo_oop_t) == MOO_SIZEOF(moo_oow_t)); + /* don't need explicit alignment since oop and oow have the same size extra_bytes = MOO_ALIGN(MOO_SIZEOF(moo_oow_t), MOO_SIZEOF(moo_oop_t)); */ - extra_bytes = MOO_SIZEOF(moo_oow_t); + extra_bytes = MOO_SIZEOF(moo_oow_t); } /* allocate space in the new heap */ tmp = moo_allocheapspace(moo, &moo->heap->newspace, MOO_SIZEOF(moo_obj_t) + nbytes_aligned + extra_bytes); /* allocation here must not fail because - * i'm allocating the new space in a new heap for - * moving an existing object in the current heap. + * i'm allocating the new space in a new heap for + * moving an existing object in the current heap. * * assuming the new heap is as large as the old heap, * and garbage collection doesn't allocate more objects * than in the old heap, it must not fail. */ - MOO_ASSERT (moo, tmp != MOO_NULL); + MOO_ASSERT (moo, tmp != MOO_NULL); /* copy the payload to the new object */ MOO_MEMCPY (tmp, oop, MOO_SIZEOF(moo_obj_t) + nbytes_aligned); @@ -1175,8 +1175,8 @@ static moo_oop_t gc_ss_move_oop (moo_t* moo, moo_oop_t oop) /* mark the old object that it has migrated to the new heap */ MOO_OBJ_SET_FLAGS_MOVED (oop, 1); - /* let the class field of the old object point to the new - * object allocated in the new heap. it is returned in + /* let the class field of the old object point to the new + * object allocated in the new heap. it is returned in * the 'if' block at the top of this function. */ MOO_OBJ_SET_CLASS (oop, tmp); @@ -1215,8 +1215,8 @@ static moo_uint8_t* gc_ss_scan_space (moo_t* moo, moo_uint8_t* ptr, moo_uint8_t* * determine that it is an instance of process? */ if (MOO_UNLIKELY(MOO_OBJ_GET_FLAGS_PROC(oop))) { - /* the stack in a process object doesn't need to be - * scanned in full. the slots above the stack pointer + /* the stack in a process object doesn't need to be + * scanned in full. the slots above the stack pointer * are garbages. */ size = MOO_PROCESS_NAMED_INSTVARS + MOO_OOP_TO_SMOOI(((moo_oop_process_t)oop)->sp) + 1; MOO_ASSERT (moo, size <= MOO_OBJ_GET_SIZE(oop)); @@ -1231,7 +1231,7 @@ static moo_uint8_t* gc_ss_scan_space (moo_t* moo, moo_uint8_t* ptr, moo_uint8_t* tmp = MOO_OBJ_GET_OOP_VAL(oop, i); if (MOO_OOP_IS_POINTER(tmp)) { - /* i must not use MOO_STORE_OOP() as this operation is + /* i must not use MOO_STORE_OOP() as this operation is * part of garbage collection. */ tmp = moo_updateoopforgc(moo, tmp); MOO_OBJ_SET_OOP_VAL (oop, i, tmp); @@ -1248,7 +1248,7 @@ static moo_uint8_t* gc_ss_scan_space (moo_t* moo, moo_uint8_t* ptr, moo_uint8_t* * i don't use moo->_nil because c->trgc field may not have * been updated to a new nil address while moo->_nil could * have been updated in the process of garbage collection. - * this comment will be invalidated when moo->_nil is + * this comment will be invalidated when moo->_nil is * stored in a permanent heap or GC gets changed to * a non-copying collector. no matter what GC implementation * i choose, using SMPTR(0) for this purpose is safe. */ @@ -1262,13 +1262,13 @@ static moo_uint8_t* gc_ss_scan_space (moo_t* moo, moo_uint8_t* ptr, moo_uint8_t* } /* return the pointer to the beginning of the free space in the heap */ - return ptr; + return ptr; } static void gc_ss_scan_roots (moo_t* moo) { - /* + /* * move a referenced object to the new heap. * inspect the fields of the moved object in the new heap. * move objects pointed to by the fields to the new heap. @@ -1286,18 +1286,18 @@ static void gc_ss_scan_roots (moo_t* moo) /* TODO: verify if this is correct */ MOO_ASSERT (moo, (moo_oop_t)moo->processor != moo->_nil); MOO_ASSERT (moo, (moo_oop_t)moo->processor->active != moo->_nil); - /* commit the stack pointer to the active process + /* commit the stack pointer to the active process * to limit scanning of the process stack properly */ moo->processor->active->sp = MOO_SMOOI_TO_OOP(moo->sp); } - MOO_LOG4 (moo, MOO_LOG_GC | MOO_LOG_INFO, + MOO_LOG4 (moo, MOO_LOG_GC | MOO_LOG_INFO, "Starting GC curheap base %p ptr %p newheap base %p ptr %p\n", - moo->heap->curspace.base, moo->heap->curspace.ptr, moo->heap->newspace.base, moo->heap->newspace.ptr); + moo->heap->curspace.base, moo->heap->curspace.ptr, moo->heap->newspace.base, moo->heap->newspace.ptr); newspace_scan_ptr = (moo_uint8_t*)MOO_ALIGN((moo_uintptr_t)moo->heap->newspace.base, MOO_SIZEOF(moo_oop_t)); - /* TODO: allocate common objects like _nil and the root dictionary + /* TODO: allocate common objects like _nil and the root dictionary * in the permanant heap. minimize moving around */ old_nil = moo->_nil; @@ -1360,7 +1360,7 @@ static void gc_ss_scan_roots (moo_t* moo) if (moo->active_method) moo->active_method = (moo_oop_method_t)moo_updateoopforgc(moo, (moo_oop_t)moo->active_method); - moo_rbt_walk (&moo->modtab, call_module_gc, moo); + moo_rbt_walk (&moo->modtab, call_module_gc, moo); for (cb = moo->evtcb_list; cb; cb = cb->next) { @@ -1373,7 +1373,7 @@ static void gc_ss_scan_roots (moo_t* moo) /* scan the new heap to move referenced objects */ newspace_scan_ptr = gc_ss_scan_space(moo, newspace_scan_ptr, &moo->heap->newspace.ptr); - /* check finalizable objects registered and scan the heap again. + /* check finalizable objects registered and scan the heap again. * symbol table compation is placed after this phase assuming that * no symbol is added to be finalized. */ gcfin_count = move_finalizable_objects(moo); @@ -1381,7 +1381,7 @@ static void gc_ss_scan_roots (moo_t* moo) /* traverse the symbol table for unreferenced symbols. * if the symbol has not moved to the new heap, the symbol - * is not referenced by any other objects than the symbol + * is not referenced by any other objects than the symbol * table itself */ /*if (!moo->igniting) */ compact_symbol_table (moo, old_nil); @@ -1389,7 +1389,7 @@ static void gc_ss_scan_roots (moo_t* moo) moo->symtab = (moo_oop_dic_t)moo_updateoopforgc(moo, (moo_oop_t)moo->symtab); /* scan the new heap again from the end position of - * the previous scan to move referenced objects by + * the previous scan to move referenced objects by * the symbol table. */ newspace_scan_ptr = gc_ss_scan_space(moo, newspace_scan_ptr, &moo->heap->newspace.ptr); @@ -1412,7 +1412,7 @@ static void gc_ss_scan_roots (moo_t* moo) buc = (moo_oop_oop_t) moo->symtab->bucket; for (index = 0; index < MOO_OBJ_GET_SIZE(buc); index++) { - if ((moo_oop_t)buc->slot[index] != moo->_nil) + if ((moo_oop_t)buc->slot[index] != moo->_nil) { MOO_LOG1 (moo, MOO_LOG_GC | MOO_LOG_DEBUG, "\t%O\n", buc->slot[index]); } @@ -1428,9 +1428,9 @@ static void gc_ss_scan_roots (moo_t* moo) moo_clearmethodcache (moo); /* TODO: include some gc statstics like number of live objects, gc performance, etc */ - MOO_LOG4 (moo, MOO_LOG_GC | MOO_LOG_INFO, + MOO_LOG4 (moo, MOO_LOG_GC | MOO_LOG_INFO, "Finished GC curheap base %p ptr %p newheap base %p ptr %p\n", - moo->heap->curspace.base, moo->heap->curspace.ptr, moo->heap->newspace.base, moo->heap->newspace.ptr); + moo->heap->curspace.base, moo->heap->curspace.ptr, moo->heap->newspace.base, moo->heap->newspace.ptr); } @@ -1447,7 +1447,7 @@ if (moo->gci.lazy_sweep) moo_gc_ms_sweep_lazy (moo, MOO_TYPE_MAX(moo_oow_t)); /*moo->gci.stack.max = 0;*/ gc_ms_mark_roots (moo); - if (!full && moo->gci.lazy_sweep) + if (!full && moo->gci.lazy_sweep) { /* set the lazy sweeping point to the head of the allocated blocks. * hawk_allocbytes() updates moo->gci.ls.prev if it is called while @@ -1532,7 +1532,7 @@ moo_oop_t moo_shallowcopy (moo_t* moo, moo_oop_t oop) MOO_MEMCPY (z, oop, total_bytes); MOO_OBJ_SET_FLAGS_RDONLY (z, 0); /* a copied object is not read-only */ MOO_OBJ_SET_FLAGS_HASH (z, 0); /* no hash field */ - return z; + return z; } return oop; @@ -1629,9 +1629,9 @@ static moo_oow_t move_finalizable_objects (moo_t* moo) * from the root except this finalizable list. this object would be * garbage if not for finalizatin. it's almost collectable. but it * will survive this cycle for finalization. - * + * * if garbages consist of finalizable objects only, GC should fail miserably. - * however this is quite unlikely because some key objects for VM execution + * however this is quite unlikely because some key objects for VM execution * like context objects doesn't require finalization. */ x->oop = moo_updateoopforgc(moo, x->oop); diff --git a/lib/heap.c b/lib/heap.c index cd06a7a..aa3d119 100644 --- a/lib/heap.c +++ b/lib/heap.c @@ -67,7 +67,7 @@ moo_heap_t* moo_makeheap (moo_t* moo, moo_oow_t size) alloc_size = size; heap = (moo_heap_t*)moo->vmprim.alloc_heap(moo, &alloc_size); } - if (MOO_UNLIKELY(!heap)) + if (MOO_UNLIKELY(!heap)) { const moo_ooch_t* oldmsg = moo_backuperrmsg(moo); moo_seterrbfmt (moo, moo_geterrnum(moo), "unable to allocate a heap - %js", oldmsg); @@ -131,7 +131,7 @@ moo_heap_t* moo_makeheap (moo_t* moo, moo_oow_t size) heap->newspace.ptr = (moo_uint8_t*)MOO_ALIGN(((moo_uintptr_t)heap->newspace.base), MOO_SIZEOF(moo_oop_t)); heap->newspace.limit = heap->newspace.base + space_size; - /* if size is too small, space.ptr may go past space.limit even at + /* if size is too small, space.ptr may go past space.limit even at * this moment depending on the alignment of space.base. subsequent * calls to moo_allocheapspace() are bound to fail. Make sure to * pass a heap size large enough */ @@ -181,7 +181,7 @@ void* moo_callocheapmem (moo_t* moo, moo_heap_t* heap, moo_oow_t size) MOO_ASSERT (moo, moo->gc_type == MOO_GC_TYPE_MARK_SWEEP); ptr = MOO_MMGR_ALLOC(&heap->xmmgr, size); - if (MOO_UNLIKELY(!ptr)) + if (MOO_UNLIKELY(!ptr)) { MOO_DEBUG2 (moo, "Cannot callocate %zd bytes from heap - ptr %p\n", size, heap); moo_seterrnum (moo, MOO_EOOMEM); diff --git a/lib/moo-chr.h b/lib/moo-chr.h index 7ead128..e5f017d 100644 --- a/lib/moo-chr.h +++ b/lib/moo-chr.h @@ -152,7 +152,7 @@ MOO_EXPORT int moo_is_bch_type (moo_bch_t c, moo_bch_prop_t type); # if __has_builtin(__builtin_tolower) # define moo_to_bch_lower __builtin_tolower # endif -#elif (__GNUC__ >= 4) +#elif (__GNUC__ >= 4) # define moo_is_bch_upper __builtin_isupper # define moo_is_bch_lower __builtin_islower # define moo_is_bch_alpha __builtin_isalpha diff --git a/lib/moo-cmn.h b/lib/moo-cmn.h index fd7c905..95d72d0 100644 --- a/lib/moo-cmn.h +++ b/lib/moo-cmn.h @@ -27,7 +27,7 @@ #ifndef _MOO_CMN_H_ #define _MOO_CMN_H_ -/* WARNING: NEVER CHANGE/DELETE THE FOLLOWING MOO_HAVE_CFG_H DEFINITION. +/* WARNING: NEVER CHANGE/DELETE THE FOLLOWING MOO_HAVE_CFG_H DEFINITION. * IT IS USED FOR DEPLOYMENT BY MAKEFILE.AM */ /*#define MOO_HAVE_CFG_H*/ @@ -52,7 +52,7 @@ #if defined(EMSCRIPTEN) # if defined(MOO_SIZEOF___INT128) -# undef MOO_SIZEOF___INT128 +# undef MOO_SIZEOF___INT128 # define MOO_SIZEOF___INT128 0 # endif # if defined(MOO_SIZEOF_LONG) && defined(MOO_SIZEOF_INT) && (MOO_SIZEOF_LONG > MOO_SIZEOF_INT) @@ -294,7 +294,7 @@ typedef moo_int64_t moo_intptr_t; typedef moo_uint32_t moo_ushortptr_t; typedef moo_int32_t moo_shortptr_t; -#elif defined(MOO_HAVE_UINT128_T) && (MOO_SIZEOF_VOID_P == 16) +#elif defined(MOO_HAVE_UINT128_T) && (MOO_SIZEOF_VOID_P == 16) typedef moo_uint128_t moo_uintptr_t; typedef moo_int128_t moo_intptr_t; typedef moo_uint64_t moo_ushortptr_t; @@ -409,7 +409,7 @@ typedef unsigned char moo_bchu_t; /* unsigned version of moo_bch_t for # define MOO_SIZEOF_UCH_T 4 #elif defined(__GNUC__) && defined(__CHAR16_TYPE__) - typedef __CHAR16_TYPE__ moo_uch_t; + typedef __CHAR16_TYPE__ moo_uch_t; typedef moo_uint16_t moo_uchu_t; /* same as moo_uch_t as it is already unsigned */ # define MOO_SIZEOF_UCH_T 2 #else @@ -480,7 +480,7 @@ typedef unsigned int moo_bitmask_t; typedef struct moo_obj_t moo_obj_t; typedef struct moo_obj_t* moo_oop_t; -/* +/* * An object pointer(OOP) is an ordinary pointer value to an object. * but some simple numeric values are also encoded into OOP using a simple * bit-shifting and masking. @@ -488,15 +488,15 @@ typedef struct moo_obj_t* moo_oop_t; * A real OOP is stored without any bit-shifting while a non-pointer value encoded * in an OOP is bit-shifted to the left by 2 and the 2 least-significant bits * are set to 1 or 2. - * + * * This scheme works because the object allocators aligns the object size to * a multiple of sizeof(moo_oop_t). This way, the 2 least-significant bits * of a real OOP are always 0s. * - * With 2 bits, i can encode only 3 special types except object pointers. + * With 2 bits, i can encode only 3 special types except object pointers. * Since I need more than 3 special types, I extend the tag bits up to 4 bits * to represent a special data type that doesn't require a range as wide - * as a small integer. A unicode character, for instance, only requires 21 + * as a small integer. A unicode character, for instance, only requires 21 * bits at most. An error doesn't need to be as diverse as a small integer. */ @@ -540,13 +540,13 @@ typedef struct moo_obj_t* moo_oop_t; /* -------------------------------- */ -/* SMOOI takes up 62 bits on a 64-bit architecture and 30 bits +/* SMOOI takes up 62 bits on a 64-bit architecture and 30 bits * on a 32-bit architecture. The absolute value takes up 61 bits and 29 bits * respectively for the sign bit. */ #define MOO_SMOOI_BITS (MOO_OOI_BITS - MOO_OOP_TAG_BITS_LO) #define MOO_SMOOI_ABS_BITS (MOO_SMOOI_BITS - 1) #define MOO_SMOOI_MAX ((moo_ooi_t)(~((moo_oow_t)0) >> (MOO_OOP_TAG_BITS_LO + 1))) -/* Sacrificing 1 bit pattern for a negative SMOOI makes +/* Sacrificing 1 bit pattern for a negative SMOOI makes * implementation a lot eaisier in many aspects. */ /*#define MOO_SMOOI_MIN (-MOO_SMOOI_MAX - 1)*/ #define MOO_SMOOI_MIN (-MOO_SMOOI_MAX) @@ -554,7 +554,7 @@ typedef struct moo_obj_t* moo_oop_t; /* SMPTR is a special value which has been devised to encode an address value * whose low MOO_OOP_TAG_BITS_LO bits are 0. its class is SmallPointer. A pointer - * returned by most of system functions would be aligned to the pointer size. + * returned by most of system functions would be aligned to the pointer size. * you can use the followings macros when converting such a pointer without loss. */ #define MOO_IN_SMPTR_RANGE(ptr) ((((moo_oow_t)ptr) & MOO_LBMASK(moo_oow_t, MOO_OOP_TAG_BITS_LO)) == 0) @@ -703,7 +703,7 @@ struct moo_ntime_t #endif /* make a bit mask that can mask off low n bits */ -#define MOO_LBMASK(type,n) (~(~((type)0) << (n))) +#define MOO_LBMASK(type,n) (~(~((type)0) << (n))) #define MOO_LBMASK_SAFE(type,n) (((n) < MOO_BITSOF(type))? MOO_LBMASK(type,n): ~(type)0) /* make a bit mask that can mask off hig n bits */ @@ -727,7 +727,7 @@ struct moo_ntime_t (value = (((type)(value)) | (((bits) & MOO_LBMASK(type,length)) << (offset)))) -/** +/** * The MOO_BITS_MAX() macros calculates the maximum value that the 'nbits' * bits of an unsigned integer of the given 'type' can hold. * \code @@ -742,12 +742,12 @@ struct moo_ntime_t * ========================================================================= */ typedef struct moo_mmgr_t moo_mmgr_t; -/** +/** * allocate a memory chunk of the size \a n. * \return pointer to a memory chunk on success, #MOO_NULL on failure. */ typedef void* (*moo_mmgr_alloc_t) (moo_mmgr_t* mmgr, moo_oow_t n); -/** +/** * resize a memory chunk pointed to by \a ptr to the size \a n. * \return pointer to a memory chunk on success, #MOO_NULL on failure. */ @@ -760,13 +760,13 @@ typedef void (*moo_mmgr_free_t) (moo_mmgr_t* mmgr, void* ptr); /** * The moo_mmgr_t type defines the memory management interface. * As the type is merely a structure, it is just used as a single container - * for memory management functions with a pointer to user-defined data. - * The user-defined data pointer \a ctx is passed to each memory management - * function whenever it is called. You can allocate, reallocate, and free + * for memory management functions with a pointer to user-defined data. + * The user-defined data pointer \a ctx is passed to each memory management + * function whenever it is called. You can allocate, reallocate, and free * a memory chunk. * * For example, a moo_xxx_open() function accepts a pointer of the moo_mmgr_t - * type and the xxx object uses it to manage dynamic data within the object. + * type and the xxx object uses it to manage dynamic data within the object. */ struct moo_mmgr_t { @@ -783,12 +783,12 @@ struct moo_mmgr_t #define MOO_MMGR_ALLOC(mmgr,size) ((mmgr)->alloc(mmgr,size)) /** - * The MOO_MMGR_REALLOC() macro resizes a memory block pointed to by \a ptr + * The MOO_MMGR_REALLOC() macro resizes a memory block pointed to by \a ptr * to the \a size bytes using the \a mmgr memory manager. */ #define MOO_MMGR_REALLOC(mmgr,ptr,size) ((mmgr)->realloc(mmgr,ptr,size)) -/** +/** * The MOO_MMGR_FREE() macro deallocates the memory block pointed to by \a ptr. */ #define MOO_MMGR_FREE(mmgr,ptr) ((mmgr)->free(mmgr,ptr)) @@ -801,7 +801,7 @@ struct moo_mmgr_t typedef struct moo_cmgr_t moo_cmgr_t; typedef moo_oow_t (*moo_cmgr_bctouc_t) ( - const moo_bch_t* mb, + const moo_bch_t* mb, moo_oow_t size, moo_uch_t* wc ); @@ -813,8 +813,8 @@ typedef moo_oow_t (*moo_cmgr_uctobc_t) ( ); /** - * The moo_cmgr_t type defines the character-level interface to - * multibyte/wide-character conversion. This interface doesn't + * The moo_cmgr_t type defines the character-level interface to + * multibyte/wide-character conversion. This interface doesn't * provide any facility to store conversion state in a context * independent manner. This leads to the limitation that it can * handle a stateless multibyte encoding only. @@ -845,7 +845,7 @@ typedef struct moo_t moo_t; #elif defined(_WIN32) || (defined(__WATCOMC__) && (__WATCOMC__ >= 1000) && !defined(__WINDOWS_386__)) # define MOO_IMPORT __declspec(dllimport) # define MOO_EXPORT __declspec(dllexport) -# define MOO_PRIVATE +# define MOO_PRIVATE #elif defined(__GNUC__) && ((__GNUC__>= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) # define MOO_IMPORT __attribute__((visibility("default"))) # define MOO_EXPORT __attribute__((visibility("default"))) @@ -862,12 +862,12 @@ typedef struct moo_t moo_t; # define MOO_INLINE inline # define MOO_HAVE_INLINE #elif defined(__GNUC__) && defined(__GNUC_GNU_INLINE__) - /* gcc disables inline when -std=c89 or -ansi is used. + /* gcc disables inline when -std=c89 or -ansi is used. * so use __inline__ supported by gcc regardless of the options */ # define MOO_INLINE /*extern*/ __inline__ # define MOO_HAVE_INLINE #else -# define MOO_INLINE +# define MOO_INLINE # undef MOO_HAVE_INLINE #endif @@ -936,7 +936,7 @@ typedef struct moo_t moo_t; #endif */ -#if defined(__has_builtin) +#if defined(__has_builtin) #if __has_builtin(__builtin_ctz) #define MOO_HAVE_BUILTIN_CTZ #endif @@ -958,41 +958,41 @@ typedef struct moo_t moo_t; #endif #if __has_builtin(__builtin_uadd_overflow) - #define MOO_HAVE_BUILTIN_UADD_OVERFLOW + #define MOO_HAVE_BUILTIN_UADD_OVERFLOW #endif #if __has_builtin(__builtin_uaddl_overflow) - #define MOO_HAVE_BUILTIN_UADDL_OVERFLOW + #define MOO_HAVE_BUILTIN_UADDL_OVERFLOW #endif #if __has_builtin(__builtin_uaddll_overflow) - #define MOO_HAVE_BUILTIN_UADDLL_OVERFLOW + #define MOO_HAVE_BUILTIN_UADDLL_OVERFLOW #endif #if __has_builtin(__builtin_umul_overflow) - #define MOO_HAVE_BUILTIN_UMUL_OVERFLOW + #define MOO_HAVE_BUILTIN_UMUL_OVERFLOW #endif #if __has_builtin(__builtin_umull_overflow) - #define MOO_HAVE_BUILTIN_UMULL_OVERFLOW + #define MOO_HAVE_BUILTIN_UMULL_OVERFLOW #endif #if __has_builtin(__builtin_umulll_overflow) - #define MOO_HAVE_BUILTIN_UMULLL_OVERFLOW + #define MOO_HAVE_BUILTIN_UMULLL_OVERFLOW #endif #if __has_builtin(__builtin_sadd_overflow) - #define MOO_HAVE_BUILTIN_SADD_OVERFLOW + #define MOO_HAVE_BUILTIN_SADD_OVERFLOW #endif #if __has_builtin(__builtin_saddl_overflow) - #define MOO_HAVE_BUILTIN_SADDL_OVERFLOW + #define MOO_HAVE_BUILTIN_SADDL_OVERFLOW #endif #if __has_builtin(__builtin_saddll_overflow) - #define MOO_HAVE_BUILTIN_SADDLL_OVERFLOW + #define MOO_HAVE_BUILTIN_SADDLL_OVERFLOW #endif #if __has_builtin(__builtin_smul_overflow) - #define MOO_HAVE_BUILTIN_SMUL_OVERFLOW + #define MOO_HAVE_BUILTIN_SMUL_OVERFLOW #endif #if __has_builtin(__builtin_smull_overflow) - #define MOO_HAVE_BUILTIN_SMULL_OVERFLOW + #define MOO_HAVE_BUILTIN_SMULL_OVERFLOW #endif #if __has_builtin(__builtin_smulll_overflow) - #define MOO_HAVE_BUILTIN_SMULLL_OVERFLOW + #define MOO_HAVE_BUILTIN_SMULLL_OVERFLOW #endif #if __has_builtin(__builtin_expect) @@ -1032,7 +1032,7 @@ typedef struct moo_t moo_t; #endif #elif defined(__GNUC__) && defined(__GNUC_MINOR__) - #if (__GNUC__ >= 4) + #if (__GNUC__ >= 4) #define MOO_HAVE_SYNC_LOCK_TEST_AND_SET #define MOO_HAVE_SYNC_LOCK_RELEASE diff --git a/lib/moo-dos.h b/lib/moo-dos.h index d22b6f3..09f3468 100644 --- a/lib/moo-dos.h +++ b/lib/moo-dos.h @@ -85,7 +85,7 @@ # define MOO_SIZEOF_MBSTATE_T MOO_SIZEOF_LONG # define MOO_MBLEN_MAX 8 -#elif defined(__TURBOC__) +#elif defined(__TURBOC__) /* TODO: be more version specific wchar_t may be available in newer BCC */ # define MOO_SIZEOF_CHAR 1 # define MOO_SIZEOF_SHORT 2 @@ -96,7 +96,7 @@ # define MOO_SIZEOF_VOID_P 4 # define MOO_SIZEOF_FLOAT 4 # define MOO_SIZEOF_DOUBLE 8 -# define MOO_SIZEOF_LONG_DOUBLE 10 +# define MOO_SIZEOF_LONG_DOUBLE 10 # define MOO_SIZEOF_WCHAR_T 0 # define MOO_SIZEOF___INT8 0 diff --git a/lib/moo-fmt.h b/lib/moo-fmt.h index 49f592f..745663d 100644 --- a/lib/moo-fmt.h +++ b/lib/moo-fmt.h @@ -34,7 +34,7 @@ * This file defines various formatting functions. */ -/** +/** * The moo_fmt_intmax_flag_t type defines enumerators to change the * behavior of moo_fmt_intmax() and moo_fmt_uintmax(). */ @@ -163,7 +163,7 @@ typedef int (*moo_fmtout_putobj_t) ( moo_oop_t obj ); -enum moo_fmtout_fmt_type_t +enum moo_fmtout_fmt_type_t { MOO_FMTOUT_FMT_TYPE_BCH = 0, MOO_FMTOUT_FMT_TYPE_UCH @@ -193,22 +193,22 @@ extern "C" { #endif /** - * The moo_fmt_intmax_to_bcstr() function formats an integer \a value to a - * multibyte string according to the given base and writes it to a buffer - * pointed to by \a buf. It writes to the buffer at most \a size characters - * including the terminating null. The base must be between 2 and 36 inclusive - * and can be ORed with zero or more #moo_fmt_intmax_to_bcstr_flag_t enumerators. - * This ORed value is passed to the function via the \a base_and_flags + * The moo_fmt_intmax_to_bcstr() function formats an integer \a value to a + * multibyte string according to the given base and writes it to a buffer + * pointed to by \a buf. It writes to the buffer at most \a size characters + * including the terminating null. The base must be between 2 and 36 inclusive + * and can be ORed with zero or more #moo_fmt_intmax_to_bcstr_flag_t enumerators. + * This ORed value is passed to the function via the \a base_and_flags * parameter. If the formatted string is shorter than \a bufsize, the redundant - * slots are filled with the fill character \a fillchar if it is not a null + * slots are filled with the fill character \a fillchar if it is not a null * character. The filling behavior is determined by the flags shown below: * - * - If #MOO_FMT_INTMAX_TO_BCSTR_FILLRIGHT is set in \a base_and_flags, slots + * - If #MOO_FMT_INTMAX_TO_BCSTR_FILLRIGHT is set in \a base_and_flags, slots * after the formatting string are filled. - * - If #MOO_FMT_INTMAX_TO_BCSTR_FILLCENTER is set in \a base_and_flags, slots + * - If #MOO_FMT_INTMAX_TO_BCSTR_FILLCENTER is set in \a base_and_flags, slots * before the formatting string are filled. However, if it contains the * sign character, the slots between the sign character and the digit part - * are filled. + * are filled. * - If neither #MOO_FMT_INTMAX_TO_BCSTR_FILLRIGHT nor #MOO_FMT_INTMAX_TO_BCSTR_FILLCENTER * , slots before the formatting string are filled. * @@ -220,26 +220,26 @@ extern "C" { * * The terminating null is not added if #MOO_FMT_INTMAX_TO_BCSTR_NONULL is set; * The #MOO_FMT_INTMAX_TO_BCSTR_UPPERCASE flag indicates that the function should - * use the uppercase letter for a alphabetic digit; + * use the uppercase letter for a alphabetic digit; * You can set #MOO_FMT_INTMAX_TO_BCSTR_NOTRUNC if you require lossless formatting. - * The #MOO_FMT_INTMAX_TO_BCSTR_PLUSSIGN flag and #MOO_FMT_INTMAX_TO_BCSTR_EMPTYSIGN - * ensures that the plus sign and a space is added for a positive integer + * The #MOO_FMT_INTMAX_TO_BCSTR_PLUSSIGN flag and #MOO_FMT_INTMAX_TO_BCSTR_EMPTYSIGN + * ensures that the plus sign and a space is added for a positive integer * including 0 respectively. * The #MOO_FMT_INTMAX_TO_BCSTR_ZEROLEAD flag ensures that the numeric string * begins with '0' before applying the prefix. * You can set the #MOO_FMT_INTMAX_TO_BCSTR_NOZERO flag if you want the value of - * 0 to produce nothing. If both #MOO_FMT_INTMAX_TO_BCSTR_NOZERO and + * 0 to produce nothing. If both #MOO_FMT_INTMAX_TO_BCSTR_NOZERO and * #MOO_FMT_INTMAX_TO_BCSTR_ZEROLEAD are specified, '0' is still produced. - * + * * If \a prefix is not #MOO_NULL, it is inserted before the digits. - * + * * \return - * - -1 if the base is not between 2 and 36 inclusive. - * - negated number of characters required for lossless formatting + * - -1 if the base is not between 2 and 36 inclusive. + * - negated number of characters required for lossless formatting * - if \a bufsize is 0. * - if #MOO_FMT_INTMAX_TO_BCSTR_NOTRUNC is set and \a bufsize is less than * the minimum required for lossless formatting. - * - number of characters written to the buffer excluding a terminating + * - number of characters written to the buffer excluding a terminating * null in all other cases. */ MOO_EXPORT int moo_fmt_intmax_to_bcstr ( @@ -253,25 +253,25 @@ MOO_EXPORT int moo_fmt_intmax_to_bcstr ( ); /** - * The moo_fmt_intmax_to_ucstr() function formats an integer \a value to a - * wide-character string according to the given base and writes it to a buffer - * pointed to by \a buf. It writes to the buffer at most \a size characters - * including the terminating null. The base must be between 2 and 36 inclusive - * and can be ORed with zero or more #moo_fmt_intmax_to_ucstr_flag_t enumerators. - * This ORed value is passed to the function via the \a base_and_flags + * The moo_fmt_intmax_to_ucstr() function formats an integer \a value to a + * wide-character string according to the given base and writes it to a buffer + * pointed to by \a buf. It writes to the buffer at most \a size characters + * including the terminating null. The base must be between 2 and 36 inclusive + * and can be ORed with zero or more #moo_fmt_intmax_to_ucstr_flag_t enumerators. + * This ORed value is passed to the function via the \a base_and_flags * parameter. If the formatted string is shorter than \a bufsize, the redundant - * slots are filled with the fill character \a fillchar if it is not a null + * slots are filled with the fill character \a fillchar if it is not a null * character. The filling behavior is determined by the flags shown below: * - * - If #MOO_FMT_INTMAX_TO_UCSTR_FILLRIGHT is set in \a base_and_flags, slots + * - If #MOO_FMT_INTMAX_TO_UCSTR_FILLRIGHT is set in \a base_and_flags, slots * after the formatting string are filled. - * - If #MOO_FMT_INTMAX_TO_UCSTR_FILLCENTER is set in \a base_and_flags, slots + * - If #MOO_FMT_INTMAX_TO_UCSTR_FILLCENTER is set in \a base_and_flags, slots * before the formatting string are filled. However, if it contains the * sign character, the slots between the sign character and the digit part - * are filled. + * are filled. * - If neither #MOO_FMT_INTMAX_TO_UCSTR_FILLRIGHT nor #MOO_FMT_INTMAX_TO_UCSTR_FILLCENTER * , slots before the formatting string are filled. - * + * * The \a precision parameter specified the minimum number of digits to * produce from the \ value. If \a value produces fewer digits than * \a precision, the actual digits are padded with '0' to meet the precision @@ -280,26 +280,26 @@ MOO_EXPORT int moo_fmt_intmax_to_bcstr ( * * The terminating null is not added if #MOO_FMT_INTMAX_TO_UCSTR_NONULL is set; * The #MOO_FMT_INTMAX_TO_UCSTR_UPPERCASE flag indicates that the function should - * use the uppercase letter for a alphabetic digit; + * use the uppercase letter for a alphabetic digit; * You can set #MOO_FMT_INTMAX_TO_UCSTR_NOTRUNC if you require lossless formatting. - * The #MOO_FMT_INTMAX_TO_UCSTR_PLUSSIGN flag and #MOO_FMT_INTMAX_TO_UCSTR_EMPTYSIGN - * ensures that the plus sign and a space is added for a positive integer + * The #MOO_FMT_INTMAX_TO_UCSTR_PLUSSIGN flag and #MOO_FMT_INTMAX_TO_UCSTR_EMPTYSIGN + * ensures that the plus sign and a space is added for a positive integer * including 0 respectively. * The #MOO_FMT_INTMAX_TO_UCSTR_ZEROLEAD flag ensures that the numeric string * begins with 0 before applying the prefix. * You can set the #MOO_FMT_INTMAX_TO_UCSTR_NOZERO flag if you want the value of - * 0 to produce nothing. If both #MOO_FMT_INTMAX_TO_UCSTR_NOZERO and + * 0 to produce nothing. If both #MOO_FMT_INTMAX_TO_UCSTR_NOZERO and * #MOO_FMT_INTMAX_TO_UCSTR_ZEROLEAD are specified, '0' is still produced. * * If \a prefix is not #MOO_NULL, it is inserted before the digits. - * + * * \return - * - -1 if the base is not between 2 and 36 inclusive. - * - negated number of characters required for lossless formatting + * - -1 if the base is not between 2 and 36 inclusive. + * - negated number of characters required for lossless formatting * - if \a bufsize is 0. * - if #MOO_FMT_INTMAX_TO_UCSTR_NOTRUNC is set and \a bufsize is less than * the minimum required for lossless formatting. - * - number of characters written to the buffer excluding a terminating + * - number of characters written to the buffer excluding a terminating * null in all other cases. */ MOO_EXPORT int moo_fmt_intmax_to_ucstr ( @@ -313,8 +313,8 @@ MOO_EXPORT int moo_fmt_intmax_to_ucstr ( ); /** - * The moo_fmt_uintmax_to_bcstr() function formats an unsigned integer \a value - * to a multibyte string buffer. It behaves the same as moo_fmt_intmax_to_bcstr() + * The moo_fmt_uintmax_to_bcstr() function formats an unsigned integer \a value + * to a multibyte string buffer. It behaves the same as moo_fmt_intmax_to_bcstr() * except that it handles an unsigned integer. */ MOO_EXPORT int moo_fmt_uintmax_to_bcstr ( @@ -328,8 +328,8 @@ MOO_EXPORT int moo_fmt_uintmax_to_bcstr ( ); /** - * The moo_fmt_uintmax_to_ucstr() function formats an unsigned integer \a value - * to a multibyte string buffer. It behaves the same as moo_fmt_intmax_to_ucstr() + * The moo_fmt_uintmax_to_ucstr() function formats an unsigned integer \a value + * to a multibyte string buffer. It behaves the same as moo_fmt_intmax_to_ucstr() * except that it handles an unsigned integer. */ MOO_EXPORT int moo_fmt_uintmax_to_ucstr ( diff --git a/lib/moo-mac.h b/lib/moo-mac.h index 03e312f..c27b85e 100644 --- a/lib/moo-mac.h +++ b/lib/moo-mac.h @@ -26,7 +26,7 @@ /* This file is for class Mac OS */ /* Mac OS on PPC and m68k uses the big endian mode */ -#define MOO_ENDIAN_BIG +#define MOO_ENDIAN_BIG #if defined(__MWERKS__) # define MOO_SIZEOF_CHAR 1 diff --git a/lib/moo-msw.h b/lib/moo-msw.h index de6f94a..fc813b8 100644 --- a/lib/moo-msw.h +++ b/lib/moo-msw.h @@ -25,18 +25,18 @@ */ /* -Macro Meaning -_WIN64 A 64-bit platform. -_WIN32 A 32-bit platform. This value is also defined by the 64-bit - compiler for backward compatibility. -_WIN16 A 16-bit platform +Macro Meaning +_WIN64 A 64-bit platform. +_WIN32 A 32-bit platform. This value is also defined by the 64-bit + compiler for backward compatibility. +_WIN16 A 16-bit platform The following macros are specific to the architecture. -Macro Meaning -_M_IA64 Intel Itanium Processor Family -_M_IX86 x86 platform -_M_X64 x64 platform +Macro Meaning +_M_IA64 Intel Itanium Processor Family +_M_IX86 x86 platform +_M_X64 x64 platform */ /*#define MOO_ENABLE_STATIC_MODULE*/ @@ -45,9 +45,9 @@ _M_X64 x64 platform /* use UCS4 for uch_t */ /*#define MOO_WIDE_CHAR_SIZE 4*/ -/* windows for most of non-x86 platforms dropped. +/* windows for most of non-x86 platforms dropped. * make it selective to support old non-x86 windows platforms. */ -#define MOO_ENDIAN_LITTLE +#define MOO_ENDIAN_LITTLE #if defined(__WATCOMC__) # define MOO_SIZEOF_CHAR 1 diff --git a/lib/moo-opt.h b/lib/moo-opt.h index a1ea68b..e15592c 100644 --- a/lib/moo-opt.h +++ b/lib/moo-opt.h @@ -30,8 +30,8 @@ #include /** \file - * This file defines functions and data structures to process - * command-line arguments. + * This file defines functions and data structures to process + * command-line arguments. */ typedef struct moo_uopt_t moo_uopt_t; @@ -54,7 +54,7 @@ struct moo_uopt_t moo_uch_t* arg; /* argument associated with an option */ /* output */ - const moo_uch_t* lngopt; + const moo_uch_t* lngopt; /* input + output */ int ind; /* index into parent argv vector */ @@ -83,7 +83,7 @@ struct moo_bopt_t moo_bch_t* arg; /* argument associated with an option */ /* output */ - const moo_bch_t* lngopt; + const moo_bch_t* lngopt; /* input + output */ int ind; /* index into parent argv vector */ @@ -98,27 +98,27 @@ extern "C" { /** * The moo_getopt() function processes the \a argc command-line arguments - * pointed to by \a argv as configured in \a opt. It can process two - * different option styles: a single character starting with '-', and a - * long name starting with '--'. + * pointed to by \a argv as configured in \a opt. It can process two + * different option styles: a single character starting with '-', and a + * long name starting with '--'. * * A character in \a opt.str is treated as a single character option. Should * it require a parameter, specify ':' after it. * - * Two special returning option characters indicate special error conditions. + * Two special returning option characters indicate special error conditions. * - \b ? indicates a bad option stored in the \a opt->opt field. * - \b : indicates a bad parameter for an option stored in the \a opt->opt field. * * @return an option character on success, MOO_CHAR_EOF on no more options. */ MOO_EXPORT moo_uci_t moo_getuopt ( - int argc, /* argument count */ + int argc, /* argument count */ moo_uch_t* const* argv, /* argument array */ moo_uopt_t* opt /* option configuration */ ); MOO_EXPORT moo_bci_t moo_getbopt ( - int argc, /* argument count */ + int argc, /* argument count */ moo_bch_t* const* argv, /* argument array */ moo_bopt_t* opt /* option configuration */ ); diff --git a/lib/moo-os2.h b/lib/moo-os2.h index 12247af..109266d 100644 --- a/lib/moo-os2.h +++ b/lib/moo-os2.h @@ -57,7 +57,7 @@ # define MOO_SIZEOF_OFF64_T 0 # define MOO_SIZEOF_OFF_T 8 -/* I don't know the exact mbstate size. +/* I don't know the exact mbstate size. * but this should be large enough */ # define MOO_SIZEOF_MBSTATE_T MOO_SIZEOF_LONG /* TODO: check the exact value */ diff --git a/lib/moo-prv.h b/lib/moo-prv.h index 2d4646e..2aab804 100644 --- a/lib/moo-prv.h +++ b/lib/moo-prv.h @@ -35,7 +35,7 @@ /* you can define this to either 1 or 2 */ #define MOO_BCODE_LONG_PARAM_SIZE 2 -/* this is useful for debugging. moo_gc() can be called +/* this is useful for debugging. moo_gc() can be called * while moo has not been fully initialized when this is defined*/ #define MOO_SUPPORT_GC_DURING_IGNITION @@ -138,14 +138,14 @@ * named instance variables. If the spec of a class is indexed, the object * of the class can be instantiated with the size of the indexed part. * - * For example, on a platform where sizeof(moo_oow_t) is 4, + * For example, on a platform where sizeof(moo_oow_t) is 4, * the layout of the spec field of a class as an OOP value looks like this: - * - * 31 12 11 10 9 8 7 6 5 4 3 2 1 0 + * + * 31 12 11 10 9 8 7 6 5 4 3 2 1 0 * |number of named instance variables|indexed-type|flags |oop-tag| * * the number of named instance variables is stored in high 21 bits. - * the indexed type takes up bit 5 to bit 10 (assuming MOO_OBJ_TYPE_BITS is 6. + * the indexed type takes up bit 5 to bit 10 (assuming MOO_OBJ_TYPE_BITS is 6. * MOO_OBJ_TYPE_XXX enumerators are used to represent actual values). * and the indexability is stored in the flag bits which span from bit 2 to 4. * @@ -158,7 +158,7 @@ * The number of named instance variables can be greater than 0 if the * class spec is not indexed or if it's a pointer indexed class * (indexed_type == MOO_OBJ_TYPE_OOP) - * + * * indexed_type is one of the #moo_obj_type_t enumerators. */ @@ -172,13 +172,13 @@ (((moo_oow_t)(named_instvar)) << (MOO_OBJ_FLAGS_TYPE_BITS + MOO_CLASS_SPEC_FLAG_BITS)) | \ (((moo_oow_t)(indexed_type)) << (MOO_CLASS_SPEC_FLAG_BITS)) | (((moo_oow_t)flags) & MOO_LBMASK(moo_oow_t,MOO_CLASS_SPEC_FLAG_BITS))) -/* what is the number of named instance variables? - * MOO_CLASS_SPEC_NAMED_INSTVARS(MOO_OOP_TO_SMOOI(_class->spec)) +/* what is the number of named instance variables? + * MOO_CLASS_SPEC_NAMED_INSTVARS(MOO_OOP_TO_SMOOI(_class->spec)) * ensure to update Class<> (MOO_OBJ_FLAGS_TYPE_BITS + MOO_CLASS_SPEC_FLAG_BITS)) -/* is it a user-indexable class? +/* is it a user-indexable class? * all objects can be indexed with basicAt:. * this indicates if an object can be instantiated with a dynamic size * (new: size) and and can be indexed with at:. @@ -198,17 +198,17 @@ #define MOO_CLASS_SPEC_IS_UNCOPYABLE(spec) (MOO_CLASS_SPEC_FLAGS(spec) & MOO_CLASS_SPEC_FLAG_UNCOPYABLE) /* What is the maximum number of named instance variables? - * This limit is set this way because the number must be encoded into + * This limit is set this way because the number must be encoded into * the spec field of the class with limited number of bits assigned to * the number of named instance variables. */ #define MOO_MAX_NAMED_INSTVARS \ MOO_BITS_MAX(moo_oow_t, MOO_SMOOI_ABS_BITS - (MOO_OBJ_FLAGS_TYPE_BITS + MOO_CLASS_SPEC_FLAG_BITS)) -/* Given the number of named instance variables, what is the maximum number +/* Given the number of named instance variables, what is the maximum number * of indexed instance variables? The number of indexed instance variables * is not stored in the spec field of the class. It only affects the actual - * size of an object(obj->_size) selectively combined with the number of + * size of an object(obj->_size) selectively combined with the number of * named instance variables. So it's the maximum value of obj->_size minus * the number of named instance variables. */ @@ -412,7 +412,7 @@ typedef struct moo_label_t moo_label_t; struct moo_label_t { moo_oow_t blk_id; /* block id where this label belongs to */ - moo_oow_t blk_depth; /* level of the block where thsi label belongs to */ + moo_oow_t blk_depth; /* level of the block where thsi label belongs to */ moo_ioloc_t loc; /* location inside source */ moo_oow_t ip; /* instruction pointer where this label points to */ moo_label_t* next; @@ -460,7 +460,7 @@ enum moo_pragma_flag_t enum moo_cunit_type_t { - /* [NOTE] get_cunit_method_data() in comp.c depends on the order of the + /* [NOTE] get_cunit_method_data() in comp.c depends on the order of the * following enumerators */ MOO_CUNIT_BLANK = 0, MOO_CUNIT_POOLDIC, @@ -540,7 +540,7 @@ struct moo_method_data_t int variadic; /* single string containing a space separated list of temporaries */ - moo_oocs_t tmprs; + moo_oocs_t tmprs; moo_oow_t tmprs_capa; moo_oow_t tmpr_count; /* total number of temporaries including arguments */ moo_oow_t tmpr_nargs; @@ -551,7 +551,7 @@ struct moo_method_data_t /* 0 for no primitive, 1 for a normal primitive, 2 for a named primitive */ int pftype; /* primitive function number */ - moo_ooi_t pfnum; + moo_ooi_t pfnum; /* block depth - [ ... ]*/ moo_oow_t blk_idseq; @@ -579,7 +579,7 @@ struct moo_cunit_class_t int indexed_type; /* fixed instance size specified for a non-pointer class. class(#byte(N)), etc */ - moo_oow_t non_pointer_instsize; + moo_oow_t non_pointer_instsize; moo_oop_class_t self_oop; moo_oop_t super_oop; /* this may be nil. so the type is moo_oop_t */ @@ -606,7 +606,7 @@ struct moo_cunit_class_t /* instance variable, class variable, class instance variable, constant * var[0] - named instance variables * var[1] - class instance variables - * var[2] - class variables + * var[2] - class variables */ struct { @@ -618,7 +618,7 @@ struct moo_cunit_class_t moo_initv_t* initv; moo_oow_t initv_capa; - /* initv_count holds the index to the last variable with a + /* initv_count holds the index to the last variable with a * default initial value defined in this class only plus one. * inheritance is handled by the compiler separately using * the reference to the superclass. so it doesn't include @@ -627,7 +627,7 @@ struct moo_cunit_class_t * initv_count is set to 2 while count is 3. totoal_count * will be 3 too if there is no variabled defined in the * superclass chain. */ - moo_oow_t initv_count; + moo_oow_t initv_count; } var[3]; moo_oow_t dbgi_class_offset; @@ -672,7 +672,7 @@ struct moo_compiler_t int nungots; /* static input data buffer */ - moo_ioarg_t arg; + moo_ioarg_t arg; /* pointer to the current input data. initially, it points to &arg */ moo_ioarg_t* curinp; @@ -725,7 +725,7 @@ struct moo_compiler_t SHORT INSTRUCTION CODE LONG INSTRUCTION CODE ---------------------------------------------------------------------------------------------------------------- v v -0-3 0000 00XX STORE_INTO_INSTVAR 128 1000 0000 XXXXXXXX STORE_INTO_INSTVAR_X (bit 4 off, bit 3 off) +0-3 0000 00XX STORE_INTO_INSTVAR 128 1000 0000 XXXXXXXX STORE_INTO_INSTVAR_X (bit 4 off, bit 3 off) 4-7 0000 01XX STORE_INTO_INSTVAR 8-11 0000 10XX POP_INTO_INSTVAR 136 1000 1000 XXXXXXXX POP_INTO_INSTVAR_X (bit 4 off, bit 3 on) 12-15 0000 11XX POP_INTO_INSTVAR @@ -939,7 +939,7 @@ enum moo_bcode_t BCODE_PUSH_PROCESS = 0x86, /* 134 */ BCODE_PUSH_RECEIVER_NS = 0x87, /* 135 */ - BCODE_POP_INTO_INSTVAR_X = 0x88, /* 136 ## */ + BCODE_POP_INTO_INSTVAR_X = 0x88, /* 136 ## */ BCODE_PUSH_NEGONE = 0x89, /* 137 */ BCODE_PUSH_ZERO = 0x8A, /* 138 */ @@ -977,7 +977,7 @@ enum moo_bcode_t BCODE_JMPOP2_FORWARD_IF_TRUE = 0xCB, /* 203 ## */ BCODE_JMPOP_FORWARD_IF_FALSE = 0xCC, /* 204 ## */ BCODE_JMPOP2_FORWARD_IF_FALSE = 0xCD, /* 205 ## */ - + BCODE_JUMP_BACKWARD = 0xCE, /* 206 ## */ BCODE_JUMP2_BACKWARD = 0xCF, /* 207 ## */ BCODE_JUMP_BACKWARD_IF_TRUE = 0xD0, /* 208 ## */ @@ -1022,7 +1022,7 @@ enum moo_bcode_t BCODE_NOOP = 0xFF }; -/* i don't want an error raised inside the callback to override +/* i don't want an error raised inside the callback to override * the existing error number and message. */ #define vmprim_log_write(moo,mask,ptr,len) do { \ int shuterr = (moo)->shuterr; \ @@ -1098,7 +1098,7 @@ void moo_setsynerr ( * \return heap pointer on success and #MOO_NULL on failure. */ moo_heap_t* moo_makeheap ( - moo_t* moo, + moo_t* moo, moo_oow_t size ); @@ -1106,12 +1106,12 @@ moo_heap_t* moo_makeheap ( * The moo_killheap() function destroys the heap pointed to by \a heap. */ void moo_killheap ( - moo_t* moo, + moo_t* moo, moo_heap_t* heap ); /** - * The moo_allocheapspace() function allocates \a size bytes in a semi-space + * The moo_allocheapspace() function allocates \a size bytes in a semi-space * of the heap pointed to by \a heap. * * \return memory pointer on success and #MOO_NULL on failure. @@ -1122,7 +1122,7 @@ void* moo_allocheapspace ( moo_oow_t size ); -/** +/** * The moo_allocheapmem() function allocates \a size bytes from the given heap * and clears it with zeros. */ diff --git a/lib/moo-rbt.h b/lib/moo-rbt.h index 51442c7..347f8a0 100644 --- a/lib/moo-rbt.h +++ b/lib/moo-rbt.h @@ -31,37 +31,37 @@ /** \file * This file provides a red-black tree encapsulated in the #moo_rbt_t type that - * implements a self-balancing binary search tree.Its interface is very close + * implements a self-balancing binary search tree.Its interface is very close * to #moo_htb_t. * * This sample code adds a series of keys and values and print them * in descending key order. * \code * #include - * + * * static moo_rbt_walk_t walk (moo_rbt_t* rbt, moo_rbt_pair_t* pair, void* ctx) * { * moo_printf (MOO_T("key = %d, value = %d\n"), * *(int*)MOO_RBT_KPTR(pair), *(int*)MOO_RBT_VPTR(pair)); * return MOO_RBT_WALK_FORWARD; * } - * + * * int main () * { * moo_rbt_t* s1; * int i; - * + * * s1 = moo_rbt_open (MOO_MMGR_GETDFL(), 0, 1, 1); // error handling skipped * moo_rbt_setstyle (s1, moo_get_rbt_style(MOO_RBT_STYLE_INLINE_COPIERS)); - * + * * for (i = 0; i < 20; i++) * { * int x = i * 20; * moo_rbt_insert (s1, &i, MOO_SIZEOF(i), &x, MOO_SIZEOF(x)); // eror handling skipped * } - * + * * moo_rbt_rwalk (s1, walk, MOO_NULL); - * + * * moo_rbt_close (s1); * return 0; * } @@ -71,7 +71,7 @@ typedef struct moo_rbt_t moo_rbt_t; typedef struct moo_rbt_pair_t moo_rbt_pair_t; -/** +/** * The moo_rbt_walk_t type defines values that the callback function can * return to control moo_rbt_walk() and moo_rbt_rwalk(). */ @@ -98,7 +98,7 @@ typedef enum moo_rbt_id_t moo_rbt_id_t; */ typedef void* (*moo_rbt_copier_t) ( moo_rbt_t* rbt /**< red-black tree */, - void* dptr /**< pointer to a key or a value */, + void* dptr /**< pointer to a key or a value */, moo_oow_t dlen /**< length of a key or a value */ ); @@ -119,17 +119,17 @@ typedef void (*moo_rbt_freeer_t) ( * key is greater than the second key, -1 otherwise. */ typedef int (*moo_rbt_comper_t) ( - const moo_rbt_t* rbt, /**< red-black tree */ + const moo_rbt_t* rbt, /**< red-black tree */ const void* kptr1, /**< key pointer */ - moo_oow_t klen1, /**< key length */ + moo_oow_t klen1, /**< key length */ const void* kptr2, /**< key pointer */ moo_oow_t klen2 /**< key length */ ); /** - * The moo_rbt_keeper_t type defines a value keeper that is called when + * The moo_rbt_keeper_t type defines a value keeper that is called when * a value is retained in the context that it should be destroyed because - * it is identical to a new value. Two values are identical if their + * it is identical to a new value. Two values are identical if their * pointers and lengths are equal. */ typedef void (*moo_rbt_keeper_t) ( @@ -149,12 +149,12 @@ typedef moo_rbt_walk_t (*moo_rbt_walker_t) ( /** * The moo_rbt_cbserter_t type defines a callback function for moo_rbt_cbsert(). - * The moo_rbt_cbserter() function calls it to allocate a new pair for the + * The moo_rbt_cbserter() function calls it to allocate a new pair for the * key pointed to by \a kptr of the length \a klen and the callback context * \a ctx. The second parameter \a pair is passed the pointer to the existing * pair for the key or #MOO_NULL in case of no existing key. The callback * must return a pointer to a new or a reallocated pair. When reallocating the - * existing pair, this callback must destroy the existing pair and return the + * existing pair, this callback must destroy the existing pair and return the * newly reallocated pair. It must return #MOO_NULL for failure. */ typedef moo_rbt_pair_t* (*moo_rbt_cbserter_t) ( @@ -173,10 +173,10 @@ enum moo_rbt_pair_color_t typedef enum moo_rbt_pair_color_t moo_rbt_pair_color_t; /** - * The moo_rbt_pair_t type defines red-black tree pair. A pair is composed - * of a key and a value. It maintains pointers to the beginning of a key and - * a value plus their length. The length is scaled down with the scale factor - * specified in an owning tree. Use macros defined in the + * The moo_rbt_pair_t type defines red-black tree pair. A pair is composed + * of a key and a value. It maintains pointers to the beginning of a key and + * a value plus their length. The length is scaled down with the scale factor + * specified in an owning tree. Use macros defined in the */ struct moo_rbt_pair_t { @@ -201,8 +201,8 @@ struct moo_rbt_pair_t typedef struct moo_rbt_style_t moo_rbt_style_t; /** - * The moo_rbt_style_t type defines callback function sets for key/value - * pair manipulation. + * The moo_rbt_style_t type defines callback function sets for key/value + * pair manipulation. */ struct moo_rbt_style_t { @@ -338,10 +338,10 @@ MOO_EXPORT const moo_rbt_style_t* moo_rbt_getstyle ( ); /** - * The moo_rbt_setstyle() function sets internal manipulation callback + * The moo_rbt_setstyle() function sets internal manipulation callback * functions for data construction, destruction, comparison, etc. * The callback structure pointed to by \a style must outlive the tree - * pointed to by \a htb as the tree doesn't copy the contents of the + * pointed to by \a htb as the tree doesn't copy the contents of the * structure. */ MOO_EXPORT void moo_rbt_setstyle ( @@ -357,10 +357,10 @@ MOO_EXPORT moo_oow_t moo_rbt_getsize ( ); /** - * The moo_rbt_search() function searches red-black tree to find a pair with a + * The moo_rbt_search() function searches red-black tree to find a pair with a * matching key. It returns the pointer to the pair found. If it fails * to find one, it returns MOO_NULL. - * \return pointer to the pair with a maching key, + * \return pointer to the pair with a maching key, * or MOO_NULL if no match is found. */ MOO_EXPORT moo_rbt_pair_t* moo_rbt_search ( @@ -370,12 +370,12 @@ MOO_EXPORT moo_rbt_pair_t* moo_rbt_search ( ); /** - * The moo_rbt_upsert() function searches red-black tree for the pair with a + * The moo_rbt_upsert() function searches red-black tree for the pair with a * matching key. If one is found, it updates the pair. Otherwise, it inserts - * a new pair with the key and the value given. It returns the pointer to the + * a new pair with the key and the value given. It returns the pointer to the * pair updated or inserted. - * \return a pointer to the updated or inserted pair on success, - * MOO_NULL on failure. + * \return a pointer to the updated or inserted pair on success, + * MOO_NULL on failure. */ MOO_EXPORT moo_rbt_pair_t* moo_rbt_upsert ( moo_rbt_t* rbt, /**< red-black tree */ @@ -387,9 +387,9 @@ MOO_EXPORT moo_rbt_pair_t* moo_rbt_upsert ( /** * The moo_rbt_ensert() function inserts a new pair with the key and the value - * given. If there exists a pair with the key given, the function returns + * given. If there exists a pair with the key given, the function returns * the pair containing the key. - * \return pointer to a pair on success, MOO_NULL on failure. + * \return pointer to a pair on success, MOO_NULL on failure. */ MOO_EXPORT moo_rbt_pair_t* moo_rbt_ensert ( moo_rbt_t* rbt, /**< red-black tree */ @@ -401,9 +401,9 @@ MOO_EXPORT moo_rbt_pair_t* moo_rbt_ensert ( /** * The moo_rbt_insert() function inserts a new pair with the key and the value - * given. If there exists a pair with the key given, the function returns + * given. If there exists a pair with the key given, the function returns * MOO_NULL without channging the value. - * \return pointer to the pair created on success, MOO_NULL on failure. + * \return pointer to the pair created on success, MOO_NULL on failure. */ MOO_EXPORT moo_rbt_pair_t* moo_rbt_insert ( moo_rbt_t* rbt, /**< red-black tree */ @@ -427,7 +427,7 @@ MOO_EXPORT moo_rbt_pair_t* moo_rbt_update ( ); /** - * The moo_rbt_cbsert() function inserts a key/value pair by delegating pair + * The moo_rbt_cbsert() function inserts a key/value pair by delegating pair * allocation to a callback function. Depending on the callback function, * it may behave like moo_rbt_insert(), moo_rbt_upsert(), moo_rbt_update(), * moo_rbt_ensert(), or totally differently. The sample code below inserts @@ -442,7 +442,7 @@ MOO_EXPORT moo_rbt_pair_t* moo_rbt_update ( * (int)MOO_RBT_VLEN(pair), MOO_RBT_VPTR(pair), (int)MOO_RBT_VLEN(pair)); * return MOO_RBT_WALK_FORWARD; * } - * + * * moo_rbt_pair_t* cbserter ( * moo_rbt_t* rbt, moo_rbt_pair_t* pair, * void* kptr, moo_oow_t klen, void* ctx) @@ -450,53 +450,53 @@ MOO_EXPORT moo_rbt_pair_t* moo_rbt_update ( * moo_cstr_t* v = (moo_cstr_t*)ctx; * if (pair == MOO_NULL) * { - * // no existing key for the key + * // no existing key for the key * return moo_rbt_allocpair (rbt, kptr, klen, v->ptr, v->len); * } * else * { - * // a pair with the key exists. - * // in this sample, i will append the new value to the old value + * // a pair with the key exists. + * // in this sample, i will append the new value to the old value * // separated by a comma * moo_rbt_pair_t* new_pair; * moo_ooch_t comma = MOO_T(','); * moo_oob_t* vptr; - * - * // allocate a new pair, but without filling the actual value. - * // note vptr is given MOO_NULL for that purpose + * + * // allocate a new pair, but without filling the actual value. + * // note vptr is given MOO_NULL for that purpose * new_pair = moo_rbt_allocpair ( - * rbt, kptr, klen, MOO_NULL, pair->vlen + 1 + v->len); + * rbt, kptr, klen, MOO_NULL, pair->vlen + 1 + v->len); * if (new_pair == MOO_NULL) return MOO_NULL; - * - * // fill in the value space + * + * // fill in the value space * vptr = new_pair->vptr; * moo_memcpy (vptr, pair->vptr, pair->vlen*MOO_SIZEOF(moo_ooch_t)); * vptr += pair->vlen*MOO_SIZEOF(moo_ooch_t); * moo_memcpy (vptr, &comma, MOO_SIZEOF(moo_ooch_t)); * vptr += MOO_SIZEOF(moo_ooch_t); * moo_memcpy (vptr, v->ptr, v->len*MOO_SIZEOF(moo_ooch_t)); - * - * // this callback requires the old pair to be destroyed + * + * // this callback requires the old pair to be destroyed * moo_rbt_freepair (rbt, pair); - * - * // return the new pair + * + * // return the new pair * return new_pair; * } * } - * + * * int main () * { * moo_rbt_t* s1; * int i; * moo_ooch_t* keys[] = { MOO_T("one"), MOO_T("two"), MOO_T("three") }; * moo_ooch_t* vals[] = { MOO_T("1"), MOO_T("2"), MOO_T("3"), MOO_T("4"), MOO_T("5") }; - * + * * s1 = moo_rbt_open ( * MOO_MMGR_GETDFL(), 0, * MOO_SIZEOF(moo_ooch_t), MOO_SIZEOF(moo_ooch_t) - * ); // note error check is skipped + * ); // note error check is skipped * moo_rbt_setstyle (s1, &style1); - * + * * for (i = 0; i < MOO_COUNTOF(vals); i++) * { * moo_cstr_t ctx; @@ -507,7 +507,7 @@ MOO_EXPORT moo_rbt_pair_t* moo_rbt_update ( * ); // note error check is skipped * } * moo_rbt_walk (s1, print_map_pair, MOO_NULL); - * + * * moo_rbt_close (s1); * return 0; * } @@ -522,7 +522,7 @@ MOO_EXPORT moo_rbt_pair_t* moo_rbt_cbsert ( ); /** - * The moo_rbt_delete() function deletes a pair with a matching key + * The moo_rbt_delete() function deletes a pair with a matching key * \return 0 on success, -1 on failure */ MOO_EXPORT int moo_rbt_delete ( @@ -539,7 +539,7 @@ MOO_EXPORT void moo_rbt_clear ( ); /** - * The moo_rbt_walk() function traverses a red-black tree in preorder + * The moo_rbt_walk() function traverses a red-black tree in preorder * from the leftmost child. */ MOO_EXPORT void moo_rbt_walk ( @@ -549,7 +549,7 @@ MOO_EXPORT void moo_rbt_walk ( ); /** - * The moo_rbt_walk() function traverses a red-black tree in preorder + * The moo_rbt_walk() function traverses a red-black tree in preorder * from the rightmost child. */ MOO_EXPORT void moo_rbt_rwalk ( @@ -559,11 +559,11 @@ MOO_EXPORT void moo_rbt_rwalk ( ); /** - * The moo_rbt_allocpair() function allocates a pair for a key and a value + * The moo_rbt_allocpair() function allocates a pair for a key and a value * given. But it does not chain the pair allocated into the red-black tree \a rbt. - * Use this function at your own risk. + * Use this function at your own risk. * - * Take note of he following special behavior when the copier is + * Take note of he following special behavior when the copier is * #MOO_RBT_COPIER_INLINE. * - If \a kptr is #MOO_NULL, the key space of the size \a klen is reserved but * not propagated with any data. @@ -572,7 +572,7 @@ MOO_EXPORT void moo_rbt_rwalk ( */ MOO_EXPORT moo_rbt_pair_t* moo_rbt_allocpair ( moo_rbt_t* rbt, - void* kptr, + void* kptr, moo_oow_t klen, void* vptr, moo_oow_t vlen @@ -596,7 +596,7 @@ MOO_EXPORT int moo_rbt_dflcomp ( const void* kptr1, moo_oow_t klen1, const void* kptr2, - moo_oow_t klen2 + moo_oow_t klen2 ); #if defined(__cplusplus) diff --git a/lib/moo-std.h b/lib/moo-std.h index a0e8b44..8c1e079 100644 --- a/lib/moo-std.h +++ b/lib/moo-std.h @@ -31,7 +31,7 @@ struct moo_cfgstd_t const moo_ooch_t* dbg; } opt; - struct + struct { const moo_bch_t* log; const moo_bch_t* dbg; @@ -101,7 +101,7 @@ MOO_EXPORT void moo_uncatch_termreq ( /* ----------------------------------------------------------------------- */ MOO_EXPORT moo_t* moo_openstd ( - moo_oow_t xtnsize, + moo_oow_t xtnsize, const moo_cfgstd_t* cfg, moo_errinf_t* errinfo ); @@ -118,12 +118,12 @@ MOO_EXPORT int moo_compilestd( ); MOO_EXPORT int moo_compilefileb ( - moo_t* moo, + moo_t* moo, const moo_bch_t* path ); MOO_EXPORT int moo_compilefileu ( - moo_t* moo, + moo_t* moo, const moo_uch_t* path ); diff --git a/lib/moo-utl.h b/lib/moo-utl.h index 0230b00..6a5afca 100644 --- a/lib/moo-utl.h +++ b/lib/moo-utl.h @@ -640,7 +640,7 @@ MOO_EXPORT moo_oow_t moo_count_bcstr_limited ( #define MOO_BYTE_TO_BCSTR_LOWERCASE MOO_BYTE_TO_OOCSTR_LOWERCASE moo_oow_t moo_byte_to_ucstr ( - moo_oob_t byte, + moo_oob_t byte, moo_uch_t* buf, moo_oow_t size, int flagged_radix, @@ -648,7 +648,7 @@ moo_oow_t moo_byte_to_ucstr ( ); moo_oow_t moo_byte_to_bcstr ( - moo_oob_t byte, + moo_oob_t byte, moo_bch_t* buf, moo_oow_t size, int flagged_radix, @@ -733,7 +733,7 @@ MOO_EXPORT moo_cmgr_t* moo_get_cmgr_by_ucstr ( /* ------------------------------------------------------------------------- */ /** - * The moo_conv_uchars_to_utf8() function converts a unicode character string \a ucs + * The moo_conv_uchars_to_utf8() function converts a unicode character string \a ucs * to a UTF8 string and writes it into the buffer pointed to by \a bcs, but * not more than \a bcslen bytes including the terminating null. * @@ -782,7 +782,7 @@ MOO_EXPORT int moo_conv_uchars_to_utf8 ( * n = moo_conv_utf8_to_uchars (bcs, &bcslen, ucs, &ucslen); * if (n <= -1) { invalid/incomplenete sequence or buffer to small } * \endcode - * + * * The resulting \a ucslen can still be greater than 0 even if the return * value is negative. The value indiates the number of characters converted * before the error has occurred. @@ -880,19 +880,19 @@ MOO_EXPORT int moo_conv_mb8_to_ucstr ( * TIME CALCULATION WITH OVERFLOW/UNDERFLOW DETECTION * ========================================================================= */ -/** +/** * The moo_add_ntime() function adds two time structures pointed to by \a x and \a y * and stores the result in the structure pointed to by \a z. If it detects overflow/ * underflow, it stores the largest/least possible value respectively. * You may use the MOO_ADD_NTIME() macro if overflow/underflow check isn't needed. */ MOO_EXPORT void moo_add_ntime ( - moo_ntime_t* z, + moo_ntime_t* z, const moo_ntime_t* x, const moo_ntime_t* y ); -/** +/** * The moo_sub_ntime() function subtracts the time value \a y from the time value \a x * and stores the result in the structure pointed to by \a z. If it detects overflow/ * underflow, it stores the largest/least possible value respectively. @@ -951,9 +951,9 @@ static MOO_INLINE moo_uint32_t moo_bswap32 (moo_uint32_t x) ); return x; #else - return ((x >> 24)) | - ((x >> 8) & ((moo_uint32_t)0xff << 8)) | - ((x << 8) & ((moo_uint32_t)0xff << 16)) | + return ((x >> 24)) | + ((x >> 8) & ((moo_uint32_t)0xff << 8)) | + ((x << 8) & ((moo_uint32_t)0xff << 16)) | ((x << 24)); #endif } @@ -971,13 +971,13 @@ static MOO_INLINE moo_uint64_t moo_bswap64 (moo_uint64_t x) __asm__ /*volatile*/ ("rev %0, %0" : "+r"(x)); return x; #else - return ((x >> 56)) | - ((x >> 40) & ((moo_uint64_t)0xff << 8)) | - ((x >> 24) & ((moo_uint64_t)0xff << 16)) | - ((x >> 8) & ((moo_uint64_t)0xff << 24)) | - ((x << 8) & ((moo_uint64_t)0xff << 32)) | - ((x << 24) & ((moo_uint64_t)0xff << 40)) | - ((x << 40) & ((moo_uint64_t)0xff << 48)) | + return ((x >> 56)) | + ((x >> 40) & ((moo_uint64_t)0xff << 8)) | + ((x >> 24) & ((moo_uint64_t)0xff << 16)) | + ((x >> 8) & ((moo_uint64_t)0xff << 24)) | + ((x << 8) & ((moo_uint64_t)0xff << 32)) | + ((x << 24) & ((moo_uint64_t)0xff << 40)) | + ((x << 40) & ((moo_uint64_t)0xff << 48)) | ((x << 56)); #endif } @@ -989,7 +989,7 @@ static MOO_INLINE moo_uint128_t moo_bswap128 (moo_uint128_t x) #if defined(MOO_HAVE_BUILTIN_BSWAP128) return __builtin_bswap128(x); #else - return ((x >> 120)) | + return ((x >> 120)) | ((x >> 104) & ((moo_uint128_t)0xff << 8)) | ((x >> 88) & ((moo_uint128_t)0xff << 16)) | ((x >> 72) & ((moo_uint128_t)0xff << 24)) | @@ -1014,7 +1014,7 @@ static MOO_INLINE moo_uint128_t moo_bswap128 (moo_uint128_t x) #if defined(MOO_HAVE_UINT16_T) # if defined(MOO_HAVE_BUILTIN_BSWAP16) # define moo_bswap16(x) ((moo_uint16_t)__builtin_bswap16((moo_uint16_t)(x))) -# else +# else # define moo_bswap16(x) ((moo_uint16_t)(((moo_uint16_t)(x)) << 8) | (((moo_uint16_t)(x)) >> 8)) # endif #endif @@ -1022,7 +1022,7 @@ static MOO_INLINE moo_uint128_t moo_bswap128 (moo_uint128_t x) #if defined(MOO_HAVE_UINT32_T) # if defined(MOO_HAVE_BUILTIN_BSWAP32) # define moo_bswap32(x) ((moo_uint32_t)__builtin_bswap32((moo_uint32_t)(x))) -# else +# else # define moo_bswap32(x) ((moo_uint32_t)(((((moo_uint32_t)(x)) >> 24)) | \ ((((moo_uint32_t)(x)) >> 8) & ((moo_uint32_t)0xff << 8)) | \ ((((moo_uint32_t)(x)) << 8) & ((moo_uint32_t)0xff << 16)) | \ @@ -1033,7 +1033,7 @@ static MOO_INLINE moo_uint128_t moo_bswap128 (moo_uint128_t x) #if defined(MOO_HAVE_UINT64_T) # if defined(MOO_HAVE_BUILTIN_BSWAP64) # define moo_bswap64(x) ((moo_uint64_t)__builtin_bswap64((moo_uint64_t)(x))) -# else +# else # define moo_bswap64(x) ((moo_uint64_t)(((((moo_uint64_t)(x)) >> 56)) | \ ((((moo_uint64_t)(x)) >> 40) & ((moo_uint64_t)0xff << 8)) | \ ((((moo_uint64_t)(x)) >> 24) & ((moo_uint64_t)0xff << 16)) | \ @@ -1048,7 +1048,7 @@ static MOO_INLINE moo_uint128_t moo_bswap128 (moo_uint128_t x) #if defined(MOO_HAVE_UINT128_T) # if defined(MOO_HAVE_BUILTIN_BSWAP128) # define moo_bswap128(x) ((moo_uint128_t)__builtin_bswap128((moo_uint128_t)(x))) -# else +# else # define moo_bswap128(x) ((moo_uint128_t)(((((moo_uint128_t)(x)) >> 120)) | \ ((((moo_uint128_t)(x)) >> 104) & ((moo_uint128_t)0xff << 8)) | \ ((((moo_uint128_t)(x)) >> 88) & ((moo_uint128_t)0xff << 16)) | \ @@ -1193,7 +1193,7 @@ static MOO_INLINE int moo_get_pos_of_msb_set_pow2 (moo_oow_t x) : "=r"(n) /* output */ : "r"(x) /* input */ ); - return (int)(MOO_OOW_BITS - n - 1); + return (int)(MOO_OOW_BITS - n - 1); /* TODO: PPC - use cntlz, cntlzw, cntlzd, SPARC - use lzcnt, MIPS clz */ #else int pos = 0; @@ -1227,7 +1227,7 @@ static MOO_INLINE int moo_get_pos_of_msb_set (moo_oow_t x) : "=r"(n) /* output */ : "r"(x) /* input */ ); - return (int)(MOO_OOW_BITS - n - 1); + return (int)(MOO_OOW_BITS - n - 1); /* TODO: PPC - use cntlz, cntlzw, cntlzd, SPARC - use lzcnt, MIPS clz */ #else int pos = 0; diff --git a/lib/moo.c b/lib/moo.c index ada6e5d..501dfdd 100644 --- a/lib/moo.c +++ b/lib/moo.c @@ -44,7 +44,7 @@ moo_t* moo_open (moo_mmgr_t* mmgr, moo_oow_t xtnsize, moo_cmgr_t* cmgr, const mo } else MOO_MEMSET (moo + 1, 0, xtnsize); } - else if (errinfo) + else if (errinfo) { errinfo->num = MOO_ESYSMEM; moo_copy_oocstr (errinfo->msg, MOO_COUNTOF(errinfo->msg), moo_errnum_to_errstr(MOO_ESYSMEM)); @@ -132,7 +132,7 @@ int moo_init (moo_t* moo, moo_mmgr_t* mmgr, moo_cmgr_t* cmgr, const moo_vmprim_t * routine still function despite some side-effects when * reallocation fails */ /* +1 required for consistency with put_oocs and put_ooch in fmtout.c */ - moo->log.ptr = moo_allocmem(moo, (moo->log.capa + 1) * MOO_SIZEOF(*moo->log.ptr)); + moo->log.ptr = moo_allocmem(moo, (moo->log.capa + 1) * MOO_SIZEOF(*moo->log.ptr)); if (MOO_UNLIKELY(!moo->log.ptr)) goto oops; #if defined(MOO_ENABLE_GC_MARK_SWEEP) @@ -161,13 +161,13 @@ int moo_init (moo_t* moo, moo_mmgr_t* mmgr, moo_cmgr_t* cmgr, const moo_vmprim_t oops: if (modtab_inited) moo_rbt_fini (&moo->modtab); #if defined(MOO_ENABLE_GC_MARK_SWEEP) - if (moo->gci.stack.ptr) + if (moo->gci.stack.ptr) { moo_freemem (moo, moo->gci.stack.ptr); moo->gci.stack.capa = 0; } #endif - if (moo->log.ptr) + if (moo->log.ptr) { moo_freemem (moo, moo->log.ptr); moo->log.capa = 0; @@ -212,7 +212,7 @@ void moo_fini (moo_t* moo) if (moo->log.len > 0) { - /* flush pending log message that could be generated by the fini + /* flush pending log message that could be generated by the fini * callbacks. however, the actual logging might not be produced at * this point because one of the callbacks could arrange to stop * logging */ @@ -305,7 +305,7 @@ void moo_fini (moo_t* moo) } } - if (moo->log.ptr) + if (moo->log.ptr) { moo_freemem (moo, moo->log.ptr); moo->log.capa = 0; @@ -319,7 +319,7 @@ void moo_fini (moo_t* moo) moo->inttostr.xbuf.capa = 0; moo->inttostr.xbuf.len = 0; } - + if (moo->inttostr.t.ptr) { moo_freemem (moo, moo->inttostr.t.ptr); @@ -531,7 +531,7 @@ static struct const moo_bch_t* modname; int (*modload) (moo_t* moo, moo_mod_t* mod); } -static_modtab[] = +static_modtab[] = { #if defined(MOO_ENABLE_MOD_CON) { "con", moo_mod_con }, @@ -563,17 +563,17 @@ moo_mod_data_t* moo_openmod (moo_t* moo, const moo_ooch_t* name, moo_oow_t namel int n; #endif - /* maximum module name length is MOO_MOD_NAME_LEN_MAX. + /* maximum module name length is MOO_MOD_NAME_LEN_MAX. * MOD_PREFIX_LEN for MOD_PREFIX * 1 for _ at the end when moo_mod_xxx_ is attempted. * 1 for the terminating '\0'. */ - moo_ooch_t buf[MOD_PREFIX_LEN + MOO_MOD_NAME_LEN_MAX + 1 + 1]; + moo_ooch_t buf[MOD_PREFIX_LEN + MOO_MOD_NAME_LEN_MAX + 1 + 1]; /* copy instead of encoding conversion. MOD_PREFIX must not * include a character that requires encoding conversion. * note the terminating null isn't needed in buf here. */ - moo_copy_bchars_to_oochars (buf, MOD_PREFIX, MOD_PREFIX_LEN); + moo_copy_bchars_to_oochars (buf, MOD_PREFIX, MOD_PREFIX_LEN); if (namelen > MOO_COUNTOF(buf) - (MOD_PREFIX_LEN + 1 + 1)) { @@ -591,7 +591,7 @@ moo_mod_data_t* moo_openmod (moo_t* moo, const moo_ooch_t* name, moo_oow_t namel /* TODO: binary search ... */ for (n = 0; n < MOO_COUNTOF(static_modtab); n++) { - if (moo_comp_oochars_bcstr(name, namelen, static_modtab[n].modname) == 0) + if (moo_comp_oochars_bcstr(name, namelen, static_modtab[n].modname) == 0) { load = static_modtab[n].modload; break; @@ -655,7 +655,7 @@ moo_mod_data_t* moo_openmod (moo_t* moo, const moo_ooch_t* name, moo_oow_t namel md.handle = moo->vmprim.dl_open(moo, &buf[MOD_PREFIX_LEN], MOO_VMPRIM_DLOPEN_PFMOD); } - if (md.handle == MOO_NULL) + if (md.handle == MOO_NULL) { MOO_DEBUG2 (moo, "Cannot open a module [%.*js]\n", namelen, name); moo_seterrbfmt (moo, MOO_ENOENT, "unable to open a module [%.*js]", namelen, name); @@ -664,7 +664,7 @@ moo_mod_data_t* moo_openmod (moo_t* moo, const moo_ooch_t* name, moo_oow_t namel /* attempt to get moo_mod_xxx where xxx is the module name*/ load = moo->vmprim.dl_getsym(moo, md.handle, buf); - if (!load) + if (!load) { moo_seterrbfmt (moo, moo_geterrnum(moo), "unable to get module symbol [%js] in [%.*js]", buf, namelen, name); MOO_DEBUG3 (moo, "Cannot get a module symbol [%js] in [%.*js]\n", buf, namelen, name); @@ -689,7 +689,7 @@ moo_mod_data_t* moo_openmod (moo_t* moo, const moo_ooch_t* name, moo_oow_t namel if (load(moo, &mdp->mod) <= -1) { const moo_ooch_t* oldmsg = moo_backuperrmsg (moo); - moo_seterrbfmt (moo, moo_geterrnum(moo), "module initializer [%js] returned failure in [%.*js] - %js", buf, namelen, name, oldmsg); + moo_seterrbfmt (moo, moo_geterrnum(moo), "module initializer [%js] returned failure in [%.*js] - %js", buf, namelen, name, oldmsg); MOO_DEBUG3 (moo, "Module function [%js] returned failure in [%.*js]\n", buf, namelen, name); moo_rbt_delete (&moo->modtab, name, namelen); moo->vmprim.dl_close (moo, mdp->handle); @@ -710,7 +710,7 @@ void moo_closemod (moo_t* moo, moo_mod_data_t* mdp) { if (mdp->mod.unload) mdp->mod.unload (moo, &mdp->mod); - if (mdp->handle) + if (mdp->handle) { moo->vmprim.dl_close (moo, mdp->handle); MOO_DEBUG2 (moo, "Closed a module [%js] - %p\n", mdp->mod.name, mdp->handle); @@ -735,7 +735,7 @@ int moo_importmod (moo_t* moo, moo_oop_class_t _class, const moo_ooch_t* name, m int r = -1; /* moo_openmod(), moo_closemod(), etc call a user-defined callback. - * i need to protect _class in case the user-defined callback allocates + * i need to protect _class in case the user-defined callback allocates * a OOP memory chunk and GC occurs. */ moo_pushvolat (moo, (moo_oop_t*)&_class); @@ -772,7 +772,7 @@ int moo_importmod (moo_t* moo, moo_oop_class_t _class, const moo_ooch_t* name, m done: /* close the module opened above. * [NOTE] if the import callback calls the moo_querymodpf(), the returned - * function pointers will get all invalidated here. so never do + * function pointers will get all invalidated here. so never do * anything like that */ moo_closemod (moo, mdp); @@ -803,7 +803,7 @@ static void* query_mod (moo_t* moo, const moo_ooch_t* pid, moo_oow_t pidlen, moo sep = moo_rfind_oochar(pid, pidlen, '.'); if (!sep) { - /* i'm writing a conservative code here. the compiler should + /* i'm writing a conservative code here. the compiler should * guarantee that a period is included in an primitive function identifer. * what if the compiler is broken? imagine a buggy compiler rewritten * in moo itself? */ @@ -837,7 +837,7 @@ static void* query_mod (moo_t* moo, const moo_ooch_t* pid, moo_oow_t pidlen, moo { /* the primitive function is not found. but keep the module open even if it's opened above */ MOO_DEBUG4 (moo, "Cannot find a primitive %hs [%.*js] in a module [%js]\n", tags[pv], pidlen - mod_name_len - 1, sep + 1, mdp->mod.name); - moo_seterrbfmt (moo, MOO_ENOENT, "unable to find a primitive %hs [%.*js] in a module [%js]", tags[pv], pidlen - mod_name_len - 1, sep + 1, mdp->mod.name); + moo_seterrbfmt (moo, MOO_ENOENT, "unable to find a primitive %hs [%.*js] in a module [%js]", tags[pv], pidlen - mod_name_len - 1, sep + 1, mdp->mod.name); return MOO_NULL; } @@ -883,7 +883,7 @@ int moo_genpfmethod (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class, moo_met for (i = 0; mthname[i]; i++) { - if (mthname[i] == ':') + if (mthname[i] == ':') { if (variadic) goto oops_inval; arg_count++; @@ -892,7 +892,7 @@ int moo_genpfmethod (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class, moo_met /* TODO: check if name is a valid method name - more checks... */ /* TOOD: if the method name is a binary selector, it can still have an argument.. so the check below is invalid... */ - if (arg_count > 0 && mthname[i - 1] != ':') + if (arg_count > 0 && mthname[i - 1] != ':') { oops_inval: MOO_DEBUG2 (moo, "Cannot generate primitive function method [%js] in [%O] - invalid name\n", mthname, _class->name); @@ -917,7 +917,7 @@ int moo_genpfmethod (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class, moo_met * pfid => mod->name + '.' + pfname */ if (moo_copyoocstrtosbuf(moo, mod->name, MOO_SBUF_ID_TMP) <= -1 || moo_concatoocstrtosbuf(moo, dot, MOO_SBUF_ID_TMP) <= -1 || - moo_concatoocstrtosbuf(moo, pfname, MOO_SBUF_ID_TMP) <= -1) + moo_concatoocstrtosbuf(moo, pfname, MOO_SBUF_ID_TMP) <= -1) { MOO_DEBUG2 (moo, "Cannot generate primitive function method [%js] in [%O] - VM memory shortage\n", mthname, _class->name); return -1; @@ -931,7 +931,7 @@ int moo_genpfmethod (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class, moo_met } moo_pushvolat (moo, (moo_oop_t*)&pfidsym); tmp_count++; - mth = (moo_oop_method_t)moo_instantiatewithtrailer(moo, moo->_method, 1, MOO_NULL, 0); + mth = (moo_oop_method_t)moo_instantiatewithtrailer(moo, moo->_method, 1, MOO_NULL, 0); if (MOO_UNLIKELY(!mth)) { MOO_DEBUG2 (moo, "Cannot generate primitive function method [%js] in [%O] - method instantiation failure\n", mthname, _class->name); @@ -953,7 +953,7 @@ int moo_genpfmethod (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class, moo_met /* TODO: emit BCODE_RETURN_NIL as a fallback or self primitiveFailed? or anything else?? */ - if (!moo_putatdic (moo, _class->mthdic[type], (moo_oop_t)mnsym, (moo_oop_t)mth)) + if (!moo_putatdic (moo, _class->mthdic[type], (moo_oop_t)mnsym, (moo_oop_t)mth)) { MOO_DEBUG2 (moo, "Cannot generate primitive function method [%js] in [%O] - failed to add to method dictionary\n", mthname, _class->name); goto oops; @@ -977,7 +977,7 @@ int moo_genpfmethods (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class, const moo_pushvolat (moo, (moo_oop_t*)&_class); for (i = 0; i < pfcount; i++) { - if (moo_genpfmethod (moo, mod, _class, pfinfo[i].type, pfinfo[i].mthname, pfinfo[i].variadic, MOO_NULL) <= -1) + if (moo_genpfmethod (moo, mod, _class, pfinfo[i].type, pfinfo[i].mthname, pfinfo[i].variadic, MOO_NULL) <= -1) { /* TODO: delete pfmethod generated??? */ ret = -1; @@ -1069,12 +1069,12 @@ int moo_setclasstrsize (moo_t* moo, moo_oop_class_t _class, moo_oow_t size, moo_ trgc, MOO_OBJ_GET_SIZE(_class->name), MOO_OBJ_GET_CHAR_SLOT(_class->name)); return -1; } - - if (_class == moo->_method) + + if (_class == moo->_method) { /* the bytes code emitted by the compiler go to the trailer part * regardless of the trailer size. you're not allowed to change it */ - moo_seterrbfmt (moo, MOO_EPERM, "not allowed to set trailer size to %zu on the %.*js class", + moo_seterrbfmt (moo, MOO_EPERM, "not allowed to set trailer size to %zu on the %.*js class", size, MOO_OBJ_GET_SIZE(_class->name), MOO_OBJ_GET_CHAR_SLOT(_class->name)); return -1; } @@ -1082,7 +1082,7 @@ int moo_setclasstrsize (moo_t* moo, moo_oop_class_t _class, moo_oow_t size, moo_ spec = MOO_OOP_TO_SMOOI(_class->spec); if (MOO_CLASS_SPEC_IS_INDEXED(spec) && MOO_CLASS_SPEC_INDEXED_TYPE(spec) != MOO_OBJ_TYPE_OOP) { - moo_seterrbfmt (moo, MOO_EPERM, "not allowed to set trailer size to %zu on the non-pointer class %.*js", + moo_seterrbfmt (moo, MOO_EPERM, "not allowed to set trailer size to %zu on the non-pointer class %.*js", size, MOO_OBJ_GET_SIZE(_class->name), MOO_OBJ_GET_CHAR_SLOT(_class->name)); return -1; } @@ -1090,7 +1090,7 @@ int moo_setclasstrsize (moo_t* moo, moo_oop_class_t _class, moo_oow_t size, moo_ if (_class->trsize != moo->_nil) { MOO_ASSERT (moo, _class->trgc != moo->_nil); - moo_seterrbfmt (moo, MOO_EPERM, "not allowed to double-set trailer size to %zu on the %.*js class", + moo_seterrbfmt (moo, MOO_EPERM, "not allowed to double-set trailer size to %zu on the %.*js class", size, MOO_OBJ_GET_SIZE(_class->name), MOO_OBJ_GET_CHAR_SLOT(_class->name)); return -1; } @@ -1109,7 +1109,7 @@ int moo_setclasstrsize (moo_t* moo, moo_oop_class_t _class, moo_oow_t size, moo_ _class->trsize = MOO_SMOOI_TO_OOP(size); _class->trgc = MOO_SMPTR_TO_OOP(trgc); /* i don't replace NULL by nil for GC safety. */ - MOO_DEBUG5 (moo, "Set trailer size to %zu on the %.*js class with gc callback of %p(%p)\n", + MOO_DEBUG5 (moo, "Set trailer size to %zu on the %.*js class with gc callback of %p(%p)\n", size, MOO_OBJ_GET_SIZE(_class->name), MOO_OBJ_GET_CHAR_SLOT(_class->name), @@ -1133,7 +1133,7 @@ moo_oop_t moo_findclass (moo_t* moo, moo_oop_nsdic_t nsdic, const moo_ooch_t* na n.len = moo_count_oocstr(name); ass = moo_lookupdic_noseterr(moo, (moo_oop_dic_t)nsdic, &n); - if (!ass || MOO_CLASSOF(moo,ass->value) != moo->_class) + if (!ass || MOO_CLASSOF(moo,ass->value) != moo->_class) { moo_seterrnum (moo, MOO_ENOENT); return MOO_NULL; @@ -1149,14 +1149,14 @@ int moo_iskindof (moo_t* moo, moo_oop_t obj, moo_oop_class_t _class) MOO_ASSERT (moo, MOO_CLASSOF(moo,_class) == moo->_class); c = MOO_CLASSOF(moo,obj); /* c := self class */ - if (c == moo->_class) + if (c == moo->_class) { /* object is a class */ if (_class == moo->_class) return 1; /* obj isKindOf: Class */ } else { - if (c == _class) return 1; + if (c == _class) return 1; } c = (moo_oop_class_t)c->superclass; diff --git a/lib/moo.h b/lib/moo.h index c425127..25e810d 100644 --- a/lib/moo.h +++ b/lib/moo.h @@ -60,7 +60,7 @@ enum moo_errnum_t MOO_EINVAL, /**< invalid parameter or data */ MOO_ENOENT, /**< data not found */ MOO_EEXIST, /**< existing/duplicate data */ - MOO_EBUSY, /**< system busy */ + MOO_EBUSY, /**< system busy */ MOO_EACCES, /**< access denied */ MOO_EPERM, /**< operation not permitted */ MOO_ENOTDIR, /**< not directory */ @@ -126,7 +126,7 @@ enum moo_trait_t MOO_TRAIT_DEBUG_GC = (1u << 0), MOO_TRAIT_DEBUG_BIGINT = (1u << 1), - /* perform no garbage collection when the heap is full. + /* perform no garbage collection when the heap is full. * you still can use moo_gc() explicitly. */ MOO_TRAIT_NOGC = (1u << 8), @@ -174,7 +174,7 @@ typedef struct moo_obj_word_t* moo_oop_word_t; # define MOO_SIZEOF_LIW_T MOO_SIZEOF_OOW_T # define MOO_SIZEOF_LIDW_T MOO_SIZEOF_UINTMAX_T # define MOO_LIW_BITS MOO_OOW_BITS -# define MOO_LIDW_BITS (MOO_SIZEOF_UINTMAX_T * MOO_BITS_PER_BYTE) +# define MOO_LIDW_BITS (MOO_SIZEOF_UINTMAX_T * MOO_BITS_PER_BYTE) typedef moo_oop_word_t moo_oop_liword_t; # define MOO_OBJ_TYPE_LIWORD MOO_OBJ_TYPE_WORD @@ -246,7 +246,7 @@ enum moo_obj_type_t */ /* [NOTE] you can have MOO_OBJ_SHORT, MOO_OBJ_INT - * MOO_OBJ_LONG, MOO_OBJ_FLOAT, MOO_OBJ_DOUBLE, etc + * MOO_OBJ_LONG, MOO_OBJ_FLOAT, MOO_OBJ_DOUBLE, etc * type type field being 6 bits long, you can have up to 64 different types. MOO_OBJ_TYPE_SHORT, @@ -267,15 +267,15 @@ enum moo_gcfin_t typedef enum moo_gcfin_t moo_gcfin_t; /* ========================================================================= - * Object header structure - * + * Object header structure + * * _flags: - * type: the type of a payload item. - * one of MOO_OBJ_TYPE_OOP, MOO_OBJ_TYPE_CHAR, + * type: the type of a payload item. + * one of MOO_OBJ_TYPE_OOP, MOO_OBJ_TYPE_CHAR, * MOO_OBJ_TYPE_BYTE, MOO_OBJ_TYPE_HALFWORD, MOO_OBJ_TYPE_WORD - * unit: the size of a payload item in bytes. + * unit: the size of a payload item in bytes. * extra: 0 or 1. 1 indicates that the payload contains 1 more - * item than the value of the size field. used for a + * item than the value of the size field. used for a * terminating null in a variable-character object. internel * use only. * kernel: 0, 1, or 2. indicates that the object is a kernel object. @@ -291,27 +291,27 @@ typedef enum moo_gcfin_t moo_gcfin_t; * * _size: the number of payload items in an object. * it doesn't include the header size. - * + * * The total number of bytes occupied by an object can be calculated * with this fomula: * sizeof(moo_obj_t) + ALIGN((size + extra) * unit), sizeof(moo_oop_t)) - * - * If the type is known to be not MOO_OBJ_TYPE_CHAR, you can assume that + * + * If the type is known to be not MOO_OBJ_TYPE_CHAR, you can assume that * 'extra' is 0. So you can simplify the fomula in such a context. * sizeof(moo_obj_t) + ALIGN(size * unit), sizeof(moo_oop_t)) * * The ALIGN() macro is used above since allocation adjusts the payload * size to a multiple of sizeof(moo_oop_t). it assumes that sizeof(moo_obj_t) * is a multiple of sizeof(moo_oop_t). See the MOO_BYTESOF() macro. - * + * * Due to the header structure, an object can only contain items of - * homogeneous data types in the payload. + * homogeneous data types in the payload. * * It's actually possible to split the size field into 2. For example, * the upper half contains the number of oops and the lower half contains * the number of bytes/chars. This way, a variable-byte class or a variable-char * class can have normal instance variables. On the contrary, the actual byte - * size calculation and the access to the payload fields become more complex. + * size calculation and the access to the payload fields become more complex. * Therefore, i've dropped the idea. * ========================================================================= */ #define MOO_OBJ_FLAGS_TYPE_BITS 6 @@ -383,7 +383,7 @@ typedef enum moo_gcfin_t moo_gcfin_t; /* [NOTE] this macro doesn't check the range of the actual value. - * make sure that the value of each bit fields given falls within the + * make sure that the value of each bit fields given falls within the * possible range of the defined bits */ #define MOO_OBJ_MAKE_FLAGS(_ty,_u,_e,_k,_p,_m,_g,_tr,_h,_uncp) ( \ (((moo_oow_t)(_ty)) << MOO_OBJ_FLAGS_TYPE_SHIFT) | \ @@ -527,7 +527,7 @@ struct moo_nsdic_t moo_oop_t nsup; /* a class if it belongs to the class. another nsdic if it doesn't */ }; -struct moo_methowner_t +struct moo_methowner_t { /* a method can be owned by a class or an interface. * this structure defines common fields between a class and an interface and @@ -539,7 +539,7 @@ struct moo_methowner_t /* [0] - instance methods, MethodDictionary * [1] - class methods, MethodDictionary */ - moo_oop_dic_t mthdic[2]; + moo_oop_dic_t mthdic[2]; moo_oop_nsdic_t nsup; /* pointer to the upper namespace */ moo_oop_nsdic_t nsdic; /* dictionary used for namespacing - may be nil when there are no subitems underneath */ @@ -555,7 +555,7 @@ struct moo_interface_t /* [0] - instance methods, MethodDictionary * [1] - class methods, MethodDictionary */ - moo_oop_dic_t mthdic[2]; + moo_oop_dic_t mthdic[2]; moo_oop_nsdic_t nsup; /* pointer to the upper namespace */ moo_oop_nsdic_t nsdic; /* dictionary used for namespacing - may be nil when there are no subitems underneath */ @@ -571,7 +571,7 @@ struct moo_class_t /* [0] - instance methods, MethodDictionary * [1] - class methods, MethodDictionary */ - moo_oop_dic_t mthdic[2]; + moo_oop_dic_t mthdic[2]; moo_oop_nsdic_t nsup; /* pointer to the upper namespace */ moo_oop_nsdic_t nsdic; /* dictionary used for namespacing - may be nil when there are no subitems underneath */ @@ -596,9 +596,9 @@ struct moo_class_t moo_oop_t trsize; /* trailer size for new instances */ moo_oop_t trgc; /* trailer gc callback */ - /* [0] - initial values for instance variables of new instances + /* [0] - initial values for instance variables of new instances * [1] - initial values for class instance variables */ - moo_oop_t initv[2]; + moo_oop_t initv[2]; /* indexed part afterwards */ moo_oop_t cvar[1]; /* class instance variables and class variables. */ @@ -662,10 +662,10 @@ struct moo_method_t * the code bytes are placed after the trailer size. * * code bytes -> ((moo_oob_t*)&((moo_oop_oop_t)m)->slot[MOO_OBJ_GET_SIZE(m) + 1]) or - * ((moo_oob_t*)&((moo_oop_method_t)m)->literal_frame[MOO_OBJ_GET_SIZE(m) + 1 - MOO_METHOD_NAMED_INSTVARS]) + * ((moo_oob_t*)&((moo_oop_method_t)m)->literal_frame[MOO_OBJ_GET_SIZE(m) + 1 - MOO_METHOD_NAMED_INSTVARS]) * size -> ((moo_oow_t)((moo_oop_oop_t)m)->slot[MOO_OBJ_GET_SIZE(m)])*/ #define MOO_METHOD_GET_CODE_BYTE(m) MOO_OBJ_GET_TRAILER_BYTE(m) -#define MOO_METHOD_GET_CODE_SIZE(m) MOO_OBJ_GET_TRAILER_SIZE(m) +#define MOO_METHOD_GET_CODE_SIZE(m) MOO_OBJ_GET_TRAILER_SIZE(m) /* The preamble field is composed of: @@ -680,11 +680,11 @@ struct moo_method_t * 3 - return thisProcess * 4 - return nil * 5 - return true - * 6 - return false + * 6 - return false * 7 - return index. * 8 - return -index. * 9 - return selfns - * 10 - return instvar[index] + * 10 - return instvar[index] * 11 - do primitive[index] * 12 - do named primitive[index] * 13 - exception handler @@ -749,7 +749,7 @@ struct moo_context_t /* SmallInteger, stack pointer. the actual stack pointer is in the active * process. For a method context, it stores the stack pointer of the active - * process before it gets activated. the stack pointer of the active + * process before it gets activated. the stack pointer of the active * process is restored using this value upon returning. This field is * almost useless for a block context. */ moo_oop_t sp; @@ -759,20 +759,20 @@ struct moo_context_t * defined its 'home'. */ moo_oop_t ntmprs; - /* CompiledMethod for a method context, + /* CompiledMethod for a method context, * SmallInteger for a block context */ moo_oop_t method_or_nargs; /* it points to the receiver of the message for a method context. - * a base block context(created but not yet activated) has nil in this - * field. if a block context is activated by 'value', it points + * a base block context(created but not yet activated) has nil in this + * field. if a block context is activated by 'value', it points * to the block context object used as a base for shallow-copy. */ moo_oop_t receiver_or_base; /* it is set to nil for a method context. - * for a block context, it points to the active context at the - * moment the block context was created. that is, it points to - * a method context where the base block has been defined. + * for a block context, it points to the active context at the + * moment the block context was created. that is, it points to + * a method context where the base block has been defined. * an activated block context copies this field from the base block context. */ moo_oop_t home; @@ -782,14 +782,14 @@ struct moo_context_t * created within the block context also points to the same method context. * ctx->origin: method context * ctx->origin->method_or_nargs: actual method containing byte codes pertaining to ctx. - * + * * when a method context is created, it is set to itself. no change is - * made when the method context is activated. when a base block context is + * made when the method context is activated. when a base block context is * created (when MAKE_BLOCK is executed), it is set to the * origin of the active context. when the base block context is shallow-copied * for activation (when it is sent 'value'), it is set to the origin of * the base block context. */ - moo_oop_context_t origin; + moo_oop_context_t origin; /* variable indexed part - actual arguments and temporaries are placed here */ moo_oop_t stack[1]; /* context stack that stores arguments and temporaries */ @@ -889,13 +889,13 @@ struct moo_semaphore_t moo_oop_t count; /* SmallInteger */ - /* nil for normal. SmallInteger if associated with + /* nil for normal. SmallInteger if associated with * timer(MOO_SEMAPHORE_SUBTYPE_TIMED) or IO(MOO_SEMAPHORE_SUBTYPE_IO). */ - moo_oop_t subtype; + moo_oop_t subtype; union { - struct + struct { moo_oop_t index; /* index to the heap that stores timed semaphores */ moo_oop_t ftime_sec; /* firing time */ @@ -932,7 +932,7 @@ struct moo_semaphore_group_t struct { moo_oop_process_t first; - moo_oop_process_t last; + moo_oop_process_t last; } waiting; /* list of processes waiting on this semaphore group */ /* [END IMPORTANT] */ @@ -990,7 +990,7 @@ struct moo_fpdec_t /** * The MOO_BYTESOF() macro returns the size of the payload of - * an object in bytes. If the pointer given encodes a numeric value, + * an object in bytes. If the pointer given encodes a numeric value, * it returns the size of #moo_oow_t in bytes. */ #define MOO_BYTESOF(moo,oop) \ @@ -1175,7 +1175,7 @@ typedef enum moo_log_mask_t moo_log_mask_t; * ========================================================================= */ typedef void* (*moo_alloc_heap_t) ( - moo_t* moo, + moo_t* moo, moo_oow_t* size ); @@ -1491,7 +1491,7 @@ struct moo_mod_t void* ctx; }; -struct moo_mod_data_t +struct moo_mod_data_t { void* handle; moo_rbt_pair_t* pair; /* internal backreference to moo->modtab */ @@ -1599,13 +1599,13 @@ struct moo_t moo_oow_t log_maxcapa; moo_oow_t dfl_symtab_size; moo_oow_t dfl_sysdic_size; - moo_oow_t dfl_procstk_size; + moo_oow_t dfl_procstk_size; void* mod_inctx; #if defined(MOO_BUILD_DEBUG) /* set automatically when trait is set */ - moo_oow_t karatsuba_cutoff; + moo_oow_t karatsuba_cutoff; #endif } option; @@ -1636,8 +1636,8 @@ struct moo_t moo_oop_t _false; /* ============================================================= - * KERNEL CLASSES - * Be sure to Keep these kernel class pointers registered in the + * KERNEL CLASSES + * Be sure to Keep these kernel class pointers registered in the * kernel_classes table in gc.c * ============================================================= */ moo_oop_class_t _apex; /* Apex */ @@ -1682,7 +1682,7 @@ struct moo_t moo_oop_class_t _large_pointer; moo_oop_class_t _system; /* ============================================================= - * END KERNEL CLASSES + * END KERNEL CLASSES * ============================================================= */ /* ============================================================= @@ -1691,7 +1691,7 @@ struct moo_t /* 2 tag bits(lo) + 2 extended tag bits(hi). not all slots are used * because the 2 high extended bits are used only if the low tag bits * are 3 */ - moo_oop_class_t* tagged_classes[16]; + moo_oop_class_t* tagged_classes[16]; moo_oop_dic_t symtab; /* system-wide symbol table. instance of SymbolSet */ moo_oop_nsdic_t sysdic; /* system dictionary. instance of Namespace */ @@ -1708,7 +1708,7 @@ struct moo_t moo_oow_t sem_list_count; moo_oow_t sem_list_capa; - /* semaphores sorted according to time-out. + /* semaphores sorted according to time-out. * organize entries using heap as the earliest entry * needs to be checked first */ moo_oop_semaphore_t* sem_heap; @@ -1809,7 +1809,7 @@ struct moo_t moo_method_cache_item_t method_cache[2][MOO_METHOD_CACHE_SIZE]; moo_ooi_t last_inst_pointer; - struct + struct { moo_oow_t method_cache_hits; moo_oow_t method_cache_misses; @@ -1890,7 +1890,7 @@ struct moo_t /* get the receiver of a message */ #define MOO_STACK_GETRCV(moo,nargs) MOO_STACK_GET(moo, (moo)->sp - nargs) -/* you can't access arguments and receiver after these macros. +/* you can't access arguments and receiver after these macros. * also you must not call this macro more than once */ #define MOO_STACK_SETRET(moo,nargs,retv) \ do { \ @@ -1945,15 +1945,15 @@ typedef enum moo_ioarg_flag_t moo_ioarg_flag_t; */ typedef struct moo_ioarg_t moo_ioarg_t; struct moo_ioarg_t { - /** + /** * [IN] I/O object name. * It is #MOO_NULL for the main stream and points to a non-NULL string * for an included stream. */ const moo_ooch_t* name; - /** - * [OUT] I/O handle set by an open handler. + /** + * [OUT] I/O handle set by an open handler. * [IN] I/O handle referenced in read and close handler. * The source stream handler can set this field when it opens a stream. * All subsequent operations on the stream see this field as set @@ -1962,7 +1962,7 @@ struct moo_ioarg_t void* handle; /** - * [OUT] place data here + * [OUT] place data here */ moo_ooch_t buf[MOO_IOBUF_CAPA]; @@ -2139,7 +2139,7 @@ static MOO_INLINE moo_errnum_t moo_geterrnum (moo_t* moo) { return moo->errnum; #endif MOO_EXPORT void moo_seterrnum ( - moo_t* moo, + moo_t* moo, moo_errnum_t errnum ); @@ -2209,7 +2209,7 @@ MOO_EXPORT int moo_getoption ( ); /** - * The moo_setoption() function sets the value of an option + * The moo_setoption() function sets the value of an option * specified by \a id to the value pointed to by \a value. * * \return 0 on success, -1 on failure @@ -2251,15 +2251,15 @@ MOO_EXPORT moo_oop_t moo_updateoopforgc ( ); /** - * The moo_instantiate() function creates a new object instance of the class + * The moo_instantiate() function creates a new object instance of the class * \a _class. The size of the fixed part is taken from the information * contained in the class defintion. The \a vlen parameter specifies the length * of the variable part. The \a vptr parameter points to the memory area to * copy into the variable part of the new object. If \a vptr is #MOO_NULL, * the variable part is initialized to 0 or an equivalent value depending - * on the type. \a vptr is not used when the new instance is of the + * on the type. \a vptr is not used when the new instance is of the * #MOO_OBJ_TYPE_OOP type. - * + * */ MOO_EXPORT moo_oop_t moo_instantiate ( moo_t* moo, @@ -2269,7 +2269,7 @@ MOO_EXPORT moo_oop_t moo_instantiate ( ); MOO_EXPORT moo_oop_t moo_instantiatewithtrailer ( - moo_t* moo, + moo_t* moo, moo_oop_class_t _class, moo_oow_t vlen, const moo_oob_t* trptr, @@ -2308,7 +2308,7 @@ MOO_EXPORT int moo_invoke ( /** - * The moo_abort() function requests to stop on-going execution. + * The moo_abort() function requests to stop on-going execution. * On-going execution doesn't get terminated immediately when this function * returns. Termination of execution is honored by the virtual machine. * If the virtual machine is in a blocking context, termination will only @@ -2352,14 +2352,14 @@ MOO_EXPORT moo_oop_t moo_makesymbol ( ); MOO_EXPORT moo_oop_t moo_makestringwithuchars ( - moo_t* moo, - const moo_uch_t* ptr, + moo_t* moo, + const moo_uch_t* ptr, moo_oow_t len ); MOO_EXPORT moo_oop_t moo_makestringwithbchars ( - moo_t* moo, - const moo_bch_t* ptr, + moo_t* moo, + const moo_bch_t* ptr, moo_oow_t len ); @@ -2610,7 +2610,7 @@ MOO_EXPORT int moo_convutobchars ( /** - * The moo_convbtoucstr() function converts a null-terminated byte string + * The moo_convbtoucstr() function converts a null-terminated byte string * to a wide string. */ MOO_EXPORT int moo_convbtoucstr ( @@ -2817,7 +2817,7 @@ MOO_EXPORT moo_ooi_t moo_logufmtv ( const moo_uch_t* fmt, va_list ap ); - + #if defined(MOO_OOCH_IS_UCH) # define moo_logoofmt moo_logufmt # define moo_logoofmtv moo_logufmtv diff --git a/lib/number.c b/lib/number.c index 2fb7ac7..c290238 100644 --- a/lib/number.c +++ b/lib/number.c @@ -26,13 +26,13 @@ #include "moo-prv.h" -static moo_ooi_t pow_of_ten[] = { - 1L, +static moo_ooi_t pow_of_ten[] = { + 1L, 10L, 100L, 1000L, 10000L, - 100000L, + 100000L, #if (MOO_SIZEOF_OOI_T >= 4) 1000000L, 10000000L, @@ -205,7 +205,7 @@ static moo_ooi_t equalize_scale (moo_t* moo, moo_oop_t* x, moo_oop_t* y) moo_oop_t moo_truncfpdecval (moo_t* moo, moo_oop_t iv, moo_ooi_t cs, moo_ooi_t ns) { - /* this function truncates an existing fixed-point decimal value only if + /* this function truncates an existing fixed-point decimal value only if * the existing scale is greater than the new scale given. * [NOTE] this doesn't work on the fpdec object but on the inner integra * fpdec value. */ @@ -288,7 +288,7 @@ moo_oop_t moo_truncfpdec (moo_t* moo, moo_oop_t x, moo_ooi_t ns) } /* moo_makefpdec returns xv if ns <= 0. so it's safe to call it - * without checks against the 'ns <= 0' condition. + * without checks against the 'ns <= 0' condition. * setting ns to 0 or less will converts a decimal to an integer */ return moo_makefpdec(moo, xv, ns); } @@ -309,7 +309,7 @@ moo_oop_t moo_addnums (moo_t* moo, moo_oop_t x, moo_oop_t y) moo_pushvolat (moo, &y); scale = equalize_scale(moo, &x, &y); - if (scale <= -1) + if (scale <= -1) { moo_popvolats (moo, 2); return MOO_NULL; @@ -338,7 +338,7 @@ moo_oop_t moo_subnums (moo_t* moo, moo_oop_t x, moo_oop_t y) moo_pushvolat (moo, &y); scale = equalize_scale(moo, &x, &y); - if (scale <= -1) + if (scale <= -1) { moo_popvolats (moo, 2); return MOO_NULL; @@ -369,7 +369,7 @@ static moo_oop_t mul_nums (moo_t* moo, moo_oop_t x, moo_oop_t y, int mult) moo_seterrbfmt (moo, MOO_EINVAL, "parameter not numeric - %O", xv); return MOO_NULL; } - + ys = 0; yv = y; if (MOO_OOP_IS_FPDEC(moo, y)) @@ -386,7 +386,7 @@ static moo_oop_t mul_nums (moo_t* moo, moo_oop_t x, moo_oop_t y, int mult) nv = moo_mulints(moo, xv, yv); if (!nv) return MOO_NULL; - cs = xs + ys; + cs = xs + ys; if (cs <= 0) return nv; /* the result must be an integer */ ns = (mult || xs > ys)? xs: ys; @@ -451,7 +451,7 @@ moo_oop_t moo_divnums (moo_t* moo, moo_oop_t x, moo_oop_t y, int modulo) for (i = 0; i < ys; i++) { nv = moo_mulints(moo, nv, MOO_SMOOI_TO_OOP(10)); - if (!nv) + if (!nv) { moo_popvolat (moo); return MOO_NULL; @@ -481,7 +481,7 @@ static moo_oop_t comp_nums (moo_t* moo, moo_oop_t x, moo_oop_t y, moo_oop_t (*co moo_pushvolat (moo, &y); scale = equalize_scale(moo, &x, &y); - if (scale <= -1) + if (scale <= -1) { moo_popvolats (moo, 2); return MOO_NULL; diff --git a/lib/obj.c b/lib/obj.c index 8d42f55..dc7da6c 100644 --- a/lib/obj.c +++ b/lib/obj.c @@ -52,7 +52,7 @@ void* moo_allocbytes (moo_t* moo, moo_oow_t size) if (MOO_UNLIKELY(moo->igniting)) { - gch = (moo_gchdr_t*)moo_callocheapmem(moo, moo->heap, MOO_SIZEOF(*gch) + size); + gch = (moo_gchdr_t*)moo_callocheapmem(moo, moo->heap, MOO_SIZEOF(*gch) + size); if (MOO_UNLIKELY(!gch)) return MOO_NULL; } else @@ -62,7 +62,7 @@ void* moo_allocbytes (moo_t* moo, moo_oow_t size) allocsize = MOO_SIZEOF(*gch) + size; - if (moo->gci.bsz >= moo->gci.threshold) + if (moo->gci.bsz >= moo->gci.threshold) { moo_gc (moo, 0); moo->gci.threshold = moo->gci.bsz + 100000; /* TODO: change this fomula */ @@ -71,7 +71,7 @@ void* moo_allocbytes (moo_t* moo, moo_oow_t size) if (moo->gci.lazy_sweep) moo_gc_ms_sweep_lazy (moo, allocsize); - gch = (moo_gchdr_t*)moo_callocheapmem_noerr(moo, moo->heap, allocsize); + gch = (moo_gchdr_t*)moo_callocheapmem_noerr(moo, moo->heap, allocsize); if (!gch) { if (MOO_UNLIKELY(moo->option.trait & MOO_TRAIT_NOGC)) goto calloc_heapmem_fail; @@ -80,14 +80,14 @@ void* moo_allocbytes (moo_t* moo, moo_oow_t size) moo_gc (moo, 0); if (moo->gci.lazy_sweep) moo_gc_ms_sweep_lazy (moo, allocsize); - gch = (moo_gchdr_t*)moo_callocheapmem_noerr(moo, moo->heap, allocsize); - if (MOO_UNLIKELY(!gch)) + gch = (moo_gchdr_t*)moo_callocheapmem_noerr(moo, moo->heap, allocsize); + if (MOO_UNLIKELY(!gch)) { sweep_the_rest: if (moo->gci.lazy_sweep) { moo_gc_ms_sweep_lazy (moo, MOO_TYPE_MAX(moo_oow_t)); /* sweep the rest */ - gch = (moo_gchdr_t*)moo_callocheapmem(moo, moo->heap, allocsize); + gch = (moo_gchdr_t*)moo_callocheapmem(moo, moo->heap, allocsize); if (MOO_UNLIKELY(!gch)) return MOO_NULL; } else @@ -100,7 +100,7 @@ void* moo_allocbytes (moo_t* moo, moo_oow_t size) } } - if (moo->gci.lazy_sweep && moo->gci.ls.curr == moo->gci.b) + if (moo->gci.lazy_sweep && moo->gci.ls.curr == moo->gci.b) { /* if the lazy sweeping point is at the beginning of the allocation block, * moo->gc.ls.prev must get updated */ @@ -128,7 +128,7 @@ void* moo_allocbytes (moo_t* moo, moo_oow_t size) if (MOO_UNLIKELY(moo->igniting)) { /* you must increase the size of the permspace if this allocation fails */ - ptr = (moo_uint8_t*)moo_allocheapspace(moo, &moo->heap->permspace, size); + ptr = (moo_uint8_t*)moo_allocheapspace(moo, &moo->heap->permspace, size); } else { @@ -137,7 +137,7 @@ void* moo_allocbytes (moo_t* moo, moo_oow_t size) { moo_gc (moo, 1); MOO_LOG4 (moo, MOO_LOG_GC | MOO_LOG_INFO, - "GC completed - current heap ptr %p limit %p size %zd free %zd\n", + "GC completed - current heap ptr %p limit %p size %zd free %zd\n", moo->heap->curspace.ptr, moo->heap->curspace.limit, (moo_oow_t)(moo->heap->curspace.limit - moo->heap->curspace.base), (moo_oow_t)(moo->heap->curspace.limit - moo->heap->curspace.ptr) @@ -158,13 +158,13 @@ moo_oop_t moo_allocoopobj (moo_t* moo, moo_oow_t size) nbytes = size * MOO_SIZEOF(moo_oop_t); - /* this isn't really necessary since nbytes must be + /* this isn't really necessary since nbytes must be * aligned already. */ - nbytes_aligned = MOO_ALIGN(nbytes, MOO_SIZEOF(moo_oop_t)); + nbytes_aligned = MOO_ALIGN(nbytes, MOO_SIZEOF(moo_oop_t)); /* making the number of bytes to allocate a multiple of * MOO_SIZEOF(moo_oop_t) will guarantee the starting address - * of the allocated space to be an even number. + * of the allocated space to be an even number. * see MOO_OOP_IS_NUMERIC() and MOO_OOP_IS_POINTER() */ hdr = (moo_oop_oop_t)moo_allocbytes(moo, MOO_SIZEOF(moo_obj_t) + nbytes_aligned); if (MOO_UNLIKELY(!hdr)) return MOO_NULL; @@ -173,7 +173,7 @@ moo_oop_t moo_allocoopobj (moo_t* moo, moo_oow_t size) MOO_OBJ_SET_SIZE (hdr, size); MOO_OBJ_SET_CLASS (hdr, moo->_nil); - while (size > 0) + while (size > 0) { size = size - 1; MOO_OBJ_SET_OOP_VAL (hdr, size, moo->_nil); @@ -190,7 +190,7 @@ moo_oop_t moo_allocoopobjwithtrailer (moo_t* moo, moo_oow_t size, const moo_oob_ /* +1 for the trailer size of the moo_oow_t type */ nbytes = (size + 1) * MOO_SIZEOF(moo_oop_t) + blen; - nbytes_aligned = MOO_ALIGN(nbytes, MOO_SIZEOF(moo_oop_t)); + nbytes_aligned = MOO_ALIGN(nbytes, MOO_SIZEOF(moo_oop_t)); hdr = (moo_oop_oop_t)moo_allocbytes(moo, MOO_SIZEOF(moo_obj_t) + nbytes_aligned); if (MOO_UNLIKELY(!hdr)) return MOO_NULL; @@ -199,7 +199,7 @@ moo_oop_t moo_allocoopobjwithtrailer (moo_t* moo, moo_oow_t size, const moo_oob_ MOO_OBJ_SET_SIZE (hdr, size); MOO_OBJ_SET_CLASS (hdr, moo->_nil); - for (i = 0; i < size; i++) + for (i = 0; i < size; i++) { MOO_OBJ_SET_OOP_VAL (hdr, i, moo->_nil); } @@ -231,13 +231,13 @@ static MOO_INLINE moo_oop_t alloc_numeric_array (moo_t* moo, const void* ptr, mo /* 'extra' indicates an extra unit to append at the end. * it's useful to store a string with a terminating null */ /*nbytes = extra? xbytes + len: xbytes; */ - nbytes = extra? xbytes + unit: xbytes; + nbytes = extra? xbytes + unit: xbytes; nbytes_aligned = MOO_ALIGN(nbytes, MOO_SIZEOF(moo_oop_t)); /* TODO: check overflow in size calculation*/ /* making the number of bytes to allocate a multiple of * MOO_SIZEOF(moo_oop_t) will guarantee the starting address - * of the allocated space to be an even number. + * of the allocated space to be an even number. * see MOO_OOP_IS_NUMERIC() and MOO_OOP_IS_POINTER() */ hdr = (moo_oop_t)moo_allocbytes(moo, MOO_SIZEOF(moo_obj_t) + nbytes_aligned); if (MOO_UNLIKELY(!hdr)) return MOO_NULL; @@ -294,18 +294,18 @@ static MOO_INLINE int decode_spec (moo_t* moo, moo_oop_class_t _class, moo_oow_t MOO_ASSERT (moo, MOO_OOP_IS_SMOOI(_class->spec)); spec = MOO_OOP_TO_SMOOI(_class->spec); - num_fixed_fields = MOO_CLASS_SPEC_NAMED_INSTVARS(spec); + num_fixed_fields = MOO_CLASS_SPEC_NAMED_INSTVARS(spec); MOO_ASSERT (moo, num_fixed_fields <= MOO_MAX_NAMED_INSTVARS); - if (MOO_CLASS_SPEC_IS_INDEXED(spec)) + if (MOO_CLASS_SPEC_IS_INDEXED(spec)) { indexed_type = MOO_CLASS_SPEC_INDEXED_TYPE(spec); /* the number of the fixed fields for a non-pointer object are supported. - * the fixed fields of a pointer object holds named instance variables + * the fixed fields of a pointer object holds named instance variables * and a non-pointer object is facilitated with the fixed fields of the size * specified in the class description like #byte(5), #word(10). - * + * * when it comes to spec decoding, there is no difference between a pointer * object and a non-pointer object */ @@ -323,7 +323,7 @@ static MOO_INLINE int decode_spec (moo_t* moo, moo_oop_class_t _class, moo_oow_t if (num_flexi_fields > 0) { - moo_seterrbfmt (moo, MOO_EPERM, "flexi-fields(%zu) disallowed for a class %O", num_flexi_fields, _class); + moo_seterrbfmt (moo, MOO_EPERM, "flexi-fields(%zu) disallowed for a class %O", num_flexi_fields, _class); return -1; } } @@ -331,7 +331,7 @@ static MOO_INLINE int decode_spec (moo_t* moo, moo_oop_class_t _class, moo_oow_t MOO_ASSERT (moo, num_fixed_fields + num_flexi_fields <= MOO_OBJ_SIZE_MAX); *type = indexed_type; *outlen = num_fixed_fields + num_flexi_fields; - return 0; + return 0; } moo_oop_t moo_instantiate (moo_t* moo, moo_oop_class_t _class, const void* vptr, moo_oow_t vlen) @@ -350,7 +350,7 @@ moo_oop_t moo_instantiate (moo_t* moo, moo_oop_class_t _class, const void* vptr, switch (type) { case MOO_OBJ_TYPE_OOP: - /* both the fixed part(named instance variables) and + /* both the fixed part(named instance variables) and * the variable part(indexed instance variables) are allowed. */ oop = moo_allocoopobj(moo, alloclen); if (oop) @@ -362,9 +362,9 @@ moo_oop_t moo_instantiate (moo_t* moo, moo_oop_class_t _class, const void* vptr, /* [NOTE] i don't deep-copy initial values. * if you change the contents of compound values like arrays, - * it affects subsequent instantiation of the class. + * it affects subsequent instantiation of the class. * it's important that the compiler should mark compound initial - * values read-only. */ + * values read-only. */ while (i > 0) { --i; @@ -384,8 +384,8 @@ moo_oop_t moo_instantiate (moo_t* moo, moo_oop_class_t _class, const void* vptr, MOO_MEMCPY (&hdr->slot[named_instvar], vptr, vlen * MOO_SIZEOF(moo_oop_t)); } - For the above code to work, it should protect the elements of - the vptr array with moo_pushvolat(). So it might be better + For the above code to work, it should protect the elements of + the vptr array with moo_pushvolat(). So it might be better to disallow a non-NULL vptr when indexed_type is OOP. See the assertion above this comment block. */ @@ -413,7 +413,7 @@ moo_oop_t moo_instantiate (moo_t* moo, moo_oop_class_t _class, const void* vptr, break; } - if (oop) + if (oop) { moo_ooi_t spec; MOO_OBJ_SET_CLASS (oop, (moo_oop_t)_class); @@ -451,9 +451,9 @@ moo_oop_t moo_instantiatewithtrailer (moo_t* moo, moo_oop_class_t _class, moo_oo /* [NOTE] i don't deep-copy initial values. * if you change the contents of compound values like arrays, - * it affects subsequent instantiation of the class. + * it affects subsequent instantiation of the class. * it's important that the compiler should mark compound initial - * values read-only. */ + * values read-only. */ while (i > 0) { --i; @@ -481,7 +481,7 @@ moo_oop_t moo_instantiatewithtrailer (moo_t* moo, moo_oop_class_t _class, moo_oo MOO_OBJ_SET_CLASS (oop, _class); spec = MOO_OOP_TO_SMOOI(_class->spec); if (MOO_CLASS_SPEC_IS_IMMUTABLE(spec)) MOO_OBJ_SET_FLAGS_RDONLY (oop, 1); - /* the object with trailer is to to uncopyable in moo_allocoopobjwithtrailer() so no need to check/set it again here + /* the object with trailer is to to uncopyable in moo_allocoopobjwithtrailer() so no need to check/set it again here if (MOO_CLASS_SPEC_IS_UNCOPYABLE(spec)) MOO_OBJ_SET_FLAGS_UNCOPYABLE (oop, 1); */ } @@ -503,7 +503,7 @@ moo_oop_t moo_oowtoptr (moo_t* moo, moo_oow_t num) int moo_ptrtooow (moo_t* moo, moo_oop_t ptr, moo_oow_t* num) { - if (MOO_OOP_IS_SMPTR(ptr)) + if (MOO_OOP_IS_SMPTR(ptr)) { *num = (moo_oow_t)MOO_OOP_TO_SMPTR(ptr); return 0; diff --git a/lib/opt-imp.h b/lib/opt-imp.h index 0d56353..f2eeca5 100644 --- a/lib/opt-imp.h +++ b/lib/opt-imp.h @@ -27,7 +27,7 @@ /* this file is supposed to be included by opt.c multiple times */ -/* +/* * moo_getopt is based on BSD getopt. * -------------------------------------------------------------------------- * @@ -71,18 +71,18 @@ xci_t xgetopt (int argc, xch_t* const* argv, xopt_t* opt) opt->arg = MOO_NULL; opt->lngopt = MOO_NULL; - if (opt->cur == MOO_NULL) + if (opt->cur == MOO_NULL) { opt->cur = XEMSG; opt->ind = 1; } - if (*opt->cur == '\0') + if (*opt->cur == '\0') { /* update scanning pointer */ - if (opt->ind >= argc || *(opt->cur = argv[opt->ind]) != '-') + if (opt->ind >= argc || *(opt->cur = argv[opt->ind]) != '-') { - /* All arguments have been processed or the current + /* All arguments have been processed or the current * argument doesn't start with a dash */ opt->cur = XEMSG; return XCI_EOF; @@ -123,7 +123,7 @@ xci_t xgetopt (int argc, xch_t* const* argv, xopt_t* opt) while (*end != '\0' && *end != '=') end++; - for (o = opt->lng; o->str; o++) + for (o = opt->lng; o->str; o++) { const xch_t* str = o->str; @@ -147,10 +147,10 @@ xci_t xgetopt (int argc, xch_t* const* argv, xopt_t* opt) } else if (opt->arg == MOO_NULL) { - /* check if it has a remaining argument + /* check if it has a remaining argument * available */ - if (argc <= ++opt->ind) return BADARG; - /* If so, the next available argument is + if (argc <= ++opt->ind) return BADARG; + /* If so, the next available argument is * taken to be an option argument */ opt->arg = argv[opt->ind]; } @@ -160,12 +160,12 @@ xci_t xgetopt (int argc, xch_t* const* argv, xopt_t* opt) } /*if (*end == MOO_T('=')) *end = MOO_T('\0');*/ - opt->lngopt = opt->cur; + opt->lngopt = opt->cur; return BADCH; } if ((opt->opt = *opt->cur++) == ':' || - (oli = xfindcharincstr(opt->str, opt->opt)) == MOO_NULL) + (oli = xfindcharincstr(opt->str, opt->opt)) == MOO_NULL) { /* * if the user didn't specify '-' as an option, @@ -176,21 +176,21 @@ xci_t xgetopt (int argc, xch_t* const* argv, xopt_t* opt) return BADCH; } - if (*++oli != ':') + if (*++oli != ':') { /* don't need argument */ if (*opt->cur == '\0') opt->ind++; } - else + else { /* need an argument */ - if (*opt->cur != '\0') + if (*opt->cur != '\0') { /* no white space */ opt->arg = opt->cur; } - else if (argc <= ++opt->ind) + else if (argc <= ++opt->ind) { /* no arg */ opt->cur = XEMSG; diff --git a/lib/pf-basic.c b/lib/pf-basic.c index 323008f..fef32d0 100644 --- a/lib/pf-basic.c +++ b/lib/pf-basic.c @@ -27,10 +27,10 @@ #include "moo-prv.h" -/* -------------------------------------------------------------------------------- +/* -------------------------------------------------------------------------------- * COMPARISON * -------------------------------------------------------------------------------- */ - + moo_pfrc_t moo_pf_identical (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) { moo_oop_t rcv, arg, b; @@ -91,7 +91,7 @@ static int _equal_objects (moo_t* moo, moo_oop_t rcv, moo_oop_t arg) if (MOO_OBJ_GET_CLASS(rcv) != MOO_OBJ_GET_CLASS(arg)) return 0; /* different class, not equal */ MOO_ASSERT (moo, MOO_OBJ_GET_FLAGS_TYPE(rcv) == MOO_OBJ_GET_FLAGS_TYPE(arg)); - if (MOO_OBJ_GET_CLASS(rcv) == moo->_class && rcv != arg) + if (MOO_OBJ_GET_CLASS(rcv) == moo->_class && rcv != arg) { /* a class object are supposed to be unique */ return 0; @@ -124,8 +124,8 @@ static int _equal_objects (moo_t* moo, moo_oop_t rcv, moo_oop_t arg) if (MOO_UNLIKELY(MOO_OBJ_GET_FLAGS_PROC(rcv))) { - /* the stack in a process object doesn't need to be - * scanned in full. the slots above the stack pointer + /* the stack in a process object doesn't need to be + * scanned in full. the slots above the stack pointer * are garbages. */ size = MOO_PROCESS_NAMED_INSTVARS + MOO_OOP_TO_SMOOI(((moo_oop_process_t)rcv)->sp) + 1; MOO_ASSERT (moo, size <= MOO_OBJ_GET_SIZE(rcv)); @@ -139,7 +139,7 @@ static int _equal_objects (moo_t* moo, moo_oop_t rcv, moo_oop_t arg) int n; /* TODO: remove recursion */ - /* [NOTE] even if the object implements the equality method, + /* [NOTE] even if the object implements the equality method, * this primitive method doesn't honor it. */ n = _equal_objects(moo, MOO_OBJ_GET_OOP_VAL(rcv, i), MOO_OBJ_GET_OOP_VAL(arg, i)); if (n <= 0) return n; @@ -185,7 +185,7 @@ moo_pfrc_t moo_pf_not_equal (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) } -/* -------------------------------------------------------------------------------- +/* -------------------------------------------------------------------------------- * INSTANTIATION * -------------------------------------------------------------------------------- */ @@ -196,7 +196,7 @@ moo_pfrc_t moo_pf_basic_new (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) moo_oow_t size = 0; /* size of the variable/indexed part */ _class = (moo_oop_class_t)MOO_STACK_GETRCV(moo, nargs); - if (MOO_CLASSOF(moo, _class) != moo->_class) + if (MOO_CLASSOF(moo, _class) != moo->_class) { /* the receiver is not a class object */ moo_seterrbfmt (moo, MOO_EMSGRCV, "non-class receiver - %O", _class); @@ -221,15 +221,15 @@ moo_pfrc_t moo_pf_basic_new (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) } } - if (MOO_OOP_IS_SMOOI(((moo_oop_class_t)_class)->trsize)) + if (MOO_OOP_IS_SMOOI(((moo_oop_class_t)_class)->trsize)) { obj = moo_instantiatewithtrailer(moo, _class, size, MOO_NULL, MOO_OOP_TO_SMOOI(((moo_oop_class_t)_class)->trsize)); } - else + else { - /* moo_instantiate() will ignore size if the instance specification + /* moo_instantiate() will ignore size if the instance specification * disallows indexed(variable) parts. */ - /* TODO: should i check the specification before calling + /* TODO: should i check the specification before calling * moo_instantiate()? */ obj = moo_instantiate(moo, _class, MOO_NULL, size); } @@ -253,7 +253,7 @@ moo_pfrc_t moo_pf_shallow_copy (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) return MOO_PF_SUCCESS; } -/* -------------------------------------------------------------------------------- +/* -------------------------------------------------------------------------------- * BASIC ACCESS * -------------------------------------------------------------------------------- */ @@ -278,7 +278,7 @@ moo_pfrc_t moo_pf_basic_size (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) if (!MOO_OOP_IS_POINTER(rcv)) { - /* a non-pointer object has the size of 0. + /* a non-pointer object has the size of 0. * such an object doesn't consume object memory space except an OOP word */ sz = MOO_SMOOI_TO_OOP(0); } @@ -327,7 +327,7 @@ moo_pfrc_t moo_pf_basic_last_index (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) if (!MOO_OOP_IS_POINTER(rcv)) { - /* a non-pointer object has the size of 0. + /* a non-pointer object has the size of 0. * such an object doesn't consume object memory space except an OOP word. * use -1 to indicate that the last index doesn't exist */ sz = MOO_SMOOI_TO_OOP(-1); @@ -677,7 +677,7 @@ moo_pfrc_t moo_pf_basic_fill (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) return MOO_PF_FAILURE; } - if (ssz <= 0) + if (ssz <= 0) { /* no filling is performed. also no validation about the range of * source position is performed */ @@ -800,11 +800,11 @@ moo_pfrc_t moo_pf_basic_shift (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) return MOO_PF_FAILURE; } - if (ssz <= 0) + if (ssz <= 0) { /* no shifting is performed. also no validation about the range of * source position and destionation position is performed */ - goto done; + goto done; } if (sidx >= MOO_OBJ_GET_SIZE(rcv)) @@ -833,15 +833,15 @@ moo_pfrc_t moo_pf_basic_shift (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) MOO_MEMMOVE (MOO_OBJ_GET_BYTE_PTR(rcv, didx), MOO_OBJ_GET_BYTE_PTR(rcv, sidx), ssz * MOO_SIZEOF(MOO_OBJ_GET_BYTE_VAL(rcv, 0))); - + if (didx > sidx) { - MOO_MEMSET (MOO_OBJ_GET_BYTE_PTR(rcv, sidx), 0, + MOO_MEMSET (MOO_OBJ_GET_BYTE_PTR(rcv, sidx), 0, (didx - sidx) * MOO_SIZEOF(MOO_OBJ_GET_BYTE_VAL(rcv, 0))); } else { - MOO_MEMSET (MOO_OBJ_GET_BYTE_PTR(rcv, didx + ssz - 1), 0, + MOO_MEMSET (MOO_OBJ_GET_BYTE_PTR(rcv, didx + ssz - 1), 0, (sidx - didx) * MOO_SIZEOF(MOO_OBJ_GET_BYTE_VAL(rcv, 0))); } break; @@ -853,12 +853,12 @@ moo_pfrc_t moo_pf_basic_shift (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) if (didx > sidx) { - MOO_MEMSET (MOO_OBJ_GET_CHAR_PTR(rcv, sidx), 0, + MOO_MEMSET (MOO_OBJ_GET_CHAR_PTR(rcv, sidx), 0, (didx - sidx) * MOO_SIZEOF(MOO_OBJ_GET_CHAR_VAL(rcv, 0))); } else { - MOO_MEMSET (MOO_OBJ_GET_CHAR_PTR(rcv, didx + ssz - 1), 0, + MOO_MEMSET (MOO_OBJ_GET_CHAR_PTR(rcv, didx + ssz - 1), 0, (sidx - didx) * MOO_SIZEOF(MOO_OBJ_GET_CHAR_VAL(rcv, 0))); } break; @@ -870,12 +870,12 @@ moo_pfrc_t moo_pf_basic_shift (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) if (didx > sidx) { - MOO_MEMSET (MOO_OBJ_GET_HALFWORD_PTR(rcv, sidx), 0, + MOO_MEMSET (MOO_OBJ_GET_HALFWORD_PTR(rcv, sidx), 0, (didx - sidx) * MOO_SIZEOF(MOO_OBJ_GET_HALFWORD_VAL(rcv, 0))); } else { - MOO_MEMSET (MOO_OBJ_GET_HALFWORD_PTR(rcv, didx + ssz - 1), 0, + MOO_MEMSET (MOO_OBJ_GET_HALFWORD_PTR(rcv, didx + ssz - 1), 0, (sidx - didx) * MOO_SIZEOF(MOO_OBJ_GET_HALFWORD_VAL(rcv, 0))); } break; @@ -887,12 +887,12 @@ moo_pfrc_t moo_pf_basic_shift (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) if (didx > sidx) { - MOO_MEMSET (MOO_OBJ_GET_WORD_PTR(rcv, sidx), 0, + MOO_MEMSET (MOO_OBJ_GET_WORD_PTR(rcv, sidx), 0, (didx - sidx) * MOO_SIZEOF(MOO_OBJ_GET_WORD_VAL(rcv, 0))); } else { - MOO_MEMSET (MOO_OBJ_GET_WORD_PTR(rcv, didx + ssz - 1), 0, + MOO_MEMSET (MOO_OBJ_GET_WORD_PTR(rcv, didx + ssz - 1), 0, (sidx - didx) * MOO_SIZEOF(MOO_OBJ_GET_WORD_VAL(rcv, 0))); } break; @@ -906,7 +906,7 @@ moo_pfrc_t moo_pf_basic_shift (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) MOO_STORE_OOP (moo, MOO_OBJ_GET_OOP_PTR(rcv, didx + i), MOO_OBJ_GET_OOP_VAL(rcv, sidx + i)); } - while (sidx < didx) + while (sidx < didx) { /* no need to use MOO_STORE_OOP because moo->_nil is the assigned value */ MOO_OBJ_SET_OOP_VAL (rcv, sidx, moo->_nil); @@ -922,7 +922,7 @@ moo_pfrc_t moo_pf_basic_shift (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) MOO_STORE_OOP (moo, MOO_OBJ_GET_OOP_PTR(rcv, didx + i), MOO_OBJ_GET_OOP_VAL(rcv, sidx + i)); } - while (didx > sidx) + while (didx > sidx) { /* no need to use MOO_STORE_OOP because moo->_nil is the assigned value */ MOO_OBJ_SET_OOP_VAL (rcv, didx + ssz, moo->_nil); @@ -957,7 +957,7 @@ done: return MOO_PF_SUCCESS; } -/* -------------------------------------------------------------------------------- +/* -------------------------------------------------------------------------------- * BASIC QUERY * -------------------------------------------------------------------------------- */ diff --git a/lib/pf-sys.c b/lib/pf-sys.c index 393b087..793b275 100644 --- a/lib/pf-sys.c +++ b/lib/pf-sys.c @@ -323,7 +323,7 @@ static MOO_INLINE moo_pfrc_t _system_alloc (moo_t* moo, moo_ooi_t nargs, int cle MOO_ASSERT (moo, nargs == 1); tmp = MOO_STACK_GETARG(moo, nargs, 0); - if (!MOO_OOP_IS_SMOOI(tmp) || MOO_OOP_TO_SMOOI(tmp) < 0) + if (!MOO_OOP_IS_SMOOI(tmp) || MOO_OOP_TO_SMOOI(tmp) < 0) { moo_seterrbfmt (moo, MOO_EINVAL, "invalid size %O for raw memory allocation", tmp); return MOO_PF_FAILURE; @@ -342,7 +342,7 @@ static MOO_INLINE moo_pfrc_t _system_alloc (moo_t* moo, moo_ooi_t nargs, int cle MOO_STACK_SETRET (moo, nargs, tmp); return MOO_PF_SUCCESS; -} +} moo_pfrc_t moo_pf_system_calloc (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) { @@ -417,7 +417,7 @@ static MOO_INLINE moo_oop_t _fetch_raw_int (moo_t* moo, moo_int8_t* rawptr, moo_ switch (size) { - case 1: + case 1: v = ((struct st_int8_t*)&rawptr[offset])->v; break; @@ -425,18 +425,18 @@ static MOO_INLINE moo_oop_t _fetch_raw_int (moo_t* moo, moo_int8_t* rawptr, moo_ v = ((struct st_int16_t*)&rawptr[offset])->v; break; - case 4: + case 4: v = ((struct st_int32_t*)&rawptr[offset])->v; break; #if defined(MOO_HAVE_INT64_T) && (MOO_SIZEOF_OOW_T >= MOO_SIZEOF_INT64_T) - case 8: + case 8: v = ((struct st_int64_t*)&rawptr[offset])->v; break; #endif #if defined(MOO_HAVE_INT128_T) && (MOO_SIZEOF_OOW_T >= MOO_SIZEOF_INT128_T) - case 16: + case 16: v = ((struct st_int128_t*)&rawptr[offset])->v; break; #endif @@ -456,7 +456,7 @@ static MOO_INLINE moo_oop_t _fetch_raw_uint (moo_t* moo, moo_uint8_t* rawptr, mo switch (size) { - case 1: + case 1: v = ((struct st_uint8_t*)&rawptr[offset])->v; break; @@ -464,18 +464,18 @@ static MOO_INLINE moo_oop_t _fetch_raw_uint (moo_t* moo, moo_uint8_t* rawptr, mo v = ((struct st_uint16_t*)&rawptr[offset])->v; break; - case 4: + case 4: v = ((struct st_uint32_t*)&rawptr[offset])->v; break; #if defined(MOO_HAVE_UINT64_T) && (MOO_SIZEOF_OOW_T >= MOO_SIZEOF_UINT64_T) - case 8: + case 8: v = ((struct st_uint64_t*)&rawptr[offset])->v; break; #endif #if defined(MOO_HAVE_UINT128_T) && (MOO_SIZEOF_OOW_T >= MOO_SIZEOF_UINT128_T) - case 16: + case 16: v = ((struct st_uint128_t*)&rawptr[offset])->v; break; #endif @@ -503,7 +503,7 @@ static MOO_INLINE int _store_raw_int (moo_t* moo, moo_uint8_t* rawptr, moo_oow_t max = (moo_ooi_t)(~(moo_oow_t)0 >> ((MOO_SIZEOF_OOW_T - size) * MOO_BITS_PER_BYTE + 1)); min = -max - 1; - if (w > max || w < min) + if (w > max || w < min) { moo_seterrbfmt (moo, MOO_ERANGE, "value %zd out of supported range for raw signed memory store", w); return -1; @@ -511,7 +511,7 @@ static MOO_INLINE int _store_raw_int (moo_t* moo, moo_uint8_t* rawptr, moo_oow_t n = 0; switch (size) - { + { case 1: ((struct st_int8_t*)&rawptr[offset])->v = w; break; @@ -526,13 +526,13 @@ static MOO_INLINE int _store_raw_int (moo_t* moo, moo_uint8_t* rawptr, moo_oow_t #if defined(MOO_HAVE_INT64_T) && (MOO_SIZEOF_OOW_T >= MOO_SIZEOF_INT64_T) case 8: - ((struct st_int64_t*)&rawptr[offset])->v = w; + ((struct st_int64_t*)&rawptr[offset])->v = w; break; #endif #if defined(MOO_HAVE_INT128_T) && (MOO_SIZEOF_OOW_T >= MOO_SIZEOF_INT128_T) case 16: - ((struct st_int128_t*)&rawptr[offset])->v = w; + ((struct st_int128_t*)&rawptr[offset])->v = w; break; #endif @@ -541,7 +541,7 @@ static MOO_INLINE int _store_raw_int (moo_t* moo, moo_uint8_t* rawptr, moo_oow_t n = -1; } - + return n; } @@ -550,9 +550,9 @@ static MOO_INLINE int _store_raw_uint (moo_t* moo, moo_uint8_t* rawptr, moo_oow_ int n; moo_oow_t w, max; - if ((n = moo_inttooow_noseterr(moo, voop, &w)) <= 0) + if ((n = moo_inttooow_noseterr(moo, voop, &w)) <= 0) { - if (n <= -1) + if (n <= -1) { moo_seterrbfmt (moo, MOO_ERANGE, "negative value %O for raw unsigned memory store", voop); } @@ -564,7 +564,7 @@ static MOO_INLINE int _store_raw_uint (moo_t* moo, moo_uint8_t* rawptr, moo_oow_ } max = (~(moo_oow_t)0 >> ((MOO_SIZEOF_OOW_T - size) * MOO_BITS_PER_BYTE)); - if (w > max) + if (w > max) { moo_seterrbfmt (moo, MOO_ERANGE, "value %ju out of supported range for raw unsigned memory store", w); return -1; @@ -572,7 +572,7 @@ static MOO_INLINE int _store_raw_uint (moo_t* moo, moo_uint8_t* rawptr, moo_oow_ n = 0; switch (size) - { + { case 1: ((struct st_uint8_t*)&rawptr[offset])->v = w; break; @@ -648,14 +648,14 @@ static moo_pfrc_t _get_system_uint (moo_t* moo, moo_ooi_t nargs, int size) MOO_ASSERT (moo, nargs == 2); tmp = MOO_STACK_GETARG(moo, nargs, 0); - if (moo_ptrtooow(moo, tmp, (moo_oow_t*)&rawptr) <= -1) + if (moo_ptrtooow(moo, tmp, (moo_oow_t*)&rawptr) <= -1) { moo_seterrbfmt (moo, MOO_EINVAL, "invalid pointer %O for raw unsigned memory fetch", tmp); return MOO_PF_FAILURE; } tmp = MOO_STACK_GETARG(moo, nargs, 1); - if (moo_inttooow_noseterr(moo, tmp, &offset) <= 0) + if (moo_inttooow_noseterr(moo, tmp, &offset) <= 0) { moo_seterrbfmt (moo, MOO_EINVAL, "invalid offset %O for raw unsigned memory fetch", tmp); return MOO_PF_FAILURE; @@ -732,7 +732,7 @@ static moo_pfrc_t _put_system_int (moo_t* moo, moo_ooi_t nargs, int size) return MOO_PF_FAILURE; } - if (_store_raw_int(moo, rawptr, offset, size, MOO_STACK_GETARG(moo, nargs, 2)) <= -1) + if (_store_raw_int(moo, rawptr, offset, size, MOO_STACK_GETARG(moo, nargs, 2)) <= -1) { return MOO_PF_FAILURE; } @@ -833,21 +833,21 @@ moo_pfrc_t moo_pf_system_get_bytes (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) } tmp = MOO_STACK_GETARG(moo, nargs, 1); - if (moo_inttooow_noseterr(moo, tmp, &offset) <= 0) + if (moo_inttooow_noseterr(moo, tmp, &offset) <= 0) { moo_seterrbfmt (moo, MOO_EINVAL, "invalid offset %O for raw memory fetch", tmp); return MOO_PF_FAILURE; } tmp = MOO_STACK_GETARG(moo, nargs, 3); - if (moo_inttooow_noseterr(moo, tmp, &offset_in_buffer) <= 0) + if (moo_inttooow_noseterr(moo, tmp, &offset_in_buffer) <= 0) { moo_seterrbfmt (moo, MOO_EINVAL, "invalid buffer offset %O for raw memory fetch", tmp); return MOO_PF_FAILURE; } tmp = MOO_STACK_GETARG(moo, nargs, 4); - if (moo_inttooow_noseterr(moo, tmp, &len_in_buffer) <= 0) + if (moo_inttooow_noseterr(moo, tmp, &len_in_buffer) <= 0) { moo_seterrbfmt (moo, MOO_EINVAL, "invalid buffer length %O for raw memory fetch", tmp); return MOO_PF_FAILURE; @@ -867,7 +867,7 @@ moo_pfrc_t moo_pf_system_get_bytes (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) if (len_in_buffer > MOO_SMOOI_MAX) len_in_buffer = MOO_SMOOI_MAX; } else len_in_buffer = 0; - + if (len_in_buffer > 0) { MOO_MEMCPY (MOO_OBJ_GET_BYTE_PTR(tmp, offset_in_buffer), &rawptr[offset], len_in_buffer); @@ -895,21 +895,21 @@ moo_pfrc_t moo_pf_system_put_bytes (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) } tmp = MOO_STACK_GETARG(moo, nargs, 1); - if (moo_inttooow_noseterr(moo, tmp, &offset) <= 0) + if (moo_inttooow_noseterr(moo, tmp, &offset) <= 0) { moo_seterrbfmt (moo, MOO_EINVAL, "invalid offset %O for raw memory store", tmp); return MOO_PF_FAILURE; } tmp = MOO_STACK_GETARG(moo, nargs, 3); - if (moo_inttooow_noseterr(moo, tmp, &offset_in_buffer) <= 0) + if (moo_inttooow_noseterr(moo, tmp, &offset_in_buffer) <= 0) { moo_seterrbfmt (moo, MOO_EINVAL, "invalid buffer offset %O for raw memory fetch", tmp); return MOO_PF_FAILURE; } tmp = MOO_STACK_GETARG(moo, nargs, 4); - if (moo_inttooow_noseterr(moo, tmp, &len_in_buffer) <= 0) + if (moo_inttooow_noseterr(moo, tmp, &len_in_buffer) <= 0) { moo_seterrbfmt (moo, MOO_EINVAL, "invalid buffer length %O for raw memory fetch", tmp); return MOO_PF_FAILURE; @@ -921,7 +921,7 @@ moo_pfrc_t moo_pf_system_put_bytes (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) moo_seterrbfmt (moo, MOO_EINVAL, "invalid buffer %O for raw memory store", tmp); return MOO_PF_FAILURE; } - + if (offset_in_buffer < MOO_OBJ_GET_SIZE(tmp)) { moo_oow_t max_len = MOO_OBJ_GET_SIZE(tmp) - offset_in_buffer; @@ -929,7 +929,7 @@ moo_pfrc_t moo_pf_system_put_bytes (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) if (len_in_buffer > MOO_SMOOI_MAX) len_in_buffer = MOO_SMOOI_MAX; } else len_in_buffer = 0; - + if (len_in_buffer > 0) { MOO_MEMCPY (&rawptr[offset], MOO_OBJ_GET_BYTE_PTR(tmp, offset_in_buffer), len_in_buffer); @@ -1172,21 +1172,21 @@ moo_pfrc_t moo_pf_smptr_get_bytes (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) } tmp = MOO_STACK_GETARG(moo, nargs, 0); - if (moo_inttooow_noseterr(moo, tmp, &offset) <= 0) + if (moo_inttooow_noseterr(moo, tmp, &offset) <= 0) { moo_seterrbfmt (moo, MOO_EINVAL, "invalid offset %O for raw memory fetch", tmp); return MOO_PF_FAILURE; } tmp = MOO_STACK_GETARG(moo, nargs, 2); - if (moo_inttooow_noseterr(moo, tmp, &offset_in_buffer) <= 0) + if (moo_inttooow_noseterr(moo, tmp, &offset_in_buffer) <= 0) { moo_seterrbfmt (moo, MOO_EINVAL, "invalid buffer offset %O for raw memory fetch", tmp); return MOO_PF_FAILURE; } tmp = MOO_STACK_GETARG(moo, nargs, 3); - if (moo_inttooow_noseterr(moo, tmp, &len_in_buffer) <= 0) + if (moo_inttooow_noseterr(moo, tmp, &len_in_buffer) <= 0) { moo_seterrbfmt (moo, MOO_EINVAL, "invalid buffer length %O for raw memory fetch", tmp); return MOO_PF_FAILURE; @@ -1206,7 +1206,7 @@ moo_pfrc_t moo_pf_smptr_get_bytes (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) if (len_in_buffer > MOO_SMOOI_MAX) len_in_buffer = MOO_SMOOI_MAX; } else len_in_buffer = 0; - + if (len_in_buffer > 0) { MOO_MEMCPY (MOO_OBJ_GET_BYTE_PTR(tmp, offset_in_buffer), &rawptr[offset], len_in_buffer); @@ -1235,21 +1235,21 @@ moo_pfrc_t moo_pf_smptr_put_bytes (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) } tmp = MOO_STACK_GETARG(moo, nargs, 0); - if (moo_inttooow_noseterr(moo, tmp, &offset) <= 0) + if (moo_inttooow_noseterr(moo, tmp, &offset) <= 0) { moo_seterrbfmt (moo, MOO_EINVAL, "invalid offset %O for raw memory store", tmp); return MOO_PF_FAILURE; } tmp = MOO_STACK_GETARG(moo, nargs, 2); - if (moo_inttooow_noseterr(moo, tmp, &offset_in_buffer) <= 0) + if (moo_inttooow_noseterr(moo, tmp, &offset_in_buffer) <= 0) { moo_seterrbfmt (moo, MOO_EINVAL, "invalid buffer offset %O for raw memory fetch", tmp); return MOO_PF_FAILURE; } tmp = MOO_STACK_GETARG(moo, nargs, 3); - if (moo_inttooow_noseterr(moo, tmp, &len_in_buffer) <= 0) + if (moo_inttooow_noseterr(moo, tmp, &len_in_buffer) <= 0) { moo_seterrbfmt (moo, MOO_EINVAL, "invalid buffer length %O for raw memory fetch", tmp); return MOO_PF_FAILURE; @@ -1261,7 +1261,7 @@ moo_pfrc_t moo_pf_smptr_put_bytes (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) moo_seterrbfmt (moo, MOO_EINVAL, "invalid buffer %O for raw memory store", tmp); return MOO_PF_FAILURE; } - + if (offset_in_buffer < MOO_OBJ_GET_SIZE(tmp)) { moo_oow_t max_len = MOO_OBJ_GET_SIZE(tmp) - offset_in_buffer; @@ -1269,7 +1269,7 @@ moo_pfrc_t moo_pf_smptr_put_bytes (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) if (len_in_buffer > MOO_SMOOI_MAX) len_in_buffer = MOO_SMOOI_MAX; } else len_in_buffer = 0; - + if (len_in_buffer > 0) { MOO_MEMCPY (&rawptr[offset], MOO_OBJ_GET_BYTE_PTR(tmp, offset_in_buffer), len_in_buffer); @@ -1282,7 +1282,7 @@ moo_pfrc_t moo_pf_smptr_put_bytes (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) static void sprintptr (moo_ooch_t* nbuf, moo_oow_t num, moo_oow_t *lenp) { - static const moo_ooch_t hex2ascii_upper[] = + static const moo_ooch_t hex2ascii_upper[] = { '0','1','2','3','4','5','6','7','8','9', 'A','B','C','D','E','F','G','H','I','J','K','L','M', diff --git a/lib/poll-msw.c b/lib/poll-msw.c index c96d3fa..17ffc6f 100644 --- a/lib/poll-msw.c +++ b/lib/poll-msw.c @@ -1,411 +1,411 @@ -/* Emulation for poll(2) - Contributed by Paolo Bonzini. - - Copyright 2001-2003, 2006-2016 Free Software Foundation, Inc. - - This file is part of gnulib. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, see . */ - -/* Tell gcc not to warn about the (nfd < 0) tests, below. */ -#if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__ -# pragma GCC diagnostic ignored "-Wtype-limits" -#endif - -#include -#include - -#include "poll-msw.h" - -#include -#include -#include -#include - -#if defined(__BORLANDC__) -# include -# define _alloca alloca -#endif - -#ifndef INFTIM -# define INFTIM (-1) -#endif - -/* BeOS does not have MSG_PEEK. */ -#ifndef MSG_PEEK -# define MSG_PEEK 0 -#endif - -#ifndef POLLRDNORM -# define POLLRDNORM 0 -# define POLLRDBAND 0 -# define POLLWRNORM 0 -# define POLLWRBAND 0 -#endif - -static BOOL IsConsoleHandle (HANDLE h) -{ - DWORD mode; - return GetConsoleMode (h, &mode) != 0; -} - -static BOOL IsSocketHandle (HANDLE h) -{ - WSANETWORKEVENTS ev; - - if (IsConsoleHandle (h)) return FALSE; - - /* Under Wine, it seems that getsockopt returns 0 for pipes too. - WSAEnumNetworkEvents instead distinguishes the two correctly. */ - ev.lNetworkEvents = 0xDEADBEEF; - WSAEnumNetworkEvents ((SOCKET) h, NULL, &ev); - return ev.lNetworkEvents != 0xDEADBEEF; -} - -/* Declare data structures for ntdll functions. */ -typedef struct _FILE_PIPE_LOCAL_INFORMATION -{ - ULONG NamedPipeType; - ULONG NamedPipeConfiguration; - ULONG MaximumInstances; - ULONG CurrentInstances; - ULONG InboundQuota; - ULONG ReadDataAvailable; - ULONG OutboundQuota; - ULONG WriteQuotaAvailable; - ULONG NamedPipeState; - ULONG NamedPipeEnd; -} FILE_PIPE_LOCAL_INFORMATION, *PFILE_PIPE_LOCAL_INFORMATION; - -typedef struct _IO_STATUS_BLOCK -{ - union - { - DWORD Status; - PVOID Pointer; - } u; - /*ULONG_PTR Information;*/ - ULONG* Information; -} IO_STATUS_BLOCK, *PIO_STATUS_BLOCK; - -typedef enum _FILE_INFORMATION_CLASS -{ - FilePipeLocalInformation = 24 -} FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS; - -typedef DWORD (WINAPI *PNtQueryInformationFile) (HANDLE, IO_STATUS_BLOCK *, VOID *, ULONG, FILE_INFORMATION_CLASS); - -# ifndef PIPE_BUF -# define PIPE_BUF 512 -# endif - -/* Compute revents values for file handle H. If some events cannot happen - for the handle, eliminate them from *P_SOUGHT. */ - -static int windows_compute_revents (HANDLE h, int *p_sought) -{ - int i, ret, happened; - INPUT_RECORD *irbuffer; - DWORD avail, nbuffer; - BOOL bRet; - IO_STATUS_BLOCK iosb; - FILE_PIPE_LOCAL_INFORMATION fpli; - static PNtQueryInformationFile NtQueryInformationFile; - static BOOL once_only; - - switch (GetFileType (h)) - { - case FILE_TYPE_PIPE: - if (!once_only) - { - NtQueryInformationFile = (PNtQueryInformationFile) - GetProcAddress (GetModuleHandle(TEXT("ntdll.dll")), "NtQueryInformationFile"); - once_only = TRUE; - } - - happened = 0; - if (PeekNamedPipe(h, NULL, 0, NULL, &avail, NULL) != 0) - { - if (avail) - happened |= *p_sought & (POLLIN | POLLRDNORM); - } - else if (GetLastError () == ERROR_BROKEN_PIPE) - happened |= POLLHUP; - - else - { - /* It was the write-end of the pipe. Check if it is writable. - If NtQueryInformationFile fails, optimistically assume the pipe is - writable. This could happen on Windows 9x, where - NtQueryInformationFile is not available, or if we inherit a pipe - that doesn't permit FILE_READ_ATTRIBUTES access on the write end - (I think this should not happen since Windows XP SP2; WINE seems - fine too). Otherwise, ensure that enough space is available for - atomic writes. */ - memset (&iosb, 0, sizeof (iosb)); - memset (&fpli, 0, sizeof (fpli)); - - if (!NtQueryInformationFile - || NtQueryInformationFile (h, &iosb, &fpli, sizeof (fpli), FilePipeLocalInformation) - || fpli.WriteQuotaAvailable >= PIPE_BUF - || (fpli.OutboundQuota < PIPE_BUF && fpli.WriteQuotaAvailable == fpli.OutboundQuota)) - { - happened |= *p_sought & (POLLOUT | POLLWRNORM | POLLWRBAND); - } - } - return happened; - - case FILE_TYPE_CHAR: - ret = WaitForSingleObject (h, 0); - if (!IsConsoleHandle (h)) - return ret == WAIT_OBJECT_0 ? *p_sought & ~(POLLPRI | POLLRDBAND) : 0; - - nbuffer = avail = 0; - bRet = GetNumberOfConsoleInputEvents (h, &nbuffer); - if (bRet) - { - /* Input buffer. */ - *p_sought &= POLLIN | POLLRDNORM; - if (nbuffer == 0) - return POLLHUP; - if (!*p_sought) - return 0; - - irbuffer = (INPUT_RECORD *)_alloca(nbuffer * sizeof (INPUT_RECORD)); - bRet = PeekConsoleInput(h, irbuffer, nbuffer, &avail); - if (!bRet || avail == 0) - return POLLHUP; - - for (i = 0; i < avail; i++) - if (irbuffer[i].EventType == KEY_EVENT) - return *p_sought; - return 0; - } - else - { - /* Screen buffer. */ - *p_sought &= POLLOUT | POLLWRNORM | POLLWRBAND; - return *p_sought; - } - - default: - ret = WaitForSingleObject (h, 0); - if (ret == WAIT_OBJECT_0) - return *p_sought & ~(POLLPRI | POLLRDBAND); - - return *p_sought & (POLLOUT | POLLWRNORM | POLLWRBAND); - } -} - -/* Convert fd_sets returned by select into revents values. */ - -static int windows_compute_revents_socket (SOCKET h, int sought, long lNetworkEvents) -{ - int happened = 0; - - if ((lNetworkEvents & (FD_READ | FD_ACCEPT | FD_CLOSE)) == FD_ACCEPT) - happened |= (POLLIN | POLLRDNORM) & sought; - - else if (lNetworkEvents & (FD_READ | FD_ACCEPT | FD_CLOSE)) - { - int r, error; - - char data[64]; - WSASetLastError (0); - r = recv (h, data, sizeof (data), MSG_PEEK); - error = WSAGetLastError (); - WSASetLastError (0); - - if (r > 0 || error == WSAENOTCONN) - happened |= (POLLIN | POLLRDNORM) & sought; - - /* Distinguish hung-up sockets from other errors. */ - else if (r == 0 || error == WSAESHUTDOWN || error == WSAECONNRESET - || error == WSAECONNABORTED || error == WSAENETRESET) - happened |= POLLHUP; - - else - happened |= POLLERR; - } - - if (lNetworkEvents & (FD_WRITE | FD_CONNECT)) - happened |= (POLLOUT | POLLWRNORM | POLLWRBAND) & sought; - - if (lNetworkEvents & FD_OOB) - happened |= (POLLPRI | POLLRDBAND) & sought; - - return happened; -} - - -int poll (struct pollfd *pfd, nfds_t nfd, int timeout) -{ - static struct timeval tv0; - static HANDLE hEvent; - WSANETWORKEVENTS ev; - HANDLE h, handle_array[FD_SETSIZE + 2]; - DWORD ret, wait_timeout, nhandles; - fd_set rfds, wfds, xfds; - BOOL poll_again; - MSG msg; - int rc = 0; - nfds_t i; - - if (nfd < 0 || timeout < -1) - { - errno = EINVAL; - return -1; - } - - if (!hEvent) - hEvent = CreateEvent (NULL, FALSE, FALSE, NULL); - -restart: - handle_array[0] = hEvent; - nhandles = 1; - FD_ZERO (&rfds); - FD_ZERO (&wfds); - FD_ZERO (&xfds); - - /* Classify socket handles and create fd sets. */ - for (i = 0; i < nfd; i++) - { - int sought = pfd[i].events; - pfd[i].revents = 0; - if (pfd[i].fd < 0) continue; - if (!(sought & (POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM | POLLWRBAND | POLLPRI | POLLRDBAND))) continue; - - h = (HANDLE)_get_osfhandle(pfd[i].fd); - if (IsSocketHandle (h)) - { - int requested = FD_CLOSE; - - /* see above; socket handles are mapped onto select. */ - if (sought & (POLLIN | POLLRDNORM)) - { - requested |= FD_READ | FD_ACCEPT; - FD_SET ((SOCKET) h, &rfds); - } - if (sought & (POLLOUT | POLLWRNORM | POLLWRBAND)) - { - requested |= FD_WRITE | FD_CONNECT; - FD_SET ((SOCKET) h, &wfds); - } - if (sought & (POLLPRI | POLLRDBAND)) - { - requested |= FD_OOB; - FD_SET ((SOCKET) h, &xfds); - } - - if (requested) - WSAEventSelect ((SOCKET) h, hEvent, requested); - } - else - { - /* Poll now. If we get an event, do not poll again. Also, - screen buffer handles are waitable, and they'll block until - a character is available. windows_compute_revents eliminates - bits for the "wrong" direction. */ - pfd[i].revents = windows_compute_revents (h, &sought); - if (sought) handle_array[nhandles++] = h; - if (pfd[i].revents) timeout = 0; - } - } - - if (select(0, &rfds, &wfds, &xfds, &tv0) > 0) - { - /* Do MsgWaitForMultipleObjects anyway to dispatch messages, but - no need to call select again. */ - poll_again = FALSE; - wait_timeout = 0; - } - else - { - poll_again = TRUE; - if (timeout == INFTIM) - wait_timeout = INFINITE; - else - wait_timeout = timeout; - } - - for (;;) - { - ret = MsgWaitForMultipleObjects(nhandles, handle_array, FALSE, wait_timeout, QS_ALLINPUT); - - if (ret == WAIT_OBJECT_0 + nhandles) - { - /* new input of some other kind */ - BOOL bRet; - while ((bRet = PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) != 0) - { - TranslateMessage (&msg); - DispatchMessage (&msg); - } - } - else - break; - } - - if (poll_again) - select (0, &rfds, &wfds, &xfds, &tv0); - - /* Place a sentinel at the end of the array. */ - handle_array[nhandles] = NULL; - nhandles = 1; - for (i = 0; i < nfd; i++) - { - int happened; - - if (pfd[i].fd < 0) - continue; - if (!(pfd[i].events & (POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM | POLLWRBAND))) - continue; - - h = (HANDLE) _get_osfhandle (pfd[i].fd); - if (h != handle_array[nhandles]) - { - /* It's a socket. */ - WSAEnumNetworkEvents ((SOCKET) h, NULL, &ev); - WSAEventSelect ((SOCKET) h, 0, 0); - - /* If we're lucky, WSAEnumNetworkEvents already provided a way - to distinguish FD_READ and FD_ACCEPT; this saves a recv later. */ - if (FD_ISSET ((SOCKET) h, &rfds) && !(ev.lNetworkEvents & (FD_READ | FD_ACCEPT))) - ev.lNetworkEvents |= FD_READ | FD_ACCEPT; - if (FD_ISSET ((SOCKET) h, &wfds)) - ev.lNetworkEvents |= FD_WRITE | FD_CONNECT; - if (FD_ISSET ((SOCKET) h, &xfds)) - ev.lNetworkEvents |= FD_OOB; - - happened = windows_compute_revents_socket ((SOCKET) h, pfd[i].events, ev.lNetworkEvents); - } - else - { - /* Not a socket. */ - int sought = pfd[i].events; - happened = windows_compute_revents (h, &sought); - nhandles++; - } - - if ((pfd[i].revents |= happened) != 0) rc++; - } - - if (!rc && timeout == INFTIM) - { - SleepEx (1, TRUE); - goto restart; - } - - return rc; -} +/* Emulation for poll(2) + Contributed by Paolo Bonzini. + + Copyright 2001-2003, 2006-2016 Free Software Foundation, Inc. + + This file is part of gnulib. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, see . */ + +/* Tell gcc not to warn about the (nfd < 0) tests, below. */ +#if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__ +# pragma GCC diagnostic ignored "-Wtype-limits" +#endif + +#include +#include + +#include "poll-msw.h" + +#include +#include +#include +#include + +#if defined(__BORLANDC__) +# include +# define _alloca alloca +#endif + +#ifndef INFTIM +# define INFTIM (-1) +#endif + +/* BeOS does not have MSG_PEEK. */ +#ifndef MSG_PEEK +# define MSG_PEEK 0 +#endif + +#ifndef POLLRDNORM +# define POLLRDNORM 0 +# define POLLRDBAND 0 +# define POLLWRNORM 0 +# define POLLWRBAND 0 +#endif + +static BOOL IsConsoleHandle (HANDLE h) +{ + DWORD mode; + return GetConsoleMode (h, &mode) != 0; +} + +static BOOL IsSocketHandle (HANDLE h) +{ + WSANETWORKEVENTS ev; + + if (IsConsoleHandle (h)) return FALSE; + + /* Under Wine, it seems that getsockopt returns 0 for pipes too. + WSAEnumNetworkEvents instead distinguishes the two correctly. */ + ev.lNetworkEvents = 0xDEADBEEF; + WSAEnumNetworkEvents ((SOCKET) h, NULL, &ev); + return ev.lNetworkEvents != 0xDEADBEEF; +} + +/* Declare data structures for ntdll functions. */ +typedef struct _FILE_PIPE_LOCAL_INFORMATION +{ + ULONG NamedPipeType; + ULONG NamedPipeConfiguration; + ULONG MaximumInstances; + ULONG CurrentInstances; + ULONG InboundQuota; + ULONG ReadDataAvailable; + ULONG OutboundQuota; + ULONG WriteQuotaAvailable; + ULONG NamedPipeState; + ULONG NamedPipeEnd; +} FILE_PIPE_LOCAL_INFORMATION, *PFILE_PIPE_LOCAL_INFORMATION; + +typedef struct _IO_STATUS_BLOCK +{ + union + { + DWORD Status; + PVOID Pointer; + } u; + /*ULONG_PTR Information;*/ + ULONG* Information; +} IO_STATUS_BLOCK, *PIO_STATUS_BLOCK; + +typedef enum _FILE_INFORMATION_CLASS +{ + FilePipeLocalInformation = 24 +} FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS; + +typedef DWORD (WINAPI *PNtQueryInformationFile) (HANDLE, IO_STATUS_BLOCK *, VOID *, ULONG, FILE_INFORMATION_CLASS); + +# ifndef PIPE_BUF +# define PIPE_BUF 512 +# endif + +/* Compute revents values for file handle H. If some events cannot happen + for the handle, eliminate them from *P_SOUGHT. */ + +static int windows_compute_revents (HANDLE h, int *p_sought) +{ + int i, ret, happened; + INPUT_RECORD *irbuffer; + DWORD avail, nbuffer; + BOOL bRet; + IO_STATUS_BLOCK iosb; + FILE_PIPE_LOCAL_INFORMATION fpli; + static PNtQueryInformationFile NtQueryInformationFile; + static BOOL once_only; + + switch (GetFileType (h)) + { + case FILE_TYPE_PIPE: + if (!once_only) + { + NtQueryInformationFile = (PNtQueryInformationFile) + GetProcAddress (GetModuleHandle(TEXT("ntdll.dll")), "NtQueryInformationFile"); + once_only = TRUE; + } + + happened = 0; + if (PeekNamedPipe(h, NULL, 0, NULL, &avail, NULL) != 0) + { + if (avail) + happened |= *p_sought & (POLLIN | POLLRDNORM); + } + else if (GetLastError () == ERROR_BROKEN_PIPE) + happened |= POLLHUP; + + else + { + /* It was the write-end of the pipe. Check if it is writable. + If NtQueryInformationFile fails, optimistically assume the pipe is + writable. This could happen on Windows 9x, where + NtQueryInformationFile is not available, or if we inherit a pipe + that doesn't permit FILE_READ_ATTRIBUTES access on the write end + (I think this should not happen since Windows XP SP2; WINE seems + fine too). Otherwise, ensure that enough space is available for + atomic writes. */ + memset (&iosb, 0, sizeof (iosb)); + memset (&fpli, 0, sizeof (fpli)); + + if (!NtQueryInformationFile + || NtQueryInformationFile (h, &iosb, &fpli, sizeof (fpli), FilePipeLocalInformation) + || fpli.WriteQuotaAvailable >= PIPE_BUF + || (fpli.OutboundQuota < PIPE_BUF && fpli.WriteQuotaAvailable == fpli.OutboundQuota)) + { + happened |= *p_sought & (POLLOUT | POLLWRNORM | POLLWRBAND); + } + } + return happened; + + case FILE_TYPE_CHAR: + ret = WaitForSingleObject (h, 0); + if (!IsConsoleHandle (h)) + return ret == WAIT_OBJECT_0 ? *p_sought & ~(POLLPRI | POLLRDBAND) : 0; + + nbuffer = avail = 0; + bRet = GetNumberOfConsoleInputEvents (h, &nbuffer); + if (bRet) + { + /* Input buffer. */ + *p_sought &= POLLIN | POLLRDNORM; + if (nbuffer == 0) + return POLLHUP; + if (!*p_sought) + return 0; + + irbuffer = (INPUT_RECORD *)_alloca(nbuffer * sizeof (INPUT_RECORD)); + bRet = PeekConsoleInput(h, irbuffer, nbuffer, &avail); + if (!bRet || avail == 0) + return POLLHUP; + + for (i = 0; i < avail; i++) + if (irbuffer[i].EventType == KEY_EVENT) + return *p_sought; + return 0; + } + else + { + /* Screen buffer. */ + *p_sought &= POLLOUT | POLLWRNORM | POLLWRBAND; + return *p_sought; + } + + default: + ret = WaitForSingleObject (h, 0); + if (ret == WAIT_OBJECT_0) + return *p_sought & ~(POLLPRI | POLLRDBAND); + + return *p_sought & (POLLOUT | POLLWRNORM | POLLWRBAND); + } +} + +/* Convert fd_sets returned by select into revents values. */ + +static int windows_compute_revents_socket (SOCKET h, int sought, long lNetworkEvents) +{ + int happened = 0; + + if ((lNetworkEvents & (FD_READ | FD_ACCEPT | FD_CLOSE)) == FD_ACCEPT) + happened |= (POLLIN | POLLRDNORM) & sought; + + else if (lNetworkEvents & (FD_READ | FD_ACCEPT | FD_CLOSE)) + { + int r, error; + + char data[64]; + WSASetLastError (0); + r = recv (h, data, sizeof (data), MSG_PEEK); + error = WSAGetLastError (); + WSASetLastError (0); + + if (r > 0 || error == WSAENOTCONN) + happened |= (POLLIN | POLLRDNORM) & sought; + + /* Distinguish hung-up sockets from other errors. */ + else if (r == 0 || error == WSAESHUTDOWN || error == WSAECONNRESET + || error == WSAECONNABORTED || error == WSAENETRESET) + happened |= POLLHUP; + + else + happened |= POLLERR; + } + + if (lNetworkEvents & (FD_WRITE | FD_CONNECT)) + happened |= (POLLOUT | POLLWRNORM | POLLWRBAND) & sought; + + if (lNetworkEvents & FD_OOB) + happened |= (POLLPRI | POLLRDBAND) & sought; + + return happened; +} + + +int poll (struct pollfd *pfd, nfds_t nfd, int timeout) +{ + static struct timeval tv0; + static HANDLE hEvent; + WSANETWORKEVENTS ev; + HANDLE h, handle_array[FD_SETSIZE + 2]; + DWORD ret, wait_timeout, nhandles; + fd_set rfds, wfds, xfds; + BOOL poll_again; + MSG msg; + int rc = 0; + nfds_t i; + + if (nfd < 0 || timeout < -1) + { + errno = EINVAL; + return -1; + } + + if (!hEvent) + hEvent = CreateEvent (NULL, FALSE, FALSE, NULL); + +restart: + handle_array[0] = hEvent; + nhandles = 1; + FD_ZERO (&rfds); + FD_ZERO (&wfds); + FD_ZERO (&xfds); + + /* Classify socket handles and create fd sets. */ + for (i = 0; i < nfd; i++) + { + int sought = pfd[i].events; + pfd[i].revents = 0; + if (pfd[i].fd < 0) continue; + if (!(sought & (POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM | POLLWRBAND | POLLPRI | POLLRDBAND))) continue; + + h = (HANDLE)_get_osfhandle(pfd[i].fd); + if (IsSocketHandle (h)) + { + int requested = FD_CLOSE; + + /* see above; socket handles are mapped onto select. */ + if (sought & (POLLIN | POLLRDNORM)) + { + requested |= FD_READ | FD_ACCEPT; + FD_SET ((SOCKET) h, &rfds); + } + if (sought & (POLLOUT | POLLWRNORM | POLLWRBAND)) + { + requested |= FD_WRITE | FD_CONNECT; + FD_SET ((SOCKET) h, &wfds); + } + if (sought & (POLLPRI | POLLRDBAND)) + { + requested |= FD_OOB; + FD_SET ((SOCKET) h, &xfds); + } + + if (requested) + WSAEventSelect ((SOCKET) h, hEvent, requested); + } + else + { + /* Poll now. If we get an event, do not poll again. Also, + screen buffer handles are waitable, and they'll block until + a character is available. windows_compute_revents eliminates + bits for the "wrong" direction. */ + pfd[i].revents = windows_compute_revents (h, &sought); + if (sought) handle_array[nhandles++] = h; + if (pfd[i].revents) timeout = 0; + } + } + + if (select(0, &rfds, &wfds, &xfds, &tv0) > 0) + { + /* Do MsgWaitForMultipleObjects anyway to dispatch messages, but + no need to call select again. */ + poll_again = FALSE; + wait_timeout = 0; + } + else + { + poll_again = TRUE; + if (timeout == INFTIM) + wait_timeout = INFINITE; + else + wait_timeout = timeout; + } + + for (;;) + { + ret = MsgWaitForMultipleObjects(nhandles, handle_array, FALSE, wait_timeout, QS_ALLINPUT); + + if (ret == WAIT_OBJECT_0 + nhandles) + { + /* new input of some other kind */ + BOOL bRet; + while ((bRet = PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) != 0) + { + TranslateMessage (&msg); + DispatchMessage (&msg); + } + } + else + break; + } + + if (poll_again) + select (0, &rfds, &wfds, &xfds, &tv0); + + /* Place a sentinel at the end of the array. */ + handle_array[nhandles] = NULL; + nhandles = 1; + for (i = 0; i < nfd; i++) + { + int happened; + + if (pfd[i].fd < 0) + continue; + if (!(pfd[i].events & (POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM | POLLWRBAND))) + continue; + + h = (HANDLE) _get_osfhandle (pfd[i].fd); + if (h != handle_array[nhandles]) + { + /* It's a socket. */ + WSAEnumNetworkEvents ((SOCKET) h, NULL, &ev); + WSAEventSelect ((SOCKET) h, 0, 0); + + /* If we're lucky, WSAEnumNetworkEvents already provided a way + to distinguish FD_READ and FD_ACCEPT; this saves a recv later. */ + if (FD_ISSET ((SOCKET) h, &rfds) && !(ev.lNetworkEvents & (FD_READ | FD_ACCEPT))) + ev.lNetworkEvents |= FD_READ | FD_ACCEPT; + if (FD_ISSET ((SOCKET) h, &wfds)) + ev.lNetworkEvents |= FD_WRITE | FD_CONNECT; + if (FD_ISSET ((SOCKET) h, &xfds)) + ev.lNetworkEvents |= FD_OOB; + + happened = windows_compute_revents_socket ((SOCKET) h, pfd[i].events, ev.lNetworkEvents); + } + else + { + /* Not a socket. */ + int sought = pfd[i].events; + happened = windows_compute_revents (h, &sought); + nhandles++; + } + + if ((pfd[i].revents |= happened) != 0) rc++; + } + + if (!rc && timeout == INFTIM) + { + SleepEx (1, TRUE); + goto restart; + } + + return rc; +} diff --git a/lib/poll-msw.h b/lib/poll-msw.h index b8aac9c..73169fb 100644 --- a/lib/poll-msw.h +++ b/lib/poll-msw.h @@ -1,49 +1,49 @@ -#ifndef _POLL_MSW_H_ -#define _POLL_MSW_H_ - -#include - -#if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0600) -/* Event types that can be polled for. These bits may be set in `events' - to indicate the interesting event types; they will appear in `revents' - to indicate the status of the file descriptor. */ -#define POLLIN 0x001 /* There is data to read. */ -#define POLLPRI 0x002 /* There is urgent data to read. */ -#define POLLOUT 0x004 /* Writing now will not block. */ - -/* Event types always implicitly polled for. These bits need not be set in - `events', but they will appear in `revents' to indicate the status of - the file descriptor. */ -#define POLLERR 0x008 /* Error condition. */ -#define POLLHUP 0x010 /* Hung up. */ -#define POLLNVAL 0x020 /* Invalid polling request. */ - -/* Data structure describing a polling request. */ -struct pollfd -{ - int fd; /* File descriptor to poll. */ - short int events; /* Types of events poller cares about. */ - short int revents; /* Types of events that actually occurred. */ -}; - -/* Poll the file descriptors described by the NFDS structures starting at - FDS. If TIMEOUT is nonzero and not -1, allow TIMEOUT milliseconds for - an event to occur; if TIMEOUT is -1, block until an event occurs. - Returns the number of file descriptors with events, zero if timed out, - or -1 for errors. */ -#endif - -typedef unsigned long nfds_t; - - -#if defined(__cplusplus) -extern "C" { -#endif - -int poll (struct pollfd *pfd, nfds_t nfd, int timeout); - -#if defined(__cplusplus) -} -#endif - -#endif +#ifndef _POLL_MSW_H_ +#define _POLL_MSW_H_ + +#include + +#if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0600) +/* Event types that can be polled for. These bits may be set in `events' + to indicate the interesting event types; they will appear in `revents' + to indicate the status of the file descriptor. */ +#define POLLIN 0x001 /* There is data to read. */ +#define POLLPRI 0x002 /* There is urgent data to read. */ +#define POLLOUT 0x004 /* Writing now will not block. */ + +/* Event types always implicitly polled for. These bits need not be set in + `events', but they will appear in `revents' to indicate the status of + the file descriptor. */ +#define POLLERR 0x008 /* Error condition. */ +#define POLLHUP 0x010 /* Hung up. */ +#define POLLNVAL 0x020 /* Invalid polling request. */ + +/* Data structure describing a polling request. */ +struct pollfd +{ + int fd; /* File descriptor to poll. */ + short int events; /* Types of events poller cares about. */ + short int revents; /* Types of events that actually occurred. */ +}; + +/* Poll the file descriptors described by the NFDS structures starting at + FDS. If TIMEOUT is nonzero and not -1, allow TIMEOUT milliseconds for + an event to occur; if TIMEOUT is -1, block until an event occurs. + Returns the number of file descriptors with events, zero if timed out, + or -1 for errors. */ +#endif + +typedef unsigned long nfds_t; + + +#if defined(__cplusplus) +extern "C" { +#endif + +int poll (struct pollfd *pfd, nfds_t nfd, int timeout); + +#if defined(__cplusplus) +} +#endif + +#endif diff --git a/lib/sym.c b/lib/sym.c index 0c6a72d..e81762a 100644 --- a/lib/sym.c +++ b/lib/sym.c @@ -42,13 +42,13 @@ static moo_oop_oop_t expand_bucket (moo_t* moo, moo_oop_oop_t oldbuc) else if (oldsz < 400000) newsz = oldsz + (oldsz / 16); else if (oldsz < 800000) newsz = oldsz + (oldsz / 32); else if (oldsz < 1600000) newsz = oldsz + (oldsz / 64); - else + else { moo_oow_t inc, inc_max; inc = oldsz / 128; inc_max = MOO_OBJ_SIZE_MAX - oldsz; - if (inc > inc_max) + if (inc > inc_max) { if (inc_max > 0) inc = inc_max; else @@ -61,7 +61,7 @@ static moo_oop_oop_t expand_bucket (moo_t* moo, moo_oop_oop_t oldbuc) } moo_pushvolat (moo, (moo_oop_t*)&oldbuc); - newbuc = (moo_oop_oop_t)moo_instantiate(moo, moo->_array, MOO_NULL, newsz); + newbuc = (moo_oop_oop_t)moo_instantiate(moo, moo->_array, MOO_NULL, newsz); moo_popvolat (moo); if (!newbuc) return MOO_NULL; @@ -94,7 +94,7 @@ static moo_oop_t find_or_make_symbol (moo_t* moo, const moo_ooch_t* ptr, moo_oow index = moo_hash_oochars(ptr, len) % MOO_OBJ_GET_SIZE(moo->symtab->bucket); /* find a matching symbol in the open-addressed symbol table */ - while ((moo_oop_t)(symbol = (moo_oop_char_t)MOO_OBJ_GET_OOP_VAL(moo->symtab->bucket, index)) != moo->_nil) + while ((moo_oop_t)(symbol = (moo_oop_char_t)MOO_OBJ_GET_OOP_VAL(moo->symtab->bucket, index)) != moo->_nil) { MOO_ASSERT (moo, MOO_CLASSOF(moo,symbol) == moo->_symbol); @@ -107,7 +107,7 @@ static moo_oop_t find_or_make_symbol (moo_t* moo, const moo_ooch_t* ptr, moo_oow index = (index + 1) % MOO_OBJ_GET_SIZE(moo->symtab->bucket); } - if (!create) + if (!create) { moo_seterrnum (moo, MOO_ENOENT); return MOO_NULL; @@ -118,7 +118,7 @@ static moo_oop_t find_or_make_symbol (moo_t* moo, const moo_ooch_t* ptr, moo_oow tally = MOO_OOP_TO_SMOOI(moo->symtab->tally); if (tally >= MOO_SMOOI_MAX) { - /* this built-in table is not allowed to hold more than + /* this built-in table is not allowed to hold more than * MOO_SMOOI_MAX items for efficiency sake */ moo_seterrbfmt (moo, MOO_EDFULL, "unable to add a symbol %.*js - symbol table full", len, ptr); return MOO_NULL; @@ -126,7 +126,7 @@ static moo_oop_t find_or_make_symbol (moo_t* moo, const moo_ooch_t* ptr, moo_oow /* no conversion to moo_oow_t is necessary for tally + 1. * the maximum value of tally is checked to be MOO_SMOOI_MAX - 1. - * tally + 1 can produce at most MOO_SMOOI_MAX. above all, + * tally + 1 can produce at most MOO_SMOOI_MAX. above all, * MOO_SMOOI_MAX is way smaller than MOO_TYPE_MAX(moo_ooi_t). */ if (tally + 1 >= MOO_OBJ_GET_SIZE(moo->symtab->bucket)) { @@ -148,7 +148,7 @@ static moo_oop_t find_or_make_symbol (moo_t* moo, const moo_ooch_t* ptr, moo_oow /* recalculate the index for the expanded bucket */ index = moo_hash_oochars(ptr, len) % MOO_OBJ_GET_SIZE(moo->symtab->bucket); - while (MOO_OBJ_GET_OOP_VAL(moo->symtab->bucket, index) != moo->_nil) + while (MOO_OBJ_GET_OOP_VAL(moo->symtab->bucket, index) != moo->_nil) index = (index + 1) % MOO_OBJ_GET_SIZE(moo->symtab->bucket); } diff --git a/lib/utf16.c b/lib/utf16.c index 24ced11..ef49c51 100644 --- a/lib/utf16.c +++ b/lib/utf16.c @@ -40,13 +40,13 @@ moo_oow_t moo_uc_to_utf16 (moo_uch_t uc, moo_bch_t* utf16, moo_oow_t size) { moo_uint16_t* u16 = (moo_uint16_t*)utf16; - if (uc <= 0xFFFF) + if (uc <= 0xFFFF) { u16[0] = (moo_uint16_t)uc; return 2; } #if (MOO_SIZEOF_UCH_T > 2) - else if (uc <= 0x10FFFF) + else if (uc <= 0x10FFFF) { u16[0] = HIGH_SURROGATE_START | (((uc >> 16) & 0x1F) - 1) | (uc >> 10); u16[1] = LOW_SURROGATE_START | (uc & 0x3FF); @@ -63,7 +63,7 @@ moo_oow_t moo_utf16_to_uc (const moo_bch_t* utf16, moo_oow_t size, moo_uch_t* uc if (size < 2) return 0; /* incomplete sequence */ - if (u16[0] < HIGH_SURROGATE_START || u16[0] > LOW_SURROGATE_END) + if (u16[0] < HIGH_SURROGATE_START || u16[0] > LOW_SURROGATE_END) { /* BMP - U+0000 - U+D7FF, U+E000 - U+FFFF */ *uc = u16[0]; diff --git a/lib/utf8.c b/lib/utf8.c index 0afc7a6..7e395bf 100644 --- a/lib/utf8.c +++ b/lib/utf8.c @@ -58,7 +58,7 @@ struct __utf8_t typedef struct __utf8_t __utf8_t; -static __utf8_t utf8_table[] = +static __utf8_t utf8_table[] = { {0x00000000ul, 0x0000007Ful, 0x00, 0x80, 0x7F, 1}, {0x00000080ul, 0x000007FFul, 0xC0, 0xE0, 0x1F, 2}, @@ -82,7 +82,7 @@ static MOO_INLINE __utf8_t* get_utf8_slot (moo_uch_t uc) end = utf8_table + MOO_COUNTOF(utf8_table); cur = utf8_table; - while (cur < end) + while (cur < end) { if (uc >= cur->lower && uc <= cur->upper) return cur; cur++; @@ -100,7 +100,7 @@ moo_oow_t moo_uc_to_utf8 (moo_uch_t uc, moo_bch_t* utf8, moo_oow_t size) if (utf8 && cur->length <= size) { int index = cur->length; - while (index > 1) + while (index > 1) { /* * 0x3F: 00111111 @@ -130,16 +130,16 @@ moo_oow_t moo_utf8_to_uc (const moo_bch_t* utf8, moo_oow_t size, moo_uch_t* uc) end = utf8_table + MOO_COUNTOF(utf8_table); cur = utf8_table; - while (cur < end) + while (cur < end) { - if ((utf8[0] & cur->mask) == cur->fbyte) + if ((utf8[0] & cur->mask) == cur->fbyte) { - /* if size is less that cur->length, the incomplete-seqeunce + /* if size is less that cur->length, the incomplete-seqeunce * error is naturally indicated. so validate the string * only if size is as large as cur->length. */ - if (size >= cur->length) + if (size >= cur->length) { int i; @@ -151,12 +151,12 @@ moo_oow_t moo_utf8_to_uc (const moo_bch_t* utf8, moo_oow_t size, moo_uch_t* uc) for (i = 1; i < cur->length; i++) { /* in utf8, trailing bytes are all - * set with 0x80. + * set with 0x80. * * 10XXXXXX & 11000000 => 10000000 * * if not, invalid. */ - if ((utf8[i] & 0xC0) != 0x80) return 0; + if ((utf8[i] & 0xC0) != 0x80) return 0; w = (w << 6) | (utf8[i] & 0x3F); } *uc = w; @@ -166,19 +166,19 @@ moo_oow_t moo_utf8_to_uc (const moo_bch_t* utf8, moo_oow_t size, moo_uch_t* uc) for (i = 1; i < cur->length; i++) { /* in utf8, trailing bytes are all - * set with 0x80. + * set with 0x80. * * 10XXXXXX & 11000000 => 10000000 * * if not, invalid. */ - if ((utf8[i] & 0xC0) != 0x80) return 0; + if ((utf8[i] & 0xC0) != 0x80) return 0; } } } - /* this return value can indicate both - * the correct length (size >= cur->length) - * and + /* this return value can indicate both + * the correct length (size >= cur->length) + * and * the incomplete seqeunce error (size < cur->length). */ return (moo_oow_t)cur->length; diff --git a/lib/utl.c b/lib/utl.c index 1ab6619..aed7375 100644 --- a/lib/utl.c +++ b/lib/utl.c @@ -31,10 +31,10 @@ int moo_log2_for_pow2 (moo_oow_t pow2v) { #if defined(MOO_HAVE_UINT32_T) && (MOO_SIZEOF_OOW_T == 4) - static const int debruijn[32] = + static const int debruijn[32] = { 0, 1, 28, 2, 29, 14, 24, 3, - 30, 22, 20, 15, 25, 17, 4, 8, + 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9 }; @@ -43,7 +43,7 @@ int moo_log2_for_pow2 (moo_oow_t pow2v) #elif defined(MOO_HAVE_UINT64_T) && (MOO_SIZEOF_OOW_T == 8) - static const int debruijn[64] = + static const int debruijn[64] = { 0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28, @@ -126,7 +126,7 @@ int moo_comp_uchars (const moo_uch_t* str1, moo_oow_t len1, const moo_uch_t* str while (str1 < end1) { c1 = *str1; - if (str2 < end2) + if (str2 < end2) { c2 = *str2; if (c1 > c2) return 1; @@ -148,7 +148,7 @@ int moo_comp_bchars (const moo_bch_t* str1, moo_oow_t len1, const moo_bch_t* str while (str1 < end1) { c1 = *str1; - if (str2 < end2) + if (str2 < end2) { c2 = *str2; if (c1 > c2) return 1; @@ -198,10 +198,10 @@ int moo_comp_uchars_ucstr (const moo_uch_t* str1, moo_oow_t len, const moo_uch_t { /* for "abc\0" of length 4 vs "abc", the fourth character * of the first string is equal to the terminating null of - * the second string. the first string is still considered + * the second string. the first string is still considered * bigger */ const moo_uch_t* end = str1 + len; - while (str1 < end && *str2 != '\0') + while (str1 < end && *str2 != '\0') { if (*str1 != *str2) return ((moo_uchu_t)*str1 > (moo_uchu_t)*str2)? 1: -1; str1++; str2++; @@ -212,7 +212,7 @@ int moo_comp_uchars_ucstr (const moo_uch_t* str1, moo_oow_t len, const moo_uch_t int moo_comp_uchars_bcstr (const moo_uch_t* str1, moo_oow_t len, const moo_bch_t* str2) { const moo_uch_t* end = str1 + len; - while (str1 < end && *str2 != '\0') + while (str1 < end && *str2 != '\0') { if (*str1 != *str2) return ((moo_uchu_t)*str1 > (moo_bchu_t)*str2)? 1: -1; str1++; str2++; @@ -223,7 +223,7 @@ int moo_comp_uchars_bcstr (const moo_uch_t* str1, moo_oow_t len, const moo_bch_t int moo_comp_bchars_bcstr (const moo_bch_t* str1, moo_oow_t len, const moo_bch_t* str2) { const moo_bch_t* end = str1 + len; - while (str1 < end && *str2 != '\0') + while (str1 < end && *str2 != '\0') { if (*str1 != *str2) return ((moo_bchu_t)*str1 > (moo_bchu_t)*str2)? 1: -1; str1++; str2++; @@ -234,7 +234,7 @@ int moo_comp_bchars_bcstr (const moo_bch_t* str1, moo_oow_t len, const moo_bch_t int moo_comp_bchars_ucstr (const moo_bch_t* str1, moo_oow_t len, const moo_uch_t* str2) { const moo_bch_t* end = str1 + len; - while (str1 < end && *str2 != '\0') + while (str1 < end && *str2 != '\0') { if (*str1 != *str2) return ((moo_bchu_t)*str1 > (moo_uchu_t)*str2)? 1: -1; str1++; str2++; @@ -560,18 +560,18 @@ moo_oow_t moo_byte_to_ucstr (moo_oob_t byte, moo_uch_t* buf, moo_oow_t size, int radix_char = (flagged_radix & MOO_BYTE_TO_UCSTR_LOWERCASE)? 'a': 'A'; if (radix < 2 || radix > 36 || size <= 0) return 0; - do + do { - moo_oob_t digit = byte % radix; + moo_oob_t digit = byte % radix; if (digit < 10) *p++ = digit + '0'; else *p++ = digit + radix_char - 10; byte /= radix; } while (byte > 0); - if (fill != '\0') + if (fill != '\0') { - while (size - 1 > p - tmp) + while (size - 1 > p - tmp) { *bp++ = fill; size--; @@ -594,18 +594,18 @@ moo_oow_t moo_byte_to_bcstr (moo_oob_t byte, moo_bch_t* buf, moo_oow_t size, int radix_char = (flagged_radix & MOO_BYTE_TO_BCSTR_LOWERCASE)? 'a': 'A'; if (radix < 2 || radix > 36 || size <= 0) return 0; - do + do { - moo_oob_t digit = byte % radix; + moo_oob_t digit = byte % radix; if (digit < 10) *p++ = digit + '0'; else *p++ = digit + radix_char - 10; byte /= radix; } while (byte > 0); - if (fill != '\0') + if (fill != '\0') { - while (size - 1 > p - tmp) + while (size - 1 > p - tmp) { *bp++ = fill; size--; @@ -629,7 +629,7 @@ MOO_INLINE int moo_conv_bchars_to_uchars_with_cmgr ( if (ucs) { - /* destination buffer is specified. + /* destination buffer is specified. * copy the conversion result to the buffer */ moo_uch_t* q, * qend; @@ -693,7 +693,7 @@ MOO_INLINE int moo_conv_bchars_to_uchars_with_cmgr ( /* no destination buffer is specified. perform conversion * but don't copy the result. the caller can call this function * without a buffer to find the required buffer size, allocate - * a buffer with the size and call this function again with + * a buffer with the size and call this function again with * the buffer. */ moo_uch_t w; @@ -769,13 +769,13 @@ MOO_INLINE int moo_conv_uchars_to_bchars_with_cmgr ( { const moo_uch_t* p = ucs; const moo_uch_t* end = ucs + *ucslen; - int ret = 0; + int ret = 0; if (bcs) { moo_oow_t rem = *bcslen; - while (p < end) + while (p < end) { moo_oow_t n; @@ -786,12 +786,12 @@ MOO_INLINE int moo_conv_uchars_to_bchars_with_cmgr ( } n = cmgr->uctobc(*p, bcs, rem); - if (n == 0) + if (n == 0) { ret = -1; break; /* illegal character */ } - if (n > rem) + if (n > rem) { ret = -2; /* buffer too small */ break; @@ -799,7 +799,7 @@ MOO_INLINE int moo_conv_uchars_to_bchars_with_cmgr ( bcs += n; rem -= n; p++; } - *bcslen -= rem; + *bcslen -= rem; } else { @@ -811,7 +811,7 @@ MOO_INLINE int moo_conv_uchars_to_bchars_with_cmgr ( moo_oow_t n; n = cmgr->uctobc(*p, bcsbuf, MOO_COUNTOF(bcsbuf)); - if (n == 0) + if (n == 0) { ret = -1; break; /* illegal character */ @@ -823,7 +823,7 @@ MOO_INLINE int moo_conv_uchars_to_bchars_with_cmgr ( p++; mlen += n; } - /* this length excludes the terminating null character. + /* this length excludes the terminating null character. * this function doesn't even null-terminate the result. */ *bcslen = mlen; } @@ -852,14 +852,14 @@ MOO_INLINE int moo_conv_ucstr_to_bcstr_with_cmgr ( ret = -2; break; } - + n = cmgr->uctobc(*p, bcs, rem); - if (n == 0) + if (n == 0) { ret = -1; break; /* illegal character */ } - if (n > rem) + if (n > rem) { ret = -2; break; /* buffer too small */ @@ -870,13 +870,13 @@ MOO_INLINE int moo_conv_ucstr_to_bcstr_with_cmgr ( /* update bcslen to the length of the bcs string converted excluding * terminating null */ - *bcslen -= rem; + *bcslen -= rem; /* null-terminate the multibyte sequence if it has sufficient space */ if (rem > 0) *bcs = '\0'; - else + else { - /* if ret is -2 and cs[cslen] == '\0', + /* if ret is -2 and cs[cslen] == '\0', * this means that the bcs buffer was lacking one * slot for the terminating null */ ret = -2; /* buffer too small */ @@ -892,7 +892,7 @@ MOO_INLINE int moo_conv_ucstr_to_bcstr_with_cmgr ( moo_oow_t n; n = cmgr->uctobc(*p, bcsbuf, MOO_COUNTOF(bcsbuf)); - if (n == 0) + if (n == 0) { ret = -1; break; /* illegal character */ @@ -904,7 +904,7 @@ MOO_INLINE int moo_conv_ucstr_to_bcstr_with_cmgr ( p++; mlen += n; } - /* this length holds the number of resulting multi-byte characters + /* this length holds the number of resulting multi-byte characters * excluding the terminating null character */ *bcslen = mlen; } @@ -1101,7 +1101,7 @@ moo_uch_t* moo_dupbtoucharswithheadroom (moo_t* moo, moo_oow_t headroom_bytes, c moo_uch_t* ptr; inlen = bcslen; - if (moo_convbtouchars(moo, bcs, &inlen, MOO_NULL, &outlen) <= -1) + if (moo_convbtouchars(moo, bcs, &inlen, MOO_NULL, &outlen) <= -1) { /* note it's also an error if no full conversion is made in this function */ return MOO_NULL; @@ -1115,10 +1115,10 @@ moo_uch_t* moo_dupbtoucharswithheadroom (moo_t* moo, moo_oow_t headroom_bytes, c ptr = (moo_uch_t*)((moo_oob_t*)ptr + headroom_bytes); moo_convbtouchars (moo, bcs, &inlen, ptr, &outlen); - /* moo_convbtouchars() doesn't null-terminate the target. + /* moo_convbtouchars() doesn't null-terminate the target. * but in moo_dupbtouchars(), i allocate space. so i don't mind * null-terminating it with 1 extra character overhead */ - ptr[outlen] = '\0'; + ptr[outlen] = '\0'; if (ucslen) *ucslen = outlen; return ptr; } @@ -1129,7 +1129,7 @@ moo_bch_t* moo_duputobcharswithheadroom (moo_t* moo, moo_oow_t headroom_bytes, c moo_bch_t* ptr; inlen = ucslen; - if (moo_convutobchars(moo, ucs, &inlen, MOO_NULL, &outlen) <= -1) + if (moo_convutobchars(moo, ucs, &inlen, MOO_NULL, &outlen) <= -1) { /* note it's also an error if no full conversion is made in this function */ return MOO_NULL; @@ -1154,7 +1154,7 @@ moo_uch_t* moo_dupbtoucstrwithheadroom (moo_t* moo, moo_oow_t headroom_bytes, co moo_oow_t inlen, outlen; moo_uch_t* ptr; - if (moo_convbtoucstr(moo, bcs, &inlen, MOO_NULL, &outlen) <= -1) + if (moo_convbtoucstr(moo, bcs, &inlen, MOO_NULL, &outlen) <= -1) { /* note it's also an error if no full conversion is made in this function */ return MOO_NULL; @@ -1174,7 +1174,7 @@ moo_bch_t* moo_duputobcstrwithheadroom (moo_t* moo, moo_oow_t headroom_bytes, co moo_oow_t inlen, outlen; moo_bch_t* ptr; - if (moo_convutobcstr(moo, ucs, &inlen, MOO_NULL, &outlen) <= -1) + if (moo_convutobcstr(moo, ucs, &inlen, MOO_NULL, &outlen) <= -1) { /* note it's also an error if no full conversion is made in this function */ return MOO_NULL; @@ -1262,7 +1262,7 @@ static MOO_INLINE int secure_space_in_sbuf (moo_t* moo, moo_oow_t req, moo_sbuf_ newcapa = p->len + req + 1; newcapa = MOO_ALIGN_POW2(newcapa, 512); /* TODO: adjust this capacity */ - tmp = (moo_ooch_t*)moo_reallocmem(moo, p->ptr, newcapa * MOO_SIZEOF(*tmp)); + tmp = (moo_ooch_t*)moo_reallocmem(moo, p->ptr, newcapa * MOO_SIZEOF(*tmp)); if (!tmp) return -1; p->ptr = tmp; @@ -1416,7 +1416,7 @@ void moo_sub_ntime (moo_ntime_t* z, const moo_ntime_t* x, const moo_ntime_t* y) xs = MOO_TYPE_MIN(moo_ntime_sec_t); ns = 0; } - } + } else { xs = xs - ys;