fixed to clear inner data upon an error in the interactive mode
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
c795b28cb8
commit
f08ba4cd12
14
bin/hcl.c
14
bin/hcl.c
@ -533,14 +533,13 @@ static int on_fed_cnode_in_interactive_mode (hcl_t* hcl, hcl_cnode_t* obj)
|
||||
|
||||
if (hcl_compile(hcl, obj, flags) <= -1)
|
||||
{
|
||||
print_error(hcl, "failed to compile");
|
||||
/*print_error(hcl, "failed to compile"); */
|
||||
xtn->feed.pos = xtn->feed.len; /* arrange to discard the rest of the line */
|
||||
}
|
||||
else
|
||||
{
|
||||
xtn->feed.ncompexprs++;
|
||||
return -1; /* this causes the feed function to fail and
|
||||
the error hander for to print the error message */
|
||||
}
|
||||
|
||||
xtn->feed.ncompexprs++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -641,6 +640,11 @@ static int feed_loop (hcl_t* hcl, xtn_t* xtn, int verbose)
|
||||
{
|
||||
print_error (hcl, "failed to feed");
|
||||
if (len > 0) show_prompt (hcl, 0);
|
||||
|
||||
/* clear the compiled code but not executed yet */
|
||||
hcl_clearcode(hcl);
|
||||
hcl_clearfnblks(hcl);
|
||||
xtn->feed.ncompexprs = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1242,6 +1242,12 @@ static void pop_fnblk (hcl_t* hcl)
|
||||
}
|
||||
}
|
||||
|
||||
void hcl_clearfnblks (hcl_t* hcl)
|
||||
{
|
||||
while (hcl->c->fnblk.depth >= 0) pop_fnblk (hcl);
|
||||
HCL_ASSERT (hcl, hcl->c->fnblk.depth == -1);
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
static HCL_INLINE int _insert_cframe (hcl_t* hcl, hcl_ooi_t index, int opcode, hcl_cnode_t* operand)
|
||||
{
|
||||
@ -5891,8 +5897,7 @@ int hcl_compile (hcl_t* hcl, hcl_cnode_t* obj, int flags)
|
||||
* in the interactive mode, the information doesn't have
|
||||
* to get carried over.
|
||||
*/
|
||||
while (hcl->c->fnblk.depth >= 0) pop_fnblk (hcl);
|
||||
HCL_ASSERT (hcl, hcl->c->fnblk.depth == -1);
|
||||
hcl_clearfnblks (hcl);
|
||||
/* it will be recreated below */
|
||||
}
|
||||
if (flags & HCL_COMPILE_CLEAR_CODE) hcl_clearcode (hcl);
|
||||
|
@ -372,7 +372,7 @@ static void vm_checkbc (hcl_t* hcl, hcl_oob_t bcode)
|
||||
static HCL_INLINE hcl_oop_context_t make_context (hcl_t* hcl, hcl_ooi_t ntmprs)
|
||||
{
|
||||
HCL_ASSERT (hcl, ntmprs >= 0);
|
||||
//return (hcl_oop_context_t)hcl_allocoopobj(hcl, HCL_BRAND_CONTEXT, HCL_CONTEXT_NAMED_INSTVARS + (hcl_oow_t)ntmprs);
|
||||
/*return (hcl_oop_context_t)hcl_allocoopobj(hcl, HCL_BRAND_CONTEXT, HCL_CONTEXT_NAMED_INSTVARS + (hcl_oow_t)ntmprs);*/
|
||||
return (hcl_oop_context_t)hcl_instantiatewithtrailer(hcl, hcl->c_block_context, ntmprs, HCL_NULL, 0);
|
||||
}
|
||||
|
||||
|
@ -2568,6 +2568,10 @@ HCL_EXPORT void hcl_clearcode (
|
||||
hcl_t* hcl
|
||||
);
|
||||
|
||||
HCL_EXPORT void hcl_clearfnblks (
|
||||
hcl_t* hcl
|
||||
);
|
||||
|
||||
#if defined(HCL_HAVE_INLINE)
|
||||
static HCL_INLINE hcl_code_t* hcl_getcode (hcl_t* hcl) { return &hcl->code; }
|
||||
static HCL_INLINE hcl_oob_t* hcl_getbcptr (hcl_t* hcl) { return hcl->code.bc.ptr; }
|
||||
|
21
lib/read.c
21
lib/read.c
@ -1144,7 +1144,10 @@ static int feed_begin_include (hcl_t* hcl)
|
||||
return 0;
|
||||
|
||||
oops:
|
||||
if (arg) hcl_freemem (hcl, arg);
|
||||
if (arg)
|
||||
{
|
||||
hcl_freemem (hcl, arg);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -3100,7 +3103,7 @@ static int feed_from_includee (hcl_t* hcl)
|
||||
{
|
||||
const hcl_ooch_t* orgmsg = hcl_backuperrmsg(hcl);
|
||||
hcl_seterrbfmt (hcl, HCL_ERRNUM(hcl), "unable to read bytes from %js - %js", curinp->name, orgmsg);
|
||||
return -1;
|
||||
goto oops;
|
||||
}
|
||||
|
||||
if (curinp->xlen <= 0)
|
||||
@ -3109,7 +3112,7 @@ static int feed_from_includee (hcl_t* hcl)
|
||||
if (curinp->rsd.len > 0)
|
||||
{
|
||||
hcl_seterrbfmt (hcl, HCL_EECERR, "incomplete byte sequence in %js", curinp->name);
|
||||
return -1;
|
||||
goto oops;
|
||||
}
|
||||
feed_end_include (hcl);
|
||||
curinp = hcl->c->curinp;
|
||||
@ -3139,7 +3142,7 @@ static int feed_from_includee (hcl_t* hcl)
|
||||
{
|
||||
/* TODO: more accurate location of the invalid byte sequence */
|
||||
hcl_seterrbfmt (hcl, HCL_EECERR, "invalid byte sequence in %js", curinp->name);
|
||||
return -1;
|
||||
goto oops;
|
||||
}
|
||||
if (n > inplen) /* incomplete sequence */
|
||||
{
|
||||
@ -3172,7 +3175,7 @@ static int feed_from_includee (hcl_t* hcl)
|
||||
/* TODO: more accurate location of failure */
|
||||
const hcl_ooch_t* orgmsg = hcl_backuperrmsg(hcl);
|
||||
hcl_seterrbfmt (hcl, HCL_ERRNUM(hcl), "unable to read %js - %js", curinp->name, orgmsg);
|
||||
return -1;
|
||||
goto oops;
|
||||
}
|
||||
if (curinp->xlen <= 0)
|
||||
{
|
||||
@ -3193,7 +3196,7 @@ static int feed_from_includee (hcl_t* hcl)
|
||||
#endif
|
||||
|
||||
x = feed_char(hcl, c);
|
||||
if (x <= -1) return -1;
|
||||
if (x <= -1) goto oops;
|
||||
if (x >= 1)
|
||||
{
|
||||
/* consumed */
|
||||
@ -3211,13 +3214,17 @@ static int feed_from_includee (hcl_t* hcl)
|
||||
* to include the file. the file inclusion is attempted here after the return
|
||||
* value of feed_char() is used to advance the hcl->c->curinp->b.pos pointer. */
|
||||
hcl->c->feed.rd.do_include_file = 0; /* clear this regardless of inclusion result */
|
||||
if (feed_begin_include(hcl) <= -1) return -1;
|
||||
if (feed_begin_include(hcl) <= -1) goto oops;
|
||||
curinp = hcl->c->curinp;
|
||||
}
|
||||
}
|
||||
while (curinp != &hcl->c->cci_arg);
|
||||
|
||||
return 0;
|
||||
|
||||
oops:
|
||||
while (feed_end_include(hcl) >= 1) /* loop */; /* roll back the entire inclusion chain */
|
||||
return -1;
|
||||
}
|
||||
|
||||
int hcl_beginfeed (hcl_t* hcl, hcl_on_cnode_t on_cnode)
|
||||
|
Loading…
Reference in New Issue
Block a user