46
46
import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
47
47
import com .oracle .graal .python .builtins .PythonBuiltins ;
48
48
import com .oracle .graal .python .builtins .objects .PNone ;
49
- import com .oracle .graal .python .builtins .objects .PythonAbstractObject ;
50
49
import com .oracle .graal .python .builtins .objects .function .PKeyword ;
51
50
import com .oracle .graal .python .builtins .objects .module .PythonModule ;
52
51
import com .oracle .graal .python .builtins .objects .object .ObjectBuiltins ;
53
52
import com .oracle .graal .python .builtins .objects .object .PythonObjectLibrary ;
54
53
import com .oracle .graal .python .builtins .objects .type .TypeNodes ;
55
- import com .oracle .graal .python .builtins .objects .type .TypeNodes .GetNameNode ;
56
54
import com .oracle .graal .python .nodes .ErrorMessages ;
57
- import com .oracle .graal .python .nodes .SpecialAttributeNames ;
58
55
import com .oracle .graal .python .nodes .attributes .GetAttributeNode ;
59
56
import com .oracle .graal .python .nodes .builtins .FunctionNodes .GetDefaultsNode ;
60
57
import com .oracle .graal .python .nodes .builtins .FunctionNodes .GetKeywordDefaultsNode ;
61
58
import com .oracle .graal .python .nodes .call .special .LookupAndCallBinaryNode ;
59
+ import com .oracle .graal .python .nodes .call .special .LookupAndCallUnaryNode ;
62
60
import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
63
61
import com .oracle .graal .python .nodes .function .PythonBuiltinNode ;
64
62
import com .oracle .graal .python .nodes .function .builtins .PythonTernaryBuiltinNode ;
@@ -136,13 +134,25 @@ protected Object doIt(VirtualFrame frame, PMethod self, Object key,
136
134
@ Builtin (name = __REPR__ , minNumOfPositionalArgs = 1 )
137
135
@ GenerateNodeFactory
138
136
public abstract static class ReprNode extends PythonUnaryBuiltinNode {
139
- @ Specialization (limit = "3" )
140
- Object reprMethod (VirtualFrame frame , PMethod self ,
141
- @ CachedLibrary ("self.getSelf()" ) PythonObjectLibrary lib ,
142
- @ Cached ("create(__QUALNAME__)" ) GetAttributeNode getNameAttrNode ,
143
- @ Cached GetNameNode getTypeNameNode ) {
144
- String typeName = getTypeNameNode .execute (lib .getLazyPythonClass (self .getSelf ()));
145
- return strFormat ("<bound method %s of %s object at 0x%x>" , getNameAttrNode .executeObject (frame , self .getFunction ()), typeName , PythonAbstractObject .systemHashCode (self .getSelf ()));
137
+ @ Specialization
138
+ Object reprMethod (VirtualFrame frame , PMethod method ,
139
+ @ Cached ("create(__REPR__)" ) LookupAndCallUnaryNode callReprNode ,
140
+ @ Cached CastToJavaStringNode toJavaStringNode ,
141
+ @ CachedLibrary (limit = "1" ) PythonObjectLibrary pol ) {
142
+ Object self = method .getSelf ();
143
+ Object func = method .getFunction ();
144
+ String defname = "?" ;
145
+
146
+ Object funcName = pol .lookupAttribute (func , __QUALNAME__ );
147
+ if (funcName == PNone .NO_VALUE ) {
148
+ funcName = pol .lookupAttribute (func , __NAME__ );
149
+ }
150
+
151
+ try {
152
+ return strFormat ("<bound method %s of %s>" , toJavaStringNode .execute (funcName ), callReprNode .executeObject (frame , self ));
153
+ } catch (CannotCastException e ) {
154
+ return strFormat ("<bound method %s of %s>" , defname , callReprNode .executeObject (frame , self ));
155
+ }
146
156
}
147
157
148
158
@ TruffleBoundary
@@ -202,15 +212,15 @@ PMethod doGeneric(@SuppressWarnings("unused") PMethod self, Object obj, @Suppres
202
212
public abstract static class MethodName extends PythonUnaryBuiltinNode {
203
213
@ Specialization
204
214
Object getName (VirtualFrame frame , PMethod method ,
205
- @ Cached ("create(__NAME__)" ) GetAttributeNode getNameAttrNode ) {
215
+ @ Cached ("create(__NAME__)" ) GetAttributeNode getNameAttrNode ) {
206
216
return getNameAttrNode .executeObject (frame , method .getFunction ());
207
217
}
208
218
}
209
219
210
220
@ Builtin (name = __QUALNAME__ , minNumOfPositionalArgs = 1 , isGetter = true )
211
221
@ GenerateNodeFactory
212
222
public abstract static class MethodQualName extends PythonUnaryBuiltinNode {
213
- @ Specialization
223
+ @ Specialization ( limit = "3" )
214
224
Object getQualName (VirtualFrame frame , PMethod method ,
215
225
@ Cached ("create(__QUALNAME__)" ) GetAttributeNode getQualNameAttrNode ,
216
226
@ Cached ("create(__NAME__)" ) GetAttributeNode getNameAttrNode ,
@@ -223,7 +233,7 @@ Object getQualName(VirtualFrame frame, PMethod method,
223
233
return selfName ;
224
234
}
225
235
226
- Object type = isTypeNode .execute (self ) ? self : pol .getLazyPythonClass (self );
236
+ Object type = isTypeNode .execute (self ) ? self : pol .getLazyPythonClass (self );
227
237
String typeQualName ;
228
238
try {
229
239
typeQualName = castToJavaStringNode .execute (getQualNameAttrNode .executeObject (frame , type ));
0 commit comments