|
117 | 117 | import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
|
118 | 118 | import com.oracle.graal.python.builtins.objects.complex.PComplex;
|
119 | 119 | import com.oracle.graal.python.builtins.objects.dict.PDict;
|
| 120 | +import com.oracle.graal.python.builtins.objects.exception.PBaseException; |
120 | 121 | import com.oracle.graal.python.builtins.objects.floats.PFloat;
|
121 | 122 | import com.oracle.graal.python.builtins.objects.frame.PFrame;
|
122 | 123 | import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction;
|
|
149 | 150 | import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetSuperClassNode;
|
150 | 151 | import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetTypeFlagsNode;
|
151 | 152 | import com.oracle.graal.python.lib.PyNumberAsSizeNode;
|
| 153 | +import com.oracle.graal.python.lib.PyObjectGetAttr; |
152 | 154 | import com.oracle.graal.python.lib.PyObjectSizeNode;
|
153 | 155 | import com.oracle.graal.python.nodes.ErrorMessages;
|
154 | 156 | import com.oracle.graal.python.nodes.PGuards;
|
@@ -1259,22 +1261,38 @@ static Object doPCode(PCode object, PythonNativeWrapper nativeWrapper, String ke
|
1259 | 1261 | return doPCodeCached(object, nativeWrapper, key, NativeMember.byName(key), factory, toSulongNode);
|
1260 | 1262 | }
|
1261 | 1263 |
|
1262 |
| - // TODO: fallback guard |
1263 |
| - @Specialization |
1264 |
| - static Object doGeneric(@SuppressWarnings("unused") Object object, DynamicObjectNativeWrapper nativeWrapper, String key, |
| 1264 | + @Specialization(guards = {"eq(VALUE, key)", "isStopIteration(exception, getClassNode, isSubtypeNode)"}, limit = "1") |
| 1265 | + static Object doException(PBaseException exception, @SuppressWarnings("unused") PythonNativeWrapper nativeWrapper, @SuppressWarnings("unused") String key, |
| 1266 | + @Shared("getClassNode") @SuppressWarnings("unused") @Cached GetClassNode getClassNode, |
| 1267 | + @SuppressWarnings("unused") @Cached IsSubtypeNode isSubtypeNode, |
| 1268 | + @Cached PyObjectGetAttr getAttr, |
| 1269 | + @Shared("toSulongNode") @Cached ToSulongNode toSulongNode) { |
| 1270 | + return toSulongNode.execute(getAttr.execute(null, exception, "value")); |
| 1271 | + } |
| 1272 | + |
| 1273 | + protected boolean isStopIteration(PBaseException exception, GetClassNode getClassNode, IsSubtypeNode isSubtypeNode) { |
| 1274 | + return isSubtypeNode.execute(getClassNode.execute(exception), PythonBuiltinClassType.StopIteration); |
| 1275 | + } |
| 1276 | + |
| 1277 | + @Fallback |
| 1278 | + static Object doGeneric(@SuppressWarnings("unused") Object object, PythonNativeWrapper nativeWrapper, String key, |
1265 | 1279 | @CachedLibrary(limit = "1") HashingStorageLibrary lib,
|
1266 | 1280 | @Shared("toSulongNode") @Cached ToSulongNode toSulongNode,
|
1267 | 1281 | @Shared("getNativeNullNode") @Cached GetNativeNullNode getNativeNullNode) throws UnknownIdentifierException {
|
1268 |
| - // This is the preliminary generic case: There are native members we know that they |
1269 |
| - // exist but we do currently not represent them. So, store them into a dynamic object |
1270 |
| - // such that native code at least reads the value that was written before. |
1271 |
| - if (nativeWrapper.isMemberReadable(key)) { |
1272 |
| - logGeneric(key); |
1273 |
| - DynamicObjectStorage nativeMemberStore = nativeWrapper.getNativeMemberStore(); |
1274 |
| - if (nativeMemberStore != null) { |
1275 |
| - return lib.getItem(nativeMemberStore, key); |
| 1282 | + if (nativeWrapper instanceof DynamicObjectNativeWrapper) { |
| 1283 | + DynamicObjectNativeWrapper dynamicWrapper = (DynamicObjectNativeWrapper) nativeWrapper; |
| 1284 | + // This is the preliminary generic case: There are native members we know that they |
| 1285 | + // exist but we do currently not represent them. So, store them into a dynamic |
| 1286 | + // object |
| 1287 | + // such that native code at least reads the value that was written before. |
| 1288 | + if (dynamicWrapper.isMemberReadable(key)) { |
| 1289 | + logGeneric(key); |
| 1290 | + DynamicObjectStorage nativeMemberStore = dynamicWrapper.getNativeMemberStore(); |
| 1291 | + if (nativeMemberStore != null) { |
| 1292 | + return lib.getItem(nativeMemberStore, key); |
| 1293 | + } |
| 1294 | + return toSulongNode.execute(getNativeNullNode.execute()); |
1276 | 1295 | }
|
1277 |
| - return toSulongNode.execute(getNativeNullNode.execute()); |
1278 | 1296 | }
|
1279 | 1297 | throw UnknownIdentifierException.create(key);
|
1280 | 1298 | }
|
|
0 commit comments