5555import static com .oracle .graal .python .nodes .BuiltinNames .T_SEND ;
5656import static com .oracle .graal .python .nodes .ErrorMessages .BASE_MUST_BE ;
5757import static com .oracle .graal .python .nodes .ErrorMessages .OBJ_ISNT_MAPPING ;
58- import static com .oracle .graal .python .nodes .ErrorMessages .P_OBJ_DOES_NOT_SUPPORT_ITEM_ASSIGMENT ;
5958import static com .oracle .graal .python .nodes .SpecialAttributeNames .T___DOC__ ;
6059import static com .oracle .graal .python .nodes .SpecialMethodNames .T_ITEMS ;
6160import static com .oracle .graal .python .nodes .SpecialMethodNames .T_KEYS ;
6261import static com .oracle .graal .python .nodes .SpecialMethodNames .T_VALUES ;
6362import static com .oracle .graal .python .nodes .SpecialMethodNames .T___GETITEM__ ;
6463import static com .oracle .graal .python .nodes .SpecialMethodNames .T___IADD__ ;
6564import static com .oracle .graal .python .nodes .SpecialMethodNames .T___IMUL__ ;
66- import static com .oracle .graal .python .nodes .SpecialMethodNames .T___SETITEM__ ;
6765
6866import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
6967import com .oracle .graal .python .builtins .modules .BuiltinConstructors ;
9694import com .oracle .graal .python .builtins .objects .ints .PInt ;
9795import com .oracle .graal .python .builtins .objects .iterator .IteratorNodes ;
9896import com .oracle .graal .python .builtins .objects .list .PList ;
99- import com .oracle .graal .python .builtins .objects .mappingproxy .PMappingproxy ;
10097import com .oracle .graal .python .builtins .objects .method .PBuiltinMethod ;
10198import com .oracle .graal .python .builtins .objects .type .TypeNodes .IsSameTypeNode ;
10299import com .oracle .graal .python .builtins .objects .type .TypeNodes .IsTypeNode ;
107104import com .oracle .graal .python .lib .PyNumberFloatNode ;
108105import com .oracle .graal .python .lib .PyNumberIndexNode ;
109106import com .oracle .graal .python .lib .PyObjectCallMethodObjArgs ;
110- import com .oracle .graal .python .lib .PyObjectDelItem ;
111107import com .oracle .graal .python .lib .PyObjectGetAttr ;
112108import com .oracle .graal .python .lib .PyObjectGetItem ;
113109import com .oracle .graal .python .lib .PyObjectLookupAttr ;
114- import com .oracle .graal .python .lib .PyObjectSizeNode ;
115110import com .oracle .graal .python .lib .PySequenceCheckNode ;
116111import com .oracle .graal .python .lib .PySequenceContainsNode ;
112+ import com .oracle .graal .python .lib .PySequenceDelItemNode ;
117113import com .oracle .graal .python .lib .PySequenceGetItemNode ;
118114import com .oracle .graal .python .lib .PySequenceIterSearchNode ;
115+ import com .oracle .graal .python .lib .PySequenceSetItemNode ;
116+ import com .oracle .graal .python .lib .PySequenceSizeNode ;
119117import com .oracle .graal .python .lib .PySliceNew ;
120118import com .oracle .graal .python .nodes .ErrorMessages ;
121119import com .oracle .graal .python .nodes .PRaiseNode ;
149147import com .oracle .truffle .api .dsl .TypeSystemReference ;
150148import com .oracle .truffle .api .frame .VirtualFrame ;
151149import com .oracle .truffle .api .nodes .Node ;
152- import com .oracle .truffle .api .profiles .InlinedConditionProfile ;
153150import com .oracle .truffle .api .strings .TruffleString ;
154151
155152public final class PythonCextAbstractBuiltins {
@@ -501,29 +498,15 @@ Object values(Object obj,
501498
502499 @ CApiBuiltin (ret = Int , args = {PyObject , Py_ssize_t , PyObject }, call = Ignored )
503500 public abstract static class PyTruffleSequence_SetItem extends CApiTernaryBuiltinNode {
504- @ Specialization ( guards = "checkNode.execute(inliningTarget, obj)" , limit = "1" )
505- static Object setItem (Object obj , Object key , Object value ,
501+ @ Specialization
502+ static Object setItem (Object obj , long key , Object value ,
506503 @ Bind ("this" ) Node inliningTarget ,
507- @ SuppressWarnings ("unused" ) @ Exclusive @ Cached PySequenceCheckNode checkNode ,
508- @ Cached PyObjectLookupAttr lookupAttrNode ,
509- @ Cached InlinedConditionProfile hasSetItem ,
510- @ Cached CallNode callNode ,
511- @ Cached PRaiseNode .Lazy raiseNode ) {
512- Object setItemCallable = lookupAttrNode .execute (null , inliningTarget , obj , T___SETITEM__ );
513- if (hasSetItem .profile (inliningTarget , setItemCallable == PNone .NO_VALUE )) {
514- throw raiseNode .get (inliningTarget ).raise (TypeError , P_OBJ_DOES_NOT_SUPPORT_ITEM_ASSIGMENT , obj );
515- } else {
516- callNode .execute (setItemCallable , key , value );
517- return 0 ;
504+ @ Cached PySequenceSetItemNode setItemNode ) {
505+ if ((int ) key != key ) {
506+ throw PRaiseNode .raiseUncached (inliningTarget , OverflowError , ErrorMessages .CANNOT_FIT_P_INTO_INDEXSIZED_INT , key );
518507 }
519- }
520-
521- @ Specialization (guards = "!checkNode.execute(inliningTarget, obj)" , limit = "1" )
522- static Object setItem (Object obj , @ SuppressWarnings ("unused" ) Object key , @ SuppressWarnings ("unused" ) Object value ,
523- @ SuppressWarnings ("unused" ) @ Bind ("this" ) Node inliningTarget ,
524- @ SuppressWarnings ("unused" ) @ Exclusive @ Cached PySequenceCheckNode checkNode ,
525- @ Cached PRaiseNode raiseNode ) {
526- throw raiseNode .raise (TypeError , ErrorMessages .IS_NOT_A_SEQUENCE , obj );
508+ setItemNode .execute (obj , (int ) key , value );
509+ return 0 ;
527510 }
528511 }
529512
@@ -673,21 +656,25 @@ protected BinaryArithmetic.AddNode createAdd() {
673656 @ CApiBuiltin (ret = Int , args = {PyObject , Py_ssize_t }, call = Ignored )
674657 abstract static class PyTruffleSequence_DelItem extends CApiBinaryBuiltinNode {
675658 @ Specialization
676- static Object run (Object o , Object i ,
659+ static Object run (Object o , long i ,
677660 @ Bind ("this" ) Node inliningTarget ,
678- @ Cached PyObjectDelItem delItemNode ) {
679- delItemNode .execute (null , inliningTarget , o , i );
661+ @ Cached PySequenceDelItemNode delItemNode ) {
662+ if ((int ) i != i ) {
663+ throw PRaiseNode .raiseUncached (inliningTarget , OverflowError , ErrorMessages .CANNOT_FIT_P_INTO_INDEXSIZED_INT , i );
664+ }
665+ delItemNode .execute (o , (int ) i );
680666 return 0 ;
681667 }
682668 }
683669
684670 @ CApiBuiltin (ret = PyObjectTransfer , args = {PyObject , Py_ssize_t }, call = Ignored )
685671 abstract static class PyTruffleSequence_GetItem extends CApiBinaryBuiltinNode {
686672 @ Specialization
687- Object doManaged (Object delegate , long position ,
673+ static Object doManaged (Object delegate , long position ,
674+ @ Bind ("this" ) Node inliningTarget ,
688675 @ Cached PySequenceGetItemNode getItemNode ) {
689676 if ((int ) position != position ) {
690- throw PRaiseNode .raiseUncached (this , OverflowError , ErrorMessages .CANNOT_FIT_P_INTO_INDEXSIZED_INT , position );
677+ throw PRaiseNode .raiseUncached (inliningTarget , OverflowError , ErrorMessages .CANNOT_FIT_P_INTO_INDEXSIZED_INT , position );
691678 }
692679 return getItemNode .execute (null , delegate , (int ) position );
693680 }
@@ -696,21 +683,11 @@ Object doManaged(Object delegate, long position,
696683 @ CApiBuiltin (ret = Py_ssize_t , args = {PyObject }, call = Ignored )
697684 abstract static class PyTruffleSequence_Size extends CApiUnaryBuiltinNode {
698685
699- // cant use PySequence_Size: PySequence_Size returns the __len__ value also for
700- // subclasses of types not accepted by PySequence_Check as long they have an overriden
701- // __len__ method
702686 @ Specialization
703- static Object doSequence (Object obj ,
687+ static int doSequence (Object obj ,
704688 @ Bind ("this" ) Node inliningTarget ,
705- @ Cached IsSameTypeNode isSameType ,
706- @ Cached GetClassNode getClassNode ,
707- @ Cached PyObjectSizeNode sizeNode ,
708- @ Cached PRaiseNode .Lazy raiseNode ) {
709- if (obj instanceof PMappingproxy || isSameType .execute (inliningTarget , getClassNode .execute (inliningTarget , obj ), PythonBuiltinClassType .PDict )) {
710- throw raiseNode .get (inliningTarget ).raise (TypeError , ErrorMessages .IS_NOT_A_SEQUENCE , obj );
711- } else {
712- return sizeNode .execute (null , inliningTarget , obj );
713- }
689+ @ Cached PySequenceSizeNode sizeNode ) {
690+ return sizeNode .execute (null , inliningTarget , obj );
714691 }
715692 }
716693
0 commit comments