|
180 | 180 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
181 | 181 | import com.oracle.truffle.api.RootCallTarget;
|
182 | 182 | import com.oracle.truffle.api.Truffle;
|
| 183 | +import com.oracle.truffle.api.TruffleLanguage; |
183 | 184 | import com.oracle.truffle.api.debug.Debugger;
|
184 | 185 | import com.oracle.truffle.api.dsl.Cached;
|
185 | 186 | import com.oracle.truffle.api.dsl.Cached.Shared;
|
@@ -1056,6 +1057,8 @@ public abstract static class IsInstanceNode extends PythonBinaryBuiltinNode {
|
1056 | 1057 | @Child private SequenceStorageNodes.LenNode lenNode;
|
1057 | 1058 | @Child private GetObjectArrayNode getObjectArrayNode;
|
1058 | 1059 |
|
| 1060 | + @CompilationFinal private Boolean emulateJython; |
| 1061 | + |
1059 | 1062 | public static IsInstanceNode create() {
|
1060 | 1063 | return BuiltinFunctionsFactory.IsInstanceNodeFactory.create();
|
1061 | 1064 | }
|
@@ -1101,8 +1104,22 @@ boolean isInstance(VirtualFrame frame, Object instance, PTuple clsTuple,
|
1101 | 1104 | return false;
|
1102 | 1105 | }
|
1103 | 1106 |
|
| 1107 | + protected boolean emulateJython() { |
| 1108 | + if (emulateJython == null) { |
| 1109 | + CompilerDirectives.transferToInterpreterAndInvalidate(); |
| 1110 | + emulateJython = PythonOptions.getFlag(getContext(), PythonOptions.EmulateJython); |
| 1111 | + } |
| 1112 | + return emulateJython; |
| 1113 | + } |
| 1114 | + |
1104 | 1115 | @Fallback
|
1105 | 1116 | boolean isInstance(VirtualFrame frame, Object instance, Object cls) {
|
| 1117 | + TruffleLanguage.Env env = getContext().getEnv(); |
| 1118 | + if (emulateJython() && env.isHostObject(cls)) { |
| 1119 | + Object hostCls = env.asHostObject(cls); |
| 1120 | + Object hostInstance = env.isHostObject(instance) ? env.asHostObject(instance) : instance; |
| 1121 | + return hostCls instanceof Class && ((Class<?>) hostCls).isAssignableFrom(hostInstance.getClass()); |
| 1122 | + } |
1106 | 1123 | return isInstanceCheckInternal(frame, instance, cls) || typeInstanceCheckNode.executeWith(frame, cls, instance);
|
1107 | 1124 | }
|
1108 | 1125 |
|
|
0 commit comments