*** empty log message ***
This commit is contained in:
parent
4a6dcb79f2
commit
38ff71c2f2
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: map.c,v 1.12 2006-04-18 14:49:42 bacon Exp $
|
||||
* $Id: map.c,v 1.13 2006-04-19 03:42:08 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <xp/awk/awk_i.h>
|
||||
@ -143,7 +143,8 @@ xp_awk_pair_t* xp_awk_map_put (xp_awk_map_t* map, xp_char_t* key, void* val)
|
||||
return px;
|
||||
}
|
||||
|
||||
int xp_awk_map_putx (xp_awk_map_t* map, xp_char_t* key, void* val, xp_awk_pair_t** px)
|
||||
int xp_awk_map_putx (
|
||||
xp_awk_map_t* map, xp_char_t* key, void* val, xp_awk_pair_t** px)
|
||||
{
|
||||
xp_awk_pair_t* pair;
|
||||
xp_size_t hc;
|
||||
@ -155,12 +156,6 @@ int xp_awk_map_putx (xp_awk_map_t* map, xp_char_t* key, void* val, xp_awk_pair_t
|
||||
{
|
||||
if (xp_strcmp(pair->key,key) == 0)
|
||||
{
|
||||
if (pair->key != key)
|
||||
{
|
||||
xp_free ((xp_char_t*)pair->key);
|
||||
pair->key = key;
|
||||
}
|
||||
|
||||
if (px != XP_NULL)
|
||||
*px = xp_awk_map_setpair (map, pair, val);
|
||||
else
|
||||
@ -174,7 +169,13 @@ int xp_awk_map_putx (xp_awk_map_t* map, xp_char_t* key, void* val, xp_awk_pair_t
|
||||
pair = (xp_awk_pair_t*) xp_malloc (xp_sizeof(xp_awk_pair_t));
|
||||
if (pair == XP_NULL) return -1; /* error */
|
||||
|
||||
pair->key = key;
|
||||
/*pair->key = key;*/
|
||||
pair->key = xp_strdup (key); /* duplicate the key if it is new */
|
||||
if (pair->key == XP_NULL)
|
||||
{
|
||||
xp_free (pair);
|
||||
return -1; /* error */
|
||||
}
|
||||
pair->val = val;
|
||||
pair->next = map->buck[hc];
|
||||
map->buck[hc] = pair;
|
||||
@ -196,12 +197,6 @@ xp_awk_pair_t* xp_awk_map_set (xp_awk_map_t* map, xp_char_t* key, void* val)
|
||||
{
|
||||
if (xp_strcmp(pair->key,key) == 0)
|
||||
{
|
||||
if (pair->key != key)
|
||||
{
|
||||
xp_free ((xp_char_t*)pair->key);
|
||||
pair->key = key;
|
||||
}
|
||||
|
||||
return xp_awk_map_setpair (map, pair, val);
|
||||
}
|
||||
pair = pair->next;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: parse.c,v 1.84 2006-04-18 16:04:54 bacon Exp $
|
||||
* $Id: parse.c,v 1.85 2006-04-19 03:42:08 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <xp/awk/awk_i.h>
|
||||
@ -412,6 +412,8 @@ static xp_awk_nde_t* __parse_function (xp_awk_t* awk)
|
||||
xp_awk_nde_t* body;
|
||||
xp_awk_func_t* func;
|
||||
xp_size_t nargs;
|
||||
xp_awk_pair_t* pair;
|
||||
int n;
|
||||
|
||||
/* eat up the keyword 'function' and get the next token */
|
||||
if (__get_token(awk) == -1) return XP_NULL;
|
||||
@ -582,7 +584,7 @@ static xp_awk_nde_t* __parse_function (xp_awk_t* awk)
|
||||
return XP_NULL;
|
||||
}
|
||||
|
||||
/* TODO: consider if the parameters should be saved for some reasons.. */
|
||||
/* TODO: consider if the parameter names should be saved for some reasons.. */
|
||||
nargs = xp_awk_tab_getsize (&awk->parse.params);
|
||||
/* parameter names are not required anymore. clear them */
|
||||
xp_awk_tab_clear (&awk->parse.params);
|
||||
@ -595,12 +597,12 @@ static xp_awk_nde_t* __parse_function (xp_awk_t* awk)
|
||||
return XP_NULL;
|
||||
}
|
||||
|
||||
func->name = name_dup;
|
||||
func->name = XP_NULL; /* function name set below */
|
||||
func->nargs = nargs;
|
||||
func->body = body;
|
||||
|
||||
xp_assert (xp_awk_map_get(&awk->tree.funcs, name_dup) == XP_NULL);
|
||||
if (xp_awk_map_put(&awk->tree.funcs, name_dup, func) == XP_NULL)
|
||||
n = xp_awk_map_putx (&awk->tree.funcs, name_dup, func, &pair);
|
||||
if (n < 0)
|
||||
{
|
||||
xp_free (name_dup);
|
||||
xp_awk_clrpt (body);
|
||||
@ -608,6 +610,12 @@ static xp_awk_nde_t* __parse_function (xp_awk_t* awk)
|
||||
PANIC (awk, XP_AWK_ENOMEM);
|
||||
}
|
||||
|
||||
/* duplicate functions should have been detected previously */
|
||||
xp_assert (n != 0);
|
||||
|
||||
func->name = pair->key; /* do some trick to save a string. */
|
||||
xp_free (name_dup);
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: run.c,v 1.59 2006-04-18 16:04:58 bacon Exp $
|
||||
* $Id: run.c,v 1.60 2006-04-19 03:42:08 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <xp/awk/awk_i.h>
|
||||
@ -761,32 +761,11 @@ static xp_awk_val_t* __do_assignment (
|
||||
|
||||
if (var->type == XP_AWK_NDE_NAMED)
|
||||
{
|
||||
xp_awk_pair_t* pair;
|
||||
xp_char_t* name;
|
||||
int n;
|
||||
|
||||
pair = xp_awk_map_get (&awk->run.named, var->id.name);
|
||||
if (pair == XP_NULL)
|
||||
{
|
||||
name = xp_strdup (var->id.name);
|
||||
if (name == XP_NULL)
|
||||
{
|
||||
xp_awk_freeval (awk, val);
|
||||
awk->errnum = XP_AWK_ENOMEM;
|
||||
return XP_NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
name = pair->key;
|
||||
}
|
||||
|
||||
if (xp_awk_map_put(&awk->run.named, name, val) == XP_NULL)
|
||||
{
|
||||
xp_free (name);
|
||||
xp_awk_freeval (awk, val);
|
||||
awk->errnum = XP_AWK_ENOMEM;
|
||||
return XP_NULL;
|
||||
}
|
||||
n = xp_awk_map_putx (
|
||||
&awk->run.named, var->id.name, val, XP_NULL);
|
||||
if (n < 0) PANIC (awk, XP_AWK_ENOMEM);
|
||||
|
||||
xp_awk_refupval (val);
|
||||
}
|
||||
@ -919,14 +898,7 @@ xp_printf (XP_TEXT("**** index str=>%s, map->ref=%d, map->type=%d\n"), str, map-
|
||||
PANIC (awk, XP_AWK_ENOMEM);
|
||||
}
|
||||
|
||||
if (n == 0)
|
||||
{
|
||||
/* the value for the existing key has changed.
|
||||
* str is freed only if the key is in the map.
|
||||
* otherwise, it will be taken by the map */
|
||||
xp_free (str);
|
||||
}
|
||||
|
||||
xp_awk_refupval (val);
|
||||
return val;
|
||||
}
|
||||
|
@ -17,8 +17,8 @@ function sum (i)
|
||||
|
||||
BEGIN
|
||||
{
|
||||
x = sum (10000000);
|
||||
//s = sum (100);
|
||||
//x = sum (10000000);
|
||||
x = sum (100);
|
||||
s = x;
|
||||
ss = z;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user