added moo_seterrbfmt() and moo_seterrufmt()

This commit is contained in:
hyunghwan.chung 2017-05-11 14:59:20 +00:00
parent ce69989a86
commit 9208d078b2
14 changed files with 315 additions and 187 deletions

View File

@ -377,6 +377,28 @@ thisContext isExceptionContext dump.
##============================================================================
class PrimitiveFailureException(Exception)
{
var errcode.
method(#class) withErrorCode: code
{
^(self new) errorCode: code; yourself.
}
method signal
{
self.errcode := thisProcess primError.
^super signal
}
method errorCode
{
^self.errcode
}
method errorCode: code
{
self.errcode := code
}
}
class NoSuchMessageException(Exception)
@ -411,7 +433,7 @@ extend Apex
{
method(#dual,#liberal) primitiveFailed(method)
{
| a b msg |
| a b msg ec ex |
(*System logNl: 'Arguments: '.
a := 0.
@ -422,9 +444,10 @@ extend Apex
a := a + 1.
}.*)
msg := thisProcess primError asString.
if (method notNil) { msg := msg & ' - ' & (method owner name) & '<<' & (method name) }.
PrimitiveFailureException signal: msg.
ec := thisProcess primError.
msg := ec asString.
if (method notNil) { msg := msg & ' - ' & (method owner name) & '>>' & (method name) }.
(PrimitiveFailureException withErrorCode: ec) signal: msg.
}
method(#dual) doesNotUnderstand: message_name

View File

@ -278,7 +278,7 @@ static MOO_INLINE int bigint_to_oow (moo_t* moo, moo_oop_t num, moo_oow_t* w)
# error UNSUPPORTED LIW BIT SIZE
#endif
moo->errnum = MOO_ERANGE;
moo_seterrnum (moo, MOO_ERANGE);
return 0; /* not convertable */
}
@ -332,7 +332,7 @@ int moo_inttooow (moo_t* moo, moo_oop_t x, moo_oow_t* w)
if (is_bigint(moo, x)) return bigint_to_oow (moo, x, w);
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return 0; /* not convertable - too big, too small, or not an integer */
}
@ -347,7 +347,7 @@ int moo_inttoooi (moo_t* moo, moo_oop_t x, moo_ooi_t* i)
MOO_ASSERT (moo, MOO_TYPE_MAX(moo_ooi_t) + MOO_TYPE_MIN(moo_ooi_t) == -1); /* assume 2's complement */
if (w > (moo_oow_t)MOO_TYPE_MAX(moo_ooi_t) + 1)
{
moo->errnum = MOO_ERANGE; /* not convertable. number too small */
moo_seterrnum (moo, MOO_ERANGE); /* not convertable. number too small */
return 0;
}
*i = -w;
@ -356,7 +356,7 @@ int moo_inttoooi (moo_t* moo, moo_oop_t x, moo_ooi_t* i)
{
if (w > MOO_TYPE_MAX(moo_ooi_t))
{
moo->errnum = MOO_ERANGE; /* not convertable. number too big */
moo_seterrnum (moo, MOO_ERANGE); /* not convertable. number too big */
return 0;
}
*i = w;
@ -538,7 +538,7 @@ static MOO_INLINE moo_oop_t expand_bigint (moo_t* moo, moo_oop_t oop, moo_oow_t
if (inc > MOO_OBJ_SIZE_MAX - count)
{
moo->errnum = MOO_EOOMEM; /* TODO: is it a soft failure or a hard failure? is this error code proper? */
moo_seterrnum (moo, MOO_EOOMEM); /* TODO: is it a soft failure or a hard failure? is this error code proper? */
return MOO_NULL;
}
@ -1501,7 +1501,7 @@ static moo_oop_t add_unsigned_integers (moo_t* moo, moo_oop_t x, moo_oop_t y)
if (zs >= MOO_OBJ_SIZE_MAX)
{
moo->errnum = MOO_EOOMEM; /* TOOD: is it a soft failure or hard failure? */
moo_seterrnum (moo, MOO_EOOMEM); /* TOOD: is it a soft failure or hard failure? */
return MOO_NULL;
}
zs++;
@ -1550,7 +1550,7 @@ static moo_oop_t multiply_unsigned_integers (moo_t* moo, moo_oop_t x, moo_oop_t
if (ys > MOO_OBJ_SIZE_MAX - xs)
{
moo->errnum = MOO_EOOMEM; /* TOOD: is it a soft failure or hard failure? */
moo_seterrnum (moo, MOO_EOOMEM); /* TOOD: is it a soft failure or hard failure? */
return MOO_NULL;
}
@ -1710,7 +1710,7 @@ moo_oop_t moo_addints (moo_t* moo, moo_oop_t x, moo_oop_t y)
return normalize_bigint (moo, z);
oops_einval:
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_NULL;
}
@ -1801,7 +1801,7 @@ moo_oop_t moo_subints (moo_t* moo, moo_oop_t x, moo_oop_t y)
return normalize_bigint (moo, z);
oops_einval:
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_NULL;
}
@ -1905,7 +1905,7 @@ moo_oop_t moo_mulints (moo_t* moo, moo_oop_t x, moo_oop_t y)
return normalize_bigint (moo, z);
oops_einval:
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_NULL;
}
@ -1923,7 +1923,7 @@ moo_oop_t moo_divints (moo_t* moo, moo_oop_t x, moo_oop_t y, int modulo, moo_oop
if (yv == 0)
{
moo->errnum = MOO_EDIVBY0;
moo_seterrnum (moo, MOO_EDIVBY0);
return MOO_NULL;
}
@ -2044,7 +2044,7 @@ moo_oop_t moo_divints (moo_t* moo, moo_oop_t x, moo_oop_t y, int modulo, moo_oop
switch (v)
{
case 0:
moo->errnum = MOO_EDIVBY0;
moo_seterrnum (moo, MOO_EDIVBY0);
return MOO_NULL;
case 1:
@ -2157,7 +2157,7 @@ moo_oop_t moo_divints (moo_t* moo, moo_oop_t x, moo_oop_t y, int modulo, moo_oop
return normalize_bigint (moo, z);
oops_einval:
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_NULL;
}
@ -2177,7 +2177,7 @@ moo_oop_t moo_negateint (moo_t* moo, moo_oop_t x)
}
oops_einval:
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_NULL;
}
@ -2342,7 +2342,7 @@ moo_oop_t moo_bitatint (moo_t* moo, moo_oop_t x, moo_oop_t y)
}
oops_einval:
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_NULL;
}
@ -2555,7 +2555,7 @@ moo_oop_t moo_bitandints (moo_t* moo, moo_oop_t x, moo_oop_t y)
}
oops_einval:
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_NULL;
}
@ -2654,7 +2654,7 @@ moo_oop_t moo_bitorints (moo_t* moo, moo_oop_t x, moo_oop_t y)
if (zalloc < zs)
{
/* overflow in zalloc calculation above */
moo->errnum = MOO_EOOMEM; /* TODO: is it a soft failure or hard failure? */
moo_seterrnum (moo, MOO_EOOMEM); /* TODO: is it a soft failure or hard failure? */
return MOO_NULL;
}
@ -2773,7 +2773,7 @@ moo_oop_t moo_bitorints (moo_t* moo, moo_oop_t x, moo_oop_t y)
}
oops_einval:
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_NULL;
}
@ -2872,7 +2872,7 @@ moo_oop_t moo_bitxorints (moo_t* moo, moo_oop_t x, moo_oop_t y)
if (zalloc < zs)
{
/* overflow in zalloc calculation above */
moo->errnum = MOO_EOOMEM; /* TODO: is it a soft failure or hard failure? */
moo_seterrnum (moo, MOO_EOOMEM); /* TODO: is it a soft failure or hard failure? */
return MOO_NULL;
}
@ -2990,7 +2990,7 @@ moo_oop_t moo_bitxorints (moo_t* moo, moo_oop_t x, moo_oop_t y)
}
oops_einval:
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_NULL;
}
@ -3031,7 +3031,7 @@ moo_oop_t moo_bitinvint (moo_t* moo, moo_oop_t x)
if (zalloc < zs)
{
/* overflow in zalloc calculation above */
moo->errnum = MOO_EOOMEM; /* TODO: is it a soft failure or hard failure? */
moo_seterrnum (moo, MOO_EOOMEM); /* TODO: is it a soft failure or hard failure? */
return MOO_NULL;
}
@ -3092,7 +3092,7 @@ moo_oop_t moo_bitinvint (moo_t* moo, moo_oop_t x)
}
oops_einval:
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_NULL;
}
@ -3234,7 +3234,7 @@ static MOO_INLINE moo_oop_t rshift_negative_bigint_and_normalize (moo_t* moo, mo
/* this part must not be reached */
MOO_ASSERT (moo, !"internal error - must not happen");
moo->errnum = MOO_EINTERN;
moo_seterrnum (moo, MOO_EINTERN);
return MOO_NULL;
}
@ -3344,7 +3344,7 @@ static MOO_INLINE moo_oop_t lshift_bigint_and_normalize (moo_t* moo, moo_oop_t x
/* this part must not be reached */
MOO_ASSERT (moo, !"internal error - must not happen");
moo->errnum = MOO_EINTERN;
moo_seterrnum (moo, MOO_EINTERN);
return MOO_NULL;
}
@ -3518,7 +3518,7 @@ moo_oop_t moo_bitshiftint (moo_t* moo, moo_oop_t x, moo_oop_t y)
* simply return a failure here becuase it's surely too
* large after shifting */
MOO_ASSERT (moo, MOO_TYPE_MAX(moo_oow_t) >= MOO_OBJ_SIZE_BITS_MAX);
moo->errnum = MOO_EOOMEM; /* is it a soft failure or a hard failure? is this error code proper? */
moo_seterrnum (moo, MOO_EOOMEM); /* is it a soft failure or a hard failure? is this error code proper? */
return MOO_NULL;
#else
return lshift_bigint_and_normalize (moo, x, y);
@ -3564,7 +3564,7 @@ moo_oop_t moo_bitshiftint (moo_t* moo, moo_oop_t x, moo_oop_t y)
}
oops_einval:
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_NULL;
}
@ -3806,7 +3806,7 @@ moo_oop_t moo_strtoint (moo_t* moo, const moo_ooch_t* str, moo_oow_t len, int ra
oops_einval:
if (hwp && hw != hwp) moo_freemem (moo, hwp);
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_NULL;
}
@ -3857,7 +3857,7 @@ moo_oop_t moo_eqints (moo_t* moo, moo_oop_t x, moo_oop_t y)
}
oops_einval:
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_NULL;
}
@ -3878,7 +3878,7 @@ moo_oop_t moo_neints (moo_t* moo, moo_oop_t x, moo_oop_t y)
}
oops_einval:
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_NULL;
}
@ -3905,7 +3905,7 @@ moo_oop_t moo_gtints (moo_t* moo, moo_oop_t x, moo_oop_t y)
}
oops_einval:
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_NULL;
}
@ -3932,7 +3932,7 @@ moo_oop_t moo_geints (moo_t* moo, moo_oop_t x, moo_oop_t y)
}
oops_einval:
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_NULL;
}
@ -3959,7 +3959,7 @@ moo_oop_t moo_ltints (moo_t* moo, moo_oop_t x, moo_oop_t y)
}
oops_einval:
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_NULL;
}
@ -3986,7 +3986,7 @@ moo_oop_t moo_leints (moo_t* moo, moo_oop_t x, moo_oop_t y)
}
oops_einval:
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_NULL;
}
@ -4171,6 +4171,6 @@ moo_oop_t moo_inttostr (moo_t* moo, moo_oop_t num, int radix)
return s;
oops_einval:
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_NULL;
}

