did some preparatory work to support an array that uses an integer as the index
This commit is contained in:
parent
3a717bb768
commit
8b597b7acf
@ -2866,6 +2866,14 @@ HAWK_EXPORT hawk_val_t* hawk_rtx_makerexval (
|
|||||||
hawk_tre_t* code[2]
|
hawk_tre_t* code[2]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The hawk_rtx_makemapval() function creates an empty array value.
|
||||||
|
* \return value on success, #HAWK_NULL on failure
|
||||||
|
*/
|
||||||
|
HAWK_EXPORT hawk_val_t* hawk_rtx_makearrayval (
|
||||||
|
hawk_rtx_t* rtx
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The hawk_rtx_makemapval() function creates an empty map value.
|
* The hawk_rtx_makemapval() function creates an empty map value.
|
||||||
* \return value on success, #HAWK_NULL on failure
|
* \return value on success, #HAWK_NULL on failure
|
||||||
|
@ -148,6 +148,8 @@ static int fnc_function_exists (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
hawk::gc();
|
hawk::gc();
|
||||||
hawk::gc_get_threshold(gen)
|
hawk::gc_get_threshold(gen)
|
||||||
@ -209,6 +211,53 @@ static int fnc_gc_set_threshold (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#define RESET_TO_NIL (0)
|
||||||
|
#define RESET_TO_ZERO (1)
|
||||||
|
#define RESET_TO_ARRAY (2)
|
||||||
|
#define RESET_TO_MAP (3)
|
||||||
|
|
||||||
|
static int fnc_reset (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||||
|
{
|
||||||
|
hawk_val_t* tmp;
|
||||||
|
hawk_int_t type;
|
||||||
|
int x;
|
||||||
|
|
||||||
|
if (hawk_rtx_valtoint(rtx, hawk_rtx_getarg(rtx, 1), &type) <= -1) type = RESET_TO_NIL;
|
||||||
|
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case RESET_TO_ZERO:
|
||||||
|
tmp = hawk_rtx_makeintval(rtx, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RESET_TO_ARRAY:
|
||||||
|
tmp = hawk_rtx_makearrayval(rtx);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RESET_TO_MAP:
|
||||||
|
tmp = hawk_rtx_makemapval(rtx);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RESET_TO_NIL:
|
||||||
|
default:
|
||||||
|
tmp = hawk_rtx_makenilval(rtx);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (HAWK_UNLIKELY(!tmp)) return -1; /* hard failure */
|
||||||
|
|
||||||
|
hawk_rtx_refupval (rtx, tmp);
|
||||||
|
x = hawk_rtx_setrefval(rtx, (hawk_val_ref_t*)hawk_rtx_getarg(rtx, 0), tmp);
|
||||||
|
hawk_rtx_refdownval (rtx, tmp);
|
||||||
|
if (HAWK_UNLIKELY(x <= -1)) return -1; /* hard failure */
|
||||||
|
|
||||||
|
hawk_rtx_setretval (rtx, tmp);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
typedef struct fnctab_t fnctab_t;
|
typedef struct fnctab_t fnctab_t;
|
||||||
struct fnctab_t
|
struct fnctab_t
|
||||||
{
|
{
|
||||||
@ -232,13 +281,19 @@ static fnctab_t fnctab[] =
|
|||||||
{ HAWK_T("function_exists"), { { 1, 1, HAWK_NULL }, fnc_function_exists, 0 } },
|
{ HAWK_T("function_exists"), { { 1, 1, HAWK_NULL }, fnc_function_exists, 0 } },
|
||||||
{ HAWK_T("gc"), { { 0, 1, HAWK_NULL }, fnc_gc, 0 } },
|
{ HAWK_T("gc"), { { 0, 1, HAWK_NULL }, fnc_gc, 0 } },
|
||||||
{ HAWK_T("gc_get_threshold"), { { 1, 1, HAWK_NULL }, fnc_gc_get_threshold, 0 } },
|
{ 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("gc_set_threshold"), { { 2, 2, HAWK_NULL }, fnc_gc_set_threshold, 0 } },
|
||||||
|
{ HAWK_T("reset"), { { 2, 2, HAWK_T("rv") }, fnc_reset, 0 } }
|
||||||
};
|
};
|
||||||
|
|
||||||
static inttab_t inttab[] =
|
static inttab_t inttab[] =
|
||||||
{
|
{
|
||||||
/* keep this table sorted for binary search in query(). */
|
/* keep this table sorted for binary search in query(). */
|
||||||
{ HAWK_T("GC_NUM_GENS"), { HAWK_GC_NUM_GENS } }
|
{ HAWK_T("GC_NUM_GENS"), { HAWK_GC_NUM_GENS } },
|
||||||
|
|
||||||
|
{ HAWK_T("RESET_TO_ARRAY"), { RESET_TO_ARRAY } },
|
||||||
|
{ HAWK_T("RESET_TO_MAP"), { RESET_TO_MAP } },
|
||||||
|
{ HAWK_T("RESET_TO_NIL"), { RESET_TO_NIL } },
|
||||||
|
{ HAWK_T("RESET_TO_ZERO"), { RESET_TO_ZERO } }
|
||||||
};
|
};
|
||||||
|
|
||||||
static int query (hawk_mod_t* mod, hawk_t* hawk, const hawk_ooch_t* name, hawk_mod_sym_t* sym)
|
static int query (hawk_mod_t* mod, hawk_t* hawk, const hawk_ooch_t* name, hawk_mod_sym_t* sym)
|
||||||
|
@ -889,6 +889,17 @@ hawk_val_t* hawk_rtx_makerexval (hawk_rtx_t* rtx, const hawk_oocs_t* str, hawk_t
|
|||||||
return (hawk_val_t*)val;
|
return (hawk_val_t*)val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
hawk_val_t* hawk_rtx_makearrayval (hawk_rtx_t* rtx)
|
||||||
|
{
|
||||||
|
/* TODO: */
|
||||||
|
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_ENOIMPL);
|
||||||
|
return HAWK_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void free_mapval (hawk_map_t* map, void* dptr, hawk_oow_t dlen)
|
static void free_mapval (hawk_map_t* map, void* dptr, hawk_oow_t dlen)
|
||||||
{
|
{
|
||||||
hawk_rtx_t* rtx = *(hawk_rtx_t**)hawk_map_getxtn(map);
|
hawk_rtx_t* rtx = *(hawk_rtx_t**)hawk_map_getxtn(map);
|
||||||
|
Loading…
Reference in New Issue
Block a user