added moo_pfbase_t and changed some functions to return moo_pfbase_t* instead of moo_pfimpl_t
touched up some modules
This commit is contained in:
@ -3163,7 +3163,7 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs)
|
||||
{
|
||||
moo_ooi_t pf_name_index;
|
||||
moo_oop_t name;
|
||||
moo_pfimpl_t handler;
|
||||
moo_pfbase_t* pfbase;
|
||||
moo_oow_t w;
|
||||
|
||||
stack_base = moo->sp - nargs - 1; /* stack base before receiver and arguments */
|
||||
@ -3182,22 +3182,22 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs)
|
||||
/* 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) |
|
||||
(moo_oow_t)MOO_OOP_TO_SMOOI(method->preamble_data[1]);
|
||||
handler = (moo_pfimpl_t)w;
|
||||
if (handler) goto exec_handler;
|
||||
pfbase = (moo_pfbase_t*)w;
|
||||
if (pfbase) goto exec_handler;
|
||||
|
||||
#if defined(NDEBUG)
|
||||
pf_name_index = MOO_METHOD_GET_PREAMBLE_INDEX(preamble);
|
||||
name = method->slot[pf_name_index];
|
||||
#endif
|
||||
|
||||
handler = moo_querymod (moo, ((moo_oop_char_t)name)->slot, MOO_OBJ_GET_SIZE(name));
|
||||
if (handler)
|
||||
pfbase = moo_querymod (moo, ((moo_oop_char_t)name)->slot, MOO_OBJ_GET_SIZE(name));
|
||||
if (pfbase)
|
||||
{
|
||||
int n;
|
||||
|
||||
/* split a pointer to two OOP fields as SmallIntegers for storing/caching. */
|
||||
method->preamble_data[0] = MOO_SMOOI_TO_OOP((moo_oow_t)handler >> (MOO_OOW_BITS / 2));
|
||||
method->preamble_data[1] = MOO_SMOOI_TO_OOP((moo_oow_t)handler & MOO_LBMASK(moo_oow_t, MOO_OOW_BITS / 2));
|
||||
method->preamble_data[0] = MOO_SMOOI_TO_OOP((moo_oow_t)pfbase >> (MOO_OOW_BITS / 2));
|
||||
method->preamble_data[1] = MOO_SMOOI_TO_OOP((moo_oow_t)pfbase & MOO_LBMASK(moo_oow_t, MOO_OOW_BITS / 2));
|
||||
|
||||
exec_handler:
|
||||
moo_pushtmp (moo, (moo_oop_t*)&method);
|
||||
@ -3208,18 +3208,18 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs)
|
||||
* directly in the stack unlik a normal activated method context where the
|
||||
* arguments are copied to the back. */
|
||||
|
||||
n = handler (moo, nargs);
|
||||
n = pfbase->handler (moo, nargs);
|
||||
|
||||
moo_poptmp (moo);
|
||||
if (n <= MOO_PF_HARD_FAILURE)
|
||||
{
|
||||
MOO_DEBUG4 (moo, "Hard failure indicated by primitive function %p - %.*js - return code %d\n", handler, MOO_OBJ_GET_SIZE(name), ((moo_oop_char_t)name)->slot, n);
|
||||
MOO_DEBUG4 (moo, "Hard failure indicated by primitive function %p - %.*js - return code %d\n", pfbase->handler, MOO_OBJ_GET_SIZE(name), ((moo_oop_char_t)name)->slot, n);
|
||||
return -1; /* hard primitive failure */
|
||||
}
|
||||
if (n >= MOO_PF_SUCCESS) break; /* primitive ok*/
|
||||
|
||||
/* soft primitive failure */
|
||||
MOO_DEBUG3 (moo, "Soft failure indicated by primitive function %p - %.*js\n", handler, MOO_OBJ_GET_SIZE(name), ((moo_oop_char_t)name)->slot);
|
||||
MOO_DEBUG3 (moo, "Soft failure indicated by primitive function %p - %.*js\n", pfbase->handler, MOO_OBJ_GET_SIZE(name), ((moo_oop_char_t)name)->slot);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1202,7 +1202,7 @@ int moo_importmod (
|
||||
* The moo_querymod() function finds a primitive function in modules
|
||||
* with a full primitive identifier.
|
||||
*/
|
||||
moo_pfimpl_t moo_querymod (
|
||||
moo_pfbase_t* moo_querymod (
|
||||
moo_t* moo,
|
||||
const moo_ooch_t* pfid,
|
||||
moo_oow_t pfidlen
|
||||
|
@ -603,7 +603,7 @@ done2:
|
||||
return r;
|
||||
}
|
||||
|
||||
moo_pfimpl_t moo_querymod (moo_t* moo, const moo_ooch_t* pfid, moo_oow_t pfidlen)
|
||||
moo_pfbase_t* moo_querymod (moo_t* moo, const moo_ooch_t* pfid, moo_oow_t pfidlen)
|
||||
{
|
||||
/* primitive function identifier
|
||||
* _funcname
|
||||
@ -614,7 +614,7 @@ moo_pfimpl_t moo_querymod (moo_t* moo, const moo_ooch_t* pfid, moo_oow_t pfidlen
|
||||
const moo_ooch_t* sep;
|
||||
|
||||
moo_oow_t mod_name_len;
|
||||
moo_pfimpl_t handler;
|
||||
moo_pfbase_t* pfbase;
|
||||
|
||||
sep = moo_rfindoochar (pfid, pfidlen, '.');
|
||||
if (!sep)
|
||||
@ -647,7 +647,7 @@ moo_pfimpl_t moo_querymod (moo_t* moo, const moo_ooch_t* pfid, moo_oow_t pfidlen
|
||||
if (!mdp) return MOO_NULL;
|
||||
}
|
||||
|
||||
if ((handler = mdp->mod.query (moo, &mdp->mod, sep + 1)) == MOO_NULL)
|
||||
if ((pfbase = mdp->mod.query (moo, &mdp->mod, sep + 1)) == MOO_NULL)
|
||||
{
|
||||
/* the primitive function is not found. but keep the module open even if it's opened above */
|
||||
MOO_DEBUG2 (moo, "Cannot find a primitive function [%js] in a module [%js]\n", sep + 1, mdp->mod.name);
|
||||
@ -655,12 +655,13 @@ moo_pfimpl_t moo_querymod (moo_t* moo, const moo_ooch_t* pfid, moo_oow_t pfidlen
|
||||
return MOO_NULL;
|
||||
}
|
||||
|
||||
MOO_DEBUG3 (moo, "Found a primitive function [%js] in a module [%js] - %p\n", sep + 1, mdp->mod.name, handler);
|
||||
return handler;
|
||||
MOO_DEBUG3 (moo, "Found a primitive function [%js] in a module [%js] - %p\n", sep + 1, mdp->mod.name, pfbase);
|
||||
return pfbase;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#if 0
|
||||
/* add a new primitive method */
|
||||
int moo_genpfmethod (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class, moo_method_type_t type, const moo_ooch_t* mthname, int variadic, const moo_ooch_t* pfname)
|
||||
{
|
||||
@ -792,8 +793,9 @@ int moo_genpfmethods (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class, const
|
||||
moo_poptmp (moo);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
moo_pfimpl_t moo_findpfimpl (moo_t* moo, const moo_pfinfo_t* pfinfo, moo_oow_t pfcount, const moo_ooch_t* name)
|
||||
moo_pfbase_t* moo_findpfbase (moo_t* moo, const moo_pfinfo_t* pfinfo, moo_oow_t pfcount, const moo_ooch_t* name)
|
||||
{
|
||||
int left, right, mid, n;
|
||||
|
||||
@ -808,7 +810,7 @@ moo_pfimpl_t moo_findpfimpl (moo_t* moo, const moo_pfinfo_t* pfinfo, moo_oow_t p
|
||||
else if (n > 0) left = mid + 1;
|
||||
else
|
||||
{
|
||||
return pfinfo[mid].handler;
|
||||
return &pfinfo[mid].base;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -831,13 +831,21 @@ typedef moo_pfrc_t (*moo_pfimpl_t) (
|
||||
moo_ooi_t nargs
|
||||
);
|
||||
|
||||
typedef struct moo_pfbase_t moo_pfbase_t;
|
||||
struct moo_pfbase_t
|
||||
{
|
||||
moo_pfimpl_t handler;
|
||||
moo_oow_t minargs;
|
||||
moo_oow_t maxargs;
|
||||
};
|
||||
|
||||
typedef struct moo_pfinfo_t moo_pfinfo_t;
|
||||
struct moo_pfinfo_t
|
||||
{
|
||||
moo_method_type_t type;
|
||||
moo_ooch_t mthname[32];
|
||||
int variadic;
|
||||
moo_pfimpl_t handler;
|
||||
moo_pfbase_t base;
|
||||
};
|
||||
|
||||
typedef struct moo_mod_t moo_mod_t;
|
||||
@ -859,7 +867,7 @@ typedef int (*moo_mod_import_t) (
|
||||
moo_oop_class_t _class
|
||||
);
|
||||
|
||||
typedef moo_pfimpl_t (*moo_mod_query_t) (
|
||||
typedef moo_pfbase_t* (*moo_mod_query_t) (
|
||||
moo_t* moo,
|
||||
moo_mod_t* mod,
|
||||
const moo_ooch_t* name
|
||||
@ -1559,6 +1567,7 @@ MOO_EXPORT int moo_genpfmethod (
|
||||
const moo_ooch_t* name
|
||||
);
|
||||
|
||||
/*
|
||||
MOO_EXPORT int moo_genpfmethods (
|
||||
moo_t* moo,
|
||||
moo_mod_t* mod,
|
||||
@ -1566,8 +1575,9 @@ MOO_EXPORT int moo_genpfmethods (
|
||||
const moo_pfinfo_t* pfinfo,
|
||||
moo_oow_t pfcount
|
||||
);
|
||||
*/
|
||||
|
||||
MOO_EXPORT moo_pfimpl_t moo_findpfimpl (
|
||||
MOO_EXPORT moo_pfbase_t* moo_findpfbase (
|
||||
moo_t* moo,
|
||||
const moo_pfinfo_t* pfinfo,
|
||||
moo_oow_t pfcount,
|
||||
|
Reference in New Issue
Block a user