57
57
import com .oracle .graal .python .builtins .objects .dict .DictBuiltins ;
58
58
import com .oracle .graal .python .builtins .objects .dict .PDict ;
59
59
import com .oracle .graal .python .builtins .objects .ints .PInt ;
60
+ import com .oracle .graal .python .builtins .objects .type .SpecialMethodSlot ;
60
61
import com .oracle .graal .python .lib .PyNumberIndexNode ;
62
+ import com .oracle .graal .python .nodes .ErrorMessages ;
61
63
import com .oracle .graal .python .nodes .SpecialMethodNames ;
62
- import com .oracle .graal .python .nodes .call .special .LookupAndCallBinaryNode ;
64
+ import com .oracle .graal .python .nodes .call .special .CallBinaryMethodNode ;
63
65
import com .oracle .graal .python .nodes .call .special .LookupAndCallUnaryNode ;
66
+ import com .oracle .graal .python .nodes .call .special .LookupSpecialMethodSlotNode ;
64
67
import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
65
68
import com .oracle .graal .python .nodes .function .builtins .PythonBinaryBuiltinNode ;
66
69
import com .oracle .graal .python .nodes .function .builtins .PythonUnaryBuiltinNode ;
70
+ import com .oracle .graal .python .nodes .object .GetClassNode ;
67
71
import com .oracle .graal .python .nodes .truffle .PythonArithmeticTypes ;
68
72
import com .oracle .graal .python .nodes .util .CannotCastException ;
69
73
import com .oracle .graal .python .nodes .util .CastToJavaStringNode ;
73
77
import com .oracle .truffle .api .dsl .Cached ;
74
78
import com .oracle .truffle .api .dsl .Fallback ;
75
79
import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
80
+ import com .oracle .truffle .api .dsl .ImportStatic ;
76
81
import com .oracle .truffle .api .dsl .NodeFactory ;
77
82
import com .oracle .truffle .api .dsl .Specialization ;
78
83
import com .oracle .truffle .api .dsl .TypeSystemReference ;
@@ -152,8 +157,8 @@ public boolean doObject(VirtualFrame frame, Object value) {
152
157
}
153
158
154
159
@ Builtin (name = "getitem" , minNumOfPositionalArgs = 2 )
155
- @ TypeSystemReference (PythonArithmeticTypes .class )
156
160
@ GenerateNodeFactory
161
+ @ ImportStatic (SpecialMethodSlot .class )
157
162
public abstract static class GetItemNode extends PythonBinaryBuiltinNode {
158
163
159
164
@ Specialization
@@ -162,17 +167,23 @@ public static Object doDict(VirtualFrame frame, PDict dict, Object item,
162
167
return getItem .execute (frame , dict , item );
163
168
}
164
169
165
- @ Specialization
170
+ @ Specialization ( guards = "!isPString(value)" )
166
171
public static Object doSequence (VirtualFrame frame , PSequence value , Object index ,
167
172
@ Cached SequenceNodes .GetSequenceStorageNode getStorage ,
168
173
@ Cached SequenceStorageNodes .GetItemNode getItemNode ) {
169
174
return getItemNode .execute (frame , getStorage .execute (value ), index );
170
175
}
171
176
172
177
@ Specialization
173
- public static Object doObject (VirtualFrame frame , Object value , Object index ,
174
- @ Cached ("create(__GETITEM__)" ) LookupAndCallBinaryNode getItemNode ) {
175
- return getItemNode .executeObject (frame , value , index );
178
+ public Object doObject (VirtualFrame frame , Object value , Object index ,
179
+ @ Cached GetClassNode getClassNode ,
180
+ @ Cached (parameters = "GetItem" ) LookupSpecialMethodSlotNode lookupGetItem ,
181
+ @ Cached CallBinaryMethodNode callGetItem ) {
182
+ Object method = lookupGetItem .execute (frame , getClassNode .execute (value ), value );
183
+ if (method == PNone .NO_VALUE ) {
184
+ throw raise (TypeError , ErrorMessages .OBJ_NOT_SUBSCRIPTABLE , value );
185
+ }
186
+ return callGetItem .executeObject (frame , method , value , index );
176
187
}
177
188
}
178
189
0 commit comments