diff --git a/ase/awk/map.c b/ase/awk/map.c index 4f125728..285a6b7a 100644 --- a/ase/awk/map.c +++ b/ase/awk/map.c @@ -1,5 +1,5 @@ /* - * $Id: map.c,v 1.4 2006-03-05 17:07:32 bacon Exp $ + * $Id: map.c,v 1.5 2006-03-06 04:04:47 bacon Exp $ */ #include @@ -17,7 +17,7 @@ static xp_size_t __hash (const xp_char_t* key); #define FREE_PAIR(map,pair) \ do { \ - xp_free ((pair)->key); \ + xp_free ((xp_char_t*)(pair)->key); \ if ((map)->freeval != XP_NULL) \ (map)->freeval ((pair)->val); \ xp_free (pair); \ @@ -78,7 +78,7 @@ void xp_awk_map_clear (xp_awk_map_t* map) xp_assert (map->size == 0); } -xp_awk_pair_t* xp_awk_map_get (xp_awk_map_t* map, const xp_char_t* key) +xp_awk_pair_t* xp_awk_map_get (xp_awk_map_t* map, xp_char_t* key) { xp_awk_pair_t* pair; xp_size_t hc; @@ -94,16 +94,6 @@ xp_awk_pair_t* xp_awk_map_get (xp_awk_map_t* map, const xp_char_t* key) return XP_NULL; } -void* xp_awk_map_getval (xp_awk_map_t* map, const xp_char_t* key) -{ - xp_awk_pair_t* pair; - - pair = xp_awk_map_get (map, key); - if (pair == XP_NULL) return XP_NULL; - - return pair->val; -} - xp_awk_pair_t* xp_awk_map_put (xp_awk_map_t* map, xp_char_t* key, void* value) { xp_awk_pair_t* pair; @@ -116,15 +106,11 @@ xp_awk_pair_t* xp_awk_map_put (xp_awk_map_t* map, xp_char_t* key, void* value) if (xp_strcmp(pair->key,key) == 0) { if (pair->key != key) { - xp_free (pair->key); + xp_free ((xp_char_t*)pair->key); pair->key = key; } - if (map->freeval != XP_NULL) { - map->freeval (pair->val); - } - pair->val = value; - return pair; + return xp_awk_map_setpair (map, pair, value); } pair = pair->next; } @@ -152,16 +138,11 @@ xp_awk_pair_t* xp_awk_map_set (xp_awk_map_t* map, xp_char_t* key, void* value) while (pair != XP_NULL) { if (xp_strcmp(pair->key,key) == 0) { if (pair->key != key) { - xp_free (pair->key); + xp_free ((xp_char_t*)pair->key); pair->key = key; } - if (map->freeval != XP_NULL) { - map->freeval (pair->val); - } - pair->val = value; - - return pair; + return xp_awk_map_setpair (map, pair, value); } pair = pair->next; } @@ -169,7 +150,32 @@ xp_awk_pair_t* xp_awk_map_set (xp_awk_map_t* map, xp_char_t* key, void* value) return XP_NULL; } -int xp_awk_map_remove (xp_awk_map_t* map, const xp_char_t* key) +xp_awk_pair_t* xp_awk_map_getpair ( + xp_awk_map_t* map, xp_char_t* key, const void** value) +{ + xp_awk_pair_t* pair; + + pair = xp_awk_map_get (map, key); + if (pair == XP_NULL) return XP_NULL; + *value = pair->val; + return pair; +} + +xp_awk_pair_t* xp_awk_map_setpair ( + xp_awk_map_t* map, xp_awk_pair_t* pair, void* value) +{ + /* use this function with care */ + if (pair->val != value) { + if (map->freeval != XP_NULL) { + map->freeval (pair->val); + } + pair->val = value; + } + + return pair; +} + +int xp_awk_map_remove (xp_awk_map_t* map, xp_char_t* key) { xp_awk_pair_t* pair, * prev; xp_size_t hc; diff --git a/ase/awk/map.h b/ase/awk/map.h index 49369fba..5f447a28 100644 --- a/ase/awk/map.h +++ b/ase/awk/map.h @@ -1,5 +1,5 @@ /* - * $Id: map.h,v 1.3 2006-03-05 17:07:32 bacon Exp $ + * $Id: map.h,v 1.4 2006-03-06 04:04:47 bacon Exp $ */ #ifndef _XP_AWK_MAP_H_ @@ -45,13 +45,16 @@ void xp_awk_map_close (xp_awk_map_t* map); void xp_awk_map_clear (xp_awk_map_t* map); -xp_awk_pair_t* xp_awk_map_get (xp_awk_map_t* map, const xp_char_t* key); -void* xp_awk_map_getval (xp_awk_map_t* map, const xp_char_t* key); - +xp_awk_pair_t* xp_awk_map_get (xp_awk_map_t* map, xp_char_t* key); xp_awk_pair_t* xp_awk_map_put (xp_awk_map_t* map, xp_char_t* key, void* val); xp_awk_pair_t* xp_awk_map_set (xp_awk_map_t* map, xp_char_t* key, void* val); -int xp_awk_map_remove (xp_awk_map_t* map, const xp_char_t* key); +xp_awk_pair_t* xp_awk_map_getpair ( + xp_awk_map_t* map, xp_char_t* key, void** value); +xp_awk_pair_t* xp_awk_map_setpair ( + xp_awk_map_t* map, xp_awk_pair_t* pair, void* value); + +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*)); #ifdef __cplusplus diff --git a/ase/awk/run.c b/ase/awk/run.c index a07684f8..ef9e4241 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c,v 1.7 2006-03-05 17:07:33 bacon Exp $ + * $Id: run.c,v 1.8 2006-03-06 04:04:47 bacon Exp $ */ #include @@ -8,6 +8,7 @@ #include #endif +static int __activate_block (xp_awk_t* awk, xp_awk_nde_blk_t* nde); static int __run_block (xp_awk_t* awk, xp_awk_nde_blk_t* nde); static int __run_statement (xp_awk_t* awk, xp_awk_nde_t* nde); @@ -40,6 +41,15 @@ xp_awk_map_walk (&awk->run.named, __printval); return 0; } +static int __activate_block (xp_awk_t* awk, xp_awk_nde_blk_t* nde) +{ + /* + if (nde->nlocals == 0 && awk->run.top_frame != XP_NULL) { + } + */ + return -1; +} + static int __run_block (xp_awk_t* awk, xp_awk_nde_blk_t* nde) { xp_awk_nde_t* p; @@ -171,7 +181,9 @@ static xp_awk_val_t* __eval_assignment (xp_awk_t* awk, xp_awk_nde_ass_t* nde) if (tgt->type == XP_AWK_NDE_NAMED) { - xp_awk_val_t* old, * new; + /* xp_awk_val_t* old, * new; */ + xp_awk_pair_t* pair; + xp_awk_val_t* new; xp_char_t* name; new = __eval_expression(awk, nde->right); @@ -179,16 +191,33 @@ static xp_awk_val_t* __eval_assignment (xp_awk_t* awk, xp_awk_nde_ass_t* nde) xp_assert (tgt != XP_NULL); if (new == XP_NULL) return XP_NULL; + /* name = tgt->id.name; old = (xp_awk_val_t*)xp_awk_map_getval(&awk->run.named, name); - if (old == XP_NULL) { + if (old == XP_NULL) + { name = xp_strdup (tgt->id.name); - if (name == XP_NULL) { + if (name == XP_NULL) + { xp_awk_freeval(new); awk->errnum = XP_AWK_ENOMEM; return XP_NULL; } } + */ + + pair = xp_awk_map_get(&awk->run.named, tgt->id.name); + if (pair == XP_NULL) + { + name = xp_strdup (tgt->id.name); + if (name == XP_NULL) + { + xp_awk_freeval(new); + awk->errnum = XP_AWK_ENOMEM; + return XP_NULL; + } + } + else name = pair->key; if (xp_awk_map_put(&awk->run.named, name, new) == XP_NULL) {