3838import com .oracle .graal .python .builtins .objects .code .PCode ;
3939import com .oracle .graal .python .builtins .objects .frame .PFrame .Reference ;
4040import com .oracle .graal .python .builtins .objects .function .PArguments ;
41+ import com .oracle .graal .python .builtins .objects .getsetdescriptor .DescriptorDeleteMarker ;
4142import com .oracle .graal .python .builtins .objects .module .PythonModule ;
4243import com .oracle .graal .python .builtins .objects .object .ObjectBuiltins .DictNode ;
4344import com .oracle .graal .python .builtins .objects .object .ObjectBuiltinsFactory ;
5354import com .oracle .graal .python .nodes .frame .ReadCallerFrameNode .FrameSelector ;
5455import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
5556import com .oracle .graal .python .nodes .function .PythonBuiltinNode ;
57+ import com .oracle .graal .python .nodes .function .builtins .PythonBinaryBuiltinNode ;
5658import com .oracle .graal .python .nodes .function .builtins .PythonUnaryBuiltinNode ;
5759import com .oracle .graal .python .nodes .util .CannotCastException ;
5860import com .oracle .graal .python .nodes .util .CastToJavaBooleanNode ;
@@ -153,14 +155,7 @@ int get(VirtualFrame frame, PFrame self,
153155 @ Bind ("this" ) Node inliningTarget ,
154156 @ Cached InlinedConditionProfile isCurrentFrameProfile ,
155157 @ Cached MaterializeFrameNode materializeNode ) {
156- // Special case because this builtin can be called without going through an invoke node:
157- // we need to sync the location of the frame if and only if 'self' represents the
158- // current frame. If 'self' represents another frame on the stack, the location is
159- // already set
160- if (isCurrentFrameProfile .profile (inliningTarget , frame != null && PArguments .getCurrentFrameInfo (frame ) == self .getRef ())) {
161- PFrame pyFrame = materializeNode .execute (frame , this , false , false );
162- assert pyFrame == self ;
163- }
158+ LinenoNode .syncLocationIfNeeded (frame , self , this , inliningTarget , isCurrentFrameProfile , materializeNode );
164159 return self .getLine ();
165160 }
166161
@@ -170,40 +165,45 @@ public static GetLinenoNode create() {
170165 }
171166 }
172167
173- @ Builtin (name = "f_lineno" , minNumOfPositionalArgs = 1 , maxNumOfPositionalArgs = 2 , isGetter = true , isSetter = true )
168+ @ Builtin (name = "f_lineno" , minNumOfPositionalArgs = 1 , maxNumOfPositionalArgs = 2 , isGetter = true , isSetter = true , allowsDelete = true )
174169 @ GenerateNodeFactory
175- public abstract static class LinenoNode extends PythonBuiltinNode {
176- public abstract Object execute (VirtualFrame frame , PFrame self , Object newLineno );
170+ public abstract static class LinenoNode extends PythonBinaryBuiltinNode {
171+
172+ @ Specialization
173+ Object delete (VirtualFrame frame , PFrame self , DescriptorDeleteMarker ignored ,
174+ @ Bind ("this" ) Node inliningTarget ,
175+ @ Cached @ Cached .Exclusive PRaiseNode .Lazy raise ) {
176+ raise .get (inliningTarget ).raise (PythonBuiltinClassType .AttributeError , ErrorMessages .CANNOT_DELETE );
177+ return PNone .NONE ;
178+ }
177179
178180 @ Specialization (guards = "isNoValue(newLineno)" )
179181 int get (VirtualFrame frame , PFrame self , Object newLineno ,
180- @ Bind ("this" ) Node inliningTarget ,
181- @ Cached .Shared ("isCurrentFrame" ) @ Cached InlinedConditionProfile isCurrentFrameProfile ,
182- @ Cached .Shared ("materialize" ) @ Cached MaterializeFrameNode materializeNode ) {
183- syncLocationIfNeeded (frame , self , inliningTarget , isCurrentFrameProfile , materializeNode );
184- return self .getLine ();
182+ @ Cached GetLinenoNode getLinenoNode ) {
183+ return getLinenoNode .executeInt (frame , self );
185184 }
186185
187- private void syncLocationIfNeeded (VirtualFrame frame , PFrame self , Node inliningTarget , InlinedConditionProfile isCurrentFrameProfile , MaterializeFrameNode materializeNode ) {
186+ static void syncLocationIfNeeded (VirtualFrame frame , PFrame self , Node location , Node inliningTarget , InlinedConditionProfile isCurrentFrameProfile , MaterializeFrameNode materializeNode ) {
188187 // Special case because this builtin can be called without going through an invoke node:
189188 // we need to sync the location of the frame if and only if 'self' represents the
190189 // current frame. If 'self' represents another frame on the stack, the location is
191190 // already set
192191 if (isCurrentFrameProfile .profile (inliningTarget , frame != null && PArguments .getCurrentFrameInfo (frame ) == self .getRef ())) {
193- PFrame pyFrame = materializeNode .execute (frame , this , false , false );
192+ PFrame pyFrame = materializeNode .execute (frame , location , false , false );
194193 assert pyFrame == self ;
195194 }
196195 }
197196
198- @ Specialization (guards = "!isNoValue(newLineno)" )
197+ @ SuppressWarnings ("truffle-static-method" ) // this is used for location here
198+ @ Specialization (guards = {"!isNoValue(newLineno)" , "!isDeleteMarker(newLineno)" })
199199 PNone set (VirtualFrame frame , PFrame self , Object newLineno ,
200200 @ Bind ("this" ) Node inliningTarget ,
201- @ Cached . Shared ( "isCurrentFrame" ) @ Cached InlinedConditionProfile isCurrentFrameProfile ,
202- @ Cached . Shared ( "materialize" ) @ Cached MaterializeFrameNode materializeNode ,
203- @ Cached PRaiseNode .Lazy raise ,
201+ @ Cached InlinedConditionProfile isCurrentFrameProfile ,
202+ @ Cached MaterializeFrameNode materializeNode ,
203+ @ Cached @ Cached . Exclusive PRaiseNode .Lazy raise ,
204204 @ Cached PyLongCheckExactNode isLong ,
205205 @ Cached PyLongAsLongAndOverflowNode toLong ) {
206- syncLocationIfNeeded (frame , self , inliningTarget , isCurrentFrameProfile , materializeNode );
206+ syncLocationIfNeeded (frame , self , this , inliningTarget , isCurrentFrameProfile , materializeNode );
207207 if (self .isTraceArgument ()) {
208208 if (isLong .execute (inliningTarget , newLineno )) {
209209 try {
0 commit comments