|
47 | 47 | import com.oracle.graal.python.builtins.PythonBuiltins;
|
48 | 48 | import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.GetNativeNullNode;
|
49 | 49 | import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.TransformExceptionToNativeNode;
|
| 50 | +import com.oracle.graal.python.builtins.objects.common.HashingStorage; |
50 | 51 | import com.oracle.graal.python.builtins.objects.common.HashingStorage.DictEntry;
|
| 52 | +import com.oracle.graal.python.builtins.objects.common.HashingStorage.InitNode; |
51 | 53 | import com.oracle.graal.python.builtins.objects.common.HashingStorageLibrary;
|
52 | 54 | import com.oracle.graal.python.builtins.objects.common.HashingStorageLibrary.HashingStorageIterable;
|
53 | 55 | import com.oracle.graal.python.builtins.objects.common.HashingStorageLibrary.HashingStorageIterator;
|
54 | 56 | import com.oracle.graal.python.builtins.objects.dict.PDict;
|
| 57 | +import com.oracle.graal.python.builtins.objects.function.PKeyword; |
55 | 58 | import com.oracle.graal.python.builtins.objects.namespace.PSimpleNamespace;
|
56 | 59 | import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
|
57 | 60 | import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
|
@@ -101,6 +104,29 @@ public Object imp(VirtualFrame frame, PDict dict,
|
101 | 104 | return getNativeNull.execute();
|
102 | 105 | }
|
103 | 106 | }
|
| 107 | + |
| 108 | + @Specialization(guards = "!isDict(dict)") |
| 109 | + public Object imp(VirtualFrame frame, Object dict, |
| 110 | + @Cached InitNode initNode, |
| 111 | + @CachedLibrary(limit = "1") HashingStorageLibrary lib, |
| 112 | + @CachedLibrary(limit = "1") DynamicObjectLibrary dyLib, |
| 113 | + @Cached TransformExceptionToNativeNode transformExceptionToNativeNode, |
| 114 | + @Cached GetNativeNullNode getNativeNull) { |
| 115 | + try { |
| 116 | + PSimpleNamespace ns = factory().createSimpleNamespace(); |
| 117 | + HashingStorage hs = initNode.execute(frame, dict, PKeyword.EMPTY_KEYWORDS); |
| 118 | + HashingStorageIterable<DictEntry> entries = lib.entries(hs); |
| 119 | + HashingStorageIterator<DictEntry> it = entries.iterator(); |
| 120 | + while (it.hasNext()) { |
| 121 | + DictEntry e = it.next(); |
| 122 | + dyLib.put(ns, e.key, e.value); |
| 123 | + } |
| 124 | + return ns; |
| 125 | + } catch (PException e) { |
| 126 | + transformExceptionToNativeNode.execute(e); |
| 127 | + return getNativeNull.execute(); |
| 128 | + } |
| 129 | + } |
104 | 130 | }
|
105 | 131 |
|
106 | 132 | }
|
0 commit comments