*** empty log message ***

This commit is contained in:
hyung-hwan 2006-04-21 17:24:31 +00:00
parent a5a2a79d9b
commit 220dd573de
7 changed files with 682 additions and 714 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c,v 1.43 2006-04-21 16:21:27 bacon Exp $
* $Id: awk.c,v 1.44 2006-04-21 17:24:31 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -9,8 +9,7 @@
#include <xp/bas/assert.h>
#endif
static void __free_func (xp_awk_t* awk, void* func);
static void __free_namedval (xp_awk_t* awk, void* val);
static void __free_func (void* awk, void* func);
xp_awk_t* xp_awk_open (void)
{
@ -59,18 +58,6 @@ xp_awk_t* xp_awk_open (void)
return XP_NULL;
}
/* TODO: initial map size... */
if (xp_awk_map_open(&awk->run.named,awk,256,__free_namedval) == XP_NULL)
{
xp_str_close (&awk->token.name);
xp_awk_map_close (&awk->tree.funcs);
xp_awk_tab_close (&awk->parse.globals);
xp_awk_tab_close (&awk->parse.locals);
xp_awk_tab_close (&awk->parse.params);
xp_free (awk);
return XP_NULL;
}
awk->opt.parse = 0;
awk->opt.run = 0;
awk->errnum = XP_AWK_ENOERR;
@ -89,14 +76,6 @@ xp_awk_t* xp_awk_open (void)
awk->tree.chain = XP_NULL;
awk->tree.chain_tail = XP_NULL;
awk->run.stack = XP_NULL;
awk->run.stack_top = 0;
awk->run.stack_base = 0;
awk->run.stack_limit = 0;
awk->run.exit_level = 0;
awk->run.icache_count = 0;
awk->run.rcache_count = 0;
awk->lex.curc = XP_CHAR_EOF;
awk->lex.ungotc_count = 0;
@ -109,7 +88,6 @@ int xp_awk_close (xp_awk_t* awk)
if (xp_awk_detsrc(awk) == -1) return -1;
xp_awk_map_close (&awk->run.named);
xp_awk_map_close (&awk->tree.funcs);
xp_awk_tab_close (&awk->parse.globals);
xp_awk_tab_close (&awk->parse.locals);
@ -126,33 +104,7 @@ int xp_awk_close (xp_awk_t* awk)
void xp_awk_clear (xp_awk_t* awk)
{
/* clear named variables */
xp_awk_map_clear (&awk->run.named);
/* destroy run stack */
if (awk->run.stack != XP_NULL)
{
xp_free (awk->run.stack);
awk->run.stack = XP_NULL;
awk->run.stack_top = 0;
awk->run.stack_base = 0;
awk->run.stack_limit = 0;
}
/* destroy values in free list */
while (awk->run.icache_count > 0)
{
--awk->run.icache_count;
xp_awk_freeval (awk,
awk->run.icache[awk->run.icache_count], xp_false);
}
while (awk->run.rcache_count > 0)
{
--awk->run.rcache_count;
xp_awk_freeval (awk,
awk->run.rcache[awk->run.rcache_count], xp_false);
}
/* TODO: kill all associated run instances... */
xp_awk_tab_clear (&awk->parse.globals);
xp_awk_tab_clear (&awk->parse.locals);
@ -230,7 +182,7 @@ int xp_awk_detsrc (xp_awk_t* awk)
return 0;
}
static void __free_func (xp_awk_t* awk, void* func)
static void __free_func (void* owner, void* func)
{
xp_awk_func_t* f = (xp_awk_func_t*) func;
@ -239,8 +191,3 @@ static void __free_func (xp_awk_t* awk, void* func)
xp_awk_clrpt (f->body);
xp_free (f);
}
static void __free_namedval (xp_awk_t* awk, void* val)
{
xp_awk_refdownval (awk, val);
}

View File

