|
44 | 44 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__MUL__;
|
45 | 45 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__NEW__;
|
46 | 46 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__RADD__;
|
| 47 | +import static com.oracle.graal.python.nodes.SpecialMethodNames.__REPR__; |
47 | 48 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__RFLOORDIV__;
|
48 | 49 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__RMUL__;
|
49 | 50 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__RSUB__;
|
50 | 51 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__RTRUEDIV__;
|
51 | 52 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__SETATTR__;
|
52 | 53 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__SETITEM__;
|
| 54 | +import static com.oracle.graal.python.nodes.SpecialMethodNames.__STR__; |
53 | 55 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__SUB__;
|
54 | 56 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__TRUEDIV__;
|
55 | 57 | import static com.oracle.graal.python.runtime.exception.PythonErrorType.AttributeError;
|
|
67 | 69 | import com.oracle.graal.python.builtins.objects.list.PList;
|
68 | 70 | import com.oracle.graal.python.nodes.PGuards;
|
69 | 71 | import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode;
|
| 72 | +import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode; |
70 | 73 | import com.oracle.graal.python.nodes.expression.BinaryArithmetic;
|
71 | 74 | import com.oracle.graal.python.nodes.expression.BinaryComparisonNode;
|
72 | 75 | import com.oracle.graal.python.nodes.expression.CastToBooleanNode;
|
@@ -912,17 +915,67 @@ protected Object doIt(TruffleObject object,
|
912 | 915 | @GenerateNodeFactory
|
913 | 916 | abstract static class IndexNode extends UnboxNode {
|
914 | 917 | @Specialization(guards = "isForeignObject(object)")
|
915 |
| - protected Object doIt(TruffleObject object, |
916 |
| - @Cached("IS_BOXED.createNode()") Node isBoxedNode, |
917 |
| - @Cached("UNBOX.createNode()") Node unboxNode) { |
918 |
| - if (ForeignAccess.sendIsBoxed(isBoxedNode, object)) { |
| 918 | + protected Object doIt(TruffleObject object) { |
| 919 | + if (isBoxed(object)) { |
919 | 920 | try {
|
920 |
| - return ForeignAccess.sendUnbox(unboxNode, object); |
| 921 | + return unboxLeft(object); |
921 | 922 | } catch (UnsupportedMessageException e) {
|
922 | 923 | throw new IllegalStateException("The object '%s' claims to be boxed, but does not support the UNBOX message");
|
923 | 924 | }
|
924 | 925 | }
|
925 | 926 | throw raiseIndexError();
|
926 | 927 | }
|
927 | 928 | }
|
| 929 | + |
| 930 | + @Builtin(name = __STR__, fixedNumOfArguments = 1) |
| 931 | + @GenerateNodeFactory |
| 932 | + abstract static class StrNode extends UnboxNode { |
| 933 | + @Child private LookupAndCallUnaryNode callStrNode; |
| 934 | + |
| 935 | + @Specialization(guards = "isForeignObject(object)") |
| 936 | + protected Object doIt(TruffleObject object) { |
| 937 | + if (isBoxed(object)) { |
| 938 | + try { |
| 939 | + return getCallStrNode().executeObject(unboxLeft(object)); |
| 940 | + } catch (UnsupportedMessageException e) { |
| 941 | + throw new IllegalStateException("The object '%s' claims to be boxed, but does not support the UNBOX message"); |
| 942 | + } |
| 943 | + } |
| 944 | + throw raise(PythonErrorType.AttributeError); |
| 945 | + } |
| 946 | + |
| 947 | + private LookupAndCallUnaryNode getCallStrNode() { |
| 948 | + if (callStrNode == null) { |
| 949 | + CompilerDirectives.transferToInterpreterAndInvalidate(); |
| 950 | + callStrNode = insert(LookupAndCallUnaryNode.create(__STR__)); |
| 951 | + } |
| 952 | + return callStrNode; |
| 953 | + } |
| 954 | + } |
| 955 | + |
| 956 | + @Builtin(name = __REPR__, fixedNumOfArguments = 1) |
| 957 | + @GenerateNodeFactory |
| 958 | + abstract static class ReprNode extends UnboxNode { |
| 959 | + @Child private LookupAndCallUnaryNode callReprNode; |
| 960 | + |
| 961 | + @Specialization(guards = "isForeignObject(object)") |
| 962 | + protected Object doIt(TruffleObject object) { |
| 963 | + if (isBoxed(object)) { |
| 964 | + try { |
| 965 | + return getCallReprNode().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"); |
| 968 | + } |
| 969 | + } |
| 970 | + throw raise(PythonErrorType.AttributeError); |
| 971 | + } |
| 972 | + |
| 973 | + private LookupAndCallUnaryNode getCallReprNode() { |
| 974 | + if (callReprNode == null) { |
| 975 | + CompilerDirectives.transferToInterpreterAndInvalidate(); |
| 976 | + callReprNode = insert(LookupAndCallUnaryNode.create(__REPR__)); |
| 977 | + } |
| 978 | + return callReprNode; |
| 979 | + } |
| 980 | + } |
928 | 981 | }
|
0 commit comments