added Apex>>basicLastIndex, Apex>>_basicLastIndex. Apex>>basicFirstIndex, Apex>>_basicFirstIndex

This commit is contained in:
hyunghwan.chung 2019-08-17 10:08:25 +00:00
parent a65b64a0d9
commit 68eb5d8db8
4 changed files with 66 additions and 0 deletions

View File

@ -119,6 +119,10 @@ extend Apex
// ------------------------------------------------------- // -------------------------------------------------------
method(#dual,#primitive,#lenient) _basicSize. method(#dual,#primitive,#lenient) _basicSize.
method(#dual,#primitive) basicSize. method(#dual,#primitive) basicSize.
method(#dual,#primitive,#lenient) _basicFirstIndex.
method(#dual,#primitive) basicFirstIndex.
method(#dual,#primitive,#lenient) _basicLastIndex.
method(#dual,#primitive) basicLastIndex.
method(#dual,#primitive) basicAt: index. method(#dual,#primitive) basicAt: index.

View File

@ -4050,6 +4050,8 @@ static pf_t pftab[] =
{ "Apex_basicAt:put:", { moo_pf_basic_at_put, 2, 2 } }, { "Apex_basicAt:put:", { moo_pf_basic_at_put, 2, 2 } },
{ "Apex_basicAt:test:put:", { moo_pf_basic_at_test_put, 3, 3 } }, { "Apex_basicAt:test:put:", { moo_pf_basic_at_test_put, 3, 3 } },
{ "Apex_basicFillFrom:with:count:", { moo_pf_basic_fill, 3, 3 } }, { "Apex_basicFillFrom:with:count:", { moo_pf_basic_fill, 3, 3 } },
{ "Apex_basicFirstIndex", { moo_pf_basic_first_index, 0, 0 } },
{ "Apex_basicLastIndex", { moo_pf_basic_last_index, 0, 0 } },
{ "Apex_basicNew", { moo_pf_basic_new, 0, 0 } }, { "Apex_basicNew", { moo_pf_basic_new, 0, 0 } },
{ "Apex_basicNew:", { moo_pf_basic_new, 1, 1 } }, { "Apex_basicNew:", { moo_pf_basic_new, 1, 1 } },
{ "Apex_basicShiftFrom:to:count:", { moo_pf_basic_shift, 3, 3 } }, { "Apex_basicShiftFrom:to:count:", { moo_pf_basic_shift, 3, 3 } },

View File

@ -1612,6 +1612,8 @@ moo_pfrc_t moo_pf_shallow_copy (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs);
moo_pfrc_t moo_pf_class (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs); moo_pfrc_t moo_pf_class (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs);
moo_pfrc_t moo_pf_basic_size (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs); moo_pfrc_t moo_pf_basic_size (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs);
moo_pfrc_t moo_pf_basic_first_index (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs);
moo_pfrc_t moo_pf_basic_last_index (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs);
moo_pfrc_t moo_pf_basic_at (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs); moo_pfrc_t moo_pf_basic_at (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs);
moo_pfrc_t moo_pf_basic_at_put (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs); moo_pfrc_t moo_pf_basic_at_put (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs);
moo_pfrc_t moo_pf_basic_at_test_put (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs); moo_pfrc_t moo_pf_basic_at_test_put (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs);

View File

@ -292,6 +292,64 @@ moo_pfrc_t moo_pf_basic_size (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
return MOO_PF_SUCCESS; return MOO_PF_SUCCESS;
} }
moo_pfrc_t moo_pf_basic_last_index (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
/* return the number of indexable fields */
moo_oop_t rcv, sz;
MOO_ASSERT (moo, nargs == 0);
rcv = MOO_STACK_GETRCV (moo, nargs);
if (!MOO_OOP_IS_POINTER(rcv) || MOO_OBJ_GET_SIZE(rcv) == 0)
{
sz = MOO_SMOOI_TO_OOP(-1);
}
else
{
sz = MOO_SMOOI_TO_OOP(0);
}
MOO_STACK_SETRET(moo, nargs, sz);
return MOO_PF_SUCCESS;
}
moo_pfrc_t moo_pf_basic_first_index (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
/* return the number of indexable fields */
moo_oop_t rcv, sz;
MOO_ASSERT (moo, nargs == 0);
rcv = MOO_STACK_GETRCV (moo, nargs);
if (!MOO_OOP_IS_POINTER(rcv))
{
/* 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);
}
else
{
moo_oow_t rcvsize = MOO_OBJ_GET_SIZE(rcv);
if (rcvsize == 0)
{
sz = MOO_SMOOI_TO_OOP(-1);
}
else
{
sz = moo_oowtoint(moo, rcvsize - 1);
if (!sz) return MOO_PF_FAILURE;
}
}
MOO_STACK_SETRET(moo, nargs, sz);
return MOO_PF_SUCCESS;
}
moo_pfrc_t moo_pf_basic_at (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) moo_pfrc_t moo_pf_basic_at (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{ {
moo_oop_t rcv, pos, v; moo_oop_t rcv, pos, v;