From 3c4e592803fb2f5fbf38a74c5fc24d053903ae44 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 10 Apr 2006 14:53:48 +0000 Subject: [PATCH] *** empty log message *** --- ase/awk/misc.c | 22 +++++++++++----------- ase/awk/parse.c | 8 ++++---- ase/awk/run.c | 36 ++++++++++++++++++++++++++---------- ase/awk/sa.h | 3 ++- 4 files changed, 43 insertions(+), 26 deletions(-) diff --git a/ase/awk/misc.c b/ase/awk/misc.c index 40dcb2cb..6c15c7a2 100644 --- a/ase/awk/misc.c +++ b/ase/awk/misc.c @@ -1,5 +1,5 @@ /* - * $Id: misc.c,v 1.3 2006-04-04 16:45:21 bacon Exp $ + * $Id: misc.c,v 1.4 2006-04-10 14:53:48 bacon Exp $ */ #include @@ -113,7 +113,7 @@ xp_real_t xp_awk_strtoreal (const xp_char_t* str) xp_real_t fraction, dblExp, * d; const xp_char_t* p; xp_cint_t c; - int exp = 0; // Exponent read from "EX" field. + int exp = 0; /* Exponent read from "EX" field */ /* * Exponent that derives from the fractional part. Under normal @@ -125,14 +125,14 @@ xp_real_t xp_awk_strtoreal (const xp_char_t* str) */ int fracExp = 0; - int mantSize; // Number of digits in mantissa. - int decPt; // Number of mantissa digits BEFORE decimal point - const xp_char_t *pExp; // Temporarily holds location of exponent in string. + int mantSize; /* Number of digits in mantissa. */ + int decPt; /* Number of mantissa digits BEFORE decimal point */ + const xp_char_t *pExp; /* Temporarily holds location of exponent in string */ int sign = 0, expSign = 0; p = str; - // Strip off leading blanks and check for a sign. + /* Strip off leading blanks and check for a sign */ while (xp_isspace(*p)) p++; while (*p != XP_CHAR('\0')) @@ -146,8 +146,8 @@ xp_real_t xp_awk_strtoreal (const xp_char_t* str) else break; } - // Count the number of digits in the mantissa (including the decimal - // point), and also locate the decimal point. + /* Count the number of digits in the mantissa (including the decimal + * point), and also locate the decimal point. */ decPt = -1; for (mantSize = 0; ; mantSize++) { c = *p; @@ -172,7 +172,7 @@ xp_real_t xp_awk_strtoreal (const xp_char_t* str) } else { - mantSize -= 1; // One of the digits was the point. + mantSize -= 1; /* One of the digits was the point */ } if (mantSize > 18) { @@ -219,7 +219,7 @@ xp_real_t xp_awk_strtoreal (const xp_char_t* str) fraction = (1.0e9 * frac1) + frac2; } - // Skim off the exponent. + /* Skim off the exponent */ p = pExp; if ((*p == XP_CHAR('E')) || (*p == XP_CHAR('e'))) { @@ -236,7 +236,7 @@ xp_real_t xp_awk_strtoreal (const xp_char_t* str) } if (!xp_isdigit(*p)) { - p = pExp; + /* p = pExp; */ goto done; } while (xp_isdigit(*p)) diff --git a/ase/awk/parse.c b/ase/awk/parse.c index 3f44098b..85e91ae3 100644 --- a/ase/awk/parse.c +++ b/ase/awk/parse.c @@ -1,5 +1,5 @@ /* - * $Id: parse.c,v 1.74 2006-04-07 16:52:42 bacon Exp $ + * $Id: parse.c,v 1.75 2006-04-10 14:53:48 bacon Exp $ */ #include @@ -732,8 +732,8 @@ static xp_awk_nde_t* __parse_block (xp_awk_t* awk, xp_bool_t is_top) xp_awk_tab_remove ( &awk->parse.locals, nlocals, tmp - nlocals); - /* adjust number of locals for a block without any statements */ - if (head == NULL) tmp = 0; + /* adjust the number of locals for a block without any statements */ + /* if (head == XP_NULL) tmp = 0; */ block->type = XP_AWK_NDE_BLK; block->next = XP_NULL; @@ -2691,7 +2691,7 @@ static int __skip_comment (xp_awk_t* awk) static int __classify_ident (xp_awk_t* awk, const xp_char_t* ident) { - struct __kwent* p = __kwtab; + struct __kwent* p; for (p = __kwtab; p->name != XP_NULL; p++) { diff --git a/ase/awk/run.c b/ase/awk/run.c index 2c91442c..036faf12 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c,v 1.42 2006-04-10 09:22:05 bacon Exp $ + * $Id: run.c,v 1.43 2006-04-10 14:53:48 bacon Exp $ */ #include @@ -287,6 +287,7 @@ static int __run_block (xp_awk_t* awk, xp_awk_nde_blk_t* nde) { xp_awk_nde_t* p; xp_size_t nlocals; + xp_size_t saved_stack_top; int n = 0; xp_assert (nde->type == XP_AWK_NDE_BLK); @@ -295,13 +296,16 @@ static int __run_block (xp_awk_t* awk, xp_awk_nde_blk_t* nde) nlocals = nde->nlocals; //xp_printf (XP_TEXT("securing space for local variables nlocals = %d\n"), nlocals); + saved_stack_top = awk->run.stack_top; + /* secure space for local variables */ while (nlocals > 0) { --nlocals; if (__raw_push(awk,xp_awk_val_nil) == -1) { - // TODO: proper error handling... + /* restore stack top */ + awk->run.stack_top = saved_stack_top; return -1; } @@ -419,9 +423,11 @@ static int __run_if_statement (xp_awk_t* awk, xp_awk_nde_if_t* nde) static int __run_while_statement (xp_awk_t* awk, xp_awk_nde_while_t* nde) { xp_awk_val_t* test; + int n = 0; if (nde->type == XP_AWK_NDE_WHILE) { + // TODO: handle run-time abortion... while (1) { test = __eval_expression (awk, nde->test); @@ -431,7 +437,6 @@ static int __run_while_statement (xp_awk_t* awk, xp_awk_nde_while_t* nde) if (xp_awk_boolval(test)) { - // TODO: break.... continue...., global exit, return... run-time abortion... if (__run_statement(awk,nde->body) == -1) { xp_awk_refdownval (awk, test); @@ -460,13 +465,10 @@ static int __run_while_statement (xp_awk_t* awk, xp_awk_nde_while_t* nde) } else if (nde->type == XP_AWK_NDE_DOWHILE) { + // TODO: handle run-time abortion... do { - if (__run_statement(awk,nde->body) == -1) - { - // TODO: error handling... - return -1; - } + if (__run_statement(awk,nde->body) == -1) return -1; if (awk->run.exit_level == EXIT_BREAK) { @@ -483,11 +485,13 @@ static int __run_while_statement (xp_awk_t* awk, xp_awk_nde_while_t* nde) if (test == XP_NULL) return -1; xp_awk_refupval (test); + if (!xp_awk_boolval(test)) { xp_awk_refdownval (awk, test); break; } + xp_awk_refdownval (awk, test); } while (1); @@ -498,9 +502,15 @@ static int __run_while_statement (xp_awk_t* awk, xp_awk_nde_while_t* nde) static int __run_for_statement (xp_awk_t* awk, xp_awk_nde_for_t* nde) { + xp_awk_val_t* val; + if (nde->init != XP_NULL) { - if (__eval_expression(awk,nde->init) == XP_NULL) return -1; + val = __eval_expression(awk,nde->init); + if (val == XP_NULL) return -1; + + xp_awk_refupval (val); + xp_awk_refdownval (awk, val); } while (1) @@ -550,7 +560,11 @@ static int __run_for_statement (xp_awk_t* awk, xp_awk_nde_for_t* nde) if (nde->incr != XP_NULL) { - if (__eval_expression(awk,nde->incr) == XP_NULL) return -1; + val = __eval_expression(awk,nde->incr); + if (val == XP_NULL) return -1; + + xp_awk_refupval (val); + xp_awk_refdownval (awk, val); } } @@ -581,6 +595,7 @@ static int __run_return_statement (xp_awk_t* awk, xp_awk_nde_return_t* nde) xp_awk_refdownval (awk, STACK_RETVAL(awk)); STACK_RETVAL(awk) = val; + xp_awk_refupval (val); /* see __eval_call for the trick */ //xp_printf (XP_TEXT("set return value....\n")); } @@ -600,6 +615,7 @@ static int __run_exit_statement (xp_awk_t* awk, xp_awk_nde_exit_t* nde) xp_awk_refdownval (awk, STACK_RETVAL_GLOBAL(awk)); STACK_RETVAL_GLOBAL(awk) = val; /* global return value */ + xp_awk_refupval (val); } diff --git a/ase/awk/sa.h b/ase/awk/sa.h index b0c4479f..20309493 100644 --- a/ase/awk/sa.h +++ b/ase/awk/sa.h @@ -1,5 +1,5 @@ /* - * $Id: sa.h,v 1.20 2006-04-06 16:25:37 bacon Exp $ + * $Id: sa.h,v 1.21 2006-04-10 14:53:48 bacon Exp $ */ #ifndef _XP_AWK_SA_H_ @@ -24,6 +24,7 @@ #ifdef XP_CHAR_IS_MCHAR #include #else +#include #include #if !defined(__BEOS__) #include