diff options
author | Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> | 2021-01-22 17:57:08 +0000 |
---|---|---|
committer | Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> | 2021-02-04 14:20:53 +0000 |
commit | a1325b902d57aa7a99bed3d2ec0fa5ce42836207 (patch) | |
tree | 37ce967cbad3faa9d65d10d33aab6919ec353616 /lib | |
parent | 99dbf64538ee1c097b9f7e93df5a45dbf1fa3e22 (diff) | |
download | perl-a1325b902d57aa7a99bed3d2ec0fa5ce42836207.tar.gz |
Initial attempt at feature 'try'
* Add feature, experimental warning, keyword
* Basic parsing
* Basic implementation as optree fragment
See also
https://github.com/Perl/perl5/issues/18504
Diffstat (limited to 'lib')
-rw-r--r-- | lib/B/Deparse-core.t | 2 | ||||
-rw-r--r-- | lib/B/Deparse.pm | 4 | ||||
-rw-r--r-- | lib/B/Op_private.pm | 1 | ||||
-rw-r--r-- | lib/feature.pm | 13 | ||||
-rw-r--r-- | lib/warnings.pm | 15 |
5 files changed, 28 insertions, 7 deletions
diff --git a/lib/B/Deparse-core.t b/lib/B/Deparse-core.t index cdbd27ce5e..9d891a7507 100644 --- a/lib/B/Deparse-core.t +++ b/lib/B/Deparse-core.t @@ -362,6 +362,7 @@ my %not_tested = map { $_ => 1} qw( END INIT UNITCHECK + catch default else elsif @@ -381,6 +382,7 @@ my %not_tested = map { $_ => 1} qw( require s tr + try unless until use diff --git a/lib/B/Deparse.pm b/lib/B/Deparse.pm index 2317aa1498..96d569acb9 100644 --- a/lib/B/Deparse.pm +++ b/lib/B/Deparse.pm @@ -52,7 +52,7 @@ use B qw(class main_root main_start main_cv svref_2object opnumber perlstring MDEREF_SHIFT ); -$VERSION = '1.55'; +$VERSION = '1.56'; use strict; our $AUTOLOAD; use warnings (); @@ -2304,6 +2304,8 @@ my %feature_keywords = ( evalbytes=>'evalbytes', __SUB__ => '__SUB__', fc => 'fc', + try => 'try', + catch => 'try', ); # keywords that are strong and also have a prototype diff --git a/lib/B/Op_private.pm b/lib/B/Op_private.pm index a3666a7181..480dac69a0 100644 --- a/lib/B/Op_private.pm +++ b/lib/B/Op_private.pm @@ -275,6 +275,7 @@ $bits{backtick}{0} = $bf[0]; @{$bits{bit_xor}}{1,0} = ($bf[1], $bf[1]); @{$bits{bless}}{3,2,1,0} = ($bf[4], $bf[4], $bf[4], $bf[4]); @{$bits{caller}}{3,2,1,0} = ($bf[4], $bf[4], $bf[4], $bf[4]); +$bits{catch}{0} = $bf[0]; @{$bits{chdir}}{3,2,1,0} = ($bf[4], $bf[4], $bf[4], $bf[4]); @{$bits{chmod}}{3,2,1,0} = ($bf[4], $bf[4], $bf[4], $bf[4]); $bits{chomp}{0} = $bf[0]; diff --git a/lib/feature.pm b/lib/feature.pm index a8e943a819..e6e0442582 100644 --- a/lib/feature.pm +++ b/lib/feature.pm @@ -5,12 +5,13 @@ package feature; -our $VERSION = '1.62'; +our $VERSION = '1.63'; our %feature = ( fc => 'feature_fc', isa => 'feature_isa', say => 'feature_say', + try => 'feature_try', state => 'feature_state', switch => 'feature_switch', bitwise => 'feature_bitwise', @@ -33,7 +34,7 @@ our %feature_bundle = ( "5.15" => [qw(bareword_filehandles current_sub evalbytes fc indirect multidimensional say state switch unicode_eval unicode_strings)], "5.23" => [qw(bareword_filehandles current_sub evalbytes fc indirect multidimensional postderef_qq say state switch unicode_eval unicode_strings)], "5.27" => [qw(bareword_filehandles bitwise current_sub evalbytes fc indirect multidimensional postderef_qq say state switch unicode_eval unicode_strings)], - "all" => [qw(bareword_filehandles bitwise current_sub declared_refs evalbytes fc indirect isa multidimensional postderef_qq refaliasing say signatures state switch unicode_eval unicode_strings)], + "all" => [qw(bareword_filehandles bitwise current_sub declared_refs evalbytes fc indirect isa multidimensional postderef_qq refaliasing say signatures state switch try unicode_eval unicode_strings)], "default" => [qw(bareword_filehandles indirect multidimensional)], ); @@ -409,6 +410,14 @@ previous versions it was simply on all the time. You can use the L<bareword::filehandles> module on CPAN to disable bareword filehandles for older versions of perl. +=head2 The 'try' feature. + +This feature enables the C<try> and C<catch> syntax, which allows exception +handling, where exceptions throwin from the body of the block introduced with +C<try> are caught by executing the body of the C<catch> block. + +For more information, see L<perlsyn/"Try Catch Exception Handling">. + =head1 FEATURE BUNDLES It's possible to load multiple features together, using diff --git a/lib/warnings.pm b/lib/warnings.pm index da1ca6caa4..a92d4904c2 100644 --- a/lib/warnings.pm +++ b/lib/warnings.pm @@ -109,6 +109,9 @@ our %Offsets = ( # Warnings Categories added in Perl 5.031 'experimental::isa' => 146, + + # Warnings Categories added in Perl 5.033 + 'experimental::try' => 148, ); our %Bits = ( @@ -122,7 +125,7 @@ our %Bits = ( 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [31] 'exec' => "\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7] 'exiting' => "\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3] - 'experimental' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x55\x51\x15\x50\x51\x05", # [51..56,58..62,66..68,70..73] + 'experimental' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x55\x51\x15\x50\x51\x15", # [51..56,58..62,66..68,70..74] 'experimental::alpha_assertions' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00", # [67] 'experimental::bitwise' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00", # [58] 'experimental::const_attr' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00", # [59] @@ -137,6 +140,7 @@ our %Bits = ( 'experimental::script_run' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00", # [68] 'experimental::signatures' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00", # [56] 'experimental::smartmatch' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00", # [54] + 'experimental::try' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10", # [74] 'experimental::uniprop_wildcards' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00", # [71] 'experimental::vlb' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", # [72] 'experimental::win32_perlio' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00", # [62] @@ -199,7 +203,7 @@ our %DeadBits = ( 'digit' => "\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [31] 'exec' => "\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [7] 'exiting' => "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # [3] - 'experimental' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xaa\xa2\x2a\xa0\xa2\x0a", # [51..56,58..62,66..68,70..73] + 'experimental' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xaa\xa2\x2a\xa0\xa2\x2a", # [51..56,58..62,66..68,70..74] 'experimental::alpha_assertions' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00", # [67] 'experimental::bitwise' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00", # [58] 'experimental::const_attr' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00", # [59] @@ -214,6 +218,7 @@ our %DeadBits = ( 'experimental::script_run' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00", # [68] 'experimental::signatures' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00", # [56] 'experimental::smartmatch' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00", # [54] + 'experimental::try' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20", # [74] 'experimental::uniprop_wildcards' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00", # [71] 'experimental::vlb' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02", # [72] 'experimental::win32_perlio' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00", # [62] @@ -267,8 +272,8 @@ our %DeadBits = ( # These are used by various things, including our own tests our $NONE = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; -our $DEFAULT = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x00\x55\x51\x55\x50\x51\x05"; # [2,4,22,23,25,52..56,58..63,66..68,70..73] -our $LAST_BIT = 148 ; +our $DEFAULT = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x00\x55\x51\x55\x50\x51\x15"; # [2,4,22,23,25,52..56,58..63,66..68,70..74] +our $LAST_BIT = 150 ; our $BYTES = 19 ; sub Croaker @@ -888,6 +893,8 @@ The current hierarchy is: | | | +- experimental::smartmatch | | + | +- experimental::try + | | | +- experimental::uniprop_wildcards | | | +- experimental::vlb |