Skip to content

Commit fc55fbe

Browse files
committed
Initial hackery to create any/all keywords
1 parent e4606a9 commit fc55fbe

File tree

15 files changed

+401
-262
lines changed

15 files changed

+401
-262
lines changed

ext/Opcode/Opcode.pm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package Opcode 1.66;
1+
package Opcode 1.67;
22

33
use strict;
44

@@ -377,6 +377,7 @@ used to implement a resource attack (e.g., consume all available CPU time).
377377
378378
grepstart grepwhile
379379
mapstart mapwhile
380+
anystart allstart anywhile
380381
enteriter iter
381382
enterloop leaveloop unstack
382383
last next redo

gv.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,8 @@ S_maybe_add_coresub(pTHX_ HV * const stash, GV *gv,
610610
case KEY___DATA__: case KEY___END__ :
611611
case KEY_ADJUST : case KEY_AUTOLOAD: case KEY_BEGIN : case KEY_CHECK :
612612
case KEY_DESTROY : case KEY_END : case KEY_INIT : case KEY_UNITCHECK:
613-
case KEY_and : case KEY_catch : case KEY_class :
613+
case KEY_all : case KEY_and : case KEY_any :
614+
case KEY_catch : case KEY_class :
614615
case KEY_continue: case KEY_cmp : case KEY_defer :
615616
case KEY_do : case KEY_dump : case KEY_else : case KEY_elsif :
616617
case KEY_eq : case KEY_eval : case KEY_field :

lib/B/Deparse-core.t

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ while (<DATA>) {
232232

233233
# Special cases
234234

235+
testit any => 'CORE::any { $a } $b, $c', 'CORE::any({$a;} $b, $c);';
236+
testit all => 'CORE::all { $a } $b, $c', 'CORE::all({$a;} $b, $c);';
237+
235238
testit dbmopen => 'CORE::dbmopen(%foo, $bar, $baz);';
236239
testit dbmclose => 'CORE::dbmclose %foo;';
237240

lib/B/Deparse.pm

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# This is based on the module of the same name by Malcolm Beattie,
88
# but essentially none of his code remains.
99

10-
package B::Deparse 1.80;
10+
package B::Deparse 1.81;
1111
use strict;
1212
use Carp;
1313
use B qw(class main_root main_start main_cv svref_2object opnumber perlstring
@@ -2334,6 +2334,8 @@ my %feature_keywords = (
23342334
finally => 'try',
23352335
defer => 'defer',
23362336
signatures => 'signatures',
2337+
any => 'any_all',
2338+
all => 'any_all',
23372339
);
23382340

23392341
# keywords that are strong and also have a prototype
@@ -3637,9 +3639,10 @@ sub pp_sort { indirop(@_, "sort") }
36373639

36383640
sub mapop {
36393641
my $self = shift;
3640-
my($op, $cx, $name) = @_;
3642+
my($op, $cx) = @_;
36413643
my($expr, @exprs);
3642-
my $kid = $op->first; # this is the (map|grep)start
3644+
my $kid = $op->first; # this is the (map|grep\any|all)start
3645+
my ( $name ) = $kid->name =~ m/(.*)start/; # anystart and allstart share anywhile
36433646
$kid = $kid->first->sibling; # skip a pushmark
36443647
my $code = $kid->first; # skip a null
36453648
if (is_scope $code) {
@@ -3657,8 +3660,9 @@ sub mapop {
36573660
$code . join(", ", @exprs), $cx, 5);
36583661
}
36593662

3660-
sub pp_mapwhile { mapop(@_, "map") }
3661-
sub pp_grepwhile { mapop(@_, "grep") }
3663+
sub pp_mapwhile { mapop(@_) }
3664+
sub pp_grepwhile { mapop(@_) }
3665+
sub pp_anywhile { mapop(@_) }
36623666
sub pp_mapstart { baseop(@_, "map") }
36633667
sub pp_grepstart { baseop(@_, "grep") }
36643668

lib/B/Op_private.pm

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

op.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12050,8 +12050,16 @@ Constructs, checks, and returns a glob reference op.
1205012050
OP *
1205112051
Perl_newGVREF(pTHX_ I32 type, OP *o)
1205212052
{
12053-
if (type == OP_MAPSTART || type == OP_GREPSTART || type == OP_SORT)
12054-
return newUNOP(OP_NULL, 0, o);
12053+
switch(type) {
12054+
/* The thing that looks like a GVREF at the start of these operators
12055+
* isn't really */
12056+
case OP_MAPSTART:
12057+
case OP_GREPSTART:
12058+
case OP_SORT:
12059+
case OP_ANYSTART:
12060+
case OP_ALLSTART:
12061+
return newUNOP(OP_NULL, 0, o);
12062+
}
1205512063

1205612064
if (!FEATURE_BAREWORD_FILEHANDLES_IS_ENABLED &&
1205712065
((PL_opargs[type] >> OASHIFT) & 7) == OA_FILEREF &&
@@ -13192,7 +13200,10 @@ Perl_ck_grep(pTHX_ OP *o)
1319213200
{
1319313201
LOGOP *gwop;
1319413202
OP *kid;
13195-
const OPCODE type = o->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
13203+
const OPCODE type =
13204+
o->op_type == OP_GREPSTART ? OP_GREPWHILE :
13205+
o->op_type == OP_MAPSTART ? OP_MAPWHILE :
13206+
OP_ANYWHILE; /* any and all both share this */
1319613207

1319713208
PERL_ARGS_ASSERT_CK_GREP;
1319813209

opcode.h

Lines changed: 24 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)