*** empty log message ***

This commit is contained in:
hyung-hwan 2006-04-10 14:53:48 +00:00
parent 04ee291f0f
commit 3c4e592803
4 changed files with 43 additions and 26 deletions

View File

@ -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 <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -113,7 +113,7 @@ xp_real_t xp_awk_strtoreal (const xp_char_t* str)
xp_real_t fraction, dblExp, * d; xp_real_t fraction, dblExp, * d;
const xp_char_t* p; const xp_char_t* p;
xp_cint_t c; 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 * 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 fracExp = 0;
int mantSize; // Number of digits in mantissa. int mantSize; /* Number of digits in mantissa. */
int decPt; // Number of mantissa digits BEFORE decimal point int decPt; /* Number of mantissa digits BEFORE decimal point */
const xp_char_t *pExp; // Temporarily holds location of exponent in string. const xp_char_t *pExp; /* Temporarily holds location of exponent in string */
int sign = 0, expSign = 0; int sign = 0, expSign = 0;
p = str; 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 (xp_isspace(*p)) p++;
while (*p != XP_CHAR('\0')) while (*p != XP_CHAR('\0'))
@ -146,8 +146,8 @@ xp_real_t xp_awk_strtoreal (const xp_char_t* str)
else break; else break;
} }
// Count the number of digits in the mantissa (including the decimal /* Count the number of digits in the mantissa (including the decimal
// point), and also locate the decimal point. * point), and also locate the decimal point. */
decPt = -1; decPt = -1;
for (mantSize = 0; ; mantSize++) { for (mantSize = 0; ; mantSize++) {
c = *p; c = *p;
@ -172,7 +172,7 @@ xp_real_t xp_awk_strtoreal (const xp_char_t* str)
} }
else else
{ {
mantSize -= 1; // One of the digits was the point. mantSize -= 1; /* One of the digits was the point */
} }
if (mantSize > 18) if (mantSize > 18)
{ {
@ -219,7 +219,7 @@ xp_real_t xp_awk_strtoreal (const xp_char_t* str)
fraction = (1.0e9 * frac1) + frac2; fraction = (1.0e9 * frac1) + frac2;
} }
// Skim off the exponent. /* Skim off the exponent */
p = pExp; p = pExp;
if ((*p == XP_CHAR('E')) || (*p == XP_CHAR('e'))) 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)) if (!xp_isdigit(*p))
{ {
p = pExp; /* p = pExp; */
goto done; goto done;
} }
while (xp_isdigit(*p)) while (xp_isdigit(*p))

View File

@ -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 <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -732,8 +732,8 @@ static xp_awk_nde_t* __parse_block (xp_awk_t* awk, xp_bool_t is_top)
xp_awk_tab_remove ( xp_awk_tab_remove (
&awk->parse.locals, nlocals, tmp - nlocals); &awk->parse.locals, nlocals, tmp - nlocals);
/* adjust number of locals for a block without any statements */ /* adjust the number of locals for a block without any statements */
if (head == NULL) tmp = 0; /* if (head == XP_NULL) tmp = 0; */
block->type = XP_AWK_NDE_BLK; block->type = XP_AWK_NDE_BLK;
block->next = XP_NULL; 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) 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++) for (p = __kwtab; p->name != XP_NULL; p++)
{ {

View File

@ -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 <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -287,6 +287,7 @@ static int __run_block (xp_awk_t* awk, xp_awk_nde_blk_t* nde)
{ {
xp_awk_nde_t* p; xp_awk_nde_t* p;
xp_size_t nlocals; xp_size_t nlocals;
xp_size_t saved_stack_top;
int n = 0; int n = 0;
xp_assert (nde->type == XP_AWK_NDE_BLK); 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; nlocals = nde->nlocals;
//xp_printf (XP_TEXT("securing space for local variables nlocals = %d\n"), 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 */ /* secure space for local variables */
while (nlocals > 0) while (nlocals > 0)
{ {
--nlocals; --nlocals;
if (__raw_push(awk,xp_awk_val_nil) == -1) 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; 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) static int __run_while_statement (xp_awk_t* awk, xp_awk_nde_while_t* nde)
{ {
xp_awk_val_t* test; xp_awk_val_t* test;
int n = 0;
if (nde->type == XP_AWK_NDE_WHILE) if (nde->type == XP_AWK_NDE_WHILE)
{ {
// TODO: handle run-time abortion...
while (1) while (1)
{ {
test = __eval_expression (awk, nde->test); 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)) if (xp_awk_boolval(test))
{ {
// TODO: break.... continue...., global exit, return... run-time abortion...
if (__run_statement(awk,nde->body) == -1) if (__run_statement(awk,nde->body) == -1)
{ {
xp_awk_refdownval (awk, test); 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) else if (nde->type == XP_AWK_NDE_DOWHILE)
{ {
// TODO: handle run-time abortion...
do do
{ {
if (__run_statement(awk,nde->body) == -1) if (__run_statement(awk,nde->body) == -1) return -1;
{
// TODO: error handling...
return -1;
}
if (awk->run.exit_level == EXIT_BREAK) 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; if (test == XP_NULL) return -1;
xp_awk_refupval (test); xp_awk_refupval (test);
if (!xp_awk_boolval(test)) if (!xp_awk_boolval(test))
{ {
xp_awk_refdownval (awk, test); xp_awk_refdownval (awk, test);
break; break;
} }
xp_awk_refdownval (awk, test); xp_awk_refdownval (awk, test);
} }
while (1); 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) 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 (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) 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 (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)); xp_awk_refdownval (awk, STACK_RETVAL(awk));
STACK_RETVAL(awk) = val; STACK_RETVAL(awk) = val;
xp_awk_refupval (val); /* see __eval_call for the trick */ xp_awk_refupval (val); /* see __eval_call for the trick */
//xp_printf (XP_TEXT("set return value....\n")); //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)); xp_awk_refdownval (awk, STACK_RETVAL_GLOBAL(awk));
STACK_RETVAL_GLOBAL(awk) = val; /* global return value */ STACK_RETVAL_GLOBAL(awk) = val; /* global return value */
xp_awk_refupval (val); xp_awk_refupval (val);
} }

View File

@ -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_ #ifndef _XP_AWK_SA_H_
@ -24,6 +24,7 @@
#ifdef XP_CHAR_IS_MCHAR #ifdef XP_CHAR_IS_MCHAR
#include <ctype.h> #include <ctype.h>
#else #else
#include <ctype.h>
#include <wchar.h> #include <wchar.h>
#if !defined(__BEOS__) #if !defined(__BEOS__)
#include <wctype.h> #include <wctype.h>