Skip to content

Commit

Permalink
Merge pull request #47 from m3m0r7/refactor-5
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
m3m0r7 authored Dec 28, 2023
2 parents a960843 + a0b448f commit a568cab
Show file tree
Hide file tree
Showing 42 changed files with 525 additions and 1,304 deletions.
2 changes: 0 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@ parameters:
checkGenericClassInNonGenericObjectType: false
ignoreErrors:
- '#[^:]+::__debugInfo\(\) return type has no value type specified in iterable type array#'
- '#Class [^\s]+ has an uninitialized readonly property \$.+?\. Assign it in the constructor#'
- '#Readonly property [^\s]+ is assigned outside of the constructor#'
- '#Attribute class [^\s]+ does not have a constructor and must be instantiated without any parameters#'
- '#Unsafe usage of new static#'
21 changes: 21 additions & 0 deletions src/VM/Core/Helper/EnumNameFindable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace RubyVM\VM\Core\Helper;

use RubyVM\VM\Exception\NotFoundEnumValueException;

trait EnumNameFindable
{
public static function find(string $name): self
{
foreach (self::cases() as $case) {
if ($case->name === $name) {
return $case;
}
}

throw new NotFoundEnumValueException(sprintf('Unknown case name %s#%s', self::class, $name));
}
}
12 changes: 11 additions & 1 deletion src/VM/Core/Runtime/Essential/KernelInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,28 @@ public function loadInstructionSequence(Aux $aux): InstructionSequence;

public function extraData(): string;

public function rubyPlatform(): string;
public function rubyPlatform(): ?string;

public function minorVersion(): int;

public function majorVersion(): int;

public function size(): int;

public function extraSize(): int;

public function userlandHeapSpace(): UserlandHeapSpaceInterface;

public function magic(): string;

public function instructionSequenceListSize(): int;

public function instructionSequenceListOffset(): int;

public function globalObjectListSize(): int;

public function globalObjectListOffset(): int;

public function instructionSequenceList(): Offsets;

public function operationProcessorEntries(): OperationProcessorEntries;
Expand Down
2 changes: 1 addition & 1 deletion src/VM/Core/Runtime/Essential/RuntimeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface RuntimeInterface
{
public function rubyVersion(): string;

public function rubyPlatform(): string;
public function rubyPlatform(): ?string;

public function extraData(): string;

Expand Down
27 changes: 8 additions & 19 deletions src/VM/Core/Runtime/Executor/Debugger/DefaultExecutorDebugger.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
use RubyVM\VM\Core\Runtime\Executor\ExecutedResult;
use RubyVM\VM\Core\Runtime\Executor\Insn\InsnInterface;
use RubyVM\VM\Core\Runtime\Executor\Operation\Operand;
use RubyVM\VM\Core\Runtime\Kernel\Ruby3_2\InstructionSequence\Insn as Ruby3_2_Insn;
use RubyVM\VM\Core\Runtime\Kernel\Ruby3_3\InstructionSequence\Insn as Ruby3_3_Insn;
use RubyVM\VM\Core\YARV\Criterion\InstructionSequence\CallInfoInterface;
use RubyVM\VM\Exception\RubyVMException;
use Symfony\Component\Console\Helper\Table;
Expand Down Expand Up @@ -112,24 +110,15 @@ private function makeDetails(InsnInterface $insn, ContextInterface $context): ?s
{
$context = $context->createSnapshot();

// TODO: Rewrite here to depending on running kernel, but here is hard coded.
return match ($insn) {
Ruby3_2_Insn::SEND,
Ruby3_2_Insn::OPT_SEND_WITHOUT_BLOCK,
Ruby3_3_Insn::SEND,
Ruby3_3_Insn::OPT_SEND_WITHOUT_BLOCK => $this->debugCallMethod($context),
Ruby3_2_Insn::GETLOCAL,
Ruby3_2_Insn::GETLOCAL_WC_0,
Ruby3_2_Insn::GETLOCAL_WC_1,
Ruby3_2_Insn::SETLOCAL,
Ruby3_2_Insn::SETLOCAL_WC_0,
Ruby3_2_Insn::SETLOCAL_WC_1,
Ruby3_3_Insn::GETLOCAL,
Ruby3_3_Insn::GETLOCAL_WC_0,
Ruby3_3_Insn::GETLOCAL_WC_1,
Ruby3_3_Insn::SETLOCAL,
Ruby3_3_Insn::SETLOCAL_WC_0,
Ruby3_3_Insn::SETLOCAL_WC_1 => $this->debugLocalVariable($context),
$insn::find('SEND'),
$insn::find('OPT_SEND_WITHOUT_BLOCK') => $this->debugCallMethod($context),
$insn::find('GETLOCAL'),
$insn::find('GETLOCAL_WC_0'),
$insn::find('GETLOCAL_WC_1'),
$insn::find('SETLOCAL'),
$insn::find('SETLOCAL_WC_0'),
$insn::find('SETLOCAL_WC_1') => $this->debugLocalVariable($context),
default => null,
};
}
Expand Down
2 changes: 2 additions & 0 deletions src/VM/Core/Runtime/Executor/Insn/InsnInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ interface InsnInterface
{
public static function of(int $value): self;

public static function find(string $name): self;

public function name(): string;

public function value(): int;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace RubyVM\VM\Core\Runtime\Kernel\Ruby3_2\HeapSpace;
namespace RubyVM\VM\Core\Runtime\Kernel\Ruby3\HeapSpace;

use RubyVM\VM\Core\Runtime\Attribute\BindAliasAs;
use RubyVM\VM\Core\Runtime\UserlandHeapSpace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace RubyVM\VM\Core\Runtime\Kernel\Ruby3_2\Internal;
namespace RubyVM\VM\Core\Runtime\Kernel\Ruby3\Internal;

class Arithmetic
{
Expand Down
Loading

0 comments on commit a568cab

Please sign in to comment.