5757import com .oracle .graal .python .builtins .objects .dict .DictBuiltins ;
5858import com .oracle .graal .python .builtins .objects .dict .PDict ;
5959import com .oracle .graal .python .builtins .objects .ints .PInt ;
60+ import com .oracle .graal .python .builtins .objects .type .SpecialMethodSlot ;
6061import com .oracle .graal .python .lib .PyNumberIndexNode ;
62+ import com .oracle .graal .python .nodes .ErrorMessages ;
6163import 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 ;
6365import com .oracle .graal .python .nodes .call .special .LookupAndCallUnaryNode ;
66+ import com .oracle .graal .python .nodes .call .special .LookupSpecialMethodSlotNode ;
6467import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
6568import com .oracle .graal .python .nodes .function .builtins .PythonBinaryBuiltinNode ;
6669import com .oracle .graal .python .nodes .function .builtins .PythonUnaryBuiltinNode ;
70+ import com .oracle .graal .python .nodes .object .GetClassNode ;
6771import com .oracle .graal .python .nodes .truffle .PythonArithmeticTypes ;
6872import com .oracle .graal .python .nodes .util .CannotCastException ;
6973import com .oracle .graal .python .nodes .util .CastToJavaStringNode ;
7377import com .oracle .truffle .api .dsl .Cached ;
7478import com .oracle .truffle .api .dsl .Fallback ;
7579import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
80+ import com .oracle .truffle .api .dsl .ImportStatic ;
7681import com .oracle .truffle .api .dsl .NodeFactory ;
7782import com .oracle .truffle .api .dsl .Specialization ;
7883import com .oracle .truffle .api .dsl .TypeSystemReference ;
@@ -152,8 +157,8 @@ public boolean doObject(VirtualFrame frame, Object value) {
152157 }
153158
154159 @ Builtin (name = "getitem" , minNumOfPositionalArgs = 2 )
155- @ TypeSystemReference (PythonArithmeticTypes .class )
156160 @ GenerateNodeFactory
161+ @ ImportStatic (SpecialMethodSlot .class )
157162 public abstract static class GetItemNode extends PythonBinaryBuiltinNode {
158163
159164 @ Specialization
@@ -162,17 +167,23 @@ public static Object doDict(VirtualFrame frame, PDict dict, Object item,
162167 return getItem .execute (frame , dict , item );
163168 }
164169
165- @ Specialization
170+ @ Specialization ( guards = "!isPString(value)" )
166171 public static Object doSequence (VirtualFrame frame , PSequence value , Object index ,
167172 @ Cached SequenceNodes .GetSequenceStorageNode getStorage ,
168173 @ Cached SequenceStorageNodes .GetItemNode getItemNode ) {
169174 return getItemNode .execute (frame , getStorage .execute (value ), index );
170175 }
171176
172177 @ 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 );
176187 }
177188 }
178189
0 commit comments