-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed interpreter constructor, runtime result, debugger interface
- Loading branch information
Showing
14 changed files
with
278 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace GoPhp; | ||
|
||
use GoPhp\Error\PanicError; | ||
|
||
use function count; | ||
use function array_shift; | ||
|
||
final class CallStackCollectorDebugger implements Debugger | ||
{ | ||
public const DEFAULT_STACK_TRACE_DEPTH = 128; | ||
|
||
/** @var list<InvokableCall|PanicError> */ | ||
private array $stackTrace = []; | ||
|
||
public function __construct( | ||
private readonly bool $enableDebug = true, | ||
private readonly int $maxTraceDepth = self::DEFAULT_STACK_TRACE_DEPTH, | ||
) {} | ||
|
||
public function addStackTrace(InvokableCall|PanicError $call): void | ||
{ | ||
if (!$this->enableDebug) { | ||
return; | ||
} | ||
|
||
$this->stackTrace[] = $call; | ||
|
||
if (count($this->stackTrace) > $this->maxTraceDepth) { | ||
array_shift($this->stackTrace); | ||
} | ||
} | ||
|
||
/** | ||
* @return list<InvokableCall|PanicError> | ||
*/ | ||
public function getStackTrace(): array | ||
{ | ||
return $this->stackTrace; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace GoPhp; | ||
|
||
use GoPhp\Error\PanicError; | ||
|
||
interface Debugger | ||
{ | ||
public function addStackTrace(InvokableCall|PanicError $call): void; | ||
|
||
/** | ||
* @return list<InvokableCall|PanicError> | ||
*/ | ||
public function getStackTrace(): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.