added qse_awk_rtx_getvaltype() and qse_awk_rtx_getintfromval() macros
This commit is contained in:
parent
4de030f8a3
commit
fe1ff5cdba
@ -135,7 +135,7 @@ typedef struct qse_awk_loc_t qse_awk_loc_t;
|
|||||||
unsigned int nstr: 2
|
unsigned int nstr: 2
|
||||||
*/
|
*/
|
||||||
#define QSE_AWK_VAL_HDR \
|
#define QSE_AWK_VAL_HDR \
|
||||||
qse_uintptr_t type: 3; \
|
qse_uintptr_t v_type: 3; \
|
||||||
qse_uintptr_t ref: ((QSE_SIZEOF_UINTPTR_T * 8) - 6); \
|
qse_uintptr_t ref: ((QSE_SIZEOF_UINTPTR_T * 8) - 6); \
|
||||||
qse_uintptr_t stat: 1; \
|
qse_uintptr_t stat: 1; \
|
||||||
qse_uintptr_t nstr: 2
|
qse_uintptr_t nstr: 2
|
||||||
@ -169,7 +169,7 @@ typedef struct qse_awk_val_nil_t qse_awk_val_nil_t;
|
|||||||
struct qse_awk_val_int_t
|
struct qse_awk_val_int_t
|
||||||
{
|
{
|
||||||
QSE_AWK_VAL_HDR;
|
QSE_AWK_VAL_HDR;
|
||||||
qse_awk_int_t val;
|
qse_awk_int_t i_val;
|
||||||
void* nde;
|
void* nde;
|
||||||
};
|
};
|
||||||
typedef struct qse_awk_val_int_t qse_awk_val_int_t;
|
typedef struct qse_awk_val_int_t qse_awk_val_int_t;
|
||||||
@ -1389,6 +1389,7 @@ enum qse_awk_val_type_t
|
|||||||
QSE_AWK_VAL_REF = 6, /**< reference to other types */
|
QSE_AWK_VAL_REF = 6, /**< reference to other types */
|
||||||
QSE_AWK_VAL_FUN = 7
|
QSE_AWK_VAL_FUN = 7
|
||||||
};
|
};
|
||||||
|
typedef enum qse_awk_val_type_t qse_awk_val_type_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The values defined are used to set the type field of the
|
* The values defined are used to set the type field of the
|
||||||
@ -2552,6 +2553,10 @@ QSE_EXPORT void qse_awk_rtx_refdownval_nofree (
|
|||||||
qse_awk_val_t* val /**< value pointer */
|
qse_awk_val_t* val /**< value pointer */
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
#define qse_awk_rtx_getvaltype(rtx,v) ((v)->v_type)
|
||||||
|
#define qse_awk_rtx_getintfromval(rtx,v) (((qse_awk_val_int_t*)(v))->i_val)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The qse_awk_rtx_valtobool() function converts a value \a val to a boolean
|
* The qse_awk_rtx_valtobool() function converts a value \a val to a boolean
|
||||||
* value.
|
* value.
|
||||||
|
@ -455,9 +455,9 @@ int Awk::Value::getStr (const char_t** str, size_t* len) const
|
|||||||
|
|
||||||
QSE_ASSERT (this->val != QSE_NULL);
|
QSE_ASSERT (this->val != QSE_NULL);
|
||||||
|
|
||||||
if (this->run != QSE_NULL)
|
if (this->run)
|
||||||
{
|
{
|
||||||
if (this->val->type == QSE_AWK_VAL_STR)
|
if (qse_awk_rtx_getvaltype (this->run->rtx, this->val) == QSE_AWK_VAL_STR)
|
||||||
{
|
{
|
||||||
p = ((qse_awk_val_str_t*)this->val)->val.ptr;
|
p = ((qse_awk_val_str_t*)this->val)->val.ptr;
|
||||||
l = ((qse_awk_val_str_t*)this->val)->val.len;
|
l = ((qse_awk_val_str_t*)this->val)->val.len;
|
||||||
@ -643,7 +643,7 @@ int Awk::Value::setIndexedVal (Run* r, const Index& idx, val_t* v)
|
|||||||
{
|
{
|
||||||
QSE_ASSERT (r != QSE_NULL);
|
QSE_ASSERT (r != QSE_NULL);
|
||||||
|
|
||||||
if (val->type != QSE_AWK_VAL_MAP)
|
if (qse_awk_rtx_getvaltype (r->rtx, val) != QSE_AWK_VAL_MAP)
|
||||||
{
|
{
|
||||||
// the previous value is not a map.
|
// the previous value is not a map.
|
||||||
// a new map value needs to be created first.
|
// a new map value needs to be created first.
|
||||||
@ -803,7 +803,7 @@ int Awk::Value::setIndexedStr (Run* r, const Index& idx, const char_t* str, bool
|
|||||||
bool Awk::Value::isIndexed () const
|
bool Awk::Value::isIndexed () const
|
||||||
{
|
{
|
||||||
QSE_ASSERT (val != QSE_NULL);
|
QSE_ASSERT (val != QSE_NULL);
|
||||||
return val->type == QSE_AWK_VAL_MAP;
|
return qse_awk_rtx_getvaltype (this->run->rtx, val) == QSE_AWK_VAL_MAP;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Awk::Value::getIndexed (const Index& idx, Value* v) const
|
int Awk::Value::getIndexed (const Index& idx, Value* v) const
|
||||||
@ -811,7 +811,7 @@ int Awk::Value::getIndexed (const Index& idx, Value* v) const
|
|||||||
QSE_ASSERT (val != QSE_NULL);
|
QSE_ASSERT (val != QSE_NULL);
|
||||||
|
|
||||||
// not a map. v is just nil. not an error
|
// not a map. v is just nil. not an error
|
||||||
if (val->type != QSE_AWK_VAL_MAP)
|
if (qse_awk_rtx_getvaltype (this->run->rtx, val) != QSE_AWK_VAL_MAP)
|
||||||
{
|
{
|
||||||
v->clear ();
|
v->clear ();
|
||||||
return 0;
|
return 0;
|
||||||
@ -836,7 +836,7 @@ Awk::Value::IndexIterator Awk::Value::getFirstIndex (Index* idx) const
|
|||||||
{
|
{
|
||||||
QSE_ASSERT (this->val != QSE_NULL);
|
QSE_ASSERT (this->val != QSE_NULL);
|
||||||
|
|
||||||
if (this->val->type != QSE_AWK_VAL_MAP) return IndexIterator::END;
|
if (qse_awk_rtx_getvaltype (this->run->rtx, this->val) != QSE_AWK_VAL_MAP) return IndexIterator::END;
|
||||||
|
|
||||||
QSE_ASSERT (this->run != QSE_NULL);
|
QSE_ASSERT (this->run != QSE_NULL);
|
||||||
|
|
||||||
@ -856,7 +856,7 @@ Awk::Value::IndexIterator Awk::Value::getNextIndex (
|
|||||||
{
|
{
|
||||||
QSE_ASSERT (val != QSE_NULL);
|
QSE_ASSERT (val != QSE_NULL);
|
||||||
|
|
||||||
if (val->type != QSE_AWK_VAL_MAP) return IndexIterator::END;
|
if (qse_awk_rtx_getvaltype (this->run->rtx, val) != QSE_AWK_VAL_MAP) return IndexIterator::END;
|
||||||
|
|
||||||
QSE_ASSERT (this->run != QSE_NULL);
|
QSE_ASSERT (this->run != QSE_NULL);
|
||||||
|
|
||||||
@ -1399,7 +1399,7 @@ int Awk::dispatch_function (Run* run, const fnc_info_t* fi)
|
|||||||
int xx;
|
int xx;
|
||||||
val_t* v = qse_awk_rtx_getarg (run->rtx, i);
|
val_t* v = qse_awk_rtx_getarg (run->rtx, i);
|
||||||
|
|
||||||
if (v->type == QSE_AWK_VAL_REF)
|
if (qse_awk_rtx_getvaltype (run->rtx, v) == QSE_AWK_VAL_REF)
|
||||||
{
|
{
|
||||||
qse_awk_val_ref_t* ref = (qse_awk_val_ref_t*)v;
|
qse_awk_val_ref_t* ref = (qse_awk_val_ref_t*)v;
|
||||||
|
|
||||||
@ -1470,7 +1470,7 @@ int Awk::dispatch_function (Run* run, const fnc_info_t* fi)
|
|||||||
"Do NOT change the run field from function handler");
|
"Do NOT change the run field from function handler");
|
||||||
|
|
||||||
val_t* v = qse_awk_rtx_getarg (run->rtx, i);
|
val_t* v = qse_awk_rtx_getarg (run->rtx, i);
|
||||||
if (v->type == QSE_AWK_VAL_REF)
|
if (qse_awk_rtx_getvaltype (run->rtx, v) == QSE_AWK_VAL_REF)
|
||||||
{
|
{
|
||||||
if (qse_awk_rtx_setrefval (run->rtx, (qse_awk_val_ref_t*)v, args[i].toVal()) <= -1)
|
if (qse_awk_rtx_setrefval (run->rtx, (qse_awk_val_ref_t*)v, args[i].toVal()) <= -1)
|
||||||
{
|
{
|
||||||
|
@ -843,7 +843,7 @@ int StdAwk::open_console_in (Console& io)
|
|||||||
*/
|
*/
|
||||||
argv = qse_awk_rtx_getgbl (rtx, this->gbl_argv);
|
argv = qse_awk_rtx_getgbl (rtx, this->gbl_argv);
|
||||||
QSE_ASSERT (argv != QSE_NULL);
|
QSE_ASSERT (argv != QSE_NULL);
|
||||||
QSE_ASSERT (argv->type == QSE_AWK_VAL_MAP);
|
QSE_ASSERT (qse_awk_rtx_getvaltype (rtx, argv) == QSE_AWK_VAL_MAP);
|
||||||
|
|
||||||
map = ((qse_awk_val_map_t*)argv)->map;
|
map = ((qse_awk_val_map_t*)argv)->map;
|
||||||
QSE_ASSERT (map != QSE_NULL);
|
QSE_ASSERT (map != QSE_NULL);
|
||||||
|
@ -434,8 +434,7 @@ static int index_or_rindex (qse_awk_rtx_t* rtx, int rindex)
|
|||||||
str1 = qse_awk_rtx_getvalstr (rtx, a1, &len1);
|
str1 = qse_awk_rtx_getvalstr (rtx, a1, &len1);
|
||||||
if (str1 == QSE_NULL)
|
if (str1 == QSE_NULL)
|
||||||
{
|
{
|
||||||
if (a0->type != QSE_AWK_VAL_STR)
|
qse_awk_rtx_freevalstr (rtx, a0, str0);
|
||||||
qse_awk_rtx_freevalstr (rtx, a0, str0);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -494,6 +493,7 @@ int qse_awk_fnc_length (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
|||||||
{
|
{
|
||||||
qse_size_t nargs;
|
qse_size_t nargs;
|
||||||
qse_awk_val_t* v;
|
qse_awk_val_t* v;
|
||||||
|
qse_awk_val_type_t vtype;
|
||||||
qse_char_t* str;
|
qse_char_t* str;
|
||||||
qse_size_t len;
|
qse_size_t len;
|
||||||
|
|
||||||
@ -508,12 +508,14 @@ int qse_awk_fnc_length (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
v = qse_awk_rtx_getarg (rtx, 0);
|
v = qse_awk_rtx_getarg (rtx, 0);
|
||||||
if (v->type == QSE_AWK_VAL_MAP)
|
vtype = qse_awk_rtx_getvaltype (rtx, v);
|
||||||
|
|
||||||
|
if (vtype == QSE_AWK_VAL_MAP)
|
||||||
{
|
{
|
||||||
/* map size */
|
/* map size */
|
||||||
len = QSE_HTB_SIZE(((qse_awk_val_map_t*)v)->map);
|
len = QSE_HTB_SIZE(((qse_awk_val_map_t*)v)->map);
|
||||||
}
|
}
|
||||||
else if (v->type == QSE_AWK_VAL_STR)
|
else if (vtype == QSE_AWK_VAL_STR)
|
||||||
{
|
{
|
||||||
/* string length */
|
/* string length */
|
||||||
len = ((qse_awk_val_str_t*)v)->val.len;
|
len = ((qse_awk_val_str_t*)v)->val.len;
|
||||||
@ -597,9 +599,11 @@ int qse_awk_fnc_split (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
|||||||
{
|
{
|
||||||
qse_size_t nargs;
|
qse_size_t nargs;
|
||||||
qse_awk_val_t* a0, * a1, * a2, * t1, * t2;
|
qse_awk_val_t* a0, * a1, * a2, * t1, * t2;
|
||||||
|
qse_awk_val_type_t a1_vtype, a2_vtype, t1_vtype;
|
||||||
|
|
||||||
qse_cstr_t str, fs;
|
qse_cstr_t str = { QSE_NULL, 0 };
|
||||||
qse_char_t* str_free = QSE_NULL, * fs_free = QSE_NULL;
|
qse_cstr_t fs;
|
||||||
|
qse_char_t* fs_free = QSE_NULL;
|
||||||
const qse_char_t* p;
|
const qse_char_t* p;
|
||||||
qse_size_t str_left, org_len;
|
qse_size_t str_left, org_len;
|
||||||
void* fs_rex = QSE_NULL;
|
void* fs_rex = QSE_NULL;
|
||||||
@ -618,8 +622,11 @@ int qse_awk_fnc_split (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
|||||||
a1 = qse_awk_rtx_getarg (rtx, 1);
|
a1 = qse_awk_rtx_getarg (rtx, 1);
|
||||||
a2 = (nargs >= 3)? qse_awk_rtx_getarg (rtx, 2): QSE_NULL;
|
a2 = (nargs >= 3)? qse_awk_rtx_getarg (rtx, 2): QSE_NULL;
|
||||||
|
|
||||||
QSE_ASSERT (a1->type == QSE_AWK_VAL_REF);
|
a1_vtype = qse_awk_rtx_getvaltype (rtx, a1);
|
||||||
|
|
||||||
|
QSE_ASSERT (a1_vtype == QSE_AWK_VAL_REF);
|
||||||
|
|
||||||
|
/*
|
||||||
if (a0->type == QSE_AWK_VAL_STR)
|
if (a0->type == QSE_AWK_VAL_STR)
|
||||||
{
|
{
|
||||||
str.ptr = ((qse_awk_val_str_t*)a0)->val.ptr;
|
str.ptr = ((qse_awk_val_str_t*)a0)->val.ptr;
|
||||||
@ -631,17 +638,21 @@ int qse_awk_fnc_split (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
|||||||
if (str.ptr == QSE_NULL) return -1;
|
if (str.ptr == QSE_NULL) return -1;
|
||||||
str_free = (qse_char_t*)str.ptr;
|
str_free = (qse_char_t*)str.ptr;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
str.ptr = qse_awk_rtx_getvalstr (rtx, a0, &str.len);
|
||||||
|
if (str.ptr == QSE_NULL) goto oops;
|
||||||
|
|
||||||
if (a2 == QSE_NULL)
|
if (a2 == QSE_NULL)
|
||||||
{
|
{
|
||||||
/* get the value from FS */
|
/* get the value from FS */
|
||||||
t1 = qse_awk_rtx_getgbl (rtx, QSE_AWK_GBL_FS);
|
t1 = qse_awk_rtx_getgbl (rtx, QSE_AWK_GBL_FS);
|
||||||
if (t1->type == QSE_AWK_VAL_NIL)
|
t1_vtype = qse_awk_rtx_getvaltype (rtx, t1);
|
||||||
|
if (t1_vtype == QSE_AWK_VAL_NIL)
|
||||||
{
|
{
|
||||||
fs.ptr = QSE_T(" ");
|
fs.ptr = QSE_T(" ");
|
||||||
fs.len = 1;
|
fs.len = 1;
|
||||||
}
|
}
|
||||||
else if (t1->type == QSE_AWK_VAL_STR)
|
else if (t1_vtype == QSE_AWK_VAL_STR)
|
||||||
{
|
{
|
||||||
fs.ptr = ((qse_awk_val_str_t*)t1)->val.ptr;
|
fs.ptr = ((qse_awk_val_str_t*)t1)->val.ptr;
|
||||||
fs.len = ((qse_awk_val_str_t*)t1)->val.len;
|
fs.len = ((qse_awk_val_str_t*)t1)->val.len;
|
||||||
@ -655,46 +666,51 @@ int qse_awk_fnc_split (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
|||||||
|
|
||||||
if (fs.len > 1) fs_rex = rtx->gbl.fs[rtx->gbl.ignorecase];
|
if (fs.len > 1) fs_rex = rtx->gbl.fs[rtx->gbl.ignorecase];
|
||||||
}
|
}
|
||||||
else if (a2->type == QSE_AWK_VAL_REX)
|
|
||||||
{
|
|
||||||
/* the third parameter is a regular expression */
|
|
||||||
fs_rex = ((qse_awk_val_rex_t*)a2)->code[rtx->gbl.ignorecase];
|
|
||||||
|
|
||||||
/* make the loop below to take fs_rex by
|
|
||||||
* setting fs_len greater than 1*/
|
|
||||||
fs.ptr = QSE_NULL;
|
|
||||||
fs.len = 2;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (a2->type == QSE_AWK_VAL_STR)
|
a2_vtype = qse_awk_rtx_getvaltype (rtx, a2);
|
||||||
|
|
||||||
|
if (a2_vtype == QSE_AWK_VAL_REX)
|
||||||
{
|
{
|
||||||
fs.ptr = ((qse_awk_val_str_t*)a2)->val.ptr;
|
/* the third parameter is a regular expression */
|
||||||
fs.len = ((qse_awk_val_str_t*)a2)->val.len;
|
fs_rex = ((qse_awk_val_rex_t*)a2)->code[rtx->gbl.ignorecase];
|
||||||
|
|
||||||
|
/* make the loop below to take fs_rex by
|
||||||
|
* setting fs_len greater than 1*/
|
||||||
|
fs.ptr = QSE_NULL;
|
||||||
|
fs.len = 2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fs.ptr = qse_awk_rtx_valtostrdup (rtx, a2, &fs.len);
|
if (a2_vtype == QSE_AWK_VAL_STR)
|
||||||
if (fs.ptr == QSE_NULL) goto oops;
|
|
||||||
fs_free = (qse_char_t*)fs.ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fs.len > 1)
|
|
||||||
{
|
|
||||||
int x;
|
|
||||||
|
|
||||||
if (rtx->gbl.ignorecase)
|
|
||||||
x = qse_awk_buildrex (rtx->awk, fs.ptr, fs.len, &errnum, QSE_NULL, &fs_rex);
|
|
||||||
else
|
|
||||||
x = qse_awk_buildrex (rtx->awk, fs.ptr, fs.len, &errnum, &fs_rex, QSE_NULL);
|
|
||||||
|
|
||||||
if (x <= -1)
|
|
||||||
{
|
{
|
||||||
qse_awk_rtx_seterrnum (rtx, errnum, QSE_NULL);
|
fs.ptr = ((qse_awk_val_str_t*)a2)->val.ptr;
|
||||||
goto oops;
|
fs.len = ((qse_awk_val_str_t*)a2)->val.len;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fs.ptr = qse_awk_rtx_valtostrdup (rtx, a2, &fs.len);
|
||||||
|
if (fs.ptr == QSE_NULL) goto oops;
|
||||||
|
fs_free = (qse_char_t*)fs.ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
fs_rex_free = fs_rex;
|
if (fs.len > 1)
|
||||||
|
{
|
||||||
|
int x;
|
||||||
|
|
||||||
|
if (rtx->gbl.ignorecase)
|
||||||
|
x = qse_awk_buildrex (rtx->awk, fs.ptr, fs.len, &errnum, QSE_NULL, &fs_rex);
|
||||||
|
else
|
||||||
|
x = qse_awk_buildrex (rtx->awk, fs.ptr, fs.len, &errnum, &fs_rex, QSE_NULL);
|
||||||
|
|
||||||
|
if (x <= -1)
|
||||||
|
{
|
||||||
|
qse_awk_rtx_seterrnum (rtx, errnum, QSE_NULL);
|
||||||
|
goto oops;
|
||||||
|
}
|
||||||
|
|
||||||
|
fs_rex_free = fs_rex;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -763,8 +779,11 @@ int qse_awk_fnc_split (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
|||||||
str.len = str_left - (p - str.ptr);
|
str.len = str_left - (p - str.ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str_free) QSE_AWK_FREE (rtx->awk, str_free);
|
/*if (str_free) QSE_AWK_FREE (rtx->awk, str_free);*/
|
||||||
|
qse_awk_rtx_freevalstr (rtx, a0, str.ptr);
|
||||||
|
|
||||||
if (fs_free) QSE_AWK_FREE (rtx->awk, fs_free);
|
if (fs_free) QSE_AWK_FREE (rtx->awk, fs_free);
|
||||||
|
|
||||||
if (fs_rex_free)
|
if (fs_rex_free)
|
||||||
{
|
{
|
||||||
if (rtx->gbl.ignorecase)
|
if (rtx->gbl.ignorecase)
|
||||||
@ -782,8 +801,11 @@ int qse_awk_fnc_split (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
oops:
|
oops:
|
||||||
if (str_free) QSE_AWK_FREE (rtx->awk, str_free);
|
/*if (str_free) QSE_AWK_FREE (rtx->awk, str_free);*/
|
||||||
|
if (str.ptr) qse_awk_rtx_freevalstr (rtx, a0, str.ptr);
|
||||||
|
|
||||||
if (fs_free) QSE_AWK_FREE (rtx->awk, fs_free);
|
if (fs_free) QSE_AWK_FREE (rtx->awk, fs_free);
|
||||||
|
|
||||||
if (fs_rex_free)
|
if (fs_rex_free)
|
||||||
{
|
{
|
||||||
if (rtx->gbl.ignorecase)
|
if (rtx->gbl.ignorecase)
|
||||||
@ -856,6 +878,7 @@ static int __substitute (qse_awk_rtx_t* run, qse_awk_int_t max_count)
|
|||||||
{
|
{
|
||||||
qse_size_t nargs;
|
qse_size_t nargs;
|
||||||
qse_awk_val_t* a0, * a1, * a2, * v;
|
qse_awk_val_t* a0, * a1, * a2, * v;
|
||||||
|
qse_awk_val_type_t a0_vtype, a1_vtype;
|
||||||
|
|
||||||
qse_cstr_t s0, s1, s2;
|
qse_cstr_t s0, s1, s2;
|
||||||
const qse_char_t* s2_end;
|
const qse_char_t* s2_end;
|
||||||
@ -881,13 +904,15 @@ static int __substitute (qse_awk_rtx_t* run, qse_awk_int_t max_count)
|
|||||||
a1 = qse_awk_rtx_getarg (run, 1);
|
a1 = qse_awk_rtx_getarg (run, 1);
|
||||||
a2 = (nargs >= 3)? qse_awk_rtx_getarg (run, 2): QSE_NULL;
|
a2 = (nargs >= 3)? qse_awk_rtx_getarg (run, 2): QSE_NULL;
|
||||||
|
|
||||||
QSE_ASSERT (a2 == QSE_NULL || a2->type == QSE_AWK_VAL_REF);
|
a0_vtype = qse_awk_rtx_getvaltype (rtx, a0);
|
||||||
|
a1_vtype = qse_awk_rtx_getvaltype (rtx, a1);
|
||||||
|
QSE_ASSERT (a2 == QSE_NULL || qse_awk_rtx_getvaltype(rtx, a2) == QSE_AWK_VAL_REF);
|
||||||
|
|
||||||
if (a0->type == QSE_AWK_VAL_REX)
|
if (a0_vtype == QSE_AWK_VAL_REX)
|
||||||
{
|
{
|
||||||
rex = ((qse_awk_val_rex_t*)a0)->code[run->gbl.ignorecase];
|
rex = ((qse_awk_val_rex_t*)a0)->code[run->gbl.ignorecase];
|
||||||
}
|
}
|
||||||
else if (a0->type == QSE_AWK_VAL_STR)
|
else if (a0_vtype == QSE_AWK_VAL_STR)
|
||||||
{
|
{
|
||||||
s0.ptr = ((qse_awk_val_str_t*)a0)->val.ptr;
|
s0.ptr = ((qse_awk_val_str_t*)a0)->val.ptr;
|
||||||
s0.len = ((qse_awk_val_str_t*)a0)->val.len;
|
s0.len = ((qse_awk_val_str_t*)a0)->val.len;
|
||||||
@ -899,7 +924,7 @@ static int __substitute (qse_awk_rtx_t* run, qse_awk_int_t max_count)
|
|||||||
s0_free = (qse_char_t*)s0.ptr;
|
s0_free = (qse_char_t*)s0.ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a1->type == QSE_AWK_VAL_STR)
|
if (a1_vtype == QSE_AWK_VAL_STR)
|
||||||
{
|
{
|
||||||
s1.ptr = ((qse_awk_val_str_t*)a1)->val.ptr;
|
s1.ptr = ((qse_awk_val_str_t*)a1)->val.ptr;
|
||||||
s1.len = ((qse_awk_val_str_t*)a1)->val.len;
|
s1.len = ((qse_awk_val_str_t*)a1)->val.len;
|
||||||
@ -931,7 +956,7 @@ static int __substitute (qse_awk_rtx_t* run, qse_awk_int_t max_count)
|
|||||||
}
|
}
|
||||||
new_inited = 1;
|
new_inited = 1;
|
||||||
|
|
||||||
if (a0->type != QSE_AWK_VAL_REX)
|
if (a0_vtype != QSE_AWK_VAL_REX)
|
||||||
{
|
{
|
||||||
qse_awk_errnum_t errnum;
|
qse_awk_errnum_t errnum;
|
||||||
int x;
|
int x;
|
||||||
|
@ -1298,7 +1298,7 @@ int qse_awk_rtx_matchrex (
|
|||||||
|
|
||||||
icase = rtx->gbl.ignorecase;
|
icase = rtx->gbl.ignorecase;
|
||||||
|
|
||||||
if (val->type == QSE_AWK_VAL_REX)
|
if (qse_awk_rtx_getvaltype (rtx, val) == QSE_AWK_VAL_REX)
|
||||||
{
|
{
|
||||||
code = ((qse_awk_val_rex_t*)val)->code[icase];
|
code = ((qse_awk_val_rex_t*)val)->code[icase];
|
||||||
}
|
}
|
||||||
@ -1335,7 +1335,7 @@ int qse_awk_rtx_matchrex (
|
|||||||
if (x <= -1) qse_awk_rtx_seterrnum (rtx, awkerr, QSE_NULL);
|
if (x <= -1) qse_awk_rtx_seterrnum (rtx, awkerr, QSE_NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (val->type == QSE_AWK_VAL_REX)
|
if (qse_awk_rtx_getvaltype(rtx, val) == QSE_AWK_VAL_REX)
|
||||||
{
|
{
|
||||||
/* nothing to free */
|
/* nothing to free */
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ int qse_awk_rtx_setrec (
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
QSE_ASSERT (run->inrec.d0->type == QSE_AWK_VAL_NIL);
|
QSE_ASSERT (qse_awk_rtx_getvaltype (run, run->inrec.d0) == QSE_AWK_VAL_NIL);
|
||||||
/* d0 should be cleared before the next line is reached
|
/* d0 should be cleared before the next line is reached
|
||||||
* as it doesn't call qse_awk_rtx_refdownval on run->inrec.d0 */
|
* as it doesn't call qse_awk_rtx_refdownval on run->inrec.d0 */
|
||||||
run->inrec.d0 = v;
|
run->inrec.d0 = v;
|
||||||
@ -98,23 +98,26 @@ static int split_record (qse_awk_rtx_t* rtx)
|
|||||||
qse_char_t* p, * px;
|
qse_char_t* p, * px;
|
||||||
qse_size_t len, nflds;
|
qse_size_t len, nflds;
|
||||||
qse_awk_val_t* v, * fs;
|
qse_awk_val_t* v, * fs;
|
||||||
|
qse_awk_val_type_t fsvtype;
|
||||||
qse_char_t* fs_ptr, * fs_free;
|
qse_char_t* fs_ptr, * fs_free;
|
||||||
qse_size_t fs_len;
|
qse_size_t fs_len;
|
||||||
qse_awk_errnum_t errnum;
|
qse_awk_errnum_t errnum;
|
||||||
int how;
|
int how;
|
||||||
|
|
||||||
|
|
||||||
/* inrec should be cleared before split_record is called */
|
/* inrec should be cleared before split_record is called */
|
||||||
QSE_ASSERT (rtx->inrec.nflds == 0);
|
QSE_ASSERT (rtx->inrec.nflds == 0);
|
||||||
|
|
||||||
/* get FS */
|
/* get FS */
|
||||||
fs = qse_awk_rtx_getgbl (rtx, QSE_AWK_GBL_FS);
|
fs = qse_awk_rtx_getgbl (rtx, QSE_AWK_GBL_FS);
|
||||||
if (fs->type == QSE_AWK_VAL_NIL)
|
fsvtype = qse_awk_rtx_getvaltype (rtx, fs);
|
||||||
|
if (fsvtype == QSE_AWK_VAL_NIL)
|
||||||
{
|
{
|
||||||
fs_ptr = QSE_T(" ");
|
fs_ptr = QSE_T(" ");
|
||||||
fs_len = 1;
|
fs_len = 1;
|
||||||
fs_free = QSE_NULL;
|
fs_free = QSE_NULL;
|
||||||
}
|
}
|
||||||
else if (fs->type == QSE_AWK_VAL_STR)
|
else if (fsvtype == QSE_AWK_VAL_STR)
|
||||||
{
|
{
|
||||||
fs_ptr = ((qse_awk_val_str_t*)fs)->val.ptr;
|
fs_ptr = ((qse_awk_val_str_t*)fs)->val.ptr;
|
||||||
fs_len = ((qse_awk_val_str_t*)fs)->val.len;
|
fs_len = ((qse_awk_val_str_t*)fs)->val.len;
|
||||||
@ -506,9 +509,9 @@ static int recomp_record_fields (
|
|||||||
}
|
}
|
||||||
|
|
||||||
v = qse_awk_rtx_getgbl (run, QSE_AWK_GBL_NF);
|
v = qse_awk_rtx_getgbl (run, QSE_AWK_GBL_NF);
|
||||||
QSE_ASSERT (v->type == QSE_AWK_VAL_INT);
|
QSE_ASSERT (qse_awk_rtx_getvaltype (rtx, v) == QSE_AWK_VAL_INT);
|
||||||
|
|
||||||
if (((qse_awk_val_int_t*)v)->val != max)
|
if (qse_awk_rtx_getintfromval (rtx, v)!= max)
|
||||||
{
|
{
|
||||||
v = qse_awk_rtx_makeintval (run, (qse_awk_int_t)max);
|
v = qse_awk_rtx_makeintval (run, (qse_awk_int_t)max);
|
||||||
if (v == QSE_NULL) return -1;
|
if (v == QSE_NULL) return -1;
|
||||||
|
@ -194,8 +194,12 @@ static QSE_INLINE int resolve_rs (
|
|||||||
qse_awk_rtx_t* rtx, qse_awk_val_t* rs, qse_cstr_t* rrs)
|
qse_awk_rtx_t* rtx, qse_awk_val_t* rs, qse_cstr_t* rrs)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
qse_awk_val_type_t rs_vtype;
|
||||||
|
|
||||||
switch (rs->type)
|
|
||||||
|
rs_vtype = qse_awk_rtx_getvaltype (rtx, rs);
|
||||||
|
|
||||||
|
switch (rs_vtype)
|
||||||
{
|
{
|
||||||
case QSE_AWK_VAL_NIL:
|
case QSE_AWK_VAL_NIL:
|
||||||
rrs->ptr = QSE_NULL;
|
rrs->ptr = QSE_NULL;
|
||||||
@ -623,7 +627,7 @@ int qse_awk_rtx_readio (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rrs.ptr && rs->type != QSE_AWK_VAL_STR)
|
if (rrs.ptr && qse_awk_rtx_getvaltype (rtx, rs) != QSE_AWK_VAL_STR)
|
||||||
QSE_AWK_FREE (run->awk, rrs.ptr);
|
QSE_AWK_FREE (run->awk, rrs.ptr);
|
||||||
qse_awk_rtx_refdownval (run, rs);
|
qse_awk_rtx_refdownval (run, rs);
|
||||||
|
|
||||||
@ -637,8 +641,12 @@ int qse_awk_rtx_writeio_val (
|
|||||||
qse_char_t* str;
|
qse_char_t* str;
|
||||||
qse_size_t len;
|
qse_size_t len;
|
||||||
int n;
|
int n;
|
||||||
|
qse_awk_val_type_t vtype;
|
||||||
|
|
||||||
if (v->type == QSE_AWK_VAL_STR)
|
|
||||||
|
vtype = qse_awk_rtx_getvaltype (run, v);
|
||||||
|
|
||||||
|
if (vtype == QSE_AWK_VAL_STR)
|
||||||
{
|
{
|
||||||
str = ((qse_awk_val_str_t*)v)->val.ptr;
|
str = ((qse_awk_val_str_t*)v)->val.ptr;
|
||||||
len = ((qse_awk_val_str_t*)v)->val.len;
|
len = ((qse_awk_val_str_t*)v)->val.len;
|
||||||
@ -657,7 +665,14 @@ int qse_awk_rtx_writeio_val (
|
|||||||
|
|
||||||
n = qse_awk_rtx_writeio_str (run, out_type, name, str, len);
|
n = qse_awk_rtx_writeio_str (run, out_type, name, str, len);
|
||||||
|
|
||||||
if (v->type != QSE_AWK_VAL_STR) QSE_AWK_FREE (run->awk, str);
|
if (vtype == QSE_AWK_VAL_STR)
|
||||||
|
{
|
||||||
|
/* nothing to free */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QSE_AWK_FREE (run->awk, str);
|
||||||
|
}
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -91,7 +91,7 @@ enum qse_awk_unrop_type_t
|
|||||||
QSE_AWK_UNROP_MINUS,
|
QSE_AWK_UNROP_MINUS,
|
||||||
QSE_AWK_UNROP_LNOT,
|
QSE_AWK_UNROP_LNOT,
|
||||||
QSE_AWK_UNROP_BNOT,
|
QSE_AWK_UNROP_BNOT,
|
||||||
QSE_AWK_UNROP_DEF /* : in the unary operation context */
|
QSE_AWK_UNROP_DEF /* `, is defined */
|
||||||
};
|
};
|
||||||
|
|
||||||
enum qse_awk_incop_type_t
|
enum qse_awk_incop_type_t
|
||||||
|
@ -1392,7 +1392,7 @@ static int open_rio_console (qse_awk_rtx_t* rtx, qse_awk_rio_arg_t* riod)
|
|||||||
*/
|
*/
|
||||||
argv = qse_awk_rtx_getgbl (rtx, xtn->gbl_argv);
|
argv = qse_awk_rtx_getgbl (rtx, xtn->gbl_argv);
|
||||||
QSE_ASSERT (argv != QSE_NULL);
|
QSE_ASSERT (argv != QSE_NULL);
|
||||||
QSE_ASSERT (argv->type == QSE_AWK_VAL_MAP);
|
QSE_ASSERT (qse_awk_rtx_getvaltype (rtx, argv) == QSE_AWK_VAL_MAP);
|
||||||
|
|
||||||
map = ((qse_awk_val_map_t*)argv)->map;
|
map = ((qse_awk_val_map_t*)argv)->map;
|
||||||
QSE_ASSERT (map != QSE_NULL);
|
QSE_ASSERT (map != QSE_NULL);
|
||||||
|
@ -71,7 +71,7 @@ qse_awk_val_t* qse_getawknilval (void)
|
|||||||
|
|
||||||
int qse_awk_rtx_isnilval (qse_awk_rtx_t* rtx, qse_awk_val_t* val)
|
int qse_awk_rtx_isnilval (qse_awk_rtx_t* rtx, qse_awk_val_t* val)
|
||||||
{
|
{
|
||||||
return val->type == QSE_AWK_VAL_NIL;
|
return val->v_type == QSE_AWK_VAL_NIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
qse_awk_val_t* qse_awk_rtx_makenilval (qse_awk_rtx_t* rtx)
|
qse_awk_val_t* qse_awk_rtx_makenilval (qse_awk_rtx_t* rtx)
|
||||||
@ -79,14 +79,50 @@ qse_awk_val_t* qse_awk_rtx_makenilval (qse_awk_rtx_t* rtx)
|
|||||||
return (qse_awk_val_t*)&awk_nil;
|
return (qse_awk_val_t*)&awk_nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define NUM_TYPE_BITS 2
|
||||||
|
#define TYPE_BITS_POINTER 0
|
||||||
|
#define TYPE_BITS_QUICKINT 1
|
||||||
|
#define TYPE_BITS_RESERVED_1 2
|
||||||
|
#define TYPE_BITS_RESERVED_2 3
|
||||||
|
#define SIGN_BIT ((qse_uintptr_t)1 << (QSE_SIZEOF(qse_uintptr_t) * 8 - 1))
|
||||||
|
|
||||||
|
/* shrink the bit range by 1 more bit to ease signbit handling.
|
||||||
|
* i want abs(max) == abs(min).
|
||||||
|
* i don't want abs(max) + 1 == abs(min). e.g min: -32768, max: 32767
|
||||||
|
*/
|
||||||
|
#define QUICKINT_MAX ((~(qse_uintptr_t)0) >> (NUM_TYPE_BITS + 1))
|
||||||
|
#define QUICKINT_MIN (-QUICKINT_MAX)
|
||||||
|
|
||||||
|
#define IS_QUICKINT(v) ((v) >= QUICKINT_MIN && (v) <= QUICKINT_MAX)
|
||||||
|
#define POINTER_TYPE_BITS(p) (((qse_uintptr_t)(p)) | NUM_TYPE_BITS)
|
||||||
|
|
||||||
|
static QSE_INLINE qse_awk_val_t* quickint_to_pointer (qse_awk_int_t v)
|
||||||
|
{
|
||||||
|
qse_uintptr_t r;
|
||||||
|
|
||||||
|
if (v < 0)
|
||||||
|
{
|
||||||
|
r = (((qse_uintptr_t)-v) << NUM_TYPE_BITS) | TYPE_BITS_QUICKINT | SIGN_BIT;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
r = ((qse_uintptr_t)v << NUM_TYPE_BITS) | TYPE_BITS_QUICKINT;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (qse_awk_val_t*)r;
|
||||||
|
}
|
||||||
|
|
||||||
qse_awk_val_t* qse_awk_rtx_makeintval (qse_awk_rtx_t* rtx, qse_awk_int_t v)
|
qse_awk_val_t* qse_awk_rtx_makeintval (qse_awk_rtx_t* rtx, qse_awk_int_t v)
|
||||||
{
|
{
|
||||||
qse_awk_val_int_t* val;
|
qse_awk_val_int_t* val;
|
||||||
|
|
||||||
if (v >= awk_int[0].val &&
|
// if (IS_QUICKINT(v)) return quickint_to_pinter (v);
|
||||||
v <= awk_int[QSE_COUNTOF(awk_int)-1].val)
|
|
||||||
|
if (v >= awk_int[0].i_val &&
|
||||||
|
v <= awk_int[QSE_COUNTOF(awk_int)-1].i_val)
|
||||||
{
|
{
|
||||||
return (qse_awk_val_t*)&awk_int[v-awk_int[0].val];
|
return (qse_awk_val_t*)&awk_int[v-awk_int[0].i_val];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rtx->vmgr.ifree == QSE_NULL)
|
if (rtx->vmgr.ifree == QSE_NULL)
|
||||||
@ -132,11 +168,11 @@ qse_awk_val_t* qse_awk_rtx_makeintval (qse_awk_rtx_t* rtx, qse_awk_int_t v)
|
|||||||
val = rtx->vmgr.ifree;
|
val = rtx->vmgr.ifree;
|
||||||
rtx->vmgr.ifree = (qse_awk_val_int_t*)val->nde;
|
rtx->vmgr.ifree = (qse_awk_val_int_t*)val->nde;
|
||||||
|
|
||||||
val->type = QSE_AWK_VAL_INT;
|
val->v_type = QSE_AWK_VAL_INT;
|
||||||
val->ref = 0;
|
val->ref = 0;
|
||||||
val->stat = 0;
|
val->stat = 0;
|
||||||
val->nstr = 0;
|
val->nstr = 0;
|
||||||
val->val = v;
|
val->i_val = v;
|
||||||
val->nde = QSE_NULL;
|
val->nde = QSE_NULL;
|
||||||
|
|
||||||
#ifdef DEBUG_VAL
|
#ifdef DEBUG_VAL
|
||||||
@ -188,7 +224,7 @@ qse_awk_val_t* qse_awk_rtx_makefltval (qse_awk_rtx_t* rtx, qse_awk_flt_t v)
|
|||||||
val = rtx->vmgr.rfree;
|
val = rtx->vmgr.rfree;
|
||||||
rtx->vmgr.rfree = (qse_awk_val_flt_t*)val->nde;
|
rtx->vmgr.rfree = (qse_awk_val_flt_t*)val->nde;
|
||||||
|
|
||||||
val->type = QSE_AWK_VAL_FLT;
|
val->v_type = QSE_AWK_VAL_FLT;
|
||||||
val->ref = 0;
|
val->ref = 0;
|
||||||
val->stat = 0;
|
val->stat = 0;
|
||||||
val->nstr = 0;
|
val->nstr = 0;
|
||||||
@ -235,7 +271,7 @@ qse_awk_val_t* qse_awk_rtx_makestrvalwithxstr (
|
|||||||
#ifdef ENABLE_FEATURE_SCACHE
|
#ifdef ENABLE_FEATURE_SCACHE
|
||||||
init:
|
init:
|
||||||
#endif
|
#endif
|
||||||
val->type = QSE_AWK_VAL_STR;
|
val->v_type = QSE_AWK_VAL_STR;
|
||||||
val->ref = 0;
|
val->ref = 0;
|
||||||
val->stat = 0;
|
val->stat = 0;
|
||||||
val->nstr = 0;
|
val->nstr = 0;
|
||||||
@ -392,7 +428,7 @@ qse_awk_val_t* qse_awk_rtx_makestrval2 (
|
|||||||
#ifdef ENABLE_FEATURE_SCACHE
|
#ifdef ENABLE_FEATURE_SCACHE
|
||||||
init:
|
init:
|
||||||
#endif
|
#endif
|
||||||
val->type = QSE_AWK_VAL_STR;
|
val->v_type = QSE_AWK_VAL_STR;
|
||||||
val->ref = 0;
|
val->ref = 0;
|
||||||
val->stat = 0;
|
val->stat = 0;
|
||||||
val->nstr = 0;
|
val->nstr = 0;
|
||||||
@ -457,7 +493,7 @@ qse_awk_val_t* qse_awk_rtx_makerexval (
|
|||||||
return QSE_NULL;
|
return QSE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
val->type = QSE_AWK_VAL_REX;
|
val->v_type = QSE_AWK_VAL_REX;
|
||||||
val->ref = 0;
|
val->ref = 0;
|
||||||
val->stat = 0;
|
val->stat = 0;
|
||||||
val->nstr = 0;
|
val->nstr = 0;
|
||||||
@ -554,7 +590,7 @@ qse_awk_val_t* qse_awk_rtx_makemapval (qse_awk_rtx_t* rtx)
|
|||||||
return QSE_NULL;
|
return QSE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
val->type = QSE_AWK_VAL_MAP;
|
val->v_type = QSE_AWK_VAL_MAP;
|
||||||
val->ref = 0;
|
val->ref = 0;
|
||||||
val->stat = 0;
|
val->stat = 0;
|
||||||
val->nstr = 0;
|
val->nstr = 0;
|
||||||
@ -643,7 +679,7 @@ qse_awk_val_t* qse_awk_rtx_setmapvalfld (
|
|||||||
qse_awk_rtx_t* rtx, qse_awk_val_t* map,
|
qse_awk_rtx_t* rtx, qse_awk_val_t* map,
|
||||||
const qse_char_t* kptr, qse_size_t klen, qse_awk_val_t* v)
|
const qse_char_t* kptr, qse_size_t klen, qse_awk_val_t* v)
|
||||||
{
|
{
|
||||||
QSE_ASSERT (map->type == QSE_AWK_VAL_MAP);
|
QSE_ASSERT (qse_awk_rtx_getvaltype (rtx, map) == QSE_AWK_VAL_MAP);
|
||||||
|
|
||||||
if (qse_htb_upsert (
|
if (qse_htb_upsert (
|
||||||
((qse_awk_val_map_t*)map)->map,
|
((qse_awk_val_map_t*)map)->map,
|
||||||
@ -668,7 +704,7 @@ qse_awk_val_t* qse_awk_rtx_getmapvalfld (
|
|||||||
{
|
{
|
||||||
qse_htb_pair_t* pair;
|
qse_htb_pair_t* pair;
|
||||||
|
|
||||||
QSE_ASSERT (map->type == QSE_AWK_VAL_MAP);
|
QSE_ASSERT (qse_awk_rtx_getvaltype (rtx, map) == QSE_AWK_VAL_MAP);
|
||||||
|
|
||||||
pair = qse_htb_search (((qse_awk_val_map_t*)map)->map, kptr, klen);
|
pair = qse_htb_search (((qse_awk_val_map_t*)map)->map, kptr, klen);
|
||||||
if (pair == QSE_NULL)
|
if (pair == QSE_NULL)
|
||||||
@ -689,18 +725,18 @@ qse_awk_val_t* qse_awk_rtx_getmapvalfld (
|
|||||||
qse_awk_val_map_itr_t* qse_awk_rtx_getfirstmapvalitr (
|
qse_awk_val_map_itr_t* qse_awk_rtx_getfirstmapvalitr (
|
||||||
qse_awk_rtx_t* rtx, qse_awk_val_t* map, qse_awk_val_map_itr_t* itr)
|
qse_awk_rtx_t* rtx, qse_awk_val_t* map, qse_awk_val_map_itr_t* itr)
|
||||||
{
|
{
|
||||||
QSE_ASSERT (map->type == QSE_AWK_VAL_MAP);
|
QSE_ASSERT (qse_awk_rtx_getvaltype (rtx, map) == QSE_AWK_VAL_MAP);
|
||||||
itr->pair = qse_htb_getfirstpair (
|
|
||||||
((qse_awk_val_map_t*)map)->map, &itr->buckno);
|
itr->pair = qse_htb_getfirstpair (((qse_awk_val_map_t*)map)->map, &itr->buckno);
|
||||||
return itr->pair? itr: QSE_NULL;
|
return itr->pair? itr: QSE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
qse_awk_val_map_itr_t* qse_awk_rtx_getnextmapvalitr (
|
qse_awk_val_map_itr_t* qse_awk_rtx_getnextmapvalitr (
|
||||||
qse_awk_rtx_t* rtx, qse_awk_val_t* map, qse_awk_val_map_itr_t* itr)
|
qse_awk_rtx_t* rtx, qse_awk_val_t* map, qse_awk_val_map_itr_t* itr)
|
||||||
{
|
{
|
||||||
QSE_ASSERT (map->type == QSE_AWK_VAL_MAP);
|
QSE_ASSERT (qse_awk_rtx_getvaltype (rtx, map) == QSE_AWK_VAL_MAP);
|
||||||
itr->pair = qse_htb_getnextpair (
|
|
||||||
((qse_awk_val_map_t*)map)->map, itr->pair, &itr->buckno);
|
itr->pair = qse_htb_getnextpair (((qse_awk_val_map_t*)map)->map, itr->pair, &itr->buckno);
|
||||||
return itr->pair? itr: QSE_NULL;
|
return itr->pair? itr: QSE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -724,7 +760,7 @@ qse_awk_val_t* qse_awk_rtx_makerefval (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val->type = QSE_AWK_VAL_REF;
|
val->v_type = QSE_AWK_VAL_REF;
|
||||||
val->ref = 0;
|
val->ref = 0;
|
||||||
val->stat = 0;
|
val->stat = 0;
|
||||||
val->nstr = 0;
|
val->nstr = 0;
|
||||||
@ -746,7 +782,7 @@ qse_awk_val_t* qse_awk_rtx_makefunval (
|
|||||||
return QSE_NULL;
|
return QSE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
val->type = QSE_AWK_VAL_FUN;
|
val->v_type = QSE_AWK_VAL_FUN;
|
||||||
val->fun = (qse_awk_fun_t*)fun;
|
val->fun = (qse_awk_fun_t*)fun;
|
||||||
|
|
||||||
return (qse_awk_val_t*)val;
|
return (qse_awk_val_t*)val;
|
||||||
@ -777,9 +813,20 @@ int qse_awk_rtx_isstaticval (qse_awk_rtx_t* rtx, qse_awk_val_t* val)
|
|||||||
return IS_STATICVAL(val);
|
return IS_STATICVAL(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
void qse_awk_rtx_freeval (
|
void qse_awk_rtx_freeval (qse_awk_rtx_t* rtx, qse_awk_val_t* val, int cache)
|
||||||
qse_awk_rtx_t* rtx, qse_awk_val_t* val, int cache)
|
|
||||||
{
|
{
|
||||||
|
qse_awk_val_type_t vtype;
|
||||||
|
|
||||||
|
switch (POINTER_TYPE_BITS(val))
|
||||||
|
{
|
||||||
|
// case TYPE_BITS_QUICKINT:
|
||||||
|
/* do nothing */
|
||||||
|
// return;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (IS_STATICVAL(val)) return;
|
if (IS_STATICVAL(val)) return;
|
||||||
|
|
||||||
#ifdef DEBUG_VAL
|
#ifdef DEBUG_VAL
|
||||||
@ -788,7 +835,8 @@ void qse_awk_rtx_freeval (
|
|||||||
qse_errputstrf (QSE_T("\n"));
|
qse_errputstrf (QSE_T("\n"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch (val->type)
|
vtype = qse_awk_rtx_getvaltype (rtx, val);
|
||||||
|
switch (vtype)
|
||||||
{
|
{
|
||||||
case QSE_AWK_VAL_NIL:
|
case QSE_AWK_VAL_NIL:
|
||||||
{
|
{
|
||||||
@ -961,7 +1009,7 @@ static int val_ref_to_bool (
|
|||||||
/* A reference value is not able to point to another
|
/* A reference value is not able to point to another
|
||||||
* refernce value for the way values are represented
|
* refernce value for the way values are represented
|
||||||
* in QSEAWK */
|
* in QSEAWK */
|
||||||
QSE_ASSERT ((*xref)->type != QSE_AWK_VAL_REF);
|
QSE_ASSERT (qse_awk_rtx_getvaltype (rtx, *xref)!= QSE_AWK_VAL_REF);
|
||||||
|
|
||||||
/* make a recursive call back to the caller */
|
/* make a recursive call back to the caller */
|
||||||
return qse_awk_rtx_valtobool (rtx, *xref);
|
return qse_awk_rtx_valtobool (rtx, *xref);
|
||||||
@ -969,17 +1017,19 @@ static int val_ref_to_bool (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int qse_awk_rtx_valtobool (qse_awk_rtx_t* rtx, const qse_awk_val_t* val)
|
int qse_awk_rtx_valtobool (qse_awk_rtx_t* rtx, const qse_awk_val_t* val)
|
||||||
{
|
{
|
||||||
|
qse_awk_val_type_t vtype;
|
||||||
|
|
||||||
if (val == QSE_NULL) return 0;
|
if (val == QSE_NULL) return 0;
|
||||||
|
|
||||||
switch (val->type)
|
vtype = qse_awk_rtx_getvaltype (rtx, val);
|
||||||
|
switch (vtype)
|
||||||
{
|
{
|
||||||
case QSE_AWK_VAL_NIL:
|
case QSE_AWK_VAL_NIL:
|
||||||
return 0;
|
return 0;
|
||||||
case QSE_AWK_VAL_INT:
|
case QSE_AWK_VAL_INT:
|
||||||
return ((qse_awk_val_int_t*)val)->val != 0;
|
return qse_awk_rtx_getintfromval (rtx, val) != 0;
|
||||||
case QSE_AWK_VAL_FLT:
|
case QSE_AWK_VAL_FLT:
|
||||||
return ((qse_awk_val_flt_t*)val)->val != 0.0;
|
return ((qse_awk_val_flt_t*)val)->val != 0.0;
|
||||||
case QSE_AWK_VAL_STR:
|
case QSE_AWK_VAL_STR:
|
||||||
@ -987,10 +1037,10 @@ int qse_awk_rtx_valtobool (qse_awk_rtx_t* rtx, const qse_awk_val_t* val)
|
|||||||
case QSE_AWK_VAL_REX: /* TODO: is this correct? */
|
case QSE_AWK_VAL_REX: /* TODO: is this correct? */
|
||||||
return ((qse_awk_val_rex_t*)val)->str.len > 0;
|
return ((qse_awk_val_rex_t*)val)->str.len > 0;
|
||||||
case QSE_AWK_VAL_MAP:
|
case QSE_AWK_VAL_MAP:
|
||||||
return 0; /* TODO: is this correct? */
|
/* true if the map size is greater than 0. false if not */
|
||||||
|
return QSE_HTB_SIZE(((qse_awk_val_map_t*)val)->map) > 0;
|
||||||
case QSE_AWK_VAL_REF:
|
case QSE_AWK_VAL_REF:
|
||||||
return val_ref_to_bool (rtx, (qse_awk_val_ref_t*)val);
|
return val_ref_to_bool (rtx, (qse_awk_val_ref_t*)val);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QSE_ASSERTX (
|
QSE_ASSERTX (
|
||||||
@ -1081,19 +1131,20 @@ static int val_int_to_str (
|
|||||||
qse_awk_rtx_valtostr_out_t* out)
|
qse_awk_rtx_valtostr_out_t* out)
|
||||||
{
|
{
|
||||||
qse_char_t* tmp;
|
qse_char_t* tmp;
|
||||||
qse_awk_uint_t t;
|
|
||||||
qse_size_t rlen = 0;
|
qse_size_t rlen = 0;
|
||||||
int type = out->type & ~QSE_AWK_RTX_VALTOSTR_PRINT;
|
int type = out->type & ~QSE_AWK_RTX_VALTOSTR_PRINT;
|
||||||
|
qse_awk_int_t orgval = qse_awk_rtx_getintfromval (rtx, v);
|
||||||
|
qse_awk_uint_t t;
|
||||||
|
|
||||||
if (v->val == 0) rlen++;
|
if (orgval == 0) rlen++;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* non-zero values */
|
/* non-zero values */
|
||||||
if (v->val < 0)
|
if (orgval < 0)
|
||||||
{
|
{
|
||||||
t = v->val * -1; rlen++;
|
t = orgval * -1; rlen++;
|
||||||
}
|
}
|
||||||
else t = v->val;
|
else t = orgval;
|
||||||
while (t > 0) { rlen++; t /= 10; }
|
while (t > 0) { rlen++; t /= 10; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1179,10 +1230,10 @@ static int val_int_to_str (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (v->val == 0) tmp[0] = QSE_T('0');
|
if (orgval == 0) tmp[0] = QSE_T('0');
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
t = (v->val < 0)? (v->val * -1): v->val;
|
t = (orgval < 0)? (orgval * -1): orgval;
|
||||||
|
|
||||||
/* fill in the buffer with digits */
|
/* fill in the buffer with digits */
|
||||||
while (t > 0)
|
while (t > 0)
|
||||||
@ -1192,7 +1243,7 @@ static int val_int_to_str (
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* insert the negative sign if necessary */
|
/* insert the negative sign if necessary */
|
||||||
if (v->val < 0) tmp[--rlen] = QSE_T('-');
|
if (orgval < 0) tmp[--rlen] = QSE_T('-');
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -1365,7 +1416,7 @@ static int val_ref_to_str (
|
|||||||
/* A reference value is not able to point to another
|
/* A reference value is not able to point to another
|
||||||
* refernce value for the way values are represented
|
* refernce value for the way values are represented
|
||||||
* in QSEAWK */
|
* in QSEAWK */
|
||||||
QSE_ASSERT ((*xref)->type != QSE_AWK_VAL_REF);
|
QSE_ASSERT (qse_awk_rtx_getvaltype (rtx, *xref) != QSE_AWK_VAL_REF);
|
||||||
|
|
||||||
/* make a recursive call back to the caller */
|
/* make a recursive call back to the caller */
|
||||||
return qse_awk_rtx_valtostr (rtx, *xref, out);
|
return qse_awk_rtx_valtostr (rtx, *xref, out);
|
||||||
@ -1377,7 +1428,9 @@ int qse_awk_rtx_valtostr (
|
|||||||
qse_awk_rtx_t* rtx, const qse_awk_val_t* v,
|
qse_awk_rtx_t* rtx, const qse_awk_val_t* v,
|
||||||
qse_awk_rtx_valtostr_out_t* out)
|
qse_awk_rtx_valtostr_out_t* out)
|
||||||
{
|
{
|
||||||
switch (v->type)
|
qse_awk_val_type_t vtype = qse_awk_rtx_getvaltype (rtx, v);
|
||||||
|
|
||||||
|
switch (vtype)
|
||||||
{
|
{
|
||||||
case QSE_AWK_VAL_NIL:
|
case QSE_AWK_VAL_NIL:
|
||||||
{
|
{
|
||||||
@ -1492,7 +1545,7 @@ qse_wchar_t* qse_awk_rtx_valtowcsdup (
|
|||||||
qse_char_t* qse_awk_rtx_getvalstr (
|
qse_char_t* qse_awk_rtx_getvalstr (
|
||||||
qse_awk_rtx_t* rtx, const qse_awk_val_t* v, qse_size_t* len)
|
qse_awk_rtx_t* rtx, const qse_awk_val_t* v, qse_size_t* len)
|
||||||
{
|
{
|
||||||
if (v->type == QSE_AWK_VAL_STR)
|
if (qse_awk_rtx_getvaltype(rtx, v) == QSE_AWK_VAL_STR)
|
||||||
{
|
{
|
||||||
if (len) *len = ((qse_awk_val_str_t*)v)->val.len;
|
if (len) *len = ((qse_awk_val_str_t*)v)->val.len;
|
||||||
return ((qse_awk_val_str_t*)v)->val.ptr;
|
return ((qse_awk_val_str_t*)v)->val.ptr;
|
||||||
@ -1506,7 +1559,7 @@ qse_char_t* qse_awk_rtx_getvalstr (
|
|||||||
void qse_awk_rtx_freevalstr (
|
void qse_awk_rtx_freevalstr (
|
||||||
qse_awk_rtx_t* rtx, const qse_awk_val_t* v, qse_char_t* str)
|
qse_awk_rtx_t* rtx, const qse_awk_val_t* v, qse_char_t* str)
|
||||||
{
|
{
|
||||||
if (v->type != QSE_AWK_VAL_STR &&
|
if (qse_awk_rtx_getvaltype(rtx, v) != QSE_AWK_VAL_STR &&
|
||||||
str != ((qse_awk_val_str_t*)v)->val.ptr)
|
str != ((qse_awk_val_str_t*)v)->val.ptr)
|
||||||
{
|
{
|
||||||
qse_awk_rtx_freemem (rtx, str);
|
qse_awk_rtx_freemem (rtx, str);
|
||||||
@ -1563,7 +1616,7 @@ static int val_ref_to_num (
|
|||||||
/* A reference value is not able to point to another
|
/* A reference value is not able to point to another
|
||||||
* refernce value for the way values are represented
|
* refernce value for the way values are represented
|
||||||
* in QSEAWK */
|
* in QSEAWK */
|
||||||
QSE_ASSERT ((*xref)->type != QSE_AWK_VAL_REF);
|
QSE_ASSERT (qse_awk_rtx_getvaltype (rtx, *xref) != QSE_AWK_VAL_REF);
|
||||||
|
|
||||||
/* make a recursive call back to the caller */
|
/* make a recursive call back to the caller */
|
||||||
return qse_awk_rtx_valtonum (rtx, *xref, l, r);
|
return qse_awk_rtx_valtonum (rtx, *xref, l, r);
|
||||||
@ -1575,7 +1628,9 @@ static int val_ref_to_num (
|
|||||||
int qse_awk_rtx_valtonum (
|
int qse_awk_rtx_valtonum (
|
||||||
qse_awk_rtx_t* rtx, const qse_awk_val_t* v, qse_awk_int_t* l, qse_awk_flt_t* r)
|
qse_awk_rtx_t* rtx, const qse_awk_val_t* v, qse_awk_int_t* l, qse_awk_flt_t* r)
|
||||||
{
|
{
|
||||||
switch (v->type)
|
qse_awk_val_type_t vtype = qse_awk_rtx_getvaltype (rtx, v);
|
||||||
|
|
||||||
|
switch (vtype)
|
||||||
{
|
{
|
||||||
case QSE_AWK_VAL_NIL:
|
case QSE_AWK_VAL_NIL:
|
||||||
{
|
{
|
||||||
@ -1585,7 +1640,7 @@ int qse_awk_rtx_valtonum (
|
|||||||
|
|
||||||
case QSE_AWK_VAL_INT:
|
case QSE_AWK_VAL_INT:
|
||||||
{
|
{
|
||||||
*l = ((qse_awk_val_int_t*)v)->val;
|
*l = qse_awk_rtx_getintfromval (rtx, v);
|
||||||
return 0; /* long */
|
return 0; /* long */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1691,20 +1746,22 @@ static qse_awk_uint_t hash (qse_uint8_t* ptr, qse_size_t len)
|
|||||||
|
|
||||||
qse_awk_int_t qse_awk_rtx_hashval (qse_awk_rtx_t* rtx, qse_awk_val_t* v)
|
qse_awk_int_t qse_awk_rtx_hashval (qse_awk_rtx_t* rtx, qse_awk_val_t* v)
|
||||||
{
|
{
|
||||||
|
qse_awk_val_type_t vtype = qse_awk_rtx_getvaltype (rtx, v);
|
||||||
qse_awk_int_t hv;
|
qse_awk_int_t hv;
|
||||||
|
|
||||||
switch (v->type)
|
switch (vtype)
|
||||||
{
|
{
|
||||||
case QSE_AWK_VAL_NIL:
|
case QSE_AWK_VAL_NIL:
|
||||||
hv = 0;
|
hv = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case QSE_AWK_VAL_INT:
|
case QSE_AWK_VAL_INT:
|
||||||
|
{
|
||||||
|
qse_awk_int_t tmp = qse_awk_rtx_getintfromval (rtx, v);
|
||||||
/*hv = ((qse_awk_val_int_t*)v)->val;*/
|
/*hv = ((qse_awk_val_int_t*)v)->val;*/
|
||||||
hv = (qse_awk_int_t)hash (
|
hv = (qse_awk_int_t)hash ((qse_uint8_t*)&tmp, QSE_SIZEOF(tmp));
|
||||||
(qse_uint8_t*)&((qse_awk_val_int_t*)v)->val,
|
|
||||||
QSE_SIZEOF(((qse_awk_val_int_t*)v)->val));
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case QSE_AWK_VAL_FLT:
|
case QSE_AWK_VAL_FLT:
|
||||||
hv = (qse_awk_int_t)hash (
|
hv = (qse_awk_int_t)hash (
|
||||||
@ -1736,7 +1793,9 @@ qse_awk_int_t qse_awk_rtx_hashval (qse_awk_rtx_t* rtx, qse_awk_val_t* v)
|
|||||||
|
|
||||||
int qse_awk_rtx_setrefval (qse_awk_rtx_t* rtx, qse_awk_val_ref_t* ref, qse_awk_val_t* val)
|
int qse_awk_rtx_setrefval (qse_awk_rtx_t* rtx, qse_awk_val_ref_t* ref, qse_awk_val_t* val)
|
||||||
{
|
{
|
||||||
if (val->type == QSE_AWK_VAL_REX || val->type == QSE_AWK_VAL_REF)
|
qse_awk_val_type_t vtype = qse_awk_rtx_getvaltype (rtx, val);
|
||||||
|
|
||||||
|
if (vtype == QSE_AWK_VAL_REX || vtype == QSE_AWK_VAL_REF)
|
||||||
{
|
{
|
||||||
/* though it is possible that an intrinsic function handler
|
/* though it is possible that an intrinsic function handler
|
||||||
* can accept a regular expression withtout evaluation when 'x'
|
* can accept a regular expression withtout evaluation when 'x'
|
||||||
@ -1753,8 +1812,7 @@ int qse_awk_rtx_setrefval (qse_awk_rtx_t* rtx, qse_awk_val_ref_t* ref, qse_awk_v
|
|||||||
{
|
{
|
||||||
case QSE_AWK_VAL_REF_POS:
|
case QSE_AWK_VAL_REF_POS:
|
||||||
{
|
{
|
||||||
|
switch (vtype)
|
||||||
switch (val->type)
|
|
||||||
{
|
{
|
||||||
case QSE_AWK_VAL_MAP:
|
case QSE_AWK_VAL_MAP:
|
||||||
/* a map is assigned to a positional. this is disallowed. */
|
/* a map is assigned to a positional. this is disallowed. */
|
||||||
@ -1799,7 +1857,7 @@ int qse_awk_rtx_setrefval (qse_awk_rtx_t* rtx, qse_awk_val_ref_t* ref, qse_awk_v
|
|||||||
case QSE_AWK_VAL_REF_GBLIDX:
|
case QSE_AWK_VAL_REF_GBLIDX:
|
||||||
case QSE_AWK_VAL_REF_LCLIDX:
|
case QSE_AWK_VAL_REF_LCLIDX:
|
||||||
case QSE_AWK_VAL_REF_ARGIDX:
|
case QSE_AWK_VAL_REF_ARGIDX:
|
||||||
if (val->type == QSE_AWK_VAL_MAP)
|
if (vtype == QSE_AWK_VAL_MAP)
|
||||||
{
|
{
|
||||||
/* an indexed variable cannot be assigned a map.
|
/* an indexed variable cannot be assigned a map.
|
||||||
* in other cases, it falls down to the default case. */
|
* in other cases, it falls down to the default case. */
|
||||||
@ -1811,13 +1869,14 @@ int qse_awk_rtx_setrefval (qse_awk_rtx_t* rtx, qse_awk_val_ref_t* ref, qse_awk_v
|
|||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
qse_awk_val_t** rref;
|
qse_awk_val_t** rref;
|
||||||
|
qse_awk_val_type_t rref_vtype;
|
||||||
|
|
||||||
rref = (qse_awk_val_t**)ref->adr;
|
rref = (qse_awk_val_t**)ref->adr; /* old value pointer */
|
||||||
if (val->type == QSE_AWK_VAL_MAP)
|
rref_vtype = qse_awk_rtx_getvaltype (rtx, *rref); /* old value type */
|
||||||
|
if (vtype == QSE_AWK_VAL_MAP)
|
||||||
{
|
{
|
||||||
/* new value: map, old value: nil or map => ok */
|
/* new value: map, old value: nil or map => ok */
|
||||||
if ((*rref)->type != QSE_AWK_VAL_NIL &&
|
if (rref_vtype != QSE_AWK_VAL_NIL && rref_vtype != QSE_AWK_VAL_MAP)
|
||||||
(*rref)->type != QSE_AWK_VAL_MAP)
|
|
||||||
{
|
{
|
||||||
if (!(rtx->awk->opt.trait & QSE_AWK_FLEXMAP))
|
if (!(rtx->awk->opt.trait & QSE_AWK_FLEXMAP))
|
||||||
{
|
{
|
||||||
@ -1830,7 +1889,7 @@ int qse_awk_rtx_setrefval (qse_awk_rtx_t* rtx, qse_awk_val_ref_t* ref, qse_awk_v
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* new value: scalar, old value: nil or scalar => ok */
|
/* new value: scalar, old value: nil or scalar => ok */
|
||||||
if ((*rref)->type == QSE_AWK_VAL_MAP)
|
if (rref_vtype == QSE_AWK_VAL_MAP)
|
||||||
{
|
{
|
||||||
if (!(rtx->awk->opt.trait & QSE_AWK_FLEXMAP))
|
if (!(rtx->awk->opt.trait & QSE_AWK_FLEXMAP))
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user