42
42
43
43
import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
44
44
import com .oracle .graal .python .builtins .objects .PNone ;
45
- import com .oracle .graal .python .builtins .objects .exception .GetExceptionTracebackNode ;
46
45
import com .oracle .graal .python .builtins .objects .exception .PBaseException ;
47
46
import com .oracle .graal .python .builtins .objects .function .PArguments ;
48
- import com .oracle .graal .python .builtins .objects .function .PKeyword ;
49
- import com .oracle .graal .python .nodes .SpecialMethodNames ;
47
+ import com .oracle .graal .python .builtins .objects .traceback .GetTracebackNode ;
50
48
import com .oracle .graal .python .nodes .attributes .GetAttributeNode ;
51
- import com .oracle .graal .python .nodes .attributes .LookupInheritedAttributeNode ;
52
49
import com .oracle .graal .python .nodes .call .CallNode ;
53
- import com .oracle .graal .python .nodes .call .special .LookupAndCallBinaryNode ;
54
50
import com .oracle .graal .python .nodes .control .GetIteratorExpressionNode .GetIteratorNode ;
55
51
import com .oracle .graal .python .nodes .control .GetNextNode ;
56
52
import com .oracle .graal .python .nodes .expression .ExpressionNode ;
61
57
import com .oracle .truffle .api .CompilerDirectives ;
62
58
import com .oracle .truffle .api .CompilerDirectives .CompilationFinal ;
63
59
import com .oracle .truffle .api .frame .VirtualFrame ;
64
- import com .oracle .truffle .api .profiles .BranchProfile ;
65
60
66
61
public class YieldFromNode extends AbstractYieldNode implements GeneratorControlNode {
67
62
@ Child private GetIteratorNode iter = GetIteratorNode .create ();
@@ -70,27 +65,27 @@ public class YieldFromNode extends AbstractYieldNode implements GeneratorControl
70
65
71
66
@ Child private GetAttributeNode getValue ;
72
67
73
- @ Child private LookupInheritedAttributeNode getCloseNode ;
68
+ @ Child private GetAttributeNode getCloseNode ;
74
69
@ Child private CallNode callCloseNode ;
75
70
76
- @ Child private LookupInheritedAttributeNode getThrowNode ;
71
+ @ Child private GetAttributeNode getThrowNode ;
77
72
@ Child private CallNode callThrowNode ;
78
73
@ Child private GetClassNode getExcClassNode ;
79
74
80
- @ Child private LookupAndCallBinaryNode getSendNode ;
75
+ @ Child private GetAttributeNode getSendNode ;
81
76
@ Child private CallNode callSendNode ;
82
77
83
- @ Child private GetExceptionTracebackNode getExceptionTracebackNode ;
78
+ @ Child private GetTracebackNode getTracebackNode ;
84
79
85
80
@ Child private IsBuiltinClassProfile stopIterProfile1 = IsBuiltinClassProfile .create ();
86
81
@ Child private IsBuiltinClassProfile stopIterProfile2 = IsBuiltinClassProfile .create ();
87
82
@ Child private IsBuiltinClassProfile stopIterProfile3 = IsBuiltinClassProfile .create ();
88
83
@ Child private IsBuiltinClassProfile genExitProfile = IsBuiltinClassProfile .create ();
84
+ @ Child private IsBuiltinClassProfile hasNoCloseProfile = IsBuiltinClassProfile .create ();
85
+ @ Child private IsBuiltinClassProfile hasNoThrowProfile = IsBuiltinClassProfile .create ();
89
86
90
87
@ CompilationFinal private int iteratorSlot ;
91
88
92
- private final BranchProfile noThrow = BranchProfile .create ();
93
-
94
89
@ Child private ExpressionNode right ;
95
90
96
91
public YieldFromNode (ExpressionNode right ) {
@@ -143,9 +138,17 @@ public Object execute(VirtualFrame frame) {
143
138
// ....raise _e
144
139
if (genExitProfile .profileException (_e , PythonBuiltinClassType .GeneratorExit )) {
145
140
access .setIterator (frame , iteratorSlot , null );
146
- Object close = getGetCloseNode ().execute (_i );
147
- if (close != PNone .NO_VALUE ) {
148
- getCallCloseNode ().execute (frame , close , new Object []{_i }, PKeyword .EMPTY_KEYWORDS );
141
+ Object close = null ;
142
+ try {
143
+ close = getGetCloseNode ().executeObject (frame , _i );
144
+ } catch (PException pe ) {
145
+ if (!hasNoCloseProfile .profileException (pe , PythonBuiltinClassType .AttributeError )) {
146
+ // TODO msimacek: CPython writes the exception (!=AttributeError) as
147
+ // unraisable and discards it
148
+ }
149
+ }
150
+ if (close != null ) {
151
+ getCallCloseNode ().execute (frame , close );
149
152
}
150
153
throw _e ;
151
154
}
@@ -161,24 +164,26 @@ public Object execute(VirtualFrame frame) {
161
164
// ........except StopIteration as _e:
162
165
// ............_r = _e.value
163
166
// ............break
164
- Object _m = getGetThrowNode ().execute (_i );
165
- if (_m == PNone .NO_VALUE ) {
166
- noThrow .enter ();
167
+ Object _m ;
168
+ try {
169
+ _m = getGetThrowNode ().executeObject (frame , _i );
170
+ } catch (PException pe ) {
171
+ pe .expectAttributeError (hasNoThrowProfile );
167
172
access .setIterator (frame , iteratorSlot , null );
168
173
throw _e ;
169
- } else {
170
- try {
171
- PBaseException pythonException = ((PException ) _s ).setCatchingFrameAndGetEscapedException (frame );
172
- _y = getCallThrowNode ().execute (frame , _m ,
173
- new Object []{_i , getExceptionClassNode ().execute (pythonException ),
174
- pythonException ,
175
- ensureGetTracebackNode ().execute (frame , pythonException )},
176
- PKeyword .EMPTY_KEYWORDS );
177
- } catch (PException _e2 ) {
178
- access .setIterator (frame , iteratorSlot , null );
179
- _e2 .expectStopIteration (stopIterProfile2 );
180
- return getGetValue ().executeObject (frame , _e2 .setCatchingFrameAndGetEscapedException (frame ));
174
+ }
175
+ try {
176
+ PBaseException pythonException = ((PException ) _s ).setCatchingFrameAndGetEscapedException (frame );
177
+ Object excType = getExceptionClassNode ().execute (pythonException );
178
+ Object excTraceback = ensureGetTracebackNode ().execute (((PException ) _s ).getTraceback ());
179
+ if (excTraceback == null ) {
180
+ excTraceback = PNone .NONE ;
181
181
}
182
+ _y = getCallThrowNode ().execute (frame , _m , excType , pythonException , excTraceback );
183
+ } catch (PException _e2 ) {
184
+ access .setIterator (frame , iteratorSlot , null );
185
+ _e2 .expectStopIteration (stopIterProfile2 );
186
+ return getGetValue ().executeObject (frame , _e2 .setCatchingFrameAndGetEscapedException (frame ));
182
187
}
183
188
} else {
184
189
// else:
@@ -195,9 +200,9 @@ public Object execute(VirtualFrame frame) {
195
200
gotNothing .enter ();
196
201
_y = next .execute (frame , _i );
197
202
} else {
198
- Object send = getGetSendNode ().executeObject (frame , _i , "send" );
203
+ Object send = getGetSendNode ().executeObject (frame , _i );
199
204
// send will be bound at this point
200
- _y = getCallSendNode ().execute (frame , send , new Object []{ _s }, PKeyword . EMPTY_KEYWORDS );
205
+ _y = getCallSendNode ().execute (frame , send , _s );
201
206
}
202
207
} catch (PException _e ) {
203
208
access .setIterator (frame , iteratorSlot , null );
@@ -225,10 +230,10 @@ private GetClassNode getExceptionClassNode() {
225
230
return getExcClassNode ;
226
231
}
227
232
228
- private LookupInheritedAttributeNode getGetCloseNode () {
233
+ private GetAttributeNode getGetCloseNode () {
229
234
if (getCloseNode == null ) {
230
235
CompilerDirectives .transferToInterpreterAndInvalidate ();
231
- getCloseNode = insert (LookupInheritedAttributeNode .create ("close" ));
236
+ getCloseNode = insert (GetAttributeNode .create ("close" ));
232
237
}
233
238
return getCloseNode ;
234
239
}
@@ -241,10 +246,10 @@ private CallNode getCallCloseNode() {
241
246
return callCloseNode ;
242
247
}
243
248
244
- private LookupInheritedAttributeNode getGetThrowNode () {
249
+ private GetAttributeNode getGetThrowNode () {
245
250
if (getThrowNode == null ) {
246
251
CompilerDirectives .transferToInterpreterAndInvalidate ();
247
- getThrowNode = insert (LookupInheritedAttributeNode .create ("throw" ));
252
+ getThrowNode = insert (GetAttributeNode .create ("throw" ));
248
253
}
249
254
return getThrowNode ;
250
255
}
@@ -257,10 +262,10 @@ private CallNode getCallThrowNode() {
257
262
return callThrowNode ;
258
263
}
259
264
260
- private LookupAndCallBinaryNode getGetSendNode () {
265
+ private GetAttributeNode getGetSendNode () {
261
266
if (getSendNode == null ) {
262
267
CompilerDirectives .transferToInterpreterAndInvalidate ();
263
- getSendNode = insert (LookupAndCallBinaryNode .create (SpecialMethodNames . __GETATTRIBUTE__ ));
268
+ getSendNode = insert (GetAttributeNode .create ("send" ));
264
269
}
265
270
return getSendNode ;
266
271
}
@@ -273,12 +278,12 @@ private CallNode getCallSendNode() {
273
278
return callSendNode ;
274
279
}
275
280
276
- private GetExceptionTracebackNode ensureGetTracebackNode () {
277
- if (getExceptionTracebackNode == null ) {
281
+ private GetTracebackNode ensureGetTracebackNode () {
282
+ if (getTracebackNode == null ) {
278
283
CompilerDirectives .transferToInterpreterAndInvalidate ();
279
- getExceptionTracebackNode = insert (GetExceptionTracebackNode .create ());
284
+ getTracebackNode = insert (GetTracebackNode .create ());
280
285
}
281
- return getExceptionTracebackNode ;
286
+ return getTracebackNode ;
282
287
}
283
288
284
289
public void setIteratorSlot (int slot ) {
0 commit comments