From eaef4b7cf061a0fc2a608925b6e2bf085cbd4568 Mon Sep 17 00:00:00 2001 From: mohanson Date: Wed, 13 Nov 2024 15:36:53 +0800 Subject: [PATCH] 2024-11-13 15:36:52 --- pywasm/core.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pywasm/core.py b/pywasm/core.py index df0cad9..f2c135a 100644 --- a/pywasm/core.py +++ b/pywasm/core.py @@ -1903,6 +1903,7 @@ def evaluate(self) -> None: case pywasm.opcode.i32_div_s: b = self.stack.value.pop().into_i32() a = self.stack.value.pop().into_i32() + assert a != -1 << 31 or b != -1 # Python's default division of integers is return the floor (towards negative infinity) with no # ability to change that. You can read the BDFL's reason why. # See: https://python-history.blogspot.com/2010/08/why-pythons-integer-division-floors.html @@ -2013,6 +2014,7 @@ def evaluate(self) -> None: case pywasm.opcode.i64_div_s: b = self.stack.value.pop().into_i64() a = self.stack.value.pop().into_i64() + assert a != -1 << 63 or b != -1 c = a // b if a * b > 0 else (a + (-a % b)) // b d = ValInst.from_i64(c) self.stack.value.append(d)