Skip to content

Commit

Permalink
Initial progress at OP_MULTIPARAM
Browse files Browse the repository at this point in the history
An initial attempt at implementing OP_MULTIPARAM by rewriting arg ops.
Handles mandatory, optional, and slurpy params.

Implement optional parameters with OP_PARAMTEST and OP_PARAMSTORE; use
the same SvPADSTALE flag trick that XS-Parse-Sublike uses
  • Loading branch information
leonerd committed Dec 4, 2024
1 parent 70f1c38 commit 401d481
Show file tree
Hide file tree
Showing 9 changed files with 613 additions and 8 deletions.
30 changes: 30 additions & 0 deletions dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,7 @@ S_do_op_dump_bar(pTHX_ I32 level, UV bar, PerlIO *file, const OP *o)
case OP_ARGDEFELEM:
case OP_ENTERTRY:
case OP_ONCE:
case OP_PARAMTEST:
S_opdump_indent(aTHX_ o, level, bar, file, "OTHER");
S_opdump_link(aTHX_ o, cLOGOPo->op_other, file);
break;
Expand Down Expand Up @@ -1563,6 +1564,35 @@ S_do_op_dump_bar(pTHX_ I32 level, UV bar, PerlIO *file, const OP *o)
break;
}

case OP_MULTIPARAM:
{
struct op_multiparam_aux *aux = (struct op_multiparam_aux *)cUNOP_AUXo->op_aux;
UV nparams = aux->params;
UV nparams_mandatory = nparams - aux->opt_params;
if(aux->opt_params)
S_opdump_indent(aTHX_ o, level, bar, file, "PARAMS = %" UVuf " .. %" UVuf "\n",
nparams - aux->opt_params, nparams);
else
S_opdump_indent(aTHX_ o, level, bar, file, "PARAMS = %" UVuf "\n",
nparams);

for(Size_t i = 0; i < nparams; i++) {
PADOFFSET padix = aux->param_padix[i];
if(padix)
S_opdump_indent(aTHX_ o, level, bar, file, " PARAM [%zd] PADIX = %" UVuf "%s\n",
i, aux->param_padix[i], i >= nparams_mandatory ? " OPT" : "");
else
S_opdump_indent(aTHX_ o, level, bar, file, " PARAM [%zd] ANON\n",
i);
}

if(aux->slurpy)
S_opdump_indent(aTHX_ o, level, bar, file, "SLURPY = '%c' PADIX = %" UVuf "\n",
aux->slurpy, aux->slurpy_padix);

break;
}

case OP_CUSTOM:
{
void (*custom_dumper)(pTHX_ const OP *o, struct Perl_OpDumpContext *ctx) =
Expand Down
8 changes: 7 additions & 1 deletion lib/B/Op_private.pm

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions op.h
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,16 @@ struct op_argcheck_aux {
char slurpy; /* presence of slurpy: may be '\0', '@' or '%' */
};

/* for OP_MULTIPARAM */

struct op_multiparam_aux {
UV params;
UV opt_params;
char slurpy;
PADOFFSET *param_padix; /* points at storage allocated along with the struct itself, immediately following */
PADOFFSET slurpy_padix;
};

#define MI_INIT_WORKAROUND_PACK "Module::Install::DSL"


Expand Down
10 changes: 6 additions & 4 deletions opcode.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 401d481

Please sign in to comment.