Skip to content

Commit 11b6372

Browse files
committed
Implement if statement which including to generate StackMapTable feature
1 parent 7628c08 commit 11b6372

File tree

289 files changed

+6096
-1518
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

289 files changed

+6096
-1518
lines changed

docs/compiler/README-ja.md

Lines changed: 101 additions & 244 deletions
Large diffs are not rendered by default.

docs/compiler/README.md

Lines changed: 101 additions & 244 deletions
Large diffs are not rendered by default.

phpcs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
</rule>
99

1010
<rule ref="Squiz.Classes.ValidClassName.NotCamelCaps">
11+
<exclude-pattern>./src/Compiler/Emulator/Mnemonics</exclude-pattern>
1112
<exclude-pattern>./src/Compiler/Lang/Assembler/Bundler/Packages</exclude-pattern>
1213
<exclude-pattern>./src/Kernel/Types</exclude-pattern>
1314
<exclude-pattern>./src/Kernel/Mnemonics</exclude-pattern>

src/Compiler/Builder/Attribute.php

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33

44
use PHPJava\Compiler\Builder\Finder\Result\FinderResultInterface;
55
use PHPJava\Compiler\Builder\Maps\EntryMap;
6+
use PHPJava\Compiler\Lang\Assembler\Traits\ConstantPoolManageable;
7+
use PHPJava\Compiler\Lang\Assembler\Traits\Enhancer\ConstantPoolEnhanceable;
68

79
class Attribute implements BuilderInterface, EntryInterface
810
{
11+
use ConstantPoolManageable;
12+
use ConstantPoolEnhanceable;
13+
914
/**
1015
* @var string
1116
*/
@@ -26,11 +31,6 @@ class Attribute implements BuilderInterface, EntryInterface
2631
*/
2732
protected $constantPoolIndex;
2833

29-
public function __construct(FinderResultInterface $constantPoolIndex)
30-
{
31-
$this->constantPoolIndex = $constantPoolIndex;
32-
}
33-
3434
public function getConstantPoolIndex(): int
3535
{
3636
/**
@@ -67,4 +67,31 @@ public function setAttributes(array $attributes): self
6767
$this->attributes = $attributes;
6868
return $this;
6969
}
70+
71+
public function getName(): string
72+
{
73+
return current(
74+
array_slice(
75+
explode(
76+
'\\',
77+
get_class($this)
78+
),
79+
-1,
80+
1
81+
)
82+
);
83+
}
84+
85+
public function beginPrepare(): Attribute
86+
{
87+
$attributeName = $this->getName();
88+
89+
$this->getEnhancedConstantPool()
90+
->addUtf8($attributeName);
91+
92+
$this->constantPoolIndex = $this->getEnhancedConstantPool()
93+
->findUtf8($attributeName);
94+
95+
return $this;
96+
}
7097
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
namespace PHPJava\Compiler\Builder\Attributes\Architects\Frames;
3+
4+
use PHPJava\Compiler\Builder\Attributes\Architects\ArchitectInterface;
5+
6+
class AppendFrame extends FullFrame implements ArchitectInterface
7+
{
8+
public function getTag(): int
9+
{
10+
return 251 + count($this->locals);
11+
}
12+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
namespace PHPJava\Compiler\Builder\Attributes\Architects\Frames;
3+
4+
use PHPJava\Compiler\Builder\Attributes\Architects\Architect;
5+
use PHPJava\Compiler\Builder\Attributes\Architects\ArchitectInterface;
6+
7+
abstract class Frame extends Architect implements ArchitectInterface
8+
{
9+
protected $programCounter = 0;
10+
protected $branchTarget = 0;
11+
protected $locals = [];
12+
protected $stacks = [];
13+
protected $offsetDelta;
14+
15+
abstract public function getTag(): int;
16+
17+
public function setProgramCounter(int $offset): self
18+
{
19+
$this->programCounter = $offset;
20+
return $this;
21+
}
22+
23+
public function getProgramCounter(): int
24+
{
25+
return $this->programCounter;
26+
}
27+
28+
public function setBranchTarget(int $offset): self
29+
{
30+
$this->branchTarget = $offset;
31+
return $this;
32+
}
33+
34+
public function getBranchTarget(): int
35+
{
36+
return $this->branchTarget;
37+
}
38+
39+
public function getOffsetDelta(): int
40+
{
41+
return $this->offsetDelta;
42+
}
43+
44+
public function setOffsetDelta(int $offsetDelta): self
45+
{
46+
$this->offsetDelta = $offsetDelta;
47+
return $this;
48+
}
49+
50+
public function getLocals(): array
51+
{
52+
return $this->locals;
53+
}
54+
55+
public function addLocal(int $verificationType, ...$arguments): self
56+
{
57+
$this->locals[] = [$verificationType, $arguments];
58+
return $this;
59+
}
60+
61+
public function addStack(int $verificationType, ...$arguments): self
62+
{
63+
$this->stacks[] = [$verificationType, $arguments];
64+
return $this;
65+
}
66+
67+
public function setLocals(array $locals): self
68+
{
69+
$this->locals = $locals;
70+
return $this;
71+
}
72+
73+
public function setStacks(array $stacks): self
74+
{
75+
$this->stacks = $stacks;
76+
return $this;
77+
}
78+
79+
public function getStacks(): array
80+
{
81+
return $this->stacks;
82+
}
83+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
namespace PHPJava\Compiler\Builder\Attributes\Architects\Frames;
3+
4+
use PHPJava\Compiler\Builder\Attributes\Architects\ArchitectInterface;
5+
6+
class FullFrame extends Frame implements ArchitectInterface
7+
{
8+
public function getTag(): int
9+
{
10+
return 255;
11+
}
12+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
namespace PHPJava\Compiler\Builder\Attributes\Architects\Frames;
3+
4+
use PHPJava\Compiler\Builder\Attributes\Architects\ArchitectInterface;
5+
use PHPJava\Exceptions\AssembleStructureException;
6+
7+
class SameFrame extends FullFrame implements ArchitectInterface
8+
{
9+
const MIN = 0;
10+
const MAX = 63;
11+
12+
public function getTag(): int
13+
{
14+
if ($this->offsetDelta < static::MIN || $this->offsetDelta > static::MAX) {
15+
throw new AssembleStructureException(
16+
'Offset delta in SameFrame is invalid.'
17+
);
18+
}
19+
return $this->offsetDelta;
20+
}
21+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
namespace PHPJava\Compiler\Builder\Attributes\Architects\Frames;
3+
4+
use PHPJava\Compiler\Builder\Attributes\Architects\ArchitectInterface;
5+
6+
class SameFrameExtended extends FullFrame implements ArchitectInterface
7+
{
8+
public function getTag(): int
9+
{
10+
return 251;
11+
}
12+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
namespace PHPJava\Compiler\Builder\Attributes\Architects\Frames;
3+
4+
use PHPJava\Compiler\Builder\Attributes\Architects\ArchitectInterface;
5+
use PHPJava\Exceptions\AssembleStructureException;
6+
7+
class SameLocals1StackItemFrame extends FullFrame implements ArchitectInterface
8+
{
9+
const MIN = 64;
10+
const MAX = 127;
11+
12+
public function getTag(): int
13+
{
14+
if ((64 + $this->offsetDelta) < static::MIN || (64 + $this->offsetDelta) > static::MAX) {
15+
throw new AssembleStructureException(
16+
'Offset delta in SameLocals1StackItemFrame is invalid.'
17+
);
18+
}
19+
return 64 + $this->offsetDelta;
20+
}
21+
}

0 commit comments

Comments
 (0)