@@ -74,15 +74,17 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
74
74
public abstract static class ReprNode extends PythonUnaryBuiltinNode {
75
75
@ Specialization
76
76
String repr (VirtualFrame frame , PFrame self ,
77
- @ Cached GetCodeNode getCodeNode ) {
77
+ @ Cached GetCodeNode getCodeNode ,
78
+ @ Cached GetLinenoNode getLinenoNode ) {
78
79
PCode code = getCodeNode .executeObject (frame , self );
79
- return getFormat (self , code );
80
+ int lineno = getLinenoNode .executeInt (frame , self );
81
+ return getFormat (self , code , lineno );
80
82
}
81
83
82
84
@ TruffleBoundary
83
- private static String getFormat (PFrame self , PCode code ) {
85
+ private static String getFormat (PFrame self , PCode code , int lineno ) {
84
86
return String .format ("<frame at 0x%x, file %s, line %d, code %s>" ,
85
- self .hashCode (), code .getFilename (), self . getLine () , code .getName ());
87
+ self .hashCode (), code .getFilename (), lineno , code .getName ());
86
88
}
87
89
}
88
90
@@ -124,10 +126,26 @@ Object get(VirtualFrame frame, @SuppressWarnings("unused") PFrame self) {
124
126
@ Builtin (name = "f_lineno" , minNumOfPositionalArgs = 1 , isGetter = true )
125
127
@ GenerateNodeFactory
126
128
public abstract static class GetLinenoNode extends PythonBuiltinNode {
129
+ public abstract int executeInt (VirtualFrame frame , PFrame self );
130
+
127
131
@ Specialization
128
- int get (PFrame self ) {
132
+ int get (VirtualFrame frame , PFrame self ,
133
+ @ Cached ConditionProfile isCurrentFrameProfile ,
134
+ @ Cached MaterializeFrameNode materializeNode ) {
135
+ // Special case because this builtin can be called without going through an invoke node:
136
+ // we need to sync the location of the frame if and only if 'self' represents the
137
+ // current frame. If 'self' represents another frame on the stack, the location is
138
+ // already set
139
+ if (isCurrentFrameProfile .profile (PArguments .getCurrentFrameInfo (frame ) == self .getRef ())) {
140
+ PFrame pyFrame = materializeNode .execute (frame , this , false , false );
141
+ assert pyFrame == self ;
142
+ }
129
143
return self .getLine ();
130
144
}
145
+
146
+ public static GetLinenoNode create () {
147
+ return FrameBuiltinsFactory .GetLinenoNodeFactory .create (new ReadArgumentNode [0 ]);
148
+ }
131
149
}
132
150
133
151
@ Builtin (name = "f_lasti" , minNumOfPositionalArgs = 1 , isGetter = true )
0 commit comments