added hawk_killecb() and hawk_rtx_killecb()

corrected a new silly flaw in the ON_STATEMENT() macro
This commit is contained in:
hyung-hwan 2022-06-09 06:01:44 +00:00
parent 676496325e
commit c8eb44b54b
4 changed files with 54 additions and 13 deletions

View File

@ -578,6 +578,21 @@ void hawk_haltall (hawk_t* hawk)
hawk->haltall = 1; hawk->haltall = 1;
} }
void hawk_killecb (hawk_t* hawk, hawk_ecb_t* ecb)
{
hawk_ecb_t* prev, * cur;
for (cur = hawk->ecb, prev = HAWK_NULL; cur != (hawk_ecb_t*)hawk; cur = cur->next)
{
if (cur == ecb)
{
if (prev) prev->next = cur->next;
else hawk->ecb = cur->next;
cur->next = HAWK_NULL;
break;
}
}
}
hawk_ecb_t* hawk_popecb (hawk_t* hawk) hawk_ecb_t* hawk_popecb (hawk_t* hawk)
{ {
hawk_ecb_t* top = hawk->ecb; hawk_ecb_t* top = hawk->ecb;

View File

@ -1719,21 +1719,26 @@ HAWK_EXPORT int hawk_setopt (
const void* value const void* value
); );
HAWK_EXPORT void hawk_killecb (
hawk_t* hawk,
hawk_ecb_t* ecb
);
/** /**
* The hawk_popecb() function pops an hawk event callback set * The hawk_popecb() function pops an hawk event callback set
* and returns the pointer to it. If no callback set can be popped, * and returns the pointer to it. If no callback set can be popped,
* it returns #HAWK_NULL. * it returns #HAWK_NULL.
*/ */
HAWK_EXPORT hawk_ecb_t* hawk_popecb ( HAWK_EXPORT hawk_ecb_t* hawk_popecb (
hawk_t* hawk /**< hawk */ hawk_t* hawk
); );
/** /**
* The hawk_pushecb() function register a runtime callback set. * The hawk_pushecb() function register a runtime callback set.
*/ */
HAWK_EXPORT void hawk_pushecb ( HAWK_EXPORT void hawk_pushecb (
hawk_t* hawk, /**< hawk */ hawk_t* hawk,
hawk_ecb_t* ecb /**< callback set */ hawk_ecb_t* ecb
); );
/** /**
@ -2398,6 +2403,11 @@ HAWK_EXPORT void hawk_rtx_setrio (
const hawk_rio_cbs_t* rio const hawk_rio_cbs_t* rio
); );
HAWK_EXPORT void hawk_rtx_killecb (
hawk_rtx_t* rtx, /**< runtime context */
hawk_rtx_ecb_t* ecb /**< callback set */
);
/** /**
* The hawk_rtx_popecb() function pops a runtime callback set * The hawk_rtx_popecb() function pops a runtime callback set
* and returns the pointer to it. If no callback set can be popped, * and returns the pointer to it. If no callback set can be popped,

View File

@ -983,6 +983,21 @@ void hawk_rtx_setrio (hawk_rtx_t* rtx, const hawk_rio_cbs_t* rio)
rtx->rio.handler[HAWK_RIO_CONSOLE] = rio->console; rtx->rio.handler[HAWK_RIO_CONSOLE] = rio->console;
} }
void hawk_rtx_killecb (hawk_rtx_t* rtx, hawk_rtx_ecb_t* ecb)
{
hawk_rtx_ecb_t* prev, * cur;
for (cur = rtx->ecb, prev = HAWK_NULL; cur != (hawk_rtx_ecb_t*)rtx; cur = cur->next)
{
if (cur == ecb)
{
if (prev) prev->next = cur->next;
else rtx->ecb = cur->next;
cur->next = HAWK_NULL;
break;
}
}
}
hawk_rtx_ecb_t* hawk_rtx_popecb (hawk_rtx_t* rtx) hawk_rtx_ecb_t* hawk_rtx_popecb (hawk_rtx_t* rtx)
{ {
hawk_rtx_ecb_t* top = rtx->ecb; hawk_rtx_ecb_t* top = rtx->ecb;
@ -2233,9 +2248,10 @@ static int run_block (hawk_rtx_t* rtx, hawk_nde_blk_t* nde)
#define ON_STATEMENT(rtx,nde) do { \ #define ON_STATEMENT(rtx,nde) do { \
hawk_rtx_ecb_t* ecb, * ecb_next; \ hawk_rtx_ecb_t* ecb, * ecb_next; \
if ((rtx)->hawk->haltall) (rtx)->exit_level = EXIT_ABORT; \ if ((rtx)->hawk->haltall) (rtx)->exit_level = EXIT_ABORT; \
for (ecb = (rtx)->ecb; ecb != (hawk_rtx_ecb_t*)(rtx); ecb = ecb_next) \ for (ecb = (rtx)->ecb; ecb != (hawk_rtx_ecb_t*)(rtx); ecb = ecb_next) { \
ecb_next = ecb->next; \ ecb_next = ecb->next; \
if (ecb->stmt) ecb->stmt (rtx, nde, ecb->ctx); \ if (ecb->stmt) ecb->stmt (rtx, nde, ecb->ctx); \
} \
} while(0) } while(0)
static int run_statement (hawk_rtx_t* rtx, hawk_nde_t* nde) static int run_statement (hawk_rtx_t* rtx, hawk_nde_t* nde)

View File

@ -3921,15 +3921,6 @@ void hawk_sed_setlinenum (hawk_sed_t* sed, hawk_oow_t num)
sed->e.in.num = num; sed->e.in.num = num;
} }
hawk_sed_ecb_t* hawk_sed_popecb (hawk_sed_t* sed)
{
hawk_sed_ecb_t* top = sed->ecb;
if (top == (hawk_sed_ecb_t*)sed) return HAWK_NULL;
sed->ecb = top->next;
top->next = HAWK_NULL;
return top;
}
void hawk_sed_killecb (hawk_sed_t* sed, hawk_sed_ecb_t* ecb) void hawk_sed_killecb (hawk_sed_t* sed, hawk_sed_ecb_t* ecb)
{ {
hawk_sed_ecb_t* prev, * cur; hawk_sed_ecb_t* prev, * cur;
@ -3945,6 +3936,15 @@ void hawk_sed_killecb (hawk_sed_t* sed, hawk_sed_ecb_t* ecb)
} }
} }
hawk_sed_ecb_t* hawk_sed_popecb (hawk_sed_t* sed)
{
hawk_sed_ecb_t* top = sed->ecb;
if (top == (hawk_sed_ecb_t*)sed) return HAWK_NULL;
sed->ecb = top->next;
top->next = HAWK_NULL;
return top;
}
void hawk_sed_pushecb (hawk_sed_t* sed, hawk_sed_ecb_t* ecb) void hawk_sed_pushecb (hawk_sed_t* sed, hawk_sed_ecb_t* ecb)
{ {
ecb->next = sed->ecb; ecb->next = sed->ecb;