@ -1,10 +1,14 @@
/*
* $Id: awk_i.h,v 1.6 2006-04-21 16:21:27 bacon Exp $
* $Id: awk_i.h,v 1.7 2006-04-21 17:24:31 bacon Exp $
*/
#ifndef _XP_AWK_AWKI_H_
#define _XP_AWK_AWKI_H_
typedef struct xp_awk_chain_t xp_awk_chain_t;
typedef struct xp_awk_run_t xp_awk_run_t;
typedef struct xp_awk_tree_t xp_awk_tree_t;
#include <xp/awk/awk.h>
#include <xp/awk/tree.h>
#include <xp/awk/tab.h>
@ -18,9 +22,6 @@
#include <xp/bas/str.h>
#endif
typedef struct xp_awk_chain_t xp_awk_chain_t;
typedef struct xp_awk_run-t xp_awk_run_t;
/*
*
struct xp_awk_parse_t
@ -54,6 +55,16 @@ run with run_stack
*/
struct xp_awk_tree_t
{
xp_size_t nglobals;
xp_awk_map_t funcs;
xp_awk_nde_t* begin;
xp_awk_nde_t* end;
xp_awk_chain_t* chain;
xp_awk_chain_t* chain_tail;
};
struct xp_awk_t
{
/* options */
@ -73,15 +84,7 @@ struct xp_awk_t
void* out_arg;
/* parse tree */
struct
{
xp_size_t nglobals;
xp_awk_map_t funcs;
xp_awk_nde_t* begin;
xp_awk_nde_t* end;
xp_awk_chain_t* chain;
xp_awk_chain_t* chain_tail;
} tree;
xp_awk_tree_t tree;
/* temporary information that the parser needs */
struct
@ -92,23 +95,6 @@ struct xp_awk_t
xp_size_t nlocals_max;
} parse;
/* run-time data structure */
struct
{
xp_awk_map_t named;
void** stack;
xp_size_t stack_top;
xp_size_t stack_base;
xp_size_t stack_limit;
int exit_level;
xp_awk_val_int_t* icache[100]; /* TODO: ... */
xp_awk_val_real_t* rcache[100]; /* TODO: ... */
xp_size_t icache_count;
xp_size_t rcache_count;
} run;
/* source buffer management */
struct
{
@ -153,6 +139,9 @@ struct xp_awk_run_t
/* input_stream */
/* output_stream */
xp_awk_t* awk;
int opt;
xp_awk_tree_t* tree;
xp_size_t nglobals;
};
#endif

View File

