27
27
28
28
import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
29
29
import com .oracle .graal .python .builtins .objects .dict .PDict ;
30
+ import com .oracle .graal .python .builtins .objects .frame .PFrame ;
30
31
import com .oracle .graal .python .builtins .objects .function .PArguments ;
31
32
import com .oracle .graal .python .builtins .objects .mappingproxy .PMappingproxy ;
32
33
import com .oracle .graal .python .builtins .objects .module .PythonModule ;
38
39
import com .oracle .graal .python .nodes .attributes .GetAttributeNode ;
39
40
import com .oracle .graal .python .nodes .attributes .GetAttributeNode .GetAnyAttributeNode ;
40
41
import com .oracle .graal .python .nodes .attributes .SetAttributeNode ;
42
+ import com .oracle .graal .python .nodes .frame .MaterializeFrameNode ;
43
+ import com .oracle .graal .python .nodes .frame .ReadLocalsNode ;
41
44
import com .oracle .graal .python .nodes .object .IsBuiltinClassProfile ;
42
45
import com .oracle .graal .python .nodes .subscript .GetItemNode ;
43
46
import com .oracle .graal .python .nodes .subscript .SetItemNode ;
@@ -65,6 +68,8 @@ public class ImportStarNode extends AbstractImportNode {
65
68
@ Child private CastToJavaStringNode castToStringNode ;
66
69
@ Child private GetAnyAttributeNode readNode ;
67
70
@ Child private PRaiseNode raiseNode ;
71
+ @ Child private MaterializeFrameNode getPFrameNode ;
72
+ @ Child private ReadLocalsNode getLocalsNode ;
68
73
69
74
@ Child private IsBuiltinClassProfile isAttributeErrorProfile ;
70
75
@@ -105,7 +110,8 @@ public ImportStarNode(String moduleName, int level) {
105
110
@ Override
106
111
public void executeVoid (VirtualFrame frame ) {
107
112
Object importedModule = importModule (frame , moduleName , PArguments .getGlobals (frame ), new String []{"*" }, level );
108
- PythonObject globals = PArguments .getGlobals (frame );
113
+ PFrame pFrame = ensureGetPFrameNode ().execute (frame , this , true , true );
114
+ PythonObject locals = (PythonObject ) ensureGetLocalsNode ().execute (frame , pFrame );
109
115
110
116
if (javaImport .profile (emulateJython () && getContext ().getEnv ().isHostObject (importedModule ))) {
111
117
try {
@@ -116,7 +122,7 @@ public void executeVoid(VirtualFrame frame) {
116
122
// interop protocol guarantees these are Strings
117
123
String attrName = (String ) interopLib .readArrayElement (hostAttrs , i );
118
124
Object attr = interopLib .readMember (importedModule , attrName );
119
- writeAttribute (frame , globals , attrName , attr );
125
+ writeAttribute (frame , locals , attrName , attr );
120
126
}
121
127
} catch (UnknownIdentifierException | UnsupportedMessageException | InvalidArrayIndexException e ) {
122
128
CompilerDirectives .transferToInterpreterAndInvalidate ();
@@ -137,7 +143,7 @@ public void executeVoid(VirtualFrame frame) {
137
143
throw raise (PythonBuiltinClassType .TypeError , ErrorMessages .ATTR_NAME_MUST_BE_STRING , attrNameObj );
138
144
}
139
145
Object attr = readAttribute (frame , importedModule , attrName );
140
- writeAttribute (frame , globals , attrName , attr );
146
+ writeAttribute (frame , locals , attrName , attr );
141
147
}
142
148
} catch (PException e ) {
143
149
e .expectAttributeError (ensureIsAttributeErrorProfile ());
@@ -148,7 +154,7 @@ public void executeVoid(VirtualFrame frame) {
148
154
// 'ceval.c: import_all_from')
149
155
if (!name .startsWith ("__" )) {
150
156
Object attr = readAttribute (frame , importedModule , name );
151
- writeAttribute (frame , globals , name , attr );
157
+ writeAttribute (frame , locals , name , attr );
152
158
}
153
159
}
154
160
}
@@ -179,6 +185,22 @@ private CastToJavaStringNode ensureCastToStringNode() {
179
185
return castToStringNode ;
180
186
}
181
187
188
+ private MaterializeFrameNode ensureGetPFrameNode () {
189
+ if (getPFrameNode == null ) {
190
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
191
+ getPFrameNode = insert (MaterializeFrameNode .create ());
192
+ }
193
+ return getPFrameNode ;
194
+ }
195
+
196
+ private ReadLocalsNode ensureGetLocalsNode () {
197
+ if (getLocalsNode == null ) {
198
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
199
+ getLocalsNode = insert (ReadLocalsNode .create ());
200
+ }
201
+ return getLocalsNode ;
202
+ }
203
+
182
204
private IsBuiltinClassProfile ensureIsAttributeErrorProfile () {
183
205
if (isAttributeErrorProfile == null ) {
184
206
CompilerDirectives .transferToInterpreterAndInvalidate ();
0 commit comments