Skip to content

Commit 10589d6

Browse files
committed
Fix StackMapTable problems
1 parent 4fad288 commit 10589d6

File tree

10 files changed

+51
-35
lines changed

10 files changed

+51
-35
lines changed

src/Compiler/Builder/Attributes/Architects/Frames/Frame.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ public function getLocals(): array
5454

5555
public function addLocal(int $verificationType, ...$arguments): self
5656
{
57-
$this->locals[] = [$verificationType, $arguments];
57+
$this->locals[] = array_merge([$verificationType], $arguments);
5858
return $this;
5959
}
6060

6161
public function addStack(int $verificationType, ...$arguments): self
6262
{
63-
$this->stacks[] = [$verificationType, $arguments];
63+
$this->stacks[] = array_merge([$verificationType], $arguments);
6464
return $this;
6565
}
6666

src/Compiler/Builder/Attributes/StackMapTable.php

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use PHPJava\Core\JVM\Stream\BinaryWriter;
1919
use PHPJava\Exceptions\AssembleStructureException;
2020
use PHPJava\Kernel\Maps\VerificationTypeTag;
21-
use PHPJava\Kernel\Resolvers\TypeResolver;
2221
use PHPJava\Kernel\Types\_Byte;
2322
use PHPJava\Kernel\Types\_Char;
2423
use PHPJava\Kernel\Types\_Float;
@@ -93,21 +92,6 @@ public function getValue(): string
9392
$emulatedAccumulator = new Accumulator();
9493
$currentOffset = 0;
9594

