improved qse_htb_t to use less memory. this resulted in backward-incompatible interface

This commit is contained in:
2010-10-28 06:54:37 +00:00
parent 167449e3f1
commit 81f314d676
9 changed files with 411 additions and 181 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.cpp 328 2010-07-08 06:58:44Z hyunghwan.chung $
* $Id: Awk.cpp 363 2010-10-27 12:54:37Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE.
@ -1128,7 +1128,9 @@ int Awk::open ()
qse_awk_seterrstr (awk, xerrstr);
functionMap = qse_htb_open (
qse_awk_getmmgr(awk), QSE_SIZEOF(this), 512, 70);
qse_awk_getmmgr(awk), QSE_SIZEOF(this), 512, 70,
QSE_SIZEOF(qse_char_t), 1
);
if (functionMap == QSE_NULL)
{
qse_awk_close (awk);
@ -1139,9 +1141,29 @@ int Awk::open ()
}
*(Awk**)QSE_XTN(functionMap) = this;
static qse_htb_mancbs_t mancbs =
{
{
QSE_HTB_COPIER_INLINE,
QSE_HTB_COPIER_DEFAULT
},
{
QSE_HTB_FREEER_DEFAULT,
free_function_map_value
},
QSE_HTB_HASHER_DEFAULT,
QSE_HTB_COMPER_DEFAULT,
QSE_HTB_KEEPER_DEFAULT,
QSE_HTB_SIZER_DEFAULT
};
qse_htb_setmancbs (functionMap, &mancbs);
#if 0
qse_htb_setscale (functionMap, QSE_HTB_KEY, QSE_SIZEOF(qse_char_t));
qse_htb_setcopier (functionMap, QSE_HTB_KEY, QSE_HTB_COPIER_INLINE);
qse_htb_setfreeer (functionMap, QSE_HTB_VAL, free_function_map_value);
qse_htb_setscale (functionMap, QSE_HTB_KEY, QSE_SIZEOF(qse_char_t));
#endif
return 0;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c 344 2010-08-17 13:15:14Z hyunghwan.chung $
* $Id: awk.c 363 2010-10-27 12:54:37Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE.
@ -72,10 +72,75 @@ static void clear_token (qse_awk_tok_t* tok)
tok->loc.colm = 0;
}
qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtn, qse_awk_prm_t* prm)
{
qse_awk_t* awk;
static qse_htb_mancbs_t mancbs1 =
{
{
QSE_HTB_COPIER_INLINE,
QSE_HTB_COPIER_INLINE
},
{
QSE_HTB_FREEER_DEFAULT,
QSE_HTB_FREEER_DEFAULT
},
QSE_HTB_HASHER_DEFAULT,
QSE_HTB_COMPER_DEFAULT,
QSE_HTB_KEEPER_DEFAULT,
QSE_HTB_SIZER_DEFAULT
};
static qse_htb_mancbs_t mancbs2 =
{
{
QSE_HTB_COPIER_INLINE,
QSE_HTB_COPIER_DEFAULT
},
{
QSE_HTB_FREEER_DEFAULT,
QSE_HTB_FREEER_DEFAULT
},
QSE_HTB_HASHER_DEFAULT,
QSE_HTB_COMPER_DEFAULT,
QSE_HTB_KEEPER_DEFAULT,
QSE_HTB_SIZER_DEFAULT
};
static qse_htb_mancbs_t treefuncbs =
{
{
QSE_HTB_COPIER_INLINE,
QSE_HTB_COPIER_DEFAULT
},
{
QSE_HTB_FREEER_DEFAULT,
free_fun
},
QSE_HTB_HASHER_DEFAULT,
QSE_HTB_COMPER_DEFAULT,
QSE_HTB_KEEPER_DEFAULT,
QSE_HTB_SIZER_DEFAULT
};
static qse_htb_mancbs_t fncusercbs =
{
{
QSE_HTB_COPIER_INLINE,
QSE_HTB_COPIER_DEFAULT
},
{
QSE_HTB_FREEER_DEFAULT,
free_fnc
},
QSE_HTB_HASHER_DEFAULT,
QSE_HTB_COMPER_DEFAULT,
QSE_HTB_KEEPER_DEFAULT,
QSE_HTB_SIZER_DEFAULT
};
if (mmgr == QSE_NULL)
{
mmgr = QSE_MMGR_GETDFL();
@ -113,50 +178,51 @@ qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtn, qse_awk_prm_t* prm)
if (init_token (mmgr, &awk->tok) == -1) goto oops;
if (init_token (mmgr, &awk->ntok) == -1) goto oops;
awk->wtab = qse_htb_open (mmgr, QSE_SIZEOF(awk), 512, 70);
awk->wtab = qse_htb_open (
mmgr, QSE_SIZEOF(awk),
512, 70, QSE_SIZEOF(qse_char_t), QSE_SIZEOF(qse_char_t)
);
if (awk->wtab == QSE_NULL) goto oops;
*(qse_awk_t**)QSE_XTN(awk->wtab) = awk;
qse_htb_setcopier (awk->wtab, QSE_HTB_KEY, QSE_HTB_COPIER_INLINE);
qse_htb_setcopier (awk->wtab, QSE_HTB_VAL, QSE_HTB_COPIER_INLINE);
qse_htb_setscale (awk->wtab, QSE_HTB_KEY, QSE_SIZEOF(qse_char_t));
qse_htb_setscale (awk->wtab, QSE_HTB_VAL, QSE_SIZEOF(qse_char_t));
qse_htb_setmancbs (awk->wtab, &mancbs1);
awk->rwtab = qse_htb_open (mmgr, QSE_SIZEOF(awk), 512, 70);
awk->rwtab = qse_htb_open (
mmgr, QSE_SIZEOF(awk),
512, 70, QSE_SIZEOF(qse_char_t), QSE_SIZEOF(qse_char_t)
);
if (awk->rwtab == QSE_NULL) goto oops;
*(qse_awk_t**)QSE_XTN(awk->rwtab) = awk;
qse_htb_setcopier (awk->rwtab, QSE_HTB_KEY, QSE_HTB_COPIER_INLINE);
qse_htb_setcopier (awk->rwtab, QSE_HTB_VAL, QSE_HTB_COPIER_INLINE);
qse_htb_setscale (awk->rwtab, QSE_HTB_KEY, QSE_SIZEOF(qse_char_t));
qse_htb_setscale (awk->rwtab, QSE_HTB_VAL, QSE_SIZEOF(qse_char_t));
qse_htb_setmancbs (awk->rwtab, &mancbs1);
awk->sio.names = qse_htb_open (mmgr, QSE_SIZEOF(awk), 128, 70);
awk->sio.names = qse_htb_open (
mmgr, QSE_SIZEOF(awk), 128, 70, QSE_SIZEOF(qse_char_t), 1
);
if (awk->sio.names == QSE_NULL) goto oops;
*(qse_awk_t**)QSE_XTN(awk->sio.names) = awk;
qse_htb_setcopier (awk->sio.names, QSE_HTB_KEY, QSE_HTB_COPIER_INLINE);
qse_htb_setscale (awk->sio.names, QSE_HTB_KEY, QSE_SIZEOF(qse_char_t));
qse_htb_setmancbs (awk->sio.names, &mancbs2);
awk->sio.inp = &awk->sio.arg;
/* TODO: initial map size?? */
awk->tree.funs = qse_htb_open (mmgr, QSE_SIZEOF(awk), 512, 70);
awk->tree.funs = qse_htb_open (
mmgr, QSE_SIZEOF(awk), 512, 70, QSE_SIZEOF(qse_char_t), 1
);
if (awk->tree.funs == QSE_NULL) goto oops;
*(qse_awk_t**)QSE_XTN(awk->tree.funs) = awk;
qse_htb_setcopier (awk->tree.funs, QSE_HTB_KEY, QSE_HTB_COPIER_INLINE);
qse_htb_setfreeer (awk->tree.funs, QSE_HTB_VAL, free_fun);
qse_htb_setscale (awk->tree.funs, QSE_HTB_KEY, QSE_SIZEOF(qse_char_t));
qse_htb_setmancbs (awk->tree.funs, &treefuncbs);
awk->parse.funs = qse_htb_open (mmgr, QSE_SIZEOF(awk), 256, 70);
awk->parse.funs = qse_htb_open (
mmgr, QSE_SIZEOF(awk), 256, 70, QSE_SIZEOF(qse_char_t), 1
);
if (awk->parse.funs == QSE_NULL) goto oops;
*(qse_awk_t**)QSE_XTN(awk->parse.funs) = awk;
qse_htb_setcopier (awk->parse.funs, QSE_HTB_KEY, QSE_HTB_COPIER_INLINE);
qse_htb_setscale (awk->parse.funs, QSE_HTB_KEY, QSE_SIZEOF(qse_char_t));
qse_htb_setmancbs (awk->parse.funs, &mancbs2);
awk->parse.named = qse_htb_open (mmgr, QSE_SIZEOF(awk), 256, 70);
awk->parse.named = qse_htb_open (
mmgr, QSE_SIZEOF(awk), 256, 70, QSE_SIZEOF(qse_char_t), 1
);
if (awk->parse.named == QSE_NULL) goto oops;
*(qse_awk_t**)QSE_XTN(awk->parse.named) = awk;
qse_htb_setcopier (
awk->parse.named, QSE_HTB_KEY, QSE_HTB_COPIER_INLINE);
qse_htb_setscale (
awk->parse.named, QSE_HTB_KEY, QSE_SIZEOF(qse_char_t));
qse_htb_setmancbs (awk->parse.named, &mancbs2);
awk->parse.gbls = qse_lda_open (mmgr, QSE_SIZEOF(awk), 128);
awk->parse.lcls = qse_lda_open (mmgr, QSE_SIZEOF(awk), 64);
@ -167,16 +233,16 @@ qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtn, qse_awk_prm_t* prm)
awk->parse.params == QSE_NULL) goto oops;
*(qse_awk_t**)QSE_XTN(awk->parse.gbls) = awk;
qse_lda_setcopier (awk->parse.gbls, QSE_LDA_COPIER_INLINE);
qse_lda_setscale (awk->parse.gbls, QSE_SIZEOF(qse_char_t));
qse_lda_setcopier (awk->parse.gbls, QSE_LDA_COPIER_INLINE);
*(qse_awk_t**)QSE_XTN(awk->parse.lcls) = awk;
qse_lda_setcopier (awk->parse.lcls, QSE_LDA_COPIER_INLINE);
qse_lda_setscale (awk->parse.lcls, QSE_SIZEOF(qse_char_t));
qse_lda_setcopier (awk->parse.lcls, QSE_LDA_COPIER_INLINE);
*(qse_awk_t**)QSE_XTN(awk->parse.params) = awk;
qse_lda_setcopier (awk->parse.params, QSE_LDA_COPIER_INLINE);
qse_lda_setscale (awk->parse.params, QSE_SIZEOF(qse_char_t));
qse_lda_setcopier (awk->parse.params, QSE_LDA_COPIER_INLINE);
awk->option = QSE_AWK_CLASSIC;
awk->errinf.num = QSE_AWK_ENOERR;
@ -197,12 +263,12 @@ qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtn, qse_awk_prm_t* prm)
awk->tree.chain_size = 0;
awk->fnc.sys = QSE_NULL;
awk->fnc.user = qse_htb_open (mmgr, QSE_SIZEOF(awk), 512, 70);
awk->fnc.user = qse_htb_open (
mmgr, QSE_SIZEOF(awk), 512, 70, QSE_SIZEOF(qse_char_t), 1
);
if (awk->fnc.user == QSE_NULL) goto oops;
*(qse_awk_t**)QSE_XTN(awk->fnc.user) = awk;
qse_htb_setcopier (awk->fnc.user, QSE_HTB_KEY, QSE_HTB_COPIER_INLINE);
qse_htb_setfreeer (awk->fnc.user, QSE_HTB_VAL, free_fnc);
qse_htb_setscale (awk->fnc.user, QSE_HTB_KEY, QSE_SIZEOF(qse_char_t));
qse_htb_setmancbs (awk->fnc.user, &fncusercbs);
if (qse_awk_initgbls (awk) <= -1) goto oops;

