aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Execution
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-07-07 19:08:07 +0900
committernsfisis <nsfisis@gmail.com>2024-07-07 19:08:07 +0900
commitf815ac9998a6b9df06ae53e6d32467ebd7bdbd31 (patch)
tree77bae47e0a09dcd9213c5e768a7689370c4f7d9e /src/Execution
parent799f7790b9b8d1dc126eeab7e6e04327b6cfe717 (diff)
downloadphp-waddiwasi-f815ac9998a6b9df06ae53e6d32467ebd7bdbd31.tar.gz
php-waddiwasi-f815ac9998a6b9df06ae53e6d32467ebd7bdbd31.tar.zst
php-waddiwasi-f815ac9998a6b9df06ae53e6d32467ebd7bdbd31.zip
feat: improve API to define host funcs
Diffstat (limited to 'src/Execution')
-rw-r--r--src/Execution/Runtime.php22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/Execution/Runtime.php b/src/Execution/Runtime.php
index 2f69431..aad077a 100644
--- a/src/Execution/Runtime.php
+++ b/src/Execution/Runtime.php
@@ -30,6 +30,7 @@ use function count;
use function fdiv;
use function floor;
use function intdiv;
+use function is_array;
use function is_int;
use function is_nan;
use function max;
@@ -284,9 +285,26 @@ final class Runtime
}
}
- private function doInvokeHostFunc(FuncInsts\Host $f): void
+ private function doInvokeHostFunc(FuncInsts\Host $fn): void
{
- ($f->callback)($this);
+ $paramTypes = $fn->type->params->types;
+ $n = count($paramTypes);
+ $resultTypes = $fn->type->results->types;
+ $m = count($resultTypes);
+
+ $params = array_reverse($this->stack->popNValues($n));
+ $results = ($fn->callback)($this, ...$params);
+ if ($results === null) {
+ assert($m === 0);
+ return;
+ }
+ if (!is_array($results)) {
+ $results = [$results];
+ }
+ assert($m === count($results));
+ foreach ($results as $result) {
+ $this->stack->pushValue($result);
+ }
}
/**