96-
foreach ($this->getStore()->getAll() as $localStorage) {
97-
[$localStorageIndex, $type] = $localStorage;
98-
[$verificationTypeTag, $objectClassType] = TypeResolver::getVerificationTypeTagByKernelType($type);
99-
$emulatedAccumulator->setToLocal(
100-
$localStorageIndex,
101-
[
102-
$verificationTypeTag,
103-
$objectClassType !== null
104-
? $this->getEnhancedConstantPool()
105-
->findClass($objectClassType)
106-
: null,
107-
]
108-
);
109-
}
110-
11195
foreach ($this->operations as $operation) {
11296
$programCounter = $this->calculateProgramCounterByOperationCodes(
11397
$this->operations,
@@ -141,7 +125,7 @@ public function getValue(): string
141125
usort(
142126
$entries,
143127
static function (FullFrame $a, FullFrame $b) {
144-
return $a->getBranchTarget() - $b->getBranchTarget();
128+
return $a->getBranchTarget() <=> $b->getBranchTarget();
145129
}
146130
);
147131

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
<?php
22
namespace PHPJava\Compiler\Emulator\Mnemonics;
33

4+
use PHPJava\Kernel\Maps\VerificationTypeTag;
5+
46
class _aload_0 extends AbstractOperationCode implements OperationCodeInterface
57
{
68
use \PHPJava\Compiler\Emulator\Traits\GeneralProcessor;
79

810
public function execute(): void
911
{
1012
$this->accumulator->pushToOperandStack(
11-
$this->accumulator
12-
->getFromLocal(0)
13+
[
14+
VerificationTypeTag::ITEM_Object,
15+
$this->getEnhancedConstantPool()
16+
->findClass(\PHPJava\Packages\java\lang\_String::class),
17+
]
1318
);
1419
}
1520
}
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
<?php
22
namespace PHPJava\Compiler\Emulator\Mnemonics;
33

4+
use PHPJava\Kernel\Maps\VerificationTypeTag;
5+
46
class _aload_1 extends AbstractOperationCode implements OperationCodeInterface
57
{
68
use \PHPJava\Compiler\Emulator\Traits\GeneralProcessor;
79

810
public function execute(): void
911
{
1012
$this->accumulator->pushToOperandStack(
11-
$this->accumulator
12-
->getFromLocal(0)
13+
[
14+
VerificationTypeTag::ITEM_Object,
15+
$this->getEnhancedConstantPool()
16+
->findClass(\PHPJava\Packages\java\lang\_String::class),
17+
]
1318
);
1419
}
1520
}
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
<?php
22
namespace PHPJava\Compiler\Emulator\Mnemonics;
33

4+
use PHPJava\Kernel\Maps\VerificationTypeTag;
5+
46
class _aload_2 extends AbstractOperationCode implements OperationCodeInterface
57
{
68
use \PHPJava\Compiler\Emulator\Traits\GeneralProcessor;
79

810
public function execute(): void
911
{
1012
$this->accumulator->pushToOperandStack(
11-
$this->accumulator
12-
->getFromLocal(0)
13+
[
14+
VerificationTypeTag::ITEM_Object,
15+
$this->getEnhancedConstantPool()
16+
->findClass(\PHPJava\Packages\java\lang\_String::class),
17+
]
1318
);
1419
}
1520
}
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
<?php
22
namespace PHPJava\Compiler\Emulator\Mnemonics;
33

4+
use PHPJava\Kernel\Maps\VerificationTypeTag;
5+
46
class _aload_3 extends AbstractOperationCode implements OperationCodeInterface
57
{
68
use \PHPJava\Compiler\Emulator\Traits\GeneralProcessor;
79

810
public function execute(): void
911
{
1012
$this->accumulator->pushToOperandStack(
11-
$this->accumulator
12-
->getFromLocal(0)
13+
[
14+
VerificationTypeTag::ITEM_Object,
15+
$this->getEnhancedConstantPool()
16+
->findClass(\PHPJava\Packages\java\lang\_String::class),
17+
]
1318
);
1419
}
1520
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
<?php
22
namespace PHPJava\Compiler\Emulator\Mnemonics;
33

4+
use PHPJava\Kernel\Maps\VerificationTypeTag;
5+
46
class _iload_0 extends AbstractOperationCode implements OperationCodeInterface
57
{
68
use \PHPJava\Compiler\Emulator\Traits\GeneralProcessor;
79

810
public function execute(): void
911
{
1012
$this->accumulator->pushToOperandStack(
11-
$this->accumulator
12-
->getFromLocal(0)
13+
[
14+
VerificationTypeTag::ITEM_Integer,
15+
]
1316
);
1417
}
1518
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
<?php
22
namespace PHPJava\Compiler\Emulator\Mnemonics;
33

4+
use PHPJava\Kernel\Maps\VerificationTypeTag;
5+
46
class _iload_1 extends AbstractOperationCode implements OperationCodeInterface
57
{
68
use \PHPJava\Compiler\Emulator\Traits\GeneralProcessor;
79

810
public function execute(): void
911
{
1012
$this->accumulator->pushToOperandStack(
11-
$this->accumulator
12-
->getFromLocal(1)
13+
[
14+
VerificationTypeTag::ITEM_Integer,
15+
]
1316
);
1417
}
1518
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
<?php
22
namespace PHPJava\Compiler\Emulator\Mnemonics;
33

4+
use PHPJava\Kernel\Maps\VerificationTypeTag;
5+
46
class _iload_2 extends AbstractOperationCode implements OperationCodeInterface
57
{
68
use \PHPJava\Compiler\Emulator\Traits\GeneralProcessor;
79

810
public function execute(): void
911
{
1012
$this->accumulator->pushToOperandStack(
11-
$this->accumulator
12-
->getFromLocal(2)
13+
[
14+
VerificationTypeTag::ITEM_Integer,
15+
]
1316
);
1417
}
1518
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
<?php
22
namespace PHPJava\Compiler\Emulator\Mnemonics;
33

4+
use PHPJava\Kernel\Maps\VerificationTypeTag;
5+
46
class _iload_3 extends AbstractOperationCode implements OperationCodeInterface
57
{
68
use \PHPJava\Compiler\Emulator\Traits\GeneralProcessor;
79

810
public function execute(): void
911
{
1012
$this->accumulator->pushToOperandStack(
11-
$this->accumulator
12-
->getFromLocal(3)
13+
[
14+
VerificationTypeTag::ITEM_Integer,
15+
]
1316
);
1417
}
1518
}

0 commit comments

Comments
 (0)