enhanced the awk deparser to print @pragma stack_limit if different from the default settings.

defined QSE_AWK_MAX_DFL_STACK_LIMIT
This commit is contained in:
hyung-hwan 2019-06-10 04:57:51 +00:00
parent e8395f98da
commit d7940a7c5b
3 changed files with 24 additions and 7 deletions

View File

@ -76,6 +76,11 @@ typedef struct qse_awk_tree_t qse_awk_tree_t;
#define QSE_AWK_DFL_RTX_STACK_LIMIT 5120
#define QSE_AWK_MIN_RTX_STACK_LIMIT 512
#if (QSE_SIZEOF_VOID_P <= 4)
# define QSE_AWK_MAX_RTX_STACK_LIMIT ((qse_size_t)1 << (QSE_SIZEOF_VOID_P * 4 + 1))
#else
# define QSE_AWK_MAX_RTX_STACK_LIMIT ((qse_size_t)1 << (QSE_SIZEOF_VOID_P * 4))
#endif
#define QSE_AWK_ALLOC(awk,size) QSE_MMGR_ALLOC((awk)->mmgr,size)
#define QSE_AWK_REALLOC(awk,ptr,size) QSE_MMGR_REALLOC((awk)->mmgr,ptr,size)

View File

@ -484,6 +484,8 @@ int qse_awk_setopt (qse_awk_t* awk, qse_awk_opt_t id, const void* value)
case QSE_AWK_RTX_STACK_LIMIT:
awk->opt.rtx_stack_limit = *(const qse_size_t*)value;
if (awk->opt.rtx_stack_limit < QSE_AWK_MIN_RTX_STACK_LIMIT) awk->opt.rtx_stack_limit = QSE_AWK_MIN_RTX_STACK_LIMIT;
else if (awk->opt.rtx_stack_limit > QSE_AWK_MAX_RTX_STACK_LIMIT) awk->opt.rtx_stack_limit = QSE_AWK_MAX_RTX_STACK_LIMIT;
return 0;
}

View File

@ -990,8 +990,11 @@ static int parse_progunit (qse_awk_t* awk)
}
sl = qse_strxtolong(QSE_STR_PTR(awk->tok.name), QSE_STR_LEN(awk->tok.name), 10, QSE_NULL);
if (sl < QSE_AWK_MIN_RTX_STACK_LIMIT) sl = QSE_AWK_MIN_RTX_STACK_LIMIT;
else if (sl > QSE_AWK_MAX_RTX_STACK_LIMIT) sl = QSE_AWK_MAX_RTX_STACK_LIMIT;
/* take the specified value if it's greater than the existing value */
if (sl > awk->parse.pragma.rtx_stack_limit) awk->parse.pragma.rtx_stack_limit = sl;
}
else
{
@ -6558,17 +6561,25 @@ static int deparse (qse_awk_t* awk)
QSE_MEMSET (&awk->sio.arg, 0, QSE_SIZEOF(awk->sio.arg));
CLRERR (awk);
op = awk->sio.outf (
awk, QSE_AWK_SIO_OPEN, &awk->sio.arg, QSE_NULL, 0);
op = awk->sio.outf(awk, QSE_AWK_SIO_OPEN, &awk->sio.arg, QSE_NULL, 0);
if (op <= -1)
{
if (ISNOERR(awk))
SETERR_ARG (awk, QSE_AWK_EOPEN, QSE_T("<SOUT>"), 6);
if (ISNOERR(awk)) SETERR_ARG (awk, QSE_AWK_EOPEN, QSE_T("<SOUT>"), 6);
return -1;
}
#define EXIT_DEPARSE() do { n = -1; goto exit_deparse; } while(0)
if (awk->parse.pragma.rtx_stack_limit > 0 && awk->parse.pragma.rtx_stack_limit != awk->opt.rtx_stack_limit)
{
qse_size_t len;
len = qse_awk_inttostr(awk, (qse_awk_int_t)awk->parse.pragma.rtx_stack_limit, 10, QSE_NULL, tmp, QSE_COUNTOF(tmp));
if (qse_awk_putsrcstr(awk, QSE_T("@pragma stack_limit ")) <= -1 ||
qse_awk_putsrcstrn (awk, tmp, len) <= -1 ||
qse_awk_putsrcstr(awk, QSE_T(";\n")) <= -1) EXIT_DEPARSE ();
}
if (awk->tree.ngbls > awk->tree.ngbls_base)
{
qse_size_t i, len;
@ -6576,8 +6587,7 @@ static int deparse (qse_awk_t* awk)
QSE_ASSERT (awk->tree.ngbls > 0);
qse_awk_getkwname (awk, QSE_AWK_KWID_XGLOBAL, &kw);
if (qse_awk_putsrcstrn(awk,kw.ptr,kw.len) <= -1 ||
qse_awk_putsrcstr (awk, QSE_T(" ")) <= -1) EXIT_DEPARSE ();
if (qse_awk_putsrcstrn(awk, kw.ptr, kw.len) <= -1 || qse_awk_putsrcstr (awk, QSE_T(" ")) <= -1) EXIT_DEPARSE ();
for (i = awk->tree.ngbls_base; i < awk->tree.ngbls - 1; i++)
{
@ -6588,7 +6598,7 @@ static int deparse (qse_awk_t* awk)
}
else
{
len = qse_awk_inttostr (awk, (qse_awk_int_t)i, 10, QSE_T("__g"), tmp, QSE_COUNTOF(tmp));
len = qse_awk_inttostr(awk, (qse_awk_int_t)i, 10, QSE_T("__g"), tmp, QSE_COUNTOF(tmp));
QSE_ASSERT (len != (qse_size_t)-1);
if (qse_awk_putsrcstrn (awk, tmp, len) <= -1) EXIT_DEPARSE ();
}