changed the free list implementation in hawk-inst.go
All checks were successful
continuous-integration/drone/push Build is passing

added go wrapper functions to manipulate return value and arguments
This commit is contained in:
2025-11-24 00:17:46 +09:00
parent 24c91d3376
commit a5bcb8ea6c
6 changed files with 349 additions and 112 deletions

View File

@@ -2550,7 +2550,7 @@ int Hawk::addFunction (
{
HAWK_ASSERT(this->hawk != HAWK_NULL);
hawk_fnc_mspec_t spec;
hawk_fnc_bspec_t spec;
HAWK_MEMSET (&spec, 0, HAWK_SIZEOF(spec));
spec.arg.min = minArgs;
@@ -2601,7 +2601,7 @@ int Hawk::addFunction (
{
HAWK_ASSERT(this->hawk != HAWK_NULL);
hawk_fnc_wspec_t spec;
hawk_fnc_uspec_t spec;
HAWK_MEMSET (&spec, 0, HAWK_SIZEOF(spec));
spec.arg.min = minArgs;

View File

@@ -146,66 +146,66 @@ static hawk_fnc_t* add_fnc (hawk_t* hawk, const hawk_ooch_t* name, const hawk_fn
return fnc;
}
hawk_fnc_t* hawk_addfncwithbcstr (hawk_t* hawk, const hawk_bch_t* name, const hawk_fnc_mspec_t* spec)
hawk_fnc_t* hawk_addfncwithbcstr (hawk_t* hawk, const hawk_bch_t* name, const hawk_fnc_bspec_t* spec)
{
#if defined(HAWK_OOCH_IS_BCH)
return add_fnc(hawk, name, spec);
#else
hawk_ucs_t wcs;
hawk_fnc_t* fnc;
hawk_fnc_spec_t wspec;
hawk_fnc_spec_t uspec;
HAWK_STATIC_ASSERT (HAWK_SIZEOF(*spec) == HAWK_SIZEOF(wspec));
HAWK_STATIC_ASSERT (HAWK_SIZEOF(*spec) == HAWK_SIZEOF(uspec));
HAWK_MEMCPY (&wspec, spec, HAWK_SIZEOF(wspec));
HAWK_MEMCPY (&uspec, spec, HAWK_SIZEOF(uspec));
if (spec->arg.spec)
{
wcs.ptr = hawk_dupbtoucstr(hawk, spec->arg.spec, &wcs.len, 0);
if (HAWK_UNLIKELY(!wcs.ptr)) return HAWK_NULL;
wspec.arg.spec = wcs.ptr;
uspec.arg.spec = wcs.ptr;
}
wcs.ptr = hawk_dupbtoucstr(hawk, name, &wcs.len, 0);
if (HAWK_UNLIKELY(!wcs.ptr))
{
if (wspec.arg.spec) hawk_freemem(hawk, (hawk_uch_t*)wspec.arg.spec);
if (uspec.arg.spec) hawk_freemem(hawk, (hawk_uch_t*)uspec.arg.spec);
return HAWK_NULL;
}
fnc = add_fnc(hawk, wcs.ptr, &wspec);
fnc = add_fnc(hawk, wcs.ptr, &uspec);
hawk_freemem(hawk, wcs.ptr);
if (wspec.arg.spec) hawk_freemem(hawk, (hawk_uch_t*)wspec.arg.spec);
if (uspec.arg.spec) hawk_freemem(hawk, (hawk_uch_t*)uspec.arg.spec);
return fnc;
#endif
}
hawk_fnc_t* hawk_addfncwithucstr (hawk_t* hawk, const hawk_uch_t* name, const hawk_fnc_wspec_t* spec)
hawk_fnc_t* hawk_addfncwithucstr (hawk_t* hawk, const hawk_uch_t* name, const hawk_fnc_uspec_t* spec)
{
#if defined(HAWK_OOCH_IS_BCH)
hawk_bcs_t mbs;
hawk_fnc_t* fnc;
hawk_fnc_spec_t mspec;
hawk_fnc_spec_t bspec;
HAWK_STATIC_ASSERT (HAWK_SIZEOF(*spec) == HAWK_SIZEOF(mspec));
HAWK_STATIC_ASSERT (HAWK_SIZEOF(*spec) == HAWK_SIZEOF(bspec));
HAWK_MEMCPY (&mspec, spec, HAWK_SIZEOF(mspec));
HAWK_MEMCPY (&bspec, spec, HAWK_SIZEOF(bspec));
if (spec->arg.spec)
{
mbs.ptr = hawk_duputobcstr(hawk, spec->arg.spec, &mbs.len);
if (HAWK_UNLIKELY(!mbs.ptr)) return HAWK_NULL;
mspec.arg.spec = mbs.ptr;
bspec.arg.spec = mbs.ptr;
}
mbs.ptr = hawk_duputobcstr(hawk, name, &mbs.len);
if (HAWK_UNLIKELY(!mbs.ptr))
{
if (mspec.arg.spec) hawk_freemem(hawk, (hawk_bch_t*)mspec.arg.spec);
if (bspec.arg.spec) hawk_freemem(hawk, (hawk_bch_t*)bspec.arg.spec);
return HAWK_NULL;
}
fnc = add_fnc(hawk, mbs.ptr, &mspec);
fnc = add_fnc(hawk, mbs.ptr, &bspec);
hawk_freemem(hawk, mbs.ptr);
if (mspec.arg.spec) hawk_freemem(hawk, (hawk_bch_t*)mspec.arg.spec);
if (bspec.arg.spec) hawk_freemem(hawk, (hawk_bch_t*)bspec.arg.spec);
return fnc;
#else
return add_fnc(hawk, name, spec);

View File

@@ -916,10 +916,10 @@ typedef int (*hawk_fnc_impl_t) (
);
/**
* The hawk_fnc_marg_t type defines a structure to describe arguments
* The hawk_fnc_barg_t type defines a structure to describe arguments
* to an implicit function.
*/
struct hawk_fnc_marg_t
struct hawk_fnc_barg_t
{
/** minimum numbers of argument for a function */
hawk_oow_t min;
@@ -939,28 +939,28 @@ struct hawk_fnc_marg_t
*/
const hawk_bch_t* spec;
};
typedef struct hawk_fnc_marg_t hawk_fnc_marg_t;
typedef struct hawk_fnc_barg_t hawk_fnc_barg_t;
/**
* The hawk_fnc_warg_t type defines a structure to describe arguments
* The hawk_fnc_uarg_t type defines a structure to describe arguments
* to an implicit function.
*/
struct hawk_fnc_warg_t
struct hawk_fnc_uarg_t
{
hawk_oow_t min;
hawk_oow_t max;
const hawk_uch_t* spec;
};
typedef struct hawk_fnc_warg_t hawk_fnc_warg_t;
typedef struct hawk_fnc_uarg_t hawk_fnc_uarg_t;
/**
* The hawk_fnc_mspec_t type defines a structure to hold the specification
* The hawk_fnc_bspec_t type defines a structure to hold the specification
* of an intrinsic function or a module function.
*/
struct hawk_fnc_mspec_t
struct hawk_fnc_bspec_t
{
/** argument descriptor */
hawk_fnc_marg_t arg;
hawk_fnc_barg_t arg;
/** pointer to the function implementing this function */
hawk_fnc_impl_t impl;
@@ -975,16 +975,16 @@ struct hawk_fnc_mspec_t
*/
int trait;
};
typedef struct hawk_fnc_mspec_t hawk_fnc_mspec_t;
typedef struct hawk_fnc_bspec_t hawk_fnc_bspec_t;
/**
* The hawk_fnc_wspec_t type defines a structure to hold the specification
* The hawk_fnc_uspec_t type defines a structure to hold the specification
* of an intrinsic function or a module function.
*/
struct hawk_fnc_wspec_t
struct hawk_fnc_uspec_t
{
/** argument descriptor */
hawk_fnc_warg_t arg;
hawk_fnc_uarg_t arg;
/** pointer to the function implementing this function */
hawk_fnc_impl_t impl;
@@ -999,14 +999,14 @@ struct hawk_fnc_wspec_t
*/
int trait;
};
typedef struct hawk_fnc_wspec_t hawk_fnc_wspec_t;
typedef struct hawk_fnc_uspec_t hawk_fnc_uspec_t;
#if defined(HAWK_OOCH_IS_BCH)
typedef hawk_fnc_marg_t hawk_fnc_arg_t;
typedef hawk_fnc_mspec_t hawk_fnc_spec_t;
typedef hawk_fnc_barg_t hawk_fnc_arg_t;
typedef hawk_fnc_bspec_t hawk_fnc_spec_t;
#else
typedef hawk_fnc_warg_t hawk_fnc_arg_t;
typedef hawk_fnc_wspec_t hawk_fnc_spec_t;
typedef hawk_fnc_uarg_t hawk_fnc_arg_t;
typedef hawk_fnc_uspec_t hawk_fnc_spec_t;
#endif
/* ------------------------------------------------------------------------ */
@@ -2002,7 +2002,7 @@ HAWK_EXPORT int hawk_findgblwithucstr (
HAWK_EXPORT hawk_fnc_t* hawk_addfncwithbcstr (
hawk_t* hawk,
const hawk_bch_t* name,
const hawk_fnc_mspec_t* spec
const hawk_fnc_bspec_t* spec
);
/**
@@ -2011,7 +2011,7 @@ HAWK_EXPORT hawk_fnc_t* hawk_addfncwithbcstr (
HAWK_EXPORT hawk_fnc_t* hawk_addfncwithucstr (
hawk_t* hawk,
const hawk_uch_t* name,
const hawk_fnc_wspec_t* spec
const hawk_fnc_uspec_t* spec
);
/**
@@ -2737,7 +2737,7 @@ HAWK_EXPORT hawk_oow_t hawk_rtx_getnargs (
*/
HAWK_EXPORT hawk_val_t* hawk_rtx_getarg (
hawk_rtx_t* rtx,
hawk_oow_t idx
hawk_oow_t idx
);
/**