|
47 | 47 | import com.oracle.graal.python.builtins.PythonBuiltinClassType;
|
48 | 48 | import com.oracle.graal.python.builtins.modules.MathGuards;
|
49 | 49 | import com.oracle.graal.python.builtins.objects.PNone;
|
| 50 | +import com.oracle.graal.python.builtins.objects.floats.PFloat; |
| 51 | +import com.oracle.graal.python.builtins.objects.ints.PInt; |
50 | 52 | import com.oracle.graal.python.builtins.objects.list.PList;
|
51 | 53 | import com.oracle.graal.python.builtins.objects.slice.PSlice;
|
52 | 54 | import com.oracle.graal.python.builtins.objects.tuple.PTuple;
|
|
58 | 60 | import com.oracle.graal.python.nodes.builtins.ListNodesFactory.ConstructListNodeGen;
|
59 | 61 | import com.oracle.graal.python.nodes.builtins.ListNodesFactory.CreateListFromIteratorNodeGen;
|
60 | 62 | import com.oracle.graal.python.nodes.builtins.ListNodesFactory.FastConstructListNodeGen;
|
| 63 | +import com.oracle.graal.python.nodes.builtins.ListNodesFactory.IndexNodeGen; |
61 | 64 | import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
|
62 | 65 | import com.oracle.graal.python.nodes.control.GetIteratorNode;
|
63 | 66 | import com.oracle.graal.python.nodes.control.GetNextNode;
|
64 | 67 | import com.oracle.graal.python.nodes.object.GetClassNode;
|
| 68 | +import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes; |
65 | 69 | import com.oracle.graal.python.runtime.exception.PException;
|
66 | 70 | import com.oracle.graal.python.runtime.exception.PythonErrorType;
|
67 | 71 | import com.oracle.graal.python.runtime.sequence.PSequence;
|
|
72 | 76 | import com.oracle.truffle.api.dsl.Fallback;
|
73 | 77 | import com.oracle.truffle.api.dsl.ImportStatic;
|
74 | 78 | import com.oracle.truffle.api.dsl.Specialization;
|
| 79 | +import com.oracle.truffle.api.dsl.TypeSystemReference; |
75 | 80 | import com.oracle.truffle.api.profiles.ConditionProfile;
|
76 | 81 |
|
77 | 82 | public abstract class ListNodes {
|
@@ -179,41 +184,78 @@ public static FastConstructListNode create() {
|
179 | 184 | }
|
180 | 185 | }
|
181 | 186 |
|
182 |
| - public static class IndexNode extends PBaseNode { |
| 187 | + @TypeSystemReference(PythonArithmeticTypes.class) |
| 188 | + public abstract static class IndexNode extends PBaseNode { |
183 | 189 | private static final String DEFAULT_ERROR_MSG = "list indices must be integers or slices, not %p";
|
184 | 190 | @Child LookupAndCallUnaryNode getIndexNode;
|
185 | 191 | private final CheckType checkType;
|
186 | 192 | private final String errorMessage;
|
187 | 193 |
|
188 |
| - private static enum CheckType { |
| 194 | + protected static enum CheckType { |
189 | 195 | SUBSCRIPT,
|
190 | 196 | INTEGER,
|
191 | 197 | NUMBER;
|
192 | 198 | }
|
193 | 199 |
|
194 |
| - private IndexNode(String message, CheckType type) { |
| 200 | + protected IndexNode(String message, CheckType type) { |
195 | 201 | checkType = type;
|
196 | 202 | getIndexNode = LookupAndCallUnaryNode.create(__INDEX__);
|
197 | 203 | errorMessage = message;
|
198 | 204 | }
|
199 | 205 |
|
200 | 206 | public static IndexNode create(String message) {
|
201 |
| - return new IndexNode(message, CheckType.SUBSCRIPT); |
| 207 | + return IndexNodeGen.create(message, CheckType.SUBSCRIPT); |
202 | 208 | }
|
203 | 209 |
|
204 | 210 | public static IndexNode create() {
|
205 |
| - return new IndexNode(DEFAULT_ERROR_MSG, CheckType.SUBSCRIPT); |
| 211 | + return IndexNodeGen.create(DEFAULT_ERROR_MSG, CheckType.SUBSCRIPT); |
206 | 212 | }
|
207 | 213 |
|
208 | 214 | public static IndexNode createInteger(String msg) {
|
209 |
| - return new IndexNode(msg, CheckType.INTEGER); |
| 215 | + return IndexNodeGen.create(msg, CheckType.INTEGER); |
210 | 216 | }
|
211 | 217 |
|
212 | 218 | public static IndexNode createNumber(String msg) {
|
213 |
| - return new IndexNode(msg, CheckType.NUMBER); |
| 219 | + return IndexNodeGen.create(msg, CheckType.NUMBER); |
214 | 220 | }
|
215 | 221 |
|
216 |
| - public Object execute(Object object) { |
| 222 | + public abstract Object execute(Object object); |
| 223 | + |
| 224 | + protected boolean isSubscript() { |
| 225 | + return checkType == CheckType.SUBSCRIPT; |
| 226 | + } |
| 227 | + |
| 228 | + protected boolean isNumber() { |
| 229 | + return checkType == CheckType.NUMBER; |
| 230 | + } |
| 231 | + |
| 232 | + @Specialization |
| 233 | + long doLong(long slice) { |
| 234 | + return slice; |
| 235 | + } |
| 236 | + |
| 237 | + @Specialization |
| 238 | + PInt doPInt(PInt slice) { |
| 239 | + return slice; |
| 240 | + } |
| 241 | + |
| 242 | + @Specialization(guards = "isSubscript()") |
| 243 | + PSlice doSlice(PSlice slice) { |
| 244 | + return slice; |
| 245 | + } |
| 246 | + |
| 247 | + @Specialization(guards = "isNumber()") |
| 248 | + float doFloat(float slice) { |
| 249 | + return slice; |
| 250 | + } |
| 251 | + |
| 252 | + @Specialization(guards = "isNumber()") |
| 253 | + double doDouble(double slice) { |
| 254 | + return slice; |
| 255 | + } |
| 256 | + |
| 257 | + @Fallback |
| 258 | + Object doGeneric(Object object) { |
217 | 259 | Object idx = getIndexNode.executeObject(object);
|
218 | 260 | boolean valid = false;
|
219 | 261 | switch (checkType) {
|
|
0 commit comments