Skip to content

Commit e0263f3

Browse files
committed
Add B::Deparse support for assigning xor
1 parent 450f5f6 commit e0263f3

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/B/Deparse.pm

Lines changed: 11 additions & 2 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.84;
10+
package B::Deparse 1.85;
1111
use strict;
1212
use Carp;
1313
use B qw(class main_root main_start main_cv svref_2object opnumber perlstring
@@ -3320,7 +3320,16 @@ sub pp_dor { logop(@_, "//", 10) }
33203320

33213321
# xor is syntactically a logop, but it's really a binop (contrary to
33223322
# old versions of opcode.pl). Syntax is what matters here.
3323-
sub pp_xor { logop(@_, "xor", 2, "^^", 10, "") }
3323+
sub pp_xor {
3324+
my $self = shift;
3325+
my ($op, $cx) = @_;
3326+
if ($cx > 2 or $op->flags & OPf_STACKED) {
3327+
binop($self, @_, "^^", 10, ASSIGN);
3328+
}
3329+
else {
3330+
binop($self, @_, "xor", 2);
3331+
}
3332+
}
33243333

33253334
sub logassignop {
33263335
my $self = shift;

lib/B/Deparse.t

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3450,3 +3450,8 @@ $_ = (!$p) isa 'Some::Class';
34503450
$_ = (!$p) =~ tr/1//;
34513451
$_ = (!$p) =~ /1/;
34523452
$_ = (!$p) =~ s/1//r;
3453+
####
3454+
# xor operator
3455+
my($x, $y, $z);
3456+
$z = 1 + ($x ^^ $y);
3457+
$z = ($x ^^= $y);

0 commit comments

Comments
 (0)