diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-04-29 22:38:16 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-04-29 22:38:16 +0900 |
| commit | 50eec918e8c1f83f3e95a9cb82ed03cfd2cbb1c0 (patch) | |
| tree | f8def1cdbd781a3ba68a58bb8fe6f63c78b46c17 | |
| parent | a6e1225bdaee353f764ec471e2d613a2d5b893b0 (diff) | |
| download | php-waddiwasi-50eec918e8c1f83f3e95a9cb82ed03cfd2cbb1c0.tar.gz php-waddiwasi-50eec918e8c1f83f3e95a9cb82ed03cfd2cbb1c0.tar.zst php-waddiwasi-50eec918e8c1f83f3e95a9cb82ed03cfd2cbb1c0.zip | |
refactor
| -rw-r--r-- | src/Execution/Runtime.php | 28 |
1 files 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]); |
