111
111
import com .oracle .graal .python .builtins .objects .tuple .PTuple ;
112
112
import com .oracle .graal .python .builtins .objects .tuple .StructSequence ;
113
113
import com .oracle .graal .python .builtins .objects .type .TypeNodes ;
114
- import com .oracle .graal .python .lib .PyLongAsIntNode ;
115
114
import com .oracle .graal .python .lib .PyLongAsIntNodeGen ;
116
- import com .oracle .graal .python .lib .PyLongAsLongAndOverflowNode ;
117
115
import com .oracle .graal .python .lib .PyLongAsLongAndOverflowNodeGen ;
118
- import com .oracle .graal .python .lib .PyLongCheckNode ;
116
+ import com .oracle .graal .python .lib .PyLongCheckNodeGen ;
119
117
import com .oracle .graal .python .lib .PyNumberAsSizeNode ;
120
118
import com .oracle .graal .python .lib .PyObjectCallMethodObjArgs ;
121
119
import com .oracle .graal .python .lib .PyObjectLookupAttr ;
@@ -841,18 +839,6 @@ abstract static class ExceptHookNode extends PythonBuiltinNode {
841
839
static final String VALUE_UNKNOWN = "<unknown>" ;
842
840
static final String NL = "\n " ;
843
841
844
- @ Child private ReadAttributeFromObjectNode readAttributeFromObjectNode ;
845
- @ Child private PyLongAsLongAndOverflowNode pyLongAsLongAndOverflowNode ;
846
- @ Child private PyLongAsIntNode pyLongAsIntNode ;
847
- @ Child private PyLongCheckNode pyLongCheckNode ;
848
- @ Child private GetExceptionTracebackNode getExceptionTracebackNode ;
849
- @ Child private GetClassNode getClassNode ;
850
- @ Child private TypeNodes .GetNameNode getNameNode ;
851
- @ Child private PyObjectLookupAttr objectLookupAttr ;
852
- @ Child private CastToJavaStringNode castToJavaStringNode ;
853
- @ Child private PyObjectStrAsObjectNode strAsObjNode ;
854
- @ Child private TracebackBuiltins .GetTracebackFrameNode getTracebackFrameNode ;
855
- @ Child private PyObjectCallMethodObjArgs callMethod ;
856
842
@ Child private TracebackBuiltins .MaterializeTruffleStacktraceNode truffleStacktraceNode ;
857
843
858
844
@ CompilerDirectives .ValueType
@@ -881,127 +867,78 @@ private PTraceback getNextTb(PTraceback traceback) {
881
867
return traceback .getNext ();
882
868
}
883
869
884
- private PyObjectCallMethodObjArgs ensureCallMethodNode () {
885
- if (callMethod == null ) {
886
- CompilerDirectives .transferToInterpreterAndInvalidate ();
887
- callMethod = insert (PyObjectCallMethodObjArgs .create ());
888
- }
889
- return callMethod ;
870
+ private static void write (VirtualFrame frame , Object file , String data ) {
871
+ PyObjectCallMethodObjArgs .getUncached ().execute (frame , file , WRITE , data );
890
872
}
891
873
892
- private void print (VirtualFrame frame , Object file , String data ) {
893
- ensureCallMethodNode ().execute (frame , file , WRITE , data );
874
+ private static void flush (VirtualFrame frame , Object file ) {
875
+ PyObjectCallMethodObjArgs . getUncached ().execute (frame , file , FLUSH );
894
876
}
895
877
896
- private void flush (VirtualFrame frame , Object file ) {
897
- ensureCallMethodNode ().execute (frame , file , FLUSH );
898
- }
899
-
900
- private PFrame getFrame (VirtualFrame frame , PTraceback tb ) {
901
- if (getTracebackFrameNode == null ) {
902
- CompilerDirectives .transferToInterpreterAndInvalidate ();
903
- getTracebackFrameNode = insert (TracebackBuiltins .GetTracebackFrameNode .create ());
904
- }
905
- return getTracebackFrameNode .execute (frame , tb );
878
+ private static PFrame getFrame (VirtualFrame frame , PTraceback tb ) {
879
+ return TracebackBuiltins .GetTracebackFrameNode .getUncached ().execute (frame , tb );
906
880
}
907
881
908
882
private PCode getCode (VirtualFrame frame , PTraceback tb ) {
909
883
return factory ().createCode (getFrame (frame , tb ).getTarget ());
910
884
}
911
885
912
- private Object str (VirtualFrame frame , Object value ) {
913
- if (strAsObjNode == null ) {
914
- CompilerDirectives .transferToInterpreterAndInvalidate ();
915
- strAsObjNode = insert (PyObjectStrAsObjectNode .create ());
916
- }
917
-
886
+ private static Object str (VirtualFrame frame , Object value ) {
918
887
try {
919
- return strAsObjNode .execute (frame , value );
888
+ return PyObjectStrAsObjectNode . getUncached () .execute (frame , value );
920
889
} catch (PException pe ) {
921
890
return null ;
922
891
}
923
892
}
924
893
925
- private String castToString (Object value ) {
926
- if (castToJavaStringNode == null ) {
927
- CompilerDirectives .transferToInterpreterAndInvalidate ();
928
- castToJavaStringNode = insert (CastToJavaStringNode .create ());
929
- }
930
- return castToJavaStringNode .execute (value );
894
+ private static String castToString (Object value ) {
895
+ return CastToJavaStringNode .getUncached ().execute (value );
931
896
}
932
897
933
- private String tryCastToString (Object value ) {
898
+ private static String tryCastToString (Object value ) {
934
899
try {
935
900
return castToString (value );
936
901
} catch (CannotCastException e ) {
937
902
return null ;
938
903
}
939
904
}
940
905
941
- private Object lookupAttr (VirtualFrame frame , Object object , String attr ) {
942
- if (objectLookupAttr == null ) {
943
- CompilerDirectives .transferToInterpreterAndInvalidate ();
944
- objectLookupAttr = insert (PyObjectLookupAttr .create ());
945
- }
946
- return objectLookupAttr .execute (frame , object , attr );
906
+ private static Object lookupAttr (VirtualFrame frame , Object object , String attr ) {
907
+ return PyObjectLookupAttr .getUncached ().execute (frame , object , attr );
947
908
}
948
909
949
- private String lookupStrAttr (VirtualFrame frame , Object object , String attr ) {
910
+ private static String lookupStrAttr (VirtualFrame frame , Object object , String attr ) {
950
911
final Object value = lookupAttr (frame , object , attr );
951
912
return value != PNone .NO_VALUE ? castToString (value ) : null ;
952
913
}
953
914
954
- private boolean hasAttr (VirtualFrame frame , Object object , String attr ) {
915
+ private static boolean hasAttr (VirtualFrame frame , Object object , String attr ) {
955
916
return lookupAttr (frame , object , attr ) != PNone .NO_VALUE ;
956
917
}
957
918
958
- private String getName (Object type ) {
959
- if (getNameNode == null ) {
960
- CompilerDirectives .transferToInterpreterAndInvalidate ();
961
- getNameNode = insert (TypeNodes .GetNameNode .create ());
962
- }
963
- return getNameNode .execute (type );
919
+ private static String getName (Object type ) {
920
+ return TypeNodes .GetNameNode .getUncached ().execute (type );
964
921
}
965
922
966
- private Object getClass (Object object ) {
967
- if (getClassNode == null ) {
968
- CompilerDirectives .transferToInterpreterAndInvalidate ();
969
- getClassNode = insert (GetClassNode .create ());
970
- }
971
- return getClassNode .execute (object );
923
+ private static Object getClass (Object object ) {
924
+ return GetClassNode .getUncached ().execute (object );
972
925
}
973
926
974
- private PTraceback getExceptionTraceback (PBaseException e ) {
975
- if (getExceptionTracebackNode == null ) {
976
- CompilerDirectives .transferToInterpreterAndInvalidate ();
977
- getExceptionTracebackNode = insert (GetExceptionTracebackNode .create ());
978
- }
979
- return getExceptionTracebackNode .execute (e );
927
+ private static PTraceback getExceptionTraceback (PBaseException e ) {
928
+ return GetExceptionTracebackNode .getUncached ().execute (e );
980
929
}
981
930
982
931
private boolean checkLong (Object object ) {
983
- if (pyLongCheckNode == null ) {
984
- CompilerDirectives .transferToInterpreterAndInvalidate ();
985
- pyLongCheckNode = insert (PyLongCheckNode .create ());
986
- }
987
- return pyLongCheckNode .execute (object );
932
+ return PyLongCheckNodeGen .getUncached ().execute (object );
988
933
}
989
934
990
- private int asInt (VirtualFrame frame , Object object ) {
991
- if (pyLongAsIntNode == null ) {
992
- CompilerDirectives .transferToInterpreterAndInvalidate ();
993
- pyLongAsIntNode = insert (PyLongAsIntNodeGen .create ());
994
- }
995
- return pyLongAsIntNode .execute (frame , object );
935
+ private static int asInt (VirtualFrame frame , Object object ) {
936
+ return PyLongAsIntNodeGen .getUncached ().execute (frame , object );
996
937
}
997
938
998
- private long asLongAndOverflow (VirtualFrame frame , Object object , long overflowValue ) {
999
- if (pyLongAsLongAndOverflowNode == null ) {
1000
- CompilerDirectives .transferToInterpreterAndInvalidate ();
1001
- pyLongAsLongAndOverflowNode = insert (PyLongAsLongAndOverflowNodeGen .create ());
1002
- }
939
+ private static long asLongAndOverflow (VirtualFrame frame , Object object , long overflowValue ) {
1003
940
try {
1004
- return pyLongAsLongAndOverflowNode .execute (frame , object );
941
+ return PyLongAsLongAndOverflowNodeGen . getUncached () .execute (frame , object );
1005
942
} catch (OverflowException e ) {
1006
943
if (object instanceof PInt ) {
1007
944
return ((PInt ) object ).isZeroOrNegative () ? 0 : overflowValue ;
@@ -1010,12 +947,8 @@ private long asLongAndOverflow(VirtualFrame frame, Object object, long overflowV
1010
947
}
1011
948
}
1012
949
1013
- private Object readAttr (Object object , String attribute ) {
1014
- if (readAttributeFromObjectNode == null ) {
1015
- CompilerDirectives .transferToInterpreterAndInvalidate ();
1016
- readAttributeFromObjectNode = insert (ReadAttributeFromObjectNode .create ());
1017
- }
1018
- return readAttributeFromObjectNode .execute (object , attribute );
950
+ private static Object readAttr (Object object , String attribute ) {
951
+ return ReadAttributeFromObjectNode .getUncached ().execute (object , attribute );
1019
952
}
1020
953
1021
954
void printTraceBack (VirtualFrame frame , PythonModule sys , Object out , PTraceback tb ) {
@@ -1027,7 +960,7 @@ void printTraceBack(VirtualFrame frame, PythonModule sys, Object out, PTraceback
1027
960
return ;
1028
961
}
1029
962
}
1030
- print (frame , out , "Traceback (most recent call last):\n " );
963
+ write (frame , out , "Traceback (most recent call last):\n " );
1031
964
printInternal (frame , out , tb , limit );
1032
965
}
1033
966
@@ -1036,7 +969,7 @@ void printLineRepeated(VirtualFrame frame, Object out, int count) {
1036
969
cnt -= TB_RECURSIVE_CUTOFF ;
1037
970
final StringBuilder sb = PythonUtils .newStringBuilder (" [Previous line repeated " );
1038
971
PythonUtils .append (sb , cnt , (cnt > 1 ) ? " more times]\n " : " more time]\n " );
1039
- print (frame , out , PythonUtils .sbToString (sb ));
972
+ write (frame , out , PythonUtils .sbToString (sb ));
1040
973
}
1041
974
1042
975
void displayLine (VirtualFrame frame , Object out , String fileName , int lineNo , String name ) {
@@ -1046,7 +979,7 @@ void displayLine(VirtualFrame frame, Object out, String fileName, int lineNo, St
1046
979
1047
980
final StringBuilder sb = PythonUtils .newStringBuilder (" File \" " );
1048
981
PythonUtils .append (sb , fileName , "\" , line " , lineNo , ", in " , name , NL );
1049
- print (frame , out , PythonUtils .sbToString (sb ));
982
+ write (frame , out , PythonUtils .sbToString (sb ));
1050
983
// ignore errors since we can't report them, can we?
1051
984
displaySourceLine (frame , out , fileName , lineNo , 4 );
1052
985
}
@@ -1090,9 +1023,9 @@ CharSequence getSourceLine(String fileName, int lineNo) {
1090
1023
void displaySourceLine (VirtualFrame frame , Object out , String fileName , int lineNo , int indent ) {
1091
1024
final CharSequence line = getSourceLine (fileName , lineNo );
1092
1025
if (line != null ) {
1093
- print (frame , out , getIndent (indent ));
1094
- print (frame , out , PythonUtils .trimLeft (line ));
1095
- print (frame , out , NL );
1026
+ write (frame , out , getIndent (indent ));
1027
+ write (frame , out , PythonUtils .trimLeft (line ));
1028
+ write (frame , out , NL );
1096
1029
}
1097
1030
}
1098
1031
@@ -1222,19 +1155,19 @@ void printErrorText(VirtualFrame frame, Object out, SyntaxErrData syntaxErrData)
1222
1155
text = PythonUtils .substring (text , idx );
1223
1156
}
1224
1157
1225
- print (frame , out , " " );
1226
- print (frame , out , text );
1158
+ write (frame , out , " " );
1159
+ write (frame , out , text );
1227
1160
if (text .charAt (0 ) == '\0' || text .charAt (text .length () - 1 ) != '\n' ) {
1228
- print (frame , out , NL );
1161
+ write (frame , out , NL );
1229
1162
}
1230
1163
if (offset == -1 ) {
1231
1164
return ;
1232
1165
}
1233
- print (frame , out , " " );
1166
+ write (frame , out , " " );
1234
1167
while (--offset > 0 ) {
1235
- print (frame , out , " " );
1168
+ write (frame , out , " " );
1236
1169
}
1237
- print (frame , out , "^\n " );
1170
+ write (frame , out , "^\n " );
1238
1171
}
1239
1172
1240
1173
private String classNameNoDot (String name ) {
@@ -1246,9 +1179,9 @@ void printException(VirtualFrame frame, PythonModule sys, Object out, Object exc
1246
1179
Object value = excValue ;
1247
1180
final Object type = getClass (value );
1248
1181
if (!PGuards .isPBaseException (value )) {
1249
- print (frame , out , "TypeError: print_exception(): Exception expected for value, " );
1250
- print (frame , out , getName (type ));
1251
- print (frame , out , " found\n " );
1182
+ write (frame , out , "TypeError: print_exception(): Exception expected for value, " );
1183
+ write (frame , out , getName (type ));
1184
+ write (frame , out , " found\n " );
1252
1185
return ;
1253
1186
}
1254
1187
@@ -1264,7 +1197,7 @@ void printException(VirtualFrame frame, PythonModule sys, Object out, Object exc
1264
1197
value = syntaxErrData .message ;
1265
1198
StringBuilder sb = PythonUtils .newStringBuilder (" File \" " );
1266
1199
PythonUtils .append (sb , castToString (str (frame , syntaxErrData .fileName )), "\" , line " , syntaxErrData .lineNo , "\n " );
1267
- print (frame , out , PythonUtils .sbToString (sb ));
1200
+ write (frame , out , PythonUtils .sbToString (sb ));
1268
1201
1269
1202
// Can't be bothered to check all those PyFile_WriteString() calls
1270
1203
if (syntaxErrData .text != null ) {
@@ -1282,35 +1215,35 @@ void printException(VirtualFrame frame, PythonModule sys, Object out, Object exc
1282
1215
String moduleName ;
1283
1216
Object v = lookupAttr (frame , type , __MODULE__ );
1284
1217
if (v == PNone .NO_VALUE || !PGuards .isString (v )) {
1285
- print (frame , out , VALUE_UNKNOWN );
1218
+ write (frame , out , VALUE_UNKNOWN );
1286
1219
} else {
1287
1220
moduleName = castToString (v );
1288
1221
if (!moduleName .equals (BUILTINS )) {
1289
- print (frame , out , moduleName );
1290
- print (frame , out , "." );
1222
+ write (frame , out , moduleName );
1223
+ write (frame , out , "." );
1291
1224
}
1292
1225
}
1293
1226
if (className == null ) {
1294
- print (frame , out , VALUE_UNKNOWN );
1227
+ write (frame , out , VALUE_UNKNOWN );
1295
1228
} else {
1296
- print (frame , out , className );
1229
+ write (frame , out , className );
1297
1230
}
1298
1231
1299
1232
if (value != PNone .NONE ) {
1300
1233
// only print colon if the str() of the object is not the empty string
1301
1234
v = str (frame , value );
1302
1235
String s = tryCastToString (v );
1303
1236
if (v == null ) {
1304
- print (frame , out , ": <exception str() failed>" );
1237
+ write (frame , out , ": <exception str() failed>" );
1305
1238
} else if (!PGuards .isString (v ) || (s != null && !s .isEmpty ())) {
1306
- print (frame , out , ": " );
1239
+ write (frame , out , ": " );
1307
1240
}
1308
1241
if (s != null ) {
1309
- print (frame , out , s );
1242
+ write (frame , out , s );
1310
1243
}
1311
1244
}
1312
1245
1313
- print (frame , out , NL );
1246
+ write (frame , out , NL );
1314
1247
}
1315
1248
1316
1249
@ TruffleBoundary
@@ -1326,12 +1259,12 @@ void printExceptionRecursive(MaterializedFrame frame, PythonModule sys, Object o
1326
1259
if (cause != null ) {
1327
1260
if (!contains (seen , cause )) {
1328
1261
printExceptionRecursive (frame , sys , out , cause , seen );
1329
- print (frame , out , CAUSE_MESSAGE );
1262
+ write (frame , out , CAUSE_MESSAGE );
1330
1263
}
1331
1264
} else if (context != null && !exc .getSuppressContext ()) {
1332
1265
if (!contains (seen , context )) {
1333
1266
printExceptionRecursive (frame , sys , out , context , seen );
1334
- print (frame , out , CONTEXT_MESSAGE );
1267
+ write (frame , out , CONTEXT_MESSAGE );
1335
1268
}
1336
1269
}
1337
1270
}
0 commit comments