adding va-count, va-get, va-context for handling variable arguments

This commit is contained in:
hyung-hwan 2021-05-16 10:32:27 +00:00
parent 3f1e5f297f
commit a9abaf5623
2 changed files with 101 additions and 6 deletions

View File

@ -774,6 +774,97 @@ static hcl_pfrc_t pf_integer_bshift (hcl_t* hcl, hcl_mod_t* mod, hcl_ooi_t nargs
return HCL_PF_SUCCESS;
}
/* ------------------------------------------------------------------------- */
static hcl_pfrc_t pf_va_context (hcl_t* hcl, hcl_mod_t* mod, hcl_ooi_t nargs)
{
HCL_STACK_SETRET (hcl, nargs, hcl->active_context);
return HCL_PF_SUCCESS;
}
static hcl_pfrc_t pf_va_count (hcl_t* hcl, hcl_mod_t* mod, hcl_ooi_t nargs)
{
hcl_context_t* ctx;
hcl_ooi_t tmpr_mask, va, fixed_nargs, nrvars, nlvars, nvaargs;
if (nargs >= 1)
{
ctx = HCL_STACK_GETARG(hcl, nargs, 0);
if (!HCL_IS_CONTEXT(hcl, ctx))
{
hcl_seterrbfmt (hcl, HCL_EINVAL, "not a proper va context - %O", ctx);
return HCL_PF_FAILURE;
}
}
else
{
ctx = hcl->active_context;
}
tmpr_mask = HCL_OOP_TO_SMOOI(ctx->tmpr_mask);
va = GET_BLKTMPR_MASK_VA(tmpr_mask);
fixed_nargs = GET_BLKTMPR_MASK_NARGS(tmpr_mask);
nrvars = GET_BLKTMPR_MASK_NRVARS(tmpr_mask);
nlvars = GET_BLKTMPR_MASK_NLVARS(tmpr_mask);
/*if (!va) TODO: need this check?
{
}*/
nvaargs = HCL_OBJ_GET_SIZE(ctx) - fixed_nargs - nrvars - nlvars - HCL_CONTEXT_NAMED_INSTVARS;
HCL_STACK_SETRET (hcl, nargs, HCL_SMOOI_TO_OOP(nvaargs));
return HCL_PF_SUCCESS;
}
static hcl_pfrc_t pf_va_get (hcl_t* hcl, hcl_mod_t* mod, hcl_ooi_t nargs)
{
hcl_oop_t ret;
hcl_context_t* ctx;
hcl_ooi_t tmpr_mask, va, fixed_nargs, nrvars, nlvars, nvaargs;
hcl_oow_t index;
if (nargs >= 2)
{
ctx = HCL_STACK_GETARG(hcl, nargs, 1);
if (!HCL_IS_CONTEXT(hcl, ctx))
{
hcl_seterrbfmt (hcl, HCL_EINVAL, "not a proper va context - %O", ctx);
return HCL_PF_FAILURE;
}
}
else
{
ctx = hcl->active_context;
}
tmpr_mask = HCL_OOP_TO_SMOOI(ctx->tmpr_mask);
va = GET_BLKTMPR_MASK_VA(tmpr_mask);
fixed_nargs = GET_BLKTMPR_MASK_NARGS(tmpr_mask);
nrvars = GET_BLKTMPR_MASK_NRVARS(tmpr_mask);
nlvars = GET_BLKTMPR_MASK_NLVARS(tmpr_mask);
if (hcl_inttooow(hcl, HCL_STACK_GETARG(hcl, nargs, 0), &index) == 0)
{
return HCL_PF_FAILURE;
}
/*
if (!va) TODO: need this check?
{
}*/
nvaargs = HCL_OBJ_GET_SIZE(ctx) - fixed_nargs - nrvars - nlvars - HCL_CONTEXT_NAMED_INSTVARS;
if (index >= nvaargs)
{
hcl_seterrbfmt (hcl, HCL_EINVAL, "va index(%zu) out of bounds for va of size %zd", index, nvaargs);
return HCL_PF_FAILURE;
}
HCL_STACK_SETRET (hcl, nargs, ctx->slot[fixed_nargs + nrvars + nlvars + index]);
return HCL_PF_SUCCESS;
}
/* ------------------------------------------------------------------------- */
static pf_t builtin_prims[] =
@ -839,6 +930,10 @@ static pf_t builtin_prims[] =
{ 1, HCL_TYPE_MAX(hcl_oow_t), pf_integer_mquo, 4, { 'm','d','i','v' } },
{ 2, HCL_TYPE_MAX(hcl_oow_t), pf_integer_mod, 3, { 'm','o','d' } },
{ 0, 0, pf_va_context, 10, { 'v','a','-','c','o','n','t','e','x','t' } },
{ 0, 1, pf_va_count, 8, { 'v','a','-','c','o','u','n','t' } },
{ 1, 2, pf_va_get, 6, { 'v','a','-','g','e','t' } },
{ 0, 0, hcl_pf_process_current, 15, { 'c','u','r','r','e','n','t','-','p','r','o','c','e','s','s'} },
{ 1, HCL_TYPE_MAX(hcl_oow_t), hcl_pf_process_fork, 4, { 'f','o','r','k'} },
{ 1, 1, hcl_pf_process_resume, 6, { 'r','e','s','u','m','e' } },

View File

@ -46,7 +46,7 @@ static hcl_pfrc_t pf_arr_get (hcl_t* hcl, hcl_mod_t* mod, hcl_ooi_t nargs)
if (index >= HCL_OBJ_GET_SIZE(arr))
{
hcl_seterrbfmt (hcl, HCL_EINVAL, "array index(%zu) out of bounds(0-%zu)", index, HCL_OBJ_GET_SIZE(arr) - 1);
hcl_seterrbfmt (hcl, HCL_EINVAL, "array index(%zu) out of boundsfor array of size %zu", index, HCL_OBJ_GET_SIZE(arr));
return HCL_PF_FAILURE;
}
@ -74,7 +74,7 @@ static hcl_pfrc_t pf_arr_put (hcl_t* hcl, hcl_mod_t* mod, hcl_ooi_t nargs)
if (index >= HCL_OBJ_GET_SIZE(arr))
{
hcl_seterrbfmt (hcl, HCL_EINVAL, "array index(%zu) out of bounds(0-%zu)", index, HCL_OBJ_GET_SIZE(arr) - 1);
hcl_seterrbfmt (hcl, HCL_EINVAL, "array index(%zu) out of bounds for array of size %zu", index, HCL_OBJ_GET_SIZE(arr));
return HCL_PF_FAILURE;
}