|
6 | 6 | */ |
7 | 7 | package com.oracle.graal.python.runtime.formatting; |
8 | 8 |
|
9 | | -import static com.oracle.graal.python.nodes.SpecialMethodNames.T___INDEX__; |
10 | | -import static com.oracle.graal.python.nodes.SpecialMethodNames.T___INT__; |
11 | | -import static com.oracle.graal.python.runtime.exception.PythonErrorType.AttributeError; |
12 | 9 | import static com.oracle.graal.python.runtime.exception.PythonErrorType.MemoryError; |
13 | 10 | import static com.oracle.graal.python.runtime.exception.PythonErrorType.OverflowError; |
14 | 11 | import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError; |
|
20 | 17 |
|
21 | 18 | import com.oracle.graal.python.builtins.Python3Core; |
22 | 19 | import com.oracle.graal.python.builtins.PythonBuiltinClassType; |
23 | | -import com.oracle.graal.python.builtins.objects.PNone; |
24 | | -import com.oracle.graal.python.builtins.objects.PythonAbstractObject; |
25 | 20 | import com.oracle.graal.python.builtins.objects.function.PKeyword; |
26 | 21 | import com.oracle.graal.python.builtins.objects.ints.PInt; |
27 | 22 | import com.oracle.graal.python.builtins.objects.tuple.TupleBuiltins; |
28 | 23 | import com.oracle.graal.python.lib.PyFloatAsDoubleNode; |
| 24 | +import com.oracle.graal.python.lib.PyNumberCheckNode; |
| 25 | +import com.oracle.graal.python.lib.PyNumberIndexNode; |
29 | 26 | import com.oracle.graal.python.lib.PyObjectGetItem; |
30 | 27 | import com.oracle.graal.python.lib.PyObjectSizeNode; |
31 | 28 | import com.oracle.graal.python.nodes.ErrorMessages; |
@@ -190,20 +187,18 @@ protected final Object asNumber(Object arg, char specType) { |
190 | 187 | } else if (arg instanceof Boolean) { |
191 | 188 | // Fast path for simple booleans |
192 | 189 | return (Boolean) arg ? 1 : 0; |
193 | | - } else if (arg instanceof PythonAbstractObject) { |
194 | | - // Try again with arg.__int__() or __index__() depending on the spec type |
| 190 | + } else if (PyNumberCheckNode.executeUncached(arg)) { |
195 | 191 | try { |
196 | | - TruffleString magicName = useIndexMagicMethod(specType) ? T___INDEX__ : T___INT__; |
197 | | - Object attribute = lookupAttribute(arg, magicName); |
198 | | - if (!(attribute instanceof PNone)) { |
199 | | - return call(attribute, arg); |
| 192 | + if (useIndexMagicMethod(specType)) { |
| 193 | + return PyNumberIndexNode.executeUncached(arg); |
| 194 | + } else { |
| 195 | + return CallNode.executeUncached(PythonBuiltinClassType.PInt, arg); |
200 | 196 | } |
201 | 197 | } catch (PException e) { |
202 | | - e.expectUncached(AttributeError); |
203 | | - // No __int__/__index__ defined (at Python level) |
| 198 | + e.expectUncached(TypeError); |
204 | 199 | } |
205 | 200 | } |
206 | | - return arg; |
| 201 | + return null; |
207 | 202 | } |
208 | 203 |
|
209 | 204 | protected double asFloat(Object arg) { |
|
0 commit comments