Skip to content

Commit 28cb54b

Browse files
committed
Add a subsignature_append_fence_op()
A "fence op" is a miscellaneous op fragment that performs some work for side-effects during processing of a subroutine signature. In terms of timing, it will run at some time after any previously-defined arguments have been assigned from argument values passed in by the caller, but before any defaulting expressions for parameters that come after it are run. We specifically make no guarantees about whether parameters defined after this op have had their values assigned, nor whether defaulting expressions of earlier parameters have already been invoked. This is intentional because upcoming changes will change the order of these. The intention here is that method subroutines will use a fence op for the `OP_METHSTART` behaviour, ensuring that subsequent defaulting expressions can see the values of field bindings established by processing the `$self` parameter.
1 parent 03d4dc5 commit 28cb54b

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

embed.fnc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3110,6 +3110,8 @@ CRp |NV |str_to_version |NN SV *sv
31103110
: Used in pp_ctl.c
31113111
p |void |sub_crush_depth|NN CV *cv
31123112
: Used in perly.y
3113+
p |void |subsignature_append_fence_op \
3114+
|NN OP *o
31133115
p |void |subsignature_append_positional \
31143116
|PADOFFSET padix \
31153117
|OPCODE defmode \

embed.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,7 @@
11621162
# define sighandler1 Perl_sighandler1
11631163
# define sighandler3 Perl_sighandler3
11641164
# define sub_crush_depth(a) Perl_sub_crush_depth(aTHX_ a)
1165+
# define subsignature_append_fence_op(a) Perl_subsignature_append_fence_op(aTHX_ a)
11651166
# define subsignature_append_positional(a,b,c) Perl_subsignature_append_positional(aTHX_ a,b,c)
11661167
# define subsignature_append_slurpy(a,b) Perl_subsignature_append_slurpy(aTHX_ a,b)
11671168
# define subsignature_finish() Perl_subsignature_finish(aTHX)

op.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16479,7 +16479,7 @@ struct yy_parser_signature {
1647916479
UV elems; /* number of signature elements seen so far */
1648016480
UV optelems; /* number of optional signature elems seen */
1648116481
char slurpy; /* the sigil of the slurpy var (or null) */
16482-
OP *elemops; /* NULL, or an OP_LINESEQ of individual element ops */
16482+
OP *elemops; /* NULL, or an OP_LINESEQ of individual element and fence ops */
1648316483
};
1648416484

1648516485
static void
@@ -16518,6 +16518,24 @@ Perl_subsignature_start(pTHX)
1651816518
PL_parser->signature = signature;
1651916519
}
1652016520

16521+
/* Appends another arbitrary optree into the accumulated set of signature-
16522+
* handling ops. This op will be invoked at some time after all of the
16523+
* parameters already present have received their values, but before any of
16524+
* the defaulting expressions for later parameters are executed.
16525+
*/
16526+
16527+
void
16528+
Perl_subsignature_append_fence_op(pTHX_ OP *o)
16529+
{
16530+
PERL_ARGS_ASSERT_SUBSIGNATURE_APPEND_FENCE_OP;
16531+
assert(PL_parser);
16532+
yy_parser_signature *signature = PL_parser->signature;
16533+
assert(signature);
16534+
16535+
signature->elemops = op_append_elem(OP_LINESEQ, signature->elemops,
16536+
o);
16537+
}
16538+
1652116539
/* Appends another positional scalar parameter to the accumulated set of
1652216540
* subroutine params. `padix` may be zero, but if not it must be the pad
1652316541
* index of a scalar pad lexical to store the incoming argument value into.

proto.h

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

0 commit comments

Comments
 (0)