113
113
import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
114
114
import com .oracle .graal .python .builtins .PythonBuiltins ;
115
115
import com .oracle .graal .python .builtins .modules .BuiltinFunctionsFactory .GetAttrNodeFactory ;
116
- import com .oracle .graal .python .builtins .modules .BuiltinFunctionsFactory .GlobalsNodeFactory ;
117
116
import com .oracle .graal .python .builtins .modules .BuiltinFunctionsFactory .HexNodeFactory ;
118
117
import com .oracle .graal .python .builtins .modules .BuiltinFunctionsFactory .OctNodeFactory ;
119
118
import com .oracle .graal .python .builtins .modules .WarningsModuleBuiltins .WarnNode ;
164
163
import com .oracle .graal .python .lib .GetNextNode ;
165
164
import com .oracle .graal .python .lib .PyCallableCheckNode ;
166
165
import com .oracle .graal .python .lib .PyEvalGetGlobals ;
166
+ import com .oracle .graal .python .lib .PyEvalGetLocals ;
167
167
import com .oracle .graal .python .lib .PyMappingCheckNode ;
168
168
import com .oracle .graal .python .lib .PyNumberAsSizeNode ;
169
169
import com .oracle .graal .python .lib .PyNumberIndexNode ;
215
215
import com .oracle .graal .python .nodes .expression .BinaryOpNode ;
216
216
import com .oracle .graal .python .nodes .expression .CoerceToBooleanNode ;
217
217
import com .oracle .graal .python .nodes .expression .TernaryArithmetic ;
218
+ import com .oracle .graal .python .nodes .frame .GetFrameLocalsNode ;
218
219
import com .oracle .graal .python .nodes .frame .ReadCallerFrameNode ;
219
220
import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
220
221
import com .oracle .graal .python .nodes .function .PythonBuiltinNode ;
@@ -765,12 +766,11 @@ public abstract static class DirNode extends PythonBuiltinNode {
765
766
// logic like in 'Objects/object.c: _dir_locals'
766
767
@ Specialization (guards = "isNoValue(object)" )
767
768
Object locals (VirtualFrame frame , @ SuppressWarnings ("unused" ) Object object ,
768
- @ Cached ReadCallerFrameNode readCallerFrameNode ,
769
+ @ Cached PyEvalGetLocals getLocals ,
769
770
@ Cached ("create(T_KEYS)" ) LookupAndCallUnaryNode callKeysNode ,
770
771
@ Cached ListBuiltins .ListSortNode sortNode ,
771
772
@ Cached ListNodes .ConstructListNode constructListNode ) {
772
-
773
- Object localsDict = LocalsNode .getLocalsDict (frame , readCallerFrameNode );
773
+ Object localsDict = getLocals .execute (frame );
774
774
Object keysObj = callKeysNode .executeObject (frame , localsDict );
775
775
PList list = constructListNode .execute (frame , keysObj );
776
776
sortNode .execute (frame , list );
@@ -861,8 +861,8 @@ private static void inheritGlobals(PFrame callerFrame, Object[] args) {
861
861
PArguments .setGlobals (args , callerFrame .getGlobals ());
862
862
}
863
863
864
- private static void inheritLocals (PFrame callerFrame , Object [] args ) {
865
- Object callerLocals = callerFrame . getLocals ( );
864
+ private static void inheritLocals (VirtualFrame frame , PFrame callerFrame , Object [] args , GetFrameLocalsNode getFrameLocalsNode ) {
865
+ Object callerLocals = getFrameLocalsNode . execute ( frame , callerFrame );
866
866
setCustomLocals (args , callerLocals );
867
867
}
868
868
@@ -889,12 +889,13 @@ private void setCustomGlobals(VirtualFrame frame, PDict globals, HashingCollecti
889
889
@ Specialization
890
890
Object execInheritGlobalsInheritLocals (VirtualFrame frame , Object source , @ SuppressWarnings ("unused" ) PNone globals , @ SuppressWarnings ("unused" ) PNone locals ,
891
891
@ Cached ReadCallerFrameNode readCallerFrameNode ,
892
- @ Shared ("getCt" ) @ Cached CodeNodes .GetCodeCallTargetNode getCt ) {
892
+ @ Shared ("getCt" ) @ Cached CodeNodes .GetCodeCallTargetNode getCt ,
893
+ @ Cached GetFrameLocalsNode getFrameLocalsNode ) {
893
894
PCode code = createAndCheckCode (frame , source );
894
895
PFrame callerFrame = readCallerFrameNode .executeWith (frame , 0 );
895
896
Object [] args = PArguments .create ();
896
897
inheritGlobals (callerFrame , args );
897
- inheritLocals (callerFrame , args );
898
+ inheritLocals (frame , callerFrame , args , getFrameLocalsNode );
898
899
899
900
return invokeNode .execute (frame , getCt .execute (code ), args );
900
901
}
@@ -2265,9 +2266,9 @@ private Object iterateGeneric(VirtualFrame frame, Object iterator, Object start,
2265
2266
}
2266
2267
}
2267
2268
2268
- @ Builtin (name = "globals" )
2269
+ @ Builtin (name = "globals" , needsFrame = true , alwaysNeedsCallerFrame = true )
2269
2270
@ GenerateNodeFactory
2270
- public abstract static class GlobalsNode extends PythonBuiltinNode {
2271
+ abstract static class GlobalsNode extends PythonBuiltinNode {
2271
2272
private final ConditionProfile condProfile = ConditionProfile .create ();
2272
2273
2273
2274
@ Specialization
@@ -2281,10 +2282,6 @@ public Object globals(VirtualFrame frame,
2281
2282
return globals ;
2282
2283
}
2283
2284
}
2284
-
2285
- public static GlobalsNode create () {
2286
- return GlobalsNodeFactory .create (null );
2287
- }
2288
2285
}
2289
2286
2290
2287
@ Builtin (name = "locals" , needsFrame = true , alwaysNeedsCallerFrame = true )
@@ -2293,18 +2290,8 @@ abstract static class LocalsNode extends PythonBuiltinNode {
2293
2290
2294
2291
@ Specialization
2295
2292
Object locals (VirtualFrame frame ,
2296
- @ Cached ReadCallerFrameNode readCallerFrameNode ) {
2297
- return getLocalsDict (frame , readCallerFrameNode );
2298
- }
2299
-
2300
- static Object getLocalsDict (VirtualFrame frame , ReadCallerFrameNode readCallerFrameNode ) {
2301
- PFrame callerFrame = readCallerFrameNode .executeWith (frame , 0 );
2302
- return callerFrame .getLocals ();
2303
- }
2304
-
2305
- @ NeverDefault
2306
- public static LocalsNode create () {
2307
- return BuiltinFunctionsFactory .LocalsNodeFactory .create (null );
2293
+ @ Cached PyEvalGetLocals getLocals ) {
2294
+ return getLocals .execute (frame );
2308
2295
}
2309
2296
}
2310
2297
@@ -2314,8 +2301,8 @@ abstract static class VarsNode extends PythonUnaryBuiltinNode {
2314
2301
2315
2302
@ Specialization (guards = "isNoValue(none)" )
2316
2303
Object vars (VirtualFrame frame , @ SuppressWarnings ("unused" ) PNone none ,
2317
- @ Cached LocalsNode localsNode ) {
2318
- return localsNode .execute (frame );
2304
+ @ Cached PyEvalGetLocals getLocals ) {
2305
+ return getLocals .execute (frame );
2319
2306
}
2320
2307
2321
2308
@ Specialization (guards = "!isNoValue(obj)" )
0 commit comments