40
40
*/
41
41
package com .oracle .graal .python .builtins .objects .cext ;
42
42
43
+ import com .oracle .graal .python .builtins .objects .cext .DynamicObjectNativeWrapper .PAsPointerNode ;
44
+ import com .oracle .graal .python .builtins .objects .cext .DynamicObjectNativeWrapper .ReadNativeMemberDispatchNode ;
45
+ import com .oracle .graal .python .builtins .objects .cext .DynamicObjectNativeWrapper .ToNativeNode ;
46
+ import com .oracle .graal .python .runtime .interop .InteropArray ;
47
+ import com .oracle .truffle .api .dsl .Cached ;
48
+ import com .oracle .truffle .api .dsl .Specialization ;
49
+ import com .oracle .truffle .api .interop .InteropLibrary ;
43
50
import com .oracle .truffle .api .interop .TruffleObject ;
51
+ import com .oracle .truffle .api .interop .UnknownIdentifierException ;
52
+ import com .oracle .truffle .api .interop .UnsupportedMessageException ;
53
+ import com .oracle .truffle .api .library .ExportLibrary ;
54
+ import com .oracle .truffle .api .library .ExportMessage ;
55
+ import com .oracle .truffle .llvm .spi .NativeTypeLibrary ;
44
56
57
+ @ ExportLibrary (InteropLibrary .class )
58
+ @ ExportLibrary (NativeTypeLibrary .class )
45
59
public class TruffleObjectNativeWrapper extends PythonNativeWrapper {
46
60
47
61
public TruffleObjectNativeWrapper (TruffleObject foreignObject ) {
@@ -52,4 +66,76 @@ public static TruffleObjectNativeWrapper wrap(TruffleObject foreignObject) {
52
66
assert !(foreignObject instanceof PythonNativeWrapper ) : "attempting to wrap a native wrapper" ;
53
67
return new TruffleObjectNativeWrapper (foreignObject );
54
68
}
55
- }
69
+
70
+ @ ExportMessage
71
+ boolean hasMembers () {
72
+ return true ;
73
+ }
74
+
75
+ @ ExportMessage
76
+ protected boolean isMemberReadable (@ SuppressWarnings ("unused" ) String member ) {
77
+ // TODO(fa) should that be refined?
78
+ return true ;
79
+ }
80
+
81
+ @ ExportMessage
82
+ protected Object getMembers (@ SuppressWarnings ("unused" ) boolean includeInternal ) {
83
+ return new InteropArray (new String []{DynamicObjectNativeWrapper .GP_OBJECT });
84
+ }
85
+
86
+ @ ExportMessage (name = "readMember" )
87
+ abstract static class ReadNode {
88
+
89
+ @ Specialization (guards = {"key == cachedObBase" , "isObBase(cachedObBase)" }, limit = "1" )
90
+ static Object doObBaseCached (TruffleObjectNativeWrapper object , @ SuppressWarnings ("unused" ) String key ,
91
+ @ Cached ("key" ) @ SuppressWarnings ("unused" ) String cachedObBase ) {
92
+ return object ;
93
+ }
94
+
95
+ @ Specialization
96
+ static Object execute (TruffleObjectNativeWrapper object , String key ,
97
+ @ Cached ReadNativeMemberDispatchNode readNativeMemberNode ,
98
+ @ Cached CExtNodes .AsPythonObjectNode getDelegate ) throws UnsupportedMessageException , UnknownIdentifierException {
99
+ Object delegate = getDelegate .execute (object );
100
+
101
+ // special key for the debugger
102
+ if (key .equals (DynamicObjectNativeWrapper .GP_OBJECT )) {
103
+ return delegate ;
104
+ }
105
+ return readNativeMemberNode .execute (delegate , key );
106
+ }
107
+
108
+ protected static boolean isObBase (String key ) {
109
+ return NativeMemberNames .OB_BASE .equals (key );
110
+ }
111
+ }
112
+
113
+ @ ExportMessage
114
+ protected boolean isPointer (
115
+ @ Cached CExtNodes .IsPointerNode pIsPointerNode ) {
116
+ return pIsPointerNode .execute (this );
117
+ }
118
+
119
+ @ ExportMessage
120
+ protected long asPointer (
121
+ @ Cached PAsPointerNode pAsPointerNode ) {
122
+ return pAsPointerNode .execute (this );
123
+ }
124
+
125
+ @ ExportMessage
126
+ protected void toNative (
127
+ @ Cached .Exclusive @ Cached ToNativeNode toNativeNode ) {
128
+ toNativeNode .execute (this );
129
+ }
130
+
131
+ @ ExportMessage
132
+ protected boolean hasNativeType () {
133
+ return true ;
134
+ }
135
+
136
+ @ ExportMessage
137
+ protected Object getNativeType (
138
+ @ Cached PGetDynamicTypeNode getDynamicTypeNode ) {
139
+ return getDynamicTypeNode .execute (this );
140
+ }
141
+ }
0 commit comments