trying to implement byte array in awk

This commit is contained in:
hyung-hwan 2019-04-14 16:17:12 +00:00
parent 1a16fd8888
commit 5e0754e607
4 changed files with 277 additions and 147 deletions

View File

@ -133,14 +133,14 @@ typedef qse_floc_t qse_awk_loc_t;
*/ */
/* /*
#define QSE_AWK_VAL_HDR \ #define QSE_AWK_VAL_HDR \
unsigned int type: 3; \ unsigned int type: 4; \
unsigned int ref: 26; \ unsigned int ref: 25; \
unsigned int stat: 1; \ unsigned int stat: 1; \
unsigned int nstr: 2 unsigned int nstr: 2
*/ */
#define QSE_AWK_VAL_HDR \ #define QSE_AWK_VAL_HDR \
qse_uintptr_t v_type: 3; \ qse_uintptr_t v_type: 4; \
qse_uintptr_t ref: ((QSE_SIZEOF_UINTPTR_T * 8) - 6); \ qse_uintptr_t ref: ((QSE_SIZEOF_UINTPTR_T * 8) - 7); \
qse_uintptr_t stat: 1; \ qse_uintptr_t stat: 1; \
qse_uintptr_t nstr: 2 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; 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 * The qse_awk_val_rex_t type is a regular expression type. The type field
* is #QSE_AWK_VAL_REX. * 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 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 * must be synchronized with an internal table of the __cmp_val
* function in run.c */ * function in run.c */
QSE_AWK_VAL_NIL = 0, /**< nil */ QSE_AWK_VAL_NIL = 0, /**< nil */
QSE_AWK_VAL_INT = 1, /**< integer */ QSE_AWK_VAL_INT = 1, /**< integer */
QSE_AWK_VAL_FLT = 2, /**< floating-pointer number */ QSE_AWK_VAL_FLT = 2, /**< floating-pointer number */
QSE_AWK_VAL_STR = 3, /**< string */ 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_REX = 6, /**< regular expression */
QSE_AWK_VAL_REF = 6, /**< reference to other types */ QSE_AWK_VAL_REF = 7, /**< reference to other types */
QSE_AWK_VAL_FUN = 7 QSE_AWK_VAL_FUN = 8
}; };
typedef enum qse_awk_val_type_t qse_awk_val_type_t; 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 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. * The qse_awk_rtx_makerexval() function creates a regular expression value.
* \return value on success, #QSE_NULL on failure * \return value on success, #QSE_NULL on failure

View File

@ -754,6 +754,18 @@ typedef struct qse_wcstr_t qse_wcstr_t;
typedef qse_wcstr_t qse_cstr_t; typedef qse_wcstr_t qse_cstr_t;
#endif #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. * The qse_xptl_t type defines a pair type of a pointer and a length.
*/ */

View File

