Skip to content

Commit f8ecfa6

Browse files
committed
Implement named parameters in signatures (PPC0024)
This adds a major new ability to subroutine signatures, allowing callers to pass parameters by name/value pairs rather than by position. sub f ($x, $y, :$alpha, :$beta = undef) { ... } f( 123, 456, alpha => 789 ); Originally specified in https://github.com/Perl/PPCs/blob/main/ppcs/ppc0024-signature-named-parameters.md This feature is currently considered experimental.
1 parent 147d5f1 commit f8ecfa6

File tree

21 files changed

+2027
-1439
lines changed

21 files changed

+2027
-1439
lines changed

dump.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,6 +1804,11 @@ S_do_op_dump_bar(pTHX_ I32 level, UV bar, PerlIO *file, const OP *o,
18041804
S_opdump_indent(aTHX_ o, level, bar, file, " PARAM [%zd] ANON\n",
18051805
i);
18061806
}
1807+
for(size_t i = 0; i < aux->n_named; i++) {
1808+
struct op_multiparam_named_aux *named = aux->named + i;
1809+
S_opdump_indent(aTHX_ o, level, bar, file, " NAMEDPARAM <%.*s> PADIX = %" UVuf "%s\n",
1810+
named->namelen, named->namepv, named->padix, named->is_required ? "" : " OPT");
1811+
}
18071812

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

embed.fnc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3209,6 +3209,11 @@ p |void |sub_crush_depth|NN CV *cv
32093209
: Used in perly.y
32103210
p |void |subsignature_append_fence_op \
32113211
|NN OP *o
3212+
p |void |subsignature_append_named \
3213+
|NN const char *paramname \
3214+
|PADOFFSET padix \
3215+
|OPCODE defmode \
3216+
|NULLOK OP *defexpr
32123217
p |void |subsignature_append_positional \
32133218
|PADOFFSET padix \
32143219
|OPCODE defmode \

embed.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,7 @@
11631163
# define sighandler3 Perl_sighandler3
11641164
# define sub_crush_depth(a) Perl_sub_crush_depth(aTHX_ a)
11651165
# define subsignature_append_fence_op(a) Perl_subsignature_append_fence_op(aTHX_ a)
1166+
# define subsignature_append_named(a,b,c,d) Perl_subsignature_append_named(aTHX_ a,b,c,d)
11661167
# define subsignature_append_positional(a,b,c) Perl_subsignature_append_positional(aTHX_ a,b,c)
11671168
# define subsignature_append_slurpy(a,b) Perl_subsignature_append_slurpy(aTHX_ a,b)
11681169
# define subsignature_finish() Perl_subsignature_finish(aTHX)

lib/warnings.pm

Lines changed: 172 additions & 165 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)