merge leavegiven op type into leaveloop

The leaveloop op type can already do the whole job, with leavegiven being
a near duplicate of it.  Replace all uses of leavegiven with leaveloop.
This commit is contained in:
Zefram 2017-12-05 21:24:19 +00:00
parent 40b0df696c
commit 16ea2c1905
9 changed files with 193 additions and 230 deletions

View File

@ -426,7 +426,7 @@ These are a hotchpotch of opcodes still waiting to be considered
entertry leavetry -- can be used to 'hide' fatal errors
entergiven leavegiven
entergiven
enterwhen leavewhen
continue
smartmatch

View File

@ -2539,23 +2539,16 @@ sub pp_lock { unop(@_, "lock") }
sub pp_continue { unop(@_, "continue"); }
sub givwhen {
my $self = shift;
my($op, $cx, $givwhen) = @_;
sub pp_leavewhen {
my($self, $op, $cx) = @_;
my $when = $self->keyword("when");
my $enterop = $op->first;
my $cond = $enterop->first;
my $cond_str = $self->deparse($cond, 1);
my $block = $self->deparse($cond->sibling, 0);
return "$givwhen ($cond_str) {\n".
"\t$block\n".
"\b}\cK";
return "$when ($cond_str) {\n\t$block\n\b}\cK";
}
sub pp_leavegiven { givwhen(@_, $_[0]->keyword("given")); }
sub pp_leavewhen { givwhen(@_, $_[0]->keyword("when")); }
sub pp_exists {
my $self = shift;
my($op, $cx) = @_;
@ -3792,6 +3785,13 @@ sub loop_common {
$bare = 1;
}
$body = $kid;
} elsif ($enter->name eq "entergiven") { # given
my $given = $self->keyword("given");
my $enterop = $op->first;
my $topic = $enterop->first;
my $topic_str = $self->deparse($topic, 1);
my $block = $self->deparse($topic->sibling, 0);
return "$given ($topic_str) {\n\t$block\n\b}\cK";
} elsif ($enter->name eq "enteriter") { # foreach
my $ary = $enter->first->sibling; # first was pushmark
my $var = $ary->sibling;

View File

@ -405,7 +405,6 @@ $bits{lc}{0} = $bf[0];
$bits{lcfirst}{0} = $bf[0];
@{$bits{le}}{1,0} = ($bf[1], $bf[1]);
$bits{leaveeval}{0} = $bf[0];
$bits{leavegiven}{0} = $bf[0];
@{$bits{leaveloop}}{1,0} = ($bf[1], $bf[1]);
$bits{leavesub}{0} = $bf[0];
$bits{leavesublv}{0} = $bf[0];

3
op.c
View File

@ -2210,7 +2210,6 @@ Perl_scalarvoid(pTHX_ OP *arg)
case OP_LEAVETRY:
case OP_LEAVELOOP:
case OP_LINESEQ:
case OP_LEAVEGIVEN:
case OP_LEAVEWHEN:
kids:
for (kid = cLISTOPo->op_first; kid; kid = OpSIBLING(kid))
@ -8776,7 +8775,7 @@ Perl_newGIVENOP(pTHX_ OP *cond, OP *block, PADOFFSET defsv_off)
OpLASTSIB_set(block, enterop);
enterop->op_flags = OPf_KIDS;
leaveop = newUNOP(OP_LEAVEGIVEN, 0, enterop);
leaveop = newBINOP(OP_LEAVELOOP, 0, enterop, newOP(OP_NULL, 0));
leaveop->op_next = LINKLIST(cond);
cond->op_next = enterop;
enterop = CHECKOP(OP_ENTERGIVEN, enterop);

View File

@ -364,7 +364,6 @@ EXTCONST char* const PL_op_name[] = {
"method_redir",
"method_redir_super",
"entergiven",
"leavegiven",
"enterwhen",
"leavewhen",
"continue",
@ -768,7 +767,6 @@ EXTCONST char* const PL_op_desc[] = {
"redirect method with known name",
"redirect super method with known name",
"given()",
"leave given block",
"when()",
"leave when block",
"continue",
@ -1184,7 +1182,6 @@ EXT Perl_ppaddr_t PL_ppaddr[] /* or perlvars.h */
Perl_pp_method_redir,
Perl_pp_method_redir_super,
Perl_pp_entergiven,
Perl_pp_leavegiven,
Perl_pp_enterwhen,
Perl_pp_leavewhen,
Perl_pp_continue,
@ -1596,7 +1593,6 @@ EXT Perl_check_t PL_check[] /* or perlvars.h */
Perl_ck_null, /* method_redir */
Perl_ck_null, /* method_redir_super */
Perl_ck_null, /* entergiven */
Perl_ck_null, /* leavegiven */
Perl_ck_null, /* enterwhen */
Perl_ck_null, /* leavewhen */
Perl_ck_null, /* continue */
@ -2004,7 +2000,6 @@ EXTCONST U32 PL_opargs[] = {
0x00000e40, /* method_redir */
0x00000e40, /* method_redir_super */
0x00000940, /* entergiven */
0x00000100, /* leavegiven */
0x00000340, /* enterwhen */
0x00000100, /* leavewhen */
0x00000000, /* continue */
@ -2667,7 +2662,6 @@ EXTCONST I16 PL_op_private_bitdef_ix[] = {
0, /* method_redir */
0, /* method_redir_super */
-1, /* entergiven */
0, /* leavegiven */
0, /* enterwhen */
0, /* leavewhen */
-1, /* continue */
@ -2863,7 +2857,7 @@ EXTCONST I16 PL_op_private_bitdef_ix[] = {
*/
EXTCONST U16 PL_op_private_bitdefs[] = {
0x0003, /* scalar, prototype, refgen, srefgen, readline, regcmaybe, regcreset, regcomp, substcont, chop, schop, defined, undef, study, preinc, i_preinc, predec, i_predec, postinc, i_postinc, postdec, i_postdec, negate, i_negate, not, complement, ucfirst, lcfirst, uc, lc, quotemeta, aeach, avalues, each, pop, shift, grepstart, mapstart, mapwhile, range, and, or, dor, andassign, orassign, dorassign, argcheck, argdefelem, method, method_named, method_super, method_redir, method_redir_super, leavegiven, enterwhen, leavewhen, untie, tied, dbmclose, getsockname, getpeername, lstat, stat, readlink, readdir, telldir, rewinddir, closedir, localtime, alarm, require, dofile, entertry, ghbyname, gnbyname, gpbyname, shostent, snetent, sprotoent, sservent, gpwnam, gpwuid, ggrnam, ggrgid, lock, once, fc, anonconst */
0x0003, /* scalar, prototype, refgen, srefgen, readline, regcmaybe, regcreset, regcomp, substcont, chop, schop, defined, undef, study, preinc, i_preinc, predec, i_predec, postinc, i_postinc, postdec, i_postdec, negate, i_negate, not, complement, ucfirst, lcfirst, uc, lc, quotemeta, aeach, avalues, each, pop, shift, grepstart, mapstart, mapwhile, range, and, or, dor, andassign, orassign, dorassign, argcheck, argdefelem, method, method_named, method_super, method_redir, method_redir_super, enterwhen, leavewhen, untie, tied, dbmclose, getsockname, getpeername, lstat, stat, readlink, readdir, telldir, rewinddir, closedir, localtime, alarm, require, dofile, entertry, ghbyname, gnbyname, gpbyname, shostent, snetent, sprotoent, sservent, gpwnam, gpwuid, ggrnam, ggrgid, lock, once, fc, anonconst */
0x2ebc, 0x3fb9, /* pushmark */
0x00bd, /* wantarray, runcv */
0x0578, 0x1930, 0x406c, 0x3b28, 0x3305, /* const */
@ -3158,7 +3152,6 @@ EXTCONST U8 PL_op_private_valid[] = {
/* METHOD_REDIR */ (OPpARG1_MASK),
/* METHOD_REDIR_SUPER */ (OPpARG1_MASK),
/* ENTERGIVEN */ (0),
/* LEAVEGIVEN */ (OPpARG1_MASK),
/* ENTERWHEN */ (OPpARG1_MASK),
/* LEAVEWHEN */ (OPpARG1_MASK),
/* CONTINUE */ (0),

357
opnames.h
View File

@ -232,188 +232,187 @@ typedef enum opcode {
OP_METHOD_REDIR = 215,
OP_METHOD_REDIR_SUPER = 216,
OP_ENTERGIVEN = 217,
OP_LEAVEGIVEN = 218,
OP_ENTERWHEN = 219,
OP_LEAVEWHEN = 220,
OP_CONTINUE = 221,
OP_OPEN = 222,
OP_CLOSE = 223,
OP_PIPE_OP = 224,
OP_FILENO = 225,
OP_UMASK = 226,
OP_BINMODE = 227,
OP_TIE = 228,
OP_UNTIE = 229,
OP_TIED = 230,
OP_DBMOPEN = 231,
OP_DBMCLOSE = 232,
OP_SSELECT = 233,
OP_SELECT = 234,
OP_GETC = 235,
OP_READ = 236,
OP_ENTERWRITE = 237,
OP_LEAVEWRITE = 238,
OP_PRTF = 239,
OP_PRINT = 240,
OP_SAY = 241,
OP_SYSOPEN = 242,
OP_SYSSEEK = 243,
OP_SYSREAD = 244,
OP_SYSWRITE = 245,
OP_EOF = 246,
OP_TELL = 247,
OP_SEEK = 248,
OP_TRUNCATE = 249,
OP_FCNTL = 250,
OP_IOCTL = 251,
OP_FLOCK = 252,
OP_SEND = 253,
OP_RECV = 254,
OP_SOCKET = 255,
OP_SOCKPAIR = 256,
OP_BIND = 257,
OP_CONNECT = 258,
OP_LISTEN = 259,
OP_ACCEPT = 260,
OP_SHUTDOWN = 261,
OP_GSOCKOPT = 262,
OP_SSOCKOPT = 263,
OP_GETSOCKNAME = 264,
OP_GETPEERNAME = 265,
OP_LSTAT = 266,
OP_STAT = 267,
OP_FTRREAD = 268,
OP_FTRWRITE = 269,
OP_FTREXEC = 270,
OP_FTEREAD = 271,
OP_FTEWRITE = 272,
OP_FTEEXEC = 273,
OP_FTIS = 274,
OP_FTSIZE = 275,
OP_FTMTIME = 276,
OP_FTATIME = 277,
OP_FTCTIME = 278,
OP_FTROWNED = 279,
OP_FTEOWNED = 280,
OP_FTZERO = 281,
OP_FTSOCK = 282,
OP_FTCHR = 283,
OP_FTBLK = 284,
OP_FTFILE = 285,
OP_FTDIR = 286,
OP_FTPIPE = 287,
OP_FTSUID = 288,
OP_FTSGID = 289,
OP_FTSVTX = 290,
OP_FTLINK = 291,
OP_FTTTY = 292,
OP_FTTEXT = 293,
OP_FTBINARY = 294,
OP_CHDIR = 295,
OP_CHOWN = 296,
OP_CHROOT = 297,
OP_UNLINK = 298,
OP_CHMOD = 299,
OP_UTIME = 300,
OP_RENAME = 301,
OP_LINK = 302,
OP_SYMLINK = 303,
OP_READLINK = 304,
OP_MKDIR = 305,
OP_RMDIR = 306,
OP_OPEN_DIR = 307,
OP_READDIR = 308,
OP_TELLDIR = 309,
OP_SEEKDIR = 310,
OP_REWINDDIR = 311,
OP_CLOSEDIR = 312,
OP_FORK = 313,
OP_WAIT = 314,
OP_WAITPID = 315,
OP_SYSTEM = 316,
OP_EXEC = 317,
OP_KILL = 318,
OP_GETPPID = 319,
OP_GETPGRP = 320,
OP_SETPGRP = 321,
OP_GETPRIORITY = 322,
OP_SETPRIORITY = 323,
OP_TIME = 324,
OP_TMS = 325,
OP_LOCALTIME = 326,
OP_GMTIME = 327,
OP_ALARM = 328,
OP_SLEEP = 329,
OP_SHMGET = 330,
OP_SHMCTL = 331,
OP_SHMREAD = 332,
OP_SHMWRITE = 333,
OP_MSGGET = 334,
OP_MSGCTL = 335,
OP_MSGSND = 336,
OP_MSGRCV = 337,
OP_SEMOP = 338,
OP_SEMGET = 339,
OP_SEMCTL = 340,
OP_REQUIRE = 341,
OP_DOFILE = 342,
OP_HINTSEVAL = 343,
OP_ENTEREVAL = 344,
OP_LEAVEEVAL = 345,
OP_ENTERTRY = 346,
OP_LEAVETRY = 347,
OP_GHBYNAME = 348,
OP_GHBYADDR = 349,
OP_GHOSTENT = 350,
OP_GNBYNAME = 351,
OP_GNBYADDR = 352,
OP_GNETENT = 353,
OP_GPBYNAME = 354,
OP_GPBYNUMBER = 355,
OP_GPROTOENT = 356,
OP_GSBYNAME = 357,
OP_GSBYPORT = 358,
OP_GSERVENT = 359,
OP_SHOSTENT = 360,
OP_SNETENT = 361,
OP_SPROTOENT = 362,
OP_SSERVENT = 363,
OP_EHOSTENT = 364,
OP_ENETENT = 365,
OP_EPROTOENT = 366,
OP_ESERVENT = 367,
OP_GPWNAM = 368,
OP_GPWUID = 369,
OP_GPWENT = 370,
OP_SPWENT = 371,
OP_EPWENT = 372,
OP_GGRNAM = 373,
OP_GGRGID = 374,
OP_GGRENT = 375,
OP_SGRENT = 376,
OP_EGRENT = 377,
OP_GETLOGIN = 378,
OP_SYSCALL = 379,
OP_LOCK = 380,
OP_ONCE = 381,
OP_CUSTOM = 382,
OP_COREARGS = 383,
OP_AVHVSWITCH = 384,
OP_RUNCV = 385,
OP_FC = 386,
OP_PADCV = 387,
OP_INTROCV = 388,
OP_CLONECV = 389,
OP_PADRANGE = 390,
OP_REFASSIGN = 391,
OP_LVREF = 392,
OP_LVREFSLICE = 393,
OP_LVAVREF = 394,
OP_ANONCONST = 395,
OP_ENTERWHEN = 218,
OP_LEAVEWHEN = 219,
OP_CONTINUE = 220,
OP_OPEN = 221,
OP_CLOSE = 222,
OP_PIPE_OP = 223,
OP_FILENO = 224,
OP_UMASK = 225,
OP_BINMODE = 226,
OP_TIE = 227,
OP_UNTIE = 228,
OP_TIED = 229,
OP_DBMOPEN = 230,
OP_DBMCLOSE = 231,
OP_SSELECT = 232,
OP_SELECT = 233,
OP_GETC = 234,
OP_READ = 235,
OP_ENTERWRITE = 236,
OP_LEAVEWRITE = 237,
OP_PRTF = 238,
OP_PRINT = 239,
OP_SAY = 240,
OP_SYSOPEN = 241,
OP_SYSSEEK = 242,
OP_SYSREAD = 243,
OP_SYSWRITE = 244,
OP_EOF = 245,
OP_TELL = 246,
OP_SEEK = 247,
OP_TRUNCATE = 248,
OP_FCNTL = 249,
OP_IOCTL = 250,
OP_FLOCK = 251,
OP_SEND = 252,
OP_RECV = 253,
OP_SOCKET = 254,
OP_SOCKPAIR = 255,
OP_BIND = 256,
OP_CONNECT = 257,
OP_LISTEN = 258,
OP_ACCEPT = 259,
OP_SHUTDOWN = 260,
OP_GSOCKOPT = 261,
OP_SSOCKOPT = 262,
OP_GETSOCKNAME = 263,
OP_GETPEERNAME = 264,
OP_LSTAT = 265,
OP_STAT = 266,
OP_FTRREAD = 267,
OP_FTRWRITE = 268,
OP_FTREXEC = 269,
OP_FTEREAD = 270,
OP_FTEWRITE = 271,
OP_FTEEXEC = 272,
OP_FTIS = 273,
OP_FTSIZE = 274,
OP_FTMTIME = 275,
OP_FTATIME = 276,
OP_FTCTIME = 277,
OP_FTROWNED = 278,
OP_FTEOWNED = 279,
OP_FTZERO = 280,
OP_FTSOCK = 281,
OP_FTCHR = 282,
OP_FTBLK = 283,
OP_FTFILE = 284,
OP_FTDIR = 285,
OP_FTPIPE = 286,
OP_FTSUID = 287,
OP_FTSGID = 288,
OP_FTSVTX = 289,
OP_FTLINK = 290,
OP_FTTTY = 291,
OP_FTTEXT = 292,
OP_FTBINARY = 293,
OP_CHDIR = 294,
OP_CHOWN = 295,
OP_CHROOT = 296,
OP_UNLINK = 297,
OP_CHMOD = 298,
OP_UTIME = 299,
OP_RENAME = 300,
OP_LINK = 301,
OP_SYMLINK = 302,
OP_READLINK = 303,
OP_MKDIR = 304,
OP_RMDIR = 305,
OP_OPEN_DIR = 306,
OP_READDIR = 307,
OP_TELLDIR = 308,
OP_SEEKDIR = 309,
OP_REWINDDIR = 310,
OP_CLOSEDIR = 311,
OP_FORK = 312,
OP_WAIT = 313,
OP_WAITPID = 314,
OP_SYSTEM = 315,
OP_EXEC = 316,
OP_KILL = 317,
OP_GETPPID = 318,
OP_GETPGRP = 319,
OP_SETPGRP = 320,
OP_GETPRIORITY = 321,
OP_SETPRIORITY = 322,
OP_TIME = 323,
OP_TMS = 324,
OP_LOCALTIME = 325,
OP_GMTIME = 326,
OP_ALARM = 327,
OP_SLEEP = 328,
OP_SHMGET = 329,
OP_SHMCTL = 330,
OP_SHMREAD = 331,
OP_SHMWRITE = 332,
OP_MSGGET = 333,
OP_MSGCTL = 334,
OP_MSGSND = 335,
OP_MSGRCV = 336,
OP_SEMOP = 337,
OP_SEMGET = 338,
OP_SEMCTL = 339,
OP_REQUIRE = 340,
OP_DOFILE = 341,
OP_HINTSEVAL = 342,
OP_ENTEREVAL = 343,
OP_LEAVEEVAL = 344,
OP_ENTERTRY = 345,
OP_LEAVETRY = 346,
OP_GHBYNAME = 347,
OP_GHBYADDR = 348,
OP_GHOSTENT = 349,
OP_GNBYNAME = 350,
OP_GNBYADDR = 351,
OP_GNETENT = 352,
OP_GPBYNAME = 353,
OP_GPBYNUMBER = 354,
OP_GPROTOENT = 355,
OP_GSBYNAME = 356,
OP_GSBYPORT = 357,
OP_GSERVENT = 358,
OP_SHOSTENT = 359,
OP_SNETENT = 360,
OP_SPROTOENT = 361,
OP_SSERVENT = 362,
OP_EHOSTENT = 363,
OP_ENETENT = 364,
OP_EPROTOENT = 365,
OP_ESERVENT = 366,
OP_GPWNAM = 367,
OP_GPWUID = 368,
OP_GPWENT = 369,
OP_SPWENT = 370,
OP_EPWENT = 371,
OP_GGRNAM = 372,
OP_GGRGID = 373,
OP_GGRENT = 374,
OP_SGRENT = 375,
OP_EGRENT = 376,
OP_GETLOGIN = 377,
OP_SYSCALL = 378,
OP_LOCK = 379,
OP_ONCE = 380,
OP_CUSTOM = 381,
OP_COREARGS = 382,
OP_AVHVSWITCH = 383,
OP_RUNCV = 384,
OP_FC = 385,
OP_PADCV = 386,
OP_INTROCV = 387,
OP_CLONECV = 388,
OP_PADRANGE = 389,
OP_REFASSIGN = 390,
OP_LVREF = 391,
OP_LVREFSLICE = 392,
OP_LVAVREF = 393,
OP_ANONCONST = 394,
OP_max
} opcode;
#define MAXO 396
#define MAXO 395
#define OP_FREED MAXO
/* the OP_IS_* macros are optimized to a simple range check because

View File

@ -4571,31 +4571,6 @@ PP(pp_entergiven)
RETURN;
}
PP(pp_leavegiven)
{
PERL_CONTEXT *cx;
U8 gimme;
SV **oldsp;
PERL_UNUSED_CONTEXT;
cx = CX_CUR();
assert(CxTYPE(cx) == CXt_LOOP_GIVEN);
oldsp = PL_stack_base + cx->blk_oldsp;
gimme = cx->blk_gimme;
if (gimme == G_VOID)
PL_stack_sp = oldsp;
else
leave_adjust_stacks(oldsp, oldsp, gimme, 1);
CX_LEAVE_SCOPE(cx);
cx_poploop(cx);
cx_popblock(cx);
CX_POP(cx);
return NORMAL;
}
PP(pp_smartmatch)
{
dSP;
@ -4676,7 +4651,7 @@ PP(pp_leavewhen)
}
else {
PERL_ASYNC_CHECK();
assert(cx->blk_loop.my_op->op_nextop->op_type == OP_LEAVEGIVEN);
assert(cx->blk_loop.my_op->op_nextop->op_type == OP_LEAVELOOP);
return cx->blk_loop.my_op->op_nextop;
}
}

View File

@ -134,7 +134,6 @@ PERL_CALLCONV OP *Perl_pp_lc(pTHX);
PERL_CALLCONV OP *Perl_pp_le(pTHX);
PERL_CALLCONV OP *Perl_pp_leave(pTHX);
PERL_CALLCONV OP *Perl_pp_leaveeval(pTHX);
PERL_CALLCONV OP *Perl_pp_leavegiven(pTHX);
PERL_CALLCONV OP *Perl_pp_leaveloop(pTHX);
PERL_CALLCONV OP *Perl_pp_leavesub(pTHX);
PERL_CALLCONV OP *Perl_pp_leavesublv(pTHX);

View File

@ -329,7 +329,6 @@ method_redir redirect method with known name ck_null d.
method_redir_super redirect super method with known name ck_null d.
entergiven given() ck_null d{
leavegiven leave given block ck_null 1
enterwhen when() ck_null d|
leavewhen leave when block ck_null 1
continue continue ck_null 0