changing code to use more macros for the slot field access

This commit is contained in:
hyunghwan.chung 2018-12-12 15:05:18 +00:00
parent 8d10b4a5fa
commit 3d57095c4a
4 changed files with 54 additions and 26 deletions

View File

@ -114,7 +114,7 @@ static moo_oop_association_t find_or_upsert (moo_t* moo, moo_oop_dic_t dic, moo_
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_OBJ_GET_SIZE(key) == MOO_OBJ_GET_SIZE(ass->key) &&
moo_equal_oochars(key->slot, ((moo_oop_char_t)ass->key)->slot, 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. */ /* the value of MOO_NULL indicates no insertion or update. */
if (value) MOO_STORE_OOP (moo, &ass->value, value); /*ass->value = value;*/ /* update */ if (value) MOO_STORE_OOP (moo, &ass->value, value); /*ass->value = value;*/ /* update */
@ -219,7 +219,7 @@ moo_oop_association_t moo_lookupdic_noseterr (moo_t* moo, moo_oop_dic_t dic, con
MOO_ASSERT (moo, MOO_OBJ_IS_CHAR_POINTER(ass->key)); MOO_ASSERT (moo, MOO_OBJ_IS_CHAR_POINTER(ass->key));
if (name->len == MOO_OBJ_GET_SIZE(ass->key) && if (name->len == MOO_OBJ_GET_SIZE(ass->key) &&
moo_equal_oochars(name->ptr, ((moo_oop_char_t)ass->key)->slot, name->len)) moo_equal_oochars(name->ptr, MOO_OBJ_GET_CHAR_SLOT(ass->key), name->len))
{ {
return ass; return ass;
} }
@ -305,7 +305,7 @@ int moo_deletedic (moo_t* moo, moo_oop_dic_t dic, const moo_oocs_t* name)
MOO_ASSERT (moo, MOO_OBJ_IS_CHAR_POINTER(ass->key)); MOO_ASSERT (moo, MOO_OBJ_IS_CHAR_POINTER(ass->key));
if (name->len == MOO_OBJ_GET_SIZE(ass->key) && if (name->len == MOO_OBJ_GET_SIZE(ass->key) &&
moo_equal_oochars(name->ptr, ((moo_oop_char_t)ass->key)->slot, name->len)) moo_equal_oochars(name->ptr, MOO_OBJ_GET_CHAR_SLOT(ass->key), name->len))
{ {
goto found; goto found;
} }
@ -328,7 +328,7 @@ found:
/* get the natural hash index for the data in the slot at /* get the natural hash index for the data in the slot at
* the current hash index */ * the current hash index */
ass = (moo_oop_association_t)dic->bucket->slot[y]; ass = (moo_oop_association_t)dic->bucket->slot[y];
z = moo_hashoochars(((moo_oop_char_t)ass->key)->slot, MOO_OBJ_GET_SIZE(ass->key)) % bs; z = moo_hashoochars(MOO_OBJ_GET_CHAR_SLOT(ass->key), MOO_OBJ_GET_SIZE(ass->key)) % bs;
/* move an element if necesary */ /* move an element if necesary */
if ((y > x && (z <= x || z > y)) || if ((y > x && (z <= x || z > y)) ||

View File

@ -800,6 +800,8 @@ static moo_oop_process_t signal_semaphore (moo_t* moo, moo_oop_semaphore_t sem)
/* the semaphore belongs to a semaphore group */ /* the semaphore belongs to a semaphore group */
if ((moo_oop_t)sg->waiting.first != moo->_nil) if ((moo_oop_t)sg->waiting.first != moo->_nil)
{ {
moo_ooi_t sp;
/* there is a process waiting on the process group */ /* there is a process waiting on the process group */
proc = sg->waiting.first; proc = sg->waiting.first;
@ -815,7 +817,8 @@ static moo_oop_process_t signal_semaphore (moo_t* moo, moo_oop_semaphore_t sem)
* change the return value forcibly to the actual signaled * change the return value forcibly to the actual signaled
* semaphore */ * semaphore */
MOO_ASSERT (moo, MOO_OOP_TO_SMOOI(proc->sp) < (moo_ooi_t)(MOO_OBJ_GET_SIZE(proc) - MOO_PROCESS_NAMED_INSTVARS)); MOO_ASSERT (moo, MOO_OOP_TO_SMOOI(proc->sp) < (moo_ooi_t)(MOO_OBJ_GET_SIZE(proc) - MOO_PROCESS_NAMED_INSTVARS));
proc->slot[MOO_OOP_TO_SMOOI(proc->sp)] = (moo_oop_t)sem; sp = MOO_OOP_TO_SMOOI(proc->sp);
MOO_STORE_OOP (moo, &proc->slot[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 */ * signaled contains an IO semaphore */
@ -1529,7 +1532,7 @@ static MOO_INLINE int activate_new_method (moo_t* moo, moo_oop_method_t mth, moo
moo_poptmp (moo); moo_poptmp (moo);
if (!ctx) return -1; if (!ctx) return -1;
ctx->sender = moo->active_context; MOO_STORE_OOP (moo, &ctx->sender, moo->active_context);
ctx->ip = MOO_SMOOI_TO_OOP(0); ctx->ip = MOO_SMOOI_TO_OOP(0);
/* ctx->sp will be set further down */ /* ctx->sp will be set further down */
@ -1553,10 +1556,10 @@ static MOO_INLINE int activate_new_method (moo_t* moo, moo_oop_method_t mth, moo
*/ */
ctx->ntmprs = MOO_SMOOI_TO_OOP(ntmprs); ctx->ntmprs = MOO_SMOOI_TO_OOP(ntmprs);
ctx->method_or_nargs = (moo_oop_t)mth; MOO_STORE_OOP (moo, &ctx->method_or_nargs, (moo_oop_t)mth);
/* the 'home' field of a method context is always moo->_nil. /* the 'home' field of a method context is always moo->_nil.
ctx->home = moo->_nil;*/ ctx->home = moo->_nil;*/
ctx->origin = ctx; /* point to self */ MOO_STORE_OOP (moo, &ctx->origin, ctx); /* point to self */
/* /*
* Assume this message sending expression: * Assume this message sending expression:
@ -1584,14 +1587,16 @@ static MOO_INLINE int activate_new_method (moo_t* moo, moo_oop_method_t mth, moo
for (i = actual_nargs, j = ntmprs + (actual_nargs - nargs); i > nargs; i--) for (i = actual_nargs, j = ntmprs + (actual_nargs - nargs); i > nargs; i--)
{ {
/* place variadic arguments after local temporaries */ /* place variadic arguments after local temporaries */
ctx->slot[--j] = MOO_STACK_GETTOP(moo); --j;
MOO_STORE_OOP (moo, &ctx->slot[j], MOO_STACK_GETTOP(moo));
MOO_STACK_POP (moo); MOO_STACK_POP (moo);
} }
MOO_ASSERT (moo, i == nargs); MOO_ASSERT (moo, i == nargs);
while (i > 0) while (i > 0)
{ {
/* place normal argument before local temporaries */ /* place normal argument before local temporaries */
ctx->slot[--i] = MOO_STACK_GETTOP(moo); --i;
MOO_STORE_OOP (moo, &ctx->slot[i], MOO_STACK_GETTOP(moo));
MOO_STACK_POP (moo); MOO_STACK_POP (moo);
} }
} }
@ -1600,12 +1605,13 @@ static MOO_INLINE int activate_new_method (moo_t* moo, moo_oop_method_t mth, moo
for (i = actual_nargs; i > 0; ) for (i = actual_nargs; i > 0; )
{ {
/* place normal argument before local temporaries */ /* place normal argument before local temporaries */
ctx->slot[--i] = MOO_STACK_GETTOP (moo); --i;
MOO_STORE_OOP (moo, &ctx->slot[i], MOO_STACK_GETTOP(moo));
MOO_STACK_POP (moo); MOO_STACK_POP (moo);
} }
} }
/* copy receiver */ /* copy receiver */
ctx->receiver_or_source = MOO_STACK_GETTOP (moo); MOO_STORE_OOP (moo, &ctx->receiver_or_source, MOO_STACK_GETTOP(moo));
MOO_STACK_POP (moo); MOO_STACK_POP (moo);
MOO_ASSERT (moo, moo->sp >= -1); MOO_ASSERT (moo, moo->sp >= -1);
@ -2160,10 +2166,10 @@ static moo_pfrc_t __block_value (moo_t* moo, moo_oop_context_t rcv_blkctx, moo_o
#else #else
blkctx->ip = rcv_blkctx->ip; blkctx->ip = rcv_blkctx->ip;
blkctx->ntmprs = rcv_blkctx->ntmprs; blkctx->ntmprs = rcv_blkctx->ntmprs;
blkctx->method_or_nargs = rcv_blkctx->method_or_nargs; MOO_STORE_OOP (moo, &blkctx->method_or_nargs, rcv_blkctx->method_or_nargs);
blkctx->receiver_or_source = (moo_oop_t)rcv_blkctx; MOO_STORE_OOP (moo, &blkctx->receiver_or_source, (moo_oop_t)rcv_blkctx);
blkctx->home = rcv_blkctx->home; MOO_STORE_OOP (moo, &blkctx->home, rcv_blkctx->home);
blkctx->origin = rcv_blkctx->origin; MOO_STORE_OOP (moo, &blkctx->origin, rcv_blkctx->origin);
#endif #endif
/* TODO: check the stack size of a block context to see if it's large enough to hold arguments */ /* TODO: check the stack size of a block context to see if it's large enough to hold arguments */
@ -2173,12 +2179,12 @@ static moo_pfrc_t __block_value (moo_t* moo, moo_oop_context_t rcv_blkctx, moo_o
* to pass array elements to the new block */ * to pass array elements to the new block */
moo_oop_oop_t xarg; moo_oop_oop_t xarg;
MOO_ASSERT (moo, nargs == 1); MOO_ASSERT (moo, nargs == 1);
xarg = (moo_oop_oop_t)MOO_STACK_GETTOP (moo); xarg = (moo_oop_oop_t)MOO_STACK_GETTOP(moo);
MOO_ASSERT (moo, MOO_OBJ_IS_OOP_POINTER(xarg)); 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++) for (i = 0; i < num_first_arg_elems; i++)
{ {
blkctx->slot[i] = xarg->slot[i]; MOO_STORE_OOP (moo, &blkctx->slot[i], xarg->slot[i]);
} }
} }
else else
@ -2186,14 +2192,15 @@ static moo_pfrc_t __block_value (moo_t* moo, moo_oop_context_t rcv_blkctx, moo_o
/* copy the arguments to the stack */ /* copy the arguments to the stack */
for (i = 0; i < nargs; i++) for (i = 0; i < nargs; i++)
{ {
blkctx->slot[i] = MOO_STACK_GETARG(moo, nargs, i); register moo_oop_t tmp = MOO_STACK_GETARG(moo, nargs, i);
MOO_STORE_OOP (moo, &blkctx->slot[i], tmp);
} }
} }
MOO_STACK_POPS (moo, nargs + 1); /* pop arguments and receiver */ MOO_STACK_POPS (moo, nargs + 1); /* pop arguments and receiver */
MOO_ASSERT (moo, blkctx->home != moo->_nil); MOO_ASSERT (moo, blkctx->home != moo->_nil);
blkctx->sp = MOO_SMOOI_TO_OOP(-1); /* not important at all */ blkctx->sp = MOO_SMOOI_TO_OOP(-1); /* not important at all */
blkctx->sender = moo->active_context; MOO_STORE_OOP (moo, &blkctx->sender, moo->active_context);
*pblkctx = blkctx; *pblkctx = blkctx;
return MOO_PF_SUCCESS; return MOO_PF_SUCCESS;

View File

@ -500,6 +500,27 @@ struct moo_obj_word_t
#define MOO_OBJ_GET_WORD_SLOT(oop) (((moo_oop_word_t)(oop))->slot) #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) #define MOO_OBJ_GET_LIWORD_SLOT(oop) (((moo_oop_liword_t)(oop))->slot)
#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])
#define MOO_OBJ_GET_HALFWORD_SLOT_PTR(oop,idx) (&(((moo_oop_halfword_t)(oop))->slot)[idx])
#define MOO_OBJ_GET_WORD_SLOT_PTR(oop,idx) (&(((moo_oop_word_t)(oop))->slot)[idx])
#define MOO_OBJ_GET_LIWORD_SLOT_PTR(oop,idx) (&(((moo_oop_liword_t)(oop))->slot)[idx])
#define MOO_OBJ_GET_OOP_SLOT_VAL(oop,idx) ((((moo_oop_oop_t)(oop))->slot)[idx])
#define MOO_OBJ_GET_CHAR_SLOT_VAL(oop,idx) ((((moo_oop_char_t)(oop))->slot)[idx])
#define MOO_OBJ_GET_BYTE_SLOT_VAL(oop,idx) ((((moo_oop_byte_t)(oop))->slot)[idx])
#define MOO_OBJ_GET_HALFWORD_SLOT_VAL(oop,idx) ((((moo_oop_halfword_t)(oop))->slot)[idx])
#define MOO_OBJ_GET_WORD_SLOT_VAL(oop,idx) ((((moo_oop_word_t)(oop))->slot)[idx])
#define MOO_OBJ_GET_LIWORD_SLOT_VAL(oop,idx) ((((moo_oop_liword_t)(oop))->slot)[idx])
/*#define MOO_OBJ_SET_OOP_SLOT_VAL(oop,idx,val) ((((moo_oop_oop_t)(oop))->slot)[idx] = (val)) - I must use MOO_STORE_OOP() instead.*/
#define MOO_OBJ_SET_CHAR_SLOT_VAL(oop,idx,val) ((((moo_oop_char_t)(oop))->slot)[idx] = (val))
#define MOO_OBJ_SET_BYTE_SLOT_VAL(oop,idx,val) ((((moo_oop_byte_t)(oop))->slot)[idx] = (val))
#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))
typedef struct moo_trailer_t moo_trailer_t; typedef struct moo_trailer_t moo_trailer_t;
struct moo_trailer_t struct moo_trailer_t
{ {

View File

@ -106,7 +106,7 @@ static moo_pfrc_t pf_open (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
goto softfail; goto softfail;
} }
handle = moo->vmprim.dl_open (moo, ((moo_oop_char_t)name)->slot, 0); handle = moo->vmprim.dl_open (moo, MOO_OBJ_GET_CHAR_SLOT(name), 0);
if (!handle) goto softfail; if (!handle) goto softfail;
#if defined(USE_DYNCALL) #if defined(USE_DYNCALL)
@ -125,7 +125,7 @@ static moo_pfrc_t pf_open (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
ffi->dc = dc; ffi->dc = dc;
#endif #endif
MOO_DEBUG3 (moo, "<ffi.open> %.*js => %p\n", MOO_OBJ_GET_SIZE(name), ((moo_oop_char_t)name)->slot, ffi->handle); MOO_DEBUG3 (moo, "<ffi.open> %.*js => %p\n", MOO_OBJ_GET_SIZE(name), MOO_OBJ_GET_CHAR_SLOT(name), ffi->handle);
MOO_STACK_SETRETTORCV (moo, nargs); MOO_STACK_SETRETTORCV (moo, nargs);
return MOO_PF_SUCCESS; return MOO_PF_SUCCESS;
@ -203,7 +203,7 @@ static moo_pfrc_t pf_call (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
dcReset (ffi->dc); dcReset (ffi->dc);
i = 0; i = 0;
if (i < MOO_OBJ_GET_SIZE(sig) && ((moo_oop_char_t)sig)->slot[i] == '|') if (i < MOO_OBJ_GET_SIZE(sig) && MOO_OBJ_GET_CHAR_SLOT(sig)[i] == '|')
{ {
dcMode (ffi->dc, DC_CALL_C_ELLIPSIS); dcMode (ffi->dc, DC_CALL_C_ELLIPSIS);
@ -219,7 +219,7 @@ static moo_pfrc_t pf_call (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
moo_ooch_t fmtc; moo_ooch_t fmtc;
moo_oop_t arg; moo_oop_t arg;
fmtc = ((moo_oop_char_t)sig)->slot[i]; fmtc = MOO_OBJ_GET_CHAR_SLOT(sig)[i];
if (fmtc == ')') if (fmtc == ')')
{ {
@ -499,10 +499,10 @@ static moo_pfrc_t pf_getsym (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
goto softfail; goto softfail;
} }
sym = moo->vmprim.dl_getsym (moo, ffi->handle, ((moo_oop_char_t)name)->slot); sym = moo->vmprim.dl_getsym (moo, ffi->handle, MOO_OBJ_GET_CHAR_SLOT(name));
if (!sym) goto softfail; if (!sym) goto softfail;
MOO_DEBUG4 (moo, "<ffi.getsym> %.*js => %p in %p\n", MOO_OBJ_GET_SIZE(name), ((moo_oop_char_t)name)->slot, sym, ffi->handle); MOO_DEBUG4 (moo, "<ffi.getsym> %.*js => %p in %p\n", MOO_OBJ_GET_SIZE(name), MOO_OBJ_GET_CHAR_SLOT(name), sym, ffi->handle);
MOO_ASSERT (moo, MOO_IN_SMPTR_RANGE(sym)); MOO_ASSERT (moo, MOO_IN_SMPTR_RANGE(sym));
MOO_STACK_SETRET (moo, nargs, MOO_SMPTR_TO_OOP(sym)); MOO_STACK_SETRET (moo, nargs, MOO_SMPTR_TO_OOP(sym));