Skip to content

Commit

Permalink
ZE3: Added zephir_bitwise_xor_function
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyklay committed Oct 11, 2017
1 parent 82891e2 commit fb706a7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Library/Operators/Bitwise/BitwiseBaseOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,11 @@ public function optimizeConstantFolding(array $expression, CompilationContext $c
}

/**
* {@inheritdoc}
*
* @param array $expression
* @param CompilationContext $compilationContext
* @return bool|CompiledExpression
*/
public function compile($expression, CompilationContext $compilationContext)
{
Expand Down
10 changes: 10 additions & 0 deletions kernels/ZendEngine3/operators.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,16 @@ int zephir_bitwise_or_function(zval *result, zval *op1, zval *op2)
return status;
}

/**
* Do bitwise_xor function keeping ref_count and is_ref
*/
int zephir_bitwise_xor_function(zval *result, zval *op1, zval *op2)
{
int status;
status = bitwise_xor_function(result, op1, op2);
return status;
}

/**
* Check if a zval is less/equal than other
*/
Expand Down
16 changes: 16 additions & 0 deletions test/bitwise.zep
Original file line number Diff line number Diff line change
Expand Up @@ -948,4 +948,20 @@ class Bitwise
{
return a & ~b;
}

protected function getInt(int num) -> int
{
return num;
}

/**
* @issue 1581
*/
public function testbitwiseXor()
{
var i = this->getInt(123),
j = this->getInt(321);

return i ^ j;
}
}
6 changes: 6 additions & 0 deletions unit-tests/Extension/BitwiseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,11 @@ public function testBitwise()
// Bitwise NOT
$this->assertSame($t->testBitwiseNot(666), -667);
$this->assertSame($t->testBitwiseAndNot(5, 4), 1);

/**
* Bitwise XOR
* @issue 1581
*/
$this->assertSame(123 ^ 321, $t->testbitwiseXor());
}
}

0 comments on commit fb706a7

Please sign in to comment.