58
58
import com .oracle .graal .python .builtins .PythonBuiltins ;
59
59
import com .oracle .graal .python .builtins .objects .PNone ;
60
60
import com .oracle .graal .python .lib .PyObjectSizeNode ;
61
- import com .oracle .graal .python .nodes .PGuards ;
62
61
import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
63
62
import com .oracle .graal .python .nodes .function .builtins .PythonBinaryBuiltinNode ;
64
63
import com .oracle .graal .python .nodes .function .builtins .PythonTernaryBuiltinNode ;
@@ -91,24 +90,29 @@ Object reduce(PTupleGetter self,
91
90
@ Builtin (name = __GET__ , minNumOfPositionalArgs = 2 , maxNumOfPositionalArgs = 3 )
92
91
@ GenerateNodeFactory
93
92
abstract static class TupleGetterGetNode extends PythonTernaryBuiltinNode {
94
- @ Specialization
95
- Object get (VirtualFrame frame , PTupleGetter self , Object instance , @ SuppressWarnings ("unused" ) Object owner ,
93
+ @ Specialization ()
94
+ Object getTuple (VirtualFrame frame , PTupleGetter self , PTuple instance , @ SuppressWarnings ("unused" ) Object owner ,
96
95
@ Cached PyObjectSizeNode sizeNode ,
97
96
@ Cached TupleBuiltins .GetItemNode getItemNode ) {
98
97
final int index = self .getIndex ();
99
- if (!PGuards .isPTuple (instance )) {
100
- if (instance == PNone .NONE ) {
101
- return self ;
102
- }
103
- throw raise (PythonBuiltinClassType .TypeError , DESC_FOR_INDEX_S_FOR_S_DOESNT_APPLY_TO_P ,
104
- index , "tuple subclasses" , instance );
105
- }
106
98
if (index >= sizeNode .execute (frame , instance )) {
107
99
throw raise (PythonBuiltinClassType .IndexError , TUPLE_OUT_OF_BOUNDS );
108
100
}
109
101
110
102
return getItemNode .execute (frame , instance , index );
111
103
}
104
+
105
+ @ Specialization
106
+ Object getNone (@ SuppressWarnings ("unused" ) VirtualFrame frame , PTupleGetter self , @ SuppressWarnings ("unused" ) PNone instance , @ SuppressWarnings ("unused" ) Object owner ) {
107
+ return self ;
108
+ }
109
+
110
+ @ Specialization (guards = {"!isPTuple(instance)" , "!isNone(instance)" })
111
+ Object getOthers (@ SuppressWarnings ("unused" ) VirtualFrame frame , PTupleGetter self , Object instance , @ SuppressWarnings ("unused" ) Object owner ) {
112
+ final int index = self .getIndex ();
113
+ throw raise (PythonBuiltinClassType .TypeError , DESC_FOR_INDEX_S_FOR_S_DOESNT_APPLY_TO_P ,
114
+ index , "tuple subclasses" , instance );
115
+ }
112
116
}
113
117
114
118
@ Builtin (name = __SET__ , minNumOfPositionalArgs = 3 )
@@ -135,14 +139,12 @@ Object delete(PTupleGetter self, Object instance) {
135
139
@ GenerateNodeFactory
136
140
abstract static class TupleGetterDocNode extends PythonBinaryBuiltinNode {
137
141
@ Specialization (guards = "!isNoValue(value)" )
138
- @ SuppressWarnings ("unused" )
139
142
Object set (PTupleGetter self , Object value ) {
140
143
self .setDoc (value );
141
144
return PNone .NONE ;
142
145
}
143
146
144
147
@ Specialization (guards = "isNoValue(value)" )
145
- @ SuppressWarnings ("unused" )
146
148
Object get (PTupleGetter self , @ SuppressWarnings ("unused" ) PNone value ) {
147
149
return self .getDoc ();
148
150
}
0 commit comments