Skip to content

Commit 046d9f8

Browse files
committed
Implement assigning xor (^^=) operator
When I added '^^' I forgot to implement or test the assigning version of it. Also it seems `pp_xor` had the left and right arguments round the wrong way; but until the asymmetry introduced by this change nobody had noticed before. This is now fixed.
1 parent 68ce332 commit 046d9f8

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

pp_ctl.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,11 +2172,12 @@ Perl_die_unwind(pTHX_ SV *msv)
21722172

21732173
PP(pp_xor)
21742174
{
2175-
SV *left = PL_stack_sp[0];
2176-
SV *right = PL_stack_sp[-1];
2177-
rpp_replace_2_IMM_NN(SvTRUE_NN(left) != SvTRUE_NN(right)
2178-
? &PL_sv_yes
2179-
: &PL_sv_no);
2175+
SV *left = PL_stack_sp[-1];
2176+
SV *right = PL_stack_sp[0];
2177+
bool ret = SvTRUE_NN(left) != SvTRUE_NN(right);
2178+
rpp_replace_2_IMM_NN(boolSV(ret));
2179+
if (PL_op->op_flags & OPf_STACKED)
2180+
sv_setbool(left, ret);
21802181
return NORMAL;
21812182
}
21822183

t/op/lop.t

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ BEGIN {
1010
set_up_inc('../lib');
1111
}
1212

13-
plan tests => 47;
13+
plan tests => 57;
1414

1515
for my $i (undef, 0 .. 2, "", "0 but true") {
1616
my $true = 1;
@@ -105,6 +105,10 @@ for my $test (
105105
my ($a,$b, $exp) = @$test;
106106
is(($a xor $b), $exp, "($a xor $b) == '$exp'");
107107
is(($a ^^ $b), $exp, "($a ^^ $b) == '$exp'");
108+
109+
my ($lhs, $rhs) = @$test;
110+
$lhs ^^= $rhs;
111+
is($lhs, $exp, "$a ^^= $b gives '$exp'");
108112
}
109113

110114
# precedence

toke.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6097,6 +6097,10 @@ yyl_caret(pTHX_ char *s)
60976097
TOKEN(0);
60986098
}
60996099
pl_yylval.ival = OP_XOR;
6100+
if (*s == '=') {
6101+
s++;
6102+
OPERATOR(ASSIGNOP);
6103+
}
61006104
OPERATOR(OROR);
61016105
}
61026106
if (bof && s[1] == '.')

0 commit comments

Comments
 (0)