|
55 | 55 | import java.util.Iterator;
|
56 | 56 | import java.util.List;
|
57 | 57 |
|
| 58 | +import com.oracle.graal.python.PythonLanguage; |
58 | 59 | import com.oracle.graal.python.builtins.Builtin;
|
59 | 60 | import com.oracle.graal.python.builtins.CoreFunctions;
|
60 | 61 | import com.oracle.graal.python.builtins.PythonBuiltinClassType;
|
|
79 | 80 | import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
|
80 | 81 | import com.oracle.graal.python.nodes.object.GetClassNode;
|
81 | 82 | import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
|
| 83 | +import com.oracle.graal.python.runtime.PythonContext; |
82 | 84 | import com.oracle.graal.python.runtime.exception.PException;
|
83 | 85 | import com.oracle.graal.python.runtime.object.PythonObjectFactory;
|
84 | 86 | import com.oracle.graal.python.util.PythonUtils;
|
85 | 87 | import com.oracle.truffle.api.dsl.Cached;
|
| 88 | +import com.oracle.truffle.api.dsl.CachedContext; |
86 | 89 | import com.oracle.truffle.api.dsl.Fallback;
|
87 | 90 | import com.oracle.truffle.api.dsl.GenerateNodeFactory;
|
88 | 91 | import com.oracle.truffle.api.dsl.ImportStatic;
|
@@ -123,27 +126,39 @@ private static void fillItems(VirtualFrame frame, StringBuilder sb, LookupAndCal
|
123 | 126 |
|
124 | 127 | @Specialization(limit = "3")
|
125 | 128 | public static Object repr(VirtualFrame frame, PBaseSet self,
|
126 |
| - @Cached IsBuiltinClassProfile isBuiltinClass, |
| 129 | + @CachedContext(PythonLanguage.class) PythonContext ctxt, |
127 | 130 | @Cached("create(__REPR__)") LookupAndCallUnaryNode repr,
|
128 | 131 | @Cached TypeNodes.GetNameNode getNameNode,
|
129 | 132 | @Cached GetClassNode getClassNode,
|
130 | 133 | @CachedLibrary("self.getDictStorage()") HashingStorageLibrary hlib) {
|
131 | 134 | StringBuilder sb = PythonUtils.newStringBuilder();
|
132 |
| - int len = hlib.length(self.getDictStorage()); |
133 |
| - HashingStorageLibrary.HashingStorageIterator<Object> iter = hlib.keys(self.getDictStorage()).iterator(); |
134 | 135 | Object clazz = getClassNode.execute(self);
|
135 |
| - if (len > 0 && clazz == PythonBuiltinClassType.PSet && isBuiltinClass.profileIsAnyBuiltinClass(clazz)) { |
136 |
| - fillItems(frame, sb, repr, iter); |
| 136 | + int len = hlib.length(self.getDictStorage()); |
| 137 | + if (len == 0) { |
| 138 | + PythonUtils.append(sb, getNameNode.execute(clazz)); |
| 139 | + PythonUtils.append(sb, "()"); |
| 140 | + return PythonUtils.sbToString(sb); |
| 141 | + } |
| 142 | + if (!ctxt.reprEnter(self)) { |
| 143 | + PythonUtils.append(sb, getNameNode.execute(clazz)); |
| 144 | + PythonUtils.append(sb, "(...)"); |
137 | 145 | return PythonUtils.sbToString(sb);
|
138 | 146 | }
|
139 |
| - String typeName = getNameNode.execute(clazz); |
140 |
| - PythonUtils.append(sb, typeName); |
141 |
| - PythonUtils.append(sb, "("); |
142 |
| - if (len > 0) { |
| 147 | + try { |
| 148 | + HashingStorageLibrary.HashingStorageIterator<Object> iter = hlib.keys(self.getDictStorage()).iterator(); |
| 149 | + boolean showType = clazz != PythonBuiltinClassType.PSet; |
| 150 | + if (showType) { |
| 151 | + PythonUtils.append(sb, getNameNode.execute(clazz)); |
| 152 | + PythonUtils.append(sb, '('); |
| 153 | + } |
143 | 154 | fillItems(frame, sb, repr, iter);
|
| 155 | + if (showType) { |
| 156 | + PythonUtils.append(sb, ')'); |
| 157 | + } |
| 158 | + return PythonUtils.sbToString(sb); |
| 159 | + } finally { |
| 160 | + ctxt.reprLeave(self); |
144 | 161 | }
|
145 |
| - PythonUtils.append(sb, ")"); |
146 |
| - return PythonUtils.sbToString(sb); |
147 | 162 | }
|
148 | 163 | }
|
149 | 164 |
|
|
0 commit comments