diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-07-07 14:58:59 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-07-07 14:58:59 +0900 |
| commit | 799f7790b9b8d1dc126eeab7e6e04327b6cfe717 (patch) | |
| tree | 9049c734cbb72cecfc7551b42e9803256690a4d0 | |
| parent | e79241c1988e7c0b3d422cdb99c9a105d0cfa903 (diff) | |
| download | php-waddiwasi-799f7790b9b8d1dc126eeab7e6e04327b6cfe717.tar.gz php-waddiwasi-799f7790b9b8d1dc126eeab7e6e04327b6cfe717.tar.zst php-waddiwasi-799f7790b9b8d1dc126eeab7e6e04327b6cfe717.zip | |
refactor: Stack
| -rw-r--r-- | src/Execution/Runtime.php | 2 | ||||
| -rw-r--r-- | src/Execution/Stack.php | 22 |
2 files changed, 9 insertions, 15 deletions
diff --git a/src/Execution/Runtime.php b/src/Execution/Runtime.php index 98893d0..2f69431 100644 --- a/src/Execution/Runtime.php +++ b/src/Execution/Runtime.php @@ -66,7 +66,7 @@ final class Runtime $moduleInstInit = $allocator->allocPreInitModule($module, $externVals); - $stack = new Stack([]); + $stack = new Stack(); $frameInit = new Frame(0, [], $moduleInstInit, 'preinit'); $stack->pushFrame($frameInit); diff --git a/src/Execution/Stack.php b/src/Execution/Stack.php index dfecfec..1e32388 100644 --- a/src/Execution/Stack.php +++ b/src/Execution/Stack.php @@ -21,11 +21,12 @@ final class Stack private ?Frame $currentFrame = null; /** - * @param list<int|float|Ref|Frame|Label> $entries + * @var list<int|float|Ref|Frame|Label> */ - public function __construct( - private array $entries, - ) { + private array $entries; + + public function __construct() + { } public function pushFrame(Frame $frame): void @@ -154,17 +155,10 @@ final class Stack public function popEntriesToCurrentFrame(): void { - while (!$this->isEmpty()) { - if ($this->pop() instanceof Frame) { - break; - } - } - array_pop($this->frames); - if (count($this->frames) === 0) { - $this->currentFrame = null; - } else { - $this->currentFrame = end($this->frames); + while (!$this->isEmpty() && !$this->top() instanceof Frame) { + $this->pop(); } + $this->popFrame(); } public function top(): int|float|Ref|Frame|Label|null |
