*** empty log message ***

This commit is contained in:
hyung-hwan 2006-06-19 15:43:27 +00:00
parent c871f68651
commit 706a535740
7 changed files with 93 additions and 48 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.c,v 1.53 2006-06-19 09:08:50 bacon Exp $ * $Id: awk.c,v 1.54 2006-06-19 15:43:27 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -225,7 +225,7 @@ xp_size_t xp_awk_getsrcline (xp_awk_t* awk)
} }
/* TODO: redo it */ /* TODO: imrove this... should it close io when it is overridden with a new handler??? */
int xp_awk_setextio (xp_awk_t* awk, int id, xp_awk_io_t handler, void* arg) int xp_awk_setextio (xp_awk_t* awk, int id, xp_awk_io_t handler, void* arg)
{ {
if (id < 0 || id >= xp_countof(awk->extio)) if (id < 0 || id >= xp_countof(awk->extio))
@ -233,6 +233,7 @@ int xp_awk_setextio (xp_awk_t* awk, int id, xp_awk_io_t handler, void* arg)
awk->errnum = XP_AWK_EINVAL; awk->errnum = XP_AWK_EINVAL;
return -1; return -1;
} }
awk->extio[id] = handler; awk->extio[id] = handler;
return 0; return 0;
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk_i.h,v 1.17 2006-06-19 09:08:50 bacon Exp $ * $Id: awk_i.h,v 1.18 2006-06-19 15:43:27 bacon Exp $
*/ */
#ifndef _XP_AWK_AWKI_H_ #ifndef _XP_AWK_AWKI_H_
@ -10,12 +10,12 @@ typedef struct xp_awk_run_t xp_awk_run_t;
typedef struct xp_awk_tree_t xp_awk_tree_t; typedef struct xp_awk_tree_t xp_awk_tree_t;
#include <xp/awk/awk.h> #include <xp/awk/awk.h>
#include <xp/awk/tree.h>
#include <xp/awk/tab.h>
#include <xp/awk/map.h> #include <xp/awk/map.h>
#include <xp/awk/val.h> #include <xp/awk/val.h>
#include <xp/awk/run.h>
#include <xp/awk/func.h> #include <xp/awk/func.h>
#include <xp/awk/tree.h>
#include <xp/awk/tab.h>
#include <xp/awk/run.h>
#ifdef XP_AWK_STAND_ALONE #ifdef XP_AWK_STAND_ALONE
#include <xp/awk/sa.h> #include <xp/awk/sa.h>

View File

