added moo_seterrwithsyserro()let the compier to remove the leading underscores when resolving a primitive function in a separate module

This commit is contained in:
hyunghwan.chung
2017-12-17 15:20:58 +00:00
parent cf88ac40ec
commit e63596688a
8 changed files with 65 additions and 65 deletions

View File

@ -6435,6 +6435,8 @@ static int __compile_method_definition (moo_t* moo)
if (moo->c->mth.primitive)
{
moo_oocs_t mthname;
/* the primitive method must be of this form
* method(#primitive) method_name.
*/
@ -6445,6 +6447,26 @@ static int __compile_method_definition (moo_t* moo)
return -1;
}
/*
* remove all leading underscores from the method name when building a primitive
* identifer. multiple methods can map to the same primitive handler.
* for class X, you may have method(#primitive) aa and method(#primitive) _aa
* to map to the X_aa primitive handler.
*/
mthname = moo->c->mth.name;
while (mthname.len > 0)
{
if (*mthname.ptr != '_') break;
mthname.ptr++;
mthname.len--;
}
if (mthname.len == 0)
{
MOO_DEBUG2 (moo, "Invalid primitive function name - %.*js\n", moo->c->mth.name.len, moo->c->mth.name.ptr);
set_syntax_error (moo, MOO_SYNERR_PFIDINVAL, &moo->c->mth.name_loc, &moo->c->mth.name);
return -1;
}
if (moo->c->cls.self_oop->modname == moo->_nil)
{
/* no module name specified in the class definition using 'from'.
@ -6453,31 +6475,8 @@ static int __compile_method_definition (moo_t* moo)
moo_oow_t savedlen;
moo_ooi_t pfnum;
moo_pfbase_t* pfbase;
moo_oocs_t mthname;
/* primitive identifer = classname_methodname */
/*
* remove all leading underscores from the method name when building a primitive
* identifer. multiple methods can map to the same primitive handler.
* for class X, you may have method(#primitive) aa and method(#primitive) _aa
* to map to the X_aa primitive handler.
*/
mthname = moo->c->mth.name;
while (mthname.len > 0)
{
if (*mthname.ptr != '_') break;
mthname.ptr++;
mthname.len--;
}
if (mthname.len == 0)
{
MOO_DEBUG2 (moo, "Invalid primitive function name - %.*js\n", moo->c->mth.name.len, moo->c->mth.name.ptr);
set_syntax_error (moo, MOO_SYNERR_PFIDINVAL, &moo->c->mth.name_loc, &moo->c->mth.name);
return -1;
}
/* compose the identifer into the back of the cls.modname buffer.
* i'll revert it when done. */
@ -6532,7 +6531,7 @@ static int __compile_method_definition (moo_t* moo)
tmp.len = MOO_OBJ_GET_SIZE(moo->c->cls.self_oop->modname);
if (copy_string_to (moo, &tmp, &moo->c->cls.modname, &moo->c->cls.modname_capa, 1, '\0') <= -1 ||
copy_string_to (moo, &moo->c->mth.name, &moo->c->cls.modname, &moo->c->cls.modname_capa, 1, '.') <= -1 ||
copy_string_to (moo, &mthname, &moo->c->cls.modname, &moo->c->cls.modname_capa, 1, '.') <= -1 ||
add_symbol_literal(moo, &moo->c->cls.modname, savedlen, &litidx) <= -1)
{
moo->c->cls.modname.len = savedlen;

View File

@ -290,6 +290,28 @@ moo_errnum_t moo_syserr_to_errnum (int e)
#endif
}
/* --------------------------------------------------------------------------
* ERROR NUMBER/MESSAGE HANDLING
* -------------------------------------------------------------------------- */
const moo_ooch_t* moo_geterrstr (moo_t* moo)
{
return moo_errnum_to_errstr (moo->errnum);
}
const moo_ooch_t* moo_geterrmsg (moo_t* moo)
{
if (moo->errmsg.len <= 0) return moo_errnum_to_errstr (moo->errnum);
return moo->errmsg.buf;
}
void moo_seterrwithsyserr (moo_t* moo, int syserr)
{
moo_bch_t msgbuf[64];
strerror_r (errno, msgbuf, MOO_COUNTOF(msgbuf));
moo_seterrbfmt (moo, moo_syserr_to_errnum(errno), "%s", msgbuf);
}
/* --------------------------------------------------------------------------
* ASSERTION FAILURE HANDLER
* -------------------------------------------------------------------------- */

View File

@ -1745,8 +1745,6 @@ static moo_pfrc_t pf_hash (moo_t* moo, moo_ooi_t nargs)
}
static moo_pfrc_t pf_perform (moo_t* moo, moo_ooi_t nargs)
{
moo_oop_t /*rcv,*/ selector;

View File

@ -2348,7 +2348,7 @@ int main (int argc, char* argv[])
if (synerr.tgt.len > 0)
{
moo_logbfmt (moo, MOO_LOG_ERROR | MOO_LOG_STDERR, " in place of %.*js", synerr.tgt.len, synerr.tgt.ptr);
moo_logbfmt (moo, MOO_LOG_ERROR | MOO_LOG_STDERR, " - %.*js", synerr.tgt.len, synerr.tgt.ptr);
}
if (moo_geterrmsg(moo) != moo_geterrstr(moo))

View File

@ -230,17 +230,6 @@ void moo_fini (moo_t* moo)
}
}
const moo_ooch_t* moo_geterrstr (moo_t* moo)
{
return moo_errnum_to_errstr (moo->errnum);
}
const moo_ooch_t* moo_geterrmsg (moo_t* moo)
{
if (moo->errmsg.len <= 0) return moo_errnum_to_errstr (moo->errnum);
return moo->errmsg.buf;
}
int moo_setoption (moo_t* moo, moo_option_t id, const void* value)
{
switch (id)

View File

@ -1594,20 +1594,24 @@ MOO_EXPORT void moo_fini (
#endif
void moo_seterrbfmt (
MOO_EXPORT void moo_seterrbfmt (
moo_t* moo,
moo_errnum_t errnum,
const moo_bch_t* fmt,
...
);
void moo_seterrufmt (
MOO_EXPORT void moo_seterrufmt (
moo_t* moo,
moo_errnum_t errnum,
const moo_uch_t* fmt,
...
);
MOO_EXPORT void moo_seterrwithsyserr (
moo_t* moo,
int syserr
);
MOO_EXPORT const moo_ooch_t* moo_geterrmsg (
moo_t* moo