Skip to content

Commit 257fc9b

Browse files
committed
Fix mnemonics and wrap Kernel\Types for scalar values
1 parent ccf2600 commit 257fc9b

File tree

13 files changed

+126
-30
lines changed

13 files changed

+126
-30
lines changed

src/Kernel/Mnemonics/_iadd.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use PHPJava\Exceptions\NotImplementedException;
55
use PHPJava\Kernel\Types\_Int;
66
use PHPJava\Utilities\BinaryTool;
7+
use PHPJava\Utilities\Extractor;
78

89
final class _iadd implements OperationInterface
910
{
@@ -15,14 +16,13 @@ public function execute(): void
1516
$rightValue = $this->getStack();
1617
$leftValue = $this->getStack();
1718

18-
if ($leftValue instanceof _Int) {
19-
$leftValue = $leftValue->getValue();
20-
}
21-
22-
if ($rightValue instanceof _Int) {
23-
$rightValue = $rightValue->getValue();
24-
}
25-
26-
$this->pushStack(BinaryTool::add($leftValue, $rightValue));
19+
$this->pushStack(
20+
new _Int(
21+
BinaryTool::add(
22+
Extractor::realValue($leftValue),
23+
Extractor::realValue($rightValue)
24+
)
25+
)
26+
);
2727
}
2828
}

src/Kernel/Mnemonics/_idiv.php

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

44
use PHPJava\Exceptions\NotImplementedException;
5+
use PHPJava\Kernel\Types\_Double;
56
use PHPJava\Utilities\BinaryTool;
7+
use PHPJava\Utilities\Extractor;
68

79
final class _idiv implements OperationInterface
810
{
@@ -11,6 +13,16 @@ final class _idiv implements OperationInterface
1113

1214
public function execute(): void
1315
{
14-
throw new NotImplementedException(__CLASS__);
16+
$value2 = $this->getStack();
17+
$value1 = $this->getStack();
18+
19+
$this->pushStack(
20+
new _Double(
21+
BinaryTool::div(
22+
Extractor::realValue($value1),
23+
Extractor::realValue($value2)
24+
)
25+
)
26+
);
1527
}
1628
}

src/Kernel/Mnemonics/_imul.php

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

44
use PHPJava\Exceptions\NotImplementedException;
5+
use PHPJava\Kernel\Types\_Int;
56
use PHPJava\Utilities\BinaryTool;
7+
use PHPJava\Utilities\Extractor;
68

79
final class _imul implements OperationInterface
810
{
@@ -14,6 +16,13 @@ public function execute(): void
1416
$value2 = $this->getStack();
1517
$value1 = $this->getStack();
1618

17-
$this->pushStack(BinaryTool::multiply($value1, $value2, 4));
19+
$this->pushStack(
20+
new _Int(
21+
BinaryTool::multiply(
22+
Extractor::realValue($value1),
23+
Extractor::realValue($value2)
24+
)
25+
)
26+
);
1827
}
1928
}

src/Kernel/Mnemonics/_ireturn.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ final class _ireturn implements OperationInterface
1515
*/
1616
public function execute()
1717
{
18-
return new _Int($this->getStack());
18+
$value = $this->getStack();
19+
return ($value instanceof _Int)
20+
? $value
21+
: new _Int($value);
1922
}
2023
}

src/Kernel/Mnemonics/_isub.php

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

44
use PHPJava\Exceptions\NotImplementedException;
5+
use PHPJava\Kernel\Types\_Int;
56
use PHPJava\Utilities\BinaryTool;
7+
use PHPJava\Utilities\Extractor;
68

79
final class _isub implements OperationInterface
810
{
@@ -14,6 +16,13 @@ public function execute(): void
1416
$rightValue = $this->getStack();
1517
$leftValue = $this->getStack();
1618

17-
$this->pushStack(BinaryTool::sub($leftValue, $rightValue, 4));
19+
$this->pushStack(
20+
new _Int(
21+
BinaryTool::sub(
22+
Extractor::realValue($leftValue),
23+
Extractor::realValue($rightValue)
24+
)
25+
)
26+
);
1827
}
1928
}

