From c844eac5926d1efbdfbf2e8bcc3989ba6a6aee50 Mon Sep 17 00:00:00 2001 From: Lukas Mai Date: Fri, 24 May 2024 06:34:53 +0200 Subject: [PATCH] B::Deparse: teach Deparse about ^^ (high-precedence xor) --- lib/B/Deparse-core.t | 4 ++-- lib/B/Deparse.pm | 4 ++-- lib/B/Deparse.t | 6 ++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/B/Deparse-core.t b/lib/B/Deparse-core.t index b46c6b1d344d..a898cf60bc13 100644 --- a/lib/B/Deparse-core.t +++ b/lib/B/Deparse-core.t @@ -123,7 +123,7 @@ sub testit { # Deparse can't distinguish 'and' from '&&' etc -my %infix_map = qw(and && or ||); +my %infix_map = (and => '&&', or => '||', xor => '^^'); # Test a keyword that is a binary infix operator, like 'cmp'. # $parens - "$a op $b" is deparsed as "($a op $b)" @@ -686,4 +686,4 @@ wantarray 0 - warn @ p1 write 01 - x B - -xor B p +xor B - diff --git a/lib/B/Deparse.pm b/lib/B/Deparse.pm index 309d65e29704..ec632f1824b2 100644 --- a/lib/B/Deparse.pm +++ b/lib/B/Deparse.pm @@ -7,7 +7,7 @@ # This is based on the module of the same name by Malcolm Beattie, # but essentially none of his code remains. -package B::Deparse 1.76; +package B::Deparse 1.77; use strict; use Carp; use B qw(class main_root main_start main_cv svref_2object opnumber perlstring @@ -3277,7 +3277,7 @@ sub pp_dor { logop(@_, "//", 10) } # xor is syntactically a logop, but it's really a binop (contrary to # old versions of opcode.pl). Syntax is what matters here. -sub pp_xor { logop(@_, "xor", 2, "", 0, "") } +sub pp_xor { logop(@_, "xor", 2, "^^", 10, "") } sub logassignop { my $self = shift; diff --git a/lib/B/Deparse.t b/lib/B/Deparse.t index 522b73a527cf..6f35cb638984 100644 --- a/lib/B/Deparse.t +++ b/lib/B/Deparse.t @@ -1879,10 +1879,10 @@ CORE::do({}); >>>> () = (return 1); () = (return ($1 + $2) * $3); -() = (return ($a xor $b)); +() = (return $a ^^ $b); () = (do 'file') + time; () = (do ($1 + $2) * $3) + time; -() = (do ($1 xor $2)) + time; +() = (do ($1 ^^ $2)) + time; () = (goto 1); () = (require 'foo') + 3; () = (require foo) + 3; @@ -1911,6 +1911,8 @@ require v5.16; #### # [perl #97476] not() *does* follow the llafr $_ = ($a xor not +($1 || 2) ** 2); +>>>> +$_ = $a ^^ !($1 || 2) ** 2; #### # Precedence conundrums with argument-less function calls () = (eof) + 1;