Skip to content

Commit 68eb9e9

Browse files
committed
Add _castore
1 parent 753f154 commit 68eb9e9

3 files changed

Lines changed: 27 additions & 7 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/_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)