View File

@ -377,7 +377,7 @@ static int end_include (moo_t* moo);
static void set_syntax_error (moo_t* moo, moo_synerrnum_t num, const moo_ioloc_t* loc, const moo_oocs_t* tgt)
{
moo->errnum = MOO_ESYNTAX;
moo_seterrnum (moo, MOO_ESYNTAX);
moo->c->synerr.num = num;
/* The SCO compiler complains of this ternary operation saying:
@ -533,7 +533,7 @@ static int string_to_smooi (moo_t* moo, moo_oocs_t* str, int radixed, moo_ooi_t*
if (value < old_value)
{
/* overflow must have occurred */
moo->errnum = MOO_ERANGE;
moo_seterrnum (moo, MOO_ERANGE);
return -1;
}
old_value = value;
@ -543,14 +543,14 @@ static int string_to_smooi (moo_t* moo, moo_oocs_t* str, int radixed, moo_ooi_t*
if (ptr < end)
{
/* trailing garbage? */
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return -1;
}
MOO_ASSERT (moo, -MOO_SMOOI_MAX == MOO_SMOOI_MIN);
if (value > MOO_SMOOI_MAX)
{
moo->errnum = MOO_ERANGE;
moo_seterrnum (moo, MOO_ERANGE);
return -1;
}
@ -2002,7 +2002,7 @@ static MOO_INLINE int emit_byte_instruction (moo_t* moo, moo_oob_t code)
* at the max when incremented */
if (moo->c->mth.code.len == MOO_SMOOI_MAX - 1)
{
moo->errnum = MOO_EBCFULL; /* byte code too big */
moo_seterrnum (moo, MOO_EBCFULL); /* byte code too big */
return -1;
}
@ -2118,7 +2118,7 @@ static int emit_single_param_instruction (moo_t* moo, int cmd, moo_oow_t param_1
}
MOO_DEBUG1 (moo, "Invalid single param instruction opcode %d\n", (int)cmd);
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return -1;
write_short:
@ -2128,7 +2128,7 @@ write_short:
write_long:
if (param_1 > MAX_CODE_PARAM)
{
moo->errnum = MOO_ERANGE;
moo_seterrnum (moo, MOO_ERANGE);
return -1;
}
#if (MOO_BCODE_LONG_PARAM_SIZE == 2)
@ -2175,7 +2175,7 @@ static int emit_double_param_instruction (moo_t* moo, int cmd, moo_oow_t param_1
}
MOO_DEBUG1 (moo, "Invalid double param instruction opcode %d\n", (int)cmd);
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return -1;
write_short:
@ -2186,7 +2186,7 @@ write_short:
write_long:
if (param_1 > MAX_CODE_PARAM || param_2 > MAX_CODE_PARAM)
{
moo->errnum = MOO_ERANGE;
moo_seterrnum (moo, MOO_ERANGE);
return -1;
}
#if (MOO_BCODE_LONG_PARAM_SIZE == 2)
@ -2725,7 +2725,7 @@ static moo_ooi_t find_class_level_variable (moo_t* moo, moo_oop_class_t self, co
super = ((moo_oop_class_t)super)->superclass;
}
moo->errnum = MOO_ENOENT;
moo_seterrnum (moo, MOO_ENOENT);
return -1;
done:
@ -3912,7 +3912,7 @@ static int get_variable_info (moo_t* moo, const moo_oocs_t* name, const moo_iolo
default:
/* internal error - it must not happen */
moo->errnum = MOO_EINTERN;
moo_seterrnum (moo, MOO_EINTERN);
return -1;
}
}
@ -4637,7 +4637,7 @@ static int compile_expression_primary (moo_t* moo, const moo_oocs_t* ident, cons
break;
default:
moo->errnum = MOO_EINTERN;
moo_seterrnum (moo, MOO_EINTERN);
return -1;
}
@ -5648,7 +5648,7 @@ static int compile_method_expression (moo_t* moo, int pop)
break;
default:
moo->errnum = MOO_EINTERN;
moo_seterrnum (moo, MOO_EINTERN);
goto oops;
}
}
@ -7539,7 +7539,7 @@ int moo_compile (moo_t* moo, moo_ioimpl_t io)
if (!io)
{
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return -1;
}

View File

@ -561,7 +561,7 @@ int moo_decode (moo_t* moo, moo_oop_method_t mth, const moo_oocs_t* classfqn)
default:
LOG_INST_1 (moo, "UNKNOWN BYTE CODE ENCOUNTERED %x", (int)bcode);
moo->errnum = MOO_EINTERN;
moo_seterrnum (moo, MOO_EINTERN);
break;
}

View File