@ -1,5 +1,5 @@
/* /*
* $Id: parse.c,v 1.116 2006-06-18 11:18:49 bacon Exp $ * $Id: parse.c,v 1.117 2006-06-19 15:43:27 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -145,7 +145,8 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk);
static xp_awk_nde_t* __parse_primary_ident (xp_awk_t* awk); static xp_awk_nde_t* __parse_primary_ident (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);
static xp_awk_nde_t* __parse_funcall (xp_awk_t* awk, xp_char_t* name); static xp_awk_nde_t* __parse_fncall (
xp_awk_t* awk, xp_char_t* name, xp_awk_bfn_t* bfn);
static xp_awk_nde_t* __parse_if (xp_awk_t* awk); static xp_awk_nde_t* __parse_if (xp_awk_t* awk);
static xp_awk_nde_t* __parse_while (xp_awk_t* awk); static xp_awk_nde_t* __parse_while (xp_awk_t* awk);
static xp_awk_nde_t* __parse_for (xp_awk_t* awk); static xp_awk_nde_t* __parse_for (xp_awk_t* awk);
@ -2043,27 +2044,18 @@ static xp_awk_nde_t* __parse_primary_ident (xp_awk_t* awk)
{ {
xp_awk_nde_t* nde; xp_awk_nde_t* nde;
xp_free (name_dup);
if (!MATCH(awk,TOKEN_LPAREN)) if (!MATCH(awk,TOKEN_LPAREN))
{ {
/* built-in function should be in the form /* built-in function should be in the form
* of the function call */ * of the function call */
xp_free (name_dup);
PANIC (awk, XP_AWK_ELPAREN); PANIC (awk, XP_AWK_ELPAREN);
} }
/* bfn->handler... */ nde = __parse_fncall (awk, XP_NULL, bfn);
nde = __parse_funcall (awk, name_dup);
if (nde == XP_NULL) xp_free (name_dup);
return (xp_awk_nde_t*)nde; return (xp_awk_nde_t*)nde;
} }
/* TODO: user-defined functions */
/*
if (__is_ufname (name_dup))
{
}
*/
/* now we know that name_dup is a normal identifier. */ /* now we know that name_dup is a normal identifier. */
if (MATCH(awk,TOKEN_LBRACK)) if (MATCH(awk,TOKEN_LBRACK))
{ {
@ -2076,7 +2068,7 @@ static xp_awk_nde_t* __parse_primary_ident (xp_awk_t* awk)
{ {
/* function call */ /* function call */
xp_awk_nde_t* nde; xp_awk_nde_t* nde;
nde = __parse_funcall (awk, name_dup); nde = __parse_fncall (awk, name_dup, XP_NULL);
if (nde == XP_NULL) xp_free (name_dup); if (nde == XP_NULL) xp_free (name_dup);
return (xp_awk_nde_t*)nde; return (xp_awk_nde_t*)nde;
} }
@ -2271,7 +2263,8 @@ static xp_awk_nde_t* __parse_hashidx (xp_awk_t* awk, xp_char_t* name)
PANIC (awk, XP_AWK_EUNDEF); PANIC (awk, XP_AWK_EUNDEF);
} }
static xp_awk_nde_t* __parse_funcall (xp_awk_t* awk, xp_char_t* name) static xp_awk_nde_t* __parse_fncall (
xp_awk_t* awk, xp_char_t* name, xp_awk_bfn_t* bfn)
{ {
xp_awk_nde_t* head, * curr, * nde; xp_awk_nde_t* head, * curr, * nde;
xp_awk_nde_call_t* call; xp_awk_nde_call_t* call;
@ -2336,11 +2329,22 @@ static xp_awk_nde_t* __parse_funcall (xp_awk_t* awk, xp_char_t* name)
PANIC (awk, XP_AWK_ENOMEM); PANIC (awk, XP_AWK_ENOMEM);
} }
call->type = XP_AWK_NDE_CALL; if (bfn != XP_NULL)
call->next = XP_NULL; {
call->name = name; call->type = XP_AWK_NDE_BFN;
call->args = head; call->next = XP_NULL;
call->nargs = nargs; call->what.bfn = bfn;
call->args = head;
call->nargs = nargs;
}
else
{
call->type = XP_AWK_NDE_UFN;
call->next = XP_NULL;
call->what.name = name;
call->args = head;
call->nargs = nargs;
}
return (xp_awk_nde_t*)call; return (xp_awk_nde_t*)call;
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: run.c,v 1.99 2006-06-19 09:08:50 bacon Exp $ * $Id: run.c,v 1.100 2006-06-19 15:43:27 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -120,7 +120,8 @@ static xp_awk_val_t* __eval_unary (xp_awk_run_t* run, xp_awk_nde_t* nde);
static xp_awk_val_t* __eval_incpre (xp_awk_run_t* run, xp_awk_nde_t* nde); static xp_awk_val_t* __eval_incpre (xp_awk_run_t* run, xp_awk_nde_t* nde);
static xp_awk_val_t* __eval_incpst (xp_awk_run_t* run, xp_awk_nde_t* nde); static xp_awk_val_t* __eval_incpst (xp_awk_run_t* run, xp_awk_nde_t* nde);
static xp_awk_val_t* __eval_cnd (xp_awk_run_t* run, xp_awk_nde_t* nde); static xp_awk_val_t* __eval_cnd (xp_awk_run_t* run, xp_awk_nde_t* nde);
static xp_awk_val_t* __eval_call (xp_awk_run_t* run, xp_awk_nde_t* nde); static xp_awk_val_t* __eval_bfn (xp_awk_run_t* run, xp_awk_nde_t* nde);
static xp_awk_val_t* __eval_ufn (xp_awk_run_t* run, xp_awk_nde_t* nde);
static xp_awk_val_t* __eval_int (xp_awk_run_t* run, xp_awk_nde_t* nde); static xp_awk_val_t* __eval_int (xp_awk_run_t* run, xp_awk_nde_t* nde);
static xp_awk_val_t* __eval_real (xp_awk_run_t* run, xp_awk_nde_t* nde); static xp_awk_val_t* __eval_real (xp_awk_run_t* run, xp_awk_nde_t* nde);
static xp_awk_val_t* __eval_str (xp_awk_run_t* run, xp_awk_nde_t* nde); static xp_awk_val_t* __eval_str (xp_awk_run_t* run, xp_awk_nde_t* nde);
@ -315,15 +316,15 @@ static int __run_main (xp_awk_run_t* run)
}; };
static xp_awk_nde_call_t nde = static xp_awk_nde_call_t nde =
{ {
XP_AWK_NDE_CALL, /* type */ XP_AWK_NDE_UFN, /* type */
XP_NULL, /* next */ XP_NULL, /* next */
m_a_i_n, /* name */ m_a_i_n, /* name */
XP_NULL /* args */ XP_NULL /* args */
}; };
run->exit_level = EXIT_NONE; run->exit_level = EXIT_NONE;
v = __eval_call(run,(xp_awk_nde_t*)&nde); v = __eval_ufn (run, (xp_awk_nde_t*)&nde);
if (v == XP_NULL) n = -1; if (v == XP_NULL) n = -1;
else else
{ {
@ -1000,7 +1001,7 @@ static int __run_return_statement (xp_awk_run_t* run, xp_awk_nde_return_t* nde)
xp_awk_refdownval (run, STACK_RETVAL(run)); xp_awk_refdownval (run, STACK_RETVAL(run));
STACK_RETVAL(run) = val; STACK_RETVAL(run) = val;
xp_awk_refupval (val); /* see __eval_call for the trick */ xp_awk_refupval (val); /* see __eval_ufn for the trick */
/*xp_printf (XP_T("set return value....\n"));*/ /*xp_printf (XP_T("set return value....\n"));*/
} }
@ -1065,7 +1066,8 @@ static xp_awk_val_t* __eval_expression (xp_awk_run_t* run, xp_awk_nde_t* nde)
__eval_incpre, __eval_incpre,
__eval_incpst, __eval_incpst,
__eval_cnd, __eval_cnd,
__eval_call, __eval_bfn,
__eval_ufn,
__eval_int, __eval_int,
__eval_real, __eval_real,
__eval_str, __eval_str,
@ -2528,7 +2530,13 @@ static xp_awk_val_t* __eval_cnd (xp_awk_run_t* run, xp_awk_nde_t* nde)
return v; return v;
} }
static xp_awk_val_t* __eval_call (xp_awk_run_t* run, xp_awk_nde_t* nde) static xp_awk_val_t* __eval_bfn (xp_awk_run_t* run, xp_awk_nde_t* nde)
{
xp_printf (XP_T("__eval_bfn not implemented properly....\n"));
PANIC (run, XP_AWK_EINTERNAL);
}
static xp_awk_val_t* __eval_ufn (xp_awk_run_t* run, xp_awk_nde_t* nde)
{ {
xp_awk_func_t* func; xp_awk_func_t* func;
xp_awk_pair_t* pair; xp_awk_pair_t* pair;
@ -2540,7 +2548,7 @@ static xp_awk_val_t* __eval_call (xp_awk_run_t* run, xp_awk_nde_t* nde)
int n; int n;
/*xp_printf (XP_T(".....__eval_call\n"));*/ /*xp_printf (XP_T(".....__eval_call\n"));*/
pair = xp_awk_map_get (&run->awk->tree.funcs, call->name); pair = xp_awk_map_get (&run->awk->tree.funcs, call->what.name);
if (pair == XP_NULL) PANIC (run, XP_AWK_ENOSUCHFUNC); if (pair == XP_NULL) PANIC (run, XP_AWK_ENOSUCHFUNC);
func = (xp_awk_func_t*)pair->val; func = (xp_awk_func_t*)pair->val;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: tree.c,v 1.54 2006-06-18 10:53:06 bacon Exp $ * $Id: tree.c,v 1.55 2006-06-19 15:43:27 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -339,10 +339,19 @@ static int __print_expression (xp_awk_nde_t* nde)
break; break;
} }
case XP_AWK_NDE_CALL: case XP_AWK_NDE_BFN:
{ {
xp_awk_nde_call_t* px = (xp_awk_nde_call_t*)nde; xp_awk_nde_call_t* px = (xp_awk_nde_call_t*)nde;
xp_printf (XP_T("%s ("), px->name); xp_printf (XP_T("%s ("), px->what.bfn->name);
if (__print_expression_list (px->args) == -1) return -1;
xp_printf (XP_T(")"));
break;
}
case XP_AWK_NDE_UFN:
{
xp_awk_nde_call_t* px = (xp_awk_nde_call_t*)nde;
xp_printf (XP_T("%s ("), px->what.name);
if (__print_expression_list (px->args) == -1) return -1; if (__print_expression_list (px->args) == -1) return -1;
xp_printf (XP_T(")")); xp_printf (XP_T(")"));
break; break;
@ -912,10 +921,19 @@ void xp_awk_clrpt (xp_awk_nde_t* tree)
break; break;
} }
case XP_AWK_NDE_CALL: case XP_AWK_NDE_BFN:
{ {
xp_awk_nde_call_t* px = (xp_awk_nde_call_t*)p; xp_awk_nde_call_t* px = (xp_awk_nde_call_t*)p;
xp_free (px->name); /* xp_free (px->what.bfn); */
xp_awk_clrpt (px->args);
xp_free (p);
break;
}
case XP_AWK_NDE_UFN:
{
xp_awk_nde_call_t* px = (xp_awk_nde_call_t*)p;
xp_free (px->what.name);
xp_awk_clrpt (px->args); xp_awk_clrpt (px->args);
xp_free (p); xp_free (p);
break; break;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: tree.h,v 1.45 2006-06-18 10:53:06 bacon Exp $ * $Id: tree.h,v 1.46 2006-06-19 15:43:27 bacon Exp $
*/ */
#ifndef _XP_AWK_TREE_H_ #ifndef _XP_AWK_TREE_H_
@ -39,7 +39,8 @@ enum
XP_AWK_NDE_EXP_INCPRE, XP_AWK_NDE_EXP_INCPRE,
XP_AWK_NDE_EXP_INCPST, XP_AWK_NDE_EXP_INCPST,
XP_AWK_NDE_CND, XP_AWK_NDE_CND,
XP_AWK_NDE_CALL, XP_AWK_NDE_BFN,
XP_AWK_NDE_UFN,
XP_AWK_NDE_INT, XP_AWK_NDE_INT,
XP_AWK_NDE_REAL, XP_AWK_NDE_REAL,
XP_AWK_NDE_STR, XP_AWK_NDE_STR,
@ -209,11 +210,15 @@ struct xp_awk_nde_var_t
xp_awk_nde_t* idx; /* XP_NULL for XXXIDX */ xp_awk_nde_t* idx; /* XP_NULL for XXXIDX */
}; };
/* XP_AWK_NDE_CALL */ /* XP_AWK_NDE_BFN, XP_AWK_NDE_UFN */
struct xp_awk_nde_call_t struct xp_awk_nde_call_t
{ {
XP_AWK_NDE_HDR; XP_AWK_NDE_HDR;
xp_char_t* name; union
{
xp_char_t* name;
xp_awk_bfn_t* bfn;
} what;
xp_awk_nde_t* args; xp_awk_nde_t* args;
xp_size_t nargs; xp_size_t nargs;
}; };

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.c,v 1.38 2006-06-19 09:08:50 bacon Exp $ * $Id: awk.c,v 1.39 2006-06-19 15:43:27 bacon Exp $
*/ */
#include <xp/awk/awk.h> #include <xp/awk/awk.h>
@ -176,8 +176,12 @@ static xp_ssize_t process_extio_pipe (
{ {
return -1; return -1;
} }
}
default:
{
return -1;
}
}
} }
static xp_ssize_t process_extio_file ( static xp_ssize_t process_extio_file (
@ -222,6 +226,11 @@ static xp_ssize_t process_extio_file (
{ {
return -1; return -1;
} }
default:
{
return -1;
}
} }
} }