|
45 | 45 |
|
46 | 46 | import com.oracle.graal.python.builtins.objects.PNone; |
47 | 47 | import com.oracle.graal.python.builtins.objects.object.ObjectNodes; |
48 | | -import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary; |
49 | 48 | import com.oracle.graal.python.builtins.objects.str.PString; |
| 49 | +import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot; |
50 | 50 | import com.oracle.graal.python.nodes.ErrorMessages; |
51 | 51 | import com.oracle.graal.python.nodes.PNodeWithContext; |
52 | 52 | import com.oracle.graal.python.nodes.PRaiseNode; |
| 53 | +import com.oracle.graal.python.nodes.call.special.CallUnaryMethodNode; |
| 54 | +import com.oracle.graal.python.nodes.call.special.LookupSpecialMethodSlotNode; |
| 55 | +import com.oracle.graal.python.nodes.object.GetClassNode; |
| 56 | +import com.oracle.graal.python.runtime.exception.PException; |
53 | 57 | import com.oracle.truffle.api.dsl.Cached; |
54 | 58 | import com.oracle.truffle.api.dsl.GenerateUncached; |
| 59 | +import com.oracle.truffle.api.dsl.ImportStatic; |
55 | 60 | import com.oracle.truffle.api.dsl.Specialization; |
56 | 61 | import com.oracle.truffle.api.frame.Frame; |
57 | 62 | import com.oracle.truffle.api.frame.VirtualFrame; |
58 | | -import com.oracle.truffle.api.library.CachedLibrary; |
59 | 63 | import com.oracle.truffle.api.profiles.ConditionProfile; |
60 | 64 |
|
61 | 65 | /** |
|
67 | 71 | * @see PyObjectReprAsJavaStringNode |
68 | 72 | */ |
69 | 73 | @GenerateUncached |
| 74 | +@ImportStatic(SpecialMethodSlot.class) |
70 | 75 | public abstract class PyObjectReprAsObjectNode extends PNodeWithContext { |
71 | 76 | public abstract Object execute(Frame frame, Object object); |
72 | 77 |
|
73 | | - @Specialization(limit = "3") |
| 78 | + @Specialization |
74 | 79 | static Object repr(VirtualFrame frame, Object obj, |
75 | | - @CachedLibrary("obj") PythonObjectLibrary objLib, |
76 | | - @CachedLibrary(limit = "2") PythonObjectLibrary methodLib, |
| 80 | + @Cached GetClassNode getClassNode, |
| 81 | + @Cached(parameters = "Repr") LookupSpecialMethodSlotNode lookupRepr, |
| 82 | + @Cached CallUnaryMethodNode callRepr, |
77 | 83 | @Cached ObjectNodes.DefaultObjectReprNode defaultRepr, |
78 | | - @Cached ConditionProfile hasRepr, |
79 | 84 | @Cached ConditionProfile isString, |
80 | 85 | @Cached ConditionProfile isPString, |
81 | 86 | @Cached PRaiseNode raiseNode) { |
82 | | - Object reprMethod = objLib.lookupAttributeOnType(obj, __REPR__); |
83 | | - if (hasRepr.profile(reprMethod != PNone.NO_VALUE)) { |
84 | | - Object result = methodLib.callUnboundMethodIgnoreGetException(reprMethod, frame, obj); |
| 87 | + Object type = getClassNode.execute(obj); |
| 88 | + Object reprMethod; |
| 89 | + try { |
| 90 | + reprMethod = lookupRepr.execute(frame, type, obj); |
| 91 | + } catch (PException e) { |
| 92 | + return defaultRepr.execute(frame, obj); |
| 93 | + } |
| 94 | + if (reprMethod != PNone.NO_VALUE) { |
| 95 | + Object result = callRepr.executeObject(frame, reprMethod, obj); |
85 | 96 | if (isString.profile(result instanceof String) || isPString.profile(result instanceof PString)) { |
86 | 97 | return result; |
87 | 98 | } |
|
0 commit comments