60
60
import static com .oracle .graal .python .nodes .SpecialMethodNames .__GETNEWARGS__ ;
61
61
import static com .oracle .graal .python .nodes .SpecialMethodNames .__GETSTATE__ ;
62
62
import static com .oracle .graal .python .nodes .SpecialMethodNames .__NEW__ ;
63
- import static com .oracle .graal .python .nodes .SpecialMethodNames .__REPR__ ;
64
63
import static com .oracle .graal .python .runtime .exception .PythonErrorType .TypeError ;
65
64
import static com .oracle .graal .python .runtime .object .IDUtils .ID_ELLIPSIS ;
66
65
import static com .oracle .graal .python .runtime .object .IDUtils .ID_EMPTY_BYTES ;
78
77
import com .oracle .graal .python .builtins .modules .BuiltinFunctions ;
79
78
import com .oracle .graal .python .builtins .objects .PNone ;
80
79
import com .oracle .graal .python .builtins .objects .PNotImplemented ;
81
- import com .oracle .graal .python .builtins .objects .bytes .BytesUtils ;
82
80
import com .oracle .graal .python .builtins .objects .bytes .PBytes ;
83
81
import com .oracle .graal .python .builtins .objects .cext .PythonAbstractNativeObject ;
84
82
import com .oracle .graal .python .builtins .objects .common .EconomicMapStorage ;
90
88
import com .oracle .graal .python .builtins .objects .dict .PDict ;
91
89
import com .oracle .graal .python .builtins .objects .ellipsis .PEllipsis ;
92
90
import com .oracle .graal .python .builtins .objects .floats .PFloat ;
93
- import com .oracle .graal .python .builtins .objects .function .PArguments ;
94
91
import com .oracle .graal .python .builtins .objects .ints .PInt ;
95
92
import com .oracle .graal .python .builtins .objects .list .PList ;
96
93
import com .oracle .graal .python .builtins .objects .object .ObjectNodesFactory .GetFullyQualifiedNameNodeGen ;
103
100
import com .oracle .graal .python .lib .PyObjectLookupAttr ;
104
101
import com .oracle .graal .python .lib .PyObjectSizeNode ;
105
102
import com .oracle .graal .python .nodes .BuiltinNames ;
106
- import com .oracle .graal .python .nodes .ErrorMessages ;
107
103
import com .oracle .graal .python .nodes .PGuards ;
108
104
import com .oracle .graal .python .nodes .PNodeWithContext ;
109
105
import com .oracle .graal .python .nodes .PNodeWithState ;
110
- import com .oracle .graal .python .nodes .PRaiseNode ;
111
106
import com .oracle .graal .python .nodes .SpecialAttributeNames ;
112
107
import com .oracle .graal .python .nodes .attributes .ReadAttributeFromDynamicObjectNode ;
113
108
import com .oracle .graal .python .nodes .attributes .WriteAttributeToDynamicObjectNode ;
134
129
import com .oracle .truffle .api .library .CachedLibrary ;
135
130
import com .oracle .truffle .api .nodes .Node ;
136
131
import com .oracle .truffle .api .object .HiddenKey ;
137
- import com .oracle .truffle .api .profiles .BranchProfile ;
138
132
import com .oracle .truffle .api .profiles .ConditionProfile ;
139
133
140
134
public abstract class ObjectNodes {
@@ -772,73 +766,6 @@ static String get(VirtualFrame frame, Object self,
772
766
}
773
767
}
774
768
775
- /**
776
- * Equivalent of CPython's {@code PyObject_Repr}.
777
- *
778
- * The output can be either a {@link String} or a {@link PString}.
779
- *
780
- * @see ReprAsJavaStringNode
781
- */
782
- @ GenerateUncached
783
- public abstract static class ReprAsObjectNode extends PNodeWithContext {
784
- public abstract Object execute (Frame frame , Object object );
785
-
786
- @ Specialization (limit = "3" )
787
- static Object repr (VirtualFrame frame , Object obj ,
788
- @ CachedLibrary ("obj" ) PythonObjectLibrary objLib ,
789
- @ CachedLibrary (limit = "2" ) PythonObjectLibrary methodLib ,
790
- @ Cached DefaultObjectReprNode defaultRepr ,
791
- @ Cached ConditionProfile hasRepr ,
792
- @ Cached ConditionProfile isString ,
793
- @ Cached ConditionProfile isPString ,
794
- @ Cached BranchProfile getRaisedException ,
795
- @ Cached PRaiseNode raiseNode ) {
796
- Object reprMethod = objLib .lookupAttributeOnType (obj , __REPR__ );
797
- if (hasRepr .profile (reprMethod != PNone .NO_VALUE )) {
798
- Object result = methodLib .callUnboundMethodIgnoreGetException (reprMethod , frame , obj );
799
- if (isString .profile (result instanceof String ) || isPString .profile (result instanceof PString )) {
800
- return result ;
801
- }
802
- if (result != PNone .NO_VALUE ) {
803
- throw raiseNode .raise (TypeError , ErrorMessages .RETURNED_NON_STRING , __REPR__ , obj );
804
- }
805
- getRaisedException .enter ();
806
- }
807
- return defaultRepr .execute (frame , obj );
808
- }
809
-
810
- public static ReprAsObjectNode create () {
811
- return ObjectNodesFactory .ReprAsObjectNodeGen .create ();
812
- }
813
- }
814
-
815
- /**
816
- * Equivalent of CPython's {@code PyObject_Repr}.
817
- *
818
- * The output is always coerced to a Java {@link String}
819
- *
820
- * @see ReprAsObjectNode
821
- */
822
- @ GenerateUncached
823
- public abstract static class ReprAsJavaStringNode extends PNodeWithContext {
824
- public abstract String execute (Frame frame , Object object );
825
-
826
- @ Specialization
827
- static String repr (VirtualFrame frame , Object obj ,
828
- @ Cached ReprAsObjectNode reprNode ,
829
- @ Cached CastToJavaStringNode cast ) {
830
- return cast .execute (reprNode .execute (frame , obj ));
831
- }
832
-
833
- public static ReprAsJavaStringNode create () {
834
- return ObjectNodesFactory .ReprAsJavaStringNodeGen .create ();
835
- }
836
-
837
- public static ReprAsJavaStringNode getUncached () {
838
- return ObjectNodesFactory .ReprAsJavaStringNodeGen .getUncached ();
839
- }
840
- }
841
-
842
769
/**
843
770
* Default repr for objects that don't override {@code __repr__}
844
771
*/
@@ -858,78 +785,4 @@ public static DefaultObjectReprNode create() {
858
785
}
859
786
}
860
787
861
- /**
862
- * Equivalent of CPython's {@code PyObject_Str}.
863
- *
864
- * The output can be either a {@link String} or a {@link PString}.
865
- *
866
- * @see StrAsJavaStringNode
867
- */
868
- @ GenerateUncached
869
- public abstract static class StrAsObjectNode extends PNodeWithContext {
870
- public abstract Object execute (Frame frame , Object object );
871
-
872
- @ Specialization (limit = "3" )
873
- static Object str (VirtualFrame frame , Object obj ,
874
- @ Cached ConditionProfile gotState ,
875
- @ CachedLibrary ("obj" ) PythonObjectLibrary objLib ) {
876
- if (gotState .profile (frame != null )) {
877
- return objLib .asPStringWithState (obj , PArguments .getThreadState (frame ));
878
- } else {
879
- return objLib .asPString (obj );
880
- }
881
- }
882
-
883
- public static StrAsObjectNode create () {
884
- return ObjectNodesFactory .StrAsObjectNodeGen .create ();
885
- }
886
- }
887
-
888
- /**
889
- * Equivalent of CPython's {@code PyObject_Str}.
890
- *
891
- * The output is always coerced to a Java {@link String}
892
- *
893
- * @see StrAsObjectNode
894
- */
895
- @ GenerateUncached
896
- public abstract static class StrAsJavaStringNode extends PNodeWithContext {
897
- public abstract String execute (Frame frame , Object object );
898
-
899
- @ Specialization
900
- static String str (VirtualFrame frame , Object obj ,
901
- @ Cached StrAsObjectNode strNode ,
902
- @ Cached CastToJavaStringNode cast ) {
903
- return cast .execute (strNode .execute (frame , obj ));
904
- }
905
-
906
- public static StrAsJavaStringNode create () {
907
- return ObjectNodesFactory .StrAsJavaStringNodeGen .create ();
908
- }
909
-
910
- public static StrAsJavaStringNode getUncached () {
911
- return ObjectNodesFactory .StrAsJavaStringNodeGen .getUncached ();
912
- }
913
- }
914
-
915
- @ GenerateUncached
916
- public abstract static class AsciiNode extends PNodeWithContext {
917
- public abstract String execute (Frame frame , Object object );
918
-
919
- @ Specialization
920
- static String ascii (VirtualFrame frame , Object obj ,
921
- @ Cached ObjectNodes .ReprAsJavaStringNode reprNode ) {
922
- String repr = reprNode .execute (frame , obj );
923
- byte [] bytes = BytesUtils .unicodeNonAsciiEscape (repr );
924
- return PythonUtils .newString (bytes );
925
- }
926
-
927
- public static AsciiNode create () {
928
- return ObjectNodesFactory .AsciiNodeGen .create ();
929
- }
930
-
931
- public static AsciiNode getUncached () {
932
- return ObjectNodesFactory .AsciiNodeGen .getUncached ();
933
- }
934
- }
935
788
}
0 commit comments