Skip to content

Commit 2c9a7d6

Browse files
committed
Add double and float calculating operations
1 parent 637dbc4 commit 2c9a7d6

22 files changed

+389
-57
lines changed

src/Core/JVM/Invoker/Invokable.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,12 @@ function () use ($fullName) {
266266
);
267267
}
268268

269-
if ($returnValue !== null) {
269+
if ($opcode === OpCode::_return ||
270+
$opcode === OpCode::_areturn ||
271+
$opcode === OpCode::_freturn ||
272+
$opcode === OpCode::_dreturn ||
273+
$opcode === OpCode::_ireturn
274+
) {
270275
if ($isEnabledTrace) {
271276
$this->javaClassInvoker->getJavaClass()->appendDebug($debugTraces);
272277
}

src/Kernel/Mnemonics/_dcmpg.php

Lines changed: 22 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\_Int;
6+
use PHPJava\Utilities\Extractor;
57

68
final class _dcmpg implements OperationInterface
79
{
@@ -10,6 +12,25 @@ final class _dcmpg 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+
if ($leftOperand > $rightOperand) {
19+
$this->pushToOperandStack(
20+
new _Int(1)
21+
);
22+
return;
23+
}
24+
25+
if ($leftOperand < $rightOperand) {
26+
$this->pushToOperandStack(
27+
new _Int(-1)
28+
);
29+
return;
30+
}
31+
32+
$this->pushToOperandStack(
33+
new _Int(0)
34+
);
1435
}
1536
}

src/Kernel/Mnemonics/_dcmpl.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
22
namespace PHPJava\Kernel\Mnemonics;
33

4-
use PHPJava\Exceptions\NotImplementedException;
4+
use PHPJava\Kernel\Types\_Int;
5+
use PHPJava\Utilities\Extractor;
56

67
final class _dcmpl implements OperationInterface
78
{
@@ -10,6 +11,25 @@ final class _dcmpl implements OperationInterface
1011

1112
public function execute(): void
1213
{
13-
throw new NotImplementedException(__CLASS__);
14+
$rightOperand = Extractor::getRealValue($this->popFromOperandStack());
15+
$leftOperand = Extractor::getRealValue($this->popFromOperandStack());
16+
17+
if ($leftOperand > $rightOperand) {
18+
$this->pushToOperandStack(
19+
new _Int(1)
20+
);
21+
return;
22+
}
23+
24+
if ($leftOperand < $rightOperand) {
25+
$this->pushToOperandStack(
26+
new _Int(-1)
27+
);
28+
return;
29+
}
30+
31+
$this->pushToOperandStack(
32+
new _Int(0)
33+
);
1434
}
1535
}

src/Kernel/Mnemonics/_dconst_0.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
<?php
22
namespace PHPJava\Kernel\Mnemonics;
33

4+
use PHPJava\Kernel\Types\_Double;
5+
46
final class _dconst_0 implements OperationInterface
57
{
68
use \PHPJava\Kernel\Core\Accumulator;
79
use \PHPJava\Kernel\Core\ConstantPool;
810

911
public function execute(): void
1012
{
11-
$this->pushToOperandStack(0);
13+
$this->pushToOperandStack(
14+
new _Double(0)
15+
);
1216
}
1317
}

src/Kernel/Mnemonics/_dconst_1.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
<?php
22
namespace PHPJava\Kernel\Mnemonics;
33

4+
use PHPJava\Kernel\Types\_Double;
5+
46
final class _dconst_1 implements OperationInterface
57
{
68
use \PHPJava\Kernel\Core\Accumulator;
79
use \PHPJava\Kernel\Core\ConstantPool;
810

911
public function execute(): void
1012
{
11-
$this->pushToOperandStack(1);
13+
$this->pushToOperandStack(
14+
new _Double(1)
15+
);
1216
}
1317
}

src/Kernel/Mnemonics/_ddiv.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?php
22
namespace PHPJava\Kernel\Mnemonics;
33

4-
use PHPJava\Exceptions\NotImplementedException;
4+
use PHPJava\Kernel\Types\_Double;
5+
use PHPJava\Utilities\BinaryTool;
6+
use PHPJava\Utilities\Extractor;
57

68
final class _ddiv implements OperationInterface
79
{
@@ -10,6 +12,16 @@ final class _ddiv implements OperationInterface
1012

1113
public function execute(): void
1214
{
13-
throw new NotImplementedException(__CLASS__);
15+
$value2 = $this->popFromOperandStack();
16+
$value1 = $this->popFromOperandStack();
17+
18+
$this->pushToOperandStack(
19+
new _Double(
20+
BinaryTool::div(
21+
Extractor::getRealValue($value1),
22+
Extractor::getRealValue($value2)
23+
)
24+
)
25+
);
1426
}
1527
}

src/Kernel/Mnemonics/_fcmpg.php

Lines changed: 22 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\_Int;
6+
use PHPJava\Utilities\Extractor;
57

68
final class _fcmpg implements OperationInterface
79
{
@@ -10,6 +12,25 @@ final class _fcmpg 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+
if ($leftOperand > $rightOperand) {
19+
$this->pushToOperandStack(
20+
new _Int(1)
21+
);
22+
return;
23+
}
24+
25+
if ($leftOperand < $rightOperand) {
26+
$this->pushToOperandStack(
27+
new _Int(-1)
28+
);
29+
return;
30+
}
31+
32+
$this->pushToOperandStack(
33+
new _Int(0)
34+
);
1435
}
1536
}

src/Kernel/Mnemonics/_fcmpl.php

Lines changed: 22 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\_Int;
6+
use PHPJava\Utilities\Extractor;
57

68
final class _fcmpl implements OperationInterface
79
{
@@ -10,6 +12,25 @@ final class _fcmpl 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+
if ($leftOperand > $rightOperand) {
19+
$this->pushToOperandStack(
20+
new _Int(1)
21+
);
22+
return;
23+
}
24+
25+
if ($leftOperand < $rightOperand) {
26+
$this->pushToOperandStack(
27+
new _Int(-1)
28+
);
29+
return;
30+
}
31+
32+
$this->pushToOperandStack(
33+
new _Int(0)
34+
);
1435
}
1536
}

src/Kernel/Mnemonics/_fconst_0.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
namespace PHPJava\Kernel\Mnemonics;
33

4-
use PHPJava\Exceptions\NotImplementedException;
4+
use PHPJava\Kernel\Types\_Float;
55

66
final class _fconst_0 implements OperationInterface
77
{
@@ -10,6 +10,6 @@ final class _fconst_0 implements OperationInterface
1010

1111
public function execute(): void
1212
{
13-
throw new NotImplementedException(__CLASS__);
13+
$this->pushToOperandStack(new _Float(0));
1414
}
1515
}

src/Kernel/Mnemonics/_fconst_1.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
namespace PHPJava\Kernel\Mnemonics;
33

4-
use PHPJava\Exceptions\NotImplementedException;
4+
use PHPJava\Kernel\Types\_Float;
55

66
final class _fconst_1 implements OperationInterface
77
{
@@ -10,6 +10,6 @@ final class _fconst_1 implements OperationInterface
1010

1111
public function execute(): void
1212
{
13-
throw new NotImplementedException(__CLASS__);
13+
$this->pushToOperandStack(new _Float(1));
1414
}
1515
}

0 commit comments

Comments
 (0)