From 9434e96a9040b5f467b229178b3ae588cf93208b Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 16 Apr 2006 16:30:59 +0000 Subject: [PATCH] *** empty log message *** --- ase/awk/parse.c | 11 +++++-- ase/awk/run.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++--- ase/awk/tree.c | 48 +++++++++++++++++----------- ase/awk/tree.h | 15 ++------- ase/awk/val.h | 4 +-- 5 files changed, 121 insertions(+), 42 deletions(-) diff --git a/ase/awk/parse.c b/ase/awk/parse.c index 49a836ab..fac1a09d 100644 --- a/ase/awk/parse.c +++ b/ase/awk/parse.c @@ -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 @@ -1531,6 +1531,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk) /*nde->id.name = XP_NULL;*/ nde->id.name = name_dup; nde->id.idxa = idxa; + nde->idx = XP_NULL; 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 = name_dup; nde->id.idxa = idxa; + nde->idx = XP_NULL; 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 = name_dup; nde->id.idxa = idxa; + nde->idx = XP_NULL; 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->id.name = name_dup; nde->id.idxa = (xp_size_t)-1; + nde->idx = XP_NULL; 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) { xp_awk_nde_t* idx; - xp_awk_nde_idx_t* nde; + xp_awk_nde_var_t* nde; xp_size_t idxa; 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; } - 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) { 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 = name; nde->id.idxa = idxa; + nde->idx = idx; return (xp_awk_nde_t*)nde; } diff --git a/ase/awk/run.c b/ase/awk/run.c index 8121fd43..c1d81733 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -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 @@ -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 ( 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) { xp_awk_pair_t* pair; @@ -804,7 +811,62 @@ static xp_awk_val_t* __do_assignment ( } 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) { @@ -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) { - 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* idx; + xp_awk_val_t* idx, *res; xp_char_t* str; + xp_awk_pair_t* pair; if (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); } +/* 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); - 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) diff --git a/ase/awk/tree.c b/ase/awk/tree.c index 8d561b85..fac3536a 100644 --- a/ase/awk/tree.c +++ b/ase/awk/tree.c @@ -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 @@ -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_printf (XP_TEXT("__arg%lu"), (unsigned long)((xp_awk_nde_var_t*)nde)->id.idxa); + xp_assert (((xp_awk_nde_var_t*)nde)->idx == XP_NULL); break; case XP_AWK_NDE_ARGIDX: xp_assert (((xp_awk_nde_var_t*)nde)->id.idxa != (xp_size_t)-1); xp_printf (XP_TEXT("__arg%lu["), - (unsigned long)((xp_awk_nde_idx_t*)nde)->id.idxa); - __print_expression (((xp_awk_nde_idx_t*)nde)->idx); + (unsigned long)((xp_awk_nde_var_t*)nde)->id.idxa); + xp_assert (((xp_awk_nde_var_t*)nde)->idx != XP_NULL); + __print_expression (((xp_awk_nde_var_t*)nde)->idx); xp_printf (XP_TEXT("]")); break; case XP_AWK_NDE_NAMED: 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_assert (((xp_awk_nde_var_t*)nde)->idx == XP_NULL); break; case XP_AWK_NDE_NAMEDIDX: - xp_assert (((xp_awk_nde_idx_t*)nde)->id.idxa == (xp_size_t)-1); - xp_printf (XP_TEXT("%s["), ((xp_awk_nde_idx_t*)nde)->id.name); - __print_expression (((xp_awk_nde_idx_t*)nde)->idx); + 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_assert (((xp_awk_nde_var_t*)nde)->idx != XP_NULL); + __print_expression (((xp_awk_nde_var_t*)nde)->idx); xp_printf (XP_TEXT("]")); 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_assert (((xp_awk_nde_var_t*)nde)->idx == XP_NULL); break; 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["), - (unsigned long)((xp_awk_nde_idx_t*)nde)->id.idxa); + (unsigned long)((xp_awk_nde_var_t*)nde)->id.idxa); } 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("]")); 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_assert (((xp_awk_nde_var_t*)nde)->idx == XP_NULL); break; 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["), - (unsigned long)((xp_awk_nde_idx_t*)nde)->id.idxa); + (unsigned long)((xp_awk_nde_var_t*)nde)->id.idxa); } 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("]")); break; @@ -597,23 +605,25 @@ void xp_awk_clrpt (xp_awk_nde_t* tree) break; 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_LOCAL: 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) xp_free (((xp_awk_nde_var_t*)p)->id.name); xp_free (p); break; 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_LOCALIDX: case XP_AWK_NDE_ARGIDX: - xp_awk_clrpt (((xp_awk_nde_idx_t*)p)->idx); - if (((xp_awk_nde_idx_t*)p)->id.name != XP_NULL) - xp_free (((xp_awk_nde_idx_t*)p)->id.name); + xp_assert (((xp_awk_nde_var_t*)p)->idx != XP_NULL); + xp_awk_clrpt (((xp_awk_nde_var_t*)p)->idx); + if (((xp_awk_nde_var_t*)p)->id.name != XP_NULL) + xp_free (((xp_awk_nde_var_t*)p)->id.name); xp_free (p); break; diff --git a/ase/awk/tree.h b/ase/awk/tree.h index 223363b7..0dc5c071 100644 --- a/ase/awk/tree.h +++ b/ase/awk/tree.h @@ -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_ @@ -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_str_t xp_awk_nde_str_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_if_t xp_awk_nde_if_t; @@ -165,17 +164,7 @@ struct xp_awk_nde_var_t xp_char_t* name; xp_size_t idxa; } id; -}; - -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_t* idx; /* XP_NULL for XXXIDX */ }; /* XP_AWK_NDE_CALL */ diff --git a/ase/awk/val.h b/ase/awk/val.h index 3b6b26e1..18a1a09f 100644 --- a/ase/awk/val.h +++ b/ase/awk/val.h @@ -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_ @@ -66,7 +66,7 @@ struct xp_awk_val_str_t struct xp_awk_val_map_t { XP_AWK_VAL_HDR; - /* xp_awk_vap_t vap; */ + xp_awk_map_t* map; }; #ifdef __cplusplus