Skip to content

Commit 1fe3fc5

Browse files
authored
Merge pull request #98 from php-java/add-mnemonic
Add mnemonics
2 parents e91092f + 68eb9e9 commit 1fe3fc5

8 files changed

Lines changed: 33 additions & 12 deletions

File tree

src/Kernel/Mnemonics/_castore.php

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

79
final class _castore implements OperationInterface
810
{
@@ -11,6 +13,19 @@ final class _castore implements OperationInterface
1113

1214
public function execute(): void
1315
{
14-
throw new NotImplementedException(__CLASS__);
16+
$value = Extractor::realValue($this->popFromOperandStack());
17+
$index = Extractor::realValue($this->popFromOperandStack());
18+
19+
/**
20+
* @var Type $arrayref
21+
*/
22+
$arrayref = $this->popFromOperandStack();
23+
24+
// The value is a ref.
25+
$arrayref[$index] = chr($value);
26+
27+
$this->pushToOperandStack(
28+
$arrayref
29+
);
1530
}
1631
}

src/Kernel/Mnemonics/_fstore.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ final class _fstore implements OperationInterface
1111

1212
public function execute(): void
1313
{
14-
throw new NotImplementedException(__CLASS__);
14+
$index = $this->readUnsignedByte();
15+
$this->setLocalStorage($index, $this->popFromOperandStack());
1516
}
1617
}

src/Kernel/Mnemonics/_fstore_0.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ final class _fstore_0 implements OperationInterface
1111

1212
public function execute(): void
1313
{
14-
throw new NotImplementedException(__CLASS__);
14+
$this->setLocalStorage(0, $this->popFromOperandStack());
1515
}
1616
}

src/Kernel/Mnemonics/_fstore_1.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ final class _fstore_1 implements OperationInterface
1111

1212
public function execute(): void
1313
{
14-
throw new NotImplementedException(__CLASS__);
14+
$this->setLocalStorage(1, $this->popFromOperandStack());
1515
}
1616
}

src/Kernel/Mnemonics/_fstore_2.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ final class _fstore_2 implements OperationInterface
1111

1212
public function execute(): void
1313
{
14-
throw new NotImplementedException(__CLASS__);
14+
$this->setLocalStorage(2, $this->popFromOperandStack());
1515
}
1616
}

src/Kernel/Mnemonics/_fstore_3.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ final class _fstore_3 implements OperationInterface
1111

1212
public function execute(): void
1313
{
14-
throw new NotImplementedException(__CLASS__);
14+
$this->setLocalStorage(3, $this->popFromOperandStack());
1515
}
1616
}

src/Kernel/Mnemonics/_iastore.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ final class _iastore implements OperationInterface
1414

1515
public function execute(): void
1616
{
17-
$data = Extractor::realValue($this->popFromOperandStack());
18-
$arrayref = Extractor::realValue($this->popFromOperandStack());
17+
$value = Extractor::realValue($this->popFromOperandStack());
18+
$index = Extractor::realValue($this->popFromOperandStack());
1919

2020
/**
21-
* @var Type $value
21+
* @var Type $arrayref
2222
*/
23-
$value = $this->popFromOperandStack();
23+
$arrayref = $this->popFromOperandStack();
2424

2525
// The value is a ref.
26-
$value[$arrayref] = $data;
26+
$arrayref[$index] = $value;
2727

2828
$this->pushToOperandStack(
29-
$value
29+
$arrayref
3030
);
3131
}
3232
}

src/Kernel/Types/_Array/Collection.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ public function getType($default = null): ?string
2525
) ?? $default;
2626
}
2727

28+
public function __toString()
29+
{
30+
return implode($this->data);
31+
}
32+
2833
public function toArray()
2934
{
3035
return $this->data;

0 commit comments

Comments
 (0)