Skip to content

Commit d8cd90c

Browse files
committed
Add drem, frem, if_icmpeq, ifnull, lrem
1 parent 57f9293 commit d8cd90c

5 files changed

Lines changed: 47 additions & 5 deletions

File tree

src/Kernel/Mnemonics/_drem.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
namespace PHPJava\Kernel\Mnemonics;
33

44
use PHPJava\Exceptions\NotImplementedException;
5+
use PHPJava\Kernel\Types\_Double;
6+
use PHPJava\Utilities\Extractor;
57

68
final class _drem implements OperationInterface
79
{
@@ -10,6 +12,13 @@ final class _drem implements OperationInterface
1012

1113
public function execute(): void
1214
{
13-
throw new NotImplementedException(__CLASS__);
15+
$rightOperand = Extractor::getRealValue($this->popFromOperandStack());
16+
$leftOperand = Extractor::getRealValue($this->popFromOperandStack());
17+
18+
$this->pushToOperandStack(
19+
_Double::get(
20+
$leftOperand % $rightOperand
21+
)
22+
);
1423
}
1524
}

src/Kernel/Mnemonics/_frem.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
namespace PHPJava\Kernel\Mnemonics;
33

44
use PHPJava\Exceptions\NotImplementedException;
5+
use PHPJava\Kernel\Types\_Float;
6+
use PHPJava\Utilities\Extractor;
57

68
final class _frem implements OperationInterface
79
{
@@ -10,6 +12,13 @@ final class _frem implements OperationInterface
1012

1113
public function execute(): void
1214
{
13-
throw new NotImplementedException(__CLASS__);
15+
$rightOperand = Extractor::getRealValue($this->popFromOperandStack());
16+
$leftOperand = Extractor::getRealValue($this->popFromOperandStack());
17+
18+
$this->pushToOperandStack(
19+
_Float::get(
20+
$leftOperand % $rightOperand
21+
)
22+
);
1423
}
1524
}

src/Kernel/Mnemonics/_if_icmpeq.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace PHPJava\Kernel\Mnemonics;
33

44
use PHPJava\Exceptions\NotImplementedException;
5+
use PHPJava\Utilities\Extractor;
56

67
final class _if_icmpeq implements OperationInterface
78
{
@@ -10,6 +11,13 @@ final class _if_icmpeq implements OperationInterface
1011

1112
public function execute(): void
1213
{
13-
throw new NotImplementedException(__CLASS__);
14+
$offset = $this->readShort();
15+
16+
$rightOperand = Extractor::getRealValue($this->popFromOperandStack());
17+
$leftOperand = Extractor::getRealValue($this->popFromOperandStack());
18+
19+
if ($leftOperand == $rightOperand) {
20+
$this->setOffset($this->getProgramCounter() + $offset);
21+
}
1422
}
1523
}

src/Kernel/Mnemonics/_ifnull.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace PHPJava\Kernel\Mnemonics;
33

44
use PHPJava\Exceptions\NotImplementedException;
5+
use PHPJava\Utilities\Extractor;
56

67
final class _ifnull implements OperationInterface
78
{
@@ -10,6 +11,12 @@ final class _ifnull implements OperationInterface
1011

1112
public function execute(): void
1213
{
13-
throw new NotImplementedException(__CLASS__);
14+
$offset = $this->readShort();
15+
16+
$branch = Extractor::getRealValue($this->popFromOperandStack());
17+
18+
if ($branch === null) {
19+
$this->setOffset($this->getProgramCounter() + $offset);
20+
}
1421
}
1522
}

src/Kernel/Mnemonics/_lrem.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
namespace PHPJava\Kernel\Mnemonics;
33

44
use PHPJava\Exceptions\NotImplementedException;
5+
use PHPJava\Kernel\Types\_Long;
6+
use PHPJava\Utilities\Extractor;
57

68
final class _lrem implements OperationInterface
79
{
@@ -10,6 +12,13 @@ final class _lrem implements OperationInterface
1012

1113
public function execute(): void
1214
{
13-
throw new NotImplementedException(__CLASS__);
15+
$rightOperand = Extractor::getRealValue($this->popFromOperandStack());
16+
$leftOperand = Extractor::getRealValue($this->popFromOperandStack());
17+
18+
$this->pushToOperandStack(
19+
_Long::get(
20+
$leftOperand % $rightOperand
21+
)
22+
);
1423
}
1524
}

0 commit comments

Comments
 (0)