From 73d19c2f4bdae0aac4ebe8303ff88f42a9e59978 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 2 Jun 2024 04:41:59 +0900 Subject: test: add more trap kind --- src/Execution/Runtime.php | 26 ++++++++++++++++---------- src/Execution/TrapKind.php | 1 + 2 files changed, 17 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/Execution/Runtime.php b/src/Execution/Runtime.php index ade7cf1..5b97be3 100644 --- a/src/Execution/Runtime.php +++ b/src/Execution/Runtime.php @@ -955,8 +955,11 @@ final class Runtime { $c2 = $this->stack->popInt(); $c1 = $this->stack->popInt(); - if ($c2 === 0 || ($c1 === PHP_INT_MIN && $c2 === -1)) { - throw new TrapException("i32.div_s: divide by zero or overflow"); + if ($c2 === 0) { + throw new TrapException("i32.div_s: divide by zero", trapKind: TrapKind::DivideByZero); + } + if ($c1 === PHP_INT_MIN && $c2 === -1) { + throw new TrapException("i32.div_s: overflow"); } $this->stack->pushValue(intdiv($c1, $c2)); } @@ -966,7 +969,7 @@ final class Runtime $c2 = $this->stack->popInt(); $c1 = $this->stack->popInt(); if ($c2 === 0) { - throw new TrapException("i32.div_u: divide by zero"); + throw new TrapException("i32.div_u: divide by zero", trapKind: TrapKind::DivideByZero); } $this->stack->pushValue(intdiv($c1, $c2)); } @@ -1107,8 +1110,11 @@ final class Runtime { $c2 = $this->stack->popInt(); $c1 = $this->stack->popInt(); - if ($c2 === 0 || ($c1 === PHP_INT_MIN && $c2 === -1)) { - throw new TrapException("i32.rem_s: divide by zero or overflow"); + if ($c2 === 0) { + throw new TrapException("i32.rem_s: divide by zero or overflow", trapKind: TrapKind::DivideByZero); + } + if ($c1 === PHP_INT_MIN && $c2 === -1) { + throw new TrapException("i32.rem_s: divide by zero or overflow", trapKind: TrapKind::DivideByZero); } $this->stack->pushValue($c1 % $c2); } @@ -1118,7 +1124,7 @@ final class Runtime $c2 = $this->stack->popInt(); $c1 = $this->stack->popInt(); if ($c2 === 0) { - throw new TrapException("i32.rem_u: divide by zero"); + throw new TrapException("i32.rem_u: divide by zero", trapKind: TrapKind::DivideByZero); } $this->stack->pushValue($c1 % $c2); } @@ -1327,7 +1333,7 @@ final class Runtime $c2 = $this->stack->popInt(); $c1 = $this->stack->popInt(); if ($c2 === 0) { - throw new TrapException("i64.div_s: divide by zero"); + throw new TrapException("i64.div_s: divide by zero", trapKind: TrapKind::DivideByZero); } $this->stack->pushValue(intdiv($c1, $c2)); } @@ -1337,7 +1343,7 @@ final class Runtime $c2 = $this->stack->popInt(); $c1 = $this->stack->popInt(); if ($c2 === 0) { - throw new TrapException("i64.div_u: divide by zero"); + throw new TrapException("i64.div_u: divide by zero", trapKind: TrapKind::DivideByZero); } $this->stack->pushValue(intdiv($c1, $c2)); } @@ -1510,7 +1516,7 @@ final class Runtime $c2 = $this->stack->popInt(); $c1 = $this->stack->popInt(); if ($c2 === 0) { - throw new TrapException("i64.rem_s: divide by zero"); + throw new TrapException("i64.rem_s: divide by zero", trapKind: TrapKind::DivideByZero); } $this->stack->pushValue($c1 % $c2); } @@ -1520,7 +1526,7 @@ final class Runtime $c2 = $this->stack->popInt(); $c1 = $this->stack->popInt(); if ($c2 === 0) { - throw new TrapException("i64.rem_u: divide by zero"); + throw new TrapException("i64.rem_u: divide by zero", trapKind: TrapKind::DivideByZero); } $this->stack->pushValue($c1 % $c2); } diff --git a/src/Execution/TrapKind.php b/src/Execution/TrapKind.php index c44747d..5cdc480 100644 --- a/src/Execution/TrapKind.php +++ b/src/Execution/TrapKind.php @@ -13,4 +13,5 @@ enum TrapKind case UninitializedElement; case IndirectCallTypeMismatch; case UndefinedElement; + case DivideByZero; } -- cgit v1.2.3-70-g09d2