62
62
import com .oracle .graal .python .builtins .objects .cext .NativeWrappers .PythonClassNativeWrapper ;
63
63
import com .oracle .graal .python .builtins .objects .cext .NativeWrappers .PythonNativeWrapper ;
64
64
import com .oracle .graal .python .builtins .objects .cext .NativeWrappers .PythonObjectNativeWrapper ;
65
+ import com .oracle .graal .python .builtins .objects .cext .PythonObjectNativeWrapperMRFactory .GetSulongTypeNodeGen ;
65
66
import com .oracle .graal .python .builtins .objects .cext .PythonObjectNativeWrapperMRFactory .PAsPointerNodeGen ;
66
67
import com .oracle .graal .python .builtins .objects .cext .PythonObjectNativeWrapperMRFactory .ReadNativeMemberNodeGen ;
67
68
import com .oracle .graal .python .builtins .objects .cext .PythonObjectNativeWrapperMRFactory .ToPyObjectNodeGen ;
84
85
import com .oracle .graal .python .builtins .objects .object .PythonObject ;
85
86
import com .oracle .graal .python .builtins .objects .slice .PSlice ;
86
87
import com .oracle .graal .python .builtins .objects .str .PString ;
88
+ import com .oracle .graal .python .builtins .objects .type .LazyPythonClass ;
87
89
import com .oracle .graal .python .builtins .objects .type .PythonBuiltinClass ;
88
90
import com .oracle .graal .python .builtins .objects .type .PythonClass ;
89
91
import com .oracle .graal .python .nodes .PGuards ;
@@ -135,11 +137,51 @@ public class PythonObjectNativeWrapperMR {
135
137
@ SuppressWarnings ("unknown-message" )
136
138
@ Resolve (message = "com.oracle.truffle.llvm.spi.GetDynamicType" )
137
139
abstract static class GetDynamicTypeNode extends Node {
138
- @ Child GetClassNode getClass = GetClassNode .create ();
139
- @ Child AsPythonObjectNode getDelegate = AsPythonObjectNode .create ();
140
+ @ Child private GetLazyClassNode getLazyClassNode = GetLazyClassNode .create ();
141
+ @ Child private GetSulongTypeNode getSulongTypeNode = GetSulongTypeNode .create ();
142
+ @ Child private AsPythonObjectNode getDelegate = AsPythonObjectNode .create ();
140
143
141
144
public Object access (PythonNativeWrapper object ) {
142
- PythonClass klass = getClass .execute (getDelegate .execute (object ));
145
+ return getSulongTypeNode .execute (getLazyClassNode .execute (getDelegate .execute (object )));
146
+ }
147
+ }
148
+
149
+ abstract static class GetSulongTypeNode extends PNodeWithContext {
150
+
151
+ private final ConditionProfile profile = ConditionProfile .createBinaryProfile ();
152
+
153
+ public abstract Object execute (LazyPythonClass clazz );
154
+
155
+ @ Specialization (guards = "clazz == cachedClass" , limit = "10" )
156
+ Object doBuiltinCached (@ SuppressWarnings ("unused" ) PythonBuiltinClassType clazz ,
157
+ @ Cached ("clazz" ) @ SuppressWarnings ("unused" ) PythonBuiltinClassType cachedClass ,
158
+ @ Cached ("getSulongTypeForBuiltinClass(clazz)" ) Object sulongType ) {
159
+ return sulongType ;
160
+ }
161
+
162
+ @ Specialization (replaces = "doBuiltinCached" )
163
+ Object doBuiltinGeneric (PythonBuiltinClassType clazz ) {
164
+ return getSulongTypeForBuiltinClass (clazz );
165
+ }
166
+
167
+ @ Specialization (assumptions = "singleContextAssumption()" , guards = "clazz == cachedClass" )
168
+ Object doGeneric (@ SuppressWarnings ("unused" ) PythonClass clazz ,
169
+ @ Cached ("clazz" ) @ SuppressWarnings ("unused" ) PythonClass cachedClass ,
170
+ @ Cached ("doGeneric(clazz)" ) Object sulongType ) {
171
+ return sulongType ;
172
+ }
173
+
174
+ @ Specialization
175
+ Object doGeneric (PythonClass clazz ) {
176
+ return getSulongTypeForClass (clazz );
177
+ }
178
+
179
+ protected Object getSulongTypeForBuiltinClass (PythonBuiltinClassType clazz ) {
180
+ PythonClass pythonClass = getPythonClass (clazz , profile );
181
+ return getSulongTypeForClass (pythonClass );
182
+ }
183
+
184
+ private static Object getSulongTypeForClass (PythonClass klass ) {
143
185
Object sulongType = klass .getSulongType ();
144
186
if (sulongType == null ) {
145
187
CompilerDirectives .transferToInterpreter ();
@@ -163,6 +205,11 @@ private static Object findBuiltinClass(PythonClass klass) {
163
205
}
164
206
return sulongType ;
165
207
}
208
+
209
+ public static GetSulongTypeNode create () {
210
+ return GetSulongTypeNodeGen .create ();
211
+ }
212
+
166
213
}
167
214
168
215
@ Resolve (message = "READ" )
0 commit comments