86
86
import com .oracle .graal .python .annotations .ArgumentClinic ;
87
87
import com .oracle .graal .python .builtins .Builtin ;
88
88
import com .oracle .graal .python .builtins .CoreFunctions ;
89
+ import com .oracle .graal .python .builtins .Python3Core ;
89
90
import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
90
91
import com .oracle .graal .python .builtins .PythonBuiltins ;
91
92
import com .oracle .graal .python .builtins .modules .BuiltinFunctionsFactory .GetAttrNodeFactory ;
124
125
import com .oracle .graal .python .builtins .objects .type .TypeNodes .IsTypeNode ;
125
126
import com .oracle .graal .python .lib .PyNumberAsSizeNode ;
126
127
import com .oracle .graal .python .lib .PyNumberIndexNode ;
128
+ import com .oracle .graal .python .lib .PyObjectAsciiNode ;
129
+ import com .oracle .graal .python .lib .PyObjectReprAsObjectNode ;
127
130
import com .oracle .graal .python .lib .PyObjectSizeNode ;
131
+ import com .oracle .graal .python .lib .PyObjectStrAsJavaStringNode ;
132
+ import com .oracle .graal .python .lib .PyObjectStrAsObjectNode ;
128
133
import com .oracle .graal .python .nodes .BuiltinNames ;
129
134
import com .oracle .graal .python .nodes .ErrorMessages ;
130
135
import com .oracle .graal .python .nodes .GraalPythonTranslationErrorNode ;
183
188
import com .oracle .graal .python .nodes .util .CastToJavaStringNode ;
184
189
import com .oracle .graal .python .runtime .ExecutionContext .IndirectCallContext ;
185
190
import com .oracle .graal .python .runtime .PythonContext ;
186
- import com .oracle .graal .python .builtins .Python3Core ;
187
191
import com .oracle .graal .python .runtime .PythonOptions ;
188
192
import com .oracle .graal .python .runtime .PythonParser .ParserMode ;
189
193
import com .oracle .graal .python .runtime .exception .PException ;
@@ -829,6 +833,7 @@ PCode generic(VirtualFrame frame, Object wSource, Object wFilename, Object wMode
829
833
@ Cached CastToJavaStringNode castStr ,
830
834
@ Cached CastToJavaIntExactNode castInt ,
831
835
@ Cached CodecsModuleBuiltins .HandleDecodingErrorNode handleDecodingErrorNode ,
836
+ @ Cached PyObjectStrAsJavaStringNode asStrNode ,
832
837
@ CachedLibrary ("wSource" ) InteropLibrary interopLib ,
833
838
@ CachedLibrary (limit = "4" ) PythonObjectLibrary lib ,
834
839
@ Cached WarnNode warnNode ) {
@@ -870,7 +875,7 @@ PCode generic(VirtualFrame frame, Object wSource, Object wFilename, Object wMode
870
875
}
871
876
checkOptimize (optimize , kwOptimize );
872
877
}
873
- String source = sourceAsString (wSource , filename , interopLib , lib , handleDecodingErrorNode );
878
+ String source = sourceAsString (frame , wSource , filename , interopLib , lib , handleDecodingErrorNode , asStrNode );
874
879
checkSource (source );
875
880
return compile (source , filename , mode , flags , kwDontInherit , optimize );
876
881
}
@@ -894,7 +899,8 @@ private void checkFlags(int flags) {
894
899
}
895
900
896
901
// 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 ) {
898
904
if (interopLib .isString (source )) {
899
905
try {
900
906
return interopLib .asString (source );
@@ -919,7 +925,7 @@ String sourceAsString(Object source, String filename, InteropLibrary interopLib,
919
925
handleDecodingErrorNode .execute (decoder , "strict" , source );
920
926
throw CompilerDirectives .shouldNotReachHere ();
921
927
} 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 ()));
923
929
}
924
930
}
925
931
return decoder .getString ();
@@ -1527,23 +1533,23 @@ public abstract static class PrintNode extends PythonBuiltinNode {
1527
1533
PNone printNoKeywords (VirtualFrame frame , Object [] values , @ SuppressWarnings ("unused" ) PNone sep , @ SuppressWarnings ("unused" ) PNone end , @ SuppressWarnings ("unused" ) PNone file ,
1528
1534
@ SuppressWarnings ("unused" ) PNone flush ,
1529
1535
@ CachedLibrary (limit = "3" ) PythonObjectLibrary lib ,
1530
- @ CachedLibrary ( limit = "3" ) PythonObjectLibrary valueLib ) {
1536
+ @ Cached PyObjectStrAsObjectNode strNode ) {
1531
1537
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 );
1533
1539
}
1534
1540
1535
1541
@ Specialization (guards = {"!isNone(file)" , "!isNoValue(file)" })
1536
1542
PNone printAllGiven (VirtualFrame frame , Object [] values , String sep , String end , Object file , boolean flush ,
1537
1543
@ CachedLibrary (limit = "3" ) PythonObjectLibrary lib ,
1538
- @ CachedLibrary ( limit = "3" ) PythonObjectLibrary valueLib ) {
1544
+ @ Cached PyObjectStrAsObjectNode strNode ) {
1539
1545
int lastValue = values .length - 1 ;
1540
1546
Object writeMethod = lib .lookupAttributeStrict (file , frame , "write" );
1541
1547
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 ]));
1543
1549
lib .callObject (writeMethod , frame , sep );
1544
1550
}
1545
1551
if (lastValue >= 0 ) {
1546
- lib .callObject (writeMethod , frame , valueLib . asPString ( values [lastValue ]));
1552
+ lib .callObject (writeMethod , frame , strNode . execute ( frame , values [lastValue ]));
1547
1553
}
1548
1554
lib .callObject (writeMethod , frame , end );
1549
1555
if (flush ) {
@@ -1560,7 +1566,7 @@ PNone printGeneric(VirtualFrame frame, Object[] values, Object sepIn, Object end
1560
1566
@ Cached ("createIfTrueNode()" ) CoerceToBooleanNode castFlush ,
1561
1567
@ Cached PRaiseNode raiseNode ,
1562
1568
@ CachedLibrary (limit = "4" ) PythonObjectLibrary lib ,
1563
- @ CachedLibrary ( limit = "3" ) PythonObjectLibrary valueLib ) {
1569
+ @ Cached PyObjectStrAsObjectNode strNode ) {
1564
1570
String sep ;
1565
1571
try {
1566
1572
sep = sepIn instanceof PNone ? DEFAULT_SEPARATOR : castSep .execute (sepIn );
@@ -1587,7 +1593,7 @@ PNone printGeneric(VirtualFrame frame, Object[] values, Object sepIn, Object end
1587
1593
} else {
1588
1594
flush = castFlush .executeBoolean (frame , flushIn );
1589
1595
}
1590
- return printAllGiven (frame , values , sep , end , file , flush , lib , valueLib );
1596
+ return printAllGiven (frame , values , sep , end , file , flush , lib , strNode );
1591
1597
}
1592
1598
1593
1599
private Object getStdout () {
@@ -1628,7 +1634,7 @@ abstract static class ReprNode extends PythonUnaryBuiltinNode {
1628
1634
1629
1635
@ Specialization
1630
1636
static Object repr (VirtualFrame frame , Object obj ,
1631
- @ Cached ObjectNodes . ReprAsObjectNode reprNode ) {
1637
+ @ Cached PyObjectReprAsObjectNode reprNode ) {
1632
1638
return reprNode .execute (frame , obj );
1633
1639
}
1634
1640
}
@@ -1671,7 +1677,7 @@ abstract static class AsciiNode extends PythonUnaryBuiltinNode {
1671
1677
1672
1678
@ Specialization
1673
1679
public static String ascii (VirtualFrame frame , Object obj ,
1674
- @ Cached ObjectNodes . AsciiNode asciiNode ) {
1680
+ @ Cached PyObjectAsciiNode asciiNode ) {
1675
1681
return asciiNode .execute (frame , obj );
1676
1682
}
1677
1683
}
0 commit comments