changed how to compare a map against data of other types.

fixed some problems in handling nonblocking connect and send with watt-32
This commit is contained in:
hyung-hwan 2014-10-23 16:09:05 +00:00
parent 84798f4fd0
commit 2218670769
9 changed files with 207 additions and 68 deletions

View File

@ -1382,10 +1382,9 @@ enum qse_awk_val_type_t
QSE_AWK_VAL_INT = 1, /**< integer */
QSE_AWK_VAL_FLT = 2, /**< floating-pointer number */
QSE_AWK_VAL_STR = 3, /**< string */
QSE_AWK_VAL_MAP = 4, /**< map */
QSE_AWK_VAL_REX = 4, /**< regular expression */
QSE_AWK_VAL_MAP = 5, /**< map */
QSE_AWK_VAL_REX = 5, /**< regular expression */
QSE_AWK_VAL_REF = 6, /**< reference to other types */
QSE_AWK_VAL_FUN = 7
};

View File

@ -4146,42 +4146,48 @@ static qse_awk_val_t* eval_binop_band (
return qse_awk_rtx_makeintval (rtx, l1 & l2);
}
static int __cmp_nil_nil (
qse_awk_rtx_t* run, qse_awk_val_t* left, qse_awk_val_t* right)
static QSE_INLINE int __cmp_nil_nil (
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
{
return 0;
}
static int __cmp_nil_int (
static QSE_INLINE int __cmp_nil_int (
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
{
qse_awk_int_t v = QSE_AWK_RTX_GETINTFROMVAL (rtx, right);
return (v < 0)? 1: ((v > 0)? -1: 0);
}
static int __cmp_nil_real (
qse_awk_rtx_t* run, qse_awk_val_t* left, qse_awk_val_t* right)
static QSE_INLINE int __cmp_nil_flt (
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
{
if (((qse_awk_val_flt_t*)right)->val < 0) return 1;
if (((qse_awk_val_flt_t*)right)->val > 0) return -1;
return 0;
}
static int __cmp_nil_str (
qse_awk_rtx_t* run, qse_awk_val_t* left, qse_awk_val_t* right)
static QSE_INLINE int __cmp_nil_str (
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
{
return (((qse_awk_val_str_t*)right)->val.len == 0)? 0: -1;
}
static int __cmp_int_nil (
qse_awk_rtx_t* run, qse_awk_val_t* left, qse_awk_val_t* right)
static QSE_INLINE int __cmp_nil_map (
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
{
return (QSE_HTB_SIZE(((qse_awk_val_map_t*)right)->map) == 0)? 0: -1;
}
static QSE_INLINE int __cmp_int_nil (
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
{
qse_awk_int_t v = QSE_AWK_RTX_GETINTFROMVAL (rtx, left);
return (v > 0)? 1: ((v < 0)? -1: 0);
}
static int __cmp_int_int (
qse_awk_rtx_t* run, qse_awk_val_t* left, qse_awk_val_t* right)
static QSE_INLINE int __cmp_int_int (
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
{
qse_awk_int_t v1 = QSE_AWK_RTX_GETINTFROMVAL (rtx, left);
@ -4189,8 +4195,8 @@ static int __cmp_int_int (
return (v1 > v2)? 1: ((v1 < v2)? -1: 0);
}
static int __cmp_int_real (
qse_awk_rtx_t* run, qse_awk_val_t* left, qse_awk_val_t* right)
static QSE_INLINE int __cmp_int_flt (
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
{
qse_awk_int_t v1 = QSE_AWK_RTX_GETINTFROMVAL (rtx, left);
if (v1 > ((qse_awk_val_flt_t*)right)->val) return 1;
@ -4198,7 +4204,7 @@ static int __cmp_int_real (
return 0;
}
static int __cmp_int_str (
static QSE_INLINE int __cmp_int_str (
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
{
qse_awk_rtx_valtostr_out_t out;
@ -4256,8 +4262,18 @@ static int __cmp_int_str (
return n;
}
static int __cmp_flt_nil (
qse_awk_rtx_t* run, qse_awk_val_t* left, qse_awk_val_t* right)
static QSE_INLINE int __cmp_int_map (
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
{
qse_awk_int_t v1 = QSE_AWK_RTX_GETINTFROMVAL (rtx, left);
qse_awk_int_t v2 = QSE_HTB_SIZE(((qse_awk_val_map_t*)right)->map);
if (v1 > v2) return 1;
if (v1 < v2) return -1;
return 0;
}
static QSE_INLINE int __cmp_flt_nil (
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
{
if (((qse_awk_val_flt_t*)left)->val > 0) return 1;
if (((qse_awk_val_flt_t*)left)->val < 0) return -1;
@ -4265,7 +4281,7 @@ static int __cmp_flt_nil (
}
static int __cmp_flt_int (
qse_awk_rtx_t* run, qse_awk_val_t* left, qse_awk_val_t* right)
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
{
qse_awk_int_t v2 = QSE_AWK_RTX_GETINTFROMVAL (rtx, right);
if (((qse_awk_val_flt_t*)left)->val > v2) return 1;
@ -4273,8 +4289,8 @@ static int __cmp_flt_int (
return 0;
}
static int __cmp_flt_real (
qse_awk_rtx_t* run, qse_awk_val_t* left, qse_awk_val_t* right)
static int __cmp_flt_flt (
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
{
if (((qse_awk_val_flt_t*)left)->val >
((qse_awk_val_flt_t*)right)->val) return 1;
@ -4335,25 +4351,34 @@ static int __cmp_flt_str (
return n;
}
static int __cmp_str_nil (
qse_awk_rtx_t* run, qse_awk_val_t* left, qse_awk_val_t* right)
static QSE_INLINE int __cmp_flt_map (
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
{
qse_awk_int_t v2 = QSE_HTB_SIZE(((qse_awk_val_map_t*)right)->map);
if (((qse_awk_val_flt_t*)left)->val > v2) return 1;
if (((qse_awk_val_flt_t*)left)->val < v2) return -1;
return 0;
}
static QSE_INLINE int __cmp_str_nil (
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
{
return (((qse_awk_val_str_t*)left)->val.len == 0)? 0: 1;
}
static int __cmp_str_int (
qse_awk_rtx_t* run, qse_awk_val_t* left, qse_awk_val_t* right)
static QSE_INLINE int __cmp_str_int (
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
{
return -__cmp_int_str (run, right, left);
return -__cmp_int_str (rtx, right, left);
}
static int __cmp_str_real (
qse_awk_rtx_t* run, qse_awk_val_t* left, qse_awk_val_t* right)
static QSE_INLINE int __cmp_str_flt (
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
{
return -__cmp_flt_str (run, right, left);
return -__cmp_flt_str (rtx, right, left);
}
static int __cmp_str_str (
static QSE_INLINE int __cmp_str_str (
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
{
qse_awk_val_str_t* ls, * rs;
@ -4433,6 +4458,49 @@ static int __cmp_str_str (
}
}
static QSE_INLINE int __cmp_str_map (
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
{
/* can't compare a map with a string */
SETERR_COD (rtx, QSE_AWK_EOPERAND);
return CMP_ERROR;
}
static QSE_INLINE int __cmp_map_nil (
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
{
return -__cmp_nil_map (rtx, right, left);
}
static QSE_INLINE int __cmp_map_int (
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
{
return -__cmp_int_map (rtx, right, left);
}
static QSE_INLINE int __cmp_map_flt (
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
{
return -__cmp_flt_map (rtx, right, left);
}
static QSE_INLINE int __cmp_map_str (
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
{
/* can't compare a map with a string */
SETERR_COD (rtx, QSE_AWK_EOPERAND);
return CMP_ERROR;
}
static QSE_INLINE int __cmp_map_map (
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
{
/* can't compare a map with a map */
SETERR_COD (rtx, QSE_AWK_EOPERAND);
return CMP_ERROR;
}
static int __cmp_val (
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
{
@ -4443,26 +4511,34 @@ static int __cmp_val (
{
/* this table must be synchronized with
* the QSE_AWK_VAL_XXX values in awk.h */
__cmp_nil_nil, __cmp_nil_int, __cmp_nil_real, __cmp_nil_str,
__cmp_int_nil, __cmp_int_int, __cmp_int_real, __cmp_int_str,
__cmp_flt_nil, __cmp_flt_int, __cmp_flt_real, __cmp_flt_str,
__cmp_str_nil, __cmp_str_int, __cmp_str_real, __cmp_str_str,
__cmp_nil_nil, __cmp_nil_int, __cmp_nil_flt, __cmp_nil_str, __cmp_nil_map,
__cmp_int_nil, __cmp_int_int, __cmp_int_flt, __cmp_int_str, __cmp_int_map,
__cmp_flt_nil, __cmp_flt_int, __cmp_flt_flt, __cmp_flt_str, __cmp_flt_map,
__cmp_str_nil, __cmp_str_int, __cmp_str_flt, __cmp_str_str, __cmp_str_map,
__cmp_map_nil, __cmp_map_int, __cmp_map_flt, __cmp_map_str, __cmp_map_map
};
lvtype = QSE_AWK_RTX_GETVALTYPE(rtx, left);
rvtype = QSE_AWK_RTX_GETVALTYPE(rtx, right);
if (lvtype == QSE_AWK_VAL_MAP || rvtype == QSE_AWK_VAL_MAP)
if (!(rtx->awk->opt.trait & QSE_AWK_FLEXMAP) &&
(lvtype == QSE_AWK_VAL_MAP || rvtype == QSE_AWK_VAL_MAP))
{
/* TODO: get the map size and use it for comparison */
/* a map can't be compared againt other values */
SETERR_COD (rtx, QSE_AWK_EOPERAND);
return CMP_ERROR;
}
QSE_ASSERT (lvtype >= QSE_AWK_VAL_NIL && lvtype <= QSE_AWK_VAL_STR);
QSE_ASSERT (rvtype >= QSE_AWK_VAL_NIL && rvtype <= QSE_AWK_VAL_STR);
QSE_ASSERT (lvtype >= QSE_AWK_VAL_NIL && lvtype <= QSE_AWK_VAL_MAP);
QSE_ASSERT (rvtype >= QSE_AWK_VAL_NIL && rvtype <= QSE_AWK_VAL_MAP);
return func[lvtype * 4 + rvtype] (rtx, left, right);
/* mapping fomula and table layout assume:
* QSE_AWK_VAL_NIL = 0
* QSE_AWK_VAL_INT = 1
* QSE_AWK_VAL_FLT = 2
* QSE_AWK_VAL_STR = 3
* QSE_AWK_VAL_MAP = 4
*/
return func[lvtype * 5 + rvtype] (rtx, left, right);
}
static int teq_val (qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
@ -4514,7 +4590,6 @@ static int teq_val (qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* righ
}
}
return n;
}

View File

@ -154,6 +154,7 @@ qse_awk_val_t* qse_awk_rtx_makeintval (qse_awk_rtx_t* rtx, qse_awk_int_t v)
val->i_val = v;
val->nde = QSE_NULL;
printf ("makeintval => %p\n", val);
#ifdef DEBUG_VAL
qse_errputstrf (QSE_T("makeintval => %jd [%p]\n"), (qse_intmax_t)v, val);
#endif

View File

@ -73,15 +73,14 @@ struct qse_awk_val_rchunk_t
/* qse_awk_val_t pointer encoding assumes that
* the 2 least significant bits of a real pointer are all zeros. */
#define VAL_NUM_TYPE_BITS 2
#define VAL_MASK_TYPE_BITS 3
/* qse_awk_val_t pointer encoding assumes the pointer is an even number.
* is this a safe assumption? do i have to use memalign or write my own
* aligned malloc()? */
#define VAL_NUM_TYPE_BITS 1
#define VAL_MASK_TYPE_BITS 1
#define VAL_TYPE_BITS_POINTER 0
#define VAL_TYPE_BITS_QUICKINT 1
#define VAL_TYPE_BITS_RESERVED_1 2
#define VAL_TYPE_BITS_RESERVED_2 3
#define VAL_SIGN_BIT ((qse_uintptr_t)1 << (QSE_SIZEOF_UINTPTR_T * 8 - 1))
/* shrink the bit range by 1 more bit to ease signbit handling.
@ -100,7 +99,9 @@ struct qse_awk_val_rchunk_t
/* sizeof(qse_intptr_t) may not be the same as sizeof(qse_awk_int_t).
* so step-by-step type conversions are needed.
* e.g) pointer to uintptr_t, uintptr_t to intptr_t, intptr_t to awk_int_t */
#define GET_QUICKINT_FROM_POINTER(p) (((qse_uintptr_t)(p) & VAL_SIGN_BIT)? -(qse_intptr_t)(((qse_uintptr_t)(p) & ~VAL_SIGN_BIT) >> 2): (qse_intptr_t)((qse_uintptr_t)(p) >> 2))
#define POSITIVE_QUICKINT_FROM_POINTER(p) ((qse_intptr_t)((qse_uintptr_t)(p) >> VAL_NUM_TYPE_BITS))
#define NEGATIVE_QUICKINT_FROM_POINTER(p) (-(qse_intptr_t)(((qse_uintptr_t)(p) & ~VAL_SIGN_BIT) >> VAL_NUM_TYPE_BITS))
#define GET_QUICKINT_FROM_POINTER(p) (((qse_uintptr_t)(p) & VAL_SIGN_BIT)? NEGATIVE_QUICKINT_FROM_POINTER(p): POSITIVE_QUICKINT_FROM_POINTER(p))
#define QSE_AWK_RTX_GETVALTYPE(rtx,p) (IS_QUICKINT_POINTER(p)? QSE_AWK_VAL_INT: (p)->v_type)
#define QSE_AWK_RTX_GETINTFROMVAL(rtx,p) ((IS_QUICKINT_POINTER(p)? (qse_awk_int_t)GET_QUICKINT_FROM_POINTER(p): ((qse_awk_val_int_t*)(p))->i_val))

View File

@ -237,8 +237,19 @@ static qse_mux_errnum_t skerr_to_errnum (int e)
case EPIPE:
return QSE_MUX_EPIPE;
#if defined(EAGAIN) || defined(EWOULDBLOCK)
#if defined(EAGAIN) && defined(EWOULDBLOCK)
case EAGAIN:
#if (EWOULDBLOCK != EAGAIN)
case EWOULDBLOCK:
#endif
#elif defined(EAGAIN)
case EAGAIN:
#else
case EWOULDBLOCK;
#endif
return QSE_MUX_EAGAIN;
#endif
default:
return QSE_MUX_ESYSERR;

View File

@ -176,8 +176,20 @@ static qse_nwio_errnum_t skerr_to_errnum (int e)
case EPIPE:
return QSE_NWIO_EPIPE;
#if defined(EAGAIN) || defined(EWOULDBLOCK)
#if defined(EAGAIN) && defined(EWOULDBLOCK)
case EAGAIN:
#if (EWOULDBLOCK != EAGAIN)
case EWOULDBLOCK:
#endif
#elif defined(EAGAIN)
case EAGAIN:
#else
case EWOULDBLOCK;
#endif
return QSE_NWIO_EAGAIN;
#endif
#if defined(ECONNREFUSED) || defined(ENETUNREACH) || defined(EHOSTUNREACH) || defined(EHOSTDOWN)
#if defined(ECONNREFUSED)

View File

@ -90,6 +90,7 @@
} \
}
/*
#elif defined(__DOS__)
#define IMPLEMENT_SYSERR_TO_ERRNUM(obj1,obj2) \
@ -105,6 +106,7 @@
default: return __SYSERRNUM__ (obj2, ESYSERR); \
} \
}
*/
#elif defined(vms) || defined(__vms)
@ -143,7 +145,7 @@
} \
}
#else
#elif defined(EAGAIN)
#define IMPLEMENT_SYSERR_TO_ERRNUM(obj1,obj2) \
static __SYSERRTYPE__(obj1) syserr_to_errnum (int e) \
@ -164,6 +166,47 @@
} \
}
#elif defined(EWOULDBLOCK)
#define IMPLEMENT_SYSERR_TO_ERRNUM(obj1,obj2) \
static __SYSERRTYPE__(obj1) syserr_to_errnum (int e) \
{ \
switch (e) \
{ \
case ENOMEM: return __SYSERRNUM__ (obj2, ENOMEM); \
case EINVAL: return __SYSERRNUM__ (obj2, EINVAL); \
case EBUSY: \
case EACCES: return __SYSERRNUM__ (obj2, EACCES); \
case ENOTDIR: \
case ENOENT: return __SYSERRNUM__ (obj2, ENOENT); \
case EEXIST: return __SYSERRNUM__ (obj2, EEXIST); \
case EINTR: return __SYSERRNUM__ (obj2, EINTR); \
case EPIPE: return __SYSERRNUM__ (obj2, EPIPE); \
case EWOULDBLOCK: return __SYSERRNUM__ (obj2, EAGAIN); \
default: return __SYSERRNUM__ (obj2, ESYSERR); \
} \
}
#else
#define IMPLEMENT_SYSERR_TO_ERRNUM(obj1,obj2) \
static __SYSERRTYPE__(obj1) syserr_to_errnum (int e) \
{ \
switch (e) \
{ \
case ENOMEM: return __SYSERRNUM__ (obj2, ENOMEM); \
case EINVAL: return __SYSERRNUM__ (obj2, EINVAL); \
case EBUSY: \
case EACCES: return __SYSERRNUM__ (obj2, EACCES); \
case ENOTDIR: \
case ENOENT: return __SYSERRNUM__ (obj2, ENOENT); \
case EEXIST: return __SYSERRNUM__ (obj2, EEXIST); \
case EINTR: return __SYSERRNUM__ (obj2, EINTR); \
case EPIPE: return __SYSERRNUM__ (obj2, EPIPE); \
default: return __SYSERRNUM__ (obj2, ESYSERR); \
} \
}
#endif
#endif

View File

@ -242,16 +242,6 @@ static qse_httpd_errnum_t skerr_to_errnum (int e)
#define SKERR_TO_ERRNUM() skerr_to_errnum(sock_errno())
/*
#elif defined(__DOS__)
static qse_httpd_errnum_t skerr_to_errnum (int e)
{
/ * TODO: * /
return QSE_HTTPD_ESYSERR;
}
#define SKERR_TO_ERRNUM() skerr_to_errnum(errno)
*/
#else
static qse_httpd_errnum_t skerr_to_errnum (int e)
{
@ -278,11 +268,20 @@ static qse_httpd_errnum_t skerr_to_errnum (int e)
case EPIPE:
return QSE_HTTPD_EPIPE;
#if defined(EAGAIN) || defined(EWOULDBLOCK)
#if defined(EAGAIN) && defined(EWOULDBLOCK)
case EAGAIN:
#if defined(EWEOULDBLOCK) && defined(EAGAIN) && (EWOULDBLOCK != EAGAIN)
#if (EWOULDBLOCK != EAGAIN)
case EWOULDBLOCK:
#endif
#endif
#elif defined(EAGAIN)
case EAGAIN:
#else
case EWOULDBLOCK;
#endif
return QSE_HTTPD_EAGAIN;
#endif
#if defined(ECONNREFUSED) || defined(ENETUNREACH) || defined(EHOSTUNREACH) || defined(EHOSTDOWN)
#if defined(ECONNREFUSED)
@ -1362,11 +1361,6 @@ static int is_peer_socket_connected (qse_httpd_t* httpd, qse_httpd_peer_t* peer)
return 1; /* connection completed */
/*#elif defined(__DOS__)
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOIMPL);
return -1;*/
#else
qse_sck_len_t len;
@ -1380,6 +1374,9 @@ static int is_peer_socket_connected (qse_httpd_t* httpd, qse_httpd_peer_t* peer)
}
if (ret == EINPROGRESS) return 0;
#if defined(__DOS__)
if (ret == EISCONN) return 1; /* watt-32 gives EISCONN when connected */
#endif
if (ret != 0)
{
qse_httpd_seterrnum (httpd, skerr_to_errnum (ret));

View File

@ -20,7 +20,7 @@ static int fnc_basename (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
/* get the value of the first parameter */
a0 = qse_awk_rtx_getarg (rtx, 0);
if (qse_awk_rtx_getvaltype (rtx, a0) == QSE_AWK_VAL_STR)
if (qse_awk_rtx_getvaltype (rtx, a0) == QSE_AWK_VAL_STR)
{
/* if it is a string value, don't duplicate the value */
ptr = ((qse_awk_val_str_t*)a0)->val.ptr;