@ -54,7 +54,7 @@ static moo_oop_oop_t expand_bucket (moo_t* moo, moo_oop_oop_t oldbuc)
if (inc_max > 0) inc = inc_max;
else
{
moo->errnum = MOO_EOOMEM;
moo_seterrnum (moo, MOO_EOOMEM);
return MOO_NULL;
}
}
@ -127,7 +127,7 @@ static moo_oop_association_t find_or_upsert (moo_t* moo, moo_oop_set_t dic, moo_
{
/* when value is MOO_NULL, perform no insertion.
* the value of MOO_NULL indicates no insertion or update. */
moo->errnum = MOO_ENOENT;
moo_seterrnum (moo, MOO_ENOENT);
return MOO_NULL;
}
@ -138,7 +138,7 @@ static moo_oop_association_t find_or_upsert (moo_t* moo, moo_oop_set_t dic, moo_
{
/* this built-in dictionary is not allowed to hold more than
* MOO_SMOOI_MAX items for efficiency sake */
moo->errnum = MOO_EDFULL;
moo_seterrnum (moo, MOO_EDFULL);
return MOO_NULL;
}
@ -227,7 +227,7 @@ static moo_oop_association_t lookup (moo_t* moo, moo_oop_set_t dic, const moo_oo
}
/* when value is MOO_NULL, perform no insertion */
moo->errnum = MOO_ENOENT;
moo_seterrnum (moo, MOO_ENOENT);
return MOO_NULL;
}
@ -300,7 +300,7 @@ int moo_deletedic (moo_t* moo, moo_oop_set_t dic, const moo_oocs_t* name)
index = (index + 1) % bs;
}
moo->errnum = MOO_ENOENT;
moo_seterrnum (moo, MOO_ENOENT);
return -1;
found:

View File

