*** empty log message ***

This commit is contained in:
hyung-hwan 2006-04-16 16:30:59 +00:00
parent 3eda39390d
commit 9434e96a90
5 changed files with 121 additions and 42 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: parse.c,v 1.82 2006-04-16 04:31:38 bacon Exp $ * $Id: parse.c,v 1.83 2006-04-16 16:30:59 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -1531,6 +1531,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
/*nde->id.name = XP_NULL;*/ /*nde->id.name = XP_NULL;*/
nde->id.name = name_dup; nde->id.name = name_dup;
nde->id.idxa = idxa; nde->id.idxa = idxa;
nde->idx = XP_NULL;
return (xp_awk_nde_t*)nde; return (xp_awk_nde_t*)nde;
} }
@ -1544,6 +1545,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
/*nde->id.name = XP_NULL;*/ /*nde->id.name = XP_NULL;*/
nde->id.name = name_dup; nde->id.name = name_dup;
nde->id.idxa = idxa; nde->id.idxa = idxa;
nde->idx = XP_NULL;
return (xp_awk_nde_t*)nde; return (xp_awk_nde_t*)nde;
} }
@ -1557,6 +1559,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
/*nde->id.name = XP_NULL;*/ /*nde->id.name = XP_NULL;*/
nde->id.name = name_dup; nde->id.name = name_dup;
nde->id.idxa = idxa; nde->id.idxa = idxa;
nde->idx = XP_NULL;
return (xp_awk_nde_t*)nde; return (xp_awk_nde_t*)nde;
} }
@ -1567,6 +1570,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
nde->next = XP_NULL; nde->next = XP_NULL;
nde->id.name = name_dup; nde->id.name = name_dup;
nde->id.idxa = (xp_size_t)-1; nde->id.idxa = (xp_size_t)-1;
nde->idx = XP_NULL;
return (xp_awk_nde_t*)nde; return (xp_awk_nde_t*)nde;
} }
@ -1712,7 +1716,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
static xp_awk_nde_t* __parse_hashidx (xp_awk_t* awk, xp_char_t* name) static xp_awk_nde_t* __parse_hashidx (xp_awk_t* awk, xp_char_t* name)
{ {
xp_awk_nde_t* idx; xp_awk_nde_t* idx;
xp_awk_nde_idx_t* nde; xp_awk_nde_var_t* nde;
xp_size_t idxa; xp_size_t idxa;
if (__get_token(awk) == -1) return XP_NULL; if (__get_token(awk) == -1) return XP_NULL;
@ -1732,7 +1736,7 @@ static xp_awk_nde_t* __parse_hashidx (xp_awk_t* awk, xp_char_t* name)
return XP_NULL; return XP_NULL;
} }
nde = (xp_awk_nde_idx_t*)xp_malloc(xp_sizeof(xp_awk_nde_idx_t)); nde = (xp_awk_nde_var_t*)xp_malloc(xp_sizeof(xp_awk_nde_var_t));
if (nde == XP_NULL) if (nde == XP_NULL)
{ {
xp_awk_clrpt (idx); xp_awk_clrpt (idx);
@ -1776,6 +1780,7 @@ static xp_awk_nde_t* __parse_hashidx (xp_awk_t* awk, xp_char_t* name)
/*nde->id.name = XP_NULL;*/ /*nde->id.name = XP_NULL;*/
nde->id.name = name; nde->id.name = name;
nde->id.idxa = idxa; nde->id.idxa = idxa;
nde->idx = idx;
return (xp_awk_nde_t*)nde; return (xp_awk_nde_t*)nde;
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: run.c,v 1.52 2006-04-16 13:30:19 bacon Exp $ * $Id: run.c,v 1.53 2006-04-16 16:30:59 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -749,6 +749,13 @@ static xp_awk_val_t* __eval_assignment (xp_awk_t* awk, xp_awk_nde_t* nde)
static xp_awk_val_t* __do_assignment ( static xp_awk_val_t* __do_assignment (
xp_awk_t* awk, xp_awk_nde_var_t* var, xp_awk_val_t* val) xp_awk_t* awk, xp_awk_nde_var_t* var, xp_awk_val_t* val)
{ {
if (val->type == XP_AWK_VAL_MAP)
{
/* TODO */
/* a map cannot be assigned to a variable */
PANIC (awk, XP_AWK_EMAPASS);
}
if (var->type == XP_AWK_NDE_NAMED) if (var->type == XP_AWK_NDE_NAMED)
{ {
xp_awk_pair_t* pair; xp_awk_pair_t* pair;
@ -804,7 +811,62 @@ static xp_awk_val_t* __do_assignment (
} }
else if (var->type == XP_AWK_NDE_GLOBALIDX) else if (var->type == XP_AWK_NDE_GLOBALIDX)
{ {
/* TODO: */ xp_awk_nde_var_t* tgt = (xp_awk_nde_var_t*)nde;
xp_awk_val_t* v = STACK_GLOBAL(awk,tgt->id.idxa);
xp_awk_val_t* idx, *res;
xp_char_t* str;
xp_awk_map_val_t* mv;
if (v->type != XP_AWK_VAL_NIL ||
v->type != XP_AWK_VAL_MAP) PANIC (awk, XP_AWK_ENOTINDEXABLE);
xp_assert (tgt->idx != XP_NULL);
idx = __eval_expression (awk, tgt->idx);
if (idx == XP_NULL) return XP_NULL;
xp_awk_refupval (idx);
str = __val_to_str (idx);
if (str == XP_NULL)
{
/* TODO: how to tell memory error from conversion error? */
xp_awk_refdownval (awk, idx);
/*PANIC (awk, XP_AWK_ENOMEM);*/
PANIC (awk, XP_AWK_EINDEX);
}
if (v->type == XP_AWK_VAL_NIL)
{
mv = xp_awk_makemap_val (awk);
if (mv == XP_NULL)
{
xp_free (str);
xp_awk_refdownval (awk, idx);
PANIC (awk, XP_AWK_ENOMEM);
}
xp_awk_refdownval (awk, v);
STACK_GLOBAL(awk,var->id.idxa) = mv;
xp_awk_refupval (awk, mv);
}
else
{
mv = STACK_GLOBAL(awk,var->id.idxa);
}
// TODO: refdown old val....
if (xp_awk_map_put(awk, str, val) == XP_NULL)
{
// TODO:............
xp_free (str);
xp_awk_refdownval (awk, idx);
PANIC (awk, XP_AWK_ENOMEM);
}
xp_free (str);
xp_awk_refdownval (awk, idx);
xp_awk_refupval (val);
} }
else if (var->type == XP_AWK_NDE_LOCALIDX) else if (var->type == XP_AWK_NDE_LOCALIDX)
{ {
@ -2074,24 +2136,37 @@ static xp_awk_val_t* __eval_namedidx (xp_awk_t* awk, xp_awk_nde_t* nde)
static xp_awk_val_t* __eval_globalidx (xp_awk_t* awk, xp_awk_nde_t* nde) static xp_awk_val_t* __eval_globalidx (xp_awk_t* awk, xp_awk_nde_t* nde)
{ {
xp_awk_nde_idx_t* tgt = (xp_awk_nde_idx_t*)nde; xp_awk_nde_var_t* tgt = (xp_awk_nde_var_t*)nde;
xp_awk_val_t* v = STACK_GLOBAL(awk,tgt->id.idxa); xp_awk_val_t* v = STACK_GLOBAL(awk,tgt->id.idxa);
xp_awk_val_t* idx; xp_awk_val_t* idx, *res;
xp_char_t* str; xp_char_t* str;
xp_awk_pair_t* pair;
if (v->type != XP_AWK_VAL_MAP) PANIC (awk, XP_AWK_ENOTINDEXABLE); if (v->type != XP_AWK_VAL_MAP) PANIC (awk, XP_AWK_ENOTINDEXABLE);
xp_assert (tgt->idx != XP_NULL);
idx = __eval_expression (awk, tgt->idx); idx = __eval_expression (awk, tgt->idx);
if (idx == XP_NULL) return XP_NULL;
xp_awk_refupval (idx);
str = __val_to_str (idx); str = __val_to_str (idx);
if (str == XP_NULL) if (str == XP_NULL)
{ {
/* TODO: how to tell memory error from conversion error? */ /* TODO: how to tell memory error from conversion error? */
xp_awk_refdownval (awk, idx);
/*PANIC (awk, XP_AWK_ENOMEM);*/ /*PANIC (awk, XP_AWK_ENOMEM);*/
PANIC (awk, XP_AWK_EINDEX); PANIC (awk, XP_AWK_EINDEX);
} }
/* TODO: check this out........ */
pair = xp_awk_map_get (((xp_awk_val_map_t*)v)->map, str);
res = (pair == XP_NULL)? xp_awk_val_nil: (xp_awk_val_t*)pair->val;
xp_free (str); xp_free (str);
return XP_NULL; xp_awk_refdownval (awk, idx);
return res;
} }
static xp_awk_val_t* __eval_localidx (xp_awk_t* awk, xp_awk_nde_t* nde) static xp_awk_val_t* __eval_localidx (xp_awk_t* awk, xp_awk_nde_t* nde)

View File

@ -1,5 +1,5 @@
/* /*
* $Id: tree.c,v 1.38 2006-04-16 04:31:38 bacon Exp $ * $Id: tree.c,v 1.39 2006-04-16 16:30:59 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -173,25 +173,29 @@ static int __print_expression (xp_awk_nde_t* nde)
xp_assert (((xp_awk_nde_var_t*)nde)->id.idxa != (xp_size_t)-1); xp_assert (((xp_awk_nde_var_t*)nde)->id.idxa != (xp_size_t)-1);
xp_printf (XP_TEXT("__arg%lu"), xp_printf (XP_TEXT("__arg%lu"),
(unsigned long)((xp_awk_nde_var_t*)nde)->id.idxa); (unsigned long)((xp_awk_nde_var_t*)nde)->id.idxa);
xp_assert (((xp_awk_nde_var_t*)nde)->idx == XP_NULL);
break; break;
case XP_AWK_NDE_ARGIDX: case XP_AWK_NDE_ARGIDX:
xp_assert (((xp_awk_nde_var_t*)nde)->id.idxa != (xp_size_t)-1); xp_assert (((xp_awk_nde_var_t*)nde)->id.idxa != (xp_size_t)-1);
xp_printf (XP_TEXT("__arg%lu["), xp_printf (XP_TEXT("__arg%lu["),
(unsigned long)((xp_awk_nde_idx_t*)nde)->id.idxa); (unsigned long)((xp_awk_nde_var_t*)nde)->id.idxa);
__print_expression (((xp_awk_nde_idx_t*)nde)->idx); xp_assert (((xp_awk_nde_var_t*)nde)->idx != XP_NULL);
__print_expression (((xp_awk_nde_var_t*)nde)->idx);
xp_printf (XP_TEXT("]")); xp_printf (XP_TEXT("]"));
break; break;
case XP_AWK_NDE_NAMED: case XP_AWK_NDE_NAMED:
xp_assert (((xp_awk_nde_var_t*)nde)->id.idxa == (xp_size_t)-1); xp_assert (((xp_awk_nde_var_t*)nde)->id.idxa == (xp_size_t)-1);
xp_printf (XP_TEXT("%s"), ((xp_awk_nde_var_t*)nde)->id.name); xp_printf (XP_TEXT("%s"), ((xp_awk_nde_var_t*)nde)->id.name);
xp_assert (((xp_awk_nde_var_t*)nde)->idx == XP_NULL);
break; break;
case XP_AWK_NDE_NAMEDIDX: case XP_AWK_NDE_NAMEDIDX:
xp_assert (((xp_awk_nde_idx_t*)nde)->id.idxa == (xp_size_t)-1); xp_assert (((xp_awk_nde_var_t*)nde)->id.idxa == (xp_size_t)-1);
xp_printf (XP_TEXT("%s["), ((xp_awk_nde_idx_t*)nde)->id.name); xp_printf (XP_TEXT("%s["), ((xp_awk_nde_var_t*)nde)->id.name);
__print_expression (((xp_awk_nde_idx_t*)nde)->idx); xp_assert (((xp_awk_nde_var_t*)nde)->idx != XP_NULL);
__print_expression (((xp_awk_nde_var_t*)nde)->idx);
xp_printf (XP_TEXT("]")); xp_printf (XP_TEXT("]"));
break; break;
@ -205,19 +209,21 @@ static int __print_expression (xp_awk_nde_t* nde)
{ {
xp_printf (XP_TEXT("%s"), ((xp_awk_nde_var_t*)nde)->id.name); xp_printf (XP_TEXT("%s"), ((xp_awk_nde_var_t*)nde)->id.name);
} }
xp_assert (((xp_awk_nde_var_t*)nde)->idx == XP_NULL);
break; break;
case XP_AWK_NDE_GLOBALIDX: case XP_AWK_NDE_GLOBALIDX:
if (((xp_awk_nde_idx_t*)nde)->id.idxa != (xp_size_t)-1) if (((xp_awk_nde_var_t*)nde)->id.idxa != (xp_size_t)-1)
{ {
xp_printf (XP_TEXT("__global%lu["), xp_printf (XP_TEXT("__global%lu["),
(unsigned long)((xp_awk_nde_idx_t*)nde)->id.idxa); (unsigned long)((xp_awk_nde_var_t*)nde)->id.idxa);
} }
else else
{ {
xp_printf (XP_TEXT("%s["), ((xp_awk_nde_idx_t*)nde)->id.name); xp_printf (XP_TEXT("%s["), ((xp_awk_nde_var_t*)nde)->id.name);
} }
__print_expression (((xp_awk_nde_idx_t*)nde)->idx); xp_assert (((xp_awk_nde_var_t*)nde)->idx != XP_NULL);
__print_expression (((xp_awk_nde_var_t*)nde)->idx);
xp_printf (XP_TEXT("]")); xp_printf (XP_TEXT("]"));
break; break;
@ -231,19 +237,21 @@ static int __print_expression (xp_awk_nde_t* nde)
{ {
xp_printf (XP_TEXT("%s"), ((xp_awk_nde_var_t*)nde)->id.name); xp_printf (XP_TEXT("%s"), ((xp_awk_nde_var_t*)nde)->id.name);
} }
xp_assert (((xp_awk_nde_var_t*)nde)->idx == XP_NULL);
break; break;
case XP_AWK_NDE_LOCALIDX: case XP_AWK_NDE_LOCALIDX:
if (((xp_awk_nde_idx_t*)nde)->id.idxa != (xp_size_t)-1) if (((xp_awk_nde_var_t*)nde)->id.idxa != (xp_size_t)-1)
{ {
xp_printf (XP_TEXT("__local%lu["), xp_printf (XP_TEXT("__local%lu["),
(unsigned long)((xp_awk_nde_idx_t*)nde)->id.idxa); (unsigned long)((xp_awk_nde_var_t*)nde)->id.idxa);
} }
else else
{ {
xp_printf (XP_TEXT("%s["), ((xp_awk_nde_idx_t*)nde)->id.name); xp_printf (XP_TEXT("%s["), ((xp_awk_nde_var_t*)nde)->id.name);
} }
__print_expression (((xp_awk_nde_idx_t*)nde)->idx); xp_assert (((xp_awk_nde_var_t*)nde)->idx != XP_NULL);
__print_expression (((xp_awk_nde_var_t*)nde)->idx);
xp_printf (XP_TEXT("]")); xp_printf (XP_TEXT("]"));
break; break;
@ -597,23 +605,25 @@ void xp_awk_clrpt (xp_awk_nde_t* tree)
break; break;
case XP_AWK_NDE_NAMED: case XP_AWK_NDE_NAMED:
xp_assert (((xp_awk_nde_idx_t*)p)->id.name != XP_NULL); xp_assert (((xp_awk_nde_var_t*)p)->id.name != XP_NULL);
case XP_AWK_NDE_GLOBAL: case XP_AWK_NDE_GLOBAL:
case XP_AWK_NDE_LOCAL: case XP_AWK_NDE_LOCAL:
case XP_AWK_NDE_ARG: case XP_AWK_NDE_ARG:
xp_assert (((xp_awk_nde_var_t*)p)->idx == XP_NULL);
if (((xp_awk_nde_var_t*)p)->id.name != XP_NULL) if (((xp_awk_nde_var_t*)p)->id.name != XP_NULL)
xp_free (((xp_awk_nde_var_t*)p)->id.name); xp_free (((xp_awk_nde_var_t*)p)->id.name);
xp_free (p); xp_free (p);
break; break;
case XP_AWK_NDE_NAMEDIDX: case XP_AWK_NDE_NAMEDIDX:
xp_assert (((xp_awk_nde_idx_t*)p)->id.name != XP_NULL); xp_assert (((xp_awk_nde_var_t*)p)->id.name != XP_NULL);
case XP_AWK_NDE_GLOBALIDX: case XP_AWK_NDE_GLOBALIDX:
case XP_AWK_NDE_LOCALIDX: case XP_AWK_NDE_LOCALIDX:
case XP_AWK_NDE_ARGIDX: case XP_AWK_NDE_ARGIDX:
xp_awk_clrpt (((xp_awk_nde_idx_t*)p)->idx); xp_assert (((xp_awk_nde_var_t*)p)->idx != XP_NULL);
if (((xp_awk_nde_idx_t*)p)->id.name != XP_NULL) xp_awk_clrpt (((xp_awk_nde_var_t*)p)->idx);
xp_free (((xp_awk_nde_idx_t*)p)->id.name); if (((xp_awk_nde_var_t*)p)->id.name != XP_NULL)
xp_free (((xp_awk_nde_var_t*)p)->id.name);
xp_free (p); xp_free (p);
break; break;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: tree.h,v 1.33 2006-04-14 16:26:00 bacon Exp $ * $Id: tree.h,v 1.34 2006-04-16 16:30:59 bacon Exp $
*/ */
#ifndef _XP_AWK_TREE_H_ #ifndef _XP_AWK_TREE_H_
@ -65,7 +65,6 @@ typedef struct xp_awk_nde_int_t xp_awk_nde_int_t;
typedef struct xp_awk_nde_real_t xp_awk_nde_real_t; typedef struct xp_awk_nde_real_t xp_awk_nde_real_t;
typedef struct xp_awk_nde_str_t xp_awk_nde_str_t; typedef struct xp_awk_nde_str_t xp_awk_nde_str_t;
typedef struct xp_awk_nde_var_t xp_awk_nde_var_t; typedef struct xp_awk_nde_var_t xp_awk_nde_var_t;
typedef struct xp_awk_nde_idx_t xp_awk_nde_idx_t;
typedef struct xp_awk_nde_call_t xp_awk_nde_call_t; typedef struct xp_awk_nde_call_t xp_awk_nde_call_t;
typedef struct xp_awk_nde_if_t xp_awk_nde_if_t; typedef struct xp_awk_nde_if_t xp_awk_nde_if_t;
@ -165,17 +164,7 @@ struct xp_awk_nde_var_t
xp_char_t* name; xp_char_t* name;
xp_size_t idxa; xp_size_t idxa;
} id; } id;
}; xp_awk_nde_t* idx; /* XP_NULL for XXXIDX */
struct xp_awk_nde_idx_t
{
XP_AWK_NDE_HDR;
struct /* could it be union? */
{
xp_char_t* name;
xp_size_t idxa;
} id;
xp_awk_nde_t* idx;
}; };
/* XP_AWK_NDE_CALL */ /* XP_AWK_NDE_CALL */

View File

@ -1,5 +1,5 @@
/* /*
* $Id: val.h,v 1.15 2006-04-14 10:56:42 bacon Exp $ * $Id: val.h,v 1.16 2006-04-16 16:30:59 bacon Exp $
*/ */
#ifndef _XP_AWK_VAL_H_ #ifndef _XP_AWK_VAL_H_
@ -66,7 +66,7 @@ struct xp_awk_val_str_t
struct xp_awk_val_map_t struct xp_awk_val_map_t
{ {
XP_AWK_VAL_HDR; XP_AWK_VAL_HDR;
/* xp_awk_vap_t vap; */ xp_awk_map_t* map;
}; };
#ifdef __cplusplus #ifdef __cplusplus