Skip to content

Commit 85470bc

Browse files
committed
Support native type in 'GetSuperClassNode'.
1 parent 5ac9ce5 commit 85470bc

File tree

1 file changed

+23
-4
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type

1 file changed

+23
-4
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeNodes.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040
*/
4141
package com.oracle.graal.python.builtins.objects.type;
4242

43+
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.SystemError;
4344
import static com.oracle.graal.python.nodes.SpecialMethodNames.__EQ__;
4445

4546
import java.util.ArrayList;
4647
import java.util.Collection;
47-
import java.util.HashSet;
4848
import java.util.Iterator;
4949
import java.util.List;
5050
import java.util.Set;
@@ -92,6 +92,7 @@
9292
import com.oracle.truffle.api.interop.UnknownIdentifierException;
9393
import com.oracle.truffle.api.interop.UnsupportedMessageException;
9494
import com.oracle.truffle.api.nodes.Node;
95+
import com.oracle.truffle.api.profiles.ConditionProfile;
9596
import com.oracle.truffle.api.profiles.ValueProfile;
9697

9798
public abstract class TypeNodes {
@@ -263,28 +264,46 @@ public static GetNameNode create() {
263264

264265
}
265266

267+
@TypeSystemReference(PythonTypes.class)
268+
@ImportStatic(NativeMemberNames.class)
266269
public abstract static class GetSuperClassNode extends PNodeWithContext {
267270

268271
public abstract LazyPythonClass execute(Object obj);
269272

270273
@Specialization
271-
LazyPythonClass doPythonClass(ManagedPythonClass obj) {
274+
LazyPythonClass doManaged(ManagedPythonClass obj) {
272275
return obj.getSuperClass();
273276
}
274277

275278
@Specialization
276-
LazyPythonClass doPythonClass(PythonBuiltinClassType obj) {
279+
LazyPythonClass doBuiltin(PythonBuiltinClassType obj) {
277280
return obj.getBase();
278281
}
279282

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+
280295
@TruffleBoundary
281296
public static LazyPythonClass doSlowPath(Object obj) {
282297
if (obj instanceof ManagedPythonClass) {
283298
return ((ManagedPythonClass) obj).getSuperClass();
284299
} else if (obj instanceof PythonBuiltinClassType) {
285300
return ((PythonBuiltinClassType) obj).getBase();
286301
} 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);
288307
}
289308
throw new IllegalStateException("unknown type " + obj.getClass().getName());
290309
}

0 commit comments

Comments
 (0)