|
65 | 65 | import com.oracle.graal.python.builtins.objects.method.PMethod;
|
66 | 66 | import com.oracle.graal.python.builtins.objects.module.PythonModule;
|
67 | 67 | import com.oracle.graal.python.builtins.objects.object.PythonObject;
|
| 68 | +import com.oracle.graal.python.builtins.objects.type.TypeNodes; |
68 | 69 | import com.oracle.graal.python.nodes.ErrorMessages;
|
69 | 70 | import com.oracle.graal.python.nodes.argument.ReadIndexedArgumentNode;
|
70 | 71 | import com.oracle.graal.python.nodes.argument.ReadVarArgsNode;
|
71 | 72 | import com.oracle.graal.python.nodes.function.FunctionRootNode;
|
72 | 73 | import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
|
73 | 74 | import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
|
| 75 | +import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode; |
74 | 76 | import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
|
75 | 77 | import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
|
| 78 | +import com.oracle.graal.python.nodes.object.GetClassNode; |
76 | 79 | import com.oracle.graal.python.nodes.subscript.GetItemNode;
|
77 | 80 | import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
|
78 | 81 | import com.oracle.graal.python.nodes.util.CannotCastException;
|
@@ -456,4 +459,29 @@ protected Object getToolPath(String tool) {
|
456 | 459 | return toolPath.toString();
|
457 | 460 | }
|
458 | 461 | }
|
| 462 | + |
| 463 | + // Equivalent of PyType_IsSubtype |
| 464 | + @Builtin(name = "is_subtype", minNumOfPositionalArgs = 2) |
| 465 | + @GenerateNodeFactory |
| 466 | + public abstract static class IsSubtypeNode extends PythonBinaryBuiltinNode { |
| 467 | + @Specialization |
| 468 | + public boolean isSubtype(VirtualFrame frame, Object derived, Object cls, |
| 469 | + @Cached com.oracle.graal.python.nodes.classes.IsSubtypeNode isSubtypeNode) { |
| 470 | + return isSubtypeNode.execute(frame, derived, cls); |
| 471 | + } |
| 472 | + } |
| 473 | + |
| 474 | + // Equivalent of PyObject_TypeCheck |
| 475 | + @Builtin(name = "type_check", minNumOfPositionalArgs = 2) |
| 476 | + @GenerateNodeFactory |
| 477 | + public abstract static class TypeCheckNode extends PythonBinaryBuiltinNode { |
| 478 | + @Specialization(limit = "3") |
| 479 | + boolean typeCheck(VirtualFrame frame, Object instance, Object cls, |
| 480 | + @Cached GetClassNode getClassNode, |
| 481 | + @Cached TypeNodes.IsSameTypeNode isSameTypeNode, |
| 482 | + @Cached com.oracle.graal.python.nodes.classes.IsSubtypeNode isSubtypeNode) { |
| 483 | + Object instanceClass = getClassNode.execute(instance); |
| 484 | + return isSameTypeNode.execute(instanceClass, cls) || isSubtypeNode.execute(frame, instanceClass, cls); |
| 485 | + } |
| 486 | + } |
459 | 487 | }
|
0 commit comments