*** empty log message ***

This commit is contained in:
hyung-hwan 2006-04-30 17:12:51 +00:00
parent 49b3853fd6
commit f73544e769
9 changed files with 118 additions and 23 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.h,v 1.59 2006-04-30 15:50:38 bacon Exp $
* $Id: awk.h,v 1.60 2006-04-30 17:10:30 bacon Exp $
*/
#ifndef _XP_AWK_AWK_H_
@ -96,7 +96,7 @@ enum
XP_AWK_EDIVBYZERO, /* divide by zero */
XP_AWK_EOPERAND, /* invalid operand */
XP_AWK_ENOSUCHFUNC, /* no such function */
XP_AWK_ENOTASSIGNABLE, /* not indexable value */
XP_AWK_ENOTASSIGNABLE, /* value not assignable */
XP_AWK_ENOTINDEXABLE, /* not indexable value */
XP_AWK_EWRONGINDEX, /* wrong index */
XP_AWK_EINTERNAL /* internal error */

View File

@ -1,5 +1,5 @@
/*
* $Id: map.c,v 1.15 2006-04-24 07:46:35 bacon Exp $
* $Id: map.c,v 1.16 2006-04-30 17:10:30 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -261,7 +261,8 @@ int xp_awk_map_remove (xp_awk_map_t* map, xp_char_t* key)
return -1;
}
int xp_awk_map_walk (xp_awk_map_t* map, int (*walker) (xp_awk_pair_t*))
int xp_awk_map_walk (xp_awk_map_t* map,
int (*walker) (xp_awk_pair_t*,void*), void* arg)
{
xp_size_t i;
xp_awk_pair_t* pair, * next;
@ -273,7 +274,7 @@ int xp_awk_map_walk (xp_awk_map_t* map, int (*walker) (xp_awk_pair_t*))
while (pair != XP_NULL)
{
next = pair->next;
if (walker(pair) == -1) return -1;
if (walker(pair,arg) == -1) return -1;
pair = next;
}
}

View File

@ -1,5 +1,5 @@
/*
* $Id: map.h,v 1.10 2006-04-24 07:46:35 bacon Exp $
* $Id: map.h,v 1.11 2006-04-30 17:10:30 bacon Exp $
*/
#ifndef _XP_AWK_MAP_H_
@ -57,7 +57,8 @@ xp_awk_pair_t* xp_awk_map_setpair (
xp_awk_map_t* map, xp_awk_pair_t* pair, void* val);
int xp_awk_map_remove (xp_awk_map_t* map, xp_char_t* key);
int xp_awk_map_walk (xp_awk_map_t* map, int (*walker) (xp_awk_pair_t*));
int xp_awk_map_walk (xp_awk_map_t* map,
int (*walker)(xp_awk_pair_t*,void*), void* arg);
#ifdef __cplusplus
}

View File

