added hcl_compile_flag_t

This commit is contained in:
hyung-hwan 2021-04-24 13:50:51 +00:00
parent e716c8bba9
commit 999024e54b
5 changed files with 32 additions and 16 deletions

View File

@ -677,6 +677,7 @@ int main (int argc, char* argv[])
const char* logopt = HCL_NULL; const char* logopt = HCL_NULL;
hcl_oow_t heapsize = DEFAULT_HEAPSIZE; hcl_oow_t heapsize = DEFAULT_HEAPSIZE;
int cflags;
int verbose = 0; int verbose = 0;
#if defined(HCL_BUILD_DEBUG) #if defined(HCL_BUILD_DEBUG)
@ -847,6 +848,8 @@ hcl_logufmt (hcl, HCL_LOG_WARN, fmt, ustr, 0x6789);
hcl_setoption (hcl, HCL_TRAIT, &trait); hcl_setoption (hcl, HCL_TRAIT, &trait);
} }
#endif #endif
cflags = 0;
if (xtn->reader_istty) cflags = HCL_COMPILE_CLEAR_CODE | HCL_COMPILE_CLEAR_FNBLK;
while (1) while (1)
{ {
@ -882,17 +885,8 @@ count++;
goto oops; goto oops;
} }
if (xtn->reader_istty)
{
/* clear the byte code buffer */
/* TODO: create a proper function for this and call it */
hcl->code.bc.len = 0;
hcl->code.lit.len = 0;
}
if (verbose) hcl_prbfmt (hcl, "\n"); /* flush the output buffer by hcl_print above */ if (verbose) hcl_prbfmt (hcl, "\n"); /* flush the output buffer by hcl_print above */
n = hcl_compile(hcl, obj, cflags);
n = hcl_compile(hcl, obj);
hcl_freecnode (hcl, obj); /* not needed any more */ hcl_freecnode (hcl, obj); /* not needed any more */
if (n <= -1) if (n <= -1)

View File

@ -3685,13 +3685,18 @@ static HCL_INLINE int emit_throw (hcl_t* hcl)
/* ========================================================================= */ /* ========================================================================= */
int hcl_compile (hcl_t* hcl, hcl_cnode_t* obj) int hcl_compile (hcl_t* hcl, hcl_cnode_t* obj, int flags)
{ {
hcl_oow_t saved_bc_len, saved_lit_len; hcl_oow_t saved_bc_len, saved_lit_len;
hcl_bitmask_t log_default_type_mask; hcl_bitmask_t log_default_type_mask;
hcl_fnblk_info_t top_fnblk_saved; hcl_fnblk_info_t top_fnblk_saved;
HCL_ASSERT (hcl, GET_TOP_CFRAME_INDEX(hcl) < 0); HCL_ASSERT (hcl, GET_TOP_CFRAME_INDEX(hcl) < 0);
if (flags & HCL_COMPILE_CLEAR_CODE)
{
hcl->code.bc.len = 0;
hcl->code.lit.len = 0;
}
saved_bc_len = hcl->code.bc.len; saved_bc_len = hcl->code.bc.len;
saved_lit_len = hcl->code.lit.len; saved_lit_len = hcl->code.lit.len;
@ -3930,7 +3935,11 @@ int hcl_compile (hcl_t* hcl, hcl_cnode_t* obj)
HCL_ASSERT (hcl, hcl->c->fnblk.depth == 0); /* ensure the virtual function block be the only one left */ HCL_ASSERT (hcl, hcl->c->fnblk.depth == 0); /* ensure the virtual function block be the only one left */
hcl->code.ngtmprs = hcl->c->fnblk.info[0].tmprcnt; /* populate the number of global temporary variables */ hcl->code.ngtmprs = hcl->c->fnblk.info[0].tmprcnt; /* populate the number of global temporary variables */
/*pop_fnblk (hcl); keep the top-level virtual function block by keeping this line commented out */ if (flags & HCL_COMPILE_CLEAR_FNBLK)
{
pop_fnblk (hcl);
HCL_ASSERT (hcl, hcl->c->fnblk.depth == -1);
}
hcl ->log.default_type_mask = log_default_type_mask; hcl ->log.default_type_mask = log_default_type_mask;
return 0; return 0;

View File

@ -1396,7 +1396,7 @@ int hcl_server_proto_handle_request (hcl_server_proto_t* proto)
} }
proto->worker->opstate = HCL_SERVER_WORKER_OPSTATE_COMPILE; proto->worker->opstate = HCL_SERVER_WORKER_OPSTATE_COMPILE;
n = hcl_compile(proto->hcl, obj); n = hcl_compile(proto->hcl, obj, HCL_COMPILE_CLEAR_CODE | HCL_COMPILE_CLEAR_FNBLK);
hcl_freecnode (proto->hcl, obj); hcl_freecnode (proto->hcl, obj);
if (n <= -1) if (n <= -1)
{ {

View File

@ -83,9 +83,9 @@ static void fill_bigint_tables (hcl_t* hcl)
} }
} }
static void* alloc_heap (hcl_t* hcl, hcl_oow_t size) static void* alloc_heap (hcl_t* hcl, hcl_oow_t* size)
{ {
return hcl_allocmem(hcl, size); return hcl_allocmem(hcl, *size);
} }
static void free_heap (hcl_t* hcl, void* ptr) static void free_heap (hcl_t* hcl, void* ptr)

View File

@ -1344,6 +1344,16 @@ struct hcl_dbgi_t
#if defined(HCL_INCLUDE_COMPILER) #if defined(HCL_INCLUDE_COMPILER)
typedef struct hcl_compiler_t hcl_compiler_t; typedef struct hcl_compiler_t hcl_compiler_t;
typedef struct hcl_cnode_t hcl_cnode_t; typedef struct hcl_cnode_t hcl_cnode_t;
enum hcl_compile_flag_t
{
/* clear byte codes at the beginnign of hcl_compile() */
HCL_COMPILE_CLEAR_CODE = (1 << 0),
/* clear the top-level function block at the end of hcl_compile() */
HCL_COMPILE_CLEAR_FNBLK = (1 << 1)
};
typedef enum hcl_compile_flag_t hcl_compile_flag_t;
#endif #endif
#define HCL_ERRMSG_CAPA (2048) #define HCL_ERRMSG_CAPA (2048)
@ -2029,10 +2039,13 @@ HCL_EXPORT hcl_ooi_t hcl_proutufmt (
... ...
); );
#if defined(HCL_INCLUDE_COMPILER)
HCL_EXPORT int hcl_compile ( HCL_EXPORT int hcl_compile (
hcl_t* hcl, hcl_t* hcl,
hcl_cnode_t* obj hcl_cnode_t* obj,
int flags
); );
#endif
/** /**
* The hcl_decode() function decodes instructions from the position * The hcl_decode() function decodes instructions from the position