src/Kernel/Mnemonics/_ladd.php

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

44
use PHPJava\Exceptions\NotImplementedException;
5+
use PHPJava\Kernel\Types\_Long;
56
use PHPJava\Utilities\BinaryTool;
7+
use PHPJava\Utilities\Extractor;
68

79
final class _ladd implements OperationInterface
810
{
@@ -14,6 +16,13 @@ public function execute(): void
1416
$value2 = $this->getStack();
1517
$value1 = $this->getStack();
1618

17-
$this->pushStack(BinaryTool::add($value1, $value2));
19+
$this->pushStack(
20+
new _Long(
21+
BinaryTool::add(
22+
Extractor::realValue($value1),
23+
Extractor::realValue($value2)
24+
)
25+
)
26+
);
1827
}
1928
}

src/Kernel/Mnemonics/_ldiv.php

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

44
use PHPJava\Exceptions\NotImplementedException;
5+
use PHPJava\Kernel\Types\_Double;
56
use PHPJava\Utilities\BinaryTool;
7+
use PHPJava\Utilities\Extractor;
68

79
final class _ldiv implements OperationInterface
810
{
@@ -11,6 +13,16 @@ final class _ldiv implements OperationInterface
1113

1214
public function execute(): void
1315
{
14-
throw new NotImplementedException(__CLASS__);
16+
$value2 = $this->getStack();
17+
$value1 = $this->getStack();
18+
19+
$this->pushStack(
20+
new _Double(
21+
BinaryTool::div(
22+
Extractor::realValue($value1),
23+
Extractor::realValue($value2)
24+
)
25+
)
26+
);
1527
}
1628
}

src/Kernel/Mnemonics/_lmul.php

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

44
use PHPJava\Exceptions\NotImplementedException;
5+
use PHPJava\Kernel\Types\_Long;
56
use PHPJava\Utilities\BinaryTool;
7+
use PHPJava\Utilities\Extractor;
68

79
final class _lmul implements OperationInterface
810
{
@@ -14,6 +16,13 @@ public function execute(): void
1416
$value2 = $this->getStack();
1517
$value1 = $this->getStack();
1618

17-
$this->pushStack(BinaryTool::multiply($value1, $value2, 8));
19+
$this->pushStack(
20+
new _Long(
21+
BinaryTool::multiply(
22+
Extractor::realValue($value1),
23+
Extractor::realValue($value2)
24+
)
25+
)
26+
);
1827
}
1928
}

src/Kernel/Mnemonics/_lreturn.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22
namespace PHPJava\Kernel\Mnemonics;
33

44
use PHPJava\Exceptions\NotImplementedException;
5+
use PHPJava\Kernel\Types\_Long;
56
use PHPJava\Utilities\BinaryTool;
67

78
final class _lreturn implements OperationInterface
89
{
910
use \PHPJava\Kernel\Core\Accumulator;
1011
use \PHPJava\Kernel\Core\ConstantPool;
1112

12-
public function execute(): void
13+
public function execute()
1314
{
14-
return new JavaTypeLong($this->getStack());
15+
$value = $this->getStack();
16+
return ($value instanceof _Long)
17+
? $value
18+
: new _Long($value);
1519
}
1620
}

src/Kernel/Mnemonics/_lsub.php

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

44
use PHPJava\Exceptions\NotImplementedException;
5+
use PHPJava\Kernel\Types\_Long;
56
use PHPJava\Utilities\BinaryTool;
7+
use PHPJava\Utilities\Extractor;
68

79
final class _lsub implements OperationInterface
810
{
@@ -14,6 +16,13 @@ public function execute(): void
1416
$value2 = $this->getStack();
1517
$value1 = $this->getStack();
1618

17-
$this->pushStack(BinaryTool::sub($value1, $value2, 8));
19+
$this->pushStack(
20+
new _Long(
21+
BinaryTool::sub(
22+
Extractor::realValue($value1),
23+
Extractor::realValue($value2)
24+
)
25+
)
26+
);
1827
}
1928
}

0 commit comments

Comments
 (0)