53
53
import static com .oracle .graal .python .builtins .modules .io .IONodes .CLOSED ;
54
54
import static com .oracle .graal .python .builtins .modules .io .IONodes .DETACH ;
55
55
import static com .oracle .graal .python .builtins .modules .io .IONodes .FILENO ;
56
+ import static com .oracle .graal .python .builtins .modules .io .IONodes .FLUSH ;
56
57
import static com .oracle .graal .python .builtins .modules .io .IONodes .ISATTY ;
57
58
import static com .oracle .graal .python .builtins .modules .io .IONodes .MODE ;
58
59
import static com .oracle .graal .python .builtins .modules .io .IONodes .NAME ;
78
79
import com .oracle .graal .python .builtins .CoreFunctions ;
79
80
import com .oracle .graal .python .builtins .objects .PNone ;
80
81
import com .oracle .graal .python .builtins .objects .type .TypeNodes ;
82
+ import com .oracle .graal .python .lib .PyObjectCallMethodObjArgs ;
83
+ import com .oracle .graal .python .lib .PyObjectGetAttr ;
81
84
import com .oracle .graal .python .lib .PyObjectLookupAttr ;
82
- import com .oracle .graal .python .nodes . call . special . LookupAndCallUnaryNode ;
85
+ import com .oracle .graal .python .lib . PyObjectReprAsJavaStringNode ;
83
86
import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
84
87
import com .oracle .graal .python .nodes .function .builtins .PythonBinaryBuiltinNode ;
85
88
import com .oracle .graal .python .nodes .function .builtins .PythonTernaryClinicBuiltinNode ;
@@ -113,10 +116,10 @@ abstract static class CloseNode extends PythonUnaryWithInitErrorBuiltinNode {
113
116
114
117
private static Object close (VirtualFrame frame , PBuffered self ,
115
118
BufferedIONodes .EnterBufferedNode lock ,
116
- IONodes . CallClose callClose ) {
119
+ PyObjectCallMethodObjArgs callMethodClose ) {
117
120
try {
118
121
lock .enter (self );
119
- Object res = callClose .execute (frame , self .getRaw ());
122
+ Object res = callMethodClose .execute (frame , self .getRaw (), CLOSE );
120
123
if (self .getBuffer () != null ) {
121
124
self .setBuffer (null );
122
125
}
@@ -129,9 +132,9 @@ private static Object close(VirtualFrame frame, PBuffered self,
129
132
@ Specialization (guards = "self.isOK()" )
130
133
static Object doit (VirtualFrame frame , PBuffered self ,
131
134
@ Cached BufferedIONodes .IsClosedNode isClosedNode ,
132
- @ Cached IONodes . CallFlush flush ,
133
- @ Cached IONodes . CallClose callClose ,
134
- @ Cached IONodes . CallDeallocWarn deallocWarn ,
135
+ @ Cached PyObjectCallMethodObjArgs callMethodFlush ,
136
+ @ Cached PyObjectCallMethodObjArgs callMethodClose ,
137
+ @ Cached PyObjectCallMethodObjArgs callMethodDeallocWarn ,
135
138
@ Cached BufferedIONodes .EnterBufferedNode lock ,
136
139
@ Cached ConditionProfile profile ) {
137
140
try {
@@ -141,25 +144,25 @@ static Object doit(VirtualFrame frame, PBuffered self,
141
144
}
142
145
if (self .isFinalizing ()) {
143
146
if (self .getRaw () != null ) {
144
- deallocWarn .execute (frame , self .getRaw (), self );
147
+ callMethodDeallocWarn .execute (frame , self .getRaw (), _DEALLOC_WARN , self );
145
148
}
146
149
}
147
150
} finally {
148
151
BufferedIONodes .EnterBufferedNode .leave (self );
149
152
}
150
153
/* flush() will most probably re-take the lock, so drop it first */
151
154
try {
152
- flush .execute (frame , self );
155
+ callMethodFlush .execute (frame , self , FLUSH );
153
156
} catch (PException e ) {
154
157
try {
155
- close (frame , self , lock , callClose );
158
+ close (frame , self , lock , callMethodClose );
156
159
} catch (PException ee ) {
157
160
chainExceptions (ee .getEscapedException (), e );
158
161
throw ee .getExceptionForReraise ();
159
162
}
160
163
throw e ;
161
164
}
162
- return close (frame , self , lock , callClose );
165
+ return close (frame , self , lock , callMethodClose );
163
166
}
164
167
}
165
168
@@ -168,8 +171,8 @@ static Object doit(VirtualFrame frame, PBuffered self,
168
171
abstract static class DetachNode extends PythonUnaryWithInitErrorBuiltinNode {
169
172
@ Specialization (guards = "self.isOK()" )
170
173
static Object doit (VirtualFrame frame , PBuffered self ,
171
- @ Cached IONodes . CallFlush flush ) {
172
- flush .execute (frame , self );
174
+ @ Cached PyObjectCallMethodObjArgs callMethodFlush ) {
175
+ callMethodFlush .execute (frame , self , FLUSH );
173
176
Object raw = self .getRaw ();
174
177
self .clearRaw ();
175
178
self .setDetached (true );
@@ -183,8 +186,8 @@ static Object doit(VirtualFrame frame, PBuffered self,
183
186
abstract static class SeekableNode extends PythonUnaryWithInitErrorBuiltinNode {
184
187
@ Specialization (guards = "self.isOK()" )
185
188
static Object doit (VirtualFrame frame , PBuffered self ,
186
- @ Cached IONodes . CallSeekable seekable ) {
187
- return seekable .execute (frame , self .getRaw ());
189
+ @ Cached PyObjectCallMethodObjArgs callMethod ) {
190
+ return callMethod .execute (frame , self .getRaw (), SEEKABLE );
188
191
}
189
192
}
190
193
@@ -193,8 +196,8 @@ static Object doit(VirtualFrame frame, PBuffered self,
193
196
abstract static class FileNoNode extends PythonUnaryWithInitErrorBuiltinNode {
194
197
@ Specialization (guards = "self.isOK()" )
195
198
static Object doit (VirtualFrame frame , PBuffered self ,
196
- @ Cached IONodes . CallFileNo fileNo ) {
197
- return fileNo .execute (frame , self .getRaw ());
199
+ @ Cached PyObjectCallMethodObjArgs callMethod ) {
200
+ return callMethod .execute (frame , self .getRaw (), FILENO );
198
201
}
199
202
}
200
203
@@ -203,8 +206,8 @@ static Object doit(VirtualFrame frame, PBuffered self,
203
206
abstract static class IsAttyNode extends PythonUnaryWithInitErrorBuiltinNode {
204
207
@ Specialization (guards = "self.isOK()" )
205
208
static Object doit (VirtualFrame frame , PBuffered self ,
206
- @ Cached IONodes . CallIsAtty isAtty ) {
207
- return isAtty .execute (frame , self .getRaw ());
209
+ @ Cached PyObjectCallMethodObjArgs callMethod ) {
210
+ return callMethod .execute (frame , self .getRaw (), ISATTY );
208
211
}
209
212
}
210
213
@@ -213,8 +216,8 @@ static Object doit(VirtualFrame frame, PBuffered self,
213
216
abstract static class DeallocWarnNode extends PythonBinaryBuiltinNode {
214
217
@ Specialization (guards = {"self.isOK()" , "self.getRaw() != null" })
215
218
static Object doit (VirtualFrame frame , PBuffered self , Object source ,
216
- @ Cached IONodes . CallDeallocWarn deallocWarn ) {
217
- deallocWarn .execute (frame , self .getRaw (), source );
219
+ @ Cached PyObjectCallMethodObjArgs callMethod ) {
220
+ callMethod .execute (frame , self .getRaw (), _DEALLOC_WARN , source );
218
221
return PNone .NONE ;
219
222
}
220
223
@@ -296,12 +299,12 @@ static Object doit(VirtualFrame frame, PBuffered self, Object pos,
296
299
@ Cached ("create(TRUNCATE)" ) BufferedIONodes .CheckIsClosedNode checkIsClosedNode ,
297
300
@ Cached BufferedIONodes .RawTellNode rawTellNode ,
298
301
@ Cached BufferedIONodes .FlushAndRewindUnlockedNode flushAndRewindUnlockedNode ,
299
- @ Cached IONodes . CallTruncate truncate ) {
302
+ @ Cached PyObjectCallMethodObjArgs callMethodTruncate ) {
300
303
checkIsClosedNode .execute (frame , self );
301
304
try {
302
305
lock .enter (self );
303
306
flushAndRewindUnlockedNode .execute (frame , self );
304
- Object res = truncate .execute (frame , self .getRaw (), pos );
307
+ Object res = callMethodTruncate .execute (frame , self .getRaw (), TRUNCATE , pos );
305
308
/* Reset cached position */
306
309
rawTellNode .execute (frame , self );
307
310
return res ;
@@ -349,8 +352,8 @@ static Object doit(VirtualFrame frame, PBuffered self,
349
352
abstract static class NameNode extends PythonUnaryWithInitErrorBuiltinNode {
350
353
@ Specialization (guards = "self.isOK()" )
351
354
static Object doit (VirtualFrame frame , PBuffered self ,
352
- @ Cached IONodes . GetName getName ) {
353
- return getName .execute (frame , self .getRaw ());
355
+ @ Cached PyObjectGetAttr getAttr ) {
356
+ return getAttr .execute (frame , self .getRaw (), NAME );
354
357
}
355
358
}
356
359
@@ -359,8 +362,8 @@ static Object doit(VirtualFrame frame, PBuffered self,
359
362
abstract static class ModeNode extends PythonUnaryWithInitErrorBuiltinNode {
360
363
@ Specialization (guards = "self.isOK()" )
361
364
static Object doit (VirtualFrame frame , PBuffered self ,
362
- @ Cached IONodes . GetMode getMode ) {
363
- return getMode .execute (frame , self .getRaw ());
365
+ @ Cached PyObjectGetAttr getAttr ) {
366
+ return getAttr .execute (frame , self .getRaw (), MODE );
364
367
}
365
368
}
366
369
@@ -373,8 +376,8 @@ Object repr(VirtualFrame frame, PBuffered self,
373
376
@ Cached TypeNodes .GetNameNode getNameNode ,
374
377
@ Cached GetClassNode getClassNode ,
375
378
@ Cached IsBuiltinClassProfile isValueError ,
376
- @ Cached ( "create(__REPR__)" ) LookupAndCallUnaryNode repr ) {
377
- Object clazz = getNameNode .execute (getClassNode .execute (self ));
379
+ @ Cached PyObjectReprAsJavaStringNode repr ) {
380
+ String typeName = getNameNode .execute (getClassNode .execute (self ));
378
381
Object nameobj = PNone .NO_VALUE ;
379
382
try {
380
383
nameobj = lookup .execute (frame , self , NAME );
@@ -383,14 +386,14 @@ Object repr(VirtualFrame frame, PBuffered self,
383
386
// ignore
384
387
}
385
388
if (nameobj instanceof PNone ) {
386
- return PythonUtils .format ("<%s>" , clazz );
389
+ return PythonUtils .format ("<%s>" , typeName );
387
390
} else {
388
391
if (!getContext ().reprEnter (self )) {
389
- throw raise (RuntimeError , "reentrant call inside %s.__repr__" , clazz );
392
+ throw raise (RuntimeError , "reentrant call inside %s.__repr__" , typeName );
390
393
} else {
391
394
try {
392
- Object name = repr .executeObject (frame , nameobj );
393
- return PythonUtils .format ("<%s name=%s>" , clazz , name );
395
+ String name = repr .execute (frame , nameobj );
396
+ return PythonUtils .format ("<%s name=%s>" , typeName , name );
394
397
} finally {
395
398
getContext ().reprLeave (self );
396
399
}
0 commit comments