@ -109,7 +109,7 @@
static void signal_io_semaphore (moo_t* moo, moo_ooi_t mask, void* ctx);
static int send_message (moo_t* moo, moo_oop_char_t selector, int to_super, moo_ooi_t nargs);
static int send_private_message (moo_t* moo, const moo_ooch_t* nameptr, moo_oow_t namelen, int to_super, moo_ooi_t nargs);
static int send_message_with_str (moo_t* moo, const moo_ooch_t* nameptr, moo_oow_t namelen, int to_super, moo_ooi_t nargs);
/* ------------------------------------------------------------------------- */
static MOO_INLINE int vm_startup (moo_t* moo)
@ -254,7 +254,7 @@ static MOO_INLINE int chain_into_processor (moo_t* moo, moo_oop_process_t proc)
#if defined(MOO_DEBUG_VM_PROCESSOR)
MOO_LOG0 (moo, MOO_LOG_IC | MOO_LOG_FATAL, "Processor - too many process\n");
#endif
moo->errnum = MOO_EPFULL;
moo_seterrnum (moo, MOO_EPFULL);
return -1;
}
@ -512,7 +512,7 @@ static int async_signal_semaphore (moo_t* moo, moo_oop_semaphore_t sem)
{
if (moo->sem_list_count >= SEM_LIST_MAX)
{
moo->errnum = MOO_ESLFULL;
moo_seterrnum (moo, MOO_ESLFULL);
return -1;
}
@ -676,7 +676,7 @@ static int add_to_sem_heap (moo_t* moo, moo_oop_semaphore_t sem)
if (moo->sem_heap_count >= SEM_HEAP_MAX)
{
moo->errnum = MOO_ESHFULL;
moo_seterrnum (moo, MOO_ESHFULL);
return -1;
}
@ -754,7 +754,7 @@ static int add_to_sem_io (moo_t* moo, moo_oop_semaphore_t sem)
if (moo->sem_io_count >= SEM_IO_MAX)
{
moo->errnum = MOO_ESHFULL;
moo_seterrnum (moo, MOO_ESHFULL);
return -1;
}
@ -1115,7 +1115,7 @@ not_found:
}
MOO_DEBUG3 (moo, "Method [%.*js] not found for %O\n", message->len, message->ptr, receiver);
moo->errnum = MOO_ENOENT;
moo_seterrnum (moo, MOO_ENOENT);
return MOO_NULL;
}
@ -1149,7 +1149,7 @@ static int start_initial_process_and_context (moo_t* moo, const moo_oocs_t* objn
* i can't use it as a start-up method.
TODO: overcome this problem
*/
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return -1;
}
@ -1416,7 +1416,7 @@ static moo_pfrc_t _equal_objects (moo_t* moo, moo_ooi_t nargs)
/* MOO_OBJ_TYPE_OOP, ... */
MOO_DEBUG1 (moo, "<_equal_objects> Cannot compare objects of type %d\n", (int)MOO_OBJ_GET_FLAGS_TYPE(rcv));
moo->errnum = MOO_ENOIMPL; /* TODO: better error code */
moo_seterrnum (moo, MOO_ENOIMPL); /* TODO: better error code */
return -1;
}
}
@ -1464,7 +1464,7 @@ static MOO_INLINE moo_pfrc_t pf_basic_new (moo_t* moo, moo_ooi_t nargs)
{
/* the receiver is not a class object */
MOO_DEBUG1 (moo, "<pf_basic_new> Receiver is not a class - %O\n", _class);
moo->errnum = MOO_EMSGRCV;
moo_seterrnum (moo, MOO_EMSGRCV);
return MOO_PF_FAILURE;
}
@ -1472,7 +1472,7 @@ static MOO_INLINE moo_pfrc_t pf_basic_new (moo_t* moo, moo_ooi_t nargs)
if (MOO_CLASS_SELFSPEC_FLAGS(MOO_OOP_TO_SMOOI(_class->selfspec)) & MOO_CLASS_SELFSPEC_FLAG_LIMITED)
{
MOO_DEBUG1 (moo, "<pf_basic_new> Receiver is #limited - %O\n", _class);
moo->errnum = MOO_EPERM;
moo_seterrnum (moo, MOO_EPERM);
return MOO_PF_FAILURE;
}
@ -1483,7 +1483,7 @@ static MOO_INLINE moo_pfrc_t pf_basic_new (moo_t* moo, moo_ooi_t nargs)
{
/* integer out of range or not integer */
MOO_DEBUG0 (moo, "<pf_basic_new> Size out of range or not integer\n");
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_PF_FAILURE;
}
}
@ -1555,7 +1555,7 @@ static moo_pfrc_t pf_basic_at (moo_t* moo, moo_ooi_t nargs)
if (!MOO_OOP_IS_POINTER(rcv))
{
/* the receiver is a special numeric object, not a normal pointer */
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_PF_FAILURE;
}
@ -1563,13 +1563,13 @@ static moo_pfrc_t pf_basic_at (moo_t* moo, moo_ooi_t nargs)
if (moo_inttooow (moo, pos, &idx) <= 0)
{
/* negative integer or not integer */
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_PF_FAILURE;
}
if (idx >= MOO_OBJ_GET_SIZE(rcv))
{
/* index out of range */
moo->errnum = MOO_ERANGE;
moo_seterrnum (moo, MOO_ERANGE);
return MOO_PF_FAILURE;
}
@ -1598,7 +1598,7 @@ static moo_pfrc_t pf_basic_at (moo_t* moo, moo_ooi_t nargs)
break;
default:
moo->errnum = MOO_EINTERN;
moo_seterrnum (moo, MOO_EINTERN);
return MOO_PF_HARD_FAILURE;
}
@ -1617,14 +1617,14 @@ static moo_pfrc_t pf_basic_at_put (moo_t* moo, moo_ooi_t nargs)
if (!MOO_OOP_IS_POINTER(rcv))
{
/* the receiver is a special numeric object, not a normal pointer */
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_PF_FAILURE;
}
if (MOO_OBJ_GET_FLAGS_RDONLY(rcv))
{
/* TODO: better error handling */
moo->errnum = MOO_EPERM;
moo_seterrnum (moo, MOO_EPERM);
return MOO_PF_FAILURE;
}
@ -1634,13 +1634,13 @@ static moo_pfrc_t pf_basic_at_put (moo_t* moo, moo_ooi_t nargs)
if (moo_inttooow (moo, pos, &idx) <= 0)
{
/* negative integer or not integer */
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_PF_FAILURE;
}
if (idx >= MOO_OBJ_GET_SIZE(rcv))
{
/* index out of range */
moo->errnum = MOO_ERANGE;
moo_seterrnum (moo, MOO_ERANGE);
return MOO_PF_FAILURE;
}
@ -1650,7 +1650,7 @@ static moo_pfrc_t pf_basic_at_put (moo_t* moo, moo_ooi_t nargs)
if (!MOO_OOP_IS_SMOOI(val))
{
/* the value is not a character */
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_PF_FAILURE;
}
/* TOOD: must I check the range of the value? */
@ -1661,7 +1661,7 @@ static moo_pfrc_t pf_basic_at_put (moo_t* moo, moo_ooi_t nargs)
if (!MOO_OOP_IS_CHAR(val))
{
/* the value is not a character */
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_PF_FAILURE;
}
((moo_oop_char_t)rcv)->slot[idx] = MOO_OOP_TO_CHAR(val);
@ -1671,7 +1671,7 @@ static moo_pfrc_t pf_basic_at_put (moo_t* moo, moo_ooi_t nargs)
if (!MOO_OOP_IS_SMOOI(val))
{
/* the value is not a number */
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_PF_FAILURE;
}
@ -1686,7 +1686,7 @@ static moo_pfrc_t pf_basic_at_put (moo_t* moo, moo_ooi_t nargs)
if (moo_inttooow (moo, val, &w) <= 0)
{
/* the value is not a number, out of range, or negative */
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_PF_FAILURE;
}
((moo_oop_word_t)rcv)->slot[idx] = w;
@ -1698,7 +1698,7 @@ static moo_pfrc_t pf_basic_at_put (moo_t* moo, moo_ooi_t nargs)
break;
default:
moo->errnum = MOO_EINTERN;
moo_seterrnum (moo, MOO_EINTERN);
return MOO_PF_HARD_FAILURE;
}
@ -1760,7 +1760,7 @@ static moo_pfrc_t pf_hash (moo_t* moo, moo_ooi_t nargs)
default:
/* MOO_OBJ_TYPE_OOP, ... */
MOO_DEBUG1 (moo, "<pf_hash> Cannot hash an object of type %d\n", type);
moo->errnum = MOO_ENOIMPL; /* TODO: better error code? */
moo_seterrnum (moo, MOO_ENOIMPL); /* TODO: better error code? */
return MOO_PF_FAILURE;
}
break;
@ -1785,7 +1785,7 @@ static moo_pfrc_t pf_responds_to (moo_t* moo, moo_ooi_t nargs)
if (MOO_CLASSOF(moo,selector) != moo->_symbol)
{
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_PF_FAILURE;
}
@ -1815,7 +1815,7 @@ static moo_pfrc_t pf_perform (moo_t* moo, moo_ooi_t nargs)
if (MOO_CLASSOF(moo,selector) != moo->_symbol)
{
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_PF_FAILURE;
}
@ -1847,7 +1847,7 @@ static moo_pfrc_t pf_exceptionize_error (moo_t* moo, moo_ooi_t nargs)
/* the receiver is a special numeric object, not a normal pointer.
* excceptionization is not supported for small integers, characters, and errors.
* first of all, methods of these classes must not return errors */
moo->errnum = MOO_EMSGRCV;
moo_seterrnum (moo, MOO_EMSGRCV);
return MOO_PF_FAILURE;
}
@ -1874,7 +1874,7 @@ static moo_pfrc_t pf_context_goto (moo_t* moo, moo_ooi_t nargs)
{
MOO_LOG2 (moo, MOO_LOG_PRIMITIVE | MOO_LOG_ERROR,
"Error(%hs) - invalid receiver, not a method context - %O\n", __PRIMITIVE_NAME__, rcv);
moo->errnum = MOO_EMSGRCV;
moo_seterrnum (moo, MOO_EMSGRCV);
return MOO_PF_FAILURE;
}
@ -1883,7 +1883,7 @@ static moo_pfrc_t pf_context_goto (moo_t* moo, moo_ooi_t nargs)
{
MOO_LOG1 (moo, MOO_LOG_PRIMITIVE | MOO_LOG_ERROR,
"Error(%hs) - invalid pc\n", __PRIMITIVE_NAME__);
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_PF_FAILURE;
}
@ -1930,7 +1930,7 @@ static moo_pfrc_t __block_value (moo_t* moo, moo_oop_context_t rcv_blkctx, moo_o
MOO_LOG2 (moo, MOO_LOG_PRIMITIVE | MOO_LOG_ERROR,
"Error(%hs) - re-valuing of a block context - %O\n", __PRIMITIVE_NAME__, rcv_blkctx);
moo->errnum = MOO_EPERM;
moo_seterrnum (moo, MOO_EPERM);
return MOO_PF_FAILURE;
}
MOO_ASSERT (moo, MOO_OBJ_GET_SIZE(rcv_blkctx) == MOO_CONTEXT_NAMED_INSTVARS);
@ -1941,7 +1941,7 @@ static moo_pfrc_t __block_value (moo_t* moo, moo_oop_context_t rcv_blkctx, moo_o
"Error(%hs) - wrong number of arguments to a block context %O - %zd expected, %zd given\n",
__PRIMITIVE_NAME__, rcv_blkctx, MOO_OOP_TO_SMOOI(rcv_blkctx->method_or_nargs), actual_arg_count);
moo->errnum = MOO_ENUMARGS;
moo_seterrnum (moo, MOO_ENUMARGS);
return MOO_PF_FAILURE;
}
@ -2020,7 +2020,7 @@ static moo_pfrc_t pf_block_value (moo_t* moo, moo_ooi_t nargs)
/* the receiver must be a block context */
MOO_LOG2 (moo, MOO_LOG_PRIMITIVE | MOO_LOG_ERROR,
"Error(%hs) - invalid receiver, not a block context - %O\n", __PRIMITIVE_NAME__, rcv_blkctx);
moo->errnum = MOO_EMSGRCV;
moo_seterrnum (moo, MOO_EMSGRCV);
return MOO_PF_FAILURE;
}
@ -2048,7 +2048,7 @@ static moo_pfrc_t pf_block_new_process (moo_t* moo, moo_ooi_t nargs)
{
/* too many arguments */
/* TODO: proper error handling */
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_PF_FAILURE;
}
@ -2061,7 +2061,7 @@ static moo_pfrc_t pf_block_new_process (moo_t* moo, moo_ooi_t nargs)
{
/* the only optional argument must be an OOP-indexable
* object like an array */
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_PF_FAILURE;
}
@ -2074,7 +2074,7 @@ static moo_pfrc_t pf_block_new_process (moo_t* moo, moo_ooi_t nargs)
/* the receiver must be a block context */
MOO_LOG2 (moo, MOO_LOG_PRIMITIVE | MOO_LOG_ERROR,
"Error(%hs) - invalid receiver, not a block context - %O\n", __PRIMITIVE_NAME__, rcv_blkctx);
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_PF_FAILURE;
}
@ -2785,7 +2785,7 @@ static moo_pfrc_t pf_character_as_smooi (moo_t* moo, moo_ooi_t nargs)
rcv = MOO_STACK_GETRCV(moo, nargs);
if (!MOO_OOP_IS_CHAR(rcv))
{
moo->errnum = MOO_EMSGRCV;
moo_seterrnum (moo, MOO_EMSGRCV);
return MOO_PF_HARD_FAILURE;
}
@ -2804,7 +2804,7 @@ static moo_pfrc_t pf_smooi_as_character (moo_t* moo, moo_ooi_t nargs)
rcv = MOO_STACK_GETRCV(moo, nargs);
if (!MOO_OOP_IS_SMOOI(rcv))
{
moo->errnum = MOO_EMSGRCV;
moo_seterrnum (moo, MOO_EMSGRCV);
return MOO_PF_HARD_FAILURE;
}
@ -2824,7 +2824,7 @@ static moo_pfrc_t pf_smooi_as_error (moo_t* moo, moo_ooi_t nargs)
rcv = MOO_STACK_GETRCV(moo, nargs);
if (!MOO_OOP_IS_SMOOI(rcv))
{
moo->errnum = MOO_EMSGRCV;
moo_seterrnum (moo, MOO_EMSGRCV);
return MOO_PF_HARD_FAILURE;
}
@ -2846,7 +2846,7 @@ static moo_pfrc_t pf_error_as_character (moo_t* moo, moo_ooi_t nargs)
rcv = MOO_STACK_GETRCV(moo, nargs);
if (!MOO_OOP_IS_ERROR(rcv))
{
moo->errnum = MOO_EMSGRCV;
moo_seterrnum (moo, MOO_EMSGRCV);
return MOO_PF_HARD_FAILURE;
}
@ -2866,7 +2866,7 @@ static moo_pfrc_t pf_error_as_integer (moo_t* moo, moo_ooi_t nargs)
rcv = MOO_STACK_GETRCV(moo, nargs);
if (!MOO_OOP_IS_ERROR(rcv))
{
moo->errnum = MOO_EMSGRCV;
moo_seterrnum (moo, MOO_EMSGRCV);
return MOO_PF_HARD_FAILURE;
}
@ -2887,7 +2887,7 @@ static moo_pfrc_t pf_error_as_string (moo_t* moo, moo_ooi_t nargs)
rcv = MOO_STACK_GETRCV(moo, nargs);
if (!MOO_OOP_IS_ERROR(rcv))
{
moo->errnum = MOO_EMSGRCV;
moo_seterrnum (moo, MOO_EMSGRCV);
return MOO_PF_HARD_FAILURE;
}
@ -2977,7 +2977,7 @@ static moo_pfrc_t pf_smptr_free (moo_t* moo, moo_ooi_t nargs)
tmp = MOO_STACK_GETRCV(moo, nargs);
if (!MOO_OOP_IS_SMPTR(tmp))
{
moo->errnum = MOO_EMSGRCV;
moo_seterrnum (moo, MOO_EMSGRCV);
return MOO_PF_HARD_FAILURE;
}
@ -3039,7 +3039,7 @@ static MOO_INLINE moo_oop_t _fetch_raw_int (moo_t* moo, moo_int8_t* rawptr, moo_
#endif
default:
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_NULL;
}
@ -3078,7 +3078,7 @@ static MOO_INLINE moo_oop_t _fetch_raw_uint (moo_t* moo, moo_uint8_t* rawptr, mo
#endif
default:
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_NULL;
}
@ -3097,7 +3097,7 @@ static MOO_INLINE int _store_raw_int (moo_t* moo, moo_uint8_t* rawptr, moo_oow_t
if (w > max || w < min)
{
moo->errnum = MOO_ERANGE;
moo_seterrnum (moo, MOO_ERANGE);
return -1;
}
@ -3128,7 +3128,7 @@ static MOO_INLINE int _store_raw_int (moo_t* moo, moo_uint8_t* rawptr, moo_oow_t
#endif
}
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return -1;
}
@ -3140,14 +3140,14 @@ static MOO_INLINE int _store_raw_uint (moo_t* moo, moo_uint8_t* rawptr, moo_oow_
if ((n = moo_inttooow (moo, voop, &w)) <= 0)
{
if (n <= -1) moo->errnum = MOO_ERANGE; /* negative number */
if (n <= -1) moo_seterrnum (moo, MOO_ERANGE); /* negative number */
return -1;
}
max = (~(moo_oow_t)0 >> ((MOO_SIZEOF_OOW_T - size) * 8));
if (w > max)
{
moo->errnum = MOO_ERANGE;
moo_seterrnum (moo, MOO_ERANGE);
return -1;
}
@ -3178,7 +3178,7 @@ static MOO_INLINE int _store_raw_uint (moo_t* moo, moo_uint8_t* rawptr, moo_oow_
#endif
}
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return -1;
}
@ -3392,7 +3392,7 @@ static moo_pfrc_t _get_smptr_int (moo_t* moo, moo_ooi_t nargs, int size)
rcv = MOO_STACK_GETRCV(moo, nargs);
if (!MOO_OOP_IS_SMPTR(rcv))
{
moo->errnum = MOO_EMSGRCV;
moo_seterrnum (moo, MOO_EMSGRCV);
return MOO_PF_HARD_FAILURE;
}
@ -3427,7 +3427,7 @@ static moo_pfrc_t _get_smptr_uint (moo_t* moo, moo_ooi_t nargs, int size)
rcv = MOO_STACK_GETRCV(moo, nargs);
if (!MOO_OOP_IS_SMPTR(rcv))
{
moo->errnum = MOO_EMSGRCV;
moo_seterrnum (moo, MOO_EMSGRCV);
return MOO_PF_HARD_FAILURE;
}
@ -3637,7 +3637,7 @@ static moo_pfrc_t pf_smptr_as_string (moo_t* moo, moo_ooi_t nargs)
rcv = MOO_STACK_GETRCV(moo, nargs);
if (!MOO_OOP_IS_SMPTR(rcv))
{
moo->errnum = MOO_EMSGRCV;
moo_seterrnum (moo, MOO_EMSGRCV);
return MOO_PF_HARD_FAILURE;
}
@ -3804,7 +3804,7 @@ moo_pfbase_t* moo_getpfnum (moo_t* moo, const moo_ooch_t* ptr, moo_oow_t len, mo
}
}
moo->errnum = MOO_ENOENT;
moo_seterrnum (moo, MOO_ENOENT);
return MOO_NULL;
}
@ -3838,7 +3838,7 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs)
MOO_LOG3 (moo, MOO_LOG_IC | MOO_LOG_FATAL,
"Fatal error - Argument count mismatch for a non-variadic method [%O] - %zd expected, %zu given\n",
method->name, MOO_OOP_TO_SMOOI(method->tmpr_nargs), nargs);
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return -1;
}
}
@ -3948,7 +3948,7 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs)
{
MOO_DEBUG4 (moo, "Soft failure due to argument count mismatch for primitive function %hs - %zu-%zu expected, %zu given\n",
pftab[pfnum].name, pftab[pfnum].pfbase.minargs, pftab[pfnum].pfbase.maxargs, nargs);
moo->errnum = MOO_ENUMARGS;
moo_seterrnum (moo, MOO_ENUMARGS);
goto activate_primitive_method_body;
}
@ -3966,7 +3966,7 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs)
}
else
{
moo->errnum = MOO_ENOENT;
moo_seterrnum (moo, MOO_ENOENT);
MOO_DEBUG1 (moo, "Cannot call primitive function numbered %zd - unknown primitive function number\n", pfnum);
}
@ -4015,7 +4015,7 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs)
MOO_DEBUG5 (moo, "Soft failure due to argument count mismatch for primitive function %.*js - %zu-%zu expected, %zu given\n",
MOO_OBJ_GET_SIZE(pfname), MOO_OBJ_GET_CHAR_SLOT(pfname), pfbase->minargs, pfbase->maxargs, nargs);
moo->errnum = MOO_ENUMARGS;
moo_seterrnum (moo, MOO_ENUMARGS);
goto activate_primitive_method_body;
}
@ -4066,21 +4066,7 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs)
#endif
{
/* no byte code to execute - make it a hard failure */
#if 0
/* TODO: what is the best tactics? emulate "self primitiveFailed"? or should this be generated by the compiler
* the compiler produces no code for the body of a method(#primitive). so it will reach here if it fails when executed. */
MOO_DEBUG2 (moo, "Empty primitive body - %.*js\n", MOO_OBJ_GET_SIZE(method->name), MOO_OBJ_GET_CHAR_SLOT(method->name));
moo->sp = stack_base; /* force restore stack pointer */
MOO_STACK_PUSH (moo, moo->_nil);
/* i assume that the failed primitive handler function set the error number.
* so i don't set it here */
return -1;
#else
/* emulate 'self primitiveFailed' */
static moo_ooch_t prim_fail_msg[] = {
'p', 'r', 'i', 'm', 'i', 't', 'i', 'v', 'e',
'F', 'a', 'i', 'l', 'e', 'd'
@ -4091,12 +4077,11 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs)
{
/* a primitive function handler must not touch the stack when it returns soft failure */
MOO_DEBUG3 (moo, "Stack seems to get corrupted by a primitive handler function - %O<<%.*js\n", method->owner, MOO_OBJ_GET_SIZE(method->name), MOO_OBJ_GET_CHAR_SLOT(method->name));
moo->errnum = MOO_EINTERN;
moo_seterrnum (moo, MOO_EINTERN);
return -1;
}
MOO_DEBUG3 (moo, "Sending primitiveFailed for empty primitive body - %O<<%.*js\n", method->owner, MOO_OBJ_GET_SIZE(method->name), MOO_OBJ_GET_CHAR_SLOT(method->name));
/*
* | arg1 | <---- stack_base + 3
* | arg0 | <---- stack_base + 2
@ -4111,9 +4096,8 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs)
MOO_STACK_SET (moo, stack_base + 2, (moo_oop_t)method);
/* send primitiveFailed to self */
if (send_private_message (moo, prim_fail_msg, 15, 0, nargs + 1) <= -1) return -1;
if (send_message_with_str (moo, prim_fail_msg, 15, 0, nargs + 1) <= -1) return -1;
break;
#endif
}
if (activate_new_method (moo, method, nargs) <= -1) return -1;
@ -4166,7 +4150,7 @@ static int send_message (moo_t* moo, moo_oop_char_t selector, int to_super, moo_
"Fatal error - receiver [%O] of class [%O] does not understand a message [%.*js]\n",
receiver, MOO_CLASSOF(moo, receiver), mthname.len, mthname.ptr);
moo->errnum = MOO_EMSGSND;
moo_seterrnum (moo, MOO_EMSGSND);
return -1;
}
else
@ -4184,7 +4168,7 @@ static int send_message (moo_t* moo, moo_oop_char_t selector, int to_super, moo_
return start_method (moo, method, nargs);
}
static int send_private_message (moo_t* moo, const moo_ooch_t* nameptr, moo_oow_t namelen, int to_super, moo_ooi_t nargs)
static int send_message_with_str (moo_t* moo, const moo_ooch_t* nameptr, moo_oow_t namelen, int to_super, moo_ooi_t nargs)
{
moo_oocs_t mthname;
moo_oop_t receiver;
@ -4200,7 +4184,7 @@ static int send_private_message (moo_t* moo, const moo_ooch_t* nameptr, moo_oow_
MOO_LOG4 (moo, MOO_LOG_IC | MOO_LOG_FATAL,
"Fatal error - receiver [%O] of class [%O] does not understand a private message [%.*js]\n",
receiver, MOO_CLASSOF(moo, receiver), mthname.len, mthname.ptr);
moo->errnum = MOO_EMSGSND;
moo_seterrnum (moo, MOO_EMSGSND);
return -1;
}
@ -5207,7 +5191,7 @@ int moo_execute (moo_t* moo)
MOO_ASSERT (moo, moo->active_context->origin->ip == MOO_SMOOI_TO_OOP(-1));
MOO_LOG0 (moo, MOO_LOG_IC | MOO_LOG_ERROR, "Error - cannot return from dead context\n");
moo->errnum = MOO_EINTERN; /* TODO: can i make this error catchable at the moo level? */
moo_seterrnum (moo, MOO_EINTERN); /* TODO: can i make this error catchable at the moo level? */
goto oops;
non_local_return_ok:
@ -5245,7 +5229,7 @@ int moo_execute (moo_t* moo)
MOO_STACK_PUSH (moo, (moo_oop_t)unwind_stop);
MOO_STACK_PUSH (moo, (moo_oop_t)return_value);
if (send_private_message (moo, fbm, 16, 0, 2) <= -1) goto oops;
if (send_message_with_str (moo, fbm, 16, 0, 2) <= -1) goto oops;
}
else
{
@ -5461,7 +5445,7 @@ int moo_execute (moo_t* moo)
default:
MOO_LOG1 (moo, MOO_LOG_IC | MOO_LOG_FATAL, "Fatal error - unknown byte code 0x%zx\n", bcode);
moo->errnum = MOO_EINTERN;
moo_seterrnum (moo, MOO_EINTERN);
goto oops;
}
}

