|
47 | 47 | import com.oracle.truffle.api.dsl.NodeChild;
|
48 | 48 | import com.oracle.truffle.api.dsl.NodeChildren;
|
49 | 49 | import com.oracle.truffle.api.dsl.Specialization;
|
| 50 | +import com.oracle.truffle.api.interop.ForeignAccess; |
| 51 | +import com.oracle.truffle.api.interop.Message; |
| 52 | +import com.oracle.truffle.api.interop.TruffleObject; |
| 53 | +import com.oracle.truffle.api.interop.UnknownIdentifierException; |
| 54 | +import com.oracle.truffle.api.interop.UnsupportedMessageException; |
| 55 | +import com.oracle.truffle.api.nodes.Node; |
50 | 56 | import com.oracle.truffle.api.object.Location;
|
51 | 57 | import com.oracle.truffle.api.object.Property;
|
52 | 58 | import com.oracle.truffle.api.object.Shape;
|
@@ -107,9 +113,23 @@ protected Object readIndirect(PythonObject object, Object key) {
|
107 | 113 | }
|
108 | 114 | }
|
109 | 115 |
|
| 116 | + @Specialization(guards = "isForeignObject(object)") |
| 117 | + protected Object readForeign(TruffleObject object, Object key, |
| 118 | + @Cached("createReadNode()") Node readNode) { |
| 119 | + try { |
| 120 | + return ForeignAccess.sendRead(readNode, object, key); |
| 121 | + } catch (UnknownIdentifierException | UnsupportedMessageException e) { |
| 122 | + return PNone.NO_VALUE; |
| 123 | + } |
| 124 | + } |
| 125 | + |
110 | 126 | @SuppressWarnings("unused")
|
111 |
| - @Specialization(guards = "!isPythonObject(object)") |
| 127 | + @Specialization(guards = {"!isPythonObject(object)", "!isForeignObject(object)"}) |
112 | 128 | protected PNone readUnboxed(Object object, Object key) {
|
113 | 129 | return PNone.NO_VALUE;
|
114 | 130 | }
|
| 131 | + |
| 132 | + protected Node createReadNode() { |
| 133 | + return Message.READ.createNode(); |
| 134 | + } |
115 | 135 | }
|
0 commit comments