|
70 | 70 | import com.oracle.graal.python.nodes.object.GetOrCreateDictNode;
|
71 | 71 | import com.oracle.graal.python.nodes.object.SetDictNode;
|
72 | 72 | import com.oracle.graal.python.runtime.exception.PException;
|
73 |
| -import com.oracle.truffle.api.CompilerDirectives; |
74 | 73 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
75 | 74 | import com.oracle.truffle.api.dsl.Bind;
|
76 | 75 | import com.oracle.truffle.api.dsl.Cached;
|
@@ -158,21 +157,24 @@ abstract static class GetModuleNode extends PythonBuiltinNode {
|
158 | 157 | @Specialization(guards = {"!isBuiltinFunction(self)", "isNoValue(none)"})
|
159 | 158 | static Object getModule(VirtualFrame frame, PFunction self, @SuppressWarnings("unused") PNone none,
|
160 | 159 | @Cached ReadAttributeFromObjectNode readObject,
|
| 160 | + @Cached ReadAttributeFromObjectNode readGlobals, |
161 | 161 | @Cached PyObjectGetItem getItem,
|
162 | 162 | @Cached.Shared("writeObject") @Cached WriteAttributeToObjectNode writeObject) {
|
163 | 163 | Object module = readObject.execute(self, T___MODULE__);
|
164 | 164 | if (module == PNone.NO_VALUE) {
|
165 |
| - CompilerDirectives.transferToInterpreter(); |
166 | 165 | PythonObject globals = self.getGlobals();
|
167 | 166 | // __module__: If module name is in globals, use it. Otherwise, use None.
|
168 |
| - try { |
169 |
| - if (globals instanceof PythonModule) { |
170 |
| - module = globals.getAttribute(T___NAME__); |
171 |
| - } else { |
| 167 | + if (globals instanceof PythonModule) { |
| 168 | + module = readGlobals.execute(globals, T___NAME__); |
| 169 | + if (module == PNone.NO_VALUE) { |
| 170 | + module = PNone.NONE; |
| 171 | + } |
| 172 | + } else { |
| 173 | + try { |
172 | 174 | module = getItem.execute(frame, globals, T___NAME__);
|
| 175 | + } catch (PException pe) { |
| 176 | + module = PNone.NONE; |
173 | 177 | }
|
174 |
| - } catch (PException pe) { |
175 |
| - module = PNone.NONE; |
176 | 178 | }
|
177 | 179 | writeObject.execute(self, T___MODULE__, module);
|
178 | 180 | }
|
|
0 commit comments