|
49 | 49 | import com.oracle.graal.python.builtins.PythonBuiltins;
|
50 | 50 | import com.oracle.graal.python.builtins.objects.PNotImplemented;
|
51 | 51 | import com.oracle.graal.python.nodes.SpecialMethodNames;
|
52 |
| -import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode; |
| 52 | +import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode.LookupAndCallUnaryDynamicNode; |
53 | 53 | import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
|
54 | 54 | import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
|
55 | 55 | import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
|
| 56 | +import com.oracle.graal.python.nodes.util.CastToJavaStringNode; |
| 57 | +import com.oracle.graal.python.runtime.ExecutionContext.IndirectCallContext; |
56 | 58 | import com.oracle.graal.python.runtime.PythonContext;
|
57 |
| -import com.oracle.graal.python.util.PythonUtils; |
| 59 | +import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; |
58 | 60 | import com.oracle.truffle.api.dsl.Cached;
|
59 | 61 | import com.oracle.truffle.api.dsl.CachedContext;
|
| 62 | +import com.oracle.truffle.api.dsl.CachedLanguage; |
60 | 63 | import com.oracle.truffle.api.dsl.GenerateNodeFactory;
|
61 | 64 | import com.oracle.truffle.api.dsl.NodeFactory;
|
62 | 65 | import com.oracle.truffle.api.dsl.Specialization;
|
@@ -90,7 +93,7 @@ public abstract static class HPyDebugHandleIdNode extends PythonUnaryBuiltinNode
|
90 | 93 | static Object doGeneric(PDebugHandle self,
|
91 | 94 | @CachedContext(PythonLanguage.class) PythonContext context,
|
92 | 95 | @Cached ConditionProfile profile) {
|
93 |
| - return self.getHandle().getId(context.getHPyContext(), profile); |
| 96 | + return self.getHandle().getId(context.getHPyDebugContext(), profile); |
94 | 97 | }
|
95 | 98 | }
|
96 | 99 |
|
@@ -119,13 +122,23 @@ static boolean isDebugHandle(Object object) {
|
119 | 122 | public abstract static class HPyDebugHandleReprNode extends PythonUnaryBuiltinNode {
|
120 | 123 |
|
121 | 124 | @Specialization
|
122 |
| - static Object doGeneric(VirtualFrame frame, PDebugHandle self, |
123 |
| - @CachedContext(PythonLanguage.class) PythonContext context, |
124 |
| - @Cached ConditionProfile profile, |
125 |
| - @Cached(parameters = "__REPR__") LookupAndCallUnaryNode callReprNode) { |
126 |
| - int id = self.getHandle().getId(context.getHPyContext(), profile); |
127 |
| - Object objRepr = callReprNode.executeObject(frame, self.getHandle().getDelegate()); |
128 |
| - return PythonUtils.format("DebugHandle 0x%s for %s", id, objRepr); |
| 125 | + Object doGeneric(VirtualFrame frame, PDebugHandle self, |
| 126 | + @CachedLanguage PythonLanguage language, |
| 127 | + @CachedContext(PythonLanguage.class) PythonContext context) { |
| 128 | + Object state = IndirectCallContext.enter(frame, language, context, this); |
| 129 | + try { |
| 130 | + return format(context.getHPyDebugContext(), self); |
| 131 | + } finally { |
| 132 | + IndirectCallContext.exit(frame, language, context, state); |
| 133 | + } |
| 134 | + } |
| 135 | + |
| 136 | + @TruffleBoundary |
| 137 | + private static Object format(GraalHPyDebugContext hpyDebugContext, PDebugHandle self) { |
| 138 | + int id = self.getHandle().getId(hpyDebugContext, ConditionProfile.getUncached()); |
| 139 | + Object objRepr = LookupAndCallUnaryDynamicNode.getUncached().executeObject(self.getHandle().getDelegate(), SpecialMethodNames.__REPR__); |
| 140 | + String reprStr = CastToJavaStringNode.getUncached().execute(objRepr); |
| 141 | + return String.format("<DebugHandle 0x%s for %s>", Integer.toHexString(id), reprStr); |
129 | 142 | }
|
130 | 143 | }
|
131 | 144 | }
|
0 commit comments