@ -1,5 +1,5 @@
/*
* $Id: map.c,v 1.13 2006-04-19 03:42:08 bacon Exp $
* $Id: map.c,v 1.14 2006-04-21 17:24:31 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -20,13 +20,13 @@ static xp_size_t __hash (const xp_char_t* key);
{ \
xp_free ((xp_char_t*)(pair)->key); \
if ((map)->freeval != XP_NULL) \
(map)->freeval ((map)->awk, (pair)->val); \
(map)->freeval ((map)->owner, (pair)->val); \
xp_free (pair); \
} while (0)
xp_awk_map_t* xp_awk_map_open (
xp_awk_map_t* map, xp_awk_t* awk,
xp_size_t capa, void(*freeval)(xp_awk_t*,void*))
xp_awk_map_t* map, xp_awk_t* owner,
xp_size_t capa, void(*freeval)(void*,void*))
{
if (map == XP_NULL)
{
@ -44,7 +44,7 @@ xp_awk_map_t* xp_awk_map_open (
return XP_NULL;
}
map->awk = awk;
map->owner = owner;
map->capa = capa;
map->size = 0;
map->freeval = freeval;
@ -224,7 +224,7 @@ xp_awk_pair_t* xp_awk_map_setpair (
{
if (map->freeval != XP_NULL)
{
map->freeval (map->awk, pair->val);
map->freeval (map->owner, pair->val);
}
pair->val = val;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: map.h,v 1.8 2006-04-18 14:49:42 bacon Exp $
* $Id: map.h,v 1.9 2006-04-21 17:24:31 bacon Exp $
*/
#ifndef _XP_AWK_MAP_H_
@ -28,11 +28,11 @@ struct xp_awk_pair_t
struct xp_awk_map_t
{
xp_awk_t* awk;
void* owner;
xp_size_t size;
xp_size_t capa;
xp_awk_pair_t** buck;
void (*freeval) (xp_awk_t*,void*);
void (*freeval) (void*,void*);
xp_bool_t __dynamic;
};
@ -41,8 +41,8 @@ extern "C" {
#endif
xp_awk_map_t* xp_awk_map_open (
xp_awk_map_t* map, xp_awk_t* awk,
xp_size_t capa, void(*freeval)(xp_awk_t*,void*));
xp_awk_map_t* map, void* owner,
xp_size_t capa, void(*freeval)(void*,void*));
void xp_awk_map_close (xp_awk_map_t* map);
void xp_awk_map_clear (xp_awk_map_t* map);

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/*
* $Id: val.c,v 1.24 2006-04-20 16:20:41 bacon Exp $
* $Id: val.c,v 1.25 2006-04-21 17:24:31 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -28,7 +28,7 @@ static xp_awk_val_int_t __awk_int[] =
{ XP_AWK_VAL_INT, 0, 9 },
};
xp_awk_val_t* xp_awk_makeintval (xp_awk_t* awk, xp_long_t v)
xp_awk_val_t* xp_awk_makeintval (xp_awk_run_t* run, xp_long_t v)
{
xp_awk_val_int_t* val;
@ -38,9 +38,9 @@ xp_awk_val_t* xp_awk_makeintval (xp_awk_t* awk, xp_long_t v)
return (xp_awk_val_t*)&__awk_int[v-__awk_int[0].val];
}
if (awk->run.icache_count > 0)
if (run->icache_count > 0)
{
val = awk->run.icache[--awk->run.icache_count];
val = run->icache[--run->icache_count];
}
else
{
@ -56,13 +56,13 @@ xp_awk_val_t* xp_awk_makeintval (xp_awk_t* awk, xp_long_t v)
return (xp_awk_val_t*)val;
}
xp_awk_val_t* xp_awk_makerealval (xp_awk_t* awk, xp_real_t v)
xp_awk_val_t* xp_awk_makerealval (xp_awk_run_t* run, xp_real_t v)
{
xp_awk_val_real_t* val;
if (awk->run.rcache_count > 0)
if (run->rcache_count > 0)
{
val = awk->run.rcache[--awk->run.rcache_count];
val = run->rcache[--run->rcache_count];
}
else
{
@ -120,17 +120,17 @@ xp_awk_val_t* xp_awk_makestrval2 (
return (xp_awk_val_t*)val;
}
static void __free_map_val (xp_awk_t* awk, void* v)
static void __free_map_val (void* run, void* v)
{
/*
xp_printf (XP_TEXT("refdown in map free..."));
xp_awk_printval (v);
xp_printf (XP_TEXT("\n"));
*/
xp_awk_refdownval (awk, v);
xp_awk_refdownval (run, v);
}
xp_awk_val_t* xp_awk_makemapval (xp_awk_t* awk)
xp_awk_val_t* xp_awk_makemapval (xp_awk_run_t* run)
{
xp_awk_val_map_t* val;
@ -139,7 +139,7 @@ xp_awk_val_t* xp_awk_makemapval (xp_awk_t* awk)
val->type = XP_AWK_VAL_MAP;
val->ref = 0;
val->map = xp_awk_map_open (XP_NULL, awk, 256, __free_map_val);
val->map = xp_awk_map_open (XP_NULL, run, 256, __free_map_val);
if (val->map == XP_NULL)
{
xp_free (val);
@ -156,7 +156,7 @@ xp_bool_t xp_awk_isbuiltinval (xp_awk_val_t* val)
val <= (xp_awk_val_t*)&__awk_int[xp_countof(__awk_int)-1]);
}
void xp_awk_freeval (xp_awk_t* awk, xp_awk_val_t* val, xp_bool_t cache)
void xp_awk_freeval (xp_awk_run_t* run, xp_awk_val_t* val, xp_bool_t cache)
{
if (xp_awk_isbuiltinval(val)) return;
@ -171,9 +171,9 @@ xp_printf (XP_TEXT("\n"));
case XP_AWK_VAL_INT:
if (cache == xp_true &&
awk->run.icache_count < xp_countof(awk->run.icache))
run->icache_count < xp_countof(run->icache))
{
awk->run.icache[awk->run.icache_count++] =
run->icache[run->icache_count++] =
(xp_awk_val_int_t*)val;
}
else xp_free (val);
@ -181,9 +181,9 @@ xp_printf (XP_TEXT("\n"));
case XP_AWK_VAL_REAL:
if (cache == xp_true &&
awk->run.rcache_count < xp_countof(awk->run.rcache))
run->rcache_count < xp_countof(run->rcache))
{
awk->run.rcache[awk->run.rcache_count++] =
run->rcache[run->rcache_count++] =
(xp_awk_val_real_t*)val;
}
else xp_free (val);
@ -214,7 +214,7 @@ xp_printf (XP_TEXT("\n"));
val->ref++;
}
void xp_awk_refdownval (xp_awk_t* awk, xp_awk_val_t* val)
void xp_awk_refdownval (xp_awk_run_t* run, xp_awk_val_t* val)
{
if (xp_awk_isbuiltinval(val)) return;
@ -234,11 +234,11 @@ xp_printf (XP_TEXT("**FREEING "));
xp_awk_printval (val);
xp_printf (XP_TEXT("\n"));
*/
xp_awk_freeval(awk, val, xp_true);
xp_awk_freeval(run, val, xp_true);
}
}
void xp_awk_refdownval_nofree (xp_awk_t* awk, xp_awk_val_t* val)
void xp_awk_refdownval_nofree (xp_awk_run_t* run, xp_awk_val_t* val)
{
if (xp_awk_isbuiltinval(val)) return;
@ -246,7 +246,7 @@ void xp_awk_refdownval_nofree (xp_awk_t* awk, xp_awk_val_t* val)
val->ref--;
}
xp_awk_val_t* xp_awk_cloneval (xp_awk_t* awk, xp_awk_val_t* val)
xp_awk_val_t* xp_awk_cloneval (xp_awk_run_t* run, xp_awk_val_t* val)
{
if (val == XP_NULL) return xp_awk_val_nil;
@ -255,9 +255,9 @@ xp_awk_val_t* xp_awk_cloneval (xp_awk_t* awk, xp_awk_val_t* val)
case XP_AWK_VAL_NIL:
return xp_awk_val_nil;
case XP_AWK_VAL_INT:
return xp_awk_makeintval (awk, ((xp_awk_val_int_t*)val)->val);
return xp_awk_makeintval (run, ((xp_awk_val_int_t*)val)->val);
case XP_AWK_VAL_REAL:
return xp_awk_makerealval (awk, ((xp_awk_val_real_t*)val)->val);
return xp_awk_makerealval (run, ((xp_awk_val_real_t*)val)->val);
case XP_AWK_VAL_STR:
return xp_awk_makestrval (
((xp_awk_val_str_t*)val)->buf,

View File

@ -1,5 +1,5 @@
/*
* $Id: val.h,v 1.18 2006-04-20 16:17:01 bacon Exp $
* $Id: val.h,v 1.19 2006-04-21 17:24:31 bacon Exp $
*/
#ifndef _XP_AWK_VAL_H_
@ -80,21 +80,21 @@ extern "C" {
extern xp_awk_val_t* xp_awk_val_nil;
xp_awk_val_t* xp_awk_makeintval (xp_awk_t* awk, xp_long_t v);
xp_awk_val_t* xp_awk_makerealval (xp_awk_t* awk, xp_real_t v);
xp_awk_val_t* xp_awk_makeintval (xp_awk_run_t* run, xp_long_t v);
xp_awk_val_t* xp_awk_makerealval (xp_awk_run_t* run, xp_real_t v);
xp_awk_val_t* xp_awk_makestrval (const xp_char_t* str, xp_size_t len);
xp_awk_val_t* xp_awk_makestrval2 (
const xp_char_t* str1, xp_size_t len1,
const xp_char_t* str2, xp_size_t len2);
xp_awk_val_t* xp_awk_makemapval (xp_awk_t* awk);
xp_awk_val_t* xp_awk_makemapval (xp_awk_run_t* run);
xp_bool_t xp_awk_isbuiltinval (xp_awk_val_t* val);
void xp_awk_freeval (xp_awk_t* awk, xp_awk_val_t* val, xp_bool_t cache);
void xp_awk_freeval (xp_awk_run_t* run, xp_awk_val_t* val, xp_bool_t cache);
void xp_awk_refupval (xp_awk_val_t* val);
void xp_awk_refdownval (xp_awk_t* awk, xp_awk_val_t* val);
void xp_awk_refdownval_nofree (xp_awk_t* awk, xp_awk_val_t* val);
void xp_awk_refdownval (xp_awk_run_t* run, xp_awk_val_t* val);
void xp_awk_refdownval_nofree (xp_awk_run_t* run, xp_awk_val_t* val);
xp_awk_val_t* xp_awk_cloneval (xp_awk_t* awk, xp_awk_val_t* val);
xp_awk_val_t* xp_awk_cloneval (xp_awk_run_t* run, xp_awk_val_t* val);
xp_bool_t xp_awk_boolval (xp_awk_val_t* val);
void xp_awk_printval (xp_awk_val_t* val);