View File

@ -1,5 +1,5 @@
/*
* $Id: run.c 343 2010-08-05 07:31:17Z hyunghwan.chung $
* $Id: run.c 363 2010-10-27 12:54:37Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE.
@ -787,6 +787,22 @@ static void same_namedval (qse_htb_t* map, void* dptr, qse_size_t dlen)
static int init_rtx (qse_awk_rtx_t* rtx, qse_awk_t* awk, qse_awk_rio_t* rio)
{
static qse_htb_mancbs_t mancbs_for_named =
{
{
QSE_HTB_COPIER_INLINE,
QSE_HTB_COPIER_DEFAULT
},
{
QSE_HTB_FREEER_DEFAULT,
free_namedval
},
QSE_HTB_HASHER_DEFAULT,
QSE_HTB_COMPER_DEFAULT,
same_namedval,
QSE_HTB_SIZER_DEFAULT
};
/* zero out the runtime context excluding the extension */
QSE_MEMSET (rtx, 0, QSE_SIZEOF(qse_awk_rtx_t));
@ -845,7 +861,8 @@ static int init_rtx (qse_awk_rtx_t* rtx, qse_awk_t* awk, qse_awk_rio_t* rio)
}
rtx->named = qse_htb_open (
MMGR(rtx), QSE_SIZEOF(rtx), 1024, 70);
MMGR(rtx), QSE_SIZEOF(rtx), 1024, 70, QSE_SIZEOF(qse_char_t), 1
);
if (rtx->named == QSE_NULL)
{
qse_str_fini (&rtx->format.fmt);
@ -856,10 +873,7 @@ static int init_rtx (qse_awk_rtx_t* rtx, qse_awk_t* awk, qse_awk_rio_t* rio)
return -1;
}
*(qse_awk_rtx_t**)QSE_XTN(rtx->named) = rtx;
qse_htb_setcopier (rtx->named, QSE_HTB_KEY, QSE_HTB_COPIER_INLINE);
qse_htb_setfreeer (rtx->named, QSE_HTB_VAL, free_namedval);
qse_htb_setkeeper (rtx->named, same_namedval);
qse_htb_setscale (rtx->named, QSE_HTB_KEY, QSE_SIZEOF(qse_char_t));
qse_htb_setmancbs (rtx->named, &mancbs_for_named);
rtx->format.tmp.ptr = (qse_char_t*)
QSE_AWK_ALLOC (rtx->awk, 4096*QSE_SIZEOF(qse_char_t*));

