From d33b1cc0416b8f0b05efcd2fad5200fd1db998a1 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 6 Apr 2025 02:31:47 +0900 Subject: refactor: add Runtime::instantiateFromStream() --- src/WebAssembly/Execution/Runtime.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/WebAssembly') diff --git a/src/WebAssembly/Execution/Runtime.php b/src/WebAssembly/Execution/Runtime.php index 1bb440b..a120d7d 100644 --- a/src/WebAssembly/Execution/Runtime.php +++ b/src/WebAssembly/Execution/Runtime.php @@ -4,6 +4,8 @@ declare(strict_types=1); namespace Nsfisis\Waddiwasi\WebAssembly\Execution; +use Nsfisis\Waddiwasi\Stream\StreamInterface; +use Nsfisis\Waddiwasi\WebAssembly\BinaryFormat\Decoder; use Nsfisis\Waddiwasi\WebAssembly\Structure\Instructions\Instr; use Nsfisis\Waddiwasi\WebAssembly\Structure\Instructions\Instrs; use Nsfisis\Waddiwasi\WebAssembly\Structure\Instructions\Instrs\Control\BlockType; @@ -125,6 +127,16 @@ final class Runtime implements ExporterInterface return new self($store, $stack, $moduleInst); } + public static function instantiateFromStream( + StreamInterface $stream, + Linker $linker, + ): self { + return self::instantiate( + (new Decoder($stream))->decode(), + $linker, + ); + } + public function exports(): array { return $this->module->exports; -- cgit v1.2.3-70-g09d2