@ -26,6 +26,7 @@
#include "awk-prv.h" #include "awk-prv.h"
#include <qse/cmn/fmt.h> #include <qse/cmn/fmt.h>
#include <qse/cmn/mbwc.h>
#ifdef DEBUG_RUN #ifdef DEBUG_RUN
#include <qse/cmn/sio.h> #include <qse/cmn/sio.h>
@ -4158,52 +4159,50 @@ static qse_awk_val_t* eval_binop_band (
return qse_awk_rtx_makeintval (rtx, l1 & l2); return qse_awk_rtx_makeintval (rtx, l1 & l2);
} }
static QSE_INLINE int __cmp_nil_nil ( static QSE_INLINE int __cmp_nil_nil (qse_awk_rtx_t* rtx, 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)
{ {
return 0; return 0;
} }
static QSE_INLINE 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_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
{ {
qse_awk_int_t v = QSE_AWK_RTX_GETINTFROMVAL (rtx, right); qse_awk_int_t v = QSE_AWK_RTX_GETINTFROMVAL (rtx, right);
return (v < 0)? 1: ((v > 0)? -1: 0); return (v < 0)? 1: ((v > 0)? -1: 0);
} }
static QSE_INLINE int __cmp_nil_flt ( static QSE_INLINE int __cmp_nil_flt (qse_awk_rtx_t* rtx, 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)
{ {
if (((qse_awk_val_flt_t*)right)->val < 0) return 1; if (((qse_awk_val_flt_t*)right)->val < 0) return 1;
if (((qse_awk_val_flt_t*)right)->val > 0) return -1; if (((qse_awk_val_flt_t*)right)->val > 0) return -1;
return 0; return 0;
} }
static QSE_INLINE int __cmp_nil_str ( static QSE_INLINE int __cmp_nil_str (qse_awk_rtx_t* rtx, 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)
{ {
return (((qse_awk_val_str_t*)right)->val.len == 0)? 0: -1; return (((qse_awk_val_str_t*)right)->val.len == 0)? 0: -1;
} }
static QSE_INLINE int __cmp_nil_map ( static QSE_INLINE int __cmp_nil_bytearr (qse_awk_rtx_t* rtx, 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) {
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; return (QSE_HTB_SIZE(((qse_awk_val_map_t*)right)->map) == 0)? 0: -1;
} }
static QSE_INLINE int __cmp_int_nil ( static QSE_INLINE int __cmp_int_nil (qse_awk_rtx_t* rtx, 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 v = QSE_AWK_RTX_GETINTFROMVAL (rtx, left); qse_awk_int_t v = QSE_AWK_RTX_GETINTFROMVAL(rtx, left);
return (v > 0)? 1: ((v < 0)? -1: 0); return (v > 0)? 1: ((v < 0)? -1: 0);
} }
static QSE_INLINE int __cmp_int_int ( static QSE_INLINE int __cmp_int_int (qse_awk_rtx_t* rtx, 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 v1 = QSE_AWK_RTX_GETINTFROMVAL (rtx, left); qse_awk_int_t v1 = QSE_AWK_RTX_GETINTFROMVAL(rtx, left);
qse_awk_int_t v2 = QSE_AWK_RTX_GETINTFROMVAL (rtx, right); qse_awk_int_t v2 = QSE_AWK_RTX_GETINTFROMVAL(rtx, right);
return (v1 > v2)? 1: ((v1 < v2)? -1: 0); return (v1 > v2)? 1: ((v1 < v2)? -1: 0);
} }
@ -4216,8 +4215,7 @@ static QSE_INLINE int __cmp_int_flt (
return 0; return 0;
} }
static QSE_INLINE 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_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
{ {
qse_awk_rtx_valtostr_out_t out; qse_awk_rtx_valtostr_out_t out;
int n; int n;
@ -4250,11 +4248,11 @@ static QSE_INLINE int __cmp_int_str (
} }
out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP; out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP;
if (qse_awk_rtx_valtostr (rtx, left, &out) <= -1) return CMP_ERROR; if (qse_awk_rtx_valtostr(rtx, left, &out) <= -1) return CMP_ERROR;
if (rtx->gbl.ignorecase) if (rtx->gbl.ignorecase)
{ {
n = qse_strxncasecmp ( n = qse_strxncasecmp(
out.u.cpldup.ptr, out.u.cpldup.ptr,
out.u.cpldup.len, out.u.cpldup.len,
((qse_awk_val_str_t*)right)->val.ptr, ((qse_awk_val_str_t*)right)->val.ptr,
@ -4263,7 +4261,7 @@ static QSE_INLINE int __cmp_int_str (
} }
else else
{ {
n = qse_strxncmp ( n = qse_strxncmp(
out.u.cpldup.ptr, out.u.cpldup.ptr,
out.u.cpldup.len, out.u.cpldup.len,
((qse_awk_val_str_t*)right)->val.ptr, ((qse_awk_val_str_t*)right)->val.ptr,
@ -4275,26 +4273,31 @@ static QSE_INLINE int __cmp_int_str (
return n; return n;
} }
static QSE_INLINE int __cmp_int_map ( static QSE_INLINE int __cmp_int_bytearr (qse_awk_rtx_t* rtx, 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 v1 = QSE_AWK_RTX_GETINTFROMVAL (rtx, left); /* 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); 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;
if (v1 < v2) return -1; if (v1 < v2) return -1;
return 0; return 0;
} }
static QSE_INLINE int __cmp_flt_nil ( static QSE_INLINE int __cmp_flt_nil (qse_awk_rtx_t* rtx, 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)
{ {
if (((qse_awk_val_flt_t*)left)->val > 0) return 1; if (((qse_awk_val_flt_t*)left)->val > 0) return 1;
if (((qse_awk_val_flt_t*)left)->val < 0) return -1; if (((qse_awk_val_flt_t*)left)->val < 0) return -1;
return 0; return 0;
} }
static int __cmp_flt_int ( static int __cmp_flt_int (qse_awk_rtx_t* rtx, 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); qse_awk_int_t v2 = QSE_AWK_RTX_GETINTFROMVAL (rtx, right);
if (((qse_awk_val_flt_t*)left)->val > v2) return 1; if (((qse_awk_val_flt_t*)left)->val > v2) return 1;
@ -4302,8 +4305,7 @@ static int __cmp_flt_int (
return 0; return 0;
} }
static int __cmp_flt_flt ( static int __cmp_flt_flt (qse_awk_rtx_t* rtx, 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)
{ {
if (((qse_awk_val_flt_t*)left)->val > if (((qse_awk_val_flt_t*)left)->val >
((qse_awk_val_flt_t*)right)->val) return 1; ((qse_awk_val_flt_t*)right)->val) return 1;
@ -4312,8 +4314,7 @@ static int __cmp_flt_flt (
return 0; return 0;
} }
static int __cmp_flt_str ( static int __cmp_flt_str (qse_awk_rtx_t* rtx, 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_rtx_valtostr_out_t out; qse_awk_rtx_valtostr_out_t out;
int n; int n;
@ -4339,7 +4340,7 @@ static int __cmp_flt_str (
} }
out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP; out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP;
if (qse_awk_rtx_valtostr (rtx, left, &out) <= -1) return CMP_ERROR; if (qse_awk_rtx_valtostr(rtx, left, &out) <= -1) return CMP_ERROR;
if (rtx->gbl.ignorecase) if (rtx->gbl.ignorecase)
{ {
@ -4364,35 +4365,38 @@ static int __cmp_flt_str (
return n; return n;
} }
static QSE_INLINE int __cmp_flt_map ( static int __cmp_flt_bytearr (qse_awk_rtx_t* rtx, 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)
{ {
/* 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); 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;
if (((qse_awk_val_flt_t*)left)->val < v2) return -1; if (((qse_awk_val_flt_t*)left)->val < v2) return -1;
return 0; return 0;
} }
static QSE_INLINE int __cmp_str_nil ( static QSE_INLINE int __cmp_str_nil (qse_awk_rtx_t* rtx, 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)
{ {
return (((qse_awk_val_str_t*)left)->val.len == 0)? 0: 1; return (((qse_awk_val_str_t*)left)->val.len == 0)? 0: 1;
} }
static QSE_INLINE int __cmp_str_int ( static QSE_INLINE int __cmp_str_int (qse_awk_rtx_t* rtx, 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)
{ {
return -__cmp_int_str (rtx, right, left); return -__cmp_int_str(rtx, right, left);
} }
static QSE_INLINE int __cmp_str_flt ( static QSE_INLINE int __cmp_str_flt (qse_awk_rtx_t* rtx, 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)
{ {
return -__cmp_flt_str (rtx, right, left); return -__cmp_flt_str (rtx, right, left);
} }
static QSE_INLINE 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_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
{ {
qse_awk_val_str_t* ls, * rs; qse_awk_val_str_t* ls, * rs;
@ -4403,23 +4407,21 @@ static QSE_INLINE int __cmp_str_str (
{ {
/* both are definitely strings */ /* both are definitely strings */
return (rtx->gbl.ignorecase)? return (rtx->gbl.ignorecase)?
qse_strxncasecmp (ls->val.ptr, ls->val.len, rs->val.ptr, rs->val.len): qse_strxncasecmp(ls->val.ptr, ls->val.len, rs->val.ptr, rs->val.len):
qse_strxncmp (ls->val.ptr, ls->val.len, rs->val.ptr, rs->val.len); qse_strxncmp(ls->val.ptr, ls->val.len, rs->val.ptr, rs->val.len);
} }
if (ls->nstr == 1) if (ls->nstr == 1)
{ {
qse_awk_int_t ll; qse_awk_int_t ll;
ll = qse_awk_strxtoint ( ll = qse_awk_strxtoint(rtx->awk, ls->val.ptr, ls->val.len, 0, QSE_NULL);
rtx->awk, ls->val.ptr, ls->val.len, 0, QSE_NULL);
if (rs->nstr == 1) if (rs->nstr == 1)
{ {
qse_awk_int_t rr; qse_awk_int_t rr;
rr = qse_awk_strxtoint ( rr = qse_awk_strxtoint(rtx->awk, rs->val.ptr, rs->val.len, 0, QSE_NULL);
rtx->awk, rs->val.ptr, rs->val.len, 0, QSE_NULL);
return (ll > rr)? 1: return (ll > rr)? 1:
(ll < rr)? -1: 0; (ll < rr)? -1: 0;
@ -4430,8 +4432,7 @@ static QSE_INLINE int __cmp_str_str (
QSE_ASSERT (rs->nstr == 2); QSE_ASSERT (rs->nstr == 2);
rr = qse_awk_strxtoflt ( rr = qse_awk_strxtoflt(rtx->awk, rs->val.ptr, rs->val.len, QSE_NULL);
rtx->awk, rs->val.ptr, rs->val.len, QSE_NULL);
return (ll > rr)? 1: return (ll > rr)? 1:
(ll < rr)? -1: 0; (ll < rr)? -1: 0;
@ -4443,15 +4444,13 @@ static QSE_INLINE int __cmp_str_str (
QSE_ASSERT (ls->nstr == 2); QSE_ASSERT (ls->nstr == 2);
ll = qse_awk_strxtoflt ( ll = qse_awk_strxtoflt(rtx->awk, ls->val.ptr, ls->val.len, QSE_NULL);
rtx->awk, ls->val.ptr, ls->val.len, QSE_NULL);
if (rs->nstr == 1) if (rs->nstr == 1)
{ {
qse_awk_int_t rr; qse_awk_int_t rr;
rr = qse_awk_strxtoint ( rr = qse_awk_strxtoint(rtx->awk, rs->val.ptr, rs->val.len, 0, QSE_NULL);
rtx->awk, rs->val.ptr, rs->val.len, 0, QSE_NULL);
return (ll > rr)? 1: return (ll > rr)? 1:
(ll < rr)? -1: 0; (ll < rr)? -1: 0;
@ -4462,8 +4461,7 @@ static QSE_INLINE int __cmp_str_str (
QSE_ASSERT (rs->nstr == 2); QSE_ASSERT (rs->nstr == 2);
rr = qse_awk_strxtoflt ( rr = qse_awk_strxtoflt(rtx->awk, rs->val.ptr, rs->val.len, QSE_NULL);
rtx->awk, rs->val.ptr, rs->val.len, QSE_NULL);
return (ll > rr)? 1: return (ll > rr)? 1:
(ll < rr)? -1: 0; (ll < rr)? -1: 0;
@ -4471,50 +4469,116 @@ static QSE_INLINE int __cmp_str_str (
} }
} }
static QSE_INLINE int __cmp_str_map ( static QSE_INLINE int __cmp_str_bytearr (qse_awk_rtx_t* rtx, 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_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 */ /* can't compare a map with a string */
SETERR_COD (rtx, QSE_AWK_EOPERAND); SETERR_COD (rtx, QSE_AWK_EOPERAND);
return CMP_ERROR; 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 ( static QSE_INLINE int __cmp_bytearr_int (qse_awk_rtx_t* rtx, 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) {
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); return -__cmp_nil_map (rtx, right, left);
} }
static QSE_INLINE int __cmp_map_int ( static QSE_INLINE int __cmp_map_int (qse_awk_rtx_t* rtx, 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)
{ {
return -__cmp_int_map (rtx, right, left); return -__cmp_int_map (rtx, right, left);
} }
static QSE_INLINE int __cmp_map_flt ( static QSE_INLINE int __cmp_map_flt (qse_awk_rtx_t* rtx, 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)
{ {
return -__cmp_flt_map (rtx, right, left); return -__cmp_flt_map (rtx, right, left);
} }
static QSE_INLINE int __cmp_map_str ( static QSE_INLINE int __cmp_map_str (qse_awk_rtx_t* rtx, 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)
{ {
/* can't compare a map with a string */ /* can't compare a map with a string */
SETERR_COD (rtx, QSE_AWK_EOPERAND); SETERR_COD (rtx, QSE_AWK_EOPERAND);
return CMP_ERROR; return CMP_ERROR;
} }
static QSE_INLINE int __cmp_map_map ( static QSE_INLINE int __cmp_map_bytearr (qse_awk_rtx_t* rtx, 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) {
/* 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 */ /* can't compare a map with a map */
SETERR_COD (rtx, QSE_AWK_EOPERAND); SETERR_COD (rtx, QSE_AWK_EOPERAND);
return CMP_ERROR; return CMP_ERROR;
} }
static int __cmp_val ( static int __cmp_val(
qse_awk_rtx_t* rtx, 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_val_type_t lvtype, rvtype; qse_awk_val_type_t lvtype, rvtype;
@ -4524,11 +4588,12 @@ static int __cmp_val (
{ {
/* this table must be synchronized with /* this table must be synchronized with
* the QSE_AWK_VAL_XXX values in awk.h */ * 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_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_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_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_map, __cmp_str_nil, __cmp_str_int, __cmp_str_flt, __cmp_str_str, __cmp_str_bytearr, __cmp_str_map,
__cmp_map_nil, __cmp_map_int, __cmp_map_flt, __cmp_map_str, __cmp_map_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); lvtype = QSE_AWK_RTX_GETVALTYPE(rtx, left);
@ -4549,9 +4614,10 @@ static int __cmp_val (
* QSE_AWK_VAL_INT = 1 * QSE_AWK_VAL_INT = 1
* QSE_AWK_VAL_FLT = 2 * QSE_AWK_VAL_FLT = 2
* QSE_AWK_VAL_STR = 3 * 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) static int teq_val (qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* right)
@ -4562,8 +4628,8 @@ static int teq_val (qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* righ
if (left == right) n = 1; if (left == right) n = 1;
else else
{ {
lt = QSE_AWK_RTX_GETVALTYPE (rtx, left); lt = QSE_AWK_RTX_GETVALTYPE(rtx, left);
rt = QSE_AWK_RTX_GETVALTYPE (rtx, right); rt = QSE_AWK_RTX_GETVALTYPE(rtx, right);
if (lt != rt) n = 0; if (lt != rt) n = 0;
else else
@ -4575,13 +4641,11 @@ static int teq_val (qse_awk_rtx_t* rtx, qse_awk_val_t* left, qse_awk_val_t* righ
break; break;
case QSE_AWK_VAL_INT: case QSE_AWK_VAL_INT:
n = (QSE_AWK_RTX_GETINTFROMVAL (rtx, left) == n = (QSE_AWK_RTX_GETINTFROMVAL (rtx, left) == QSE_AWK_RTX_GETINTFROMVAL (rtx, right));
QSE_AWK_RTX_GETINTFROMVAL (rtx, right));
break; break;
case QSE_AWK_VAL_FLT: case QSE_AWK_VAL_FLT:
n = ((qse_awk_val_flt_t*)left)->val == n = ((qse_awk_val_flt_t*)left)->val == ((qse_awk_val_flt_t*)right)->val;
((qse_awk_val_flt_t*)right)->val;
break; break;
case QSE_AWK_VAL_STR: 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; ((qse_awk_val_str_t*)right)->val.len) == 0;
break; 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: default:
/* map-x and map-y are always different regardless of /* map-x and map-y are always different regardless of
* their contents. however, if they are pointing to the * their contents. however, if they are pointing to the
@ -4621,7 +4693,7 @@ static qse_awk_val_t* eval_binop_tne (
static qse_awk_val_t* eval_binop_eq ( static qse_awk_val_t* eval_binop_eq (
qse_awk_rtx_t* rtx, 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)
{ {
int n = __cmp_val (rtx, left, right); int n = __cmp_val(rtx, left, right);
if (n == CMP_ERROR) return QSE_NULL; if (n == CMP_ERROR) return QSE_NULL;
return (n == 0)? QSE_AWK_VAL_ONE: QSE_AWK_VAL_ZERO; return (n == 0)? QSE_AWK_VAL_ONE: QSE_AWK_VAL_ZERO;
} }
@ -4629,7 +4701,7 @@ static qse_awk_val_t* eval_binop_eq (
static qse_awk_val_t* eval_binop_ne ( static qse_awk_val_t* eval_binop_ne (
qse_awk_rtx_t* rtx, 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)
{ {
int n = __cmp_val (rtx, left, right); int n = __cmp_val(rtx, left, right);
if (n == CMP_ERROR) return QSE_NULL; if (n == CMP_ERROR) return QSE_NULL;
return (n != 0)? QSE_AWK_VAL_ONE: QSE_AWK_VAL_ZERO; return (n != 0)? QSE_AWK_VAL_ONE: QSE_AWK_VAL_ZERO;
} }
@ -4637,7 +4709,7 @@ static qse_awk_val_t* eval_binop_ne (
static qse_awk_val_t* eval_binop_gt ( static qse_awk_val_t* eval_binop_gt (
qse_awk_rtx_t* rtx, 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)
{ {
int n = __cmp_val (rtx, left, right); int n = __cmp_val(rtx, left, right);
if (n == CMP_ERROR) return QSE_NULL; if (n == CMP_ERROR) return QSE_NULL;
return (n > 0)? QSE_AWK_VAL_ONE: QSE_AWK_VAL_ZERO; return (n > 0)? QSE_AWK_VAL_ONE: QSE_AWK_VAL_ZERO;
} }
@ -4645,7 +4717,7 @@ static qse_awk_val_t* eval_binop_gt (
static qse_awk_val_t* eval_binop_ge ( static qse_awk_val_t* eval_binop_ge (
qse_awk_rtx_t* rtx, 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)
{ {
int n = __cmp_val (rtx, left, right); int n = __cmp_val(rtx, left, right);
if (n == CMP_ERROR) return QSE_NULL; if (n == CMP_ERROR) return QSE_NULL;
return (n >= 0)? QSE_AWK_VAL_ONE: QSE_AWK_VAL_ZERO; return (n >= 0)? QSE_AWK_VAL_ONE: QSE_AWK_VAL_ZERO;
} }
@ -4653,7 +4725,7 @@ static qse_awk_val_t* eval_binop_ge (
static qse_awk_val_t* eval_binop_lt ( static qse_awk_val_t* eval_binop_lt (
qse_awk_rtx_t* rtx, 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)
{ {
int n = __cmp_val (rtx, left, right); int n = __cmp_val(rtx, left, right);
if (n == CMP_ERROR) return QSE_NULL; if (n == CMP_ERROR) return QSE_NULL;
return (n < 0)? QSE_AWK_VAL_ONE: QSE_AWK_VAL_ZERO; return (n < 0)? QSE_AWK_VAL_ONE: QSE_AWK_VAL_ZERO;
} }
@ -4661,7 +4733,7 @@ static qse_awk_val_t* eval_binop_lt (
static qse_awk_val_t* eval_binop_le ( static qse_awk_val_t* eval_binop_le (
qse_awk_rtx_t* rtx, 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)
{ {
int n = __cmp_val (rtx, left, right); int n = __cmp_val(rtx, left, right);
if (n == CMP_ERROR) return QSE_NULL; if (n == CMP_ERROR) return QSE_NULL;
return (n <= 0)? QSE_AWK_VAL_ONE: QSE_AWK_VAL_ZERO; return (n <= 0)? QSE_AWK_VAL_ONE: QSE_AWK_VAL_ZERO;
} }
@ -4671,14 +4743,14 @@ static qse_awk_val_t* eval_binop_lshift (
{ {
qse_awk_int_t l1, l2; qse_awk_int_t l1, l2;
if (qse_awk_rtx_valtoint (rtx, left, &l1) <= -1 || if (qse_awk_rtx_valtoint(rtx, left, &l1) <= -1 ||
qse_awk_rtx_valtoint (rtx, right, &l2) <= -1) qse_awk_rtx_valtoint(rtx, right, &l2) <= -1)
{ {
SETERR_COD (rtx, QSE_AWK_EOPERAND); SETERR_COD (rtx, QSE_AWK_EOPERAND);
return QSE_NULL; return QSE_NULL;
} }
return qse_awk_rtx_makeintval (rtx, l1 << l2); return qse_awk_rtx_makeintval(rtx, l1 << l2);
} }
static qse_awk_val_t* eval_binop_rshift ( static qse_awk_val_t* eval_binop_rshift (
@ -4686,8 +4758,8 @@ static qse_awk_val_t* eval_binop_rshift (
{ {
qse_awk_int_t l1, l2; qse_awk_int_t l1, l2;
if (qse_awk_rtx_valtoint (rtx, left, &l1) <= -1 || if (qse_awk_rtx_valtoint(rtx, left, &l1) <= -1 ||
qse_awk_rtx_valtoint (rtx, right, &l2) <= -1) qse_awk_rtx_valtoint(rtx, right, &l2) <= -1)
{ {
SETERR_COD (rtx, QSE_AWK_EOPERAND); SETERR_COD (rtx, QSE_AWK_EOPERAND);
return QSE_NULL; return QSE_NULL;
@ -4703,8 +4775,8 @@ static qse_awk_val_t* eval_binop_plus (
qse_awk_int_t l1, l2; qse_awk_int_t l1, l2;
qse_awk_flt_t r1, r2; qse_awk_flt_t r1, r2;
n1 = qse_awk_rtx_valtonum (rtx, left, &l1, &r1); n1 = qse_awk_rtx_valtonum(rtx, left, &l1, &r1);
n2 = qse_awk_rtx_valtonum (rtx, right, &l2, &r2); n2 = qse_awk_rtx_valtonum(rtx, right, &l2, &r2);
if (n1 <= -1 || n2 <= -1) if (n1 <= -1 || n2 <= -1)
{ {
@ -4734,8 +4806,8 @@ static qse_awk_val_t* eval_binop_minus (
qse_awk_int_t l1, l2; qse_awk_int_t l1, l2;
qse_awk_flt_t r1, r2; qse_awk_flt_t r1, r2;
n1 = qse_awk_rtx_valtonum (rtx, left, &l1, &r1); n1 = qse_awk_rtx_valtonum(rtx, left, &l1, &r1);
n2 = qse_awk_rtx_valtonum (rtx, right, &l2, &r2); n2 = qse_awk_rtx_valtonum(rtx, right, &l2, &r2);
if (n1 <= -1 || n2 <= -1) if (n1 <= -1 || n2 <= -1)
{ {

View File

@ -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; return (qse_awk_val_t*)val;
} }
qse_awk_val_t* qse_awk_rtx_makestrvalwithxstr ( qse_awk_val_t* qse_awk_rtx_makestrvalwithxstr (qse_awk_rtx_t* rtx, const qse_cstr_t* str)
qse_awk_rtx_t* rtx, const qse_cstr_t* str)
{ {
qse_awk_val_str_t* val = QSE_NULL; qse_awk_val_str_t* val = QSE_NULL;
qse_size_t rlen = str->len; qse_size_t rlen = str->len;
@ -195,10 +194,7 @@ qse_awk_val_t* qse_awk_rtx_makestrvalwithxstr (
} }
#endif #endif
val = (qse_awk_val_str_t*) QSE_AWK_ALLOC ( 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));
rtx->awk,
QSE_SIZEOF(qse_awk_val_str_t) +
(rlen + 1) * QSE_SIZEOF(qse_char_t));
if (val == QSE_NULL) if (val == QSE_NULL)
{ {
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL); qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL);
@ -222,16 +218,15 @@ init:
return (qse_awk_val_t*)val; return (qse_awk_val_t*)val;
} }
qse_awk_val_t* qse_awk_rtx_makestrvalwithmbs ( qse_awk_val_t* qse_awk_rtx_makestrvalwithmbs (qse_awk_rtx_t* rtx, const qse_mchar_t* mbs)
qse_awk_rtx_t* rtx, const qse_mchar_t* mbs)
{ {
#if defined(QSE_CHAR_IS_MCHAR) #if defined(QSE_CHAR_IS_MCHAR)
return qse_awk_rtx_makestrval (rtx, mbs, qse_mbslen(mbs)); return qse_awk_rtx_makestrval(rtx, mbs, qse_mbslen(mbs));
#else #else
qse_awk_val_t* v; qse_awk_val_t* v;
qse_wcstr_t tmp; qse_wcstr_t tmp;
tmp.ptr = qse_mbstowcsdup (mbs, &tmp.len, rtx->awk->mmgr); tmp.ptr = qse_mbstowcsdup(mbs, &tmp.len, rtx->awk->mmgr);
if (tmp.ptr == QSE_NULL) if (tmp.ptr == QSE_NULL)
{ {
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL); qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL);
@ -244,8 +239,7 @@ qse_awk_val_t* qse_awk_rtx_makestrvalwithmbs (
#endif #endif
} }
qse_awk_val_t* qse_awk_rtx_makestrvalwithwcs ( qse_awk_val_t* qse_awk_rtx_makestrvalwithwcs (qse_awk_rtx_t* rtx, const qse_wchar_t* wcs)
qse_awk_rtx_t* rtx, const qse_wchar_t* wcs)
{ {
#if defined(QSE_CHAR_IS_MCHAR) #if defined(QSE_CHAR_IS_MCHAR)
qse_awk_val_t* v; qse_awk_val_t* v;
@ -266,38 +260,35 @@ qse_awk_val_t* qse_awk_rtx_makestrvalwithwcs (
#endif #endif
} }
qse_awk_val_t* qse_awk_rtx_makestrvalwithstr ( qse_awk_val_t* qse_awk_rtx_makestrvalwithstr (qse_awk_rtx_t* rtx, const qse_char_t* str)
qse_awk_rtx_t* rtx, const qse_char_t* str)
{ {
return qse_awk_rtx_makestrval (rtx, str, qse_strlen(str)); return qse_awk_rtx_makestrval (rtx, str, qse_strlen(str));
} }
qse_awk_val_t* qse_awk_rtx_makestrvalwithmxstr ( qse_awk_val_t* qse_awk_rtx_makestrvalwithmxstr (qse_awk_rtx_t* rtx, const qse_mcstr_t* mxstr)
qse_awk_rtx_t* rtx, const qse_mcstr_t* mxstr)
{ {
#if defined(QSE_CHAR_IS_MCHAR) #if defined(QSE_CHAR_IS_MCHAR)
return qse_awk_rtx_makestrvalwithxstr (rtx, mxstr); return qse_awk_rtx_makestrvalwithxstr(rtx, mxstr);
#else #else
qse_awk_val_t* v; qse_awk_val_t* v;
qse_wcstr_t tmp; qse_wcstr_t tmp;
qse_size_t mbslen; qse_size_t mbslen;
mbslen = mxstr->len; mbslen = mxstr->len;
tmp.ptr = qse_mbsntowcsdup (mxstr->ptr, &mbslen, &tmp.len, rtx->awk->mmgr); tmp.ptr = qse_mbsntowcsdup(mxstr->ptr, &mbslen, &tmp.len, rtx->awk->mmgr);
if (tmp.ptr == QSE_NULL) if (tmp.ptr == QSE_NULL)
{ {
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL); qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
v = qse_awk_rtx_makestrvalwithxstr (rtx, &tmp); v = qse_awk_rtx_makestrvalwithxstr(rtx, &tmp);
QSE_AWK_FREE (rtx->awk, tmp.ptr); QSE_AWK_FREE (rtx->awk, tmp.ptr);
return v; return v;
#endif #endif
} }
qse_awk_val_t* qse_awk_rtx_makestrvalwithwxstr ( qse_awk_val_t* qse_awk_rtx_makestrvalwithwxstr (qse_awk_rtx_t* rtx, const qse_wcstr_t* wxstr)
qse_awk_rtx_t* rtx, const qse_wcstr_t* wxstr)
{ {
#if defined(QSE_CHAR_IS_MCHAR) #if defined(QSE_CHAR_IS_MCHAR)
qse_awk_val_t* v; qse_awk_val_t* v;
@ -305,34 +296,30 @@ qse_awk_val_t* qse_awk_rtx_makestrvalwithwxstr (
qse_size_t wcslen; qse_size_t wcslen;
wcslen = wxstr->len; wcslen = wxstr->len;
tmp.ptr = qse_wcsntombsdup (wxstr->ptr, &wcslen, &tmp.len, rtx->awk->mmgr); tmp.ptr = qse_wcsntombsdup(wxstr->ptr, &wcslen, &tmp.len, rtx->awk->mmgr);
if (tmp.ptr == QSE_NULL) if (tmp.ptr == QSE_NULL)
{ {
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL); qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
v = qse_awk_rtx_makestrvalwithxstr (rtx, &tmp); v = qse_awk_rtx_makestrvalwithxstr(rtx, &tmp);
QSE_AWK_FREE (rtx->awk, tmp.ptr); QSE_AWK_FREE (rtx->awk, tmp.ptr);
return v; return v;
#else #else
return qse_awk_rtx_makestrvalwithxstr (rtx, wxstr); return qse_awk_rtx_makestrvalwithxstr(rtx, wxstr);
#endif #endif
} }
qse_awk_val_t* qse_awk_rtx_makestrval ( qse_awk_val_t* qse_awk_rtx_makestrval (qse_awk_rtx_t* rtx, const qse_char_t* str, qse_size_t len)
qse_awk_rtx_t* rtx, const qse_char_t* str, qse_size_t len)
{ {
qse_cstr_t xstr; qse_cstr_t xstr;
xstr.ptr = (qse_char_t*)str; xstr.ptr = (qse_char_t*)str;
xstr.len = len; xstr.len = len;
return qse_awk_rtx_makestrvalwithxstr (rtx, &xstr); return qse_awk_rtx_makestrvalwithxstr(rtx, &xstr);
} }
qse_awk_val_t* qse_awk_rtx_makestrval2 ( 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_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_awk_val_str_t* val;
qse_size_t rlen = len1 + len2; 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; return v;
} }
qse_awk_val_t* qse_awk_rtx_makerexval ( qse_awk_val_t* qse_awk_rtx_makebytearrval (qse_awk_rtx_t* rtx, const qse_uint8_t* ptr, qse_size_t len)
qse_awk_rtx_t* rtx, const qse_cstr_t* str, void* code[2]) {
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_awk_val_rex_t* val;
qse_size_t totsz; qse_size_t totsz;
@ -1416,7 +1426,7 @@ qse_char_t* qse_awk_rtx_valtostrdup (
qse_awk_rtx_valtostr_out_t out; qse_awk_rtx_valtostr_out_t out;
out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP; out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP;
if (qse_awk_rtx_valtostr (rtx, v, &out) <= -1) return QSE_NULL; if (qse_awk_rtx_valtostr(rtx, v, &out) <= -1) return QSE_NULL;
if (len) *len = out.u.cpldup.len; if (len) *len = out.u.cpldup.len;
return out.u.cpldup.ptr; return out.u.cpldup.ptr;
@ -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: case QSE_AWK_VAL_MAP:
{ {
if (rtx->awk->opt.trait & QSE_AWK_FLEXMAP) if (rtx->awk->opt.trait & QSE_AWK_FLEXMAP)