Skip to content

Commit 36a1b4c

Browse files
authored
Merge pull request #152 from php-java/implement-non-implemented-mnemonics-part-2
Add mnemonics
2 parents 57f9293 + 5dbe4c2 commit 36a1b4c

23 files changed

Lines changed: 883 additions & 87 deletions

src/Core/JVM/Invoker/Invokable.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
use PHPJava\Kernel\Provider\DependencyInjectionProvider;
2121
use PHPJava\Kernel\Structures\_MethodInfo;
2222
use PHPJava\Kernel\Types\_Char;
23+
use PHPJava\Kernel\Types\_Double;
24+
use PHPJava\Kernel\Types\_Long;
2325
use PHPJava\Packages\java\lang\NoSuchMethodException;
2426
use PHPJava\Utilities\AttributionResolver;
2527
use PHPJava\Utilities\DebugTool;
@@ -123,11 +125,10 @@ function () use ($name, $arguments) {
123125
}
124126

125127
$reader = new BinaryReader($handle);
126-
$localStorage = $arguments;
127128

128129
if ($this->isDynamic()) {
129130
array_unshift(
130-
$localStorage,
131+
$arguments,
131132
$this->javaClassInvoker->getJavaClass()
132133
);
133134
}
@@ -145,13 +146,22 @@ function () use ($name, $arguments) {
145146

146147
$this->debugTool->getLogger()->info('Start operations: ' . $methodBeautified);
147148

148-
$localStorage = array_map(
149-
function ($item) {
150-
return TypeResolver::convertPHPTypeToJavaType($item);
149+
$arguments = array_map(
150+
function ($argument) {
151+
return TypeResolver::convertPHPTypeToJavaType($argument);
151152
},
152-
$localStorage
153+
$arguments
153154
);
154155

156+
$localStorage = [];
157+
foreach ($arguments as $argument) {
158+
$localStorage[] = $argument;
159+
if ($argument instanceof _Double || $argument instanceof _Long) {
160+
// Double and Long has problem which skipping next storage.
161+
$localStorage[] = null;
162+
}
163+
}
164+
155165
$dependencyInjectionProvider = (new DependencyInjectionProvider())
156166
->add(
157167
'ConstantPool',

src/Kernel/Mnemonics/_anewarray.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,25 @@ final class _anewarray implements OperationInterface
1515
*/
1616
public function execute(): void
1717
{
18-
// 配列のサイズを調べる (PHPでは不要なので実行するだけ)
18+
// Current class index for Constant Pool
1919
$this->readUnsignedShort();
2020

21-
// 空の配列を渡す (nullで埋める)
22-
$count = Extractor::getRealValue($this->popFromOperandStack());
23-
// need reference
24-
$ref = new \ArrayIterator(array_fill(0, $count, null));
25-
$this->pushToOperandStackByReference($ref);
21+
// Get an array size
22+
$count = Extractor::getRealValue(
23+
$this->popFromOperandStack()
24+
);
25+
26+
// Make an array with object.
27+
$array = new \ArrayIterator(
28+
array_fill(
29+
0,
30+
$count,
31+
null
32+
)
33+
);
34+
35+
$this->pushToOperandStackByReference(
36+
$array
37+
);
2638
}
2739
}

src/Kernel/Mnemonics/_dadd.php

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

4+
use PHPJava\Kernel\Types\_Double;
45
use PHPJava\Utilities\BinaryTool;
6+
use PHPJava\Utilities\Extractor;
57

68
final class _dadd implements OperationInterface
79
{
@@ -10,9 +12,16 @@ final class _dadd implements OperationInterface
1012

1113
public function execute(): void
1214
{
13-
$value2 = $this->popFromOperandStack();
14-
$value1 = $this->popFromOperandStack();
15+
$rightValue = $this->popFromOperandStack();
16+
$leftValue = $this->popFromOperandStack();
1517

16-
$this->pushToOperandStack(BinaryTool::add($value1, $value2));
18+
$this->pushToOperandStack(
19+
_Double::get(
20+
BinaryTool::add(
21+
Extractor::getRealValue($leftValue),
22+
Extractor::getRealValue($rightValue)
23+
)
24+
)
25+
);
1726
}
1827
}

src/Kernel/Mnemonics/_dmul.php

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

4+
use PHPJava\Kernel\Types\_Double;
45
use PHPJava\Utilities\BinaryTool;
6+
use PHPJava\Utilities\Extractor;
57

68
final class _dmul implements OperationInterface
79
{
@@ -10,9 +12,16 @@ final class _dmul implements OperationInterface
1012

1113
public function execute(): void
1214
{
13-
$value2 = $this->popFromOperandStack();
14-
$value1 = $this->popFromOperandStack();
15+
$rightValue = $this->popFromOperandStack();
16+
$leftValue = $this->popFromOperandStack();
1517

16-
$this->pushToOperandStack(BinaryTool::multiply($value1, $value2, 8));
18+
$this->pushToOperandStack(
19+
_Double::get(
20+
BinaryTool::multiply(
21+
Extractor::getRealValue($leftValue),
22+
Extractor::getRealValue($rightValue)
23+
)
24+
)
25+
);
1726
}
1827
}

src/Kernel/Mnemonics/_drem.php

Lines changed: 10 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\_Double;
5+
use PHPJava\Utilities\Extractor;
56

67
final class _drem implements OperationInterface
78
{
@@ -10,6 +11,13 @@ final class _drem 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+
$this->pushToOperandStack(
18+
_Double::get(
19+
$leftOperand % $rightOperand
20+
)
21+
);
1422
}
1523
}

src/Kernel/Mnemonics/_dsub.php

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

4+
use PHPJava\Kernel\Types\_Double;
45
use PHPJava\Utilities\BinaryTool;
6+
use PHPJava\Utilities\Extractor;
57

68
final class _dsub implements OperationInterface
79
{
@@ -13,6 +15,13 @@ public function execute(): void
1315
$rightValue = $this->popFromOperandStack();
1416
$leftValue = $this->popFromOperandStack();
1517

16-
$this->pushToOperandStack(BinaryTool::sub($leftValue, $rightValue, 8));
18+
$this->pushToOperandStack(
19+
_Double::get(
20+
BinaryTool::sub(
21+
Extractor::getRealValue($leftValue),
22+
Extractor::getRealValue($rightValue)
23+
)
24+
)
25+
);
1726
}
1827
}

src/Kernel/Mnemonics/_fadd.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\_Float;
5+
use PHPJava\Utilities\BinaryTool;
6+
use PHPJava\Utilities\Extractor;
57

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

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

src/Kernel/Mnemonics/_fmul.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\_Float;
5+
use PHPJava\Utilities\BinaryTool;
6+
use PHPJava\Utilities\Extractor;
57

68
final class _fmul implements OperationInterface
79
{
@@ -10,6 +12,16 @@ final class _fmul 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+
_Float::get(
20+
BinaryTool::multiply(
21+
Extractor::getRealValue($value1),
22+
Extractor::getRealValue($value2)
23+
)
24+
)
25+
);
1426
}
1527
}

src/Kernel/Mnemonics/_frem.php

Lines changed: 10 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\_Float;
5+
use PHPJava\Utilities\Extractor;
56

67
final class _frem implements OperationInterface
78
{
@@ -10,6 +11,13 @@ final class _frem 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+
$this->pushToOperandStack(
18+
_Float::get(
19+
$leftOperand % $rightOperand
20+
)
21+
);
1422
}
1523
}

src/Kernel/Mnemonics/_fsub.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\_Float;
5+
use PHPJava\Utilities\BinaryTool;
6+
use PHPJava\Utilities\Extractor;
57

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

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

0 commit comments

Comments
 (0)