38
38
import com .oracle .graal .python .builtins .objects .code .PCode ;
39
39
import com .oracle .graal .python .builtins .objects .frame .PFrame .Reference ;
40
40
import com .oracle .graal .python .builtins .objects .function .PArguments ;
41
+ import com .oracle .graal .python .builtins .objects .getsetdescriptor .DescriptorDeleteMarker ;
41
42
import com .oracle .graal .python .builtins .objects .module .PythonModule ;
42
43
import com .oracle .graal .python .builtins .objects .object .ObjectBuiltins .DictNode ;
43
44
import com .oracle .graal .python .builtins .objects .object .ObjectBuiltinsFactory ;
53
54
import com .oracle .graal .python .nodes .frame .ReadCallerFrameNode .FrameSelector ;
54
55
import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
55
56
import com .oracle .graal .python .nodes .function .PythonBuiltinNode ;
57
+ import com .oracle .graal .python .nodes .function .builtins .PythonBinaryBuiltinNode ;
56
58
import com .oracle .graal .python .nodes .function .builtins .PythonUnaryBuiltinNode ;
57
59
import com .oracle .graal .python .nodes .util .CannotCastException ;
58
60
import com .oracle .graal .python .nodes .util .CastToJavaBooleanNode ;
@@ -153,14 +155,7 @@ int get(VirtualFrame frame, PFrame self,
153
155
@ Bind ("this" ) Node inliningTarget ,
154
156
@ Cached InlinedConditionProfile isCurrentFrameProfile ,
155
157
@ 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 );
164
159
return self .getLine ();
165
160
}
166
161
@@ -170,40 +165,45 @@ public static GetLinenoNode create() {
170
165
}
171
166
}
172
167
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 )
174
169
@ 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
+ }
177
179
178
180
@ Specialization (guards = "isNoValue(newLineno)" )
179
181
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 );
185
184
}
186
185
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 ) {
188
187
// Special case because this builtin can be called without going through an invoke node:
189
188
// we need to sync the location of the frame if and only if 'self' represents the
190
189
// current frame. If 'self' represents another frame on the stack, the location is
191
190
// already set
192
191
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 );
194
193
assert pyFrame == self ;
195
194
}
196
195
}
197
196
198
- @ Specialization (guards = "!isNoValue(newLineno)" )
197
+ @ SuppressWarnings ("truffle-static-method" ) // this is used for location here
198
+ @ Specialization (guards = {"!isNoValue(newLineno)" , "!isDeleteMarker(newLineno)" })
199
199
PNone set (VirtualFrame frame , PFrame self , Object newLineno ,
200
200
@ 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 ,
204
204
@ Cached PyLongCheckExactNode isLong ,
205
205
@ Cached PyLongAsLongAndOverflowNode toLong ) {
206
- syncLocationIfNeeded (frame , self , inliningTarget , isCurrentFrameProfile , materializeNode );
206
+ syncLocationIfNeeded (frame , self , this , inliningTarget , isCurrentFrameProfile , materializeNode );
207
207
if (self .isTraceArgument ()) {
208
208
if (isLong .execute (inliningTarget , newLineno )) {
209
209
try {
0 commit comments