diff --git a/ase/awk/awk.c b/ase/awk/awk.c index 6ef11736..9db9eb58 100644 --- a/ase/awk/awk.c +++ b/ase/awk/awk.c @@ -1,5 +1,5 @@ /* - * $Id: awk.c,v 1.41 2006-04-16 04:31:38 bacon Exp $ + * $Id: awk.c,v 1.42 2006-04-20 16:17:01 bacon Exp $ */ #include @@ -120,8 +120,34 @@ int xp_awk_close (xp_awk_t* awk) void xp_awk_clear (xp_awk_t* awk) { + /* clear named variables */ xp_awk_map_clear (&awk->run.named); + /* destroy run stack */ + if (awk->run.stack != XP_NULL) + { + xp_free (awk->run.stack); + awk->run.stack = XP_NULL; + awk->run.stack_top = 0; + awk->run.stack_base = 0; + awk->run.stack_limit = 0; + } + + /* destroy values in free list */ + while (awk->run.icache_count > 0) + { + --awk->run.icache_count; + xp_awk_freeval (awk, + awk->run.icache[awk->run.icache_count], xp_false); + } + while (awk->run.rcache_count > 0) + { + --awk->run.rcache_count; + xp_awk_freeval (awk, + awk->run.rcache[awk->run.rcache_count], xp_false); + } + + xp_awk_tab_clear (&awk->parse.globals); xp_awk_tab_clear (&awk->parse.locals); xp_awk_tab_clear (&awk->parse.params); diff --git a/ase/awk/run.c b/ase/awk/run.c index 51155e15..0ca17147 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c,v 1.63 2006-04-20 05:44:29 bacon Exp $ + * $Id: run.c,v 1.64 2006-04-20 16:17:01 bacon Exp $ */ #include @@ -1852,7 +1852,7 @@ static xp_awk_val_t* __eval_incpst (xp_awk_t* awk, xp_awk_nde_t* nde) res2 = xp_awk_makeintval (awk, r + 1); if (res2 == XP_NULL) { - xp_awk_freeval (awk, res); + xp_awk_freeval (awk, res, xp_true); PANIC (awk, XP_AWK_ENOMEM); } } @@ -1865,7 +1865,7 @@ static xp_awk_val_t* __eval_incpst (xp_awk_t* awk, xp_awk_nde_t* nde) res2 = xp_awk_makerealval (awk, r + 1.0); if (res2 == XP_NULL) { - xp_awk_freeval (awk, res); + xp_awk_freeval (awk, res, xp_true); PANIC (awk, XP_AWK_ENOMEM); } } @@ -1886,7 +1886,7 @@ static xp_awk_val_t* __eval_incpst (xp_awk_t* awk, xp_awk_nde_t* nde) res2 = xp_awk_makeintval (awk, r - 1); if (res2 == XP_NULL) { - xp_awk_freeval (awk, res); + xp_awk_freeval (awk, res, xp_true); PANIC (awk, XP_AWK_ENOMEM); } } @@ -1899,7 +1899,7 @@ static xp_awk_val_t* __eval_incpst (xp_awk_t* awk, xp_awk_nde_t* nde) res2 = xp_awk_makerealval (awk, r - 1.0); if (res2 == XP_NULL) { - xp_awk_freeval (awk, res); + xp_awk_freeval (awk, res, xp_true); PANIC (awk, XP_AWK_ENOMEM); } } diff --git a/ase/awk/val.c b/ase/awk/val.c index b1210d5c..539385bf 100644 --- a/ase/awk/val.c +++ b/ase/awk/val.c @@ -1,5 +1,5 @@ /* - * $Id: val.c,v 1.22 2006-04-20 05:44:29 bacon Exp $ + * $Id: val.c,v 1.23 2006-04-20 16:17:01 bacon Exp $ */ #include @@ -156,7 +156,7 @@ xp_bool_t xp_awk_isbuiltinval (xp_awk_val_t* val) val <= (xp_awk_val_t*)&__awk_int[xp_countof(__awk_int)-1]); } -void xp_awk_freeval (xp_awk_t* awk, xp_awk_val_t* val) +void xp_awk_freeval (xp_awk_t* awk, xp_awk_val_t* val, xp_bool_t cache) { if (xp_awk_isbuiltinval(val)) return; @@ -170,7 +170,8 @@ xp_printf (XP_TEXT("\n")); return; case XP_AWK_VAL_INT: - if (awk->run.icache_count < xp_countof(awk->run.icache)) + if (cache == xp_true && + awk->run.icache_count < xp_countof(awk->run.icache)) { awk->run.icache[awk->run.icache_count++] = (xp_awk_val_int_t*)val; @@ -179,7 +180,8 @@ xp_printf (XP_TEXT("\n")); return; case XP_AWK_VAL_REAL: - if (awk->run.rcache_count < xp_countof(awk->run.rcache)) + if (cache == xp_true && + awk->run.rcache_count < xp_countof(awk->run.rcache)) { awk->run.rcache[awk->run.rcache_count++] = (xp_awk_val_real_t*)val; @@ -232,7 +234,7 @@ xp_printf (XP_TEXT("**FREEING ")); xp_awk_printval (val); xp_printf (XP_TEXT("\n")); */ - xp_awk_freeval(awk, val); + xp_awk_freeval(awk, val, xp_true); } }