View File

@ -1,5 +1,5 @@
/*
* $Id: val.c 328 2010-07-08 06:58:44Z hyunghwan.chung $
* $Id: val.c 363 2010-10-27 12:54:37Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE.
@ -389,6 +389,25 @@ static void same_mapval (qse_htb_t* map, void* dptr, qse_size_t dlen)
qse_awk_val_t* qse_awk_rtx_makemapval (qse_awk_rtx_t* rtx)
{
qse_awk_val_map_t* val;
static qse_htb_mancbs_t mancbs =
{
/* the key is copied inline into a pair and is freed when the pair
* is destroyed. not setting copier for a value means that the pointer
* to the data allocated somewhere else is remembered in a pair. but
* freeing the actual value is handled by free_mapval and same_mapval */
{
QSE_HTB_COPIER_INLINE,
QSE_HTB_COPIER_DEFAULT
},
{
QSE_HTB_FREEER_DEFAULT,
free_mapval
},
QSE_HTB_HASHER_DEFAULT,
QSE_HTB_COMPER_DEFAULT,
same_mapval,
QSE_HTB_SIZER_DEFAULT
};
/* CHECK */
/*
@ -429,7 +448,9 @@ qse_awk_val_t* qse_awk_rtx_makemapval (qse_awk_rtx_t* rtx)
val->nstr = 0;
val->map = (qse_htb_t*)(val + 1);
val->map = qse_htb_init (val->map, rtx->awk->mmgr, 256, 70);
val->map = qse_htb_init (
val->map, rtx->awk->mmgr, 256, 70, QSE_SIZEOF(qse_char_t), 1
);
if (val->map == QSE_NULL)
{
QSE_AWK_FREE (rtx->awk, val);
@ -437,17 +458,7 @@ qse_awk_val_t* qse_awk_rtx_makemapval (qse_awk_rtx_t* rtx)
return QSE_NULL;
}
*(qse_awk_rtx_t**)QSE_XTN(val->map) = rtx;
/* the key is copied inline into a pair and is freed when the pair
* is destroyed */
qse_htb_setcopier (val->map, QSE_HTB_KEY, QSE_HTB_COPIER_INLINE);
qse_htb_setscale (val->map, QSE_HTB_KEY, QSE_SIZEOF(qse_char_t));
/* not setting copier for a value means that the pointer to the data
* allocated somewhere else is remembered in a pair. but the freeing
* the actual value is handled by free_mapval and same_mapval */
qse_htb_setfreeer (val->map, QSE_HTB_VAL, free_mapval);
qse_htb_setkeeper (val->map, same_mapval);
qse_htb_setmancbs (val->map, &mancbs);
/* END CHECK */
return (qse_awk_val_t*)val;