|
40 | 40 | */
|
41 | 41 | package com.oracle.graal.python.builtins.objects.type;
|
42 | 42 |
|
| 43 | +import static com.oracle.graal.python.builtins.PythonBuiltinClassType.SystemError; |
43 | 44 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__EQ__;
|
44 | 45 |
|
45 | 46 | import java.util.ArrayList;
|
46 | 47 | import java.util.Collection;
|
47 |
| -import java.util.HashSet; |
48 | 48 | import java.util.Iterator;
|
49 | 49 | import java.util.List;
|
50 | 50 | import java.util.Set;
|
|
92 | 92 | import com.oracle.truffle.api.interop.UnknownIdentifierException;
|
93 | 93 | import com.oracle.truffle.api.interop.UnsupportedMessageException;
|
94 | 94 | import com.oracle.truffle.api.nodes.Node;
|
| 95 | +import com.oracle.truffle.api.profiles.ConditionProfile; |
95 | 96 | import com.oracle.truffle.api.profiles.ValueProfile;
|
96 | 97 |
|
97 | 98 | public abstract class TypeNodes {
|
@@ -263,28 +264,46 @@ public static GetNameNode create() {
|
263 | 264 |
|
264 | 265 | }
|
265 | 266 |
|
| 267 | + @TypeSystemReference(PythonTypes.class) |
| 268 | + @ImportStatic(NativeMemberNames.class) |
266 | 269 | public abstract static class GetSuperClassNode extends PNodeWithContext {
|
267 | 270 |
|
268 | 271 | public abstract LazyPythonClass execute(Object obj);
|
269 | 272 |
|
270 | 273 | @Specialization
|
271 |
| - LazyPythonClass doPythonClass(ManagedPythonClass obj) { |
| 274 | + LazyPythonClass doManaged(ManagedPythonClass obj) { |
272 | 275 | return obj.getSuperClass();
|
273 | 276 | }
|
274 | 277 |
|
275 | 278 | @Specialization
|
276 |
| - LazyPythonClass doPythonClass(PythonBuiltinClassType obj) { |
| 279 | + LazyPythonClass doBuiltin(PythonBuiltinClassType obj) { |
277 | 280 | return obj.getBase();
|
278 | 281 | }
|
279 | 282 |
|
| 283 | + @Specialization |
| 284 | + LazyPythonClass doNative(PythonNativeClass obj, |
| 285 | + @Cached("create(TP_BASE)") GetTypeMemberNode getTpBaseNode, |
| 286 | + @Cached("createBinaryProfile()") ConditionProfile profile) { |
| 287 | + Object tpBaseObj = getTpBaseNode.execute(obj); |
| 288 | + if (profile.profile(PGuards.isClass(tpBaseObj))) { |
| 289 | + return (AbstractPythonClass) tpBaseObj; |
| 290 | + } |
| 291 | + CompilerDirectives.transferToInterpreter(); |
| 292 | + throw raise(SystemError, "Invalid base type object for class %s (base type was '%p' object).", GetNameNode.doSlowPath(obj), tpBaseObj); |
| 293 | + } |
| 294 | + |
280 | 295 | @TruffleBoundary
|
281 | 296 | public static LazyPythonClass doSlowPath(Object obj) {
|
282 | 297 | if (obj instanceof ManagedPythonClass) {
|
283 | 298 | return ((ManagedPythonClass) obj).getSuperClass();
|
284 | 299 | } else if (obj instanceof PythonBuiltinClassType) {
|
285 | 300 | return ((PythonBuiltinClassType) obj).getBase();
|
286 | 301 | } else if (PGuards.isNativeClass(obj)) {
|
287 |
| - // TODO implement |
| 302 | + Object tpBaseObj = GetTypeMemberNode.doSlowPath(obj, NativeMemberNames.TP_BASE); |
| 303 | + if (PGuards.isClass(tpBaseObj)) { |
| 304 | + return (AbstractPythonClass) tpBaseObj; |
| 305 | + } |
| 306 | + PythonLanguage.getCore().raise(SystemError, "Invalid base type object for class %s (base type was '%p' object).", GetNameNode.doSlowPath(obj), tpBaseObj); |
288 | 307 | }
|
289 | 308 | throw new IllegalStateException("unknown type " + obj.getClass().getName());
|
290 | 309 | }
|
|
0 commit comments