27
27
package com .oracle .graal .python .builtins .objects .foreign ;
28
28
29
29
import static com .oracle .graal .python .builtins .PythonBuiltinClassType .AttributeError ;
30
- import static com .oracle .graal .python .builtins .PythonBuiltinClassType .OverflowError ;
31
30
import static com .oracle .graal .python .builtins .PythonBuiltinClassType .TypeError ;
32
31
import static com .oracle .graal .python .builtins .objects .str .StringUtils .simpleTruffleStringFormatUncached ;
33
32
import static com .oracle .graal .python .nodes .SpecialAttributeNames .J___BASES__ ;
34
33
import static com .oracle .graal .python .nodes .SpecialAttributeNames .T___BASES__ ;
35
34
import static com .oracle .graal .python .nodes .SpecialMethodNames .J___AND__ ;
36
35
import static com .oracle .graal .python .nodes .SpecialMethodNames .J___CALL__ ;
37
- import static com .oracle .graal .python .nodes .SpecialMethodNames .J___CONTAINS__ ;
38
- import static com .oracle .graal .python .nodes .SpecialMethodNames .J___DELITEM__ ;
39
36
import static com .oracle .graal .python .nodes .SpecialMethodNames .J___DIR__ ;
40
37
import static com .oracle .graal .python .nodes .SpecialMethodNames .J___DIVMOD__ ;
41
38
import static com .oracle .graal .python .nodes .SpecialMethodNames .J___EQ__ ;
63
60
import static com .oracle .graal .python .nodes .SpecialMethodNames .J___TRUEDIV__ ;
64
61
import static com .oracle .graal .python .nodes .SpecialMethodNames .J___XOR__ ;
65
62
import static com .oracle .graal .python .nodes .SpecialMethodNames .T___INSTANCECHECK__ ;
66
- import static com .oracle .graal .python .nodes .SpecialMethodNames .T___LEN__ ;
67
63
import static com .oracle .graal .python .nodes .StringLiterals .T_NONE ;
68
64
import static com .oracle .graal .python .util .PythonUtils .TS_ENCODING ;
69
65
84
80
import com .oracle .graal .python .builtins .objects .ints .PInt ;
85
81
import com .oracle .graal .python .builtins .objects .object .ObjectBuiltins ;
86
82
import com .oracle .graal .python .builtins .objects .object .ObjectNodes ;
87
- import com .oracle .graal .python .builtins .objects .str .StringBuiltins ;
88
83
import com .oracle .graal .python .builtins .objects .type .TpSlots ;
89
84
import com .oracle .graal .python .builtins .objects .type .slots .TpSlotBinaryFunc .MpSubscriptBuiltinNode ;
90
85
import com .oracle .graal .python .builtins .objects .type .slots .TpSlotBinaryOp .BinaryOpBuiltinNode ;
91
86
import com .oracle .graal .python .builtins .objects .type .slots .TpSlotGetAttr .GetAttrBuiltinNode ;
92
87
import com .oracle .graal .python .builtins .objects .type .slots .TpSlotInquiry .NbBoolBuiltinNode ;
93
- import com .oracle .graal .python .builtins .objects .type .slots .TpSlotLen .LenBuiltinNode ;
94
88
import com .oracle .graal .python .builtins .objects .type .slots .TpSlotSetAttr .SetAttrBuiltinNode ;
95
89
import com .oracle .graal .python .builtins .objects .type .slots .TpSlotSizeArgFun .SqItemBuiltinNode ;
96
90
import com .oracle .graal .python .lib .PyNumberAddNode ;
97
- import com .oracle .graal .python .lib .PyNumberAsSizeNode ;
98
91
import com .oracle .graal .python .lib .PyNumberMultiplyNode ;
99
- import com .oracle .graal .python .lib .PyObjectRichCompareBool ;
100
92
import com .oracle .graal .python .lib .PyObjectStrAsTruffleStringNode ;
101
93
import com .oracle .graal .python .nodes .ErrorMessages ;
102
94
import com .oracle .graal .python .nodes .PGuards ;
145
137
import com .oracle .truffle .api .frame .VirtualFrame ;
146
138
import com .oracle .truffle .api .interop .ArityException ;
147
139
import com .oracle .truffle .api .interop .InteropLibrary ;
148
- import com .oracle .truffle .api .interop .StopIterationException ;
149
140
import com .oracle .truffle .api .interop .UnknownIdentifierException ;
150
141
import com .oracle .truffle .api .interop .UnsupportedMessageException ;
151
142
import com .oracle .truffle .api .interop .UnsupportedTypeException ;
@@ -205,40 +196,6 @@ static boolean bool(Object receiver,
205
196
}
206
197
}
207
198
208
- @ Slot (SlotKind .sq_length )
209
- @ Slot (SlotKind .mp_length )
210
- @ GenerateUncached
211
- @ GenerateNodeFactory
212
- abstract static class LenNode extends LenBuiltinNode {
213
- @ Specialization
214
- static int len (Object self ,
215
- @ Bind ("this" ) Node inliningTarget ,
216
- @ CachedLibrary (limit = "3" ) InteropLibrary lib ,
217
- @ Cached GilNode gil ,
218
- @ Cached PRaiseNode .Lazy raiseNode ) {
219
- gil .release (true );
220
- long result = 0 ;
221
- boolean hasResult = false ;
222
- try {
223
- if (lib .isIterator (self ) || lib .hasIterator (self )) {
224
- return 0 ; // a value signifying it has a length, but it's unknown
225
- } else if (lib .hasHashEntries (self )) {
226
- result = lib .getHashSize (self );
227
- hasResult = true ;
228
- }
229
- } catch (UnsupportedMessageException e ) {
230
- // fall through
231
- } finally {
232
- gil .acquire ();
233
- }
234
- if (hasResult ) {
235
- return PyNumberAsSizeNode .doLongExact (inliningTarget , result , OverflowError , raiseNode );
236
- } else {
237
- throw raiseNode .get (inliningTarget ).raise (AttributeError , ErrorMessages .FOREIGN_OBJ_HAS_NO_ATTR_S , T___LEN__ );
238
- }
239
- }
240
- }
241
-
242
199
// TODO: remove once all dunder methods are converted to slots and to
243
200
// NormalizeForeignForBinopNode
244
201
abstract static class ForeignBinaryNode extends BinaryOpBuiltinNode {
@@ -748,52 +705,6 @@ private static int hashCodeBoundary(Object self) {
748
705
}
749
706
}
750
707
751
- @ Builtin (name = J___CONTAINS__ , minNumOfPositionalArgs = 2 )
752
- @ GenerateNodeFactory
753
- abstract static class ContainsNode extends PythonBinaryBuiltinNode {
754
- @ Specialization
755
- static Object contains (VirtualFrame frame , Object self , Object arg ,
756
- // accesses both self and iterator
757
- @ CachedLibrary (limit = "3" ) InteropLibrary library ,
758
- @ Bind ("this" ) Node inliningTarget ,
759
- @ Cached PyObjectRichCompareBool .EqNode eqNode ,
760
- @ Cached TruffleString .SwitchEncodingNode switchEncodingNode ,
761
- @ Cached StringBuiltins .ContainsNode containsNode ,
762
- @ Cached PForeignToPTypeNode convertNode ,
763
- @ Cached PRaiseNode .Lazy raiseNode ) {
764
- try {
765
- if (library .isString (self )) {
766
- TruffleString selfStr = switchEncodingNode .execute (library .asTruffleString (self ), TS_ENCODING );
767
- return containsNode .execute (frame , selfStr , arg );
768
- }
769
- Object iterator = null ;
770
- if (library .isIterator (self )) {
771
- iterator = self ;
772
- } else if (library .hasHashEntries (self )) {
773
- iterator = library .getHashKeysIterator (self );
774
- } else if (library .hasIterator (self )) {
775
- iterator = library .getIterator (self );
776
- }
777
- if (iterator != null ) {
778
- try {
779
- while (library .hasIteratorNextElement (iterator )) {
780
- Object next = convertNode .executeConvert (library .getIteratorNextElement (iterator ));
781
- if (eqNode .compare (frame , inliningTarget , arg , next )) {
782
- return true ;
783
- }
784
- }
785
- } catch (StopIterationException e ) {
786
- // fallthrough
787
- }
788
- return false ;
789
- }
790
- throw raiseNode .get (inliningTarget ).raise (TypeError , ErrorMessages .FOREIGN_OBJ_ISNT_ITERABLE );
791
- } catch (UnsupportedMessageException e ) {
792
- throw CompilerDirectives .shouldNotReachHere (e );
793
- }
794
- }
795
- }
796
-
797
708
@ Builtin (name = J___ITER__ , minNumOfPositionalArgs = 1 )
798
709
@ GenerateNodeFactory
799
710
public abstract static class IterNode extends PythonUnaryBuiltinNode {
@@ -808,15 +719,10 @@ static Object doGeneric(Object object,
808
719
@ Cached GilNode gil ) {
809
720
gil .release (true );
810
721
try {
811
- if (lib .isIterator (object )) {
812
- return convertNode .executeConvert (object );
813
- } else if (lib .hasIterator (object )) {
722
+ if (lib .hasIterator (object )) {
814
723
return convertNode .executeConvert (lib .getIterator (object ));
815
724
} else if (lib .isString (object )) {
816
725
return factory .createStringIterator (switchEncodingNode .execute (lib .asTruffleString (object ), TS_ENCODING ));
817
- } else if (lib .hasHashEntries (object )) {
818
- // just like dict.__iter__, we take the keys by default
819
- return convertNode .executeConvert (lib .getHashKeysIterator (object ));
820
726
}
821
727
} catch (UnsupportedMessageException e ) {
822
728
throw CompilerDirectives .shouldNotReachHere (e );
@@ -1063,18 +969,6 @@ static void doDelete(Object object, Object key, @SuppressWarnings("unused") PNon
1063
969
}
1064
970
}
1065
971
1066
- @ Builtin (name = J___DELITEM__ , minNumOfPositionalArgs = 2 )
1067
- @ GenerateNodeFactory
1068
- abstract static class DelitemNode extends PythonBinaryBuiltinNode {
1069
- @ Child private AccessForeignItemNodes .RemoveForeignItemNode delForeignItemNode = AccessForeignItemNodes .RemoveForeignItemNode .create ();
1070
-
1071
- @ Specialization
1072
- PNone doit (VirtualFrame frame , Object object , Object key ) {
1073
- delForeignItemNode .execute (frame , object , key );
1074
- return PNone .NONE ;
1075
- }
1076
- }
1077
-
1078
972
@ Builtin (name = J___DIR__ , minNumOfPositionalArgs = 1 )
1079
973
@ GenerateNodeFactory
1080
974
abstract static class DirNode extends PythonUnaryBuiltinNode {
0 commit comments