From 50eec918e8c1f83f3e95a9cb82ed03cfd2cbb1c0 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 29 Apr 2024 22:38:16 +0900 Subject: refactor --- src/Execution/Runtime.php | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/Execution/Runtime.php b/src/Execution/Runtime.php index 55fbbfb..72fbd82 100644 --- a/src/Execution/Runtime.php +++ b/src/Execution/Runtime.php @@ -19,9 +19,22 @@ use Nsfisis\Waddiwasi\Structure\Types\TableType; use Nsfisis\Waddiwasi\Structure\Types\ValType; use Nsfisis\Waddiwasi\Structure\Types\ValTypes; use RuntimeException; +use function abs; +use function array_map; +use function array_merge; +use function array_reverse; use function assert; +use function ceil; use function count; +use function floor; +use function intdiv; use function is_int; +use function max; +use function min; +use function pack; +use function round; +use function sqrt; +use function unpack; final class Runtime { @@ -184,10 +197,7 @@ final class Runtime $this->stack->pushValue($val); } $this->doInvokeFunc($funcAddr); - $results = []; - for ($i = 0; $i < count($resultTypes); $i++) { - $results[] = $this->stack->popValue(); - } + $results = $this->stack->popNValues(count($resultTypes)); $this->stack->popFrame(); return array_reverse($results); } @@ -216,10 +226,7 @@ final class Runtime $resultTypes = $fn->type->results->types; $m = count($resultTypes); $ts = $fn->code->locals; - $vals = []; - for ($i = 0; $i < $n; $i++) { - $vals[] = $this->stack->popValue(); - } + $vals = $this->stack->popNValues($n); $f = new Frame( $m, array_merge( @@ -242,10 +249,7 @@ final class Runtime private function deactivateFrame(int $arity): void { - $vals = []; - for ($i = 0; $i < $arity; $i++) { - $vals[] = $this->stack->popValue(); - } + $vals = $this->stack->popNValues($arity); $this->stack->popEntriesToCurrentFrame(); for ($i = $arity - 1; 0 <= $i; $i--) { $this->stack->pushValue($vals[$i]); -- cgit v1.2.3-70-g09d2