55
55
import static com .oracle .graal .python .nodes .BuiltinNames .T_SEND ;
56
56
import static com .oracle .graal .python .nodes .ErrorMessages .BASE_MUST_BE ;
57
57
import 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 ;
59
58
import static com .oracle .graal .python .nodes .SpecialAttributeNames .T___DOC__ ;
60
59
import static com .oracle .graal .python .nodes .SpecialMethodNames .T_ITEMS ;
61
60
import static com .oracle .graal .python .nodes .SpecialMethodNames .T_KEYS ;
62
61
import static com .oracle .graal .python .nodes .SpecialMethodNames .T_VALUES ;
63
62
import static com .oracle .graal .python .nodes .SpecialMethodNames .T___GETITEM__ ;
64
63
import static com .oracle .graal .python .nodes .SpecialMethodNames .T___IADD__ ;
65
64
import static com .oracle .graal .python .nodes .SpecialMethodNames .T___IMUL__ ;
66
- import static com .oracle .graal .python .nodes .SpecialMethodNames .T___SETITEM__ ;
67
65
68
66
import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
69
67
import com .oracle .graal .python .builtins .modules .BuiltinConstructors ;
96
94
import com .oracle .graal .python .builtins .objects .ints .PInt ;
97
95
import com .oracle .graal .python .builtins .objects .iterator .IteratorNodes ;
98
96
import com .oracle .graal .python .builtins .objects .list .PList ;
99
- import com .oracle .graal .python .builtins .objects .mappingproxy .PMappingproxy ;
100
97
import com .oracle .graal .python .builtins .objects .method .PBuiltinMethod ;
101
98
import com .oracle .graal .python .builtins .objects .type .TypeNodes .IsSameTypeNode ;
102
99
import com .oracle .graal .python .builtins .objects .type .TypeNodes .IsTypeNode ;
107
104
import com .oracle .graal .python .lib .PyNumberFloatNode ;
108
105
import com .oracle .graal .python .lib .PyNumberIndexNode ;
109
106
import com .oracle .graal .python .lib .PyObjectCallMethodObjArgs ;
110
- import com .oracle .graal .python .lib .PyObjectDelItem ;
111
107
import com .oracle .graal .python .lib .PyObjectGetAttr ;
112
108
import com .oracle .graal .python .lib .PyObjectGetItem ;
113
109
import com .oracle .graal .python .lib .PyObjectLookupAttr ;
114
- import com .oracle .graal .python .lib .PyObjectSizeNode ;
115
110
import com .oracle .graal .python .lib .PySequenceCheckNode ;
116
111
import com .oracle .graal .python .lib .PySequenceContainsNode ;
112
+ import com .oracle .graal .python .lib .PySequenceDelItemNode ;
117
113
import com .oracle .graal .python .lib .PySequenceGetItemNode ;
118
114
import com .oracle .graal .python .lib .PySequenceIterSearchNode ;
115
+ import com .oracle .graal .python .lib .PySequenceSetItemNode ;
116
+ import com .oracle .graal .python .lib .PySequenceSizeNode ;
119
117
import com .oracle .graal .python .lib .PySliceNew ;
120
118
import com .oracle .graal .python .nodes .ErrorMessages ;
121
119
import com .oracle .graal .python .nodes .PRaiseNode ;
149
147
import com .oracle .truffle .api .dsl .TypeSystemReference ;
150
148
import com .oracle .truffle .api .frame .VirtualFrame ;
151
149
import com .oracle .truffle .api .nodes .Node ;
152
- import com .oracle .truffle .api .profiles .InlinedConditionProfile ;
153
150
import com .oracle .truffle .api .strings .TruffleString ;
154
151
155
152
public final class PythonCextAbstractBuiltins {
@@ -501,29 +498,15 @@ Object values(Object obj,
501
498
502
499
@ CApiBuiltin (ret = Int , args = {PyObject , Py_ssize_t , PyObject }, call = Ignored )
503
500
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 ,
506
503
@ 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 );
518
507
}
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 ;
527
510
}
528
511
}
529
512
@@ -673,21 +656,25 @@ protected BinaryArithmetic.AddNode createAdd() {
673
656
@ CApiBuiltin (ret = Int , args = {PyObject , Py_ssize_t }, call = Ignored )
674
657
abstract static class PyTruffleSequence_DelItem extends CApiBinaryBuiltinNode {
675
658
@ Specialization
676
- static Object run (Object o , Object i ,
659
+ static Object run (Object o , long i ,
677
660
@ 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 );
680
666
return 0 ;
681
667
}
682
668
}
683
669
684
670
@ CApiBuiltin (ret = PyObjectTransfer , args = {PyObject , Py_ssize_t }, call = Ignored )
685
671
abstract static class PyTruffleSequence_GetItem extends CApiBinaryBuiltinNode {
686
672
@ Specialization
687
- Object doManaged (Object delegate , long position ,
673
+ static Object doManaged (Object delegate , long position ,
674
+ @ Bind ("this" ) Node inliningTarget ,
688
675
@ Cached PySequenceGetItemNode getItemNode ) {
689
676
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 );
691
678
}
692
679
return getItemNode .execute (null , delegate , (int ) position );
693
680
}
@@ -696,21 +683,11 @@ Object doManaged(Object delegate, long position,
696
683
@ CApiBuiltin (ret = Py_ssize_t , args = {PyObject }, call = Ignored )
697
684
abstract static class PyTruffleSequence_Size extends CApiUnaryBuiltinNode {
698
685
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
702
686
@ Specialization
703
- static Object doSequence (Object obj ,
687
+ static int doSequence (Object obj ,
704
688
@ 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 );
714
691
}
715
692
}
716
693
0 commit comments