substitute more macros for the slot field access.

simplified code by getting rid of SET_ACTIVE_METHOD_CODE() and making related changes
This commit is contained in:
hyunghwan.chung 2018-12-23 08:33:52 +00:00
parent 981882de7e
commit b13892d586
7 changed files with 52 additions and 37 deletions

View File

@ -333,7 +333,7 @@ found:
}
}
dic->bucket->slot[x] = moo->_nil; /* the value is nil. no MOO_STORE_OOP */
MOO_OBJ_SET_OOP_VAL (dic->bucket, x, moo->_nil); /* the value is nil. no MOO_STORE_OOP */
tally--;
dic->tally = MOO_SMOOI_TO_OOP(tally);

View File

@ -91,7 +91,7 @@ static MOO_INLINE const char* proc_state_to_string (int state)
STORE_ACTIVE_IP (moo); \
(moo)->active_context = (v_ctx); \
(moo)->active_method = (moo_oop_method_t)(moo)->active_context->origin->method_or_nargs; \
SET_ACTIVE_METHOD_CODE(moo); \
(moo)->active_code = MOO_METHOD_GET_CODE_BYTE((moo)->active_method); \
LOAD_ACTIVE_IP (moo); \
(moo)->processor->active->current_context = (moo)->active_context; \
} while (0)

View File

@ -1024,7 +1024,7 @@ void moo_gc (moo_t* moo)
}
*/
if (moo->active_method) SET_ACTIVE_METHOD_CODE (moo); /* update moo->active_code */
if (moo->active_method) moo->active_code = MOO_METHOD_GET_CODE_BYTE(moo->active_method); /* update moo->active_code */
if (gcfin_count > 0) moo->sem_gcfin_sigreq = 1;
/* TODO: include some gc statstics like number of live objects, gc performance, etc */

View File

@ -661,14 +661,6 @@ struct moo_compiler_t
};
#endif
#if defined(MOO_USE_METHOD_TRAILER)
/* let it point to the trailer of the method */
# define SET_ACTIVE_METHOD_CODE(moo) ((moo)->active_code = (moo_oob_t*)&(moo)->active_method->literal_frame[MOO_OBJ_GET_SIZE((moo)->active_method) + 1 - MOO_METHOD_NAMED_INSTVARS])
#else
/* let it point to the payload of the code byte array */
# define SET_ACTIVE_METHOD_CODE(moo) ((moo)->active_code = (moo)->active_method->code->slot)
#endif
#if defined(MOO_BCODE_LONG_PARAM_SIZE) && (MOO_BCODE_LONG_PARAM_SIZE == 1)
# define MAX_CODE_INDEX (0xFFu)
# define MAX_CODE_NTMPRS (0xFFu)

View File

@ -515,7 +515,7 @@ struct moo_obj_word_t
#define MOO_OBJ_GET_WORD_VAL(oop,idx) ((((moo_oop_word_t)(oop))->slot)[idx])
#define MOO_OBJ_GET_LIWORD_VAL(oop,idx) ((((moo_oop_liword_t)(oop))->slot)[idx])
/*#define MOO_OBJ_SET_OOP_VAL(oop,idx,val) ((((moo_oop_oop_t)(oop))->slot)[idx] = (val)) - I must use MOO_STORE_OOP() instead.*/
#define MOO_OBJ_SET_OOP_VAL(oop,idx,val) ((((moo_oop_oop_t)(oop))->slot)[idx] = (val)) /* NOTE: MOO_STORE_OOP() */
#define MOO_OBJ_SET_CHAR_VAL(oop,idx,val) ((((moo_oop_char_t)(oop))->slot)[idx] = (val))
#define MOO_OBJ_SET_BYTE_VAL(oop,idx,val) ((((moo_oop_byte_t)(oop))->slot)[idx] = (val))
#define MOO_OBJ_SET_HALFWORD_VAL(oop,idx,val) ((((moo_oop_halfword_t)(oop))->slot)[idx] = (val))
@ -680,18 +680,16 @@ struct moo_method_t
};
#if defined(MOO_USE_METHOD_TRAILER)
/* if m is to be type-cast to moo_oop_method_t, the macro must be
* redefined to this:
* (&((moo_oop_method_t)m)>slot[MOO_OBJ_GET_SIZE(m) + 1 - MOO_METHOD_NAMED_INSTVARS])
*/
/*((moo_oob_t*)&((moo_oop_oop_t)m)->slot[MOO_OBJ_GET_SIZE(m) + 1])*/
/* the first byte after the main payload is the trailer size
* 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])
* 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)
/*((moo_oow_t)((moo_oop_oop_t)m)->slot[MOO_OBJ_GET_SIZE(m)])*/
# define MOO_METHOD_GET_CODE_SIZE(m) MOO_OBJ_GET_TRAILER_SIZE(m)
#else
# define MOO_METHOD_GET_CODE_BYTE(m) ((m)->code->slot)
# define MOO_METHOD_GET_CODE_BYTE(m) MOO_OBJ_GET_BYTE_SLOT(((m)->code)
# define MOO_METHOD_GET_CODE_SIZE(m) MOO_OBJ_GET_SIZE((m)->code)
#endif

