added hawk::hash()

This commit is contained in:
hyung-hwan 2023-07-03 01:42:14 +09:00
parent 9fb716d5a3
commit 3f01a77f1e
2 changed files with 16 additions and 1 deletions

View File

@ -465,6 +465,20 @@ static int fnc_typename (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
return 0;
}
/* -------------------------------------------------------------------------- */
static int fnc_hash (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
{
hawk_val_t* a0;
hawk_int_t v;
const hawk_ooch_t* name;
a0 = hawk_rtx_getarg(rtx, 0);
v = hawk_rtx_hashval(rtx, a0); /* ignore v <= -1 which is an error */
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, v));
return 0;
}
/* -------------------------------------------------------------------------- */
#define A_MAX HAWK_TYPE_MAX(hawk_oow_t)
@ -480,6 +494,7 @@ static hawk_mod_fnc_tab_t fnctab[] =
{ HAWK_T("gc_get_threshold"), { { 1, 1, HAWK_NULL }, fnc_gc_get_threshold, 0 } },
{ HAWK_T("gc_set_threshold"), { { 2, 2, HAWK_NULL }, fnc_gc_set_threshold, 0 } },
{ HAWK_T("gcrefs"), { { 1, 1, HAWK_NULL }, fnc_gcrefs, 0 } },
{ HAWK_T("hash"), { { 1, 1, HAWK_NULL }, fnc_hash, 0 } },
{ HAWK_T("isarray"), { { 1, 1, HAWK_NULL }, fnc_isarr, 0 } },
{ HAWK_T("ismap"), { { 1, 1, HAWK_NULL }, fnc_ismap, 0 } },
{ HAWK_T("isnil"), { { 1, 1, HAWK_NULL }, fnc_isnil, 0 } },

View File

@ -2902,7 +2902,7 @@ static HAWK_INLINE hawk_uint_t hash (hawk_uint8_t* ptr, hawk_oow_t len)
hawk_int_t hawk_rtx_hashval (hawk_rtx_t* rtx, hawk_val_t* v)
{
hawk_val_type_t vtype = HAWK_RTX_GETVALTYPE (rtx, v);
hawk_val_type_t vtype = HAWK_RTX_GETVALTYPE(rtx, v);
hawk_int_t hv;
switch (vtype)