|
70 | 70 | import com.oracle.graal.python.builtins.objects.PNotImplemented;
|
71 | 71 | import com.oracle.graal.python.builtins.objects.foreign.TruffleObjectBuiltinsFactory.MulNodeFactory;
|
72 | 72 | import com.oracle.graal.python.builtins.objects.function.PKeyword;
|
| 73 | +import com.oracle.graal.python.builtins.objects.iterator.PForeignArrayIterator; |
73 | 74 | import com.oracle.graal.python.builtins.objects.list.PList;
|
74 | 75 | import com.oracle.graal.python.builtins.objects.object.ObjectBuiltins;
|
75 | 76 | import com.oracle.graal.python.builtins.objects.object.ObjectBuiltinsFactory;
|
|
79 | 80 | import com.oracle.graal.python.nodes.expression.BinaryArithmetic;
|
80 | 81 | import com.oracle.graal.python.nodes.expression.BinaryComparisonNode;
|
81 | 82 | import com.oracle.graal.python.nodes.expression.CastToBooleanNode;
|
| 83 | +import com.oracle.graal.python.nodes.expression.CastToListNode; |
82 | 84 | import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
|
83 | 85 | import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
|
84 | 86 | import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
|
85 | 87 | import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
|
86 | 88 | import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
|
87 | 89 | import com.oracle.graal.python.nodes.interop.PForeignToPTypeNode;
|
88 | 90 | import com.oracle.graal.python.nodes.interop.PTypeToForeignNode;
|
| 91 | +import com.oracle.graal.python.runtime.exception.PException; |
89 | 92 | import com.oracle.graal.python.runtime.exception.PythonErrorType;
|
90 | 93 | import com.oracle.truffle.api.CompilerDirectives;
|
91 | 94 | import com.oracle.truffle.api.dsl.Cached;
|
@@ -957,16 +960,36 @@ protected Object doIt(TruffleObject object) {
|
957 | 960 | abstract static class StrNode extends UnboxNode {
|
958 | 961 | @Child private LookupAndCallUnaryNode callStrNode;
|
959 | 962 | @Child private ObjectBuiltins.StrNode objectStrNode;
|
| 963 | + @Child private Node getSizeNode; |
| 964 | + @Child private Node readNode; |
960 | 965 |
|
961 |
| - @Specialization(guards = "isForeignObject(object)") |
962 |
| - protected Object doIt(TruffleObject object) { |
963 |
| - if (isBoxed(object)) { |
964 |
| - try { |
965 |
| - return getCallStrNode().executeObject(unboxLeft(object)); |
966 |
| - } catch (UnsupportedMessageException e) { |
967 |
| - throw new IllegalStateException("The object '%s' claims to be boxed, but does not support the UNBOX message"); |
| 966 | + @Specialization(guards = {"isBoxed(object)"}) |
| 967 | + protected Object doBoxed(TruffleObject object) { |
| 968 | + try { |
| 969 | + return getCallStrNode().executeObject(unboxLeft(object)); |
| 970 | + } catch (UnsupportedMessageException e) { |
| 971 | + throw new IllegalStateException("The object '%s' claims to be boxed, but does not support the UNBOX message"); |
| 972 | + } |
| 973 | + } |
| 974 | + |
| 975 | + @Specialization(guards = {"isForeignArray(object)"}) |
| 976 | + protected Object doArray(TruffleObject object, |
| 977 | + @Cached("create()") CastToListNode asList, |
| 978 | + @Cached("GET_SIZE.createNode()") Node sizeNode) { |
| 979 | + try { |
| 980 | + Object size = ForeignAccess.sendGetSize(sizeNode, object); |
| 981 | + if (size instanceof Integer) { |
| 982 | + PForeignArrayIterator iterable = factory().createForeignArrayIterator(object, (int) size); |
| 983 | + return getCallStrNode().executeObject(asList.executeWith(iterable)); |
968 | 984 | }
|
| 985 | + } catch (PException | UnsupportedMessageException e) { |
| 986 | + // fall through |
969 | 987 | }
|
| 988 | + return doIt(object); |
| 989 | + } |
| 990 | + |
| 991 | + @Fallback |
| 992 | + protected Object doIt(Object object) { |
970 | 993 | return getObjectStrNode().execute(object);
|
971 | 994 | }
|
972 | 995 |
|
|
0 commit comments