@ -1,5 +1,5 @@
/*
* $Id: parse.c,v 1.97 2006-04-30 15:50:38 bacon Exp $
* $Id: parse.c,v 1.98 2006-04-30 17:12:51 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -267,7 +267,7 @@ do { \
#ifndef XP_AWK_STAND_ALONE
#include <xp/bas/stdio.h>
#endif
static int __dump_func (xp_awk_pair_t* pair)
static int __dump_func (xp_awk_pair_t* pair, void* arg)
{
xp_awk_func_t* func = (xp_awk_func_t*)pair->val;
xp_size_t i;
@ -303,7 +303,7 @@ static void __dump (xp_awk_t* awk)
xp_printf (XP_TEXT("__global%lu;\n\n"), (unsigned long)i);
}
xp_awk_map_walk (&awk->tree.funcs, __dump_func);
xp_awk_map_walk (&awk->tree.funcs, __dump_func, XP_NULL);
if (awk->tree.begin != XP_NULL)
{

View File

@ -1,5 +1,5 @@
/*
* $Id: run.c,v 1.79 2006-04-29 12:09:29 bacon Exp $
* $Id: run.c,v 1.80 2006-04-30 17:10:30 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -46,7 +46,7 @@ static int __run_statement (xp_awk_run_t* run, xp_awk_nde_t* nde);
static int __run_if_statement (xp_awk_run_t* run, xp_awk_nde_if_t* nde);
static int __run_while_statement (xp_awk_run_t* run, xp_awk_nde_while_t* nde);
static int __run_for_statement (xp_awk_run_t* run, xp_awk_nde_for_t* nde);
static int __run_foreach_statement (xp_awk_run_t* run, xp_awk_nde_for_t* nde);
static int __run_foreach_statement (xp_awk_run_t* run, xp_awk_nde_foreach_t* nde);
static int __run_break_statement (xp_awk_run_t* run, xp_awk_nde_break_t* nde);
static int __run_continue_statement (xp_awk_run_t* run, xp_awk_nde_continue_t* nde);
static int __run_return_statement (xp_awk_run_t* run, xp_awk_nde_return_t* nde);
@ -145,7 +145,7 @@ typedef xp_awk_val_t* (*binop_func_t) (
typedef xp_awk_val_t* (*eval_expr_t) (xp_awk_run_t* run, xp_awk_nde_t* nde);
/* TODO: remove this function */
static int __printval (xp_awk_pair_t* pair)
static int __printval (xp_awk_pair_t* pair, void* arg)
{
xp_printf (XP_TEXT("%s = "), (const xp_char_t*)pair->key);
xp_awk_printval ((xp_awk_val_t*)pair->val);
@ -421,7 +421,7 @@ xp_printf (XP_TEXT("\n"));
run->exit_level = EXIT_NONE;
xp_printf (XP_TEXT("-[VARIABLES]------------------------\n"));
xp_awk_map_walk (&run->named, __printval);
xp_awk_map_walk (&run->named, __printval, XP_NULL);
xp_printf (XP_TEXT("-[END VARIABLES]--------------------------\n"));
return n;
@ -556,7 +556,7 @@ static int __run_statement (xp_awk_run_t* run, xp_awk_nde_t* nde)
case XP_AWK_NDE_FOREACH:
if (__run_foreach_statement (
run, (xp_awk_nde_for_t*)nde) == -1) return -1;
run, (xp_awk_nde_foreach_t*)nde) == -1) return -1;
break;
case XP_AWK_NDE_BREAK:
@ -769,12 +769,70 @@ static int __run_for_statement (xp_awk_run_t* run, xp_awk_nde_for_t* nde)
return 0;
}
static int __run_foreach_statement (xp_awk_run_t* run, xp_awk_nde_for_t* nde)
struct __foreach_walker_t
{
xp_printf (XP_TEXT("FOREEACH NOT IMPLEMENTED....\n"));
xp_awk_run_t* run;
xp_awk_nde_var_t* var;
xp_awk_nde_t* body;
};
static int __walk_foreach (xp_awk_pair_t* pair, void* arg)
{
struct __foreach_walker_t* w = (struct __foreach_walker_t*)arg;
xp_awk_val_t* str;
str = (xp_awk_val_t*)xp_awk_makestrval(pair->key,xp_strlen(pair->key));
if (str == XP_NULL) PANIC_I (w->run, XP_AWK_ENOMEM);
xp_awk_refupval (str);
if (__do_assignment (w->run, w->var, str) == XP_NULL)
{
xp_awk_refdownval (w->run, str);
return -1;
}
if (__run_statement (w->run, w->body) == -1)
{
xp_awk_refdownval (w->run, str);
return -1;
}
xp_awk_refdownval (w->run, str);
return 0;
}
static int __run_foreach_statement (xp_awk_run_t* run, xp_awk_nde_foreach_t* nde)
{
int n;
xp_awk_nde_exp_t* test;
xp_awk_val_t* rv;
xp_awk_map_t* map;
struct __foreach_walker_t walker;
test = (xp_awk_nde_exp_t*)nde->test;
xp_assert (test->type == XP_AWK_NDE_EXP_BIN &&
test->opcode == XP_AWK_BINOP_IN);
rv = __eval_expression (run, test->right);
if (rv == XP_NULL) return -1;
xp_awk_refupval (rv);
if (rv->type != XP_AWK_VAL_MAP)
{
xp_awk_refdownval (run, rv);
PANIC_I (run, XP_AWK_ENOTINDEXABLE);
}
map = ((xp_awk_val_map_t*)rv)->map;
walker.run = run;
walker.var = (xp_awk_nde_var_t*)test->left;
walker.body = nde->body;
n = xp_awk_map_walk (map, __walk_foreach, &walker);
xp_awk_refdownval (run, rv);
return n;
}
static int __run_break_statement (xp_awk_run_t* run, xp_awk_nde_break_t* nde)
{
run->exit_level = EXIT_BREAK;

View File

@ -1,5 +1,5 @@
/*
* $Id: tree.c,v 1.44 2006-04-29 12:41:47 bacon Exp $
* $Id: tree.c,v 1.45 2006-04-30 17:10:30 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -430,8 +430,18 @@ static void __print_statements (xp_awk_nde_t* tree, int depth)
break;
case XP_AWK_NDE_FOREACH:
/* TODO -------------------------------- */
xp_printf (XP_TEXT("*** FOREACH ***"));
__print_tabs (depth);
xp_printf (XP_TEXT("for "));
__print_expression (((xp_awk_nde_foreach_t*)p)->test);
xp_printf (XP_TEXT("\n"));
if (((xp_awk_nde_foreach_t*)p)->body->type == XP_AWK_NDE_BLK)
{
__print_statements (((xp_awk_nde_foreach_t*)p)->body, depth);
}
else
{
__print_statements (((xp_awk_nde_foreach_t*)p)->body, depth + 1);
}
break;
case XP_AWK_NDE_BREAK:

View File

@ -1,5 +1,5 @@
/*
* $Id: val.c,v 1.27 2006-04-24 14:38:46 bacon Exp $
* $Id: val.c,v 1.28 2006-04-30 17:10:30 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -321,7 +321,7 @@ xp_bool_t xp_awk_boolval (xp_awk_val_t* val)
return xp_false;
}
static int __print_pair (xp_awk_pair_t* pair)
static int __print_pair (xp_awk_pair_t* pair, void* arg)
{
xp_printf (XP_TEXT(" %s=>"), pair->key);
xp_awk_printval (pair->val);
@ -369,7 +369,7 @@ void xp_awk_printval (xp_awk_val_t* val)
case XP_AWK_VAL_MAP:
xp_printf (XP_TEXT("MAP["));
xp_awk_map_walk (((xp_awk_val_map_t*)val)->map, __print_pair);
xp_awk_map_walk (((xp_awk_val_map_t*)val)->map, __print_pair, XP_NULL);
xp_printf (XP_TEXT("]"));
break;

14
ase/test/awk/t4.awk Normal file
View File

@ -0,0 +1,14 @@
function main ()
{
local i;
for (i = 0; i < 10; i++)
{
abc[i*2] = i;
}
for (i = 0; i < 100; i++)
{
if (i in abc) j[i] = i;
}
}

11
ase/test/awk/t5.awk Normal file
View File

@ -0,0 +1,11 @@
BEGIN
{
x[1] = 20;
x[2] = 40;
x[3] = 50;
for (i in x)
{
j[i] = i;
}
}