diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-07-13 19:50:37 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-07-13 20:16:41 +0900 |
| commit | 45104a43293c4344074b4abc8cc5e279a1e78fba (patch) | |
| tree | 07e65df83b64c1568545c05113399d34ba291f1b /src | |
| parent | f26f497131923886889deb4b843b179518888b1f (diff) | |
| download | php-waddiwasi-45104a43293c4344074b4abc8cc5e279a1e78fba.tar.gz php-waddiwasi-45104a43293c4344074b4abc8cc5e279a1e78fba.tar.zst php-waddiwasi-45104a43293c4344074b4abc8cc5e279a1e78fba.zip | |
fix: some conversion errors
Diffstat (limited to 'src')
| -rw-r--r-- | src/WebAssembly/Execution/NumericOps.php | 16 | ||||
| -rw-r--r-- | src/WebAssembly/Execution/Runtime.php | 32 |
2 files changed, 24 insertions, 24 deletions
diff --git a/src/WebAssembly/Execution/NumericOps.php b/src/WebAssembly/Execution/NumericOps.php index 70d52b5..5fb37cb 100644 --- a/src/WebAssembly/Execution/NumericOps.php +++ b/src/WebAssembly/Execution/NumericOps.php @@ -691,9 +691,9 @@ final readonly class NumericOps if ($x < 0.0) { return 0; } elseif (4294967295.0 < $x) { - return 4294967295; + return -1; } else { - return (int) $x; + return self::convertU32ToS32((int) $x); } } @@ -713,9 +713,9 @@ final readonly class NumericOps if ($x < 0.0) { return 0; } elseif (4294967295.0 < $x) { - return 4294967295; + return -1; } else { - return (int) $x; + return self::convertU32ToS32((int) $x); } } @@ -1012,7 +1012,7 @@ final readonly class NumericOps if (is_infinite($x)) { return TrapKind::IntegerOverflow; } - if ($x <= -9223372036854775809.0 || 9223372036854775808.0 <= $x) { + if ($x < -9223372036854775808.0 || 9223372036854775808.0 <= $x) { return TrapKind::IntegerOverflow; } return (int) $x; @@ -1040,7 +1040,7 @@ final readonly class NumericOps if (is_infinite($x)) { return TrapKind::IntegerOverflow; } - if ($x <= -9223372036854775809.0 || 9223372036854775808.0 <= $x) { + if ($x < -9223372036854775808.0 || 9223372036854775808.0 <= $x) { return TrapKind::IntegerOverflow; } return (int) $x; @@ -1064,7 +1064,7 @@ final readonly class NumericOps { if ($x < -9223372036854775808.0) { return PHP_INT_MIN; - } elseif (9223372036854775807.0 < $x) { + } elseif (9223372036854775808.0 <= $x) { return PHP_INT_MAX; } else { return (int) $x; @@ -1087,7 +1087,7 @@ final readonly class NumericOps { if ($x < -9223372036854775808.0) { return PHP_INT_MIN; - } elseif (9223372036854775807.0 < $x) { + } elseif (9223372036854775808.0 <= $x) { return PHP_INT_MAX; } else { return (int) $x; diff --git a/src/WebAssembly/Execution/Runtime.php b/src/WebAssembly/Execution/Runtime.php index f6dce48..2604212 100644 --- a/src/WebAssembly/Execution/Runtime.php +++ b/src/WebAssembly/Execution/Runtime.php @@ -954,7 +954,7 @@ final class Runtime implements ExporterInterface $x = $this->stack->popInt(); $result = NumericOps::i32DivS($x, $y); if (!is_int($result)) { - throw new TrapException($instr::opName() . 'invalid operation', trapKind: $result); + throw new TrapException($instr::opName() . ': invalid operation', trapKind: $result); } $this->stack->pushValue($result); } @@ -965,7 +965,7 @@ final class Runtime implements ExporterInterface $x = $this->stack->popInt(); $result = NumericOps::i32DivU($x, $y); if (!is_int($result)) { - throw new TrapException($instr::opName() . 'invalid operation', trapKind: $result); + throw new TrapException($instr::opName() . ': invalid operation', trapKind: $result); } $this->stack->pushValue($result); } @@ -1096,7 +1096,7 @@ final class Runtime implements ExporterInterface $x = $this->stack->popInt(); $result = NumericOps::i32RemS($x, $y); if (!is_int($result)) { - throw new TrapException($instr::opName() . 'invalid operation', trapKind: $result); + throw new TrapException($instr::opName() . ': invalid operation', trapKind: $result); } $this->stack->pushValue($result); } @@ -1107,7 +1107,7 @@ final class Runtime implements ExporterInterface $x = $this->stack->popInt(); $result = NumericOps::i32RemU($x, $y); if (!is_int($result)) { - throw new TrapException($instr::opName() . 'invalid operation', trapKind: $result); + throw new TrapException($instr::opName() . ': invalid operation', trapKind: $result); } $this->stack->pushValue($result); } @@ -1159,7 +1159,7 @@ final class Runtime implements ExporterInterface $x = $this->stack->popFloat(); $result = NumericOps::i32TruncF32S($x); if (!is_int($result)) { - throw new TrapException($instr::opName() . 'invalid operation', trapKind: $result); + throw new TrapException($instr::opName() . ': invalid operation', trapKind: $result); } $this->stack->pushValue($result); } @@ -1169,7 +1169,7 @@ final class Runtime implements ExporterInterface $x = $this->stack->popFloat(); $result = NumericOps::i32TruncF32U($x); if (!is_int($result)) { - throw new TrapException($instr::opName() . 'invalid operation', trapKind: $result); + throw new TrapException($instr::opName() . ': invalid operation', trapKind: $result); } $this->stack->pushValue($result); } @@ -1179,7 +1179,7 @@ final class Runtime implements ExporterInterface $x = $this->stack->popFloat(); $result = NumericOps::i32TruncF64S($x); if (!is_int($result)) { - throw new TrapException($instr::opName() . 'invalid operation', trapKind: $result); + throw new TrapException($instr::opName() . ': invalid operation', trapKind: $result); } $this->stack->pushValue($result); } @@ -1189,7 +1189,7 @@ final class Runtime implements ExporterInterface $x = $this->stack->popFloat(); $result = NumericOps::i32TruncF64U($x); if (!is_int($result)) { - throw new TrapException($instr::opName() . 'invalid operation', trapKind: $result); + throw new TrapException($instr::opName() . ': invalid operation', trapKind: $result); } $this->stack->pushValue($result); } @@ -1268,7 +1268,7 @@ final class Runtime implements ExporterInterface $x = $this->stack->popInt(); $result = NumericOps::i64DivS($x, $y); if (!is_int($result)) { - throw new TrapException($instr::opName() . 'invalid operation', trapKind: $result); + throw new TrapException($instr::opName() . ': invalid operation', trapKind: $result); } $this->stack->pushValue($result); } @@ -1279,7 +1279,7 @@ final class Runtime implements ExporterInterface $x = $this->stack->popInt(); $result = NumericOps::i64DivU($x, $y); if (!is_int($result)) { - throw new TrapException($instr::opName() . 'invalid operation', trapKind: $result); + throw new TrapException($instr::opName() . ': invalid operation', trapKind: $result); } $this->stack->pushValue($result); } @@ -1428,7 +1428,7 @@ final class Runtime implements ExporterInterface $x = $this->stack->popInt(); $result = NumericOps::i64RemS($x, $y); if (!is_int($result)) { - throw new TrapException($instr::opName() . 'invalid operation', trapKind: $result); + throw new TrapException($instr::opName() . ': invalid operation', trapKind: $result); } $this->stack->pushValue($result); } @@ -1439,7 +1439,7 @@ final class Runtime implements ExporterInterface $x = $this->stack->popInt(); $result = NumericOps::i64RemU($x, $y); if (!is_int($result)) { - throw new TrapException($instr::opName() . 'invalid operation', trapKind: $result); + throw new TrapException($instr::opName() . ': invalid operation', trapKind: $result); } $this->stack->pushValue($result); } @@ -1491,7 +1491,7 @@ final class Runtime implements ExporterInterface $x = $this->stack->popFloat(); $result = NumericOps::i64TruncF32S($x); if (!is_int($result)) { - throw new TrapException($instr::opName() . 'invalid operation', trapKind: $result); + throw new TrapException($instr::opName() . ': invalid operation', trapKind: $result); } $this->stack->pushValue($result); } @@ -1501,7 +1501,7 @@ final class Runtime implements ExporterInterface $x = $this->stack->popFloat(); $result = NumericOps::i64TruncF32U($x); if (!is_int($result)) { - throw new TrapException($instr::opName() . 'invalid operation', trapKind: $result); + throw new TrapException($instr::opName() . ': invalid operation', trapKind: $result); } $this->stack->pushValue($result); } @@ -1511,7 +1511,7 @@ final class Runtime implements ExporterInterface $x = $this->stack->popFloat(); $result = NumericOps::i64TruncF64S($x); if (!is_int($result)) { - throw new TrapException($instr::opName() . 'invalid operation', trapKind: $result); + throw new TrapException($instr::opName() . ': invalid operation', trapKind: $result); } $this->stack->pushValue($result); } @@ -1521,7 +1521,7 @@ final class Runtime implements ExporterInterface $x = $this->stack->popFloat(); $result = NumericOps::i64TruncF64U($x); if (!is_int($result)) { - throw new TrapException($instr::opName() . 'invalid operation', trapKind: $result); + throw new TrapException($instr::opName() . ': invalid operation', trapKind: $result); } $this->stack->pushValue($result); } |
