Skip to content

Commit 864fd5b

Browse files
authored
Merge pull request #154 from php-java/implement-non-implemented-mnemonics-part-3
Add mnemonics
2 parents 217dc38 + e35b8cd commit 864fd5b

24 files changed

Lines changed: 413 additions & 53 deletions

src/Kernel/Mnemonics/_baload.php

Lines changed: 7 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\Utilities\Extractor;
55

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

1111
public function execute(): void
1212
{
13-
throw new NotImplementedException(__CLASS__);
13+
$index = Extractor::getRealValue($this->popFromOperandStack());
14+
$arrayref = $this->popFromOperandStack();
15+
16+
$this->pushToOperandStack(
17+
$arrayref[$index]
18+
);
1419
}
1520
}

src/Kernel/Mnemonics/_bastore.php

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

67
final class _bastore implements OperationInterface
78
{
@@ -10,6 +11,19 @@ final class _bastore implements OperationInterface
1011

1112
public function execute(): void
1213
{
13-
throw new NotImplementedException(__CLASS__);
14+
$value = $this->popFromOperandStack();
15+
$index = Extractor::getRealValue($this->popFromOperandStack());
16+
17+
/**
18+
* @var Type $arrayref
19+
*/
20+
$arrayref = $this->popFromOperandStack();
21+
22+
// The value is a ref.
23+
$arrayref[$index] = $value;
24+
25+
$this->pushToOperandStack(
26+
$arrayref
27+
);
1428
}
1529
}

src/Kernel/Mnemonics/_caload.php

Lines changed: 7 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\Utilities\Extractor;
55

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

1111
public function execute(): void
1212
{
13-
throw new NotImplementedException(__CLASS__);
13+
$index = Extractor::getRealValue($this->popFromOperandStack());
14+
$arrayref = $this->popFromOperandStack();
15+
16+
$this->pushToOperandStack(
17+
$arrayref[$index]
18+
);
1419
}
1520
}

src/Kernel/Mnemonics/_daload.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public function execute(): void
1616
$index = Extractor::getRealValue($this->popFromOperandStack());
1717
$arrayref = $this->popFromOperandStack();
1818

19-
$this->pushToOperandStack($arrayref[$index]);
19+
$this->pushToOperandStack(
20+
$arrayref[$index]
21+
);
2022
}
2123
}

src/Kernel/Mnemonics/_dastore.php

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

4+
use PHPJava\Kernel\Types\Type;
45
use PHPJava\Utilities\Extractor;
56

67
final class _dastore implements OperationInterface
@@ -15,8 +16,17 @@ public function execute(): void
1516
{
1617
$value = $this->popFromOperandStack();
1718
$index = Extractor::getRealValue($this->popFromOperandStack());
19+
20+
/**
21+
* @var Type $arrayref
22+
*/
1823
$arrayref = $this->popFromOperandStack();
1924

25+
// The value is a ref.
2026
$arrayref[$index] = $value;
27+
28+
$this->pushToOperandStack(
29+
$arrayref
30+
);
2131
}
2232
}

src/Kernel/Mnemonics/_dneg.php

Lines changed: 12 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 _dneg implements OperationInterface
79
{
@@ -10,6 +12,14 @@ final class _dneg implements OperationInterface
1012

1113
public function execute(): void
1214
{
13-
throw new NotImplementedException(__CLASS__);
15+
$value = Extractor::getRealValue(
16+
$this->popFromOperandStack()
17+
);
18+
19+
$this->pushToOperandStack(
20+
_Double::get(
21+
BinaryTool::negate($value)
22+
)
23+
);
1424
}
1525
}

src/Kernel/Mnemonics/_dstore.php

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

4-
use PHPJava\Utilities\BinaryTool;
4+
use PHPJava\Utilities\Extractor;
55

66
final class _dstore implements OperationInterface
77
{
@@ -14,8 +14,11 @@ final class _dstore implements OperationInterface
1414
public function execute(): void
1515
{
1616
$index = $this->readUnsignedByte();
17-
$value = $this->popFromOperandStack();
17+
$value = Extractor::getRealValue($this->popFromOperandStack());
1818

19-
$this->setLocalStorage($index, BinaryTool::convertDoubleToIEEE754($value));
19+
$this->setLocalStorage(
20+
$index,
21+
$value
22+
);
2023
}
2124
}

src/Kernel/Mnemonics/_faload.php

Lines changed: 7 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\Utilities\Extractor;
55

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

1111
public function execute(): void
1212
{
13-
throw new NotImplementedException(__CLASS__);
13+
$index = Extractor::getRealValue($this->popFromOperandStack());
14+
$arrayref = $this->popFromOperandStack();
15+
16+
$this->pushToOperandStack(
17+
$arrayref[$index]
18+
);
1419
}
1520
}

src/Kernel/Mnemonics/_fastore.php

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

67
final class _fastore implements OperationInterface
78
{
@@ -10,6 +11,19 @@ final class _fastore implements OperationInterface
1011

1112
public function execute(): void
1213
{
13-
throw new NotImplementedException(__CLASS__);
14+
$value = $this->popFromOperandStack();
15+
$index = Extractor::getRealValue($this->popFromOperandStack());
16+
17+
/**
18+
* @var Type $arrayref
19+
*/
20+
$arrayref = $this->popFromOperandStack();
21+
22+
// The value is a ref.
23+
$arrayref[$index] = $value;
24+
25+
$this->pushToOperandStack(
26+
$arrayref
27+
);
1428
}
1529
}

src/Kernel/Mnemonics/_fneg.php

Lines changed: 12 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 _fneg implements OperationInterface
79
{
@@ -10,6 +12,14 @@ final class _fneg implements OperationInterface
1012

1113
public function execute(): void
1214
{
13-
throw new NotImplementedException(__CLASS__);
15+
$value = Extractor::getRealValue(
16+
$this->popFromOperandStack()
17+
);
18+
19+
$this->pushToOperandStack(
20+
_Float::get(
21+
BinaryTool::negate($value)
22+
)
23+
);
1424
}
1525
}

0 commit comments

Comments
 (0)