|
44 | 44 | import static com.oracle.graal.python.runtime.exception.PythonErrorType.SystemError;
|
45 | 45 | import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
|
46 | 46 |
|
| 47 | +import java.math.BigInteger; |
47 | 48 | import java.nio.ByteBuffer;
|
48 | 49 | import java.nio.CharBuffer;
|
49 | 50 | import java.nio.charset.CharacterCodingException;
|
@@ -1897,16 +1898,23 @@ Object doSignedLong(long n, @SuppressWarnings("unused") int signed,
|
1897 | 1898 | return toSulongNode.execute(n);
|
1898 | 1899 | }
|
1899 | 1900 |
|
1900 |
| - @Specialization(guards = "signed == 0") |
1901 |
| - Object doUnsignedLong(long n, @SuppressWarnings("unused") int signed, |
| 1901 | + @Specialization(guards = {"signed == 0", "n >= 0"}) |
| 1902 | + Object doUnsignedLongPositive(long n, @SuppressWarnings("unused") int signed, |
1902 | 1903 | @Cached("create()") CExtNodes.ToSulongNode toSulongNode) {
|
1903 |
| - if (n < 0) { |
1904 |
| - CompilerDirectives.transferToInterpreter(); |
1905 |
| - throw new UnsupportedOperationException(); |
1906 |
| - } |
1907 | 1904 | return toSulongNode.execute(n);
|
1908 | 1905 | }
|
1909 | 1906 |
|
| 1907 | + @Specialization(guards = {"signed == 0", "n < 0"}) |
| 1908 | + Object doUnsignedLongNegative(long n, @SuppressWarnings("unused") int signed, |
| 1909 | + @Cached("create()") CExtNodes.ToSulongNode toSulongNode) { |
| 1910 | + return toSulongNode.execute(factory().createInt(convertToBigInteger(n))); |
| 1911 | + } |
| 1912 | + |
| 1913 | + @TruffleBoundary |
| 1914 | + private static BigInteger convertToBigInteger(long n) { |
| 1915 | + return BigInteger.valueOf(n).add(BigInteger.ONE.shiftLeft(64)); |
| 1916 | + } |
| 1917 | + |
1910 | 1918 | @Specialization
|
1911 | 1919 | Object doPointer(TruffleObject n, @SuppressWarnings("unused") int signed,
|
1912 | 1920 | @Cached("create()") CExtNodes.ToSulongNode toSulongNode) {
|
|
0 commit comments