Skip to content

Commit a0b448f

Browse files
committed
Refactor
1 parent a960843 commit a0b448f

Some content is hidden

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

42 files changed

+525
-1304
lines changed

phpstan.neon

-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,5 @@ parameters:
66
checkGenericClassInNonGenericObjectType: false
77
ignoreErrors:
88
- '#[^:]+::__debugInfo\(\) return type has no value type specified in iterable type array#'
9-
- '#Class [^\s]+ has an uninitialized readonly property \$.+?\. Assign it in the constructor#'
10-
- '#Readonly property [^\s]+ is assigned outside of the constructor#'
119
- '#Attribute class [^\s]+ does not have a constructor and must be instantiated without any parameters#'
1210
- '#Unsafe usage of new static#'
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace RubyVM\VM\Core\Helper;
6+
7+
use RubyVM\VM\Exception\NotFoundEnumValueException;
8+
9+
trait EnumNameFindable
10+
{
11+
public static function find(string $name): self
12+
{
13+
foreach (self::cases() as $case) {
14+
if ($case->name === $name) {
15+
return $case;
16+
}
17+
}
18+
19+
throw new NotFoundEnumValueException(sprintf('Unknown case name %s#%s', self::class, $name));
20+
}
21+
}

src/VM/Core/Runtime/Essential/KernelInterface.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,28 @@ public function loadInstructionSequence(Aux $aux): InstructionSequence;
3333

3434
public function extraData(): string;
3535

36-
public function rubyPlatform(): string;
36+
public function rubyPlatform(): ?string;
3737

3838
public function minorVersion(): int;
3939

4040
public function majorVersion(): int;
4141

42+
public function size(): int;
43+
44+
public function extraSize(): int;
45+
4246
public function userlandHeapSpace(): UserlandHeapSpaceInterface;
4347

48+
public function magic(): string;
49+
4450
public function instructionSequenceListSize(): int;
4551

4652
public function instructionSequenceListOffset(): int;
4753

54+
public function globalObjectListSize(): int;
55+
56+
public function globalObjectListOffset(): int;
57+
4858
public function instructionSequenceList(): Offsets;
4959

5060
public function operationProcessorEntries(): OperationProcessorEntries;

src/VM/Core/Runtime/Essential/RuntimeInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface RuntimeInterface
88
{
99
public function rubyVersion(): string;
1010

11-
public function rubyPlatform(): string;
11+
public function rubyPlatform(): ?string;
1212

1313
public function extraData(): string;
1414

src/VM/Core/Runtime/Executor/Debugger/DefaultExecutorDebugger.php

+8-19
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
use RubyVM\VM\Core\Runtime\Executor\ExecutedResult;
1010
use RubyVM\VM\Core\Runtime\Executor\Insn\InsnInterface;
1111
use RubyVM\VM\Core\Runtime\Executor\Operation\Operand;
12-
use RubyVM\VM\Core\Runtime\Kernel\Ruby3_2\InstructionSequence\Insn as Ruby3_2_Insn;
13-
use RubyVM\VM\Core\Runtime\Kernel\Ruby3_3\InstructionSequence\Insn as Ruby3_3_Insn;
1412
use RubyVM\VM\Core\YARV\Criterion\InstructionSequence\CallInfoInterface;
1513
use RubyVM\VM\Exception\RubyVMException;
1614
use Symfony\Component\Console\Helper\Table;
@@ -112,24 +110,15 @@ private function makeDetails(InsnInterface $insn, ContextInterface $context): ?s
112110
{
113111
$context = $context->createSnapshot();
114112

115-
// TODO: Rewrite here to depending on running kernel, but here is hard coded.
116113
return match ($insn) {
117-
Ruby3_2_Insn::SEND,
118-
Ruby3_2_Insn::OPT_SEND_WITHOUT_BLOCK,
119-
Ruby3_3_Insn::SEND,
120-
Ruby3_3_Insn::OPT_SEND_WITHOUT_BLOCK => $this->debugCallMethod($context),
121-
Ruby3_2_Insn::GETLOCAL,
122-
Ruby3_2_Insn::GETLOCAL_WC_0,
123-
Ruby3_2_Insn::GETLOCAL_WC_1,
124-
Ruby3_2_Insn::SETLOCAL,
125-
Ruby3_2_Insn::SETLOCAL_WC_0,
126-
Ruby3_2_Insn::SETLOCAL_WC_1,
127-
Ruby3_3_Insn::GETLOCAL,
128-
Ruby3_3_Insn::GETLOCAL_WC_0,
129-
Ruby3_3_Insn::GETLOCAL_WC_1,
130-
Ruby3_3_Insn::SETLOCAL,
131-
Ruby3_3_Insn::SETLOCAL_WC_0,
132-
Ruby3_3_Insn::SETLOCAL_WC_1 => $this->debugLocalVariable($context),
114+
$insn::find('SEND'),
115+
$insn::find('OPT_SEND_WITHOUT_BLOCK') => $this->debugCallMethod($context),
116+
$insn::find('GETLOCAL'),
117+
$insn::find('GETLOCAL_WC_0'),
118+
$insn::find('GETLOCAL_WC_1'),
119+
$insn::find('SETLOCAL'),
120+
$insn::find('SETLOCAL_WC_0'),
121+
$insn::find('SETLOCAL_WC_1') => $this->debugLocalVariable($context),
133122
default => null,
134123
};
135124
}

src/VM/Core/Runtime/Executor/Insn/InsnInterface.php

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ interface InsnInterface
88
{
99
public static function of(int $value): self;
1010

11+
public static function find(string $name): self;
12+
1113
public function name(): string;
1214

1315
public function value(): int;

src/VM/Core/Runtime/Kernel/Ruby3_2/HeapSpace/DefaultInstanceHeapSpace.php renamed to src/VM/Core/Runtime/Kernel/Ruby3/HeapSpace/DefaultInstanceHeapSpace.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace RubyVM\VM\Core\Runtime\Kernel\Ruby3_2\HeapSpace;
5+
namespace RubyVM\VM\Core\Runtime\Kernel\Ruby3\HeapSpace;
66

77
use RubyVM\VM\Core\Runtime\Attribute\BindAliasAs;
88
use RubyVM\VM\Core\Runtime\UserlandHeapSpace;

src/VM/Core/Runtime/Kernel/Ruby3_2/Internal/Arithmetic.php renamed to src/VM/Core/Runtime/Kernel/Ruby3/Internal/Arithmetic.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace RubyVM\VM\Core\Runtime\Kernel\Ruby3_2\Internal;
5+
namespace RubyVM\VM\Core\Runtime\Kernel\Ruby3\Internal;
66

77
class Arithmetic
88
{

0 commit comments

Comments
 (0)