diff --git a/ase/awk/rex.c b/ase/awk/rex.c index a1c74ef9..3b7e6948 100644 --- a/ase/awk/rex.c +++ b/ase/awk/rex.c @@ -1,5 +1,5 @@ /* - * $Id: rex.c,v 1.69 2007-02-28 11:00:32 bacon Exp $ + * $Id: rex.c,v 1.70 2007-02-28 11:04:16 bacon Exp $ * * {License} */ @@ -53,13 +53,13 @@ enum #define BOUND_MIN 0 #define BOUND_MAX (ASE_TYPE_MAX(ase_size_t)) -typedef struct __builder_t __builder_t; -typedef struct __matcher_t __matcher_t; +typedef struct builder_t builder_t; +typedef struct matcher_t matcher_t; typedef struct __match_t __match_t; #include -ASE_BEGIN_PACKED_STRUCT (__code_t) +ASE_BEGIN_PACKED_STRUCT (code_t) /*ase_byte_t cmd;*/ short cmd; short negate; /* only for CMD_CHARSET */ @@ -67,7 +67,7 @@ ASE_BEGIN_PACKED_STRUCT (__code_t) ase_size_t ubound; ASE_END_PACKED_STRUCT () -ASE_BEGIN_PACKED_STRUCT (__builder_t) +ASE_BEGIN_PACKED_STRUCT (builder_t) ase_awk_t* awk; struct @@ -98,7 +98,7 @@ ASE_BEGIN_PACKED_STRUCT (__builder_t) int errnum; ASE_END_PACKED_STRUCT () -ASE_BEGIN_PACKED_STRUCT (__matcher_t) +ASE_BEGIN_PACKED_STRUCT (matcher_t) ase_awk_t* awk; struct @@ -133,7 +133,7 @@ ASE_END_PACKED_STRUCT () #include typedef const ase_byte_t* (*atom_matcher_t) ( - __matcher_t* matcher, const ase_byte_t* base, __match_t* mat); + matcher_t* matcher, const ase_byte_t* base, __match_t* mat); #define NCHARS_REMAINING(rex) ((rex)->ptn.end - (rex)->ptn.curp) @@ -151,27 +151,27 @@ typedef const ase_byte_t* (*atom_matcher_t) ( #define SET_CODE(rex,pos,type,code) (GET_CODE(rex,pos,type) = (code)) #endif -static int __build_pattern (__builder_t* rex); -static int __build_pattern0 (__builder_t* rex); -static int __build_branch (__builder_t* rex); -static int __build_atom (__builder_t* rex); -static int __build_charset (__builder_t* rex, struct __code_t* cmd); -static int __build_occurrences (__builder_t* rex, struct __code_t* cmd); -static int __build_cclass (__builder_t* rex, ase_char_t* cc); -static int __build_range (__builder_t* rex, struct __code_t* cmd); -static int __next_char (__builder_t* rex, int level); -static int __add_code (__builder_t* rex, void* data, ase_size_t len); +static int __build_pattern (builder_t* rex); +static int __build_pattern0 (builder_t* rex); +static int __build_branch (builder_t* rex); +static int __build_atom (builder_t* rex); +static int __build_charset (builder_t* rex, struct code_t* cmd); +static int __build_occurrences (builder_t* rex, struct code_t* cmd); +static int __build_cclass (builder_t* rex, ase_char_t* cc); +static int __build_range (builder_t* rex, struct code_t* cmd); +static int __next_char (builder_t* rex, int level); +static int __add_code (builder_t* rex, void* data, ase_size_t len); #if defined(__sparc) || defined(__sparc__) -static ase_size_t __get_code (__builder_t* builder, ase_size_t pos) +static ase_size_t __get_code (builder_t* builder, ase_size_t pos) { ase_size_t code; ase_memcpy (&code, &builder->code.buf[pos], ASE_SIZEOF(code)); return code; } -static void __set_code (__builder_t* builder, ase_size_t pos, ase_size_t code) +static void __set_code (builder_t* builder, ase_size_t pos, ase_size_t code) { ase_memcpy (&builder->code.buf[pos], &code, ASE_SIZEOF(code)); } @@ -182,34 +182,34 @@ static ase_bool_t __begin_with ( const ase_char_t* str, ase_size_t len, const ase_char_t* what); static const ase_byte_t* __match_pattern ( - __matcher_t* matcher, const ase_byte_t* base, __match_t* mat); + matcher_t* matcher, const ase_byte_t* base, __match_t* mat); static const ase_byte_t* __match_branch ( - __matcher_t* matcher, const ase_byte_t* base, __match_t* mat); + matcher_t* matcher, const ase_byte_t* base, __match_t* mat); static const ase_byte_t* __match_branch_body ( - __matcher_t* matcher, const ase_byte_t* base, __match_t* mat); + matcher_t* matcher, const ase_byte_t* base, __match_t* mat); static const ase_byte_t* __match_branch_body0 ( - __matcher_t* matcher, const ase_byte_t* base, __match_t* mat); + matcher_t* matcher, const ase_byte_t* base, __match_t* mat); static const ase_byte_t* __match_atom ( - __matcher_t* matcher, const ase_byte_t* base, __match_t* mat); + matcher_t* matcher, const ase_byte_t* base, __match_t* mat); static const ase_byte_t* __match_bol ( - __matcher_t* matcher, const ase_byte_t* base, __match_t* mat); + matcher_t* matcher, const ase_byte_t* base, __match_t* mat); static const ase_byte_t* __match_eol ( - __matcher_t* matcher, const ase_byte_t* base, __match_t* mat); + matcher_t* matcher, const ase_byte_t* base, __match_t* mat); static const ase_byte_t* __match_any_char ( - __matcher_t* matcher, const ase_byte_t* base, __match_t* mat); + matcher_t* matcher, const ase_byte_t* base, __match_t* mat); static const ase_byte_t* __match_ord_char ( - __matcher_t* matcher, const ase_byte_t* base, __match_t* mat); + matcher_t* matcher, const ase_byte_t* base, __match_t* mat); static const ase_byte_t* __match_charset ( - __matcher_t* matcher, const ase_byte_t* base, __match_t* mat); + matcher_t* matcher, const ase_byte_t* base, __match_t* mat); static const ase_byte_t* __match_group ( - __matcher_t* matcher, const ase_byte_t* base, __match_t* mat); + matcher_t* matcher, const ase_byte_t* base, __match_t* mat); static const ase_byte_t* __match_occurrences ( - __matcher_t* matcher, ase_size_t si, const ase_byte_t* p, + matcher_t* matcher, ase_size_t si, const ase_byte_t* p, ase_size_t lbound, ase_size_t ubound, __match_t* mat); static ase_bool_t __test_charset ( - __matcher_t* matcher, const ase_byte_t* p, ase_size_t csc, ase_char_t c); + matcher_t* matcher, const ase_byte_t* p, ase_size_t csc, ase_char_t c); static ase_bool_t __cc_isalnum (ase_awk_t* awk, ase_char_t c); static ase_bool_t __cc_isalpha (ase_awk_t* awk, ase_char_t c); @@ -265,7 +265,7 @@ static struct __char_class_t __char_class[] = void* ase_awk_buildrex ( ase_awk_t* awk, const ase_char_t* ptn, ase_size_t len, int* errnum) { - __builder_t builder; + builder_t builder; builder.awk = awk; builder.code.capa = DEF_CODE_CAPA; @@ -329,7 +329,7 @@ int ase_awk_matchrex ( const ase_char_t* str, ase_size_t len, const ase_char_t** match_ptr, ase_size_t* match_len, int* errnum) { - __matcher_t matcher; + matcher_t matcher; __match_t mat; ase_size_t offset = 0; /*const ase_char_t* match_ptr_zero = ASE_NULL;*/ @@ -426,7 +426,7 @@ ase_bool_t ase_awk_isemptyrex (ase_awk_t* awk, void* code) return (nb == 1 && el == ASE_SIZEOF(ase_size_t)*4)? ase_true: ase_false; } -static int __build_pattern (__builder_t* builder) +static int __build_pattern (builder_t* builder) { int n; @@ -443,7 +443,7 @@ static int __build_pattern (__builder_t* builder) return n; } -static int __build_pattern0 (__builder_t* builder) +static int __build_pattern0 (builder_t* builder) { ase_size_t zero = 0; ase_size_t old_size; @@ -497,13 +497,13 @@ static int __build_pattern0 (__builder_t* builder) return 1; } -static int __build_branch (__builder_t* builder) +static int __build_branch (builder_t* builder) { int n; ase_size_t zero = 0; ase_size_t old_size; ase_size_t pos_na, pos_bl; - struct __code_t* cmd; + struct code_t* cmd; old_size = builder->code.size; @@ -515,7 +515,7 @@ static int __build_branch (__builder_t* builder) while (1) { - cmd = (struct __code_t*)&builder->code.buf[builder->code.size]; + cmd = (struct code_t*)&builder->code.buf[builder->code.size]; n = __build_atom (builder); if (n == -1) @@ -544,10 +544,10 @@ static int __build_branch (__builder_t* builder) return (builder->code.size == old_size)? 0: 1; } -static int __build_atom (__builder_t* builder) +static int __build_atom (builder_t* builder) { int n; - struct __code_t tmp; + struct code_t tmp; if (builder->ptn.curc.type == CT_EOF) return 0; @@ -599,9 +599,9 @@ static int __build_atom (__builder_t* builder) } else if (builder->ptn.curc.value == ASE_T('[')) { - struct __code_t* cmd; + struct code_t* cmd; - cmd = (struct __code_t*) + cmd = (struct code_t*) &builder->code.buf[builder->code.size]; tmp.cmd = CMD_CHARSET; @@ -650,7 +650,7 @@ static int __build_atom (__builder_t* builder) } } -static int __build_charset (__builder_t* builder, struct __code_t* cmd) +static int __build_charset (builder_t* builder, struct code_t* cmd) { ase_size_t zero = 0; ase_size_t old_size; @@ -757,7 +757,7 @@ static int __build_charset (__builder_t* builder, struct __code_t* cmd) return 1; } -static int __build_cclass (__builder_t* builder, ase_char_t* cc) +static int __build_cclass (builder_t* builder, ase_char_t* cc) { const struct __char_class_t* ccp = __char_class; ase_size_t len = builder->ptn.end - builder->ptn.curp; @@ -810,7 +810,7 @@ static int __build_cclass (__builder_t* builder, ase_char_t* cc) return 1; } -static int __build_occurrences (__builder_t* builder, struct __code_t* cmd) +static int __build_occurrences (builder_t* builder, struct code_t* cmd) { if (builder->ptn.curc.type != CT_SPECIAL) return 0; @@ -861,7 +861,7 @@ static int __build_occurrences (__builder_t* builder, struct __code_t* cmd) return 0; } -static int __build_range (__builder_t* builder, struct __code_t* cmd) +static int __build_range (builder_t* builder, struct code_t* cmd) { ase_size_t bound; @@ -906,7 +906,7 @@ what if it is not in the raight format? convert it to ordinary characters?? */ return 0; } -static int __next_char (__builder_t* builder, int level) +static int __next_char (builder_t* builder, int level) { if (builder->ptn.curp >= builder->ptn.end) { @@ -968,7 +968,7 @@ static int __next_char (__builder_t* builder, int level) return 0; } -static int __add_code (__builder_t* builder, void* data, ase_size_t len) +static int __add_code (builder_t* builder, void* data, ase_size_t len) { if (len > builder->code.capa - builder->code.size) { @@ -1032,7 +1032,7 @@ static ase_bool_t __begin_with ( } static const ase_byte_t* __match_pattern ( - __matcher_t* matcher, const ase_byte_t* base, __match_t* mat) + matcher_t* matcher, const ase_byte_t* base, __match_t* mat) { const ase_byte_t* p; __match_t mat2; @@ -1081,7 +1081,7 @@ static const ase_byte_t* __match_pattern ( } static const ase_byte_t* __match_branch ( - __matcher_t* matcher, const ase_byte_t* base, __match_t* mat) + matcher_t* matcher, const ase_byte_t* base, __match_t* mat) { /* * branch body (base+sizeof(NA)+sizeof(BL)---+ @@ -1098,7 +1098,7 @@ static const ase_byte_t* __match_branch ( } static const ase_byte_t* __match_branch_body ( - __matcher_t* matcher, const ase_byte_t* base, __match_t* mat) + matcher_t* matcher, const ase_byte_t* base, __match_t* mat) { const ase_byte_t* n; @@ -1116,7 +1116,7 @@ static const ase_byte_t* __match_branch_body ( } static const ase_byte_t* __match_branch_body0 ( - __matcher_t* matcher, const ase_byte_t* base, __match_t* mat) + matcher_t* matcher, const ase_byte_t* base, __match_t* mat) { const ase_byte_t* p; /* __match_t mat2;*/ @@ -1165,7 +1165,7 @@ static const ase_byte_t* __match_branch_body0 ( } static const ase_byte_t* __match_atom ( - __matcher_t* matcher, const ase_byte_t* base, __match_t* mat) + matcher_t* matcher, const ase_byte_t* base, __match_t* mat) { static atom_matcher_t matchers[] = { @@ -1178,19 +1178,19 @@ static const ase_byte_t* __match_atom ( }; ASE_AWK_ASSERT (matcher->awk, - ((struct __code_t*)base)->cmd >= 0 && - ((struct __code_t*)base)->cmd < ASE_COUNTOF(matchers)); + ((struct code_t*)base)->cmd >= 0 && + ((struct code_t*)base)->cmd < ASE_COUNTOF(matchers)); - return matchers[((struct __code_t*)base)->cmd] (matcher, base, mat); + return matchers[((struct code_t*)base)->cmd] (matcher, base, mat); } static const ase_byte_t* __match_bol ( - __matcher_t* matcher, const ase_byte_t* base, __match_t* mat) + matcher_t* matcher, const ase_byte_t* base, __match_t* mat) { const ase_byte_t* p = base; - const struct __code_t* cp; + const struct code_t* cp; - cp = (const struct __code_t*)p; p += ASE_SIZEOF(*cp); + cp = (const struct code_t*)p; p += ASE_SIZEOF(*cp); ASE_AWK_ASSERT (matcher->awk, cp->cmd == CMD_BOL); mat->matched = (mat->match_ptr == matcher->match.str.ptr || @@ -1201,12 +1201,12 @@ static const ase_byte_t* __match_bol ( } static const ase_byte_t* __match_eol ( - __matcher_t* matcher, const ase_byte_t* base, __match_t* mat) + matcher_t* matcher, const ase_byte_t* base, __match_t* mat) { const ase_byte_t* p = base; - const struct __code_t* cp; + const struct code_t* cp; - cp = (const struct __code_t*)p; p += ASE_SIZEOF(*cp); + cp = (const struct code_t*)p; p += ASE_SIZEOF(*cp); ASE_AWK_ASSERT (matcher->awk, cp->cmd == CMD_EOL); mat->matched = (mat->match_ptr == matcher->match.str.end || @@ -1217,13 +1217,13 @@ static const ase_byte_t* __match_eol ( } static const ase_byte_t* __match_any_char ( - __matcher_t* matcher, const ase_byte_t* base, __match_t* mat) + matcher_t* matcher, const ase_byte_t* base, __match_t* mat) { const ase_byte_t* p = base; - const struct __code_t* cp; + const struct code_t* cp; ase_size_t si = 0, lbound, ubound; - cp = (const struct __code_t*)p; p += ASE_SIZEOF(*cp); + cp = (const struct code_t*)p; p += ASE_SIZEOF(*cp); ASE_AWK_ASSERT (matcher->awk, cp->cmd == CMD_ANY_CHAR); lbound = cp->lbound; @@ -1234,10 +1234,10 @@ static const ase_byte_t* __match_any_char ( /* merge the same consecutive codes */ while (p < mat->branch_end && - cp->cmd == ((const struct __code_t*)p)->cmd) + cp->cmd == ((const struct code_t*)p)->cmd) { - lbound += ((const struct __code_t*)p)->lbound; - ubound += ((const struct __code_t*)p)->ubound; + lbound += ((const struct code_t*)p)->lbound; + ubound += ((const struct code_t*)p)->ubound; p += ASE_SIZEOF(*cp); } @@ -1269,14 +1269,14 @@ static const ase_byte_t* __match_any_char ( } static const ase_byte_t* __match_ord_char ( - __matcher_t* matcher, const ase_byte_t* base, __match_t* mat) + matcher_t* matcher, const ase_byte_t* base, __match_t* mat) { const ase_byte_t* p = base; - const struct __code_t* cp; + const struct code_t* cp; ase_size_t si = 0, lbound, ubound; ase_char_t cc; - cp = (const struct __code_t*)p; p += ASE_SIZEOF(*cp); + cp = (const struct code_t*)p; p += ASE_SIZEOF(*cp); ASE_AWK_ASSERT (matcher->awk, cp->cmd == CMD_ORD_CHAR); lbound = cp->lbound; @@ -1290,12 +1290,12 @@ static const ase_byte_t* __match_ord_char ( if (matcher->ignorecase) { while (p < mat->branch_end && - cp->cmd == ((const struct __code_t*)p)->cmd) + cp->cmd == ((const struct code_t*)p)->cmd) { if (ASE_AWK_TOUPPER (matcher->awk, *(ase_char_t*)(p+ASE_SIZEOF(*cp))) != cc) break; - lbound += ((const struct __code_t*)p)->lbound; - ubound += ((const struct __code_t*)p)->ubound; + lbound += ((const struct code_t*)p)->lbound; + ubound += ((const struct code_t*)p)->ubound; p += ASE_SIZEOF(*cp) + ASE_SIZEOF(cc); } @@ -1303,12 +1303,12 @@ static const ase_byte_t* __match_ord_char ( else { while (p < mat->branch_end && - cp->cmd == ((const struct __code_t*)p)->cmd) + cp->cmd == ((const struct code_t*)p)->cmd) { if (*(ase_char_t*)(p+ASE_SIZEOF(*cp)) != cc) break; - lbound += ((const struct __code_t*)p)->lbound; - ubound += ((const struct __code_t*)p)->ubound; + lbound += ((const struct code_t*)p)->lbound; + ubound += ((const struct code_t*)p)->ubound; p += ASE_SIZEOF(*cp) + ASE_SIZEOF(cc); } @@ -1368,15 +1368,15 @@ static const ase_byte_t* __match_ord_char ( } static const ase_byte_t* __match_charset ( - __matcher_t* matcher, const ase_byte_t* base, __match_t* mat) + matcher_t* matcher, const ase_byte_t* base, __match_t* mat) { const ase_byte_t* p = base; - const struct __code_t* cp; + const struct code_t* cp; ase_size_t si = 0, lbound, ubound, csc, csl; ase_bool_t n; ase_char_t c; - cp = (const struct __code_t*)p; p += ASE_SIZEOF(*cp); + cp = (const struct code_t*)p; p += ASE_SIZEOF(*cp); ASE_AWK_ASSERT (matcher->awk, cp->cmd == CMD_CHARSET); lbound = cp->lbound; @@ -1435,14 +1435,14 @@ static const ase_byte_t* __match_charset ( } static const ase_byte_t* __match_group ( - __matcher_t* matcher, const ase_byte_t* base, __match_t* mat) + matcher_t* matcher, const ase_byte_t* base, __match_t* mat) { const ase_byte_t* p = base; - const struct __code_t* cp; + const struct code_t* cp; __match_t mat2; ase_size_t si = 0, grp_len_static[16], * grp_len; - cp = (const struct __code_t*)p; p += ASE_SIZEOF(*cp); + cp = (const struct code_t*)p; p += ASE_SIZEOF(*cp); ASE_AWK_ASSERT (matcher->awk, cp->cmd == CMD_GROUP); mat->matched = ase_false; @@ -1568,7 +1568,7 @@ static const ase_byte_t* __match_group ( } static const ase_byte_t* __match_occurrences ( - __matcher_t* matcher, ase_size_t si, const ase_byte_t* p, + matcher_t* matcher, ase_size_t si, const ase_byte_t* p, ase_size_t lbound, ase_size_t ubound, __match_t* mat) { ASE_AWK_ASSERT (matcher->awk, si >= lbound && si <= ubound); @@ -1660,7 +1660,7 @@ static const ase_byte_t* __match_occurrences ( } static ase_bool_t __test_charset ( - __matcher_t* matcher, const ase_byte_t* p, ase_size_t csc, ase_char_t c) + matcher_t* matcher, const ase_byte_t* p, ase_size_t csc, ase_char_t c) { ase_size_t i; @@ -1835,7 +1835,7 @@ static const ase_byte_t* __print_branch (ase_awk_t* awk, const ase_byte_t* p) static const ase_byte_t* __print_atom (ase_awk_t* awk, const ase_byte_t* p) { - const struct __code_t* cp = (const struct __code_t*)p; + const struct code_t* cp = (const struct code_t*)p; if (cp->cmd == CMD_BOL) { diff --git a/ase/awk/rex.h b/ase/awk/rex.h index dc7d1671..d4ed2f48 100644 --- a/ase/awk/rex.h +++ b/ase/awk/rex.h @@ -1,5 +1,5 @@ /* - * $Id: rex.h,v 1.26 2007-02-03 10:47:41 bacon Exp $ + * $Id: rex.h,v 1.27 2007-02-28 11:00:32 bacon Exp $ * * {License} */ @@ -66,9 +66,7 @@ void ase_awk_freerex (ase_awk_t* awk, void* code); ase_bool_t ase_awk_isemptyrex (ase_awk_t* awk, void* code); -#ifdef DEBUG_REX -void ase_awk_printrex (ase_awk_t* awk, void* rex); -#endif +void ase_awk_dprintrex (ase_awk_t* awk, void* rex); #ifdef __cplusplus } diff --git a/ase/awk/run.c b/ase/awk/run.c index a66cfa50..6c3eaa6d 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -1,11 +1,15 @@ /* - * $Id: run.c,v 1.330 2007-02-24 14:31:44 bacon Exp $ + * $Id: run.c,v 1.331 2007-02-28 11:00:33 bacon Exp $ * * {License} */ #include +#ifdef DEBUG_RUN +#include +#endif + #define CMP_ERROR -99 #define DEF_BUF_CAPA 256 #define STACK_INCREMENT 512 @@ -1755,7 +1759,12 @@ static int __run_block0 (ase_awk_run_t* run, ase_awk_nde_blk_t* nde) p = nde->body; nlocals = nde->nlocals; -/*run->awk->prmfns.dprintf (ASE_T("securing space for local variables nlocals = %d\n"), (int)nlocals);*/ +#ifdef DEBUG_RUN + ase_dprintf ( + ASE_T("securing space for local variables nlocals = %d\n"), + (int)nlocals); +#endif + saved_stack_top = run->stack_top; /* secure space for local variables */ @@ -1772,10 +1781,17 @@ static int __run_block0 (ase_awk_run_t* run, ase_awk_nde_blk_t* nde) /* refupval is not required for ase_awk_val_nil */ } -/*run->awk->prmfns.dprintf (ASE_T("executing block statements\n"));*/ +#ifdef DEBUG_RUN + ase_dprintf (ASE_T("executing block statements\n")); +#endif + while (p != ASE_NULL && run->exit_level == EXIT_NONE) { -/*run->awk->prmfns.dprintf (ASE_T("running a statement\n"));*/ +#ifdef DEBUG_RUN + ase_dprintf (ASE_T("running a statement of type %d at line %d\n"), + (int)p->type, (int)p->line); +#endif + if (__run_statement (run, p) == -1) { n = -1; @@ -1784,8 +1800,10 @@ static int __run_block0 (ase_awk_run_t* run, ase_awk_nde_blk_t* nde) p = p->next; } -/*run->awk->prmfns.dprintf (ASE_T("popping off local variables\n"));*/ /* pop off local variables */ +#ifdef DEBUG_RUN + ase_dprintf (ASE_T("popping off local variables\n")); +#endif nlocals = nde->nlocals; while (nlocals > 0) { @@ -2210,14 +2228,12 @@ static int __run_return (ase_awk_run_t* run, ase_awk_nde_return_t* nde) * by the parser first of all */ ASE_AWK_ASSERT (run->awk, nde->val->next == ASE_NULL); -/*run->awk->prmfns.dprintf (ASE_T("returning....\n"));*/ val = __eval_expression (run, nde->val); if (val == ASE_NULL) return -1; ase_awk_refdownval (run, STACK_RETVAL(run)); STACK_RETVAL(run) = val; ase_awk_refupval (run, val); /* see __eval_call for the trick */ -/*run->awk->prmfns.dprintf (ASE_T("set return value....\n"));*/ } run->exit_level = EXIT_FUNCTION; @@ -3281,7 +3297,11 @@ static ase_awk_val_t* __do_assignment_map ( str = __idxnde_to_str (run, var->idx, &len); if (str == ASE_NULL) return ASE_NULL; -/*run->awk->prmfns.dprintf (ASE_T("**** index str=>%s, map->ref=%d, map->type=%d\n"), str, (int)map->ref, (int)map->type);*/ +#ifdef DEBUG_RUN + ase_dprintf (ASE_T("**** index str=>%s, map->ref=%d, map->type=%d\n"), + str, (int)map->ref, (int)map->type); +#endif + n = ase_awk_map_putx (map->map, str, len, val, ASE_NULL); if (n < 0) { @@ -5300,8 +5320,9 @@ static ase_awk_val_t* __eval_afn (ase_awk_run_t* run, ase_awk_nde_t* nde) /* run->stack_base has not been set for this - * stack frame. so STACK_ARG cannot be used */ -/*ase_awk_refdownval (run, STACK_ARG(run,nargs));*/ + * stack frame. so the STACK_ARG macro cannot be used as in + * ase_awk_refdownval (run, STACK_ARG(run,nargs));*/ + #define UNWIND_RUN_STACK(run,nargs) \ do { \ while ((nargs) > 0) \ @@ -5375,7 +5396,10 @@ static ase_awk_val_t* __eval_call ( saved_stack_top = run->stack_top; -/*run->awk->prmfns.dprintf (ASE_T("setting up function stack frame stack_top = %ld stack_base = %ld\n"), run->stack_top, run->stack_base); */ +#ifdef DEBUG_RUN + ase_dprintf (ASE_T("setting up function stack frame top=%ld base=%ld\n"), + (long)run->stack_top, (long)run->stack_base); +#endif if (__raw_push(run,(void*)run->stack_base) == -1) { ase_awk_setrunerror ( @@ -5500,7 +5524,9 @@ static ase_awk_val_t* __eval_call ( run->stack_base = saved_stack_top; STACK_NARGS(run) = (void*)nargs; -/*run->awk->prmfns.dprintf (ASE_T("running function body\n")); */ +#ifdef DEBUG_RUN + ase_dprintf (ASE_T("running function body\n")); +#endif if (afn != ASE_NULL) { @@ -5526,16 +5552,19 @@ static ase_awk_val_t* __eval_call ( } } -/*run->awk->prmfns.dprintf (ASE_T("block run complete\n")); */ - /* refdown args in the run.stack */ nargs = (ase_size_t)STACK_NARGS(run); -/*run->awk->prmfns.dprintf (ASE_T("block run complete nargs = %d\n"), (int)nargs); */ +#ifdef DEBUG_RUN + ase_dprintf (ASE_T("block run complete nargs = %d\n"), (int)nargs); +#endif for (i = 0; i < nargs; i++) { ase_awk_refdownval (run, STACK_ARG(run,i)); } -/*run->awk->prmfns.dprintf (ASE_T("got return value\n")); */ + +#ifdef DEBUG_RUN + ase_dprintf (ASE_T("got return value\n")); +#endif /* this trick has been mentioned in __run_return. * adjust the reference count of the return value. @@ -5550,7 +5579,10 @@ static ase_awk_val_t* __eval_call ( if (run->exit_level == EXIT_FUNCTION) run->exit_level = EXIT_NONE; -/*run->awk->prmfns.dprintf (ASE_T("returning from function stack_top=%ld, stack_base=%ld\n"), run->stack_top, run->stack_base); */ +#ifdef DEBUG_RUN + ase_dprintf (ASE_T("returning from function top=%ld, base=%ld\n"), + (long)run->stack_top, (long)run->stack_base); +#endif return (n == -1)? ASE_NULL: v; } @@ -6171,11 +6203,12 @@ static int __read_record (ase_awk_run_t* run) ase_awk_setrunerror (run, saved, 0, ASE_NULL); return -1; } -/* -run->awk->prmfns.dprintf (ASE_T("len = %d str=[%s]\n"), - (int)ASE_STR_LEN(&run->inrec.line), - ASE_STR_BUF(&run->inrec.line)); -*/ +#ifdef DEBUG_RUN + ase_dprintf (ASE_T("record len = %d str=[%.*s]\n"), + (int)ASE_STR_LEN(&run->inrec.line), + (int)ASE_STR_LEN(&run->inrec.line), + ASE_STR_BUF(&run->inrec.line)); +#endif if (n == 0) { ASE_AWK_ASSERT (run->awk, ASE_STR_LEN(&run->inrec.line) == 0); diff --git a/ase/awk/val.c b/ase/awk/val.c index c5dca6f8..e543b1f6 100644 --- a/ase/awk/val.c +++ b/ase/awk/val.c @@ -1,11 +1,16 @@ /* - * $Id: val.c,v 1.111 2007-02-24 14:31:44 bacon Exp $ + * $Id: val.c,v 1.112 2007-02-28 11:00:33 bacon Exp $ * * {License} */ #include +#ifdef DEBUG_VAL +#include +#endif + + static ase_char_t* __str_to_str ( ase_awk_run_t* run, const ase_char_t* str, ase_size_t str_len, int opt, ase_str_t* buf, ase_size_t* len); @@ -78,7 +83,9 @@ ase_awk_val_t* ase_awk_makeintval (ase_awk_run_t* run, ase_long_t v) val->val = v; val->nde = ASE_NULL; -/*ase_printf (ASE_T("makeintval => %p\n"), val);*/ +#ifdef DEBUG_VAL + ase_dprintf (ASE_T("makeintval => %p\n"), val); +#endif return (ase_awk_val_t*)val; } @@ -102,7 +109,9 @@ ase_awk_val_t* ase_awk_makerealval (ase_awk_run_t* run, ase_real_t v) val->val = v; val->nde = ASE_NULL; -/*ase_printf (ASE_T("makerealval => %p\n"), val);*/ +#ifdef DEBUG_VAL + ase_dprintf (ASE_T("makerealval => %p\n"), val); +#endif return (ase_awk_val_t*)val; } @@ -130,7 +139,9 @@ ase_awk_val_t* ase_awk_makestrval ( return ASE_NULL; } -/*ase_printf (ASE_T("makestrval => %p\n"), val);*/ +#ifdef DEBUG_VAL + ase_dprintf (ASE_T("makestrval => %p\n"), val); +#endif return (ase_awk_val_t*)val; } @@ -171,7 +182,9 @@ ase_awk_val_t* ase_awk_makestrval2 ( return ASE_NULL; } -/*ase_printf (ASE_T("makestrval2 => %p\n"), val);*/ +#ifdef DEBUG_VAL + ase_dprintf (ASE_T("makestrval2 => %p\n"), val); +#endif return (ase_awk_val_t*)val; } @@ -208,11 +221,12 @@ ase_awk_val_t* ase_awk_makerexval ( static void __free_map_val (void* run, void* v) { -/* -ase_printf (ASE_T("refdown in map free...")); -ase_awk_dprintval (v); -ase_printf (ASE_T("\n")); -*/ +#ifdef DEBUG_VAL + ase_dprintf (ASE_T("refdown in map free...")); + ase_awk_dprintval (run, v); + ase_dprintf (ASE_T("\n")); +#endif + ase_awk_refdownval (run, v); } @@ -275,9 +289,12 @@ void ase_awk_freeval (ase_awk_run_t* run, ase_awk_val_t* val, ase_bool_t cache) { if (ase_awk_isbuiltinval(val)) return; -/*ase_printf (ASE_T("freeing [cache=%d] ... "), cache); -ase_awk_dprintval (val); -ase_printf (ASE_T("\n"));*/ +#ifdef DEBUG_VAL + ase_dprintf (ASE_T("freeing [cache=%d] ... "), cache); + ase_awk_dprintval (run, val); + ase_dprintf (ASE_T("\n")); +#endif + if (val->type == ASE_AWK_VAL_NIL) { ASE_AWK_FREE (run->awk, val); @@ -340,15 +357,11 @@ void ase_awk_refupval (ase_awk_run_t* run, ase_awk_val_t* val) { if (ase_awk_isbuiltinval(val)) return; -/* -run->awk->prmfns.misc.dprintf ( - run->awk->prmfns.misc.custom_data, - ASE_T("ref up [ptr=%p] [count=%d] "), val, (int)val->ref); -ase_awk_dprintval (run, val); -run->awk->prmfns.misc.dprintf ( - run->awk->prmfns.misc.custom_data, - ASE_T("\n")); -*/ +#ifdef DEBUG_VAL + ase_dprintf (ASE_T("ref up [ptr=%p] [count=%d] "), val, (int)val->ref); + ase_awk_dprintval (run, val); + ase_dprintf (ASE_T("\n")); +#endif val->ref++; } @@ -357,15 +370,11 @@ void ase_awk_refdownval (ase_awk_run_t* run, ase_awk_val_t* val) { if (ase_awk_isbuiltinval(val)) return; -/* -run->awk->prmfns.misc.dprintf ( - run->awk->prmfns.misc.custom_data, - ASE_T("ref down [ptr=%p] [count=%d]\n"), val, (int)val->ref); -ase_awk_dprintval (run, val); -run->awk->prmfns.misc.dprintf ( - run->awk->prmfns.misc.custom_data, - ASE_T("\n")); -*/ +#ifdef DEBUG_VAL + ase_dprintf (ASE_T("ref down [ptr=%p] [count=%d]\n"), val, (int)val->ref); + ase_awk_dprintval (run, val); + ase_dprintf (ASE_T("\n")); +#endif ASE_AWK_ASSERTX (run->awk, val->ref > 0, "the reference count of a value should be greater than zero for it to be decremented. check the source code for any bugs"); @@ -373,11 +382,6 @@ run->awk->prmfns.misc.dprintf ( val->ref--; if (val->ref <= 0) { -/* -ase_printf (ASE_T("**FREEING [")); -ase_awk_dprintval (val); -ase_printf (ASE_T("]\n")); -*/ ase_awk_freeval(run, val, ase_true); } } @@ -471,9 +475,8 @@ ase_char_t* ase_awk_valtostr ( run, vs->buf, vs->len, opt, buf, len); } -#ifdef _DEBUG - run->awk->prmfns.misc.dprintf ( - run->awk->prmfns.misc.custom_data, +#ifdef DEBUG_VAL + ase_dprintf ( ASE_T("ERROR: WRONG VALUE TYPE [%d] in ase_awk_valtostr\n"), v->type); #endif @@ -729,9 +732,8 @@ int ase_awk_valtonum ( #endif } -#ifdef _DEBUG - run->awk->prmfns.misc.dprintf ( - run->awk->prmfns.misc.custom_data, +#ifdef DEBUG_VAL + ase_dprintf ( ASE_T("ERROR: WRONG VALUE TYPE [%d] in ase_awk_valtonum\n"), v->type); #endif