From 900377463a8264871ee42e488112b076b7973b6a Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 27 Jan 2024 13:22:56 +0900 Subject: feat: partially implement execution --- src/Execution/Stack.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/Execution/Stack.php (limited to 'src/Execution/Stack.php') diff --git a/src/Execution/Stack.php b/src/Execution/Stack.php new file mode 100644 index 0000000..1fa2dae --- /dev/null +++ b/src/Execution/Stack.php @@ -0,0 +1,42 @@ + $entries + */ + public function __construct( + private array $entries, + ) { + } + + public function push(StackEntry $entry): void + { + $this->entries[] = $entry; + } + + public function pop(): ?StackEntry + { + return array_pop($this->entries); + } + + public function top(): ?StackEntry + { + $n = array_key_last($this->entries); + return $n === null ? null : $this->entries[$n]; + } + + public function count(): int + { + return count($this->entries); + } + + public function isEmpty(): bool + { + return $this->count() === 0; + } +} -- cgit v1.2.3-70-g09d2