View File

@ -80,7 +80,11 @@ 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) hdr->slot[--size] = moo->_nil;
while (size > 0)
{
size = size - 1;
MOO_OBJ_SET_OOP_VAL (hdr, size, moo->_nil);
}
return (moo_oop_t)hdr;
}
@ -102,18 +106,22 @@ 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++) hdr->slot[i] = moo->_nil;
for (i = 0; i < size; i++)
{
MOO_OBJ_SET_OOP_VAL (hdr, i, moo->_nil);
}
/* [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;
MOO_OBJ_SET_OOP_VAL (hdr, size, (moo_oop_t)blen);
/* the trailer part is just composed of raw bytes from the moo core's perspective. */
if (bptr)
{
MOO_MEMCPY (&hdr->slot[size + 1], bptr, blen);
MOO_MEMCPY ((moo_oob_t*)MOO_OBJ_GET_OOP_PTR(hdr, size + 1), bptr, blen);
}
else
{
MOO_MEMSET (&hdr->slot[size + 1], 0, blen);
MOO_MEMSET ((moo_oob_t*)MOO_OBJ_GET_OOP_PTR(hdr, size + 1), 0, blen);
}
return (moo_oop_t)hdr;
@ -275,7 +283,7 @@ moo_oop_t moo_instantiate (moo_t* moo, moo_oop_class_t _class, const void* vptr,
while (i > 0)
{
--i;
MOO_STORE_OOP (moo, &((moo_oop_oop_t)oop)->slot[i], ((moo_oop_oop_t)_class->initv[0])->slot[i]);
MOO_STORE_OOP (moo, MOO_OBJ_GET_OOP_PTR(oop, i), MOO_OBJ_GET_OOP_VAL(_class->initv[0], i));
}
}
}
@ -361,7 +369,7 @@ moo_oop_t moo_instantiatewithtrailer (moo_t* moo, moo_oop_class_t _class, moo_oo
while (i > 0)
{
--i;
MOO_STORE_OOP (moo, &((moo_oop_oop_t)oop)->slot[i], ((moo_oop_oop_t)_class->initv[0])->slot[i]);
MOO_STORE_OOP (moo, MOO_OBJ_GET_OOP_PTR(oop, i), MOO_OBJ_GET_OOP_VAL(_class->initv[0], i));
}
}
}

View File

@ -441,7 +441,7 @@ moo_pfrc_t moo_pf_basic_at_put (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
}
case MOO_OBJ_TYPE_OOP:
MOO_STORE_OOP (moo, MOO_OBJ_GET_OOP_PTR(rcv, idx), val); /*((moo_oop_oop_t)rcv)->slot[idx] = val;*/
MOO_STORE_OOP (moo, MOO_OBJ_GET_OOP_PTR(rcv, idx), val);
break;
default:
@ -713,19 +713,36 @@ moo_pfrc_t moo_pf_basic_shift (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
break;
case MOO_OBJ_TYPE_OOP:
MOO_MEMMOVE (&((moo_oop_oop_t)rcv)->slot[didx],
&((moo_oop_oop_t)rcv)->slot[sidx],
ssz * MOO_SIZEOF(((moo_oop_oop_t)rcv)->slot[0]));
if (didx > sidx)
{
/* no need to use MOO_STORE_OOP because moo->_nil is the assigning value */
while (sidx < didx) ((moo_oop_oop_t)rcv)->slot[sidx++] = moo->_nil;
moo_oow_t i;
for (i = ssz; i > 0; )
{
MOO_STORE_OOP (moo, MOO_OBJ_GET_OOP_PTR(rcv, didx + i), MOO_OBJ_GET_OOP_VAL(rcv, sidx + i));
}
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);
sidx = sidx + 1;
}
}
else
{
/* no need to use MOO_STORE_OOP because moo->_nil is the assigning value */
while (didx > sidx) ((moo_oop_oop_t)rcv)->slot[(didx++) + ssz] = moo->_nil;
moo_oow_t i;
for (i = 0; i < ssz; i++)
{
--i;
MOO_STORE_OOP (moo, MOO_OBJ_GET_OOP_PTR(rcv, didx + i), MOO_OBJ_GET_OOP_VAL(rcv, sidx + i));
}
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);
didx = didx + 1;
}
}
break;