25
25
*/
26
26
package com .oracle .graal .python .builtins .objects .frame ;
27
27
28
+ import static com .oracle .graal .python .nodes .SpecialMethodNames .__REPR__ ;
29
+
28
30
import java .util .List ;
29
31
30
32
import com .oracle .graal .python .builtins .Builtin ;
33
35
import com .oracle .graal .python .builtins .PythonBuiltins ;
34
36
import com .oracle .graal .python .builtins .objects .PNone ;
35
37
import com .oracle .graal .python .builtins .objects .code .CodeNodes ;
38
+ import com .oracle .graal .python .builtins .objects .code .PCode ;
36
39
import com .oracle .graal .python .builtins .objects .frame .PFrame .Reference ;
37
40
import com .oracle .graal .python .builtins .objects .function .PArguments ;
38
41
import com .oracle .graal .python .builtins .objects .module .PythonModule ;
39
42
import com .oracle .graal .python .builtins .objects .object .ObjectBuiltins .DictNode ;
40
43
import com .oracle .graal .python .builtins .objects .object .ObjectBuiltinsFactory .DictNodeFactory ;
41
44
import com .oracle .graal .python .builtins .objects .object .PythonObject ;
42
45
import com .oracle .graal .python .nodes .PRootNode ;
46
+ import com .oracle .graal .python .nodes .argument .ReadArgumentNode ;
43
47
import com .oracle .graal .python .nodes .frame .MaterializeFrameNode ;
44
48
import com .oracle .graal .python .nodes .frame .ReadCallerFrameNode ;
45
49
import com .oracle .graal .python .nodes .frame .ReadLocalsNode ;
46
50
import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
47
51
import com .oracle .graal .python .nodes .function .PythonBuiltinNode ;
48
52
import com .oracle .graal .python .nodes .function .builtins .PythonUnaryBuiltinNode ;
49
53
import com .oracle .truffle .api .CompilerDirectives ;
54
+ import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
50
55
import com .oracle .truffle .api .RootCallTarget ;
51
56
import com .oracle .truffle .api .dsl .Cached ;
52
57
import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
@@ -64,6 +69,23 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
64
69
return FrameBuiltinsFactory .getFactories ();
65
70
}
66
71
72
+ @ Builtin (name = __REPR__ , minNumOfPositionalArgs = 1 )
73
+ @ GenerateNodeFactory
74
+ public abstract static class ReprNode extends PythonUnaryBuiltinNode {
75
+ @ Specialization
76
+ String repr (VirtualFrame frame , PFrame self ,
77
+ @ Cached GetCodeNode getCodeNode ) {
78
+ PCode code = getCodeNode .executeObject (frame , self );
79
+ return getFormat (self , code );
80
+ }
81
+
82
+ @ TruffleBoundary
83
+ private static String getFormat (PFrame self , PCode code ) {
84
+ return String .format ("<frame at 0x%x, file %s, line %d, code %s>" ,
85
+ self .hashCode (), code .getFilename (), self .getLine (), code .getName ());
86
+ }
87
+ }
88
+
67
89
@ Builtin (name = "f_globals" , minNumOfPositionalArgs = 1 , isGetter = true )
68
90
@ GenerateNodeFactory
69
91
public abstract static class GetGlobalsNode extends PythonBuiltinNode {
@@ -131,8 +153,10 @@ Object get(@SuppressWarnings("unused") PFrame self) {
131
153
@ Builtin (name = "f_code" , minNumOfPositionalArgs = 1 , isGetter = true )
132
154
@ GenerateNodeFactory
133
155
public abstract static class GetCodeNode extends PythonBuiltinNode {
156
+ public abstract PCode executeObject (VirtualFrame frame , PFrame self );
157
+
134
158
@ Specialization
135
- Object get (VirtualFrame frame , PFrame self ,
159
+ PCode get (VirtualFrame frame , PFrame self ,
136
160
@ Cached ("create()" ) CodeNodes .CreateCodeNode createCodeNode ) {
137
161
RootCallTarget ct = self .getTarget ();
138
162
if (ct != null ) {
@@ -144,6 +168,10 @@ Object get(VirtualFrame frame, PFrame self,
144
168
"<internal>" ,
145
169
"<internal>" , -1 , new byte [0 ]);
146
170
}
171
+
172
+ public static GetCodeNode create () {
173
+ return FrameBuiltinsFactory .GetCodeNodeFactory .create (new ReadArgumentNode [0 ]);
174
+ }
147
175
}
148
176
149
177
@ Builtin (name = "f_locals" , minNumOfPositionalArgs = 1 , isGetter = true )
0 commit comments