Skip to content

Commit cf348ed

Browse files
committed
Use Extractor::getRealValue
1 parent dc5395d commit cf348ed

8 files changed

Lines changed: 70 additions & 6 deletions

File tree

src/Kernel/Mnemonics/_aastore.php

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

4+
use PHPJava\Utilities\Extractor;
5+
46
final class _aastore implements OperationInterface
57
{
68
use \PHPJava\Kernel\Core\Accumulator;
@@ -12,7 +14,7 @@ final class _aastore implements OperationInterface
1214
public function execute(): void
1315
{
1416
$value = $this->popFromOperandStack();
15-
$index = $this->popFromOperandStack();
17+
$index = Extractor::getRealValue($this->popFromOperandStack());
1618
$arrayref = $this->popFromOperandStack();
1719

1820
$arrayref[$index] = $value;

src/Kernel/Mnemonics/_anewarray.php

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

4+
use PHPJava\Utilities\Extractor;
5+
46
final class _anewarray implements OperationInterface
57
{
68
use \PHPJava\Kernel\Core\Accumulator;
@@ -17,7 +19,7 @@ public function execute(): void
1719
$this->readUnsignedShort();
1820

1921
// 空の配列を渡す (nullで埋める)
20-
$count = $this->popFromOperandStack();
22+
$count = Extractor::getRealValue($this->popFromOperandStack());
2123
// need reference
2224
$ref = new \ArrayIterator(array_fill(0, $count, null));
2325
$this->pushToOperandStackByReference($ref);

src/Kernel/Mnemonics/_daload.php

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

4+
use PHPJava\Utilities\Extractor;
5+
46
final class _daload implements OperationInterface
57
{
68
use \PHPJava\Kernel\Core\Accumulator;
@@ -11,7 +13,7 @@ final class _daload implements OperationInterface
1113
*/
1214
public function execute(): void
1315
{
14-
$index = $this->popFromOperandStack();
16+
$index = Extractor::getRealValue($this->popFromOperandStack());
1517
$arrayref = $this->popFromOperandStack();
1618

1719
$this->pushToOperandStack($arrayref[$index]);

src/Kernel/Mnemonics/_dastore.php

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

4+
use PHPJava\Utilities\Extractor;
5+
46
final class _dastore implements OperationInterface
57
{
68
use \PHPJava\Kernel\Core\Accumulator;
@@ -12,7 +14,7 @@ final class _dastore implements OperationInterface
1214
public function execute(): void
1315
{
1416
$value = $this->popFromOperandStack();
15-
$index = $this->popFromOperandStack();
17+
$index = Extractor::getRealValue($this->popFromOperandStack());
1618
$arrayref = $this->popFromOperandStack();
1719

1820
$arrayref[$index] = $value;

src/Kernel/Mnemonics/_laload.php

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

4+
use PHPJava\Utilities\Extractor;
5+
46
final class _laload implements OperationInterface
57
{
68
use \PHPJava\Kernel\Core\Accumulator;
@@ -11,7 +13,7 @@ final class _laload implements OperationInterface
1113
*/
1214
public function execute(): void
1315
{
14-
$index = $this->popFromOperandStack();
16+
$index = Extractor::getRealValue($this->popFromOperandStack());
1517
$arrayref = $this->popFromOperandStack();
1618

1719
$this->pushToOperandStack($arrayref[$index]);

src/Kernel/Mnemonics/_lastore.php

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

4+
use PHPJava\Utilities\Extractor;
5+
46
final class _lastore implements OperationInterface
57
{
68
use \PHPJava\Kernel\Core\Accumulator;
@@ -12,7 +14,7 @@ final class _lastore implements OperationInterface
1214
public function execute(): void
1315
{
1416
$value = $this->popFromOperandStack();
15-
$index = $this->popFromOperandStack();
17+
$index = Extractor::getRealValue($this->popFromOperandStack());
1618
$arrayref = $this->popFromOperandStack();
1719

1820
$arrayref[$index] = $value;

tests/ArrayTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
namespace PHPJava\Tests;
3+
4+
class ArrayTest extends Base
5+
{
6+
protected $fixtures = [
7+
'ArrayTest',
8+
];
9+
10+
private function call($method)
11+
{
12+
$calculatedValue = $this->initiatedJavaClasses['ArrayTest']
13+
->getInvoker()
14+
->getStatic()
15+
->getMethods()
16+
->call($method);
17+
18+
return $calculatedValue;
19+
}
20+
21+
public function testCreateIntArray()
22+
{
23+
$actual = $this->call('createIntArray');
24+
25+
$this->assertEquals(3, $actual->count());
26+
$this->assertEquals(1, $actual->offsetGet(0)->getValue());
27+
$this->assertEquals(2, $actual->offsetGet(1)->getValue());
28+
$this->assertEquals(3, $actual->offsetGet(2)->getValue());
29+
}
30+
31+
public function testCreateStringArray()
32+
{
33+
$actual = $this->call('createStringArray');
34+
35+
$this->assertEquals(3, $actual->count());
36+
$this->assertEquals("foo", $actual->offsetGet(0));
37+
$this->assertEquals("bar", $actual->offsetGet(1));
38+
$this->assertEquals("baz", $actual->offsetGet(2));
39+
}
40+
}

tests/fixtures/java/ArrayTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class ArrayTest
2+
{
3+
public static int[] createIntArray()
4+
{
5+
return new int[] { 1, 2, 3 };
6+
}
7+
8+
public static String[] createStringArray()
9+
{
10+
return new String[] { "foo", "bar", "baz" };
11+
}
12+
}

0 commit comments

Comments
 (0)