experiments...

This commit is contained in:
2020-09-22 09:19:53 +00:00
parent bfba16a757
commit b8fd5c6712
6 changed files with 382 additions and 325 deletions

View File

@ -93,9 +93,46 @@ static void free_heap (hcl_t* hcl, void* ptr)
hcl_freemem (hcl, ptr);
}
static int push_code_container (hcl_t* hcl)
{
hcl_code_container_t* cc;
cc = hcl_callocmem(hcl, HCL_SIZEOF(*cc));
if (HCL_UNLIKELY(!cc)) return -1;
cc->_par = hcl->ccstk;
hcl->ccstk = cc;
return 0;
}
static void pop_code_container (hcl_t* hcl)
{
hcl_code_container_t* cc = hcl->ccstk;
if (cc->bc.arr)
{
hcl_freengcobj (hcl, (hcl_oop_t)cc->bc.arr);
cc->bc.arr = HCL_NULL;
cc->bc.len = 0;
}
if (cc->lit.arr)
{
hcl_freengcobj (hcl, (hcl_oop_t)cc->lit.arr);
cc->lit.arr = HCL_NULL;
cc->lit.len = 0;
}
hcl->ccstk = cc->_par;
hcl_freemem (hcl, cc);
}
int hcl_init (hcl_t* hcl, hcl_mmgr_t* mmgr, hcl_oow_t heapsz, const hcl_vmprim_t* vmprim)
{
int modtab_inited = 0;
int n;
if (!vmprim->syserrstrb && !vmprim->syserrstru)
{
@ -135,9 +172,10 @@ int hcl_init (hcl_t* hcl, hcl_mmgr_t* mmgr, hcl_oow_t heapsz, const hcl_vmprim_t
* reallocation fails */
/* +1 required for consistency with put_oocs and put_ooch in logfmt.c */
hcl->log.ptr = (hcl_ooch_t*)hcl_allocmem(hcl, (hcl->log.capa + 1) * HCL_SIZEOF(*hcl->log.ptr));
if (!hcl->log.ptr) goto oops;
if (HCL_UNLIKELY(!hcl->log.ptr)) goto oops;
if (hcl_rbt_init(&hcl->modtab, hcl, HCL_SIZEOF(hcl_ooch_t), 1) <= -1) goto oops;
n = hcl_rbt_init(&hcl->modtab, hcl, HCL_SIZEOF(hcl_ooch_t), 1);
if (HCL_UNLIKELY(n <= -1)) goto oops;
modtab_inited = 1;
hcl_rbt_setstyle(&hcl->modtab, hcl_get_rbt_style(HCL_RBT_STYLE_INLINE_COPIERS));
@ -154,14 +192,18 @@ int hcl_init (hcl_t* hcl, hcl_mmgr_t* mmgr, hcl_oow_t heapsz, const hcl_vmprim_t
/*hcl->permheap = hcl_makeheap (hcl, what is the best size???);
if (!hcl->curheap) goto oops; */
hcl->curheap = hcl_makeheap(hcl, heapsz);
if (!hcl->curheap) goto oops;
if (HCL_UNLIKELY(!hcl->curheap)) goto oops;
hcl->newheap = hcl_makeheap(hcl, heapsz);
if (!hcl->newheap) goto oops;
if (HCL_UNLIKELY(!hcl->newheap)) goto oops;
n = push_code_container(hcl);
if (HCL_UNLIKELY(n <= -1)) goto oops;
if (hcl->vmprim.dl_startup) hcl->vmprim.dl_startup (hcl);
return 0;
oops:
if (hcl->ccstk) pop_code_container(hcl);
if (hcl->newheap) hcl_killheap (hcl, hcl->newheap);
if (hcl->curheap) hcl_killheap (hcl, hcl->curheap);
if (hcl->permheap) hcl_killheap (hcl, hcl->permheap);
@ -253,6 +295,8 @@ void hcl_fini (hcl_t* hcl)
hcl->code.lit.len = 0;
}
while (hcl->ccstk) pop_code_container(hcl);
if (hcl->p.s.ptr)
{
hcl_freemem (hcl, hcl->p.s.ptr);
@ -320,6 +364,12 @@ void hcl_reset (hcl_t* hcl)
hcl->code.bc.len = 0;
hcl->code.lit.len = 0;
/* keep the base container */
HCL_ASSERT (hcl, hcl->ccstk != HCL_NULL);
while (hcl->ccstk->_par) pop_code_container(hcl);
hcl->ccstk->bc.len = 0;
hcl->ccstk->lit.len = 0;
/* clean up object memory */
hcl_gc (hcl);
}