From 9b45796547c8022b98a9254320323d72aecd81cb Mon Sep 17 00:00:00 2001 From: nsfisis Date: Fri, 15 Mar 2024 19:02:22 +0900 Subject: refactor: remove Expr class --- src/BinaryFormat/Code.php | 5 +++-- src/BinaryFormat/Decoder.php | 16 +++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) (limited to 'src/BinaryFormat') diff --git a/src/BinaryFormat/Code.php b/src/BinaryFormat/Code.php index cb0dbe6..6acf1e7 100644 --- a/src/BinaryFormat/Code.php +++ b/src/BinaryFormat/Code.php @@ -4,16 +4,17 @@ declare(strict_types=1); namespace Nsfisis\Waddiwasi\BinaryFormat; -use Nsfisis\Waddiwasi\Structure\Instructions\Expr; +use Nsfisis\Waddiwasi\Structure\Instructions\Instr; final readonly class Code { /** * @param list $compressedLocals + * @param list $body */ public function __construct( public array $compressedLocals, - public Expr $body, + public array $body, ) { } } diff --git a/src/BinaryFormat/Decoder.php b/src/BinaryFormat/Decoder.php index 24089d0..30c5b56 100644 --- a/src/BinaryFormat/Decoder.php +++ b/src/BinaryFormat/Decoder.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Nsfisis\Waddiwasi\BinaryFormat; -use Nsfisis\Waddiwasi\Structure\Instructions\Expr; use Nsfisis\Waddiwasi\Structure\Instructions\Instr; use Nsfisis\Waddiwasi\Structure\Instructions\Instrs; use Nsfisis\Waddiwasi\Structure\Instructions\Instrs\Control\BlockType; @@ -434,7 +433,7 @@ final class Decoder return new Elem( RefType::FuncRef, array_map( - fn ($funcRef) => new Expr([Instr::RefFunc($funcRef)]), + fn ($funcRef) => [Instr::RefFunc($funcRef)], $initFuncRefs, ), ElemMode::Active(0, $offset), @@ -445,7 +444,7 @@ final class Decoder return new Elem( $refType, array_map( - fn ($funcRef) => new Expr([Instr::RefFunc($funcRef)]), + fn ($funcRef) => [Instr::RefFunc($funcRef)], $initFuncRefs, ), ElemMode::Passive(), @@ -458,7 +457,7 @@ final class Decoder return new Elem( $refType, array_map( - fn ($funcRef) => new Expr([Instr::RefFunc($funcRef)]), + fn ($funcRef) => [Instr::RefFunc($funcRef)], $initFuncRefs, ), ElemMode::Active($table, $offset), @@ -469,7 +468,7 @@ final class Decoder return new Elem( $refType, array_map( - fn ($funcRef) => new Expr([Instr::RefFunc($funcRef)]), + fn ($funcRef) => [Instr::RefFunc($funcRef)], $initFuncRefs, ), ElemMode::Declarative(), @@ -650,9 +649,12 @@ final class Decoder return $this->decodeU32(); } - private function decodeExpr(): Expr + /** + * @return list + */ + private function decodeExpr(): array { - return new Expr($this->decodeInstrsUntil([Instrs\Control\End::class])[0]); + return $this->decodeInstrsUntil([Instrs\Control\End::class])[0]; } private function decodeInstr(): Instr -- cgit v1.2.3-70-g09d2