Skip to content

Commit 98a092a

Browse files
committed
Add an OP_CATCH opcode
More efficiently handling catch conditional logic Also unit-test that false object exceptions are recognised correctly Also clear `$@` during catch {} blocks
1 parent a6b0bd3 commit 98a092a

File tree

12 files changed

+313
-269
lines changed

12 files changed

+313
-269
lines changed

ext/Opcode/Opcode.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use strict;
66

77
our($VERSION, @ISA, @EXPORT_OK);
88

9-
$VERSION = "1.49";
9+
$VERSION = "1.50";
1010

1111
use Carp;
1212
use Exporter ();
@@ -344,7 +344,7 @@ invert_opset function.
344344
345345
cond_expr flip flop andassign orassign dorassign and or dor xor
346346
347-
warn die lineseq nextstate scope enter leave
347+
warn die lineseq nextstate scope enter leave catch
348348
349349
rv2cv anoncode prototype coreargs avhvswitch anonconst
350350

lib/B/Op_private.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ $bits{backtick}{0} = $bf[0];
275275
@{$bits{bit_xor}}{1,0} = ($bf[1], $bf[1]);
276276
@{$bits{bless}}{3,2,1,0} = ($bf[4], $bf[4], $bf[4], $bf[4]);
277277
@{$bits{caller}}{3,2,1,0} = ($bf[4], $bf[4], $bf[4], $bf[4]);
278+
$bits{catch}{0} = $bf[0];
278279
@{$bits{chdir}}{3,2,1,0} = ($bf[4], $bf[4], $bf[4], $bf[4]);
279280
@{$bits{chmod}}{3,2,1,0} = ($bf[4], $bf[4], $bf[4], $bf[4]);
280281
$bits{chomp}{0} = $bf[0];

opcode.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ EXTCONST char* const PL_op_name[] = {
549549
"isa",
550550
"cmpchain_and",
551551
"cmpchain_dup",
552+
"catch",
552553
"freed",
553554
};
554555
#endif
@@ -957,6 +958,7 @@ EXTCONST char* const PL_op_desc[] = {
957958
"derived class test",
958959
"comparison chaining",
959960
"comparand shuffling",
961+
"catch {} block",
960962
"freed op",
961963
};
962964
#endif
@@ -1368,6 +1370,7 @@ EXT Perl_ppaddr_t PL_ppaddr[] /* or perlvars.h */
13681370
Perl_pp_isa,
13691371
Perl_pp_cmpchain_and,
13701372
Perl_pp_cmpchain_dup,
1373+
Perl_pp_catch,
13711374
}
13721375
#endif
13731376
;
@@ -1775,6 +1778,7 @@ EXT Perl_check_t PL_check[] /* or perlvars.h */
17751778
Perl_ck_isa, /* isa */
17761779
Perl_ck_null, /* cmpchain_and */
17771780
Perl_ck_null, /* cmpchain_dup */
1781+
Perl_ck_null, /* catch */
17781782
}
17791783
#endif
17801784
;
@@ -2183,6 +2187,7 @@ EXTCONST U32 PL_opargs[] = {
21832187
0x00000204, /* isa */
21842188
0x00000300, /* cmpchain_and */
21852189
0x00000100, /* cmpchain_dup */
2190+
0x00000300, /* catch */
21862191
};
21872192
#endif
21882193

@@ -2850,6 +2855,7 @@ EXTCONST I16 PL_op_private_bitdef_ix[] = {
28502855
12, /* isa */
28512856
0, /* cmpchain_and */
28522857
0, /* cmpchain_dup */
2858+
0, /* catch */
28532859

28542860
};
28552861

@@ -2868,7 +2874,7 @@ EXTCONST I16 PL_op_private_bitdef_ix[] = {
28682874
*/
28692875

28702876
EXTCONST U16 PL_op_private_bitdefs[] = {
2871-
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, entergiven, 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, cmpchain_and, cmpchain_dup */
2877+
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, entergiven, 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, cmpchain_and, cmpchain_dup, catch */
28722878
0x2fdc, 0x41b9, /* pushmark */
28732879
0x00bd, /* wantarray, runcv */
28742880
0x0438, 0x1a50, 0x426c, 0x3d28, 0x3505, /* const */
@@ -3346,6 +3352,7 @@ EXTCONST U8 PL_op_private_valid[] = {
33463352
/* ISA */ (OPpARG2_MASK),
33473353
/* CMPCHAIN_AND */ (OPpARG1_MASK),
33483354
/* CMPCHAIN_DUP */ (OPpARG1_MASK),
3355+
/* CATCH */ (OPpARG1_MASK),
33493356

33503357
};
33513358

opnames.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,11 @@ typedef enum opcode {
414414
OP_ISA = 397,
415415
OP_CMPCHAIN_AND = 398,
416416
OP_CMPCHAIN_DUP = 399,
417+
OP_CATCH = 400,
417418
OP_max
418419
} opcode;
419420

420-
#define MAXO 400
421+
#define MAXO 401
421422
#define OP_FREED MAXO
422423

423424
/* the OP_IS_* macros are optimized to a simple range check because

0 commit comments

Comments
 (0)