From 3f01a77f1e222f006976f176af2d962130dfdc14 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 3 Jul 2023 01:42:14 +0900 Subject: [PATCH] added hawk::hash() --- lib/mod-hawk.c | 15 +++++++++++++++ lib/val.c | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/mod-hawk.c b/lib/mod-hawk.c index 33408159..e7bf8866 100644 --- a/lib/mod-hawk.c +++ b/lib/mod-hawk.c @@ -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 } }, diff --git a/lib/val.c b/lib/val.c index fd637e3f..9cb9e0bd 100644 --- a/lib/val.c +++ b/lib/val.c @@ -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)