45
45
import com .oracle .graal .python .builtins .objects .list .ListBuiltins ;
46
46
import com .oracle .graal .python .builtins .objects .list .ListBuiltinsFactory ;
47
47
import com .oracle .graal .python .builtins .objects .list .PList ;
48
+ import com .oracle .graal .python .builtins .objects .object .PythonObject ;
48
49
import com .oracle .graal .python .builtins .objects .tuple .PTuple ;
49
50
import com .oracle .graal .python .builtins .objects .tuple .TupleBuiltins ;
50
51
import com .oracle .graal .python .builtins .objects .tuple .TupleBuiltinsFactory ;
51
52
import com .oracle .graal .python .builtins .objects .type .PythonClass ;
52
53
import com .oracle .graal .python .nodes .SpecialMethodNames ;
54
+ import com .oracle .graal .python .nodes .call .special .LookupAndCallBinaryNode ;
53
55
import com .oracle .graal .python .nodes .truffle .PythonTypes ;
54
56
import com .oracle .truffle .api .CompilerDirectives ;
55
57
import com .oracle .truffle .api .CompilerDirectives .CompilationFinal ;
56
58
import com .oracle .truffle .api .dsl .Cached ;
59
+ import com .oracle .truffle .api .dsl .Fallback ;
57
60
import com .oracle .truffle .api .dsl .ImportStatic ;
58
61
import com .oracle .truffle .api .dsl .Specialization ;
59
62
import com .oracle .truffle .api .dsl .TypeSystemReference ;
@@ -74,6 +77,7 @@ abstract static class ReadNode extends Node {
74
77
@ Child private ToSulongNode toSulongNode ;
75
78
76
79
public Object access (PySequenceArrayWrapper object , Object key ) {
80
+ System .out .println (object .getDelegate ().toString () + "[" + key + "]" );
77
81
return getToSulongNode ().execute (getReadArrayItemNode ().execute (object .getDelegate (), key ));
78
82
}
79
83
@@ -146,6 +150,12 @@ Object doTuple(PBytes tuple, long idx) {
146
150
return tuple .getInternalByteArray ()[(int ) idx ];
147
151
}
148
152
153
+ @ Specialization (guards = {"!isTuple(object)" , "!isList(object)" })
154
+ Object doGeneric (PythonObject object , long idx ,
155
+ @ Cached ("create(__GETITEM__)" ) LookupAndCallBinaryNode getItemNode ) {
156
+ return getItemNode .executeObject (object , idx );
157
+ }
158
+
149
159
protected static ListBuiltins .GetItemNode createListGetItem () {
150
160
return ListBuiltinsFactory .GetItemNodeFactory .create (null );
151
161
}
@@ -154,6 +164,14 @@ protected static TupleBuiltins.GetItemNode createTupleGetItem() {
154
164
return TupleBuiltinsFactory .GetItemNodeFactory .create (null );
155
165
}
156
166
167
+ protected boolean isTuple (Object object ) {
168
+ return object instanceof PTuple ;
169
+ }
170
+
171
+ protected boolean isList (Object object ) {
172
+ return object instanceof PList ;
173
+ }
174
+
157
175
public static ReadArrayItemNode create () {
158
176
return ReadArrayItemNodeGen .create ();
159
177
}
0 commit comments