cleaned up code a little
This commit is contained in:
parent
1201d2890b
commit
14bc247637
@ -5,8 +5,8 @@ QSE provides a script engine for various scripting languages. It aims to produce
|
|||||||
|
|
||||||
Cross compiling for WIN32 with MINGW32
|
Cross compiling for WIN32 with MINGW32
|
||||||
|
|
||||||
./configure --host=i586-mingw32msvc --target=i586-mingw32msvc --enable-syscall
|
./configure --host=i586-mingw32msvc --target=i586-mingw32msvc --enable-syscall
|
||||||
make
|
make
|
||||||
|
|
||||||
<< DOCUMENTATION >>
|
<< DOCUMENTATION >>
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
#main ()
|
#main ()
|
||||||
{
|
{
|
||||||
#print (("%f", 1.0)); # syntax error
|
#print (("%f", 1.0)); # syntax error
|
||||||
|
@ -472,11 +472,11 @@ public:
|
|||||||
ERR_IN = QSE_AWK_EIN,
|
ERR_IN = QSE_AWK_EIN,
|
||||||
ERR_NOTVAR = QSE_AWK_ENOTVAR,
|
ERR_NOTVAR = QSE_AWK_ENOTVAR,
|
||||||
ERR_EXPRES = QSE_AWK_EEXPRES,
|
ERR_EXPRES = QSE_AWK_EEXPRES,
|
||||||
ERR_FUNC = QSE_AWK_EFUNC,
|
ERR_FUNCTION = QSE_AWK_EFUNCTION,
|
||||||
ERR_WHILE = QSE_AWK_EWHILE,
|
ERR_WHILE = QSE_AWK_EWHILE,
|
||||||
ERR_ASSIGN = QSE_AWK_EASSIGN,
|
ERR_ASSIGN = QSE_AWK_EASSIGN,
|
||||||
ERR_IDENT = QSE_AWK_EIDENT,
|
ERR_IDENT = QSE_AWK_EIDENT,
|
||||||
ERR_FNNAME = QSE_AWK_EFNNAME,
|
ERR_FUNNAME = QSE_AWK_EFUNNAME,
|
||||||
ERR_BLKBEG = QSE_AWK_EBLKBEG,
|
ERR_BLKBEG = QSE_AWK_EBLKBEG,
|
||||||
ERR_BLKEND = QSE_AWK_EBLKEND,
|
ERR_BLKEND = QSE_AWK_EBLKEND,
|
||||||
ERR_DUPBEG = QSE_AWK_EDUPBEG,
|
ERR_DUPBEG = QSE_AWK_EDUPBEG,
|
||||||
@ -510,7 +510,7 @@ public:
|
|||||||
ERR_POSIDX = QSE_AWK_EPOSIDX,
|
ERR_POSIDX = QSE_AWK_EPOSIDX,
|
||||||
ERR_ARGTF = QSE_AWK_EARGTF,
|
ERR_ARGTF = QSE_AWK_EARGTF,
|
||||||
ERR_ARGTM = QSE_AWK_EARGTM,
|
ERR_ARGTM = QSE_AWK_EARGTM,
|
||||||
ERR_FNNONE = QSE_AWK_EFNNONE,
|
ERR_FUNNONE = QSE_AWK_EFUNNONE,
|
||||||
ERR_NOTIDX = QSE_AWK_ENOTIDX,
|
ERR_NOTIDX = QSE_AWK_ENOTIDX,
|
||||||
ERR_NOTDEL = QSE_AWK_ENOTDEL,
|
ERR_NOTDEL = QSE_AWK_ENOTDEL,
|
||||||
ERR_NOTMAP = QSE_AWK_ENOTMAP,
|
ERR_NOTMAP = QSE_AWK_ENOTMAP,
|
||||||
|
@ -320,11 +320,11 @@ enum qse_awk_errnum_t
|
|||||||
QSE_AWK_ENOTVAR, /* not a variable name after 'in' */
|
QSE_AWK_ENOTVAR, /* not a variable name after 'in' */
|
||||||
QSE_AWK_EEXPRES, /* expression expected */
|
QSE_AWK_EEXPRES, /* expression expected */
|
||||||
|
|
||||||
QSE_AWK_EFUNC, /* keyword 'func' is expected */
|
QSE_AWK_EFUNCTION, /* keyword 'function' is expected */
|
||||||
QSE_AWK_EWHILE, /* keyword 'while' is expected */
|
QSE_AWK_EWHILE, /* keyword 'while' is expected */
|
||||||
QSE_AWK_EASSIGN, /* assignment statement expected */
|
QSE_AWK_EASSIGN, /* assignment statement expected */
|
||||||
QSE_AWK_EIDENT, /* identifier expected */
|
QSE_AWK_EIDENT, /* identifier expected */
|
||||||
QSE_AWK_EFNNAME, /* not a valid function name */
|
QSE_AWK_EFUNNAME, /* not a valid function name */
|
||||||
QSE_AWK_EBLKBEG, /* BEGIN requires an action block */
|
QSE_AWK_EBLKBEG, /* BEGIN requires an action block */
|
||||||
QSE_AWK_EBLKEND, /* END requires an action block */
|
QSE_AWK_EBLKEND, /* END requires an action block */
|
||||||
QSE_AWK_EDUPBEG, /* duplicate BEGIN */
|
QSE_AWK_EDUPBEG, /* duplicate BEGIN */
|
||||||
@ -362,7 +362,7 @@ enum qse_awk_errnum_t
|
|||||||
QSE_AWK_EPOSIDX, /* wrong position index */
|
QSE_AWK_EPOSIDX, /* wrong position index */
|
||||||
QSE_AWK_EARGTF, /* too few arguments */
|
QSE_AWK_EARGTF, /* too few arguments */
|
||||||
QSE_AWK_EARGTM, /* too many arguments */
|
QSE_AWK_EARGTM, /* too many arguments */
|
||||||
QSE_AWK_EFNNONE, /* "function '%.*s' not found" */
|
QSE_AWK_EFUNNONE, /* "function '%.*s' not found" */
|
||||||
QSE_AWK_ENOTIDX, /* variable not indexable */
|
QSE_AWK_ENOTIDX, /* variable not indexable */
|
||||||
QSE_AWK_ENOTDEL, /* variable not deletable */
|
QSE_AWK_ENOTDEL, /* variable not deletable */
|
||||||
QSE_AWK_ENOTMAP, /* value not a map */
|
QSE_AWK_ENOTMAP, /* value not a map */
|
||||||
|
@ -1415,7 +1415,7 @@ int Awk::dispatchFunction (Run* run, const char_t* name, size_t len)
|
|||||||
pair = qse_map_search (functionMap, name, len);
|
pair = qse_map_search (functionMap, name, len);
|
||||||
if (pair == QSE_NULL)
|
if (pair == QSE_NULL)
|
||||||
{
|
{
|
||||||
run->setError (ERR_FNNONE, 0, name, len);
|
run->setError (ERR_FUNNONE, 0, name, len);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t ext)
|
|||||||
awk->parse.nlcls_max = 0;
|
awk->parse.nlcls_max = 0;
|
||||||
|
|
||||||
awk->tree.ngbls = 0;
|
awk->tree.ngbls = 0;
|
||||||
awk->tree.nbgbls = 0;
|
awk->tree.ngbls_base = 0;
|
||||||
awk->tree.begin = QSE_NULL;
|
awk->tree.begin = QSE_NULL;
|
||||||
awk->tree.begin_tail = QSE_NULL;
|
awk->tree.begin_tail = QSE_NULL;
|
||||||
awk->tree.end = QSE_NULL;
|
awk->tree.end = QSE_NULL;
|
||||||
@ -258,8 +258,8 @@ int qse_awk_clear (qse_awk_t* awk)
|
|||||||
QSE_ASSERT (QSE_LDA_SIZE(awk->parse.gbls) == awk->tree.ngbls);
|
QSE_ASSERT (QSE_LDA_SIZE(awk->parse.gbls) == awk->tree.ngbls);
|
||||||
/* delete all non-builtin global variables */
|
/* delete all non-builtin global variables */
|
||||||
qse_lda_delete (
|
qse_lda_delete (
|
||||||
awk->parse.gbls, awk->tree.nbgbls,
|
awk->parse.gbls, awk->tree.ngbls_base,
|
||||||
QSE_LDA_SIZE(awk->parse.gbls) - awk->tree.nbgbls);
|
QSE_LDA_SIZE(awk->parse.gbls) - awk->tree.ngbls_base);
|
||||||
|
|
||||||
qse_lda_clear (awk->parse.lcls);
|
qse_lda_clear (awk->parse.lcls);
|
||||||
qse_lda_clear (awk->parse.params);
|
qse_lda_clear (awk->parse.params);
|
||||||
@ -273,9 +273,9 @@ int qse_awk_clear (qse_awk_t* awk)
|
|||||||
|
|
||||||
/* clear parse trees */
|
/* clear parse trees */
|
||||||
awk->tree.ok = 0;
|
awk->tree.ok = 0;
|
||||||
/*awk->tree.nbgbls = 0;
|
/*awk->tree.ngbls_base = 0;
|
||||||
awk->tree.ngbls = 0; */
|
awk->tree.ngbls = 0; */
|
||||||
awk->tree.ngbls = awk->tree.nbgbls;
|
awk->tree.ngbls = awk->tree.ngbls_base;
|
||||||
|
|
||||||
awk->tree.cur_fun.ptr = QSE_NULL;
|
awk->tree.cur_fun.ptr = QSE_NULL;
|
||||||
awk->tree.cur_fun.len = 0;
|
awk->tree.cur_fun.len = 0;
|
||||||
|
@ -65,8 +65,8 @@ typedef struct qse_awk_tree_t qse_awk_tree_t;
|
|||||||
|
|
||||||
struct qse_awk_tree_t
|
struct qse_awk_tree_t
|
||||||
{
|
{
|
||||||
qse_size_t ngbls; /* total number of gbls */
|
qse_size_t ngbls; /* total number of globals */
|
||||||
qse_size_t nbgbls; /* number of intrinsic gbls */
|
qse_size_t ngbls_base; /* number of intrinsic globals */
|
||||||
qse_cstr_t cur_fun;
|
qse_cstr_t cur_fun;
|
||||||
qse_map_t* funs; /* awk function map */
|
qse_map_t* funs; /* awk function map */
|
||||||
|
|
||||||
|
@ -145,17 +145,11 @@ struct binmap_t
|
|||||||
static int parse (qse_awk_t* awk);
|
static int parse (qse_awk_t* awk);
|
||||||
|
|
||||||
static qse_awk_t* parse_progunit (qse_awk_t* awk);
|
static qse_awk_t* parse_progunit (qse_awk_t* awk);
|
||||||
static qse_awk_t* collect_gbls (qse_awk_t* awk);
|
static qse_awk_t* collect_globals (qse_awk_t* awk);
|
||||||
static void adjust_static_gbls (qse_awk_t* awk);
|
static void adjust_static_globals (qse_awk_t* awk);
|
||||||
|
static qse_size_t find_global (
|
||||||
static qse_size_t get_gbl (
|
|
||||||
qse_awk_t* awk, const qse_char_t* name, qse_size_t len);
|
qse_awk_t* awk, const qse_char_t* name, qse_size_t len);
|
||||||
static qse_size_t find_gbl (
|
static qse_awk_t* collect_locals (
|
||||||
qse_awk_t* awk, const qse_char_t* name, qse_size_t len);
|
|
||||||
static int add_gbl (
|
|
||||||
qse_awk_t* awk, const qse_char_t* name, qse_size_t len,
|
|
||||||
qse_size_t line, int force);
|
|
||||||
static qse_awk_t* collect_lcls (
|
|
||||||
qse_awk_t* awk, qse_size_t nlcls, qse_bool_t istop);
|
qse_awk_t* awk, qse_size_t nlcls, qse_bool_t istop);
|
||||||
|
|
||||||
static qse_awk_nde_t* parse_function (qse_awk_t* awk);
|
static qse_awk_nde_t* parse_function (qse_awk_t* awk);
|
||||||
@ -455,14 +449,9 @@ void qse_awk_setmaxdepth (qse_awk_t* awk, int types, qse_size_t depth)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const qse_char_t* qse_awk_rtx_getgblname (
|
const qse_char_t* qse_awk_getgblname (
|
||||||
qse_awk_t* awk, qse_size_t idx, qse_size_t* len)
|
qse_awk_t* awk, qse_size_t idx, qse_size_t* len)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
*len = gtab[idx].name_len;
|
|
||||||
return gtab[idx].name;
|
|
||||||
*/
|
|
||||||
|
|
||||||
QSE_ASSERT (idx < QSE_LDA_SIZE(awk->parse.gbls));
|
QSE_ASSERT (idx < QSE_LDA_SIZE(awk->parse.gbls));
|
||||||
|
|
||||||
*len = QSE_LDA_DLEN(awk->parse.gbls,idx);
|
*len = QSE_LDA_DLEN(awk->parse.gbls,idx);
|
||||||
@ -528,7 +517,7 @@ static int parse (qse_awk_t* awk)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
adjust_static_gbls (awk);
|
adjust_static_globals (awk);
|
||||||
|
|
||||||
#define EXIT_PARSE(v) do { n = (v); goto exit_parse; } while(0)
|
#define EXIT_PARSE(v) do { n = (v); goto exit_parse; } while(0)
|
||||||
|
|
||||||
@ -567,7 +556,7 @@ static int parse (qse_awk_t* awk)
|
|||||||
QSE_MAP_KPTR(p), QSE_MAP_KLEN(p)) == QSE_NULL)
|
QSE_MAP_KPTR(p), QSE_MAP_KLEN(p)) == QSE_NULL)
|
||||||
{
|
{
|
||||||
/* TODO: set better error no & line */
|
/* TODO: set better error no & line */
|
||||||
SETERRARG (awk, QSE_AWK_EFNNONE,
|
SETERRARG (awk, QSE_AWK_EFUNNONE,
|
||||||
*(qse_size_t*)QSE_MAP_VPTR(p),
|
*(qse_size_t*)QSE_MAP_VPTR(p),
|
||||||
QSE_MAP_KPTR(p),
|
QSE_MAP_KPTR(p),
|
||||||
QSE_MAP_KLEN(p));
|
QSE_MAP_KLEN(p));
|
||||||
@ -630,7 +619,7 @@ static qse_awk_t* parse_progunit (qse_awk_t* awk)
|
|||||||
|
|
||||||
QSE_ASSERT (awk->tree.ngbls == QSE_LDA_SIZE(awk->parse.gbls));
|
QSE_ASSERT (awk->tree.ngbls == QSE_LDA_SIZE(awk->parse.gbls));
|
||||||
ngbls = awk->tree.ngbls;
|
ngbls = awk->tree.ngbls;
|
||||||
if (collect_gbls (awk) == QSE_NULL)
|
if (collect_globals (awk) == QSE_NULL)
|
||||||
{
|
{
|
||||||
qse_lda_delete (
|
qse_lda_delete (
|
||||||
awk->parse.gbls, ngbls,
|
awk->parse.gbls, ngbls,
|
||||||
@ -648,7 +637,7 @@ static qse_awk_t* parse_progunit (qse_awk_t* awk)
|
|||||||
{
|
{
|
||||||
if ((awk->option & QSE_AWK_PABLOCK) == 0)
|
if ((awk->option & QSE_AWK_PABLOCK) == 0)
|
||||||
{
|
{
|
||||||
SETERRTOK (awk, QSE_AWK_EFUNC);
|
SETERRTOK (awk, QSE_AWK_EFUNCTION);
|
||||||
return QSE_NULL;
|
return QSE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -684,7 +673,7 @@ static qse_awk_t* parse_progunit (qse_awk_t* awk)
|
|||||||
{
|
{
|
||||||
if ((awk->option & QSE_AWK_PABLOCK) == 0)
|
if ((awk->option & QSE_AWK_PABLOCK) == 0)
|
||||||
{
|
{
|
||||||
SETERRTOK (awk, QSE_AWK_EFUNC);
|
SETERRTOK (awk, QSE_AWK_EFUNCTION);
|
||||||
return QSE_NULL;
|
return QSE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -721,7 +710,7 @@ static qse_awk_t* parse_progunit (qse_awk_t* awk)
|
|||||||
/* patternless block */
|
/* patternless block */
|
||||||
if ((awk->option & QSE_AWK_PABLOCK) == 0)
|
if ((awk->option & QSE_AWK_PABLOCK) == 0)
|
||||||
{
|
{
|
||||||
SETERRTOK (awk, QSE_AWK_EFUNC);
|
SETERRTOK (awk, QSE_AWK_EFUNCTION);
|
||||||
return QSE_NULL;
|
return QSE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -744,7 +733,7 @@ static qse_awk_t* parse_progunit (qse_awk_t* awk)
|
|||||||
|
|
||||||
if ((awk->option & QSE_AWK_PABLOCK) == 0)
|
if ((awk->option & QSE_AWK_PABLOCK) == 0)
|
||||||
{
|
{
|
||||||
SETERRTOK (awk, QSE_AWK_EFUNC);
|
SETERRTOK (awk, QSE_AWK_EFUNCTION);
|
||||||
return QSE_NULL;
|
return QSE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -846,7 +835,7 @@ static qse_awk_nde_t* parse_function (qse_awk_t* awk)
|
|||||||
if (!MATCH(awk,TOKEN_IDENT))
|
if (!MATCH(awk,TOKEN_IDENT))
|
||||||
{
|
{
|
||||||
/* cannot find a valid identifier for a function name */
|
/* cannot find a valid identifier for a function name */
|
||||||
SETERRTOK (awk, QSE_AWK_EFNNAME);
|
SETERRTOK (awk, QSE_AWK_EFUNNAME);
|
||||||
return QSE_NULL;
|
return QSE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -870,7 +859,7 @@ static qse_awk_nde_t* parse_function (qse_awk_t* awk)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* check if it coincides to be a global variable name */
|
/* check if it coincides to be a global variable name */
|
||||||
g = find_gbl (awk, name, name_len);
|
g = find_global (awk, name, name_len);
|
||||||
if (g != QSE_LDA_NIL)
|
if (g != QSE_LDA_NIL)
|
||||||
{
|
{
|
||||||
SETERRARG (
|
SETERRARG (
|
||||||
@ -1233,7 +1222,7 @@ static qse_awk_nde_t* parse_block (
|
|||||||
return QSE_NULL;
|
return QSE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (collect_lcls (awk, nlcls, istop) == QSE_NULL)
|
if (collect_locals (awk, nlcls, istop) == QSE_NULL)
|
||||||
{
|
{
|
||||||
qse_lda_delete (
|
qse_lda_delete (
|
||||||
awk->parse.lcls, nlcls,
|
awk->parse.lcls, nlcls,
|
||||||
@ -1383,9 +1372,9 @@ int qse_awk_initgbls (qse_awk_t* awk)
|
|||||||
|
|
||||||
/* qse_awk_initgbls is not generic-purpose. call this from
|
/* qse_awk_initgbls is not generic-purpose. call this from
|
||||||
* qse_awk_open only. */
|
* qse_awk_open only. */
|
||||||
QSE_ASSERT (awk->tree.nbgbls == 0 && awk->tree.ngbls == 0);
|
QSE_ASSERT (awk->tree.ngbls_base == 0 && awk->tree.ngbls == 0);
|
||||||
|
|
||||||
awk->tree.nbgbls = 0;
|
awk->tree.ngbls_base = 0;
|
||||||
awk->tree.ngbls = 0;
|
awk->tree.ngbls = 0;
|
||||||
|
|
||||||
for (id = QSE_AWK_MIN_GBL_ID; id <= QSE_AWK_MAX_GBL_ID; id++)
|
for (id = QSE_AWK_MIN_GBL_ID; id <= QSE_AWK_MAX_GBL_ID; id++)
|
||||||
@ -1401,20 +1390,20 @@ int qse_awk_initgbls (qse_awk_t* awk)
|
|||||||
|
|
||||||
QSE_ASSERT ((int)g == id);
|
QSE_ASSERT ((int)g == id);
|
||||||
|
|
||||||
awk->tree.nbgbls++;
|
awk->tree.ngbls_base++;
|
||||||
awk->tree.ngbls++;
|
awk->tree.ngbls++;
|
||||||
}
|
}
|
||||||
|
|
||||||
QSE_ASSERT (awk->tree.nbgbls ==
|
QSE_ASSERT (awk->tree.ngbls_base ==
|
||||||
QSE_AWK_MAX_GBL_ID-QSE_AWK_MIN_GBL_ID+1);
|
QSE_AWK_MAX_GBL_ID-QSE_AWK_MIN_GBL_ID+1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void adjust_static_gbls (qse_awk_t* awk)
|
static void adjust_static_globals (qse_awk_t* awk)
|
||||||
{
|
{
|
||||||
int id;
|
int id;
|
||||||
|
|
||||||
QSE_ASSERT (awk->tree.nbgbls >=
|
QSE_ASSERT (awk->tree.ngbls_base >=
|
||||||
QSE_AWK_MAX_GBL_ID - QSE_AWK_MAX_GBL_ID + 1);
|
QSE_AWK_MAX_GBL_ID - QSE_AWK_MAX_GBL_ID + 1);
|
||||||
|
|
||||||
for (id = QSE_AWK_MIN_GBL_ID; id <= QSE_AWK_MAX_GBL_ID; id++)
|
for (id = QSE_AWK_MIN_GBL_ID; id <= QSE_AWK_MAX_GBL_ID; id++)
|
||||||
@ -1451,7 +1440,7 @@ static qse_lda_walk_t check_gbl (qse_lda_t* lda, qse_size_t index, void* arg)
|
|||||||
tmp.ptr = QSE_LDA_DPTR(lda,index);
|
tmp.ptr = QSE_LDA_DPTR(lda,index);
|
||||||
tmp.len = QSE_LDA_DLEN(lda,index);
|
tmp.len = QSE_LDA_DLEN(lda,index);
|
||||||
|
|
||||||
if (index < awk->tree.nbgbls)
|
if (index < awk->tree.ngbls_base)
|
||||||
{
|
{
|
||||||
qse_map_pair_t* pair;
|
qse_map_pair_t* pair;
|
||||||
|
|
||||||
@ -1472,7 +1461,7 @@ static qse_lda_walk_t check_gbl (qse_lda_t* lda, qse_size_t index, void* arg)
|
|||||||
return cg->walk;
|
return cg->walk;
|
||||||
}
|
}
|
||||||
|
|
||||||
static qse_size_t get_gbl (
|
static qse_size_t get_global (
|
||||||
qse_awk_t* awk, const qse_char_t* name, qse_size_t len)
|
qse_awk_t* awk, const qse_char_t* name, qse_size_t len)
|
||||||
{
|
{
|
||||||
check_gbl_t cg;
|
check_gbl_t cg;
|
||||||
@ -1482,15 +1471,11 @@ static qse_size_t get_gbl (
|
|||||||
cg.index = QSE_LDA_NIL;
|
cg.index = QSE_LDA_NIL;
|
||||||
cg.walk = QSE_LDA_WALK_BACKWARD;
|
cg.walk = QSE_LDA_WALK_BACKWARD;
|
||||||
|
|
||||||
/* return qse_lda_rsearch (
|
|
||||||
awk->parse.gbls, QSE_LDA_SIZE(awk->parse.gbls),
|
|
||||||
name, len); */
|
|
||||||
|
|
||||||
qse_lda_rwalk (awk->parse.gbls, check_gbl, &cg);
|
qse_lda_rwalk (awk->parse.gbls, check_gbl, &cg);
|
||||||
return cg.index;
|
return cg.index;
|
||||||
}
|
}
|
||||||
|
|
||||||
static qse_size_t find_gbl (
|
static qse_size_t find_global (
|
||||||
qse_awk_t* awk, const qse_char_t* name, qse_size_t len)
|
qse_awk_t* awk, const qse_char_t* name, qse_size_t len)
|
||||||
{
|
{
|
||||||
check_gbl_t cg;
|
check_gbl_t cg;
|
||||||
@ -1500,55 +1485,46 @@ static qse_size_t find_gbl (
|
|||||||
cg.index = QSE_LDA_NIL;
|
cg.index = QSE_LDA_NIL;
|
||||||
cg.walk = QSE_LDA_WALK_FORWARD;
|
cg.walk = QSE_LDA_WALK_FORWARD;
|
||||||
|
|
||||||
/* return qse_lda_search (awk->parse.gbls, 0, name, len); */
|
|
||||||
|
|
||||||
qse_lda_walk (awk->parse.gbls, check_gbl, &cg);
|
qse_lda_walk (awk->parse.gbls, check_gbl, &cg);
|
||||||
return cg.index;
|
return cg.index;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int add_gbl (
|
static int add_global (
|
||||||
qse_awk_t* awk, const qse_char_t* name, qse_size_t len,
|
qse_awk_t* awk, const qse_char_t* name, qse_size_t len,
|
||||||
qse_size_t line, int disabled)
|
qse_size_t line, int disabled)
|
||||||
{
|
{
|
||||||
qse_size_t ngbls;
|
qse_size_t ngbls;
|
||||||
|
|
||||||
#if 0
|
/* check if it conflict with a builtin function name */
|
||||||
if (awk->option & QSE_AWK_UNIQUEFN)
|
if (qse_awk_getfnc (awk, name, len) != QSE_NULL)
|
||||||
{
|
{
|
||||||
#endif
|
SETERRARG (
|
||||||
/* check if it conflict with a builtin function name */
|
awk, QSE_AWK_EFNCRED, awk->token.line,
|
||||||
if (qse_awk_getfnc (awk, name, len) != QSE_NULL)
|
name, len);
|
||||||
{
|
return -1;
|
||||||
SETERRARG (
|
}
|
||||||
awk, QSE_AWK_EFNCRED, awk->token.line,
|
|
||||||
name, len);
|
/* check if it conflict with a function name */
|
||||||
return -1;
|
if (qse_map_search (awk->tree.funs, name, len) != QSE_NULL)
|
||||||
}
|
{
|
||||||
|
SETERRARG (
|
||||||
/* check if it conflict with a function name */
|
awk, QSE_AWK_EFUNRED, line,
|
||||||
if (qse_map_search (awk->tree.funs, name, len) != QSE_NULL)
|
name, len);
|
||||||
{
|
return -1;
|
||||||
SETERRARG (
|
}
|
||||||
awk, QSE_AWK_EFUNRED, line,
|
|
||||||
name, len);
|
/* check if it conflict with a function name
|
||||||
return -1;
|
* caught in the function call table */
|
||||||
}
|
if (qse_map_search (awk->parse.funs, name, len) != QSE_NULL)
|
||||||
|
{
|
||||||
/* check if it conflict with a function name
|
SETERRARG (
|
||||||
* caught in the function call table */
|
awk, QSE_AWK_EFUNRED, line,
|
||||||
if (qse_map_search (awk->parse.funs, name, len) != QSE_NULL)
|
name, len);
|
||||||
{
|
return -1;
|
||||||
SETERRARG (
|
|
||||||
awk, QSE_AWK_EFUNRED, line,
|
|
||||||
name, len);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
#if 0
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/* check if it conflicts with other global variable names */
|
/* check if it conflicts with other global variable names */
|
||||||
if (find_gbl (awk, name, len) != QSE_LDA_NIL)
|
if (find_global (awk, name, len) != QSE_LDA_NIL)
|
||||||
{
|
{
|
||||||
SETERRARG (awk, QSE_AWK_EDUPGBL, line, name, len);
|
SETERRARG (awk, QSE_AWK_EDUPGBL, line, name, len);
|
||||||
return -1;
|
return -1;
|
||||||
@ -1593,17 +1569,18 @@ int qse_awk_addgbl (
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (awk->tree.ngbls > awk->tree.nbgbls)
|
if (awk->tree.ngbls > awk->tree.ngbls_base)
|
||||||
{
|
{
|
||||||
/* this function is not allow after qse_awk_parse is called */
|
/* this function is not allow after qse_awk_parse is called */
|
||||||
SETERR (awk, QSE_AWK_ENOPER);
|
SETERR (awk, QSE_AWK_ENOPER);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
n = add_gbl (awk, name, len, 0, 0);
|
|
||||||
|
n = add_global (awk, name, len, 0, 0);
|
||||||
|
|
||||||
/* update the count of the static gbls.
|
/* update the count of the static gbls.
|
||||||
* the total gbl count has been updated inside add_gbl. */
|
* the total global count has been updated inside add_global. */
|
||||||
if (n >= 0) awk->tree.nbgbls++;
|
if (n >= 0) awk->tree.ngbls_base++;
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
@ -1616,7 +1593,7 @@ int qse_awk_delgbl (
|
|||||||
#define QSE_AWK_NUM_STATIC_GBLS \
|
#define QSE_AWK_NUM_STATIC_GBLS \
|
||||||
(QSE_AWK_MAX_GBL_ID-QSE_AWK_MIN_GBL_ID+1)
|
(QSE_AWK_MAX_GBL_ID-QSE_AWK_MIN_GBL_ID+1)
|
||||||
|
|
||||||
if (awk->tree.ngbls > awk->tree.nbgbls)
|
if (awk->tree.ngbls > awk->tree.ngbls_base)
|
||||||
{
|
{
|
||||||
/* this function is not allow after qse_awk_parse is called */
|
/* this function is not allow after qse_awk_parse is called */
|
||||||
SETERR (awk, QSE_AWK_ENOPER);
|
SETERR (awk, QSE_AWK_ENOPER);
|
||||||
@ -1633,7 +1610,7 @@ int qse_awk_delgbl (
|
|||||||
|
|
||||||
/* invalidate the name if deletion is requested.
|
/* invalidate the name if deletion is requested.
|
||||||
* this approach does not delete the entry.
|
* this approach does not delete the entry.
|
||||||
* if qse_awk_addgbl is called with the same name
|
* if qse_delgbl() is called with the same name
|
||||||
* again, the entry will be appended again.
|
* again, the entry will be appended again.
|
||||||
* never call this funciton unless it is really required. */
|
* never call this funciton unless it is really required. */
|
||||||
/*
|
/*
|
||||||
@ -1646,7 +1623,7 @@ int qse_awk_delgbl (
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static qse_awk_t* collect_gbls (qse_awk_t* awk)
|
static qse_awk_t* collect_globals (qse_awk_t* awk)
|
||||||
{
|
{
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
@ -1656,7 +1633,7 @@ static qse_awk_t* collect_gbls (qse_awk_t* awk)
|
|||||||
return QSE_NULL;
|
return QSE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (add_gbl (
|
if (add_global (
|
||||||
awk,
|
awk,
|
||||||
QSE_STR_PTR(awk->token.name),
|
QSE_STR_PTR(awk->token.name),
|
||||||
QSE_STR_LEN(awk->token.name),
|
QSE_STR_LEN(awk->token.name),
|
||||||
@ -1681,7 +1658,7 @@ static qse_awk_t* collect_gbls (qse_awk_t* awk)
|
|||||||
return awk;
|
return awk;
|
||||||
}
|
}
|
||||||
|
|
||||||
static qse_awk_t* collect_lcls (
|
static qse_awk_t* collect_locals (
|
||||||
qse_awk_t* awk, qse_size_t nlcls, qse_bool_t istop)
|
qse_awk_t* awk, qse_size_t nlcls, qse_bool_t istop)
|
||||||
{
|
{
|
||||||
qse_xstr_t lcl;
|
qse_xstr_t lcl;
|
||||||
@ -1698,51 +1675,15 @@ static qse_awk_t* collect_lcls (
|
|||||||
lcl.ptr = QSE_STR_PTR(awk->token.name);
|
lcl.ptr = QSE_STR_PTR(awk->token.name);
|
||||||
lcl.len = QSE_STR_LEN(awk->token.name);
|
lcl.len = QSE_STR_LEN(awk->token.name);
|
||||||
|
|
||||||
#if 0
|
/* check if it conflict with a builtin function name
|
||||||
if (awk->option & QSE_AWK_UNIQUEFN)
|
* function f() { lcl length; } */
|
||||||
|
if (qse_awk_getfnc (awk, lcl.ptr, lcl.len) != QSE_NULL)
|
||||||
{
|
{
|
||||||
qse_bool_t iscur = QSE_FALSE;
|
SETERRARG (
|
||||||
#endif
|
awk, QSE_AWK_EFNCRED, awk->token.line,
|
||||||
|
lcl.ptr, lcl.len);
|
||||||
/* check if it conflict with a builtin function name
|
return QSE_NULL;
|
||||||
* function f() { lcl length; } */
|
|
||||||
if (qse_awk_getfnc (awk, lcl.ptr, lcl.len) != QSE_NULL)
|
|
||||||
{
|
|
||||||
SETERRARG (
|
|
||||||
awk, QSE_AWK_EFNCRED, awk->token.line,
|
|
||||||
lcl.ptr, lcl.len);
|
|
||||||
return QSE_NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
/* check if it conflict with a function name */
|
|
||||||
if (awk->tree.cur_fun.ptr != QSE_NULL)
|
|
||||||
{
|
|
||||||
iscur = (qse_strxncmp (
|
|
||||||
awk->tree.cur_fun.ptr, awk->tree.cur_fun.len,
|
|
||||||
lcl.ptr, lcl.len) == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (iscur || qse_map_search (awk->tree.funs, lcl.ptr, lcl.len) != QSE_NULL)
|
|
||||||
{
|
|
||||||
SETERRARG (
|
|
||||||
awk, QSE_AWK_EFUNRED, awk->token.line,
|
|
||||||
lcl.ptr, lcl.len);
|
|
||||||
return QSE_NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check if it conflict with a function name
|
|
||||||
* caught in the function call table */
|
|
||||||
if (qse_map_search (awk->parse.funs,
|
|
||||||
lcl.ptr, lcl.len) != QSE_NULL)
|
|
||||||
{
|
|
||||||
SETERRARG (
|
|
||||||
awk, QSE_AWK_EFUNRED, awk->token.line,
|
|
||||||
lcl.ptr, lcl.len);
|
|
||||||
return QSE_NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
if (istop)
|
if (istop)
|
||||||
{
|
{
|
||||||
@ -1760,7 +1701,7 @@ static qse_awk_t* collect_lcls (
|
|||||||
/* check if it conflicts with other local variable names */
|
/* check if it conflicts with other local variable names */
|
||||||
n = qse_lda_search (
|
n = qse_lda_search (
|
||||||
awk->parse.lcls,
|
awk->parse.lcls,
|
||||||
nlcls, /*((awk->option&QSE_AWK_SHADING)? nlcls:0)*/
|
nlcls,
|
||||||
lcl.ptr, lcl.len);
|
lcl.ptr, lcl.len);
|
||||||
if (n != QSE_LDA_NIL)
|
if (n != QSE_LDA_NIL)
|
||||||
{
|
{
|
||||||
@ -1771,10 +1712,10 @@ static qse_awk_t* collect_lcls (
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* check if it conflicts with global variable names */
|
/* check if it conflicts with global variable names */
|
||||||
n = find_gbl (awk, lcl.ptr, lcl.len);
|
n = find_global (awk, lcl.ptr, lcl.len);
|
||||||
if (n != QSE_LDA_NIL)
|
if (n != QSE_LDA_NIL)
|
||||||
{
|
{
|
||||||
if (n < awk->tree.nbgbls)
|
if (n < awk->tree.ngbls_base)
|
||||||
{
|
{
|
||||||
/* conflicting with a static global variable */
|
/* conflicting with a static global variable */
|
||||||
SETERRARG (
|
SETERRARG (
|
||||||
@ -1782,17 +1723,6 @@ static qse_awk_t* collect_lcls (
|
|||||||
lcl.ptr, lcl.len);
|
lcl.ptr, lcl.len);
|
||||||
return QSE_NULL;
|
return QSE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
if (!(awk->option & QSE_AWK_SHADING))
|
|
||||||
{
|
|
||||||
/* conflicting with a normal global variable */
|
|
||||||
SETERRARG (
|
|
||||||
awk, QSE_AWK_EDUPLCL, awk->token.line,
|
|
||||||
lcl.ptr, lcl.len);
|
|
||||||
return QSE_NULL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (QSE_LDA_SIZE(awk->parse.lcls) >= QSE_AWK_MAX_LCLS)
|
if (QSE_LDA_SIZE(awk->parse.lcls) >= QSE_AWK_MAX_LCLS)
|
||||||
@ -3305,7 +3235,7 @@ static qse_awk_nde_t* parse_primary_ident (qse_awk_t* awk, qse_size_t line)
|
|||||||
if (MATCH(awk,TOKEN_LPAREN))
|
if (MATCH(awk,TOKEN_LPAREN))
|
||||||
{
|
{
|
||||||
/* a local variable is not a function */
|
/* a local variable is not a function */
|
||||||
SETERRARG (awk, QSE_AWK_EFNNAME, line, name_dup, name_len);
|
SETERRARG (awk, QSE_AWK_EFUNNAME, line, name_dup, name_len);
|
||||||
QSE_AWK_FREE (awk, name_dup);
|
QSE_AWK_FREE (awk, name_dup);
|
||||||
return QSE_NULL;
|
return QSE_NULL;
|
||||||
}
|
}
|
||||||
@ -3339,7 +3269,7 @@ static qse_awk_nde_t* parse_primary_ident (qse_awk_t* awk, qse_size_t line)
|
|||||||
if (MATCH(awk,TOKEN_LPAREN))
|
if (MATCH(awk,TOKEN_LPAREN))
|
||||||
{
|
{
|
||||||
/* a parameter is not a function */
|
/* a parameter is not a function */
|
||||||
SETERRARG (awk, QSE_AWK_EFNNAME, line, name_dup, name_len);
|
SETERRARG (awk, QSE_AWK_EFUNNAME, line, name_dup, name_len);
|
||||||
QSE_AWK_FREE (awk, name_dup);
|
QSE_AWK_FREE (awk, name_dup);
|
||||||
return QSE_NULL;
|
return QSE_NULL;
|
||||||
}
|
}
|
||||||
@ -3364,7 +3294,7 @@ static qse_awk_nde_t* parse_primary_ident (qse_awk_t* awk, qse_size_t line)
|
|||||||
|
|
||||||
return (qse_awk_nde_t*)nde;
|
return (qse_awk_nde_t*)nde;
|
||||||
}
|
}
|
||||||
else if ((idxa = get_gbl (awk, name_dup, name_len)) != QSE_LDA_NIL)
|
else if ((idxa = get_global (awk, name_dup, name_len)) != QSE_LDA_NIL)
|
||||||
{
|
{
|
||||||
/* global variable */
|
/* global variable */
|
||||||
|
|
||||||
@ -3373,7 +3303,7 @@ static qse_awk_nde_t* parse_primary_ident (qse_awk_t* awk, qse_size_t line)
|
|||||||
if (MATCH(awk,TOKEN_LPAREN))
|
if (MATCH(awk,TOKEN_LPAREN))
|
||||||
{
|
{
|
||||||
/* a global variable is not a function */
|
/* a global variable is not a function */
|
||||||
SETERRARG (awk, QSE_AWK_EFNNAME, line, name_dup, name_len);
|
SETERRARG (awk, QSE_AWK_EFUNNAME, line, name_dup, name_len);
|
||||||
QSE_AWK_FREE (awk, name_dup);
|
QSE_AWK_FREE (awk, name_dup);
|
||||||
return QSE_NULL;
|
return QSE_NULL;
|
||||||
}
|
}
|
||||||
@ -3435,45 +3365,38 @@ static qse_awk_nde_t* parse_primary_ident (qse_awk_t* awk, qse_size_t line)
|
|||||||
|
|
||||||
if (awk->option & QSE_AWK_IMPLICIT)
|
if (awk->option & QSE_AWK_IMPLICIT)
|
||||||
{
|
{
|
||||||
#if 0
|
qse_bool_t iscur = QSE_FALSE;
|
||||||
if (awk->option & QSE_AWK_UNIQUEFN)
|
|
||||||
|
/* the name should not conflict with a function name */
|
||||||
|
/* check if it is a builtin function */
|
||||||
|
if (qse_awk_getfnc (awk, name_dup, name_len) != QSE_NULL)
|
||||||
{
|
{
|
||||||
#endif
|
SETERRARG (awk, QSE_AWK_EFNCRED, line, name_dup, name_len);
|
||||||
qse_bool_t iscur = QSE_FALSE;
|
goto exit_func;
|
||||||
|
}
|
||||||
/* the name should not conflict with a function name */
|
|
||||||
/* check if it is a builtin function */
|
/* check if it is an AWK function */
|
||||||
if (qse_awk_getfnc (awk, name_dup, name_len) != QSE_NULL)
|
if (awk->tree.cur_fun.ptr != QSE_NULL)
|
||||||
{
|
{
|
||||||
SETERRARG (awk, QSE_AWK_EFNCRED, line, name_dup, name_len);
|
iscur = (qse_strxncmp (
|
||||||
goto exit_func;
|
awk->tree.cur_fun.ptr, awk->tree.cur_fun.len,
|
||||||
}
|
name_dup, name_len) == 0);
|
||||||
|
}
|
||||||
/* check if it is an AWK function */
|
|
||||||
if (awk->tree.cur_fun.ptr != QSE_NULL)
|
if (iscur || qse_map_search (awk->tree.funs, name_dup, name_len) != QSE_NULL)
|
||||||
{
|
{
|
||||||
iscur = (qse_strxncmp (
|
/* the function is defined previously */
|
||||||
awk->tree.cur_fun.ptr, awk->tree.cur_fun.len,
|
SETERRARG (awk, QSE_AWK_EFUNRED, line, name_dup, name_len);
|
||||||
name_dup, name_len) == 0);
|
goto exit_func;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iscur || qse_map_search (awk->tree.funs, name_dup, name_len) != QSE_NULL)
|
if (qse_map_search (awk->parse.funs,
|
||||||
{
|
name_dup, name_len) != QSE_NULL)
|
||||||
/* the function is defined previously */
|
{
|
||||||
SETERRARG (awk, QSE_AWK_EFUNRED, line, name_dup, name_len);
|
/* is it one of the function calls found so far? */
|
||||||
goto exit_func;
|
SETERRARG (awk, QSE_AWK_EFUNRED, line, name_dup, name_len);
|
||||||
}
|
goto exit_func;
|
||||||
|
|
||||||
if (qse_map_search (awk->parse.funs,
|
|
||||||
name_dup, name_len) != QSE_NULL)
|
|
||||||
{
|
|
||||||
/* is it one of the function calls found so far? */
|
|
||||||
SETERRARG (awk, QSE_AWK_EFUNRED, line, name_dup, name_len);
|
|
||||||
goto exit_func;
|
|
||||||
}
|
|
||||||
#if 0
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
nde->type = QSE_AWK_NDE_NAMED;
|
nde->type = QSE_AWK_NDE_NAMED;
|
||||||
nde->line = line;
|
nde->line = line;
|
||||||
@ -3607,7 +3530,7 @@ static qse_awk_nde_t* parse_hashidx (
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* gets the global variable index */
|
/* gets the global variable index */
|
||||||
idxa = get_gbl (awk, name, name_len);
|
idxa = get_global (awk, name, name_len);
|
||||||
if (idxa != QSE_LDA_NIL)
|
if (idxa != QSE_LDA_NIL)
|
||||||
{
|
{
|
||||||
nde->type = QSE_AWK_NDE_GBLIDX;
|
nde->type = QSE_AWK_NDE_GBLIDX;
|
||||||
@ -3624,44 +3547,37 @@ static qse_awk_nde_t* parse_hashidx (
|
|||||||
|
|
||||||
if (awk->option & QSE_AWK_IMPLICIT)
|
if (awk->option & QSE_AWK_IMPLICIT)
|
||||||
{
|
{
|
||||||
#if 0
|
qse_bool_t iscur = QSE_FALSE;
|
||||||
if (awk->option & QSE_AWK_UNIQUEFN)
|
|
||||||
|
/* check if it is a builtin function */
|
||||||
|
if (qse_awk_getfnc (awk, name, name_len) != QSE_NULL)
|
||||||
{
|
{
|
||||||
#endif
|
SETERRARG (awk, QSE_AWK_EFNCRED, line, name, name_len);
|
||||||
qse_bool_t iscur = QSE_FALSE;
|
goto exit_func;
|
||||||
|
}
|
||||||
/* check if it is a builtin function */
|
|
||||||
if (qse_awk_getfnc (awk, name, name_len) != QSE_NULL)
|
/* check if it is an AWK function */
|
||||||
{
|
if (awk->tree.cur_fun.ptr != QSE_NULL)
|
||||||
SETERRARG (awk, QSE_AWK_EFNCRED, line, name, name_len);
|
{
|
||||||
goto exit_func;
|
iscur = (qse_strxncmp (
|
||||||
}
|
awk->tree.cur_fun.ptr, awk->tree.cur_fun.len,
|
||||||
|
name, name_len) == 0);
|
||||||
/* check if it is an AWK function */
|
}
|
||||||
if (awk->tree.cur_fun.ptr != QSE_NULL)
|
|
||||||
{
|
if (iscur || qse_map_search (awk->tree.funs, name, name_len) != QSE_NULL)
|
||||||
iscur = (qse_strxncmp (
|
{
|
||||||
awk->tree.cur_fun.ptr, awk->tree.cur_fun.len,
|
/* the function is defined previously */
|
||||||
name, name_len) == 0);
|
SETERRARG (awk, QSE_AWK_EFUNRED, line, name, name_len);
|
||||||
}
|
goto exit_func;
|
||||||
|
}
|
||||||
if (iscur || qse_map_search (awk->tree.funs, name, name_len) != QSE_NULL)
|
|
||||||
{
|
if (qse_map_search (
|
||||||
/* the function is defined previously */
|
awk->parse.funs, name, name_len) != QSE_NULL)
|
||||||
SETERRARG (awk, QSE_AWK_EFUNRED, line, name, name_len);
|
{
|
||||||
goto exit_func;
|
/* is it one of the function calls found so far? */
|
||||||
}
|
SETERRARG (awk, QSE_AWK_EFUNRED, line, name, name_len);
|
||||||
|
goto exit_func;
|
||||||
if (qse_map_search (
|
|
||||||
awk->parse.funs, name, name_len) != QSE_NULL)
|
|
||||||
{
|
|
||||||
/* is it one of the function calls found so far? */
|
|
||||||
SETERRARG (awk, QSE_AWK_EFUNRED, line, name, name_len);
|
|
||||||
goto exit_func;
|
|
||||||
}
|
|
||||||
#if 0
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
nde->type = QSE_AWK_NDE_NAMEDIDX;
|
nde->type = QSE_AWK_NDE_NAMEDIDX;
|
||||||
nde->line = line;
|
nde->line = line;
|
||||||
@ -3796,26 +3712,16 @@ static qse_awk_nde_t* parse_fncall (
|
|||||||
call->args = head;
|
call->args = head;
|
||||||
call->nargs = nargs;
|
call->nargs = nargs;
|
||||||
|
|
||||||
#if 0
|
/* store a non-builtin function call into the parse.funs table */
|
||||||
if (((awk->option & QSE_AWK_EXPLICIT) &&
|
if (qse_map_upsert (
|
||||||
!(awk->option & QSE_AWK_IMPLICIT)) /*||
|
awk->parse.funs, name, name_len,
|
||||||
(awk->option & QSE_AWK_UNIQUEFN)*/)
|
&line, QSE_SIZEOF(line)) == QSE_NULL)
|
||||||
{
|
{
|
||||||
#endif
|
QSE_AWK_FREE (awk, call);
|
||||||
|
if (head != QSE_NULL) qse_awk_clrpt (awk, head);
|
||||||
/* store a non-builtin function call into the parse.funs table */
|
SETERRLIN (awk, QSE_AWK_ENOMEM, line);
|
||||||
if (qse_map_upsert (
|
return QSE_NULL;
|
||||||
awk->parse.funs, name, name_len,
|
|
||||||
&line, QSE_SIZEOF(line)) == QSE_NULL)
|
|
||||||
{
|
|
||||||
QSE_AWK_FREE (awk, call);
|
|
||||||
if (head != QSE_NULL) qse_awk_clrpt (awk, head);
|
|
||||||
SETERRLIN (awk, QSE_AWK_ENOMEM, line);
|
|
||||||
return QSE_NULL;
|
|
||||||
}
|
|
||||||
#if 0
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (qse_awk_nde_t*)call;
|
return (qse_awk_nde_t*)call;
|
||||||
@ -5563,7 +5469,6 @@ static int classify_ident (
|
|||||||
|
|
||||||
if (qse_strxncmp (k, l, name, len) == 0)
|
if (qse_strxncmp (k, l, name, len) == 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
return kwp->type;
|
return kwp->type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -5671,7 +5576,7 @@ static int deparse (qse_awk_t* awk)
|
|||||||
|
|
||||||
#define EXIT_DEPARSE() do { n = -1; goto exit_deparse; } while(0)
|
#define EXIT_DEPARSE() do { n = -1; goto exit_deparse; } while(0)
|
||||||
|
|
||||||
if (awk->tree.ngbls > awk->tree.nbgbls)
|
if (awk->tree.ngbls > awk->tree.ngbls_base)
|
||||||
{
|
{
|
||||||
qse_size_t i, len;
|
qse_size_t i, len;
|
||||||
|
|
||||||
@ -5687,7 +5592,7 @@ static int deparse (qse_awk_t* awk)
|
|||||||
EXIT_DEPARSE ();
|
EXIT_DEPARSE ();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = awk->tree.nbgbls; i < awk->tree.ngbls - 1; i++)
|
for (i = awk->tree.ngbls_base; i < awk->tree.ngbls - 1; i++)
|
||||||
{
|
{
|
||||||
if ((awk->option & QSE_AWK_EXPLICIT) &&
|
if ((awk->option & QSE_AWK_EXPLICIT) &&
|
||||||
!(awk->option & QSE_AWK_IMPLICIT))
|
!(awk->option & QSE_AWK_IMPLICIT))
|
||||||
|
@ -55,11 +55,10 @@ int qse_awk_putsrcstr (qse_awk_t* awk, const qse_char_t* str);
|
|||||||
int qse_awk_putsrcstrx (
|
int qse_awk_putsrcstrx (
|
||||||
qse_awk_t* awk, const qse_char_t* str, qse_size_t len);
|
qse_awk_t* awk, const qse_char_t* str, qse_size_t len);
|
||||||
|
|
||||||
const qse_char_t* qse_awk_rtx_getgblname (
|
const qse_char_t* qse_awk_getgblname (
|
||||||
qse_awk_t* awk, qse_size_t idx, qse_size_t* len);
|
qse_awk_t* awk, qse_size_t idx, qse_size_t* len);
|
||||||
qse_cstr_t* qse_awk_getkw (qse_awk_t* awk, int id, qse_cstr_t* s);
|
qse_cstr_t* qse_awk_getkw (qse_awk_t* awk, int id, qse_cstr_t* s);
|
||||||
|
|
||||||
|
|
||||||
int qse_awk_initgbls (qse_awk_t* awk);
|
int qse_awk_initgbls (qse_awk_t* awk);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -50,12 +50,12 @@ enum exit_level_t
|
|||||||
EXIT_ABORT
|
EXIT_ABORT
|
||||||
};
|
};
|
||||||
|
|
||||||
#define DEFAULT_CONVFMT QSE_T("%.6g")
|
#define DEFAULT_CONVFMT QSE_T("%.6g")
|
||||||
#define DEFAULT_OFMT QSE_T("%.6g")
|
#define DEFAULT_OFMT QSE_T("%.6g")
|
||||||
#define DEFAULT_OFS QSE_T(" ")
|
#define DEFAULT_OFS QSE_T(" ")
|
||||||
#define DEFAULT_ORS QSE_T("\n")
|
#define DEFAULT_ORS QSE_T("\n")
|
||||||
#define DEFAULT_ORS_CRLF QSE_T("\r\n")
|
#define DEFAULT_ORS_CRLF QSE_T("\r\n")
|
||||||
#define DEFAULT_SUBSEP QSE_T("\034")
|
#define DEFAULT_SUBSEP QSE_T("\034")
|
||||||
|
|
||||||
/* the index of a positional variable should be a positive interger
|
/* the index of a positional variable should be a positive interger
|
||||||
* equal to or less than the maximum value of the type by which
|
* equal to or less than the maximum value of the type by which
|
||||||
@ -183,7 +183,7 @@ static qse_awk_val_t* eval_incpre (qse_awk_rtx_t* run, qse_awk_nde_t* nde);
|
|||||||
static qse_awk_val_t* eval_incpst (qse_awk_rtx_t* run, qse_awk_nde_t* nde);
|
static qse_awk_val_t* eval_incpst (qse_awk_rtx_t* run, qse_awk_nde_t* nde);
|
||||||
static qse_awk_val_t* eval_cnd (qse_awk_rtx_t* run, qse_awk_nde_t* nde);
|
static qse_awk_val_t* eval_cnd (qse_awk_rtx_t* run, qse_awk_nde_t* nde);
|
||||||
|
|
||||||
static qse_awk_val_t* eval_fun_intrinsic (
|
static qse_awk_val_t* eval_fun_ex (
|
||||||
qse_awk_rtx_t* run, qse_awk_nde_t* nde,
|
qse_awk_rtx_t* run, qse_awk_nde_t* nde,
|
||||||
void(*errhandler)(void*), void* eharg);
|
void(*errhandler)(void*), void* eharg);
|
||||||
|
|
||||||
@ -281,7 +281,7 @@ static int set_gbl (
|
|||||||
/* qse_awk_rtx_setgbl has been called */
|
/* qse_awk_rtx_setgbl has been called */
|
||||||
qse_cstr_t errarg;
|
qse_cstr_t errarg;
|
||||||
|
|
||||||
errarg.ptr = qse_awk_rtx_getgblname (
|
errarg.ptr = qse_awk_getgblname (
|
||||||
run->awk, idx, &errarg.len);
|
run->awk, idx, &errarg.len);
|
||||||
qse_awk_rtx_seterror (run,
|
qse_awk_rtx_seterror (run,
|
||||||
QSE_AWK_EMAPTOSCALAR, 0, &errarg, 1);
|
QSE_AWK_EMAPTOSCALAR, 0, &errarg, 1);
|
||||||
@ -1552,8 +1552,12 @@ static int qse_awk_runfunc (qse_awk_rtx_t* run, const qse_char_t* name)
|
|||||||
|
|
||||||
crdata.run = run;
|
crdata.run = run;
|
||||||
crdata.val = QSE_NULL;
|
crdata.val = QSE_NULL;
|
||||||
v = eval_fun_intrinsic (run, (qse_awk_nde_t*)&nde,
|
v = eval_fun_ex (
|
||||||
capture_retval_on_exit, &crdata);
|
run,
|
||||||
|
(qse_awk_nde_t*)&nde,
|
||||||
|
capture_retval_on_exit,
|
||||||
|
&crdata
|
||||||
|
);
|
||||||
if (v == QSE_NULL)
|
if (v == QSE_NULL)
|
||||||
{
|
{
|
||||||
if (crdata.val == QSE_NULL)
|
if (crdata.val == QSE_NULL)
|
||||||
@ -1770,8 +1774,12 @@ static int ____run_main_to_be_removed____ (
|
|||||||
|
|
||||||
crdata.run = run;
|
crdata.run = run;
|
||||||
crdata.val = QSE_NULL;
|
crdata.val = QSE_NULL;
|
||||||
v = eval_fun_intrinsic (run, (qse_awk_nde_t*)&nde,
|
v = eval_fun_ex (
|
||||||
capture_retval_on_exit, &crdata);
|
run,
|
||||||
|
(qse_awk_nde_t*)&nde,
|
||||||
|
capture_retval_on_exit,
|
||||||
|
&crdata
|
||||||
|
);
|
||||||
if (v == QSE_NULL)
|
if (v == QSE_NULL)
|
||||||
{
|
{
|
||||||
if (crdata.val == QSE_NULL)
|
if (crdata.val == QSE_NULL)
|
||||||
@ -3550,7 +3558,7 @@ static qse_awk_val_t* eval_expression (qse_awk_rtx_t* run, qse_awk_nde_t* nde)
|
|||||||
|
|
||||||
static qse_awk_val_t* eval_expression0 (qse_awk_rtx_t* run, qse_awk_nde_t* nde)
|
static qse_awk_val_t* eval_expression0 (qse_awk_rtx_t* run, qse_awk_nde_t* nde)
|
||||||
{
|
{
|
||||||
static eval_expr_t eval_func[] =
|
static eval_expr_t __evaluator[] =
|
||||||
{
|
{
|
||||||
/* the order of functions here should match the order
|
/* the order of functions here should match the order
|
||||||
* of node types declared in tree.h */
|
* of node types declared in tree.h */
|
||||||
@ -3581,11 +3589,10 @@ static qse_awk_val_t* eval_expression0 (qse_awk_rtx_t* run, qse_awk_nde_t* nde)
|
|||||||
|
|
||||||
qse_awk_val_t* v;
|
qse_awk_val_t* v;
|
||||||
|
|
||||||
|
|
||||||
QSE_ASSERT (nde->type >= QSE_AWK_NDE_GRP &&
|
QSE_ASSERT (nde->type >= QSE_AWK_NDE_GRP &&
|
||||||
(nde->type - QSE_AWK_NDE_GRP) < QSE_COUNTOF(eval_func));
|
(nde->type - QSE_AWK_NDE_GRP) < QSE_COUNTOF(__evaluator));
|
||||||
|
|
||||||
v = eval_func[nde->type-QSE_AWK_NDE_GRP] (run, nde);
|
v = __evaluator[nde->type-QSE_AWK_NDE_GRP] (run, nde);
|
||||||
|
|
||||||
if (v != QSE_NULL && run->exit_level >= EXIT_GLOBAL)
|
if (v != QSE_NULL && run->exit_level >= EXIT_GLOBAL)
|
||||||
{
|
{
|
||||||
@ -5806,7 +5813,7 @@ static qse_awk_val_t* eval_fnc (qse_awk_rtx_t* run, qse_awk_nde_t* nde)
|
|||||||
QSE_NULL, QSE_NULL, QSE_NULL);
|
QSE_NULL, QSE_NULL, QSE_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static qse_awk_val_t* eval_fun_intrinsic (
|
static qse_awk_val_t* eval_fun_ex (
|
||||||
qse_awk_rtx_t* run, qse_awk_nde_t* nde, void(*errhandler)(void*), void* eharg)
|
qse_awk_rtx_t* run, qse_awk_nde_t* nde, void(*errhandler)(void*), void* eharg)
|
||||||
{
|
{
|
||||||
qse_awk_nde_call_t* call = (qse_awk_nde_call_t*)nde;
|
qse_awk_nde_call_t* call = (qse_awk_nde_call_t*)nde;
|
||||||
@ -5823,7 +5830,7 @@ static qse_awk_val_t* eval_fun_intrinsic (
|
|||||||
errarg.len = call->what.fun.name.len,
|
errarg.len = call->what.fun.name.len,
|
||||||
|
|
||||||
qse_awk_rtx_seterror (run,
|
qse_awk_rtx_seterror (run,
|
||||||
QSE_AWK_EFNNONE, nde->line, &errarg, 1);
|
QSE_AWK_EFUNNONE, nde->line, &errarg, 1);
|
||||||
return QSE_NULL;
|
return QSE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5844,7 +5851,7 @@ static qse_awk_val_t* eval_fun_intrinsic (
|
|||||||
|
|
||||||
static qse_awk_val_t* eval_fun (qse_awk_rtx_t* run, qse_awk_nde_t* nde)
|
static qse_awk_val_t* eval_fun (qse_awk_rtx_t* run, qse_awk_nde_t* nde)
|
||||||
{
|
{
|
||||||
return eval_fun_intrinsic (run, nde, QSE_NULL, QSE_NULL);
|
return eval_fun_ex (run, nde, QSE_NULL, QSE_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* run->stack_base has not been set for this
|
/* run->stack_base has not been set for this
|
||||||
|
@ -415,7 +415,7 @@ static int print_expression (qse_awk_t* awk, qse_awk_nde_t* nde)
|
|||||||
* use the actual name */
|
* use the actual name */
|
||||||
PUT_SRCSTRX (awk, px->id.name.ptr, px->id.name.len);
|
PUT_SRCSTRX (awk, px->id.name.ptr, px->id.name.len);
|
||||||
}
|
}
|
||||||
else if (px->id.idxa < awk->tree.nbgbls)
|
else if (px->id.idxa < awk->tree.ngbls_base)
|
||||||
{
|
{
|
||||||
/* static global variables */
|
/* static global variables */
|
||||||
PUT_SRCSTRX (awk, px->id.name.ptr, px->id.name.len);
|
PUT_SRCSTRX (awk, px->id.name.ptr, px->id.name.len);
|
||||||
@ -453,7 +453,7 @@ static int print_expression (qse_awk_t* awk, qse_awk_nde_t* nde)
|
|||||||
* use the actual name */
|
* use the actual name */
|
||||||
PUT_SRCSTRX (awk, px->id.name.ptr, px->id.name.len);
|
PUT_SRCSTRX (awk, px->id.name.ptr, px->id.name.len);
|
||||||
}
|
}
|
||||||
else if (px->id.idxa < awk->tree.nbgbls)
|
else if (px->id.idxa < awk->tree.ngbls_base)
|
||||||
{
|
{
|
||||||
/* static global variables */
|
/* static global variables */
|
||||||
PUT_SRCSTRX (awk, px->id.name.ptr, px->id.name.len);
|
PUT_SRCSTRX (awk, px->id.name.ptr, px->id.name.len);
|
||||||
|
Loading…
Reference in New Issue
Block a user