some cosmetic source code changes

This commit is contained in:
hyung-hwan 2020-03-25 05:56:11 +00:00
parent 404c382e33
commit 74180e1d8a
3 changed files with 84 additions and 82 deletions

View File

@ -5571,12 +5571,12 @@ static hawk_val_t* eval_binop_ma (hawk_rtx_t* run, hawk_nde_t* left, hawk_nde_t*
HAWK_ASSERT (right->next == HAWK_NULL);
lv = eval_expression(run, left);
if (lv == HAWK_NULL) return HAWK_NULL;
if (HAWK_UNLIKELY(!lv)) return HAWK_NULL;
hawk_rtx_refupval (run, lv);
rv = eval_expression0(run, right);
if (rv == HAWK_NULL)
if (HAWK_UNLIKELY(!rv))
{
hawk_rtx_refdownval (run, lv);
return HAWK_NULL;
@ -5600,12 +5600,12 @@ static hawk_val_t* eval_binop_nm (hawk_rtx_t* run, hawk_nde_t* left, hawk_nde_t*
HAWK_ASSERT (right->next == HAWK_NULL);
lv = eval_expression(run, left);
if (lv == HAWK_NULL) return HAWK_NULL;
if (HAWK_UNLIKELY(!lv)) return HAWK_NULL;
hawk_rtx_refupval (run, lv);
rv = eval_expression0(run, right);
if (rv == HAWK_NULL)
if (HAWK_UNLIKELY(!rv))
{
hawk_rtx_refdownval (run, lv);
return HAWK_NULL;
@ -5641,7 +5641,7 @@ static hawk_val_t* eval_unary (hawk_rtx_t* rtx, hawk_nde_t* nde)
HAWK_ASSERT (exp->left->next == HAWK_NULL);
left = eval_expression(rtx, exp->left);
if (left == HAWK_NULL) return HAWK_NULL;
if (HAWK_UNLIKELY(!left)) return HAWK_NULL;
hawk_rtx_refupval (rtx, left);
@ -5649,7 +5649,7 @@ static hawk_val_t* eval_unary (hawk_rtx_t* rtx, hawk_nde_t* nde)
{
case HAWK_UNROP_MINUS:
n = hawk_rtx_valtonum(rtx, left, &l, &r);
if (n <= -1) goto exit_func;
if (HAWK_UNLIKELY(n <= -1)) goto exit_func;
res = (n == 0)? hawk_rtx_makeintval(rtx, -l):
hawk_rtx_makefltval(rtx, -r);
@ -5660,13 +5660,12 @@ static hawk_val_t* eval_unary (hawk_rtx_t* rtx, hawk_nde_t* nde)
{
/* 0 if the string length is greater than 0.
* 1 if it's empty */
res = hawk_rtx_makeintval (
rtx, !(((hawk_val_str_t*)left)->val.len > 0));
res = hawk_rtx_makeintval(rtx, !(((hawk_val_str_t*)left)->val.len > 0));
}
else
{
n = hawk_rtx_valtonum(rtx, left, &l, &r);
if (n <= -1) goto exit_func;
if (HAWK_UNLIKELY(n <= -1)) goto exit_func;
res = (n == 0)? hawk_rtx_makeintval(rtx, !l):
hawk_rtx_makefltval(rtx, !r);
@ -5675,14 +5674,14 @@ static hawk_val_t* eval_unary (hawk_rtx_t* rtx, hawk_nde_t* nde)
case HAWK_UNROP_BNOT:
n = hawk_rtx_valtoint(rtx, left, &l);
if (n <= -1) goto exit_func;
if (HAWK_UNLIKELY(n <= -1)) goto exit_func;
res = hawk_rtx_makeintval(rtx, ~l);
break;
case HAWK_UNROP_PLUS:
n = hawk_rtx_valtonum(rtx, left, &l, &r);
if (n <= -1) goto exit_func;
if (HAWK_UNLIKELY(n <= -1)) goto exit_func;
res = (n == 0)? hawk_rtx_makeintval(rtx, l):
hawk_rtx_makefltval(rtx, r);
@ -5691,7 +5690,7 @@ static hawk_val_t* eval_unary (hawk_rtx_t* rtx, hawk_nde_t* nde)
exit_func:
hawk_rtx_refdownval (rtx, left);
if (res == HAWK_NULL) ADJERR_LOC (rtx, &nde->loc);
if (HAWK_UNLIKELY(!res)) ADJERR_LOC (rtx, &nde->loc);
return res;
}
@ -5736,7 +5735,7 @@ static hawk_val_t* eval_incpre (hawk_rtx_t* rtx, hawk_nde_t* nde)
HAWK_ASSERT (exp->left->next == HAWK_NULL);
left = eval_expression(rtx, exp->left);
if (left == HAWK_NULL) return HAWK_NULL;
if (HAWK_UNLIKELY(!left)) return HAWK_NULL;
hawk_rtx_refupval (rtx, left);
left_vtype = HAWK_RTX_GETVALTYPE(rtx, left);
@ -5747,7 +5746,7 @@ static hawk_val_t* eval_incpre (hawk_rtx_t* rtx, hawk_nde_t* nde)
{
hawk_int_t r = HAWK_RTX_GETINTFROMVAL (rtx, left);
res = hawk_rtx_makeintval(rtx, r + inc_val_int);
if (res == HAWK_NULL)
if (HAWK_UNLIKELY(!res))
{
hawk_rtx_refdownval (rtx, left);
ADJERR_LOC (rtx, &nde->loc);
@ -5760,7 +5759,7 @@ static hawk_val_t* eval_incpre (hawk_rtx_t* rtx, hawk_nde_t* nde)
{
hawk_flt_t r = ((hawk_val_flt_t*)left)->val;
res = hawk_rtx_makefltval(rtx, r + inc_val_flt);
if (res == HAWK_NULL)
if (HAWK_UNLIKELY(!res))
{
hawk_rtx_refdownval (rtx, left);
ADJERR_LOC (rtx, &nde->loc);
@ -5776,7 +5775,7 @@ static hawk_val_t* eval_incpre (hawk_rtx_t* rtx, hawk_nde_t* nde)
int n;
n = hawk_rtx_valtonum(rtx, left, &v1, &v2);
if (n <= -1)
if (HAWK_UNLIKELY(n <= -1))
{
hawk_rtx_refdownval (rtx, left);
ADJERR_LOC (rtx, &nde->loc);
@ -5793,7 +5792,7 @@ static hawk_val_t* eval_incpre (hawk_rtx_t* rtx, hawk_nde_t* nde)
res = hawk_rtx_makefltval (rtx, v2 + inc_val_flt);
}
if (res == HAWK_NULL)
if (HAWK_UNLIKELY(!res))
{
hawk_rtx_refdownval (rtx, left);
ADJERR_LOC (rtx, &nde->loc);
@ -5804,7 +5803,7 @@ static hawk_val_t* eval_incpre (hawk_rtx_t* rtx, hawk_nde_t* nde)
}
}
if (do_assignment (rtx, exp->left, res) == HAWK_NULL)
if (HAWK_UNLIKELY(do_assignment(rtx, exp->left, res) == HAWK_NULL))
{
hawk_rtx_refdownval (rtx, left);
return HAWK_NULL;
@ -5855,7 +5854,7 @@ static hawk_val_t* eval_incpst (hawk_rtx_t* rtx, hawk_nde_t* nde)
HAWK_ASSERT (exp->left->next == HAWK_NULL);
left = eval_expression(rtx, exp->left);
if (left == HAWK_NULL) return HAWK_NULL;
if (HAWK_UNLIKELY(!left)) return HAWK_NULL;
hawk_rtx_refupval (rtx, left);
@ -5867,7 +5866,7 @@ static hawk_val_t* eval_incpst (hawk_rtx_t* rtx, hawk_nde_t* nde)
{
hawk_int_t r = HAWK_RTX_GETINTFROMVAL(rtx, left);
res = hawk_rtx_makeintval(rtx, r);
if (res == HAWK_NULL)
if (HAWK_UNLIKELY(!res))
{
hawk_rtx_refdownval (rtx, left);
ADJERR_LOC (rtx, &nde->loc);
@ -5875,10 +5874,10 @@ static hawk_val_t* eval_incpst (hawk_rtx_t* rtx, hawk_nde_t* nde)
}
res2 = hawk_rtx_makeintval(rtx, r + inc_val_int);
if (res2 == HAWK_NULL)
if (HAWK_UNLIKELY(!res2))
{
hawk_rtx_refdownval (rtx, left);
hawk_rtx_freeval (rtx, res, 1);
hawk_rtx_freeval (rtx, res, HAWK_RTX_FREEVAL_CACHE);
ADJERR_LOC (rtx, &nde->loc);
return HAWK_NULL;
}
@ -5890,7 +5889,7 @@ static hawk_val_t* eval_incpst (hawk_rtx_t* rtx, hawk_nde_t* nde)
{
hawk_flt_t r = ((hawk_val_flt_t*)left)->val;
res = hawk_rtx_makefltval(rtx, r);
if (res == HAWK_NULL)
if (HAWK_UNLIKELY(!res))
{
hawk_rtx_refdownval (rtx, left);
ADJERR_LOC (rtx, &nde->loc);
@ -5898,10 +5897,10 @@ static hawk_val_t* eval_incpst (hawk_rtx_t* rtx, hawk_nde_t* nde)
}
res2 = hawk_rtx_makefltval(rtx, r + inc_val_flt);
if (res2 == HAWK_NULL)
if (HAWK_UNLIKELY(!res2))
{
hawk_rtx_refdownval (rtx, left);
hawk_rtx_freeval (rtx, res, 1);
hawk_rtx_freeval (rtx, res, HAWK_RTX_FREEVAL_CACHE);
ADJERR_LOC (rtx, &nde->loc);
return HAWK_NULL;
}
@ -5916,7 +5915,7 @@ static hawk_val_t* eval_incpst (hawk_rtx_t* rtx, hawk_nde_t* nde)
int n;
n = hawk_rtx_valtonum(rtx, left, &v1, &v2);
if (n <= -1)
if (HAWK_UNLIKELY(n <= -1))
{
hawk_rtx_refdownval (rtx, left);
ADJERR_LOC (rtx, &nde->loc);
@ -5926,7 +5925,7 @@ static hawk_val_t* eval_incpst (hawk_rtx_t* rtx, hawk_nde_t* nde)
if (n == 0)
{
res = hawk_rtx_makeintval(rtx, v1);
if (res == HAWK_NULL)
if (HAWK_UNLIKELY(!res))
{
hawk_rtx_refdownval (rtx, left);
ADJERR_LOC (rtx, &nde->loc);
@ -5934,10 +5933,10 @@ static hawk_val_t* eval_incpst (hawk_rtx_t* rtx, hawk_nde_t* nde)
}
res2 = hawk_rtx_makeintval(rtx, v1 + inc_val_int);
if (res2 == HAWK_NULL)
if (HAWK_UNLIKELY(!res2))
{
hawk_rtx_refdownval (rtx, left);
hawk_rtx_freeval (rtx, res, 1);
hawk_rtx_freeval (rtx, res, HAWK_RTX_FREEVAL_CACHE);
ADJERR_LOC (rtx, &nde->loc);
return HAWK_NULL;
}
@ -5946,7 +5945,7 @@ static hawk_val_t* eval_incpst (hawk_rtx_t* rtx, hawk_nde_t* nde)
{
HAWK_ASSERT (n == 1);
res = hawk_rtx_makefltval(rtx, v2);
if (res == HAWK_NULL)
if (HAWK_UNLIKELY(!res))
{
hawk_rtx_refdownval (rtx, left);
ADJERR_LOC (rtx, &nde->loc);
@ -5954,10 +5953,10 @@ static hawk_val_t* eval_incpst (hawk_rtx_t* rtx, hawk_nde_t* nde)
}
res2 = hawk_rtx_makefltval(rtx, v2 + inc_val_flt);
if (res2 == HAWK_NULL)
if (HAWK_UNLIKELY(!res2))
{
hawk_rtx_refdownval (rtx, left);
hawk_rtx_freeval (rtx, res, 1);
hawk_rtx_freeval (rtx, res, HAWK_RTX_FREEVAL_CACHE);
ADJERR_LOC (rtx, &nde->loc);
return HAWK_NULL;
}
@ -5967,7 +5966,7 @@ static hawk_val_t* eval_incpst (hawk_rtx_t* rtx, hawk_nde_t* nde)
}
}
if (do_assignment (rtx, exp->left, res2) == HAWK_NULL)
if (HAWK_UNLIKELY(do_assignment(rtx, exp->left, res2) == HAWK_NULL))
{
hawk_rtx_refdownval (rtx, left);
return HAWK_NULL;

View File

@ -128,6 +128,10 @@ struct hawk_val_rchunk_t
#define HAWK_VAL_ONE HAWK_VTR_ONE
#define HAWK_VAL_NEGONE HAWK_VTR_NEGONE
#define HAWK_RTX_FREEVAL_CACHE (1 << 0)
#define HAWK_RTX_FREEVAL_GC_PRESERVE (1 << 1)
#if defined(__cplusplus)
extern "C" {
#endif
@ -142,7 +146,7 @@ extern hawk_val_t* hawk_val_zls;
void hawk_rtx_freeval (
hawk_rtx_t* rtx,
hawk_val_t* val,
int cache
int flags
);
void hawk_rtx_freevalchunk (

View File

@ -305,8 +305,7 @@ static void gc_free_unreachables (hawk_rtx_t* rtx, hawk_gch_t* list)
gch = list->gc_next;
while (gch != list)
{
/* -9999 preserves the outer shell */
hawk_rtx_freeval (rtx, hawk_gch_to_val(gch), -9999);
hawk_rtx_freeval (rtx, hawk_gch_to_val(gch), HAWK_RTX_FREEVAL_GC_PRESERVE);
gch = gch->gc_next;
}
@ -318,7 +317,7 @@ static void gc_free_unreachables (hawk_rtx_t* rtx, hawk_gch_t* list)
#if defined(DEBUG_GC)
hawk_logbfmt (hawk_rtx_gethawk(rtx), HAWK_LOG_STDERR, "[GC] FREEING UNREACHABLE GCH %p gc_refs %zu v_refs %zu\n", gch, gch->gc_refs, hawk_gch_to_val(gch)->v_refs);
#endif
/* do what hawk_rtx_freeval() would do without -9999 */
/* do what hawk_rtx_freeval() would do without HAWK_RTX_FREEVAL_GC_PRESERVE */
rtx->gc.all_count--;
gc_unchain_gch (gch);
hawk_rtx_freemem (rtx, gch);
@ -996,8 +995,8 @@ hawk_val_t* hawk_rtx_makemapvalwithdata (hawk_rtx_t* rtx, hawk_val_map_data_t da
if (tmp == HAWK_NULL || hawk_rtx_setmapvalfld(rtx, map, p->key.ptr, p->key.len, tmp) == HAWK_NULL)
{
if (tmp) hawk_rtx_freeval (rtx, tmp, 1);
hawk_rtx_freeval (rtx, map, 1);
if (tmp) hawk_rtx_freeval (rtx, tmp, HAWK_RTX_FREEVAL_CACHE);
hawk_rtx_freeval (rtx, map, HAWK_RTX_FREEVAL_CACHE);
return HAWK_NULL;
}
}
@ -1126,7 +1125,7 @@ int hawk_rtx_getintfromval (hawk_rtx_t* rtx, hawk_val_t* val)
return HAWK_RTX_GETINTFROMVAL(rtx, val);
}
void hawk_rtx_freeval (hawk_rtx_t* rtx, hawk_val_t* val, int cache)
void hawk_rtx_freeval (hawk_rtx_t* rtx, hawk_val_t* val, int flags)
{
hawk_val_type_t vtype;
@ -1164,7 +1163,7 @@ void hawk_rtx_freeval (hawk_rtx_t* rtx, hawk_val_t* val, int cache)
case HAWK_VAL_STR:
{
#if defined(HAWK_ENABLE_STR_CACHE)
if (cache)
if (flags & HAWK_RTX_FREEVAL_CACHE)
{
hawk_val_str_t* v = (hawk_val_str_t*)val;
hawk_oow_t aligned_len;
@ -1189,7 +1188,7 @@ void hawk_rtx_freeval (hawk_rtx_t* rtx, hawk_val_t* val, int cache)
case HAWK_VAL_MBS:
#if defined(HAWK_ENABLE_MBS_CACHE)
if (cache)
if (flags & HAWK_RTX_FREEVAL_CACHE)
{
hawk_val_mbs_t* v = (hawk_val_mbs_t*)val;
hawk_oow_t aligned_len;
@ -1233,11 +1232,11 @@ void hawk_rtx_freeval (hawk_rtx_t* rtx, hawk_val_t* val, int cache)
#if defined(HAWK_ENABLE_GC)
#if defined(DEBUG_GC)
hawk_logbfmt (hawk_rtx_gethawk(rtx), HAWK_LOG_STDERR, "[GC] FREEING GCH %p VAL %p - flags %d\n", hawk_val_to_gch(val), val, cache);
hawk_logbfmt (hawk_rtx_gethawk(rtx), HAWK_LOG_STDERR, "[GC] FREEING GCH %p VAL %p - flags %d\n", hawk_val_to_gch(val), val, flags);
#endif
hawk_map_fini (((hawk_val_map_t*)val)->map);
if (cache != -9999)
if (!(flags & HAWK_RTX_FREEVAL_GC_PRESERVE))
{
rtx->gc.all_count--;
gc_unchain_val (val);
@ -1250,7 +1249,7 @@ void hawk_rtx_freeval (hawk_rtx_t* rtx, hawk_val_t* val, int cache)
break;
case HAWK_VAL_REF:
if (cache && rtx->rcache_count < HAWK_COUNTOF(rtx->rcache))
if ((flags & HAWK_RTX_FREEVAL_CACHE) && rtx->rcache_count < HAWK_COUNTOF(rtx->rcache))
{
rtx->rcache[rtx->rcache_count++] = (hawk_val_ref_t*)val;
}
@ -1289,7 +1288,7 @@ void hawk_rtx_refdownval (hawk_rtx_t* rtx, hawk_val_t* val)
val->v_refs--;
if (val->v_refs <= 0)
{
hawk_rtx_freeval(rtx, val, 1);
hawk_rtx_freeval (rtx, val, HAWK_RTX_FREEVAL_CACHE);
}
}
}