From dcae55ab7026fbd780e46894e392178fdc801906 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 5 Oct 2020 14:49:54 +0000 Subject: [PATCH] fixing more bugs.. --- lib/comp.c | 12 +++++++----- lib/exec.c | 12 ++++++++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/comp.c b/lib/comp.c index 2f3b0c7..2d0b4a8 100644 --- a/lib/comp.c +++ b/lib/comp.c @@ -75,10 +75,13 @@ literals --> static int add_literal (hcl_t* hcl, hcl_oop_t obj, hcl_oow_t* index) { - hcl_oow_t capa, i; + hcl_oow_t capa, i, lfbase = 0; -/* TODO: speed up the following duplicate check loop */ - for (i = 0; i < hcl->code.lit.len; i++) + + lfbase = (hcl->option.trait & HCL_TRAIT_INTERACTIVE)? hcl->c->blk.info[hcl->c->blk.depth].lfbase: 0; + + /* TODO: speed up the following duplicate check loop */ + for (i = lfbase; i < hcl->code.lit.len; i++) { /* this removes redundancy of symbols, characters, and integers. */ if (((hcl_oop_oop_t)hcl->code.lit.arr)->slot[i] == obj) @@ -101,8 +104,7 @@ static int add_literal (hcl_t* hcl, hcl_oop_t obj, hcl_oow_t* index) hcl->code.lit.arr = (hcl_oop_oop_t)tmp; } - *index = hcl->code.lit.len; - if (hcl->option.trait & HCL_TRAIT_INTERACTIVE) *index -= hcl->c->blk.info[hcl->c->blk.depth].lfbase; + *index = hcl->code.lit.len - lfbase; ((hcl_oop_oop_t)hcl->code.lit.arr)->slot[hcl->code.lit.len++] = obj; return 0; diff --git a/lib/exec.c b/lib/exec.c index 9799746..d6d807c 100644 --- a/lib/exec.c +++ b/lib/exec.c @@ -182,7 +182,11 @@ static HCL_INLINE void fill_function_data (hcl_t* hcl, hcl_oop_function_t func, /* copy literal frames */ HCL_ASSERT (hcl, lfsize <= HCL_OBJ_GET_SIZE(func) - HCL_FUNCTION_NAMED_INSTVARS); - for (i = 0; i < lfsize; i++) func->literal_frame[i] = lfptr[i]; + for (i = 0; i < lfsize; i++) + { + func->literal_frame[i] = lfptr[i]; + HCL_DEBUG2 (hcl, "literal frame %d => %O\n", (int)i, lfptr[i]); + } /* initialize other fields */ func->home = homectx; @@ -2351,13 +2355,13 @@ static int execute (hcl_t* hcl) HCL_DEBUG1(hcl, "**** MAKE FUNCTION joff = %zu\n", joff); /* copy the byte codes from the active context to the new context */ #if (HCL_HCL_CODE_LONG_PARAM_SIZE == 2) - func = (hcl_oop_function_t)make_function(hcl, b4 - b3, &hcl->active_code[hcl->ip + 3], joff); + func = (hcl_oop_function_t)make_function(hcl, b4, &hcl->active_code[hcl->ip + 3], joff); #else - func = (hcl_oop_function_t)make_function(hcl, b4 - b3, &hcl->active_code[hcl->ip + 2], joff); + func = (hcl_oop_function_t)make_function(hcl, b4, &hcl->active_code[hcl->ip + 2], joff); #endif if (HCL_UNLIKELY(!func)) goto oops; - fill_function_data (hcl, func, b1, b2, hcl->active_context, &hcl->active_function->literal_frame[b3], b4 - b3); + fill_function_data (hcl, func, b1, b2, hcl->active_context, &hcl->active_function->literal_frame[b3], b4); /* push the new function to the stack of the active context */ HCL_STACK_PUSH (hcl, (hcl_oop_t)func);