trying to implement byte array in awk
This commit is contained in:
parent
1a16fd8888
commit
5e0754e607
@ -133,14 +133,14 @@ typedef qse_floc_t qse_awk_loc_t;
|
||||
*/
|
||||
/*
|
||||
#define QSE_AWK_VAL_HDR \
|
||||
unsigned int type: 3; \
|
||||
unsigned int ref: 26; \
|
||||
unsigned int type: 4; \
|
||||
unsigned int ref: 25; \
|
||||
unsigned int stat: 1; \
|
||||
unsigned int nstr: 2
|
||||
*/
|
||||
#define QSE_AWK_VAL_HDR \
|
||||
qse_uintptr_t v_type: 3; \
|
||||
qse_uintptr_t ref: ((QSE_SIZEOF_UINTPTR_T * 8) - 6); \
|
||||
qse_uintptr_t v_type: 4; \
|
||||
qse_uintptr_t ref: ((QSE_SIZEOF_UINTPTR_T * 8) - 7); \
|
||||
qse_uintptr_t stat: 1; \
|
||||
qse_uintptr_t nstr: 2
|
||||
|
||||
@ -201,6 +201,17 @@ struct qse_awk_val_str_t
|
||||
};
|
||||
typedef struct qse_awk_val_str_t qse_awk_val_str_t;
|
||||
|
||||
/**
|
||||
* The qse_awk_val_str_t type is a string type. The type field is
|
||||
* #QSE_AWK_VAL_BYTEARR.
|
||||
*/
|
||||
struct qse_awk_val_bytearr_t
|
||||
{
|
||||
QSE_AWK_VAL_HDR;
|
||||
qse_u8ptl_t val;
|
||||
};
|
||||
typedef struct qse_awk_val_bytearr_t qse_awk_val_bytearr_t;
|
||||
|
||||
/**
|
||||
* The qse_awk_val_rex_t type is a regular expression type. The type field
|
||||
* is #QSE_AWK_VAL_REX.
|
||||
@ -1383,18 +1394,19 @@ typedef enum qse_awk_gbl_id_t qse_awk_gbl_id_t;
|
||||
*/
|
||||
enum qse_awk_val_type_t
|
||||
{
|
||||
/* the values between QSE_AWK_VAL_NIL and QSE_AWK_VAL_STR inclusive
|
||||
/* the values between QSE_AWK_VAL_NIL and QSE_AWK_VAL_MAP inclusive
|
||||
* must be synchronized with an internal table of the __cmp_val
|
||||
* function in run.c */
|
||||
QSE_AWK_VAL_NIL = 0, /**< nil */
|
||||
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_BYTEARR = 4, /**< byte array */
|
||||
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
|
||||
QSE_AWK_VAL_REX = 6, /**< regular expression */
|
||||
QSE_AWK_VAL_REF = 7, /**< reference to other types */
|
||||
QSE_AWK_VAL_FUN = 8
|
||||
};
|
||||
typedef enum qse_awk_val_type_t qse_awk_val_type_t;
|
||||
|
||||
@ -2424,6 +2436,16 @@ QSE_EXPORT qse_awk_val_t* qse_awk_rtx_makenstrvalwithxstr (
|
||||
const qse_cstr_t* str
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_awk_rtx_makebytearrvaal() function create a byte array value.
|
||||
* \return value on success, #QSE_NULL on failure
|
||||
*/
|
||||
qse_awk_val_t* qse_awk_rtx_makebytearrval (
|
||||
qse_awk_rtx_t* rtx,
|
||||
const qse_uint8_t* ptr,
|
||||
qse_size_t len
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_awk_rtx_makerexval() function creates a regular expression value.
|
||||
* \return value on success, #QSE_NULL on failure
|
||||
|
@ -754,6 +754,18 @@ typedef struct qse_wcstr_t qse_wcstr_t;
|
||||
typedef qse_wcstr_t qse_cstr_t;
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* The qse_u8ptl_t type defines a structure with a pointer to 8-bit unsigned
|
||||
* integer string and its length.
|
||||
*/
|
||||
struct qse_u8ptl_t
|
||||
{
|
||||
qse_uint8_t* ptr;
|
||||
qse_size_t len;
|
||||
};
|
||||
typedef struct qse_u8ptl_t qse_u8ptl_t;
|
||||
|
||||
/**
|
||||
* The qse_xptl_t type defines a pair type of a pointer and a length.
|
||||
*/
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
#include "awk-prv.h"
|
||||
#include <qse/cmn/fmt.h>
|
||||
#include <qse/cmn/mbwc.h>
|
||||
|
||||
#ifdef DEBUG_RUN
|
||||
#include <qse/cmn/sio.h>
|
||||
@ -4158,48 +4159,46 @@ static qse_awk_val_t* eval_binop_band (
|
||||
return qse_awk_rtx_makeintval (rtx, l1 & l2);
|
||||
}
|
||||
|
||||
static QSE_INLINE int __cmp_nil_nil (
|
||||
qse_awk_rtx_t* rtx, 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 QSE_INLINE int __cmp_nil_int (
|
||||
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
|
||||
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 QSE_INLINE int __cmp_nil_flt (
|
||||
qse_awk_rtx_t* rtx, 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 QSE_INLINE int __cmp_nil_str (
|
||||
qse_awk_rtx_t* rtx, 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 QSE_INLINE int __cmp_nil_map (
|
||||
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
|
||||
static QSE_INLINE int __cmp_nil_bytearr (qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
|
||||
{
|
||||
return (((qse_awk_val_bytearr_t*)right)->val.len == 0)? 0: -1;
|
||||
}
|
||||
|
||||
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)
|
||||
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 QSE_INLINE int __cmp_int_int (
|
||||
qse_awk_rtx_t* rtx, 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);
|
||||
@ -4216,8 +4215,7 @@ static QSE_INLINE int __cmp_int_flt (
|
||||
return 0;
|
||||
}
|
||||
|
||||
static QSE_INLINE int __cmp_int_str (
|
||||
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
|
||||
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;
|
||||
int n;
|
||||
@ -4275,9 +4273,16 @@ static QSE_INLINE int __cmp_int_str (
|
||||
return n;
|
||||
}
|
||||
|
||||
static QSE_INLINE int __cmp_int_map (
|
||||
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
|
||||
static QSE_INLINE int __cmp_int_bytearr (qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
|
||||
{
|
||||
/* can't compare an integer with a byte array */
|
||||
SETERR_COD (rtx, QSE_AWK_EOPERAND);
|
||||
return CMP_ERROR;
|
||||
}
|
||||
|
||||
static QSE_INLINE int __cmp_int_map (qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
|
||||
{
|
||||
/* compare an integer and the size of a map */
|
||||
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;
|
||||
@ -4285,16 +4290,14 @@ static QSE_INLINE int __cmp_int_map (
|
||||
return 0;
|
||||
}
|
||||
|
||||
static QSE_INLINE int __cmp_flt_nil (
|
||||
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
|
||||
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;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __cmp_flt_int (
|
||||
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
|
||||
static int __cmp_flt_int (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;
|
||||
@ -4302,8 +4305,7 @@ static int __cmp_flt_int (
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __cmp_flt_flt (
|
||||
qse_awk_rtx_t* rtx, 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;
|
||||
@ -4312,8 +4314,7 @@ static int __cmp_flt_flt (
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __cmp_flt_str (
|
||||
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
|
||||
static int __cmp_flt_str (qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
|
||||
{
|
||||
qse_awk_rtx_valtostr_out_t out;
|
||||
int n;
|
||||
@ -4364,35 +4365,38 @@ static int __cmp_flt_str (
|
||||
return n;
|
||||
}
|
||||
|
||||
static QSE_INLINE int __cmp_flt_map (
|
||||
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
|
||||
static int __cmp_flt_bytearr (qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
|
||||
{
|
||||
/* can't compare a float with a byte array */
|
||||
SETERR_COD (rtx, QSE_AWK_EOPERAND);
|
||||
return CMP_ERROR;
|
||||
}
|
||||
|
||||
static QSE_INLINE int __cmp_flt_map (qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
|
||||
{
|
||||
/* compare a float with the size of a map */
|
||||
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)
|
||||
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 QSE_INLINE int __cmp_str_int (
|
||||
qse_awk_rtx_t* rtx, 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(rtx, right, left);
|
||||
}
|
||||
|
||||
static QSE_INLINE int __cmp_str_flt (
|
||||
qse_awk_rtx_t* rtx, 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 (rtx, right, left);
|
||||
}
|
||||
|
||||
static QSE_INLINE int __cmp_str_str (
|
||||
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
|
||||
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;
|
||||
|
||||
@ -4411,15 +4415,13 @@ static QSE_INLINE int __cmp_str_str (
|
||||
{
|
||||
qse_awk_int_t ll;
|
||||
|
||||
ll = qse_awk_strxtoint (
|
||||
rtx->awk, ls->val.ptr, ls->val.len, 0, QSE_NULL);
|
||||
ll = qse_awk_strxtoint(rtx->awk, ls->val.ptr, ls->val.len, 0, QSE_NULL);
|
||||
|
||||
if (rs->nstr == 1)
|
||||
{
|
||||
qse_awk_int_t rr;
|
||||
|
||||
rr = qse_awk_strxtoint (
|
||||
rtx->awk, rs->val.ptr, rs->val.len, 0, QSE_NULL);
|
||||
rr = qse_awk_strxtoint(rtx->awk, rs->val.ptr, rs->val.len, 0, QSE_NULL);
|
||||
|
||||
return (ll > rr)? 1:
|
||||
(ll < rr)? -1: 0;
|
||||
@ -4430,8 +4432,7 @@ static QSE_INLINE int __cmp_str_str (
|
||||
|
||||
QSE_ASSERT (rs->nstr == 2);
|
||||
|
||||
rr = qse_awk_strxtoflt (
|
||||
rtx->awk, rs->val.ptr, rs->val.len, QSE_NULL);
|
||||
rr = qse_awk_strxtoflt(rtx->awk, rs->val.ptr, rs->val.len, QSE_NULL);
|
||||
|
||||
return (ll > rr)? 1:
|
||||
(ll < rr)? -1: 0;
|
||||
@ -4443,15 +4444,13 @@ static QSE_INLINE int __cmp_str_str (
|
||||
|
||||
QSE_ASSERT (ls->nstr == 2);
|
||||
|
||||
ll = qse_awk_strxtoflt (
|
||||
rtx->awk, ls->val.ptr, ls->val.len, QSE_NULL);
|
||||
ll = qse_awk_strxtoflt(rtx->awk, ls->val.ptr, ls->val.len, QSE_NULL);
|
||||
|
||||
if (rs->nstr == 1)
|
||||
{
|
||||
qse_awk_int_t rr;
|
||||
|
||||
rr = qse_awk_strxtoint (
|
||||
rtx->awk, rs->val.ptr, rs->val.len, 0, QSE_NULL);
|
||||
rr = qse_awk_strxtoint(rtx->awk, rs->val.ptr, rs->val.len, 0, QSE_NULL);
|
||||
|
||||
return (ll > rr)? 1:
|
||||
(ll < rr)? -1: 0;
|
||||
@ -4462,8 +4461,7 @@ static QSE_INLINE int __cmp_str_str (
|
||||
|
||||
QSE_ASSERT (rs->nstr == 2);
|
||||
|
||||
rr = qse_awk_strxtoflt (
|
||||
rtx->awk, rs->val.ptr, rs->val.len, QSE_NULL);
|
||||
rr = qse_awk_strxtoflt(rtx->awk, rs->val.ptr, rs->val.len, QSE_NULL);
|
||||
|
||||
return (ll > rr)? 1:
|
||||
(ll < rr)? -1: 0;
|
||||
@ -4471,43 +4469,109 @@ static QSE_INLINE 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)
|
||||
static QSE_INLINE int __cmp_str_bytearr (qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
|
||||
{
|
||||
qse_awk_val_str_t* ls = (qse_awk_val_str_t*)left;
|
||||
qse_awk_val_bytearr_t* rs = (qse_awk_val_bytearr_t*)right;
|
||||
|
||||
#if (QSE_SIZEOF_MCHAR_T != QSE_SIZEOF_UINT8_T)
|
||||
# error Unsupported size of qse_mchar_t
|
||||
#endif
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
return qse_mbsxncmp(ls->val.ptr, ls->val.len, rs->val.ptr, rs->val.len);
|
||||
#else
|
||||
qse_mchar_t* mbsptr;
|
||||
qse_size_t mbslen;
|
||||
int n;
|
||||
|
||||
mbsptr = qse_wcsntombsdup(ls->val.ptr, ls->val.len, &mbslen, qse_awk_rtx_getmmgr(rtx));
|
||||
if (!mbsptr)
|
||||
{
|
||||
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL);
|
||||
return CMP_ERROR;
|
||||
}
|
||||
n = qse_mbsxncmp(mbsptr, mbslen, (const qse_mchar_t*)rs->val.ptr, rs->val.len);
|
||||
QSE_AWK_FREE (rtx->awk, mbsptr);
|
||||
return n;
|
||||
#endif
|
||||
}
|
||||
|
||||
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_bytearr_nil (qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
|
||||
{
|
||||
return (((qse_awk_val_bytearr_t*)left)->val.len == 0)? 0: 1;
|
||||
}
|
||||
|
||||
static QSE_INLINE int __cmp_map_nil (
|
||||
qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
|
||||
static QSE_INLINE int __cmp_bytearr_int (qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
|
||||
{
|
||||
return -__cmp_int_bytearr(rtx, right, left);
|
||||
}
|
||||
|
||||
static QSE_INLINE int __cmp_bytearr_flt (qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
|
||||
{
|
||||
return -__cmp_flt_bytearr(rtx, right, left);
|
||||
}
|
||||
|
||||
static QSE_INLINE int __cmp_bytearr_str (qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
|
||||
{
|
||||
return -__cmp_str_bytearr(rtx, right, left);
|
||||
}
|
||||
|
||||
static QSE_INLINE int __cmp_bytearr_bytearr (qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
|
||||
{
|
||||
qse_awk_val_bytearr_t* ls = (qse_awk_val_bytearr_t*)left;
|
||||
qse_awk_val_bytearr_t* rs = (qse_awk_val_bytearr_t*)right;
|
||||
#if (QSE_SIZEOF_MCHAR_T != QSE_SIZEOF_UINT8_T)
|
||||
# error Unsupported size of qse_mchar_t
|
||||
#endif
|
||||
return qse_mbsxncmp(ls->val.ptr, ls->val.len, rs->val.ptr, rs->val.len);
|
||||
}
|
||||
|
||||
static QSE_INLINE int __cmp_bytearr_map (qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
|
||||
{
|
||||
/* can't compare a byte array with a map */
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
static QSE_INLINE int __cmp_map_bytearr (qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
|
||||
{
|
||||
/* can't compare a map with a byte array */
|
||||
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);
|
||||
@ -4524,11 +4588,12 @@ 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_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
|
||||
__cmp_nil_nil, __cmp_nil_int, __cmp_nil_flt, __cmp_nil_str, __cmp_nil_bytearr, __cmp_nil_map,
|
||||
__cmp_int_nil, __cmp_int_int, __cmp_int_flt, __cmp_int_str, __cmp_int_bytearr, __cmp_int_map,
|
||||
__cmp_flt_nil, __cmp_flt_int, __cmp_flt_flt, __cmp_flt_str, __cmp_flt_bytearr, __cmp_flt_map,
|
||||
__cmp_str_nil, __cmp_str_int, __cmp_str_flt, __cmp_str_str, __cmp_str_bytearr, __cmp_str_map,
|
||||
__cmp_bytearr_nil, __cmp_bytearr_int, __cmp_bytearr_flt, __cmp_bytearr_str, __cmp_bytearr_bytearr, __cmp_bytearr_map,
|
||||
__cmp_map_nil, __cmp_map_int, __cmp_map_flt, __cmp_map_str, __cmp_map_bytearr, __cmp_map_map
|
||||
};
|
||||
|
||||
lvtype = QSE_AWK_RTX_GETVALTYPE(rtx, left);
|
||||
@ -4549,9 +4614,10 @@ static int __cmp_val (
|
||||
* QSE_AWK_VAL_INT = 1
|
||||
* QSE_AWK_VAL_FLT = 2
|
||||
* QSE_AWK_VAL_STR = 3
|
||||
* QSE_AWK_VAL_MAP = 4
|
||||
* QSE_AWK_VAL_BYTEARR = 4
|
||||
* QSE_AWK_VAL_MAP = 5
|
||||
*/
|
||||
return func[lvtype * 5 + rvtype] (rtx, left, right);
|
||||
return func[lvtype * 6 + rvtype](rtx, left, right);
|
||||
}
|
||||
|
||||
static int teq_val (qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
|
||||
@ -4575,13 +4641,11 @@ static int teq_val (qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* righ
|
||||
break;
|
||||
|
||||
case QSE_AWK_VAL_INT:
|
||||
n = (QSE_AWK_RTX_GETINTFROMVAL (rtx, left) ==
|
||||
QSE_AWK_RTX_GETINTFROMVAL (rtx, right));
|
||||
n = (QSE_AWK_RTX_GETINTFROMVAL (rtx, left) == QSE_AWK_RTX_GETINTFROMVAL (rtx, right));
|
||||
break;
|
||||
|
||||
case QSE_AWK_VAL_FLT:
|
||||
n = ((qse_awk_val_flt_t*)left)->val ==
|
||||
((qse_awk_val_flt_t*)right)->val;
|
||||
n = ((qse_awk_val_flt_t*)left)->val == ((qse_awk_val_flt_t*)right)->val;
|
||||
break;
|
||||
|
||||
case QSE_AWK_VAL_STR:
|
||||
@ -4592,6 +4656,14 @@ static int teq_val (qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* righ
|
||||
((qse_awk_val_str_t*)right)->val.len) == 0;
|
||||
break;
|
||||
|
||||
case QSE_AWK_VAL_BYTEARR:
|
||||
n = qse_mbsxncmp (
|
||||
((qse_awk_val_bytearr_t*)left)->val.ptr,
|
||||
((qse_awk_val_bytearr_t*)left)->val.len,
|
||||
((qse_awk_val_bytearr_t*)right)->val.ptr,
|
||||
((qse_awk_val_bytearr_t*)right)->val.len) == 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
/* map-x and map-y are always different regardless of
|
||||
* their contents. however, if they are pointing to the
|
||||
|
@ -174,8 +174,7 @@ qse_awk_val_t* qse_awk_rtx_makefltval (qse_awk_rtx_t* rtx, qse_awk_flt_t v)
|
||||
return (qse_awk_val_t*)val;
|
||||
}
|
||||
|
||||
qse_awk_val_t* qse_awk_rtx_makestrvalwithxstr (
|
||||
qse_awk_rtx_t* rtx, const qse_cstr_t* str)
|
||||
qse_awk_val_t* qse_awk_rtx_makestrvalwithxstr (qse_awk_rtx_t* rtx, const qse_cstr_t* str)
|
||||
{
|
||||
qse_awk_val_str_t* val = QSE_NULL;
|
||||
qse_size_t rlen = str->len;
|
||||
@ -195,10 +194,7 @@ qse_awk_val_t* qse_awk_rtx_makestrvalwithxstr (
|
||||
}
|
||||
#endif
|
||||
|
||||
val = (qse_awk_val_str_t*) QSE_AWK_ALLOC (
|
||||
rtx->awk,
|
||||
QSE_SIZEOF(qse_awk_val_str_t) +
|
||||
(rlen + 1) * QSE_SIZEOF(qse_char_t));
|
||||
val = (qse_awk_val_str_t*)QSE_AWK_ALLOC(rtx->awk, QSE_SIZEOF(qse_awk_val_str_t) + (rlen + 1) * QSE_SIZEOF(qse_char_t));
|
||||
if (val == QSE_NULL)
|
||||
{
|
||||
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL);
|
||||
@ -222,8 +218,7 @@ init:
|
||||
return (qse_awk_val_t*)val;
|
||||
}
|
||||
|
||||
qse_awk_val_t* qse_awk_rtx_makestrvalwithmbs (
|
||||
qse_awk_rtx_t* rtx, const qse_mchar_t* mbs)
|
||||
qse_awk_val_t* qse_awk_rtx_makestrvalwithmbs (qse_awk_rtx_t* rtx, const qse_mchar_t* mbs)
|
||||
{
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
return qse_awk_rtx_makestrval(rtx, mbs, qse_mbslen(mbs));
|
||||
@ -244,8 +239,7 @@ qse_awk_val_t* qse_awk_rtx_makestrvalwithmbs (
|
||||
#endif
|
||||
}
|
||||
|
||||
qse_awk_val_t* qse_awk_rtx_makestrvalwithwcs (
|
||||
qse_awk_rtx_t* rtx, const qse_wchar_t* wcs)
|
||||
qse_awk_val_t* qse_awk_rtx_makestrvalwithwcs (qse_awk_rtx_t* rtx, const qse_wchar_t* wcs)
|
||||
{
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
qse_awk_val_t* v;
|
||||
@ -266,14 +260,12 @@ qse_awk_val_t* qse_awk_rtx_makestrvalwithwcs (
|
||||
#endif
|
||||
}
|
||||
|
||||
qse_awk_val_t* qse_awk_rtx_makestrvalwithstr (
|
||||
qse_awk_rtx_t* rtx, const qse_char_t* str)
|
||||
qse_awk_val_t* qse_awk_rtx_makestrvalwithstr (qse_awk_rtx_t* rtx, const qse_char_t* str)
|
||||
{
|
||||
return qse_awk_rtx_makestrval (rtx, str, qse_strlen(str));
|
||||
}
|
||||
|
||||
qse_awk_val_t* qse_awk_rtx_makestrvalwithmxstr (
|
||||
qse_awk_rtx_t* rtx, const qse_mcstr_t* mxstr)
|
||||
qse_awk_val_t* qse_awk_rtx_makestrvalwithmxstr (qse_awk_rtx_t* rtx, const qse_mcstr_t* mxstr)
|
||||
{
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
return qse_awk_rtx_makestrvalwithxstr(rtx, mxstr);
|
||||
@ -296,8 +288,7 @@ qse_awk_val_t* qse_awk_rtx_makestrvalwithmxstr (
|
||||
#endif
|
||||
}
|
||||
|
||||
qse_awk_val_t* qse_awk_rtx_makestrvalwithwxstr (
|
||||
qse_awk_rtx_t* rtx, const qse_wcstr_t* wxstr)
|
||||
qse_awk_val_t* qse_awk_rtx_makestrvalwithwxstr (qse_awk_rtx_t* rtx, const qse_wcstr_t* wxstr)
|
||||
{
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
qse_awk_val_t* v;
|
||||
@ -320,8 +311,7 @@ qse_awk_val_t* qse_awk_rtx_makestrvalwithwxstr (
|
||||
#endif
|
||||
}
|
||||
|
||||
qse_awk_val_t* qse_awk_rtx_makestrval (
|
||||
qse_awk_rtx_t* rtx, const qse_char_t* str, qse_size_t len)
|
||||
qse_awk_val_t* qse_awk_rtx_makestrval (qse_awk_rtx_t* rtx, const qse_char_t* str, qse_size_t len)
|
||||
{
|
||||
qse_cstr_t xstr;
|
||||
xstr.ptr = (qse_char_t*)str;
|
||||
@ -329,10 +319,7 @@ qse_awk_val_t* qse_awk_rtx_makestrval (
|
||||
return qse_awk_rtx_makestrvalwithxstr(rtx, &xstr);
|
||||
}
|
||||
|
||||
qse_awk_val_t* qse_awk_rtx_makestrval2 (
|
||||
qse_awk_rtx_t* rtx,
|
||||
const qse_char_t* str1, qse_size_t len1,
|
||||
const qse_char_t* str2, qse_size_t len2)
|
||||
qse_awk_val_t* qse_awk_rtx_makestrval2 (qse_awk_rtx_t* rtx, const qse_char_t* str1, qse_size_t len1, const qse_char_t* str2, qse_size_t len2)
|
||||
{
|
||||
qse_awk_val_str_t* val;
|
||||
qse_size_t rlen = len1 + len2;
|
||||
@ -411,8 +398,31 @@ qse_awk_val_t* qse_awk_rtx_makenstrvalwithxstr (qse_awk_rtx_t* rtx, const qse_cs
|
||||
return v;
|
||||
}
|
||||
|
||||
qse_awk_val_t* qse_awk_rtx_makerexval (
|
||||
qse_awk_rtx_t* rtx, const qse_cstr_t* str, void* code[2])
|
||||
qse_awk_val_t* qse_awk_rtx_makebytearrval (qse_awk_rtx_t* rtx, const qse_uint8_t* ptr, qse_size_t len)
|
||||
{
|
||||
qse_awk_val_bytearr_t* val = QSE_NULL;
|
||||
qse_size_t xlen = len * QSE_SIZEOF(*ptr);
|
||||
|
||||
val = (qse_awk_val_bytearr_t*)QSE_AWK_ALLOC(rtx->awk, QSE_SIZEOF(qse_awk_val_bytearr_t) + xlen + QSE_SIZEOF(*ptr));
|
||||
if (val == QSE_NULL)
|
||||
{
|
||||
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL);
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
val->v_type = QSE_AWK_VAL_BYTEARR;
|
||||
val->ref = 0;
|
||||
val->stat = 0;
|
||||
val->nstr = 0;
|
||||
val->val.len = len;
|
||||
val->val.ptr = (qse_uint8_t*)(val + 1);
|
||||
QSE_MEMCPY (val->val.ptr, ptr, xlen);
|
||||
val->val.ptr[xlen] = 0;
|
||||
|
||||
return (qse_awk_val_t*)val;
|
||||
}
|
||||
|
||||
qse_awk_val_t* qse_awk_rtx_makerexval (qse_awk_rtx_t* rtx, const qse_cstr_t* str, void* code[2])
|
||||
{
|
||||
qse_awk_val_rex_t* val;
|
||||
qse_size_t totsz;
|
||||
@ -1590,6 +1600,20 @@ int qse_awk_rtx_valtonum (
|
||||
);
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* TODO: */
|
||||
case QSE_AWK_VAL_BYTEARR:
|
||||
{
|
||||
return qse_awk_rtx_mbstonum (
|
||||
rtx,
|
||||
QSE_AWK_RTX_STRTONUM_MAKE_OPTION(0, 0),
|
||||
((qse_awk_val_bytearr_t*)v)->val.ptr,
|
||||
((qse_awk_val_bytearr_t*)v)->val.len,
|
||||
l, r
|
||||
);
|
||||
}
|
||||
#endif
|
||||
|
||||
case QSE_AWK_VAL_MAP:
|
||||
{
|
||||
if (rtx->awk->opt.trait & QSE_AWK_FLEXMAP)
|
||||
|
Loading…
Reference in New Issue
Block a user