From b974c49c76b47086e6ba767caedfe4fad01a4dce Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 28 Mar 2006 16:33:09 +0000 Subject: [PATCH] *** empty log message *** --- ase/awk/awk.c | 3 ++- ase/awk/awk.h | 4 +++- ase/awk/run.c | 22 +++++++++++----------- ase/awk/tree.c | 10 +++++++++- ase/awk/tree.h | 12 ++++++++++-- ase/awk/val.c | 31 ++++++++++++++++++++++++------- ase/awk/val.h | 3 ++- 7 files changed, 61 insertions(+), 24 deletions(-) diff --git a/ase/awk/awk.c b/ase/awk/awk.c index bd184ce5..c0a43905 100644 --- a/ase/awk/awk.c +++ b/ase/awk/awk.c @@ -1,5 +1,5 @@ /* - * $Id: awk.c,v 1.34 2006-03-27 14:14:00 bacon Exp $ + * $Id: awk.c,v 1.35 2006-03-28 16:33:09 bacon Exp $ */ #include @@ -90,6 +90,7 @@ xp_awk_t* xp_awk_open (xp_awk_t* awk) awk->run.stack_limit = 0; awk->run.exit_level = 0; awk->run.icache_count = 0; + awk->run.rcache_count = 0; awk->lex.curc = XP_CHAR_EOF; awk->lex.ungotc_count = 0; diff --git a/ase/awk/awk.h b/ase/awk/awk.h index 361e3476..627c920f 100644 --- a/ase/awk/awk.h +++ b/ase/awk/awk.h @@ -1,5 +1,5 @@ /* - * $Id: awk.h,v 1.37 2006-03-27 11:43:17 bacon Exp $ + * $Id: awk.h,v 1.38 2006-03-28 16:33:09 bacon Exp $ */ #ifndef _XP_AWK_AWK_H_ @@ -100,7 +100,9 @@ struct xp_awk_t int exit_level; xp_awk_val_int_t* icache[100]; // TODO: ... + xp_awk_val_real_t* rcache[100]; // TODO: ... xp_size_t icache_count; + xp_size_t rcache_count; } run; /* source buffer management */ diff --git a/ase/awk/run.c b/ase/awk/run.c index 3190ed0a..c42e0b8c 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c,v 1.25 2006-03-28 11:32:58 bacon Exp $ + * $Id: run.c,v 1.26 2006-03-28 16:33:09 bacon Exp $ */ #include @@ -12,12 +12,14 @@ #define STACK_INCREMENT 512 -#define STACK_AT(awk,n) ((awk)->run.stack[(awk)->run.stack_base+n]) +#define STACK_AT(awk,n) ((awk)->run.stack[(awk)->run.stack_base+(n)]) #define STACK_NARGS(awk) ((xp_size_t)STACK_AT(awk,3)) #define STACK_ARG(awk,n) STACK_AT(awk,3+1+(n)) #define STACK_LOCAL(awk,n) STACK_AT(awk,3+STACK_NARGS(awk)+1+(n)) #define STACK_RETVAL(awk) STACK_AT(awk,2) +#define STACK_GLOBAL(awk,n) ((awk)->run.stack[n]) + #define EXIT_NONE 0 #define EXIT_BREAK 1 #define EXIT_CONTINUE 2 @@ -57,7 +59,9 @@ int xp_awk_run (xp_awk_t* awk) // TODO: clear run stack/exit_level awk->run.exit_level = EXIT_NONE; - + xp_assert (awk->run.stack_base == 0 && awk->run.stack_top == 0); + + /* secure space for global variables */ nglobals = awk->tree.nglobals; while (nglobals > 0) { @@ -443,11 +447,9 @@ static xp_awk_val_t* __eval_expression (xp_awk_t* awk, xp_awk_nde_t* nde) val = xp_awk_makeintval(awk,((xp_awk_nde_int_t*)nde)->val); break; - /* TODO: case XP_AWK_NDE_REAL: - val = xp_awk_makerealval(((xp_awk_nde_real_t*)nde)->val); + val = xp_awk_makerealval(awk,((xp_awk_nde_real_t*)nde)->val); break; - */ case XP_AWK_NDE_NAMED: { @@ -461,8 +463,8 @@ static xp_awk_val_t* __eval_expression (xp_awk_t* awk, xp_awk_nde_t* nde) case XP_AWK_NDE_GLOBAL: { - //xp_awk_nde_var_t* tgt = (xp_awk_nde_var_t*)nde; - //val = STACK_GLOBAL(awk,tgt->id.idxa); + xp_awk_nde_var_t* tgt = (xp_awk_nde_var_t*)nde; + val = STACK_GLOBAL(awk,tgt->id.idxa); } break; @@ -552,11 +554,9 @@ static xp_awk_val_t* __eval_assignment (xp_awk_t* awk, xp_awk_nde_ass_t* nde) } else if (tgt->type == XP_AWK_NDE_GLOBAL) { - /* - xp_awk_refdownval(STACK_GLOBAL(awk,tgt->id.idxa)); + xp_awk_refdownval (awk, STACK_GLOBAL(awk,tgt->id.idxa)); STACK_GLOBAL(awk,tgt->id.idxa) = val; xp_awk_refupval (val); - */ } else if (tgt->type == XP_AWK_NDE_LOCAL) { diff --git a/ase/awk/tree.c b/ase/awk/tree.c index 5945e87f..aacb53a9 100644 --- a/ase/awk/tree.c +++ b/ase/awk/tree.c @@ -1,5 +1,5 @@ /* - * $Id: tree.c,v 1.26 2006-03-23 15:36:20 bacon Exp $ + * $Id: tree.c,v 1.27 2006-03-28 16:33:09 bacon Exp $ */ #include @@ -77,6 +77,10 @@ static int __print_expression (xp_awk_nde_t* nde) #endif break; + case XP_AWK_NDE_REAL: + xp_printf (XP_TEXT("%lf"), (long double)((xp_awk_nde_real_t*)nde)->val); + break; + case XP_AWK_NDE_STR: // TODO: buf, len xp_printf (XP_TEXT("\"%s\""), ((xp_awk_nde_str_t*)nde)->buf); @@ -490,6 +494,10 @@ void xp_awk_clrpt (xp_awk_nde_t* tree) xp_free (p); break; + case XP_AWK_NDE_REAL: + xp_free (p); + break; + case XP_AWK_NDE_STR: xp_free (((xp_awk_nde_str_t*)p)->buf); xp_free (p); diff --git a/ase/awk/tree.h b/ase/awk/tree.h index 2f22bed1..d1baebec 100644 --- a/ase/awk/tree.h +++ b/ase/awk/tree.h @@ -1,5 +1,5 @@ /* - * $Id: tree.h,v 1.27 2006-03-07 16:02:18 bacon Exp $ + * $Id: tree.h,v 1.28 2006-03-28 16:33:09 bacon Exp $ */ #ifndef _XP_AWK_TREE_H_ @@ -20,7 +20,7 @@ enum XP_AWK_NDE_EXP_UNR, XP_AWK_NDE_INT, - /*TODO: XP_AWK_NDE_REAL,*/ + XP_AWK_NDE_REAL, XP_AWK_NDE_STR, XP_AWK_NDE_NAMED, XP_AWK_NDE_NAMEDIDX, @@ -55,6 +55,7 @@ typedef struct xp_awk_nde_ass_t xp_awk_nde_ass_t; typedef struct xp_awk_nde_exp_t xp_awk_nde_exp_t; typedef struct xp_awk_nde_pos_t xp_awk_nde_pos_t; typedef struct xp_awk_nde_int_t xp_awk_nde_int_t; +typedef struct xp_awk_nde_real_t xp_awk_nde_real_t; typedef struct xp_awk_nde_str_t xp_awk_nde_str_t; typedef struct xp_awk_nde_var_t xp_awk_nde_var_t; typedef struct xp_awk_nde_idx_t xp_awk_nde_idx_t; @@ -123,6 +124,13 @@ struct xp_awk_nde_int_t xp_long_t val; }; +/* XP_AWK_NDE_REAL */ +struct xp_awk_nde_real_t +{ + XP_AWK_NDE_HDR; + xp_real_t val; +}; + /* XP_AWK_NDE_STR */ struct xp_awk_nde_str_t { diff --git a/ase/awk/val.c b/ase/awk/val.c index 5cccc078..9f8f10d3 100644 --- a/ase/awk/val.c +++ b/ase/awk/val.c @@ -1,5 +1,5 @@ /* - * $Id: val.c,v 1.12 2006-03-27 14:14:00 bacon Exp $ + * $Id: val.c,v 1.13 2006-03-28 16:33:09 bacon Exp $ */ #include @@ -44,7 +44,8 @@ xp_awk_val_t* xp_awk_makeintval (xp_awk_t* awk, xp_long_t v) } else { - val = (xp_awk_val_int_t*)xp_malloc(xp_sizeof(xp_awk_val_int_t)); + val = (xp_awk_val_int_t*) + xp_malloc(xp_sizeof(xp_awk_val_int_t)); if (val == XP_NULL) return XP_NULL; } @@ -55,12 +56,20 @@ xp_awk_val_t* xp_awk_makeintval (xp_awk_t* awk, xp_long_t v) return (xp_awk_val_t*)val; } -xp_awk_val_t* xp_awk_makerealval (xp_real_t v) +xp_awk_val_t* xp_awk_makerealval (xp_awk_t* awk, xp_real_t v) { xp_awk_val_real_t* val; - val = (xp_awk_val_real_t*)xp_malloc(xp_sizeof(xp_awk_val_real_t)); - if (val == XP_NULL) return XP_NULL; + if (awk->run.rcache_count > 0) + { + val = awk->run.rcache[--awk->run.rcache_count]; + } + else + { + val = (xp_awk_val_real_t*) + xp_malloc (xp_sizeof(xp_awk_val_real_t)); + if (val == XP_NULL) return XP_NULL; + } val->type = XP_AWK_VAL_REAL; val->ref = 0; @@ -118,7 +127,15 @@ void xp_awk_freeval (xp_awk_t* awk, xp_awk_val_t* val) break; case XP_AWK_VAL_REAL: - xp_free (val); + if (awk->run.rcache_count < xp_countof(awk->run.rcache)) + { + awk->run.rcache[awk->run.rcache_count++] = + (xp_awk_val_real_t*)val; + } + else + { + xp_free (val); + } break; case XP_AWK_VAL_STR: @@ -184,7 +201,7 @@ xp_awk_val_t* xp_awk_cloneval (xp_awk_t* awk, xp_awk_val_t* val) case XP_AWK_VAL_INT: return xp_awk_makeintval (awk, ((xp_awk_val_int_t*)val)->val); case XP_AWK_VAL_REAL: - return xp_awk_makerealval (((xp_awk_val_real_t*)val)->val); + return xp_awk_makerealval (awk, ((xp_awk_val_real_t*)val)->val); case XP_AWK_VAL_STR: return xp_awk_makestrval ( ((xp_awk_val_str_t*)val)->buf, diff --git a/ase/awk/val.h b/ase/awk/val.h index 6956b246..bac4f664 100644 --- a/ase/awk/val.h +++ b/ase/awk/val.h @@ -1,5 +1,5 @@ /* - * $Id: val.h,v 1.11 2006-03-28 11:32:58 bacon Exp $ + * $Id: val.h,v 1.12 2006-03-28 16:33:09 bacon Exp $ */ #ifndef _XP_AWK_VAL_H_ @@ -76,6 +76,7 @@ extern "C" { extern xp_awk_val_t* xp_awk_val_nil; xp_awk_val_t* xp_awk_makeintval (xp_awk_t* awk, xp_long_t v); +xp_awk_val_t* xp_awk_makerealval (xp_awk_t* awk, xp_real_t v); xp_awk_val_t* xp_awk_makestrval (const xp_char_t* str, xp_size_t len); //xp_awk_val_t* xp_awk_makemapval ();