From 4affb25b28b34ba99e968d87eb1356d369bb0708 Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Sun, 16 Dec 2018 17:35:46 +0000 Subject: [PATCH] more use of MOO_STORE_OOP --- moo/lib/bigint.c | 222 +++++++++++++++++++++++------------------------ moo/lib/dic.c | 4 +- moo/lib/exec.c | 46 +++++----- moo/lib/gc.c | 2 +- moo/lib/moo.h | 2 + moo/lib/obj.c | 8 +- moo/lib/sym.c | 20 ++--- 7 files changed, 153 insertions(+), 151 deletions(-) diff --git a/moo/lib/bigint.c b/moo/lib/bigint.c index fb8e760..4b7c375 100644 --- a/moo/lib/bigint.c +++ b/moo/lib/bigint.c @@ -215,7 +215,7 @@ static int is_normalized_integer (moo_t* moo, moo_oop_t oop) sz = MOO_OBJ_GET_SIZE(oop); MOO_ASSERT (moo, sz >= 1); - return ((moo_oop_liword_t)oop)->slot[sz - 1] == 0? 0: 1; + return MOO_OBJ_GET_LIWORD_SLOT(oop)[sz - 1] == 0? 0: 1; } } @@ -247,7 +247,7 @@ static MOO_INLINE int bigint_to_oow (moo_t* moo, moo_oop_t num, moo_oow_t* w) MOO_ASSERT (moo, MOO_OBJ_GET_SIZE(num) >= 1); if (MOO_OBJ_GET_SIZE(num) == 1) { - *w = ((moo_oop_word_t)num)->slot[0]; + *w = MOO_OBJ_GET_WORD_SLOT(num)[0]; return (IS_NBIGINT(moo, num))? -1: 1; } @@ -260,7 +260,7 @@ static MOO_INLINE int bigint_to_oow (moo_t* moo, moo_oop_t num, moo_oow_t* w) MOO_ASSERT (moo, MOO_OBJ_GET_SIZE(num) >= 2); if (MOO_OBJ_GET_SIZE(num) == 2) { - *w = MAKE_WORD (((moo_oop_halfword_t)num)->slot[0], ((moo_oop_halfword_t)num)->slot[1]); + *w = MAKE_WORD (MOO_OBJ_GET_HALFWORD_SLOT(num)[0], MOO_OBJ_GET_HALFWORD_SLOT(num)[1]); return (IS_NBIGINT(moo, num))? -1: 1; } #else @@ -434,7 +434,7 @@ static MOO_INLINE moo_oop_t make_bloated_bigint_with_ooi (moo_t* moo, moo_ooi_t } if (!z) return MOO_NULL; - ((moo_oop_liword_t)z)->slot[0] = w; + MOO_OBJ_GET_LIWORD_SLOT(z)[0] = w; return z; #elif (MOO_LIW_BITS == MOO_OOHW_BITS) @@ -460,8 +460,8 @@ static MOO_INLINE moo_oop_t make_bloated_bigint_with_ooi (moo_t* moo, moo_ooi_t } if (!z) return MOO_NULL; - ((moo_oop_liword_t)z)->slot[0] = hw[0]; - if (hw[1] > 0) ((moo_oop_liword_t)z)->slot[1] = hw[1]; + MOO_OBJ_GET_LIWORD_SLOT(z)[0] = hw[0]; + if (hw[1] > 0) MOO_OBJ_GET_LIWORD_SLOT(z)[1] = hw[1]; return z; #else # error UNSUPPORTED LIW BIT SIZE @@ -538,7 +538,7 @@ static MOO_INLINE moo_oop_t expand_bigint (moo_t* moo, moo_oop_t oop, moo_oow_t for (i = 0; i < count; i++) { - ((moo_oop_liword_t)z)->slot[i] = ((moo_oop_liword_t)oop)->slot[i]; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = MOO_OBJ_GET_LIWORD_SLOT(oop)[i]; } return z; } @@ -559,7 +559,7 @@ static MOO_INLINE moo_oop_t _clone_bigint (moo_t* moo, moo_oop_t oop, moo_oow_t for (i = 0; i < count; i++) { - ((moo_oop_liword_t)z)->slot[i] = ((moo_oop_liword_t)oop)->slot[i]; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = MOO_OBJ_GET_LIWORD_SLOT(oop)[i]; } return z; } @@ -610,7 +610,7 @@ static MOO_INLINE moo_oow_t count_effective_digits (moo_oop_t oop) for (i = MOO_OBJ_GET_SIZE(oop); i > 1; ) { --i; - if (((moo_oop_liword_t)oop)->slot[i]) return i + 1; + if (MOO_OBJ_GET_LIWORD_SLOT(oop)[i]) return i + 1; } return 1; @@ -628,7 +628,7 @@ static moo_oop_t normalize_bigint (moo_t* moo, moo_oop_t oop) { moo_oow_t w; - w = ((moo_oop_liword_t)oop)->slot[0]; + w = MOO_OBJ_GET_LIWORD_SLOT(oop)[0]; if (IS_PBIGINT(moo, oop)) { if (w <= MOO_SMOOI_MAX) return MOO_SMOOI_TO_OOP(w); @@ -646,19 +646,19 @@ static moo_oop_t normalize_bigint (moo_t* moo, moo_oop_t oop) { if (IS_PBIGINT(moo, oop)) { - return MOO_SMOOI_TO_OOP(((moo_oop_liword_t)oop)->slot[0]); + return MOO_SMOOI_TO_OOP(MOO_OBJ_GET_LIWORD_SLOT(oop)[0]); } else { MOO_ASSERT (moo, IS_NBIGINT(moo, oop)); - return MOO_SMOOI_TO_OOP(-(moo_ooi_t)((moo_oop_liword_t)oop)->slot[0]); + return MOO_SMOOI_TO_OOP(-(moo_ooi_t)MOO_OBJ_GET_LIWORD_SLOT(oop)[0]); } } else if (count == 2) /* 2 half-words */ { moo_oow_t w; - w = MAKE_WORD (((moo_oop_liword_t)oop)->slot[0], ((moo_oop_liword_t)oop)->slot[1]); + w = MAKE_WORD (MOO_OBJ_GET_LIWORD_SLOT(oop)[0], MOO_OBJ_GET_LIWORD_SLOT(oop)[1]); if (IS_PBIGINT(moo, oop)) { if (w <= MOO_SMOOI_MAX) return MOO_SMOOI_TO_OOP(w); @@ -699,8 +699,8 @@ 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_oop_liword_t)x)->slot, MOO_OBJ_GET_SIZE(x), - ((moo_oop_liword_t)y)->slot, MOO_OBJ_GET_SIZE(y)); + MOO_OBJ_GET_LIWORD_SLOT(x), MOO_OBJ_GET_SIZE(x), + MOO_OBJ_GET_LIWORD_SLOT(y), MOO_OBJ_GET_SIZE(y)); } static MOO_INLINE int is_less (moo_t* moo, moo_oop_t x, moo_oop_t y) @@ -737,8 +737,8 @@ 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_oop_liword_t)x)->slot, MOO_OBJ_GET_SIZE(x), - ((moo_oop_liword_t)y)->slot, MOO_OBJ_GET_SIZE(y)); + MOO_OBJ_GET_LIWORD_SLOT(x), MOO_OBJ_GET_SIZE(x), + MOO_OBJ_GET_LIWORD_SLOT(y), MOO_OBJ_GET_SIZE(y)); } static MOO_INLINE int is_greater (moo_t* moo, moo_oop_t x, moo_oop_t y) @@ -762,7 +762,7 @@ static MOO_INLINE int is_equal (moo_t* moo, moo_oop_t x, moo_oop_t y) { /* check if two large integers are equal to each other */ return MOO_OBJ_GET_CLASS(x) == MOO_OBJ_GET_CLASS(y) && MOO_OBJ_GET_SIZE(x) == MOO_OBJ_GET_SIZE(y) && - MOO_MEMCMP(((moo_oop_liword_t)x)->slot, ((moo_oop_liword_t)y)->slot, MOO_OBJ_GET_SIZE(x) * MOO_SIZEOF(moo_liw_t)) == 0; + MOO_MEMCMP(MOO_OBJ_GET_LIWORD_SLOT(x), MOO_OBJ_GET_LIWORD_SLOT(y), MOO_OBJ_GET_SIZE(x) * MOO_SIZEOF(moo_liw_t)) == 0; } static void complement2_unsigned_array (moo_t* moo, const moo_liw_t* x, moo_oow_t xs, moo_liw_t* z) @@ -1510,9 +1510,9 @@ static moo_oop_t add_unsigned_integers (moo_t* moo, moo_oop_t x, moo_oop_t y) if (!z) return MOO_NULL; add_unsigned_array ( - ((moo_oop_liword_t)x)->slot, as, - ((moo_oop_liword_t)y)->slot, bs, - ((moo_oop_liword_t)z)->slot + MOO_OBJ_GET_LIWORD_SLOT(x), as, + MOO_OBJ_GET_LIWORD_SLOT(y), bs, + MOO_OBJ_GET_LIWORD_SLOT(z) ); return z; @@ -1531,9 +1531,9 @@ static moo_oop_t subtract_unsigned_integers (moo_t* moo, moo_oop_t x, moo_oop_t if (!z) return MOO_NULL; subtract_unsigned_array (moo, - ((moo_oop_liword_t)x)->slot, MOO_OBJ_GET_SIZE(x), - ((moo_oop_liword_t)y)->slot, MOO_OBJ_GET_SIZE(y), - ((moo_oop_liword_t)z)->slot); + 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)); return z; } @@ -1562,18 +1562,18 @@ static moo_oop_t multiply_unsigned_integers (moo_t* moo, moo_oop_t x, moo_oop_t { #endif multiply_unsigned_array ( - ((moo_oop_liword_t)x)->slot, MOO_OBJ_GET_SIZE(x), - ((moo_oop_liword_t)y)->slot, MOO_OBJ_GET_SIZE(y), - ((moo_oop_liword_t)z)->slot); + 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)); #if defined(MOO_ENABLE_KARATSUBA) } else { if (multiply_unsigned_array_karatsuba ( moo, - ((moo_oop_liword_t)x)->slot, MOO_OBJ_GET_SIZE(x), - ((moo_oop_liword_t)y)->slot, MOO_OBJ_GET_SIZE(y), - ((moo_oop_liword_t)z)->slot) == 0) return MOO_NULL; + 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)) == 0) return MOO_NULL; } #endif return z; @@ -1600,9 +1600,9 @@ static moo_oop_t divide_unsigned_integers (moo_t* moo, moo_oop_t x, moo_oop_t y, if (!rr) return MOO_NULL; divide_unsigned_array (moo, - ((moo_oop_liword_t)x)->slot, MOO_OBJ_GET_SIZE(x), - ((moo_oop_liword_t)y)->slot, MOO_OBJ_GET_SIZE(y), - ((moo_oop_liword_t)qq)->slot, ((moo_oop_liword_t)rr)->slot); + 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(qq), MOO_OBJ_GET_LIWORD_SLOT(rr)); *r = rr; return qq; @@ -2232,7 +2232,7 @@ moo_oop_t moo_bitatint (moo_t* moo, moo_oop_t x, moo_oop_t y) if (IS_PBIGINT(moo, x)) { if (wp >= xs) return MOO_SMOOI_TO_OOP(0); - v = (((moo_oop_liword_t)x)->slot[wp] >> bp) & 1; + v = (MOO_OBJ_GET_LIWORD_SLOT(x)[wp] >> bp) & 1; } else { @@ -2244,7 +2244,7 @@ moo_oop_t moo_bitatint (moo_t* moo, moo_oop_t x, moo_oop_t y) carry = 1; for (i = 0; i <= wp; i++) { - w = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)x)->slot[i]) + carry; + w = (moo_lidw_t)((moo_liw_t)~MOO_OBJ_GET_LIWORD_SLOT(x)[i]) + carry; carry = w >> MOO_LIW_BITS; } v = ((moo_oow_t)w >> bp) & 1; @@ -2316,7 +2316,7 @@ moo_oop_t moo_bitatint (moo_t* moo, moo_oop_t x, moo_oop_t y) if (IS_PBIGINT(moo, x)) { if (wp >= xs) return MOO_SMOOI_TO_OOP(0); - v = (((moo_oop_liword_t)x)->slot[wp] >> bp) & 1; + v = (MOO_OBJ_GET_LIWORD_SLOT(x)[wp] >> bp) & 1; } else { @@ -2328,7 +2328,7 @@ moo_oop_t moo_bitatint (moo_t* moo, moo_oop_t x, moo_oop_t y) carry = 1; for (i = 0; i <= wp; i++) { - w = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)x)->slot[i]) + carry; + w = (moo_lidw_t)((moo_liw_t)~MOO_OBJ_GET_LIWORD_SLOT(x)[i]) + carry; carry = w >> MOO_LIW_BITS; } v = ((moo_oow_t)w >> bp) & 1; @@ -2452,13 +2452,13 @@ moo_oop_t moo_bitandints (moo_t* moo, moo_oop_t x, moo_oop_t y) /* 2's complement on both x and y and perform bitwise-and */ for (i = 0; i < ys; i++) { - w[0] = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)x)->slot[i]) + carry[0]; + w[0] = (moo_lidw_t)((moo_liw_t)~MOO_OBJ_GET_LIWORD_SLOT(x)[i]) + carry[0]; carry[0] = w[0] >> MOO_LIW_BITS; - w[1] = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)y)->slot[i]) + carry[1]; + w[1] = (moo_lidw_t)((moo_liw_t)~MOO_OBJ_GET_LIWORD_SLOT(y)[i]) + carry[1]; carry[1] = w[1] >> MOO_LIW_BITS; - ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w[0] & (moo_liw_t)w[1]; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = (moo_liw_t)w[0] & (moo_liw_t)w[1]; } MOO_ASSERT (moo, carry[1] == 0); @@ -2466,20 +2466,20 @@ moo_oop_t moo_bitandints (moo_t* moo, moo_oop_t x, moo_oop_t y) * in y is treated as if they are all 1s. */ for (; i < xs; i++) { - w[0] = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)x)->slot[i]) + carry[0]; + w[0] = (moo_lidw_t)((moo_liw_t)~MOO_OBJ_GET_LIWORD_SLOT(x)[i]) + carry[0]; carry[0] = w[0] >> MOO_LIW_BITS; - ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w[0]; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = (moo_liw_t)w[0]; } MOO_ASSERT (moo, carry[0] == 0); /* 2's complement on the final result */ - ((moo_oop_liword_t)z)->slot[zs] = ~(moo_liw_t)0; + MOO_OBJ_GET_LIWORD_SLOT(z)[zs] = ~(moo_liw_t)0; carry[0] = 1; for (i = 0; i <= zs; i++) { - w[0] = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)z)->slot[i]) + carry[0]; + w[0] = (moo_lidw_t)((moo_liw_t)~MOO_OBJ_GET_LIWORD_SLOT(z)[i]) + carry[0]; carry[0] = w[0] >> MOO_LIW_BITS; - ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w[0]; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = (moo_liw_t)w[0]; } MOO_ASSERT (moo, carry[0] == 0); @@ -2493,9 +2493,9 @@ moo_oop_t moo_bitandints (moo_t* moo, moo_oop_t x, moo_oop_t y) carry = 1; for (i = 0; i < ys; i++) { - w = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)x)->slot[i]) + carry; + w = (moo_lidw_t)((moo_liw_t)~MOO_OBJ_GET_LIWORD_SLOT(x)[i]) + carry; carry = w >> MOO_LIW_BITS; - ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w & ((moo_oop_liword_t)y)->slot[i]; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = (moo_liw_t)w & MOO_OBJ_GET_LIWORD_SLOT(y)[i]; } /* the lacking part in y is all 0's. the remaining part in x is @@ -2511,9 +2511,9 @@ moo_oop_t moo_bitandints (moo_t* moo, moo_oop_t x, moo_oop_t y) carry = 1; for (i = 0; i < ys; i++) { - w = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)y)->slot[i]) + carry; + w = (moo_lidw_t)((moo_liw_t)~MOO_OBJ_GET_LIWORD_SLOT(y)[i]) + carry; carry = w >> MOO_LIW_BITS; - ((moo_oop_liword_t)z)->slot[i] = ((moo_oop_liword_t)x)->slot[i] & (moo_liw_t)w; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = MOO_OBJ_GET_LIWORD_SLOT(x)[i] & (moo_liw_t)w; } MOO_ASSERT (moo, carry == 0); @@ -2536,7 +2536,7 @@ moo_oop_t moo_bitandints (moo_t* moo, moo_oop_t x, moo_oop_t y) */ for (; i < xs; i++) { - ((moo_oop_liword_t)z)->slot[i] = ((moo_oop_liword_t)x)->slot[i]; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = MOO_OBJ_GET_LIWORD_SLOT(x)[i]; } } else @@ -2544,7 +2544,7 @@ moo_oop_t moo_bitandints (moo_t* moo, moo_oop_t x, moo_oop_t y) /* both are positive */ for (i = 0; i < ys; i++) { - ((moo_oop_liword_t)z)->slot[i] = ((moo_oop_liword_t)x)->slot[i] & ((moo_oop_liword_t)y)->slot[i]; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = MOO_OBJ_GET_LIWORD_SLOT(x)[i] & MOO_OBJ_GET_LIWORD_SLOT(y)[i]; } } @@ -2672,13 +2672,13 @@ moo_oop_t moo_bitorints (moo_t* moo, moo_oop_t x, moo_oop_t y) /* 2's complement on both x and y and perform bitwise-and */ for (i = 0; i < ys; i++) { - w[0] = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)x)->slot[i]) + carry[0]; + w[0] = (moo_lidw_t)((moo_liw_t)~MOO_OBJ_GET_LIWORD_SLOT(x)[i]) + carry[0]; carry[0] = w[0] >> MOO_LIW_BITS; - w[1] = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)y)->slot[i]) + carry[1]; + w[1] = (moo_lidw_t)((moo_liw_t)~MOO_OBJ_GET_LIWORD_SLOT(y)[i]) + carry[1]; carry[1] = w[1] >> MOO_LIW_BITS; - ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w[0] | (moo_liw_t)w[1]; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = (moo_liw_t)w[0] | (moo_liw_t)w[1]; } MOO_ASSERT (moo, carry[1] == 0); @@ -2688,13 +2688,13 @@ moo_oop_t moo_bitorints (moo_t* moo, moo_oop_t x, moo_oop_t y) adjust_to_negative: /* 2's complement on the final result */ - ((moo_oop_liword_t)z)->slot[zs] = ~(moo_liw_t)0; + MOO_OBJ_GET_LIWORD_SLOT(z)[zs] = ~(moo_liw_t)0; carry[0] = 1; for (i = 0; i <= zs; i++) { - w[0] = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)z)->slot[i]) + carry[0]; + w[0] = (moo_lidw_t)((moo_liw_t)~MOO_OBJ_GET_LIWORD_SLOT(z)[i]) + carry[0]; carry[0] = w[0] >> MOO_LIW_BITS; - ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w[0]; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = (moo_liw_t)w[0]; } MOO_ASSERT (moo, carry[0] == 0); @@ -2708,16 +2708,16 @@ moo_oop_t moo_bitorints (moo_t* moo, moo_oop_t x, moo_oop_t y) carry = 1; for (i = 0; i < ys; i++) { - w = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)x)->slot[i]) + carry; + w = (moo_lidw_t)((moo_liw_t)~MOO_OBJ_GET_LIWORD_SLOT(x)[i]) + carry; carry = w >> MOO_LIW_BITS; - ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w | ((moo_oop_liword_t)y)->slot[i]; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = (moo_liw_t)w | MOO_OBJ_GET_LIWORD_SLOT(y)[i]; } for (; i < xs; i++) { - w = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)x)->slot[i]) + carry; + w = (moo_lidw_t)((moo_liw_t)~MOO_OBJ_GET_LIWORD_SLOT(x)[i]) + carry; carry = w >> MOO_LIW_BITS; - ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = (moo_liw_t)w; } MOO_ASSERT (moo, carry == 0); @@ -2732,9 +2732,9 @@ moo_oop_t moo_bitorints (moo_t* moo, moo_oop_t x, moo_oop_t y) carry = 1; for (i = 0; i < ys; i++) { - w = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)y)->slot[i]) + carry; + w = (moo_lidw_t)((moo_liw_t)~MOO_OBJ_GET_LIWORD_SLOT(y)[i]) + carry; carry = w >> MOO_LIW_BITS; - ((moo_oop_liword_t)z)->slot[i] = ((moo_oop_liword_t)x)->slot[i] | (moo_liw_t)w; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = MOO_OBJ_GET_LIWORD_SLOT(x)[i] | (moo_liw_t)w; } MOO_ASSERT (moo, carry == 0); @@ -2747,7 +2747,7 @@ moo_oop_t moo_bitorints (moo_t* moo, moo_oop_t x, moo_oop_t y) * redundant. for (; i < xs; i++) { - ((moo_oop_liword_t)z)->slot[i] = ~(moo_liw_t)0; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = ~(moo_liw_t)0; } */ goto adjust_to_negative; @@ -2757,12 +2757,12 @@ moo_oop_t moo_bitorints (moo_t* moo, moo_oop_t x, moo_oop_t y) /* both are positive */ for (i = 0; i < ys; i++) { - ((moo_oop_liword_t)z)->slot[i] = ((moo_oop_liword_t)x)->slot[i] | ((moo_oop_liword_t)y)->slot[i]; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = MOO_OBJ_GET_LIWORD_SLOT(x)[i] | MOO_OBJ_GET_LIWORD_SLOT(y)[i]; } for (; i < xs; i++) { - ((moo_oop_liword_t)z)->slot[i] = ((moo_oop_liword_t)x)->slot[i]; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = MOO_OBJ_GET_LIWORD_SLOT(x)[i]; } } @@ -2890,22 +2890,22 @@ moo_oop_t moo_bitxorints (moo_t* moo, moo_oop_t x, moo_oop_t y) /* 2's complement on both x and y and perform bitwise-and */ for (i = 0; i < ys; i++) { - w[0] = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)x)->slot[i]) + carry[0]; + w[0] = (moo_lidw_t)((moo_liw_t)~MOO_OBJ_GET_LIWORD_SLOT(x)[i]) + carry[0]; carry[0] = w[0] >> MOO_LIW_BITS; - w[1] = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)y)->slot[i]) + carry[1]; + w[1] = (moo_lidw_t)((moo_liw_t)~MOO_OBJ_GET_LIWORD_SLOT(y)[i]) + carry[1]; carry[1] = w[1] >> MOO_LIW_BITS; - ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w[0] ^ (moo_liw_t)w[1]; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = (moo_liw_t)w[0] ^ (moo_liw_t)w[1]; } MOO_ASSERT (moo, carry[1] == 0); /* treat the lacking part in y as all 1s */ for (; i < xs; i++) { - w[0] = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)x)->slot[i]) + carry[0]; + w[0] = (moo_lidw_t)((moo_liw_t)~MOO_OBJ_GET_LIWORD_SLOT(x)[i]) + carry[0]; carry[0] = w[0] >> MOO_LIW_BITS; - ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w[0] ^ (~(moo_liw_t)0); + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = (moo_liw_t)w[0] ^ (~(moo_liw_t)0); } MOO_ASSERT (moo, carry[0] == 0); } @@ -2917,29 +2917,29 @@ moo_oop_t moo_bitxorints (moo_t* moo, moo_oop_t x, moo_oop_t y) carry = 1; for (i = 0; i < ys; i++) { - w = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)x)->slot[i]) + carry; + w = (moo_lidw_t)((moo_liw_t)~MOO_OBJ_GET_LIWORD_SLOT(x)[i]) + carry; carry = w >> MOO_LIW_BITS; - ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w ^ ((moo_oop_liword_t)y)->slot[i]; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = (moo_liw_t)w ^ MOO_OBJ_GET_LIWORD_SLOT(y)[i]; } /* treat the lacking part in y as all 0s */ for (; i < xs; i++) { - w = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)x)->slot[i]) + carry; + w = (moo_lidw_t)((moo_liw_t)~MOO_OBJ_GET_LIWORD_SLOT(x)[i]) + carry; carry = w >> MOO_LIW_BITS; - ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = (moo_liw_t)w; } MOO_ASSERT (moo, carry == 0); adjust_to_negative: /* 2's complement on the final result */ - ((moo_oop_liword_t)z)->slot[zs] = ~(moo_liw_t)0; + MOO_OBJ_GET_LIWORD_SLOT(z)[zs] = ~(moo_liw_t)0; carry = 1; for (i = 0; i <= zs; i++) { - w = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)z)->slot[i]) + carry; + w = (moo_lidw_t)((moo_liw_t)~MOO_OBJ_GET_LIWORD_SLOT(z)[i]) + carry; carry = w >> MOO_LIW_BITS; - ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = (moo_liw_t)w; } MOO_ASSERT (moo, carry == 0); @@ -2954,16 +2954,16 @@ moo_oop_t moo_bitxorints (moo_t* moo, moo_oop_t x, moo_oop_t y) carry = 1; for (i = 0; i < ys; i++) { - w = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)y)->slot[i]) + carry; + w = (moo_lidw_t)((moo_liw_t)~MOO_OBJ_GET_LIWORD_SLOT(y)[i]) + carry; carry = w >> MOO_LIW_BITS; - ((moo_oop_liword_t)z)->slot[i] = ((moo_oop_liword_t)x)->slot[i] ^ (moo_liw_t)w; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = MOO_OBJ_GET_LIWORD_SLOT(x)[i] ^ (moo_liw_t)w; } MOO_ASSERT (moo, carry == 0); /* treat the lacking part in y as all 1s */ for (; i < xs; i++) { - ((moo_oop_liword_t)z)->slot[i] = ((moo_oop_liword_t)x)->slot[i] ^ (~(moo_liw_t)0); + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = MOO_OBJ_GET_LIWORD_SLOT(x)[i] ^ (~(moo_liw_t)0); } goto adjust_to_negative; @@ -2973,13 +2973,13 @@ moo_oop_t moo_bitxorints (moo_t* moo, moo_oop_t x, moo_oop_t y) /* both are positive */ for (i = 0; i < ys; i++) { - ((moo_oop_liword_t)z)->slot[i] = ((moo_oop_liword_t)x)->slot[i] ^ ((moo_oop_liword_t)y)->slot[i]; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = MOO_OBJ_GET_LIWORD_SLOT(x)[i] ^ MOO_OBJ_GET_LIWORD_SLOT(y)[i]; } /* treat the lacking part in y as all 0s */ for (; i < xs; i++) { - ((moo_oop_liword_t)z)->slot[i] = ((moo_oop_liword_t)x)->slot[i]; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = MOO_OBJ_GET_LIWORD_SLOT(x)[i]; } } @@ -3044,9 +3044,9 @@ moo_oop_t moo_bitinvint (moo_t* moo, moo_oop_t x) carry = 1; for (i = 0; i < xs; i++) { - w = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)x)->slot[i]) + carry; + w = (moo_lidw_t)((moo_liw_t)~MOO_OBJ_GET_LIWORD_SLOT(x)[i]) + carry; carry = w >> MOO_LIW_BITS; - ((moo_oop_liword_t)z)->slot[i] = ~(moo_liw_t)w; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = ~(moo_liw_t)w; } MOO_ASSERT (moo, carry == 0); } @@ -3057,28 +3057,28 @@ moo_oop_t moo_bitinvint (moo_t* moo, moo_oop_t x) #if 0 for (i = 0; i < xs; i++) { - ((moo_oop_liword_t)z)->slot[i] = ~((moo_oop_liword_t)x)->slot[i]; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = ~MOO_OBJ_GET_LIWORD_SLOT(x)[i]; } - ((moo_oop_liword_t)z)->slot[zs] = ~(moo_liw_t)0; + MOO_OBJ_GET_LIWORD_SLOT(z)[zs] = ~(moo_liw_t)0; carry = 1; for (i = 0; i <= zs; i++) { - w = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)z)->slot[i]) + carry; + w = (moo_lidw_t)((moo_liw_t)~MOO_OBJ_GET_LIWORD_SLOT(z)[i]) + carry; carry = w >> MOO_LIW_BITS; - ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = (moo_liw_t)w; } MOO_ASSERT (moo, carry == 0); #else carry = 1; for (i = 0; i < xs; i++) { - w = (moo_lidw_t)(((moo_oop_liword_t)x)->slot[i]) + carry; + w = (moo_lidw_t)(MOO_OBJ_GET_LIWORD_SLOT(x)[i]) + carry; carry = w >> MOO_LIW_BITS; - ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = (moo_liw_t)w; } MOO_ASSERT (moo, i == zs); - ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)carry; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = (moo_liw_t)carry; MOO_ASSERT (moo, (carry >> MOO_LIW_BITS) == 0); #endif @@ -3113,40 +3113,40 @@ static MOO_INLINE moo_oop_t rshift_negative_bigint (moo_t* moo, moo_oop_t x, moo carry = 1; for (i = 0; i < xs; i++) { - w = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)x)->slot[i]) + carry; + w = (moo_lidw_t)((moo_liw_t)~MOO_OBJ_GET_LIWORD_SLOT(x)[i]) + carry; carry = w >> MOO_LIW_BITS; - ((moo_oop_liword_t)z)->slot[i] = ~(moo_liw_t)w; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = ~(moo_liw_t)w; } MOO_ASSERT (moo, carry == 0); /* shift to the right */ - rshift_unsigned_array (((moo_oop_liword_t)z)->slot, xs, shift); + rshift_unsigned_array (MOO_OBJ_GET_LIWORD_SLOT(z), xs, shift); /* the following lines roughly for 'z = moo_bitinv (moo, z)' */ #if 0 for (i = 0; i < xs; i++) { - ((moo_oop_liword_t)z)->slot[i] = ~((moo_oop_liword_t)z)->slot[i]; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = ~MOO_OBJ_GET_LIWORD_SLOT(z)[i]; } - ((moo_oop_liword_t)z)->slot[xs] = ~(moo_liw_t)0; + MOO_OBJ_GET_LIWORD_SLOT(z)[xs] = ~(moo_liw_t)0; carry = 1; for (i = 0; i <= xs; i++) { - w = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)z)->slot[i]) + carry; + w = (moo_lidw_t)((moo_liw_t)~MOO_OBJ_GET_LIWORD_SLOT(z)[i]) + carry; carry = w >> MOO_LIW_BITS; - ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = (moo_liw_t)w; } MOO_ASSERT (moo, carry == 0); #else carry = 1; for (i = 0; i < xs; i++) { - w = (moo_lidw_t)(((moo_oop_liword_t)z)->slot[i]) + carry; + w = (moo_lidw_t)(MOO_OBJ_GET_LIWORD_SLOT(z)[i]) + carry; carry = w >> MOO_LIW_BITS; - ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = (moo_liw_t)w; } - ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)carry; + MOO_OBJ_GET_LIWORD_SLOT(z)[i] = (moo_liw_t)carry; MOO_ASSERT (moo, (carry >> MOO_LIW_BITS) == 0); #endif @@ -3258,9 +3258,9 @@ static MOO_INLINE moo_oop_t rshift_positive_bigint_and_normalize (moo_t* moo, mo shift = MOO_SMOOI_MAX; do { - rshift_unsigned_array (((moo_oop_liword_t)z)->slot, zs, shift); - if (count_effective (((moo_oop_liword_t)z)->slot, zs) == 1 && - ((moo_oop_liword_t)z)->slot[0] == 0) + 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_SLOT(z)[0] == 0) { /* if z is 0, i don't have to go on */ break; @@ -3313,7 +3313,7 @@ static MOO_INLINE moo_oop_t lshift_bigint_and_normalize (moo_t* moo, moo_oop_t x moo_poptmp (moo); if (!z) return MOO_NULL; - lshift_unsigned_array (((moo_oop_liword_t)z)->slot, MOO_OBJ_GET_SIZE(z), shift); + lshift_unsigned_array (MOO_OBJ_GET_LIWORD_SLOT(z), MOO_OBJ_GET_SIZE(z), shift); moo_pushtmp (moo, &y); x = normalize_bigint (moo, z); @@ -3376,7 +3376,7 @@ moo_oop_t moo_bitshiftint (moo_t* moo, moo_oop_t x, moo_oop_t y) z = make_bloated_bigint_with_ooi (moo, v1, wshift); if (!z) return MOO_NULL; - lshift_unsigned_array (((moo_oop_liword_t)z)->slot, MOO_OBJ_GET_SIZE(z), v2); + lshift_unsigned_array (MOO_OBJ_GET_LIWORD_SLOT(z), MOO_OBJ_GET_SIZE(z), v2); return normalize_bigint (moo, z); } else @@ -3534,7 +3534,7 @@ moo_oop_t moo_bitshiftint (moo_t* moo, moo_oop_t x, moo_oop_t y) z = expand_bigint (moo, x, wshift); if (!z) return MOO_NULL; - lshift_unsigned_array (((moo_oop_liword_t)z)->slot, MOO_OBJ_GET_SIZE(z), shift); + lshift_unsigned_array (MOO_OBJ_GET_LIWORD_SLOT(z), MOO_OBJ_GET_SIZE(z), shift); } else { @@ -3552,7 +3552,7 @@ moo_oop_t moo_bitshiftint (moo_t* moo, moo_oop_t x, moo_oop_t y) { z = clone_bigint (moo, x, MOO_OBJ_GET_SIZE(x)); if (!z) return MOO_NULL; - rshift_unsigned_array (((moo_oop_liword_t)z)->slot, MOO_OBJ_GET_SIZE(z), shift); + rshift_unsigned_array (MOO_OBJ_GET_LIWORD_SLOT(z), MOO_OBJ_GET_SIZE(z), shift); } } @@ -4201,7 +4201,7 @@ moo_oop_t moo_inttostr (moo_t* moo, moo_oop_t num, int radix) w = 0; while (w < as) { - acc |= (moo_lidw_t)((moo_oop_liword_t)num)->slot[w] << accbits; + acc |= (moo_lidw_t)MOO_OBJ_GET_LIWORD_SLOT(num)[w] << accbits; accbits += MOO_LIW_BITS; w++; @@ -4274,7 +4274,7 @@ moo_oop_t moo_inttostr (moo_t* moo, moo_oop_t num, int radix) q = &t[as]; r = &t[as * 2]; - MOO_MEMCPY (a, ((moo_oop_liword_t)num)->slot, MOO_SIZEOF(*a) * as); + MOO_MEMCPY (a, MOO_OBJ_GET_LIWORD_SLOT(num), MOO_SIZEOF(*a) * as); do { diff --git a/moo/lib/dic.c b/moo/lib/dic.c index 1e37b30..a6410f7 100644 --- a/moo/lib/dic.c +++ b/moo/lib/dic.c @@ -76,7 +76,7 @@ static moo_oop_oop_t expand_bucket (moo_t* moo, moo_oop_oop_t oldbuc) key = (moo_oop_char_t)ass->key; MOO_ASSERT (moo, MOO_CLASSOF(moo,key) == moo->_symbol); - index = moo_hashoochars(key->slot, MOO_OBJ_GET_SIZE(key)) % newsz; + index = moo_hashoochars(MOO_OBJ_GET_CHAR_SLOT(key), MOO_OBJ_GET_SIZE(key)) % newsz; while (newbuc->slot[index] != moo->_nil) index = (index + 1) % newsz; MOO_STORE_OOP (moo, &newbuc->slot[index], (moo_oop_t)ass); /* newbuc->slot[index] = (moo_oop_t)ass; */ @@ -100,7 +100,7 @@ static moo_oop_association_t find_or_upsert (moo_t* moo, moo_oop_dic_t dic, moo_ MOO_ASSERT (moo, MOO_CLASSOF(moo,dic->tally) == moo->_small_integer); MOO_ASSERT (moo, MOO_CLASSOF(moo,dic->bucket) == moo->_array); - hv = moo_hashoochars(key->slot, MOO_OBJ_GET_SIZE(key)); + hv = moo_hashoochars(MOO_OBJ_GET_CHAR_SLOT(key), MOO_OBJ_GET_SIZE(key)); index = hv % MOO_OBJ_GET_SIZE(dic->bucket); /* find */ diff --git a/moo/lib/exec.c b/moo/lib/exec.c index 7765e1f..fcfbeff 100644 --- a/moo/lib/exec.c +++ b/moo/lib/exec.c @@ -552,7 +552,7 @@ static MOO_INLINE void chain_into_semaphore (moo_t* moo, moo_oop_process_t proc, MOO_APPEND_TO_OOP_LIST (moo, &sem->waiting, moo_oop_process_t, proc, sem_wait); - proc->sem = (moo_oop_t)sem; + MOO_STORE_OOP (moo, &proc->sem, (moo_oop_t)sem); } static MOO_INLINE void unchain_from_semaphore (moo_t* moo, moo_oop_process_t proc) @@ -597,7 +597,7 @@ static void terminate_process (moo_t* moo, moo_oop_process_t proc) unchain_from_processor (moo, proc, PROC_STATE_TERMINATED); proc->sp = MOO_SMOOI_TO_OOP(-1); /* invalidate the process stack */ - proc->current_context = proc->initial_context; /* not needed but just in case */ + MOO_STORE_OOP (moo, (moo_oop_t*)&proc->current_context, (moo_oop_t)proc->initial_context); /* not needed but just in case */ /* a runnable or running process must not be chanined to the * process list of a semaphore */ @@ -673,7 +673,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); - /*proc->current_context = proc->initial_context;*/ + /*MOO_STORE_OOP (moo, &proc->current_context = proc->initial_context);*/ } #if 0 else if (proc->state == MOO_SMOOI_TO_OOP(PROC_STATE_RUNNABLE)) @@ -775,7 +775,7 @@ static int async_signal_semaphore (moo_t* moo, moo_oop_semaphore_t sem) moo_oop_semaphore_t* tmp; new_capa = moo->sem_list_capa + SEM_LIST_INC; /* TODO: overflow check.. */ - tmp = moo_reallocmem (moo, moo->sem_list, MOO_SIZEOF(moo_oop_semaphore_t) * new_capa); + tmp = moo_reallocmem(moo, moo->sem_list, MOO_SIZEOF(moo_oop_semaphore_t) * new_capa); if (!tmp) return -1; moo->sem_list = tmp; @@ -1532,7 +1532,7 @@ static MOO_INLINE int activate_new_method (moo_t* moo, moo_oop_method_t mth, moo moo_poptmp (moo); if (!ctx) return -1; - MOO_STORE_OOP (moo, &ctx->sender, 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 */ @@ -1559,7 +1559,7 @@ static MOO_INLINE int activate_new_method (moo_t* moo, moo_oop_method_t mth, moo MOO_STORE_OOP (moo, &ctx->method_or_nargs, (moo_oop_t)mth); /* the 'home' field of a method context is always moo->_nil. ctx->home = moo->_nil;*/ - MOO_STORE_OOP (moo, &ctx->origin, ctx); /* point to self */ + MOO_STORE_OOP (moo, (moo_oop_t*)&ctx->origin, (moo_oop_t)ctx); /* point to self */ /* * Assume this message sending expression: @@ -1834,8 +1834,8 @@ TODO: overcome this problem - accept parameters.... ctx->ip = MOO_SMOOI_TO_OOP(0); /* point to the beginning */ ctx->sp = MOO_SMOOI_TO_OOP(-1); /* pointer to -1 below the bottom */ - ctx->origin = ctx; /* point to self */ - ctx->method_or_nargs = (moo_oop_t)mth; /* fake. help SWITCH_ACTIVE_CONTEXT() not fail. TODO: create a static fake method and use it... instead of 'mth' */ + MOO_STORE_OOP (moo, (moo_oop_t*)&ctx->origin, (moo_oop_t)ctx); /* point to self */ + MOO_STORE_OOP (moo, (moo_oop_t*)&ctx->method_or_nargs, (moo_oop_t)mth); /* fake. help SWITCH_ACTIVE_CONTEXT() not fail. TODO: create a static fake method and use it... instead of 'mth' */ /* [NOTE] * the receiver field and the sender field of ctx are nils. @@ -2161,7 +2161,7 @@ static moo_pfrc_t __block_value (moo_t* moo, moo_oop_context_t rcv_blkctx, moo_o /* shallow-copy the named part including home, origin, etc. */ for (i = 0; i < MOO_CONTEXT_NAMED_INSTVARS; i++) { - ((moo_oop_oop_t)blkctx)->slot[i] = ((moo_oop_oop_t)rcv_blkctx)->slot[i]; + MOO_STORE_OOP (moo, &((moo_oop_oop_t)blkctx)->slot[i], ((moo_oop_oop_t)rcv_blkctx)->slot[i]); } #else blkctx->ip = rcv_blkctx->ip; @@ -2169,7 +2169,7 @@ static moo_pfrc_t __block_value (moo_t* moo, moo_oop_context_t rcv_blkctx, moo_o MOO_STORE_OOP (moo, &blkctx->method_or_nargs, rcv_blkctx->method_or_nargs); MOO_STORE_OOP (moo, &blkctx->receiver_or_source, (moo_oop_t)rcv_blkctx); MOO_STORE_OOP (moo, &blkctx->home, rcv_blkctx->home); - MOO_STORE_OOP (moo, &blkctx->origin, rcv_blkctx->origin); + MOO_STORE_OOP (moo, (moo_oop_t*)&blkctx->origin, (moo_oop_t)rcv_blkctx->origin); #endif /* TODO: check the stack size of a block context to see if it's large enough to hold arguments */ @@ -2200,7 +2200,7 @@ static moo_pfrc_t __block_value (moo_t* moo, moo_oop_context_t rcv_blkctx, moo_o MOO_ASSERT (moo, blkctx->home != moo->_nil); blkctx->sp = MOO_SMOOI_TO_OOP(-1); /* not important at all */ - MOO_STORE_OOP (moo, &blkctx->sender, moo->active_context); + MOO_STORE_OOP (moo, (moo_oop_t*)&blkctx->sender, (moo_oop_t)moo->active_context); *pblkctx = blkctx; return MOO_PF_SUCCESS; @@ -2622,7 +2622,7 @@ static moo_pfrc_t pf_semaphore_group_add_semaphore (moo_t* moo, moo_mod_t* mod, sems_idx = MOO_OOP_TO_SMOOI(sem->count) > 0? MOO_SEMAPHORE_GROUP_SEMS_SIG: MOO_SEMAPHORE_GROUP_SEMS_UNSIG; MOO_APPEND_TO_OOP_LIST (moo, &sg->sems[sems_idx], moo_oop_semaphore_t, sem, grm); - sem->group = sg; + MOO_STORE_OOP (moo, (moo_oop_t*)&sem->group, (moo_oop_t)sg); count = MOO_OOP_TO_SMOOI(sg->sem_count); MOO_ASSERT (moo, count >= 0); @@ -4626,11 +4626,11 @@ static MOO_INLINE int make_block (moo_t* moo) blkctx->ntmprs = MOO_SMOOI_TO_OOP(b2); /* set the home context where it's defined */ - blkctx->home = (moo_oop_t)moo->active_context; + MOO_STORE_OOP (moo, &blkctx->home, (moo_oop_t)moo->active_context); /* no source for a base block context. */ blkctx->receiver_or_source = moo->_nil; - blkctx->origin = moo->active_context->origin; + MOO_STORE_OOP (moo, (moo_oop_t*)&blkctx->origin, (moo_oop_t)moo->active_context->origin); /* push the new block context to the stack of the active context */ MOO_STACK_PUSH (moo, (moo_oop_t)blkctx); @@ -4736,7 +4736,7 @@ static int __execute (moo_t* moo) store_instvar: LOG_INST1 (moo, "store_into_instvar %zu", b1); MOO_ASSERT (moo, MOO_OBJ_GET_FLAGS_TYPE(moo->active_context->receiver_or_source) == MOO_OBJ_TYPE_OOP); - ((moo_oop_oop_t)moo->active_context->origin->receiver_or_source)->slot[b1] = MOO_STACK_GETTOP(moo); + MOO_STORE_OOP (moo, &((moo_oop_oop_t)moo->active_context->origin->receiver_or_source)->slot[b1], MOO_STACK_GETTOP(moo)); NEXT_INST(); /* ------------------------------------------------- */ @@ -4755,7 +4755,7 @@ static int __execute (moo_t* moo) pop_into_instvar: LOG_INST1 (moo, "pop_into_instvar %zu", b1); MOO_ASSERT (moo, MOO_OBJ_GET_FLAGS_TYPE(moo->active_context->receiver_or_source) == MOO_OBJ_TYPE_OOP); - ((moo_oop_oop_t)moo->active_context->origin->receiver_or_source)->slot[b1] = MOO_STACK_GETTOP(moo); + MOO_STORE_OOP (moo, &((moo_oop_oop_t)moo->active_context->origin->receiver_or_source)->slot[b1], MOO_STACK_GETTOP(moo)); MOO_STACK_POP (moo); NEXT_INST(); @@ -4858,7 +4858,7 @@ static int __execute (moo_t* moo) else { /* store or pop - bit 5 off */ - ctx->slot[bx] = MOO_STACK_GETTOP(moo); + MOO_STORE_OOP (moo, &ctx->slot[bx], MOO_STACK_GETTOP(moo)); if ((bcode >> 3) & 1) { @@ -4924,7 +4924,7 @@ static int __execute (moo_t* moo) if ((bcode >> 3) & 1) { /* store or pop */ - ass->value = MOO_STACK_GETTOP(moo); + MOO_STORE_OOP (moo, &ass->value, MOO_STACK_GETTOP(moo)); if ((bcode >> 2) & 1) { @@ -5128,7 +5128,7 @@ static int __execute (moo_t* moo) if ((bcode >> 3) & 1) { /* store or pop */ - ctx->slot[b2] = MOO_STACK_GETTOP(moo); + MOO_STORE_OOP (moo, &ctx->slot[b2], MOO_STACK_GETTOP(moo)); if ((bcode >> 2) & 1) { @@ -5187,7 +5187,7 @@ static int __execute (moo_t* moo) if ((bcode >> 3) & 1) { /* store or pop */ - t->slot[b1] = MOO_STACK_GETTOP(moo); + MOO_STORE_OOP (moo, &t->slot[b1], MOO_STACK_GETTOP(moo)); if ((bcode >> 2) & 1) { @@ -5381,7 +5381,7 @@ static int __execute (moo_t* moo) t1 = MOO_STACK_GETTOP(moo); MOO_STACK_POP (moo); t2 = MOO_STACK_GETTOP(moo); - ((moo_oop_oop_t)t2)->slot[b1] = t1; + MOO_STORE_OOP (moo, &((moo_oop_oop_t)t2)->slot[b1], t1); NEXT_INST(); } @@ -5529,7 +5529,7 @@ static int __execute (moo_t* moo) * the number of temporaries of a home context */ blkctx->ntmprs = MOO_SMOOI_TO_OOP(ntmprs); - blkctx->home = (moo_oop_t)rctx; + MOO_STORE_OOP (moo, &blkctx->home, (moo_oop_t)rctx); blkctx->receiver_or_source = moo->_nil; /* [NOTE] @@ -5547,7 +5547,7 @@ static int __execute (moo_t* moo) * if it is a block context, the following condition is true. * MOO_CLASSOF(moo, rctx) == moo->_block_context */ - blkctx->origin = rctx->origin; + MOO_STORE_OOP (moo, (moo_oop_t*)&blkctx->origin, (moo_oop_t)rctx->origin); MOO_STACK_SETTOP (moo, (moo_oop_t)blkctx); NEXT_INST(); diff --git a/moo/lib/gc.c b/moo/lib/gc.c index 3418e20..d4d68eb 100644 --- a/moo/lib/gc.c +++ b/moo/lib/gc.c @@ -546,7 +546,7 @@ static int ignite_3 (moo_t* moo) if (!sym) return -1; cls = *(moo_oop_class_t*)((moo_uint8_t*)moo + kernel_classes[i].offset); - cls->name = (moo_oop_char_t)sym; + MOO_STORE_OOP (moo, (moo_oop_t*)&cls->name, sym); cls->nsup = moo->sysdic; if (!moo_putatsysdic(moo, sym, (moo_oop_t)cls)) return -1; diff --git a/moo/lib/moo.h b/moo/lib/moo.h index d11340b..0a15bc4 100644 --- a/moo/lib/moo.h +++ b/moo/lib/moo.h @@ -500,6 +500,7 @@ struct moo_obj_word_t #define MOO_OBJ_GET_WORD_SLOT(oop) (((moo_oop_word_t)(oop))->slot) #define MOO_OBJ_GET_LIWORD_SLOT(oop) (((moo_oop_liword_t)(oop))->slot) +#if 0 #define MOO_OBJ_GET_OOP_SLOT_PTR(oop,idx) (&(((moo_oop_oop_t)(oop))->slot)[idx]) #define MOO_OBJ_GET_CHAR_SLOT_PTR(oop,idx) (&(((moo_oop_char_t)(oop))->slot)[idx]) #define MOO_OBJ_GET_BYTE_SLOT_PTR(oop,idx) (&(((moo_oop_byte_t)(oop))->slot)[idx]) @@ -520,6 +521,7 @@ struct moo_obj_word_t #define MOO_OBJ_SET_HALFWORD_SLOT_VAL(oop,idx,val) ((((moo_oop_halfword_t)(oop))->slot)[idx] = (val)) #define MOO_OBJ_SET_WORD_SLOT_VAL(oop,idx,val) ((((moo_oop_word_t)(oop))->slot)[idx] = (val)) #define MOO_OBJ_SET_LIWORD_SLOT_VAL(oop,idx,val) ((((moo_oop_liword_t)(oop))->slot)[idx] = (val)) +#endif typedef struct moo_trailer_t moo_trailer_t; struct moo_trailer_t diff --git a/moo/lib/obj.c b/moo/lib/obj.c index 80f9d2c..0b0b95a 100644 --- a/moo/lib/obj.c +++ b/moo/lib/obj.c @@ -98,13 +98,13 @@ moo_oop_t moo_allocoopobjwithtrailer (moo_t* moo, moo_oow_t size, const moo_oob_ hdr = (moo_oop_oop_t)moo_allocbytes(moo, MOO_SIZEOF(moo_obj_t) + nbytes_aligned); if (!hdr) return MOO_NULL; - hdr->_flags = MOO_OBJ_MAKE_FLAGS(MOO_OBJ_TYPE_OOP, MOO_SIZEOF(moo_oop_t), 0, 0, moo->igniting, 0, 0, 1); + hdr->_flags = MOO_OBJ_MAKE_FLAGS(MOO_OBJ_TYPE_OOP, MOO_SIZEOF(moo_oop_t), 0, 0, moo->igniting, 0, 0, 1); /* TRAILER bit -> 1 */ MOO_OBJ_SET_SIZE (hdr, size); MOO_OBJ_SET_CLASS (hdr, moo->_nil); for (i = 0; i < size; i++) hdr->slot[i] = moo->_nil; - /* [NOTE] this is not converted to a SmallInteger object */ + /* [NOTE] this is not converted to a SmallInteger object. it is a special slot handled by GC for an object with the TRAILER bit set */ hdr->slot[size] = (moo_oop_t)blen; if (bptr) @@ -275,7 +275,7 @@ moo_oop_t moo_instantiate (moo_t* moo, moo_oop_class_t _class, const void* vptr, while (i > 0) { --i; - ((moo_oop_oop_t)oop)->slot[i] = ((moo_oop_oop_t)_class->initv[0])->slot[i]; + MOO_STORE_OOP (moo, &((moo_oop_oop_t)oop)->slot[i], ((moo_oop_oop_t)_class->initv[0])->slot[i]); } } } @@ -361,7 +361,7 @@ moo_oop_t moo_instantiatewithtrailer (moo_t* moo, moo_oop_class_t _class, moo_oo while (i > 0) { --i; - ((moo_oop_oop_t)oop)->slot[i] = ((moo_oop_oop_t)_class->initv[0])->slot[i]; + MOO_STORE_OOP (moo, &((moo_oop_oop_t)oop)->slot[i], ((moo_oop_oop_t)_class->initv[0])->slot[i]); } } } diff --git a/moo/lib/sym.c b/moo/lib/sym.c index a8abc43..a564af8 100644 --- a/moo/lib/sym.c +++ b/moo/lib/sym.c @@ -53,7 +53,7 @@ static moo_oop_oop_t expand_bucket (moo_t* moo, moo_oop_oop_t oldbuc) if (inc_max > 0) inc = inc_max; else { - moo_seterrnum (moo, MOO_EOOMEM); + moo_seterrbfmt (moo, MOO_EOOMEM, "unable to grow symbol table"); return MOO_NULL; } } @@ -73,9 +73,9 @@ static moo_oop_oop_t expand_bucket (moo_t* moo, moo_oop_oop_t oldbuc) MOO_ASSERT (moo, MOO_CLASSOF(moo,symbol) == moo->_symbol); /*MOO_ASSERT (moo, sym->size > 0);*/ - index = moo_hashoochars(symbol->slot, MOO_OBJ_GET_SIZE(symbol)) % newsz; + index = moo_hashoochars(MOO_OBJ_GET_CHAR_SLOT(symbol), MOO_OBJ_GET_SIZE(symbol)) % newsz; while (newbuc->slot[index] != moo->_nil) index = (index + 1) % newsz; - newbuc->slot[index] = (moo_oop_t)symbol; + MOO_STORE_OOP (moo, &newbuc->slot[index], (moo_oop_t)symbol); } } @@ -98,7 +98,7 @@ static moo_oop_t find_or_make_symbol (moo_t* moo, const moo_ooch_t* ptr, moo_oow MOO_ASSERT (moo, MOO_CLASSOF(moo,symbol) == moo->_symbol); if (len == MOO_OBJ_GET_SIZE(symbol) && - moo_equal_oochars (ptr, symbol->slot, len)) + moo_equal_oochars(ptr, MOO_OBJ_GET_CHAR_SLOT(symbol), len)) { return (moo_oop_t)symbol; } @@ -119,7 +119,7 @@ static moo_oop_t find_or_make_symbol (moo_t* moo, const moo_ooch_t* ptr, moo_oow { /* this built-in table is not allowed to hold more than * MOO_SMOOI_MAX items for efficiency sake */ - moo_seterrnum (moo, MOO_EDFULL); + moo_seterrbfmt (moo, MOO_EDFULL, "unable to add a symbol %.*js - symbol table full", len, ptr); return MOO_NULL; } @@ -157,7 +157,7 @@ static moo_oop_t find_or_make_symbol (moo_t* moo, const moo_ooch_t* ptr, moo_oow { MOO_ASSERT (moo, tally < MOO_SMOOI_MAX); moo->symtab->tally = MOO_SMOOI_TO_OOP(tally + 1); - moo->symtab->bucket->slot[index] = (moo_oop_t)symbol; + MOO_STORE_OOP (moo, &moo->symtab->bucket->slot[index], (moo_oop_t)symbol); } return (moo_oop_t)symbol; @@ -165,12 +165,12 @@ static moo_oop_t find_or_make_symbol (moo_t* moo, const moo_ooch_t* ptr, moo_oow moo_oop_t moo_makesymbol (moo_t* moo, const moo_ooch_t* ptr, moo_oow_t len) { - return find_or_make_symbol (moo, ptr, len, 1); + return find_or_make_symbol(moo, ptr, len, 1); } moo_oop_t moo_findsymbol (moo_t* moo, const moo_ooch_t* ptr, moo_oow_t len) { - return find_or_make_symbol (moo, ptr, len, 0); + return find_or_make_symbol(moo, ptr, len, 0); } moo_oop_t moo_makestringwithbchars (moo_t* moo, const moo_bch_t* ptr, moo_oow_t len) @@ -180,7 +180,7 @@ moo_oop_t moo_makestringwithbchars (moo_t* moo, const moo_bch_t* ptr, moo_oow_t moo_oop_t obj; inlen = len; - if (moo_convbtouchars (moo, ptr, &inlen, MOO_NULL, &outlen) <= -1) return MOO_NULL; + if (moo_convbtouchars(moo, ptr, &inlen, MOO_NULL, &outlen) <= -1) return MOO_NULL; obj = moo_instantiate(moo, moo->_string, MOO_NULL, outlen); if (!obj) return MOO_NULL; @@ -201,7 +201,7 @@ moo_oop_t moo_makestringwithuchars (moo_t* moo, const moo_uch_t* ptr, moo_oow_t moo_oop_t obj; inlen = len; - if (moo_convutobchars (moo, ptr, &inlen, MOO_NULL, &outlen) <= -1) return MOO_NULL; + if (moo_convutobchars(moo, ptr, &inlen, MOO_NULL, &outlen) <= -1) return MOO_NULL; obj = moo_instantiate(moo, moo->_string, MOO_NULL, outlen); if (!obj) return MOO_NULL;