8686import com .oracle .graal .python .annotations .ArgumentClinic ;
8787import com .oracle .graal .python .builtins .Builtin ;
8888import com .oracle .graal .python .builtins .CoreFunctions ;
89+ import com .oracle .graal .python .builtins .Python3Core ;
8990import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
9091import com .oracle .graal .python .builtins .PythonBuiltins ;
9192import com .oracle .graal .python .builtins .modules .BuiltinFunctionsFactory .GetAttrNodeFactory ;
124125import com .oracle .graal .python .builtins .objects .type .TypeNodes .IsTypeNode ;
125126import com .oracle .graal .python .lib .PyNumberAsSizeNode ;
126127import com .oracle .graal .python .lib .PyNumberIndexNode ;
128+ import com .oracle .graal .python .lib .PyObjectAsciiNode ;
129+ import com .oracle .graal .python .lib .PyObjectReprAsObjectNode ;
127130import com .oracle .graal .python .lib .PyObjectSizeNode ;
131+ import com .oracle .graal .python .lib .PyObjectStrAsJavaStringNode ;
132+ import com .oracle .graal .python .lib .PyObjectStrAsObjectNode ;
128133import com .oracle .graal .python .nodes .BuiltinNames ;
129134import com .oracle .graal .python .nodes .ErrorMessages ;
130135import com .oracle .graal .python .nodes .GraalPythonTranslationErrorNode ;
183188import com .oracle .graal .python .nodes .util .CastToJavaStringNode ;
184189import com .oracle .graal .python .runtime .ExecutionContext .IndirectCallContext ;
185190import com .oracle .graal .python .runtime .PythonContext ;
186- import com .oracle .graal .python .builtins .Python3Core ;
187191import com .oracle .graal .python .runtime .PythonOptions ;
188192import com .oracle .graal .python .runtime .PythonParser .ParserMode ;
189193import com .oracle .graal .python .runtime .exception .PException ;
@@ -829,6 +833,7 @@ PCode generic(VirtualFrame frame, Object wSource, Object wFilename, Object wMode
829833 @ Cached CastToJavaStringNode castStr ,
830834 @ Cached CastToJavaIntExactNode castInt ,
831835 @ Cached CodecsModuleBuiltins .HandleDecodingErrorNode handleDecodingErrorNode ,
836+ @ Cached PyObjectStrAsJavaStringNode asStrNode ,
832837 @ CachedLibrary ("wSource" ) InteropLibrary interopLib ,
833838 @ CachedLibrary (limit = "4" ) PythonObjectLibrary lib ,
834839 @ Cached WarnNode warnNode ) {
@@ -870,7 +875,7 @@ PCode generic(VirtualFrame frame, Object wSource, Object wFilename, Object wMode
870875 }
871876 checkOptimize (optimize , kwOptimize );
872877 }
873- String source = sourceAsString (wSource , filename , interopLib , lib , handleDecodingErrorNode );
878+ String source = sourceAsString (frame , wSource , filename , interopLib , lib , handleDecodingErrorNode , asStrNode );
874879 checkSource (source );
875880 return compile (source , filename , mode , flags , kwDontInherit , optimize );
876881 }
@@ -894,7 +899,8 @@ private void checkFlags(int flags) {
894899 }
895900
896901 // modeled after _Py_SourceAsString
897- String sourceAsString (Object source , String filename , InteropLibrary interopLib , PythonObjectLibrary pyLib , CodecsModuleBuiltins .HandleDecodingErrorNode handleDecodingErrorNode ) {
902+ String sourceAsString (VirtualFrame frame , Object source , String filename , InteropLibrary interopLib , PythonObjectLibrary pyLib ,
903+ CodecsModuleBuiltins .HandleDecodingErrorNode handleDecodingErrorNode , PyObjectStrAsJavaStringNode asStrNode ) {
898904 if (interopLib .isString (source )) {
899905 try {
900906 return interopLib .asString (source );
@@ -919,7 +925,7 @@ String sourceAsString(Object source, String filename, InteropLibrary interopLib,
919925 handleDecodingErrorNode .execute (decoder , "strict" , source );
920926 throw CompilerDirectives .shouldNotReachHere ();
921927 } catch (PException e ) {
922- throw raiseInvalidSyntax (filename , "(unicode error) %s" , pyLib . asPString ( e .getEscapedException ()));
928+ throw raiseInvalidSyntax (filename , "(unicode error) %s" , asStrNode . execute ( frame , e .getEscapedException ()));
923929 }
924930 }
925931 return decoder .getString ();
@@ -1527,23 +1533,23 @@ public abstract static class PrintNode extends PythonBuiltinNode {
15271533 PNone printNoKeywords (VirtualFrame frame , Object [] values , @ SuppressWarnings ("unused" ) PNone sep , @ SuppressWarnings ("unused" ) PNone end , @ SuppressWarnings ("unused" ) PNone file ,
15281534 @ SuppressWarnings ("unused" ) PNone flush ,
15291535 @ CachedLibrary (limit = "3" ) PythonObjectLibrary lib ,
1530- @ CachedLibrary ( limit = "3" ) PythonObjectLibrary valueLib ) {
1536+ @ Cached PyObjectStrAsObjectNode strNode ) {
15311537 Object stdout = getStdout ();
1532- return printAllGiven (frame , values , DEFAULT_SEPARATOR , DEFAULT_END , stdout , false , lib , valueLib );
1538+ return printAllGiven (frame , values , DEFAULT_SEPARATOR , DEFAULT_END , stdout , false , lib , strNode );
15331539 }
15341540
15351541 @ Specialization (guards = {"!isNone(file)" , "!isNoValue(file)" })
15361542 PNone printAllGiven (VirtualFrame frame , Object [] values , String sep , String end , Object file , boolean flush ,
15371543 @ CachedLibrary (limit = "3" ) PythonObjectLibrary lib ,
1538- @ CachedLibrary ( limit = "3" ) PythonObjectLibrary valueLib ) {
1544+ @ Cached PyObjectStrAsObjectNode strNode ) {
15391545 int lastValue = values .length - 1 ;
15401546 Object writeMethod = lib .lookupAttributeStrict (file , frame , "write" );
15411547 for (int i = 0 ; i < lastValue ; i ++) {
1542- lib .callObject (writeMethod , frame , valueLib . asPString ( values [i ]));
1548+ lib .callObject (writeMethod , frame , strNode . execute ( frame , values [i ]));
15431549 lib .callObject (writeMethod , frame , sep );
15441550 }
15451551 if (lastValue >= 0 ) {
1546- lib .callObject (writeMethod , frame , valueLib . asPString ( values [lastValue ]));
1552+ lib .callObject (writeMethod , frame , strNode . execute ( frame , values [lastValue ]));
15471553 }
15481554 lib .callObject (writeMethod , frame , end );
15491555 if (flush ) {
@@ -1560,7 +1566,7 @@ PNone printGeneric(VirtualFrame frame, Object[] values, Object sepIn, Object end
15601566 @ Cached ("createIfTrueNode()" ) CoerceToBooleanNode castFlush ,
15611567 @ Cached PRaiseNode raiseNode ,
15621568 @ CachedLibrary (limit = "4" ) PythonObjectLibrary lib ,
1563- @ CachedLibrary ( limit = "3" ) PythonObjectLibrary valueLib ) {
1569+ @ Cached PyObjectStrAsObjectNode strNode ) {
15641570 String sep ;
15651571 try {
15661572 sep = sepIn instanceof PNone ? DEFAULT_SEPARATOR : castSep .execute (sepIn );
@@ -1587,7 +1593,7 @@ PNone printGeneric(VirtualFrame frame, Object[] values, Object sepIn, Object end
15871593 } else {
15881594 flush = castFlush .executeBoolean (frame , flushIn );
15891595 }
1590- return printAllGiven (frame , values , sep , end , file , flush , lib , valueLib );
1596+ return printAllGiven (frame , values , sep , end , file , flush , lib , strNode );
15911597 }
15921598
15931599 private Object getStdout () {
@@ -1628,7 +1634,7 @@ abstract static class ReprNode extends PythonUnaryBuiltinNode {
16281634
16291635 @ Specialization
16301636 static Object repr (VirtualFrame frame , Object obj ,
1631- @ Cached ObjectNodes . ReprAsObjectNode reprNode ) {
1637+ @ Cached PyObjectReprAsObjectNode reprNode ) {
16321638 return reprNode .execute (frame , obj );
16331639 }
16341640 }
@@ -1671,7 +1677,7 @@ abstract static class AsciiNode extends PythonUnaryBuiltinNode {
16711677
16721678 @ Specialization
16731679 public static String ascii (VirtualFrame frame , Object obj ,
1674- @ Cached ObjectNodes . AsciiNode asciiNode ) {
1680+ @ Cached PyObjectAsciiNode asciiNode ) {
16751681 return asciiNode .execute (frame , obj );
16761682 }
16771683 }
0 commit comments