added MOO_OBJ_GET_XXX_SLOT() macros

This commit is contained in:
hyunghwan.chung 2017-01-12 17:48:04 +00:00
parent 750f529201
commit 79198df35b
3 changed files with 23 additions and 14 deletions

View File

@ -413,6 +413,12 @@ struct moo_obj_word_t
moo_oow_t slot[1];
};
#define MOO_OBJ_GET_OOP_SLOT(oop) (((moo_oop_oop_t)(oop))->slot)
#define MOO_OBJ_GET_CHAR_SLOT(oop) (((moo_oop_char_t)(oop))->slot)
#define MOO_OBJ_GET_BYTE_SLOT(oop) (((moo_oop_byte_t)(oop))->slot)
#define MOO_OBJ_GET_HALFWORD_SLOT(oop) (((moo_oop_halfword_t)(oop))->slot)
#define MOO_OBJ_GET_WORD_SLOT(oop) (((moo_oop_word_t)(oop))->slot)
typedef struct moo_trailer_t moo_trailer_t;
struct moo_trailer_t
{
@ -420,6 +426,7 @@ struct moo_trailer_t
moo_oob_t slot[1];
};
#define MOO_SET_NAMED_INSTVARS 2
typedef struct moo_set_t moo_set_t;
typedef struct moo_set_t* moo_oop_set_t;

View File

@ -243,11 +243,12 @@ static moo_pfrc_t pf_call (moo_t* moo, moo_ooi_t nargs)
/* TOOD: check if arg is a string. */
/* TODO: free all duplicated strings after call */
#if defined(MOO_OOCH_IS_UCH)
ptr = moo_dupootobchars (moo, ((moo_oop_char_t)arg)->slot, MOO_OBJ_GET_SIZE(arg), MOO_NULL);
if (!ptr) goto softfail; /* out of system memory or conversion error - soft failure */
ptr = moo_dupootobchars (moo, MOO_OBJ_GET_CHAR_SLOT(arg), MOO_OBJ_GET_SIZE(arg), MOO_NULL);
#else
ptr = moo_dupoochars (moo, ((moo_oop_char_t)arg)->slot, MOO_OBJ_GET_SIZE(arg));
ptr = MOO_OBJ_GET_CHAR_SLOT(arg);
/*ptr = moo_dupoochars (moo, MOO_OBJ_GET_CHAR_SLOT(arg), MOO_OBJ_GET_SIZE(arg));*/
#endif
if (!ptr) goto softfail; /* out of system memory or conversion error - soft failure */
dcArgPointer (dc, ptr);
j++;
@ -259,11 +260,12 @@ static moo_pfrc_t pf_call (moo_t* moo, moo_ooi_t nargs)
moo_uch_t* ptr;
#if defined(MOO_OOCH_IS_UCH)
ptr = moo_dupoochars (moo, ((moo_oop_char_t)arg)->slot, MOO_OBJ_GET_SIZE(arg));
ptr = MOO_OBJ_GET_CHAR_SLOT(arg);
/*ptr = moo_dupoochars (moo, MOO_OBJ_GET_CHAR_SLOT(arg), MOO_OBJ_GET_SIZE(arg));*/
#else
ptr = moo_dupootouchars (moo, ((moo_oop_char_t)arg)->slot, MOO_OBJ_GET_SIZE(arg), MOO_NULL);
if (!ptr) goto softfail; /* out of system memory or conversion error - soft failure */
ptr = moo_dupootouchars (moo, MOO_OBJ_GET_CHAR_SLOT(arg), MOO_OBJ_GET_SIZE(arg), MOO_NULL);
#endif
if (!ptr) goto softfail; /* out of system memory or conversion error - soft failure */
dcArgPointer (dc, ptr);
j++;

View File

@ -69,12 +69,12 @@ static moo_pfrc_t pf_open (moo_t* moo, moo_ooi_t nargs)
#if defined(MOO_OOCH_IS_UCH)
ucslen = MOO_OBJ_GET_SIZE(name);
bcslen = MOO_COUNTOF(namebuf) - 1;
if (moo_convootobchars (moo, name->slot, &ucslen, namebuf, &bcslen) <= -1) goto reterr;
if (moo_convootobchars (moo, name->slot, &ucslen, namebuf, &bcslen) <= -1) goto softfail;
namebuf[bcslen] = '\0';
ucslen = MOO_OBJ_GET_SIZE(mode);
bcslen = MOO_COUNTOF(modebuf) - 1;
if (moo_convootobchars (moo, mode->slot, &ucslen, modebuf, &bcslen) <= -1) goto reterr;
if (moo_convootobchars (moo, mode->slot, &ucslen, modebuf, &bcslen) <= -1) goto softfail;
modebuf[bcslen] = '\0';
rcv->fp = fopen (namebuf, modebuf);
@ -84,13 +84,13 @@ static moo_pfrc_t pf_open (moo_t* moo, moo_ooi_t nargs)
if (!rcv->fp)
{
moo_seterrnum (moo, moo_syserrtoerrnum(errno));
goto reterr;
goto softfail;
}
MOO_STACK_SETRETTORCV (moo, nargs);
return MOO_PF_SUCCESS;
reterr:
softfail:
MOO_STACK_SETRETTOERROR (moo, nargs);
return MOO_PF_SUCCESS;
}
@ -159,13 +159,13 @@ static moo_pfrc_t __pf_puts (moo_t* moo, moo_ooi_t nargs, moo_oow_t limit)
/* TODO: implement character conversion into stdio and use it instead of vm's conversion facility. */
if ((n = moo_convootobchars (moo, &x->slot[ucspos], &ucslen, bcs, &bcslen)) <= -1)
{
if (n != -2 || ucslen <= 0) goto reterr;
if (n != -2 || ucslen <= 0) goto softfail;
}
if (fwrite (bcs, 1, bcslen, rcv->fp) < bcslen)
{
moo_seterrnum (moo, moo_syserrtoerrnum(errno));
goto reterr;
goto softfail;
}
/* TODO: abort looping for async processing???? */
@ -176,14 +176,14 @@ static moo_pfrc_t __pf_puts (moo_t* moo, moo_ooi_t nargs, moo_oow_t limit)
else
{
moo_seterrnum (moo, MOO_EINVAL);
goto reterr;
goto softfail;
}
}
MOO_STACK_SETRETTORCV (moo, nargs);
return MOO_PF_SUCCESS;
reterr:
softfail:
MOO_STACK_SETRETTOERROR (moo, nargs);
return MOO_PF_SUCCESS;
}