@@ -788,16 +788,27 @@ abstract static class CreateEvalExecArgumentsNode extends Node {
788
788
@ Specialization
789
789
static Object [] inheritGlobals (VirtualFrame frame , Node inliningTarget , @ SuppressWarnings ("unused" ) PNone globals , Object locals , TruffleString mode ,
790
790
@ Exclusive @ Cached ReadCallerFrameNode readCallerFrameNode ,
791
+ @ Exclusive @ Cached GetOrCreateDictNode getOrCreateDictNode ,
792
+ @ Exclusive @ Cached InlinedConditionProfile haveCallerFrameProfile ,
791
793
@ Exclusive @ Cached InlinedConditionProfile haveLocals ,
792
794
@ Exclusive @ Cached PyMappingCheckNode mappingCheckNode ,
793
795
@ Exclusive @ Cached GetFrameLocalsNode getFrameLocalsNode ,
794
796
@ Exclusive @ Cached PRaiseNode raiseNode ) {
795
797
PFrame callerFrame = readCallerFrameNode .executeWith (frame , 0 );
796
798
Object [] args = PArguments .create ();
797
- PArguments .setGlobals (args , callerFrame .getGlobals ());
799
+ boolean haveCallerFrame = haveCallerFrameProfile .profile (inliningTarget , callerFrame != null );
800
+ if (haveCallerFrame ) {
801
+ PArguments .setGlobals (args , callerFrame .getGlobals ());
802
+ } else {
803
+ PArguments .setGlobals (args , getOrCreateDictNode .execute (inliningTarget , PythonContext .get (inliningTarget ).getMainModule ()));
804
+ }
798
805
if (haveLocals .profile (inliningTarget , locals instanceof PNone )) {
799
- Object callerLocals = getFrameLocalsNode .execute (inliningTarget , callerFrame );
800
- setCustomLocals (args , callerLocals );
806
+ if (haveCallerFrame ) {
807
+ Object callerLocals = getFrameLocalsNode .execute (inliningTarget , callerFrame );
808
+ setCustomLocals (args , callerLocals );
809
+ } else {
810
+ setCustomLocals (args , PArguments .getGlobals (args ));
811
+ }
801
812
} else {
802
813
if (!mappingCheckNode .execute (inliningTarget , locals )) {
803
814
throw raiseNode .raise (inliningTarget , TypeError , ErrorMessages .LOCALS_MUST_BE_MAPPING , mode , locals );
@@ -951,15 +962,21 @@ public final PCode compile(VirtualFrame frame, Object source, TruffleString file
951
962
protected abstract Object executeInternal (VirtualFrame frame , Object source , TruffleString filename , TruffleString mode , int flags , boolean dontInherit , int optimize ,
952
963
int featureVersion );
953
964
965
+ private int inheritFlags (VirtualFrame frame , int flags , ReadCallerFrameNode readCallerFrame ) {
966
+ PFrame fr = readCallerFrame .executeWith (frame , 0 );
967
+ if (fr != null ) {
968
+ PCode code = PFactory .createCode (PythonLanguage .get (this ), fr .getTarget ());
969
+ flags |= code .getFlags () & PyCF_MASK ;
970
+ }
971
+ return flags ;
972
+ }
973
+
954
974
@ Specialization
955
975
Object doCompile (VirtualFrame frame , TruffleString expression , TruffleString filename , TruffleString mode , int flags , boolean dontInherit , int optimize ,
956
976
int featureVersion ,
957
- @ Shared @ Cached ReadCallerFrameNode readCallerFrame ,
958
- @ Bind PythonLanguage language ) {
977
+ @ Shared @ Cached ReadCallerFrameNode readCallerFrame ) {
959
978
if (!dontInherit ) {
960
- PFrame fr = readCallerFrame .executeWith (frame , 0 );
961
- PCode code = PFactory .createCode (language , fr .getTarget ());
962
- flags |= code .getFlags () & PyCF_MASK ;
979
+ flags = inheritFlags (frame , flags , readCallerFrame );
963
980
}
964
981
EncapsulatingNodeReference encapsulating = EncapsulatingNodeReference .getCurrent ();
965
982
Node encapsulatingNode = encapsulating .set (this );
@@ -1037,7 +1054,7 @@ Object compile(TruffleString expression, TruffleString filename, TruffleString m
1037
1054
1038
1055
@ Specialization (limit = "3" )
1039
1056
@ SuppressWarnings ("truffle-static-method" )
1040
- Object generic (VirtualFrame frame , Object wSource , Object wFilename , TruffleString mode , int flags , @ SuppressWarnings ( "unused" ) boolean dontInherit , int optimize , int featureVersion ,
1057
+ Object generic (VirtualFrame frame , Object wSource , Object wFilename , TruffleString mode , int flags , boolean dontInherit , int optimize , int featureVersion ,
1041
1058
@ CachedLibrary (limit = "3" ) PythonBufferAcquireLibrary acquireLib ,
1042
1059
@ CachedLibrary (limit = "3" ) PythonBufferAccessLibrary bufferLib ,
1043
1060
@ Bind PythonContext context ,
@@ -1056,9 +1073,7 @@ Object generic(VirtualFrame frame, Object wSource, Object wFilename, TruffleStri
1056
1073
TruffleString filename = asPath .execute (frame , wFilename );
1057
1074
1058
1075
if (!dontInherit ) {
1059
- PFrame fr = readCallerFrame .executeWith (frame , 0 );
1060
- PCode code = PFactory .createCode (PythonLanguage .get (inliningTarget ), fr .getTarget ());
1061
- flags |= code .getFlags () & PyCF_MASK ;
1076
+ flags = inheritFlags (frame , flags , readCallerFrame );
1062
1077
}
1063
1078
1064
1079
EncapsulatingNodeReference encapsulating = EncapsulatingNodeReference .getCurrent ();
0 commit comments