View File

@ -33,7 +33,7 @@ moo_heap_t* moo_makeheap (moo_t* moo, moo_oow_t size)
heap = (moo_heap_t*)MOO_MMGR_ALLOC(moo->mmgr, MOO_SIZEOF(*heap) + size);
if (!heap)
{
moo->errnum = MOO_ESYSMEM;
moo_seterrnum (moo, MOO_ESYSMEM);
return MOO_NULL;
}
@ -70,7 +70,7 @@ void* moo_allocheapmem (moo_t* moo, moo_heap_t* heap, moo_oow_t size)
{
MOO_DEBUG5 (moo, "Cannot allocate %zd bytes from heap - ptr %p limit %p size %zd free %zd\n",
size, heap->ptr, heap->limit, (moo_oow_t)(heap->limit - heap->base), (moo_oow_t)(heap->limit - heap->ptr));
moo->errnum = MOO_EOOMEM;
moo_seterrnum (moo, MOO_EOOMEM);
return MOO_NULL;
}

View File

@ -187,6 +187,9 @@ static moo_bch_t* sprintn_upper (moo_bch_t* nbuf, moo_uintmax_t num, int base, m
/* ------------------------------------------------------------------------- */
static int put_ooch (moo_t* moo, moo_oow_t mask, moo_ooch_t ch, moo_oow_t len)
{
/* this is not equivalent to put_oocs(moo,mask,&ch, 1);
* this function is to emit a single character multiple times */
if (len <= 0) return 1;
if (moo->log.len > 0 && moo->log.last_mask != mask)
@ -212,7 +215,7 @@ redo:
if (len > MOO_TYPE_MAX(moo_oow_t) - moo->log.len)
{
/* data too big */
moo->errnum = MOO_ETOOBIG;
moo_seterrnum (moo, MOO_ETOOBIG);
return -1;
}
@ -264,6 +267,7 @@ static int put_oocs (moo_t* moo, moo_oow_t mask, const moo_ooch_t* ptr, moo_oow_
moo->log.len = 0;
}
redo:
if (len > moo->log.capa - moo->log.len)
{
moo_oow_t newcapa;
@ -272,14 +276,25 @@ static int put_oocs (moo_t* moo, moo_oow_t mask, const moo_ooch_t* ptr, moo_oow_
if (len > MOO_TYPE_MAX(moo_oow_t) - moo->log.len)
{
/* data too big */
moo->errnum = MOO_ETOOBIG;
moo_seterrnum (moo, MOO_ETOOBIG);
return -1;
}
newcapa = MOO_ALIGN(moo->log.len + len, 512); /* TODO: adjust this capacity */
/* +1 to handle line ending injection more easily */
tmp = moo_reallocmem (moo, moo->log.ptr, (newcapa + 1) * MOO_SIZEOF(*tmp));
if (!tmp) return -1;
if (!tmp)
{
if (moo->log.len > 0)
{
/* can't expand the buffer. just flush the existing contents */
moo->vmprim.log_write (moo, moo->log.last_mask, moo->log.ptr, moo->log.len);
moo->log.len = 0;
goto redo;
}
return -1;
}
moo->log.ptr = tmp;
moo->log.capa = newcapa;
@ -557,3 +572,77 @@ moo_ooi_t moo_logufmt (moo_t* moo, moo_oow_t mask, const moo_uch_t* fmt, ...)
return (x <= -1)? -1: fo.count;
}
/* --------------------------------------------------------------------------
* ERROR MESSAGE FORMATTING
* -------------------------------------------------------------------------- */
static int put_errch (moo_t* moo, moo_oow_t mask, moo_ooch_t ch, moo_oow_t len)
{
moo_oow_t max;
max = MOO_COUNTOF(moo->errmsg.buf) - moo->errmsg.len - 1;
if (len > max) len = max;
if (len <= 0) return 1;
while (len > 0)
{
moo->errmsg.buf[moo->errmsg.len++] = ch;
len--;
}
moo->errmsg.buf[moo->errmsg.len] = '\0';
return 1; /* success */
}
static int put_errcs (moo_t* moo, moo_oow_t mask, const moo_ooch_t* ptr, moo_oow_t len)
{
moo_oow_t max;
max = MOO_COUNTOF(moo->errmsg.buf) - moo->errmsg.len - 1;
if (len > max) len = max;
if (len <= 0) return 1;
MOO_MEMCPY (&moo->errmsg.buf[moo->errmsg.len], ptr, len * MOO_SIZEOF(*ptr));
moo->errmsg.len += len;
moo->errmsg.buf[moo->errmsg.len] = '\0';
return 1; /* success */
}
void moo_seterrbfmt (moo_t* moo, moo_errnum_t errnum, const moo_bch_t* fmt, ...)
{
va_list ap;
moo_fmtout_t fo;
moo->errnum = errnum;
moo->errmsg.len = 0;
fo.mask = 0; /* not used */
fo.putch = put_errch;
fo.putcs = put_errcs;
va_start (ap, fmt);
moo_logbfmtv (moo, fmt, &fo, ap);
va_end (ap);
}
void moo_seterrufmt (moo_t* moo, moo_errnum_t errnum, const moo_uch_t* fmt, ...)
{
va_list ap;
moo_fmtout_t fo;
moo->errnum = errnum;
moo->errmsg.len = 0;
fo.mask = 0; /* not used */
fo.putch = put_errch;
fo.putcs = put_errcs;
va_start (ap, fmt);
moo_logufmtv (moo, fmt, &fo, ap);
va_end (ap);
}

View File

@ -318,7 +318,7 @@ reswitch:
goto reswitch;
/* end of length modifiers */
case 'n':
case 'n': /* number of characters printed so far */
if (lm_flag & LF_J) /* j */
*(va_arg(ap, moo_intmax_t*)) = data->count;
else if (lm_flag & LF_Z) /* z */
@ -333,11 +333,8 @@ reswitch:
*(va_arg(ap, short int*)) = data->count;
else if (lm_flag & LF_C) /* hh */
*(va_arg(ap, char*)) = data->count;
else if (flagc & FLAGC_LENMOD)
{
moo->errnum = MOO_EINVAL;
goto oops;
}
else if (flagc & FLAGC_LENMOD)
goto invalid_format;
else
*(va_arg(ap, int*)) = data->count;
break;
@ -623,8 +620,7 @@ reswitch:
#endif
else if (flagc & FLAGC_LENMOD)
{
moo->errnum = MOO_EINVAL;
goto oops;
goto invalid_format;
}
else
{

View File

@ -402,7 +402,7 @@ static moo_ooi_t input_handler (moo_t* moo, moo_iocmd_t cmd, moo_ioarg_t* arg)
return read_input (moo, arg);
default:
moo->errnum = MOO_EINTERN;
moo_seterrnum (moo, MOO_EINTERN);
return -1;
}
}

View File

@ -210,6 +210,12 @@ const moo_ooch_t* moo_geterrstr (moo_t* moo)
return moo_errnumtoerrstr (moo->errnum);
}
const moo_ooch_t* moo_geterrmsg (moo_t* moo)
{
if (moo->errmsg.len <= 0) return moo_errnumtoerrstr (moo->errnum);
return moo->errmsg.buf;
}
int moo_setoption (moo_t* moo, moo_option_t id, const void* value)
{
switch (id)
@ -257,7 +263,7 @@ int moo_setoption (moo_t* moo, moo_option_t id, const void* value)
}
einval:
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return -1;
}
@ -286,7 +292,7 @@ int moo_getoption (moo_t* moo, moo_option_t id, void* value)
return 0;
};
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return -1;
}
@ -326,7 +332,7 @@ void* moo_allocmem (moo_t* moo, moo_oow_t size)
void* ptr;
ptr = MOO_MMGR_ALLOC (moo->mmgr, size);
if (!ptr) moo->errnum = MOO_ESYSMEM;
if (!ptr) moo_seterrnum (moo, MOO_ESYSMEM);
return ptr;
}
@ -335,7 +341,7 @@ void* moo_callocmem (moo_t* moo, moo_oow_t size)
void* ptr;
ptr = MOO_MMGR_ALLOC (moo->mmgr, size);
if (!ptr) moo->errnum = MOO_ESYSMEM;
if (!ptr) moo_seterrnum (moo, MOO_ESYSMEM);
else MOO_MEMSET (ptr, 0, size);
return ptr;
}
@ -343,7 +349,7 @@ void* moo_callocmem (moo_t* moo, moo_oow_t size)
void* moo_reallocmem (moo_t* moo, void* ptr, moo_oow_t size)
{
ptr = MOO_MMGR_REALLOC (moo->mmgr, ptr, size);
if (!ptr) moo->errnum = MOO_ESYSMEM;
if (!ptr) moo_seterrnum (moo, MOO_ESYSMEM);
return ptr;
}
@ -408,7 +414,7 @@ moo_mod_data_t* moo_openmod (moo_t* moo, const moo_ooch_t* name, moo_oow_t namel
if (namelen > MOO_COUNTOF(buf) - (MOD_PREFIX_LEN + 1 + 1))
{
/* module name too long */
moo->errnum = MOO_EINVAL; /* TODO: change the error number to something more specific */
moo_seterrnum (moo, MOO_EINVAL); /* TODO: change the error number to something more specific */
return MOO_NULL;
}
@ -441,7 +447,7 @@ moo_mod_data_t* moo_openmod (moo_t* moo, const moo_ooch_t* name, moo_oow_t namel
pair = moo_rbt_insert (&moo->modtab, (moo_ooch_t*)name, namelen, &md, MOO_SIZEOF(md));
if (pair == MOO_NULL)
{
moo->errnum = MOO_ESYSMEM;
moo_seterrnum (moo, MOO_ESYSMEM);
return MOO_NULL;
}
@ -464,7 +470,7 @@ MOO_DEBUG2 (moo, "xxxxxxxxxxxxxxxxxxxxxxxxx %p %d\n", mdp, (int)MOO_IS_ALIGNED_P
{
#if !defined(MOO_ENABLE_DYNAMIC_MODULE)
MOO_DEBUG2 (moo, "Cannot find a static module [%.*js]\n", namelen, name);
moo->errnum = MOO_ENOENT;
moo_seterrnum (moo, MOO_ENOENT);
return MOO_NULL;
#endif
}
@ -472,7 +478,7 @@ MOO_DEBUG2 (moo, "xxxxxxxxxxxxxxxxxxxxxxxxx %p %d\n", mdp, (int)MOO_IS_ALIGNED_P
#if !defined(MOO_ENABLE_DYNAMIC_MODULE)
MOO_DEBUG2 (moo, "Cannot open module [%.*js] - module loading disabled\n", namelen, name);
moo->errnum = MOO_ENOIMPL; /* TODO: is it a good error number for disabled module loading? */
moo_seterrnum (moo, MOO_ENOIMPL); /* TODO: is it a good error number for disabled module loading? */
return MOO_NULL;
#endif
@ -487,7 +493,7 @@ MOO_DEBUG2 (moo, "xxxxxxxxxxxxxxxxxxxxxxxxx %p %d\n", mdp, (int)MOO_IS_ALIGNED_P
if (md.handle == MOO_NULL)
{
MOO_DEBUG2 (moo, "Cannot open a module [%.*js]\n", namelen, name);
moo->errnum = MOO_ENOENT; /* TODO: be more descriptive about the error */
moo_seterrnum (moo, MOO_ENOENT); /* TODO: be more descriptive about the error */
return MOO_NULL;
}
@ -496,7 +502,7 @@ MOO_DEBUG2 (moo, "xxxxxxxxxxxxxxxxxxxxxxxxx %p %d\n", mdp, (int)MOO_IS_ALIGNED_P
if (!load)
{
MOO_DEBUG3 (moo, "Cannot get a module symbol [%js] in [%.*js]\n", buf, namelen, name);
moo->errnum = MOO_ENOENT; /* TODO: be more descriptive about the error */
moo_seterrnum (moo, MOO_ENOENT); /* TODO: be more descriptive about the error */
moo->vmprim.dl_close (moo, md.handle);
return MOO_NULL;
}
@ -507,7 +513,7 @@ MOO_DEBUG2 (moo, "xxxxxxxxxxxxxxxxxxxxxxxxx %p %d\n", mdp, (int)MOO_IS_ALIGNED_P
if (pair == MOO_NULL)
{
MOO_DEBUG2 (moo, "Cannot register a module [%.*js]\n", namelen, name);
moo->errnum = MOO_ESYSMEM;
moo_seterrnum (moo, MOO_ESYSMEM);
moo->vmprim.dl_close (moo, md.handle);
return MOO_NULL;
}
@ -518,7 +524,7 @@ MOO_DEBUG2 (moo, "xxxxxxxxxxxxxxxxxxxxxxxxx %p %d\n", mdp, (int)MOO_IS_ALIGNED_P
if (load (moo, &mdp->mod) <= -1)
{
MOO_DEBUG3 (moo, "Module function [%js] returned failure in [%.*js]\n", buf, namelen, name);
moo->errnum = MOO_ENOENT; /* TODO: proper/better error code and handling */
moo_seterrnum (moo, MOO_ENOENT); /* TODO: proper/better error code and handling */
moo_rbt_delete (&moo->modtab, name, namelen);
moo->vmprim.dl_close (moo, mdp->handle);
return MOO_NULL;
@ -575,7 +581,7 @@ int moo_importmod (moo_t* moo, moo_oop_class_t _class, const moo_ooch_t* name, m
MOO_ASSERT (moo, mdp != MOO_NULL);
MOO_DEBUG1 (moo, "Cannot import module [%js] - already active\n", mdp->mod.name);
moo->errnum = MOO_EPERM;
moo_seterrnum (moo, MOO_EPERM);
goto done2;
}
@ -585,7 +591,7 @@ int moo_importmod (moo_t* moo, moo_oop_class_t _class, const moo_ooch_t* name, m
if (!mdp->mod.import)
{
MOO_DEBUG1 (moo, "Cannot import module [%js] - importing not supported by the module\n", mdp->mod.name);
moo->errnum = MOO_ENOIMPL;
moo_seterrnum (moo, MOO_ENOIMPL);
goto done;
}
@ -630,7 +636,7 @@ moo_pfbase_t* moo_querymod (moo_t* moo, const moo_ooch_t* pfid, moo_oow_t pfidle
* what if the compiler is broken? imagine a buggy compiler rewritten
* in moo itself? */
MOO_DEBUG2 (moo, "Internal error - no period in a primitive function identifier [%.*js] - buggy compiler?\n", pfidlen, pfid);
moo->errnum = MOO_EINTERN;
moo_seterrnum (moo, MOO_EINTERN);
return MOO_NULL;
}
@ -657,7 +663,7 @@ moo_pfbase_t* moo_querymod (moo_t* moo, const moo_ooch_t* pfid, moo_oow_t pfidle
{
/* the primitive function is not found. but keep the module open even if it's opened above */
MOO_DEBUG3 (moo, "Cannot find a primitive function [%.*js] in a module [%js]\n", pfidlen - mod_name_len - 1, sep + 1, mdp->mod.name);
moo->errnum = MOO_ENOENT; /* TODO: proper error code and handling */
moo_seterrnum (moo, MOO_ENOENT); /* TODO: proper error code and handling */
return MOO_NULL;
}
@ -704,7 +710,7 @@ int moo_genpfmethod (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class, moo_met
{
oops_inval:
MOO_DEBUG2 (moo, "Cannot generate primitive function method [%js] in [%O] - invalid name\n", mthname, _class->name);
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
goto oops;
}
@ -713,7 +719,7 @@ int moo_genpfmethod (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class, moo_met
if (moo_lookupdic (moo, _class->mthdic[type], &cs) != MOO_NULL)
{
MOO_DEBUG2 (moo, "Cannot generate primitive function method [%js] in [%O] - duplicate\n", mthname, _class->name);
moo->errnum = MOO_EEXIST;
moo_seterrnum (moo, MOO_EEXIST);
goto oops;
}
@ -822,7 +828,7 @@ moo_pfbase_t* moo_findpfbase (moo_t* moo, moo_pfinfo_t* pfinfo, moo_oow_t pfcoun
else return &pfinfo[mid].base;
}
moo->errnum = MOO_ENOENT;
moo_seterrnum (moo, MOO_ENOENT);
return MOO_NULL;
}
@ -888,7 +894,7 @@ int moo_setclasstrsize (moo_t* moo, moo_oop_class_t _class, moo_oow_t size)
return 0;
eperm:
moo->errnum = MOO_EPERM;
moo_seterrnum (moo, MOO_EPERM);
return -1;
}
@ -910,7 +916,7 @@ moo_oop_t moo_findclass (moo_t* moo, moo_oop_set_t nsdic, const moo_ooch_t* name
ass = moo_lookupdic (moo, nsdic, &n);
if (!ass || MOO_CLASSOF(moo,ass->value) != moo->_class)
{
moo->errnum = MOO_ENOENT;
moo_seterrnum (moo, MOO_ENOENT);
return MOO_NULL;
}

View File

@ -976,6 +976,12 @@ struct moo_t
moo_cmgr_t* cmgr;
moo_errnum_t errnum;
struct
{
moo_ooch_t buf[2048];
moo_oow_t len;
} errmsg;
struct
{
unsigned int trait;
@ -998,6 +1004,7 @@ struct moo_t
int last_mask;
} log;
/* ========================= */
moo_heap_t* permheap; /* TODO: put kernel objects to here */
@ -1340,8 +1347,11 @@ typedef struct moo_synerr_t moo_synerr_t;
extern "C" {
#endif
#define moo_switchprocess(moo) ((moo)->switch_proc = 1)
#if defined(MOO_HAVE_INLINE)
static MOO_INLINE void moo_switchprocess(moo_t* moo) { moo->switch_proc = 1; }
#else
# define moo_switchprocess(moo) ((moo)->switch_proc = 1)
#endif
MOO_EXPORT moo_t* moo_open (
moo_mmgr_t* mmgr,
@ -1374,7 +1384,7 @@ MOO_EXPORT void moo_fini (
static MOO_INLINE void moo_setcmgr (moo_t* moo, moo_cmgr_t* cmgr) { moo->cmgr = cmgr; }
static MOO_INLINE moo_errnum_t moo_geterrnum (moo_t* moo) { return moo->errnum; }
static MOO_INLINE void moo_seterrnum (moo_t* moo, moo_errnum_t errnum) { moo->errnum = errnum; }
static MOO_INLINE void moo_seterrnum (moo_t* moo, moo_errnum_t errnum) { moo->errnum = errnum; moo->errmsg.len = 0; }
#else
# define moo_getmmgr(moo) ((moo)->mmgr)
# define moo_getxtn(moo) ((void*)((moo) + 1))
@ -1383,9 +1393,29 @@ MOO_EXPORT void moo_fini (
# define moo_setcmgr(moo,mgr) ((moo)->cmgr = (mgr))
# define moo_geterrnum(moo) ((moo)->errnum)
# define moo_seterrnum(moo,num) ((moo)->errnum = (num))
# define moo_seterrnum(moo,num) ((moo)->errmsg.len = 0, (moo)->errnum = (num),)
#endif
void moo_seterrbfmt (
moo_t* moo,
moo_errnum_t errnum,
const moo_bch_t* fmt,
...
);
void moo_seterrufmt (
moo_t* moo,
moo_errnum_t errnum,
const moo_uch_t* fmt,
...
);
MOO_EXPORT const moo_ooch_t* moo_geterrmsg (
moo_t* moo
);
MOO_EXPORT const moo_ooch_t* moo_geterrstr (
moo_t* moo
);

View File

@ -260,7 +260,7 @@ moo_oop_t moo_instantiate (moo_t* moo, moo_oop_class_t _class, const void* vptr,
if (decode_spec (moo, _class, vlen, &type, &alloclen) <= -1)
{
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_NULL;
}
@ -327,7 +327,7 @@ moo_oop_t moo_instantiate (moo_t* moo, moo_oop_class_t _class, const void* vptr,
break;
default:
moo->errnum = MOO_EINTERN;
moo_seterrnum (moo, MOO_EINTERN);
oop = MOO_NULL;
break;
}
@ -352,7 +352,7 @@ moo_oop_t moo_instantiatewithtrailer (moo_t* moo, moo_oop_class_t _class, moo_oo
if (decode_spec (moo, _class, vlen, &type, &alloclen) <= -1)
{
moo->errnum = MOO_EINVAL;
moo_seterrnum (moo, MOO_EINVAL);
return MOO_NULL;
}
@ -390,7 +390,7 @@ moo_oop_t moo_instantiatewithtrailer (moo_t* moo, moo_oop_class_t _class, moo_oo
MOO_OBJ_GET_CHAR_SLOT(_class->name),
trlen);
moo->errnum = MOO_EPERM;
moo_seterrnum (moo, MOO_EPERM);
oop = MOO_NULL;
break;
}

View File

@ -53,7 +53,7 @@ static moo_oop_oop_t expand_bucket (moo_t* moo, moo_oop_oop_t oldbuc)
if (inc_max > 0) inc = inc_max;
else
{
moo->errnum = MOO_EOOMEM;
moo_seterrnum (moo, MOO_EOOMEM);
return MOO_NULL;
}
}
@ -108,7 +108,7 @@ static moo_oop_t find_or_make_symbol (moo_t* moo, const moo_ooch_t* ptr, moo_oow
if (!create)
{
moo->errnum = MOO_ENOENT;
moo_seterrnum (moo, MOO_ENOENT);
return MOO_NULL;
}
@ -119,7 +119,7 @@ static moo_oop_t find_or_make_symbol (moo_t* moo, const moo_ooch_t* ptr, moo_oow
{
/* this built-in table is not allowed to hold more than
* MOO_SMOOI_MAX items for efficiency sake */
moo->errnum = MOO_EDFULL;
moo_seterrnum (moo, MOO_EDFULL);
return MOO_NULL;
}