added the new formatting modifier 'j' for a string and a character to handle the stix_ooch_t type more conveniently

This commit is contained in:
hyunghwan.chung 2017-01-06 10:42:59 +00:00
parent 7779229b52
commit 0332b5fa5d
8 changed files with 151 additions and 70 deletions

View File

@ -1668,7 +1668,7 @@ retry:
break; break;
} }
STIX_DEBUG2 (stix, "TOKEN: [%.*S]\n", (stix_ooi_t)stix->c->tok.name.len, stix->c->tok.name.ptr); STIX_DEBUG2 (stix, "TOKEN: [%.*js]\n", (stix_ooi_t)stix->c->tok.name.len, stix->c->tok.name.ptr);
return 0; return 0;
} }
@ -4976,7 +4976,7 @@ static int __compile_class_definition (stix_t* stix, int extend)
{ {
int super_is_nil = 0; int super_is_nil = 0;
STIX_INFO2 (stix, "Defining a class %.*S\n", stix->c->cls.fqn.len, stix->c->cls.fqn.ptr); STIX_INFO2 (stix, "Defining a class %.*js\n", stix->c->cls.fqn.len, stix->c->cls.fqn.ptr);
if (TOKEN_TYPE(stix) == STIX_IOTOK_LPAREN) if (TOKEN_TYPE(stix) == STIX_IOTOK_LPAREN)
{ {
@ -5338,7 +5338,7 @@ static int __compile_pooldic_definition (stix_t* stix)
return -1; return -1;
} }
STIX_INFO2 (stix, "Defining a pool dictionary %.*S\n", stix->c->cls.fqn.len, stix->c->cls.fqn.ptr); STIX_INFO2 (stix, "Defining a pool dictionary %.*js\n", stix->c->cls.fqn.len, stix->c->cls.fqn.ptr);
GET_TOKEN (stix); GET_TOKEN (stix);

View File

@ -58,7 +58,7 @@ int stix_decode (stix_t* stix, stix_oop_method_t mth, const stix_oocs_t* classfq
cdlen = STIX_METHOD_GET_CODE_SIZE(mth); cdlen = STIX_METHOD_GET_CODE_SIZE(mth);
if (classfqn) if (classfqn)
STIX_LOG3 (stix, DECODE_LOG_MASK, "%.*S>>%O\n", classfqn->len, classfqn->ptr, mth->name); STIX_LOG3 (stix, DECODE_LOG_MASK, "%.*js>>%O\n", classfqn->len, classfqn->ptr, mth->name);
else else
STIX_LOG2 (stix, DECODE_LOG_MASK, "%O>>%O\n", mth->owner, mth->name); STIX_LOG2 (stix, DECODE_LOG_MASK, "%O>>%O\n", mth->owner, mth->name);

View File

@ -1079,7 +1079,7 @@ not_found:
} }
} }
STIX_DEBUG3 (stix, "Method [%.*S] not found for %O\n", message->len, message->ptr, receiver); STIX_DEBUG3 (stix, "Method [%.*js] not found for %O\n", message->len, message->ptr, receiver);
stix->errnum = STIX_ENOENT; stix->errnum = STIX_ENOENT;
return STIX_NULL; return STIX_NULL;
} }
@ -1204,21 +1204,21 @@ start_over:
{ {
if (*ptr == '\0') if (*ptr == '\0')
{ {
n = stix_logbfmt (stix, mask, "%C", *ptr); n = stix_logbfmt (stix, mask, "%jc", *ptr);
STIX_ASSERT (stix, n == 1); STIX_ASSERT (stix, n == 1);
rem -= n; rem -= n;
ptr += n; ptr += n;
goto start_over; goto start_over;
} }
n = stix_logbfmt (stix, mask, "%.*S", rem, ptr); n = stix_logbfmt (stix, mask, "%.*js", rem, ptr);
if (n <= -1) break; if (n <= -1) break;
if (n == 0) if (n == 0)
{ {
/* to skip the unprinted character. /* to skip the unprinted character.
* actually, this check is not needed because of '\0' skipping * actually, this check is not needed because of '\0' skipped
* at the beginning of the loop */ * at the beginning of the loop */
n = stix_logbfmt (stix, mask, "%C", *ptr); n = stix_logbfmt (stix, mask, "%jc", *ptr);
STIX_ASSERT (stix, n == 1); STIX_ASSERT (stix, n == 1);
} }
rem -= n; rem -= n;
@ -3246,7 +3246,7 @@ static int send_message (stix_t* stix, stix_oop_char_t selector, int to_super, s
/* this must not happen as long as doesNotUnderstand: is implemented under Apex. /* this must not happen as long as doesNotUnderstand: is implemented under Apex.
* this check should indicate a very serious internal problem */ * this check should indicate a very serious internal problem */
STIX_LOG4 (stix, STIX_LOG_IC | STIX_LOG_FATAL, STIX_LOG4 (stix, STIX_LOG_IC | STIX_LOG_FATAL,
"Fatal error - receiver [%O] of class [%O] does not understand a message [%.*S]\n", "Fatal error - receiver [%O] of class [%O] does not understand a message [%.*js]\n",
receiver, STIX_CLASSOF(stix, receiver), mthname.len, mthname.ptr); receiver, STIX_CLASSOF(stix, receiver), mthname.len, mthname.ptr);
stix->errnum = STIX_EMSGSND; stix->errnum = STIX_EMSGSND;
@ -3281,7 +3281,7 @@ static int send_private_message (stix_t* stix, const stix_ooch_t* nameptr, stix_
if (!method) if (!method)
{ {
STIX_LOG4 (stix, STIX_LOG_IC | STIX_LOG_FATAL, STIX_LOG4 (stix, STIX_LOG_IC | STIX_LOG_FATAL,
"Fatal error - receiver [%O] of class [%O] does not understand a private message [%.*S]\n", "Fatal error - receiver [%O] of class [%O] does not understand a private message [%.*js]\n",
receiver, STIX_CLASSOF(stix, receiver), mthname.len, mthname.ptr); receiver, STIX_CLASSOF(stix, receiver), mthname.len, mthname.ptr);
stix->errnum = STIX_EMSGSND; stix->errnum = STIX_EMSGSND;
return -1; return -1;

View File

@ -126,12 +126,12 @@ static const stix_bch_t hex2ascii_upper[] =
'N','O','P','Q','R','S','T','U','V','W','X','H','Z' 'N','O','P','Q','R','S','T','U','V','W','X','H','Z'
}; };
static stix_ooch_t ooch_nullstr[] = { '(','n','u','l','l', ')','\0' }; static stix_uch_t uch_nullstr[] = { '(','n','u','l','l', ')','\0' };
static stix_bch_t bch_nullstr[] = { '(','n','u','l','l', ')','\0' }; static stix_bch_t bch_nullstr[] = { '(','n','u','l','l', ')','\0' };
typedef int (*stix_fmtout_putch_t) ( typedef int (*stix_fmtout_putch_t) (
stix_t* stix, stix_t* stix,
stix_oow_t mask, stix_oow_t mask,
stix_ooch_t c, stix_ooch_t c,
stix_oow_t len stix_oow_t len
); );
@ -350,7 +350,7 @@ static void print_object (stix_t* stix, stix_oow_t mask, stix_oop_t oop)
{ {
if ((stix_oop_t)c == stix->_symbol) if ((stix_oop_t)c == stix->_symbol)
{ {
stix_logbfmt (stix, mask, "#%.*S", STIX_OBJ_GET_SIZE(oop), ((stix_oop_char_t)oop)->slot); stix_logbfmt (stix, mask, "#%.*js", STIX_OBJ_GET_SIZE(oop), ((stix_oop_char_t)oop)->slot);
} }
else /*if ((stix_oop_t)c == stix->_string)*/ else /*if ((stix_oop_t)c == stix->_string)*/
{ {
@ -411,11 +411,11 @@ static void print_object (stix_t* stix, stix_oow_t mask, stix_oop_t oop)
if (escaped == ch) if (escaped == ch)
stix_logbfmt (stix, mask, "\\x%X", ch); stix_logbfmt (stix, mask, "\\x%X", ch);
else else
stix_logbfmt (stix, mask, "\\%C", escaped); stix_logbfmt (stix, mask, "\\%jc", escaped);
} }
else else
{ {
stix_logbfmt (stix, mask, "%C", ch); stix_logbfmt (stix, mask, "%jc", ch);
} }
} }
@ -423,7 +423,7 @@ static void print_object (stix_t* stix, stix_oow_t mask, stix_oop_t oop)
} }
else else
{ {
stix_logbfmt (stix, mask, "'%.*S'", STIX_OBJ_GET_SIZE(oop), ((stix_oop_char_t)oop)->slot); stix_logbfmt (stix, mask, "'%.*js'", STIX_OBJ_GET_SIZE(oop), ((stix_oop_char_t)oop)->slot);
} }
} }
} }
@ -468,7 +468,7 @@ static void print_object (stix_t* stix, stix_oow_t mask, stix_oop_t oop)
else if ((stix_oop_t)c == stix->_class) else if ((stix_oop_t)c == stix->_class)
{ {
/* print the class name */ /* print the class name */
stix_logbfmt (stix, mask, "%.*S", STIX_OBJ_GET_SIZE(((stix_oop_class_t)oop)->name), ((stix_oop_class_t)oop)->name->slot); stix_logbfmt (stix, mask, "%.*js", STIX_OBJ_GET_SIZE(((stix_oop_class_t)oop)->name), ((stix_oop_class_t)oop)->name->slot);
} }
else if ((stix_oop_t)c == stix->_association) else if ((stix_oop_t)c == stix->_association)
{ {
@ -476,7 +476,7 @@ static void print_object (stix_t* stix, stix_oow_t mask, stix_oop_t oop)
} }
else else
{ {
stix_logbfmt (stix, mask, "instance of %.*S(%p)", STIX_OBJ_GET_SIZE(c->name), ((stix_oop_char_t)c->name)->slot, oop); stix_logbfmt (stix, mask, "instance of %.*js(%p)", STIX_OBJ_GET_SIZE(c->name), ((stix_oop_char_t)c->name)->slot, oop);
} }
} }
} }
@ -487,14 +487,21 @@ static void print_object (stix_t* stix, stix_oow_t mask, stix_oop_t oop)
#undef logfmtv #undef logfmtv
#define fmtchar_t stix_bch_t #define fmtchar_t stix_bch_t
#define FMTCHAR_IS_BCH #define FMTCHAR_IS_BCH
#if defined(STIX_OOCH_IS_BCH)
# define FMTCHAR_IS_OOCH
#endif
#define logfmtv stix_logbfmtv #define logfmtv stix_logbfmtv
#include "logfmtv.h" #include "logfmtv.h"
#undef fmtchar_t #undef fmtchar_t
#undef logfmtv #undef logfmtv
#define fmtchar_t stix_ooch_t #define fmtchar_t stix_uch_t
#define logfmtv stix_logoofmtv #define logfmtv stix_logufmtv
#define FMTCHAR_IS_OOCH #define FMTCHAR_IS_UCH
#if defined(STIX_OOCH_IS_UCH)
# define FMTCHAR_IS_OOCH
#endif
#include "logfmtv.h" #include "logfmtv.h"
stix_ooi_t stix_logbfmt (stix_t* stix, stix_oow_t mask, const stix_bch_t* fmt, ...) stix_ooi_t stix_logbfmt (stix_t* stix, stix_oow_t mask, const stix_bch_t* fmt, ...)
@ -519,7 +526,7 @@ stix_ooi_t stix_logbfmt (stix_t* stix, stix_oow_t mask, const stix_bch_t* fmt, .
return (x <= -1)? -1: fo.count; return (x <= -1)? -1: fo.count;
} }
stix_ooi_t stix_logoofmt (stix_t* stix, stix_oow_t mask, const stix_ooch_t* fmt, ...) stix_ooi_t stix_logufmt (stix_t* stix, stix_oow_t mask, const stix_uch_t* fmt, ...)
{ {
int x; int x;
va_list ap; va_list ap;
@ -530,7 +537,7 @@ stix_ooi_t stix_logoofmt (stix_t* stix, stix_oow_t mask, const stix_ooch_t* fmt,
fo.putcs = put_oocs; fo.putcs = put_oocs;
va_start (ap, fmt); va_start (ap, fmt);
x = stix_logoofmtv (stix, fmt, &fo, ap); x = stix_logufmtv (stix, fmt, &fo, ap);
va_end (ap); va_end (ap);
if (stix->log.len > 0 && stix->log.ptr[stix->log.len - 1] == '\n') if (stix->log.len > 0 && stix->log.ptr[stix->log.len - 1] == '\n')

View File

@ -378,7 +378,9 @@ reswitch:
/* zeropad must not take effect for 'c' */ /* zeropad must not take effect for 'c' */
if (flagc & FLAGC_ZEROPAD) padc = ' '; if (flagc & FLAGC_ZEROPAD) padc = ' ';
if (lm_flag & LF_L) goto uppercase_c; if (lm_flag & LF_L) goto uppercase_c;
#if defined(STIX_OOCH_IS_UCH)
if (lm_flag & LF_J) goto uppercase_c;
#endif
lowercase_c: lowercase_c:
bch = STIX_SIZEOF(stix_bch_t) < STIX_SIZEOF(int)? va_arg(ap, int): va_arg(ap, stix_bch_t); bch = STIX_SIZEOF(stix_bch_t) < STIX_SIZEOF(int)? va_arg(ap, int): va_arg(ap, stix_bch_t);
@ -393,13 +395,16 @@ reswitch:
case 'C': case 'C':
{ {
stix_ooch_t ooch; stix_uch_t ooch;
/* zeropad must not take effect for 'C' */ /* zeropad must not take effect for 'C' */
if (flagc & FLAGC_ZEROPAD) padc = ' '; if (flagc & FLAGC_ZEROPAD) padc = ' ';
if (lm_flag & LF_H) goto lowercase_c; if (lm_flag & LF_H) goto lowercase_c;
#if defined(STIX_OOCH_IS_BCH)
if (lm_flag & LF_J) goto lowercase_c;
#endif
uppercase_c: uppercase_c:
ooch = STIX_SIZEOF(stix_ooch_t) < STIX_SIZEOF(int)? va_arg(ap, int): va_arg(ap, stix_ooch_t); ooch = STIX_SIZEOF(stix_uch_t) < STIX_SIZEOF(int)? va_arg(ap, int): va_arg(ap, stix_uch_t);
/* precision 0 doesn't kill the letter */ /* precision 0 doesn't kill the letter */
width--; width--;
@ -417,11 +422,15 @@ reswitch:
/* zeropad must not take effect for 'S' */ /* zeropad must not take effect for 'S' */
if (flagc & FLAGC_ZEROPAD) padc = ' '; if (flagc & FLAGC_ZEROPAD) padc = ' ';
if (lm_flag & LF_L) goto uppercase_s; if (lm_flag & LF_L) goto uppercase_s;
#if defined(STIX_OOCH_IS_UCH)
if (lm_flag & LF_J) goto uppercase_s;
#endif
lowercase_s: lowercase_s:
bsp = va_arg (ap, stix_bch_t*); bsp = va_arg (ap, stix_bch_t*);
if (bsp == STIX_NULL) bsp = bch_nullstr; if (bsp == STIX_NULL) bsp = bch_nullstr;
#if defined(STIX_OOCH_IS_UCH)
/* get the length */ /* get the length */
for (bslen = 0; bsp[bslen]; bslen++); for (bslen = 0; bsp[bslen]; bslen++);
@ -461,34 +470,94 @@ reswitch:
} }
if ((flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (padc, width); if ((flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (padc, width);
break; #else
}
case 'S':
{
const stix_ooch_t* sp;
/* zeropad must not take effect for 's' */
if (flagc & FLAGC_ZEROPAD) padc = ' ';
if (lm_flag & LF_H) goto lowercase_s;
uppercase_s:
sp = va_arg (ap, stix_ooch_t*);
if (sp == STIX_NULL) sp = ooch_nullstr;
if (flagc & FLAGC_DOT) if (flagc & FLAGC_DOT)
{ {
for (n = 0; n < precision && sp[n]; n++); for (n = 0; n < precision && bsp[n]; n++);
} }
else else
{ {
for (n = 0; sp[n]; n++); for (n = 0; bsp[n]; n++);
} }
width -= n; width -= n;
if (!(flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (padc, width); if (!(flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (padc, width);
PUT_OOCS (sp, n); PUT_OOCS (bsp, n);
if ((flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (padc, width); if ((flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (padc, width);
#endif
break;
}
case 'S':
{
const stix_uch_t* usp;
stix_oow_t uslen, slen;
/* zeropad must not take effect for 's' */
if (flagc & FLAGC_ZEROPAD) padc = ' ';
if (lm_flag & LF_H) goto lowercase_s;
#if defined(STIX_OOCH_IS_UCH)
if (lm_flag & LF_J) goto lowercase_s;
#endif
uppercase_s:
usp = va_arg (ap, stix_uch_t*);
if (usp == STIX_NULL) usp = uch_nullstr;
#if defined(STIX_OOCH_IS_BCH)
/* get the length */
for (uslen = 0; usp[uslen]; uslen++);
if (stix_convutooochars (stix, usp, &uslen, STIX_NULL, &slen) <= -1)
{
/* conversion error */
stix->errnum = STIX_EECERR;
goto oops;
}
/* slen holds the length after conversion */
n = slen;
if ((flagc & FLAGC_DOT) && precision < slen) n = precision;
width -= n;
if (!(flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (padc, width);
{
stix_ooch_t conv_buf[32];
stix_oow_t conv_len, src_len, tot_len = 0;
while (n > 0)
{
STIX_ASSERT (stix, uslen > tot_len);
src_len = uslen - tot_len;
conv_len = STIX_COUNTOF(conv_buf);
/* this must not fail since the dry-run above was successful */
stix_convutooochars (stix, &usp[tot_len], &src_len, conv_buf, &conv_len);
tot_len += src_len;
if (conv_len > n) conv_len = n;
PUT_OOCS (conv_buf, conv_len);
n -= conv_len;
}
}
if ((flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (padc, width);
#else
if (flagc & FLAGC_DOT)
{
for (n = 0; n < precision && usp[n]; n++);
}
else
{
for (n = 0; usp[n]; n++);
}
width -= n;
if (!(flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (padc, width);
PUT_OOCS (usp, n);
if ((flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (padc, width);
#endif
break; break;
} }

View File

@ -24,7 +24,6 @@
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "stix-prv.h" #include "stix-prv.h"
stix_oop_process_t stix_addnewproc (stix_t* stix) stix_oop_process_t stix_addnewproc (stix_t* stix)

View File

@ -455,7 +455,7 @@ stix_mod_data_t* stix_openmod (stix_t* stix, const stix_ooch_t* name, stix_oow_t
if (md.handle == STIX_NULL) if (md.handle == STIX_NULL)
{ {
STIX_DEBUG2 (stix, "Cannot open a module [%.*S]\n", namelen, name); STIX_DEBUG2 (stix, "Cannot open a module [%.*js]\n", namelen, name);
stix->errnum = STIX_ENOENT; /* TODO: be more descriptive about the error */ stix->errnum = STIX_ENOENT; /* TODO: be more descriptive about the error */
return STIX_NULL; return STIX_NULL;
} }
@ -464,7 +464,7 @@ stix_mod_data_t* stix_openmod (stix_t* stix, const stix_ooch_t* name, stix_oow_t
load = stix->vmprim.dl_getsym (stix, md.handle, buf); load = stix->vmprim.dl_getsym (stix, md.handle, buf);
if (!load) if (!load)
{ {
STIX_DEBUG3 (stix, "Cannot get a module symbol [%S] in [%.*S]\n", buf, namelen, name); STIX_DEBUG3 (stix, "Cannot get a module symbol [%js] in [%.*js]\n", buf, namelen, name);
stix->errnum = STIX_ENOENT; /* TODO: be more descriptive about the error */ stix->errnum = STIX_ENOENT; /* TODO: be more descriptive about the error */
stix->vmprim.dl_close (stix, md.handle); stix->vmprim.dl_close (stix, md.handle);
return STIX_NULL; return STIX_NULL;
@ -475,7 +475,7 @@ stix_mod_data_t* stix_openmod (stix_t* stix, const stix_ooch_t* name, stix_oow_t
pair = stix_rbt_insert (&stix->modtab, (void*)name, namelen, &md, STIX_SIZEOF(md)); pair = stix_rbt_insert (&stix->modtab, (void*)name, namelen, &md, STIX_SIZEOF(md));
if (pair == STIX_NULL) if (pair == STIX_NULL)
{ {
STIX_DEBUG2 (stix, "Cannot register a module [%.*S]\n", namelen, name); STIX_DEBUG2 (stix, "Cannot register a module [%.*js]\n", namelen, name);
stix->errnum = STIX_ESYSMEM; stix->errnum = STIX_ESYSMEM;
stix->vmprim.dl_close (stix, md.handle); stix->vmprim.dl_close (stix, md.handle);
return STIX_NULL; return STIX_NULL;
@ -484,7 +484,7 @@ stix_mod_data_t* stix_openmod (stix_t* stix, const stix_ooch_t* name, stix_oow_t
mdp = (stix_mod_data_t*)STIX_RBT_VPTR(pair); mdp = (stix_mod_data_t*)STIX_RBT_VPTR(pair);
if (load (stix, &mdp->mod) <= -1) if (load (stix, &mdp->mod) <= -1)
{ {
STIX_DEBUG3 (stix, "Module function [%S] returned failure in [%.*S]\n", buf, namelen, name); STIX_DEBUG3 (stix, "Module function [%js] returned failure in [%.*js]\n", buf, namelen, name);
stix->errnum = STIX_ENOENT; /* TODO: proper error code and handling */ stix->errnum = STIX_ENOENT; /* TODO: proper error code and handling */
stix_rbt_delete (&stix->modtab, name, namelen); stix_rbt_delete (&stix->modtab, name, namelen);
stix->vmprim.dl_close (stix, mdp->handle); stix->vmprim.dl_close (stix, mdp->handle);
@ -493,7 +493,7 @@ stix_mod_data_t* stix_openmod (stix_t* stix, const stix_ooch_t* name, stix_oow_t
mdp->pair = pair; mdp->pair = pair;
STIX_DEBUG2 (stix, "Opened a module [%S] - %p\n", mdp->mod.name, mdp->handle); STIX_DEBUG2 (stix, "Opened a module [%js] - %p\n", mdp->mod.name, mdp->handle);
/* the module loader must ensure to set a proper query handler */ /* the module loader must ensure to set a proper query handler */
STIX_ASSERT (stix, mdp->mod.query != STIX_NULL); STIX_ASSERT (stix, mdp->mod.query != STIX_NULL);
@ -508,7 +508,7 @@ void stix_closemod (stix_t* stix, stix_mod_data_t* mdp)
if (mdp->handle) if (mdp->handle)
{ {
stix->vmprim.dl_close (stix, mdp->handle); stix->vmprim.dl_close (stix, mdp->handle);
STIX_DEBUG2 (stix, "Closed a module [%S] - %p\n", mdp->mod.name, mdp->handle); STIX_DEBUG2 (stix, "Closed a module [%js] - %p\n", mdp->mod.name, mdp->handle);
mdp->handle = STIX_NULL; mdp->handle = STIX_NULL;
} }
@ -548,7 +548,7 @@ int stix_importmod (stix_t* stix, stix_oop_t _class, const stix_ooch_t* name, st
if (!mdp->mod.import) if (!mdp->mod.import)
{ {
STIX_DEBUG1 (stix, "Cannot import module [%S] - importing not supported by the module\n", mdp->mod.name); STIX_DEBUG1 (stix, "Cannot import module [%js] - importing not supported by the module\n", mdp->mod.name);
stix->errnum = STIX_ENOIMPL; stix->errnum = STIX_ENOIMPL;
r = -1; r = -1;
goto done; goto done;
@ -556,7 +556,7 @@ int stix_importmod (stix_t* stix, stix_oop_t _class, const stix_ooch_t* name, st
if (mdp->mod.import (stix, &mdp->mod, _class) <= -1) if (mdp->mod.import (stix, &mdp->mod, _class) <= -1)
{ {
STIX_DEBUG1 (stix, "Cannot import module [%S] - module's import() returned failure\n", mdp->mod.name); STIX_DEBUG1 (stix, "Cannot import module [%js] - module's import() returned failure\n", mdp->mod.name);
r = -1; r = -1;
goto done; goto done;
} }
@ -593,7 +593,7 @@ stix_pfimpl_t stix_querymod (stix_t* stix, const stix_ooch_t* pfid, stix_oow_t p
* guarantee that an underscore is included in an primitive identifer. * guarantee that an underscore is included in an primitive identifer.
* what if the compiler is broken? imagine a buggy compiler rewritten * what if the compiler is broken? imagine a buggy compiler rewritten
* in stix itself? */ * in stix itself? */
STIX_DEBUG2 (stix, "Internal error - no period in a primitive function identifier [%.*S] - buggy compiler?\n", pfidlen, pfid); STIX_DEBUG2 (stix, "Internal error - no period in a primitive function identifier [%.*js] - buggy compiler?\n", pfidlen, pfid);
stix->errnum = STIX_EINTERN; stix->errnum = STIX_EINTERN;
return STIX_NULL; return STIX_NULL;
} }
@ -615,12 +615,12 @@ stix_pfimpl_t stix_querymod (stix_t* stix, const stix_ooch_t* pfid, stix_oow_t p
if ((handler = mdp->mod.query (stix, &mdp->mod, sep + 1)) == STIX_NULL) if ((handler = mdp->mod.query (stix, &mdp->mod, sep + 1)) == STIX_NULL)
{ {
/* the primitive function is not found. keep the module open */ /* the primitive function is not found. keep the module open */
STIX_DEBUG2 (stix, "Cannot find a primitive function [%S] in a module [%S]\n", sep + 1, mdp->mod.name); STIX_DEBUG2 (stix, "Cannot find a primitive function [%js] in a module [%js]\n", sep + 1, mdp->mod.name);
stix->errnum = STIX_ENOENT; /* TODO: proper error code and handling */ stix->errnum = STIX_ENOENT; /* TODO: proper error code and handling */
return STIX_NULL; return STIX_NULL;
} }
STIX_DEBUG3 (stix, "Found a primitive function [%S] in a module [%S] - %p\n", sep + 1, mdp->mod.name, handler); STIX_DEBUG3 (stix, "Found a primitive function [%js] in a module [%js] - %p\n", sep + 1, mdp->mod.name, handler);
return handler; return handler;
} }
@ -661,7 +661,7 @@ int stix_genpfmethod (stix_t* stix, stix_mod_t* mod, stix_oop_t _class, stix_met
if (arg_count > 0 && mthname[i - 1] != ':') if (arg_count > 0 && mthname[i - 1] != ':')
{ {
oops_inval: oops_inval:
STIX_DEBUG2 (stix, "Cannot generate primitive function method [%S] in [%O] - invalid name\n", mthname, cls->name); STIX_DEBUG2 (stix, "Cannot generate primitive function method [%js] in [%O] - invalid name\n", mthname, cls->name);
stix->errnum = STIX_EINVAL; stix->errnum = STIX_EINVAL;
goto oops; goto oops;
} }
@ -670,7 +670,7 @@ int stix_genpfmethod (stix_t* stix, stix_mod_t* mod, stix_oop_t _class, stix_met
cs.len = i; cs.len = i;
if (stix_lookupdic (stix, cls->mthdic[type], &cs) != STIX_NULL) if (stix_lookupdic (stix, cls->mthdic[type], &cs) != STIX_NULL)
{ {
STIX_DEBUG2 (stix, "Cannot generate primitive function method [%S] in [%O] - duplicate\n", mthname, cls->name); STIX_DEBUG2 (stix, "Cannot generate primitive function method [%js] in [%O] - duplicate\n", mthname, cls->name);
stix->errnum = STIX_EEXIST; stix->errnum = STIX_EEXIST;
goto oops; goto oops;
} }
@ -685,14 +685,14 @@ int stix_genpfmethod (stix_t* stix, stix_mod_t* mod, stix_oop_t _class, stix_met
stix_concatoocstrtosbuf(stix, dot, 0) <= -1 || stix_concatoocstrtosbuf(stix, dot, 0) <= -1 ||
stix_concatoocstrtosbuf(stix, pfname, 0) <= -1) stix_concatoocstrtosbuf(stix, pfname, 0) <= -1)
{ {
STIX_DEBUG2 (stix, "Cannot generate primitive function method [%S] in [%O] - VM memory shortage\n", mthname, cls->name); STIX_DEBUG2 (stix, "Cannot generate primitive function method [%js] in [%O] - VM memory shortage\n", mthname, cls->name);
return -1; return -1;
} }
pfidsym = (stix_oop_char_t)stix_makesymbol (stix, stix->sbuf[0].ptr, stix->sbuf[0].len); pfidsym = (stix_oop_char_t)stix_makesymbol (stix, stix->sbuf[0].ptr, stix->sbuf[0].len);
if (!pfidsym) if (!pfidsym)
{ {
STIX_DEBUG2 (stix, "Cannot generate primitive function method [%S] in [%O] - symbol instantiation failure\n", mthname, cls->name); STIX_DEBUG2 (stix, "Cannot generate primitive function method [%js] in [%O] - symbol instantiation failure\n", mthname, cls->name);
goto oops; goto oops;
} }
stix_pushtmp (stix, (stix_oop_t*)&pfidsym); tmp_count++; stix_pushtmp (stix, (stix_oop_t*)&pfidsym); tmp_count++;
@ -704,7 +704,7 @@ int stix_genpfmethod (stix_t* stix, stix_mod_t* mod, stix_oop_t _class, stix_met
#endif #endif
if (!mth) if (!mth)
{ {
STIX_DEBUG2 (stix, "Cannot generate primitive function method [%S] in [%O] - method instantiation failure\n", mthname, cls->name); STIX_DEBUG2 (stix, "Cannot generate primitive function method [%js] in [%O] - method instantiation failure\n", mthname, cls->name);
goto oops; goto oops;
} }
@ -725,11 +725,11 @@ int stix_genpfmethod (stix_t* stix, stix_mod_t* mod, stix_oop_t _class, stix_met
if (!stix_putatdic (stix, cls->mthdic[type], (stix_oop_t)mnsym, (stix_oop_t)mth)) if (!stix_putatdic (stix, cls->mthdic[type], (stix_oop_t)mnsym, (stix_oop_t)mth))
{ {
STIX_DEBUG2 (stix, "Cannot generate primitive function method [%S] in [%O] - failed to add to method dictionary\n", mthname, cls->name); STIX_DEBUG2 (stix, "Cannot generate primitive function method [%js] in [%O] - failed to add to method dictionary\n", mthname, cls->name);
goto oops; goto oops;
} }
STIX_DEBUG2 (stix, "Generated primitive function method [%S] in [%O]\n", mthname, cls->name); STIX_DEBUG2 (stix, "Generated primitive function method [%js] in [%O]\n", mthname, cls->name);
stix_poptmps (stix, tmp_count); tmp_count = 0; stix_poptmps (stix, tmp_count); tmp_count = 0;
return 0; return 0;

View File

@ -1341,10 +1341,10 @@ STIX_EXPORT int stix_genpfmethod (
# define stix_convootobcstr(stix,oocs,oocslen,bcs,bcslen) stix_convutobcstr(stix,oocs,oocslen,bcs,bcslen) # define stix_convootobcstr(stix,oocs,oocslen,bcs,bcslen) stix_convutobcstr(stix,oocs,oocslen,bcs,bcslen)
# define stix_convbtooocstr(stix,bcs,bcslen,oocs,oocslen) stix_convbtoucstr(stix,bcs,bcslen,oocs,oocslen) # define stix_convbtooocstr(stix,bcs,bcslen,oocs,oocslen) stix_convbtoucstr(stix,bcs,bcslen,oocs,oocslen)
#else #else
# define stix_convootobchars(stix,oocs,oocslen,bcs,bcslen) stix_convutobchars(stix,oocs,oocslen,bcs,bcslen) # define stix_convootouchars(stix,oocs,oocslen,bcs,bcslen) stix_convbtouchars(stix,oocs,oocslen,bcs,bcslen)
# define stix_convbtooochars(stix,bcs,bcslen,oocs,oocslen) stix_convbtouchars(stix,bcs,bcslen,oocs,oocslen) # define stix_convutooochars(stix,bcs,bcslen,oocs,oocslen) stix_convutobchars(stix,bcs,bcslen,oocs,oocslen)
# define stix_convootobcstr(stix,oocs,oocslen,bcs,bcslen) stix_convutobcstr(stix,oocs,oocslen,bcs,bcslen) # define stix_convootoucstr(stix,oocs,oocslen,bcs,bcslen) stix_convbtoucstr(stix,oocs,oocslen,bcs,bcslen)
# define stix_convbtooocstr(stix,bcs,bcslen,oocs,oocslen) stix_convbtoucstr(stix,bcs,bcslen,oocs,oocslen) # define stix_convutooocstr(stix,bcs,bcslen,oocs,oocslen) stix_convutobcstr(stix,bcs,bcslen,oocs,oocslen)
#endif #endif
STIX_EXPORT int stix_convbtouchars ( STIX_EXPORT int stix_convbtouchars (
@ -1400,13 +1400,19 @@ STIX_EXPORT stix_ooi_t stix_logbfmt (
... ...
); );
STIX_EXPORT stix_ooi_t stix_logoofmt ( STIX_EXPORT stix_ooi_t stix_logufmt (
stix_t* stix, stix_t* stix,
stix_oow_t mask, stix_oow_t mask,
const stix_ooch_t* fmt, const stix_uch_t* fmt,
... ...
); );
#if defined(STIX_OOCH_IS_UCH)
# define stix_logoofmt stix_logufmt
#else
# define stix_logoofmt stix_logbfmt
#endif
/* ========================================================================= /* =========================================================================
* MISCELLANEOUS HELPER FUNCTIONS * MISCELLANEOUS HELPER FUNCTIONS
* ========================================================================= */ * ========================================================================= */