44
44
import com .oracle .graal .python .nodes .expression .BinaryOpNode ;
45
45
import com .oracle .graal .python .nodes .frame .ReadNode ;
46
46
import com .oracle .graal .python .runtime .sequence .SequenceUtil .NormalizeIndexNode ;
47
+ import com .oracle .truffle .api .CompilerDirectives ;
47
48
import com .oracle .truffle .api .dsl .Cached ;
48
- import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
49
49
import com .oracle .truffle .api .dsl .Specialization ;
50
50
import com .oracle .truffle .api .frame .VirtualFrame ;
51
51
import com .oracle .truffle .api .nodes .NodeInfo ;
52
52
53
53
@ NodeInfo (shortName = __GETITEM__ )
54
- @ GenerateNodeFactory
55
54
public abstract class GetItemNode extends BinaryOpNode implements ReadNode {
56
55
57
- @ Child private NormalizeIndexNode normalize = NormalizeIndexNode . create () ;
56
+ @ Child private NormalizeIndexNode normalize ;
58
57
59
58
public abstract Object execute (Object primary , Object slice );
60
59
@@ -69,11 +68,19 @@ public PNode getSlice() {
69
68
public abstract Object execute (VirtualFrame frame , Object primary , Object slice );
70
69
71
70
public static GetItemNode create () {
72
- return GetItemNodeFactory .create (null , null );
71
+ return GetItemNodeGen .create (null , null );
73
72
}
74
73
75
74
public static GetItemNode create (PNode primary , PNode slice ) {
76
- return GetItemNodeFactory .create (primary , slice );
75
+ return GetItemNodeGen .create (primary , slice );
76
+ }
77
+
78
+ private NormalizeIndexNode ensureNormalize () {
79
+ if (normalize == null ) {
80
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
81
+ normalize = insert (NormalizeIndexNode .create ());
82
+ }
83
+ return normalize ;
77
84
}
78
85
79
86
private int toInt (PInt index ) {
@@ -87,7 +94,7 @@ private int toInt(PInt index) {
87
94
88
95
@ Override
89
96
public PNode makeWriteNode (PNode rhs ) {
90
- return SetItemNodeFactory .create (getPrimary (), getSlice (), rhs );
97
+ return SetItemNode .create (getPrimary (), getSlice (), rhs );
91
98
}
92
99
93
100
@ Specialization
@@ -145,7 +152,7 @@ public String doString(String primary, PInt idx) {
145
152
146
153
@ Specialization
147
154
public Object doPBytes (PBytes primary , int idx ) {
148
- return primary .getItemNormalized (normalize .forRange (idx , primary .len ()));
155
+ return primary .getItemNormalized (ensureNormalize () .forRange (idx , primary .len ()));
149
156
}
150
157
151
158
@ Specialization
@@ -155,7 +162,7 @@ public Object doPBytes(PBytes bytes, PInt idx) {
155
162
156
163
@ Specialization
157
164
public Object doPByteArray (PByteArray primary , int idx ) {
158
- return primary .getItemNormalized (normalize .forRange (idx , primary .len ()));
165
+ return primary .getItemNormalized (ensureNormalize () .forRange (idx , primary .len ()));
159
166
}
160
167
161
168
@ Specialization
@@ -165,62 +172,62 @@ public Object doPByteArray(PByteArray bytearray, PInt idx) {
165
172
166
173
@ Specialization
167
174
public Object doPRange (PRange primary , int idx ) {
168
- return primary .getItemNormalized (normalize .forRange (idx , primary .len ()));
175
+ return primary .getItemNormalized (ensureNormalize () .forRange (idx , primary .len ()));
169
176
}
170
177
171
178
@ Specialization
172
179
public Object doPRange (PRange primary , long idx ) {
173
- return primary .getItemNormalized (normalize .forRange (idx , primary .len ()));
180
+ return primary .getItemNormalized (ensureNormalize () .forRange (idx , primary .len ()));
174
181
}
175
182
176
183
@ Specialization
177
184
public int doPIntArray (PIntArray primary , int idx ) {
178
- return primary .getIntItemNormalized (normalize .forArray (idx , primary .len ()));
185
+ return primary .getIntItemNormalized (ensureNormalize () .forArray (idx , primary .len ()));
179
186
}
180
187
181
188
@ Specialization
182
189
public int doPIntArray (PIntArray primary , long idx ) {
183
- return primary .getIntItemNormalized (normalize .forArray (idx , primary .len ()));
190
+ return primary .getIntItemNormalized (ensureNormalize () .forArray (idx , primary .len ()));
184
191
}
185
192
186
193
@ Specialization
187
194
public long doPLongArray (PLongArray primary , int idx ) {
188
- return primary .getLongItemNormalized (normalize .forArray (idx , primary .len ()));
195
+ return primary .getLongItemNormalized (ensureNormalize () .forArray (idx , primary .len ()));
189
196
}
190
197
191
198
@ Specialization
192
199
public long doPLongArray (PLongArray primary , long idx ) {
193
- return primary .getLongItemNormalized (normalize .forArray (idx , primary .len ()));
200
+ return primary .getLongItemNormalized (ensureNormalize () .forArray (idx , primary .len ()));
194
201
}
195
202
196
203
@ Specialization
197
204
public double doPDoubleArray (PDoubleArray primary , int idx ) {
198
- return primary .getDoubleItemNormalized (normalize .forArray (idx , primary .len ()));
205
+ return primary .getDoubleItemNormalized (ensureNormalize () .forArray (idx , primary .len ()));
199
206
}
200
207
201
208
@ Specialization
202
209
public double doPDoubleArray (PDoubleArray primary , long idx ) {
203
- return primary .getDoubleItemNormalized (normalize .forArray (idx , primary .len ()));
210
+ return primary .getDoubleItemNormalized (ensureNormalize () .forArray (idx , primary .len ()));
204
211
}
205
212
206
213
@ Specialization
207
214
public char doPCharArray (PCharArray primary , int idx ) {
208
- return primary .getCharItemNormalized (normalize .forArray (idx , primary .len ()));
215
+ return primary .getCharItemNormalized (ensureNormalize () .forArray (idx , primary .len ()));
209
216
}
210
217
211
218
@ Specialization
212
219
public char doPCharArray (PCharArray primary , long idx ) {
213
- return primary .getCharItemNormalized (normalize .forArray (idx , primary .len ()));
220
+ return primary .getCharItemNormalized (ensureNormalize () .forArray (idx , primary .len ()));
214
221
}
215
222
216
223
@ Specialization
217
224
public Object doPArray (PArray primary , long idx ) {
218
- return primary .getItemNormalized (normalize .forArray (idx , primary .len ()));
225
+ return primary .getItemNormalized (ensureNormalize () .forArray (idx , primary .len ()));
219
226
}
220
227
221
228
@ Specialization
222
229
public Object doPArray (PArray primary , PInt idx ) {
223
- return primary .getItemNormalized (normalize .forArray (toInt (idx ), primary .len ()));
230
+ return primary .getItemNormalized (ensureNormalize () .forArray (toInt (idx ), primary .len ()));
224
231
}
225
232
226
233
@ Specialization
0 commit comments