@@ -104,6 +104,15 @@ private PRaiseNode getRaiseNode() {
104
104
105
105
@ Override
106
106
public void executeVoid (VirtualFrame frame ) {
107
+ executeImpl (frame , false );
108
+ }
109
+
110
+ @ Override
111
+ public Object returnExecute (VirtualFrame frame ) {
112
+ return executeImpl (frame , true );
113
+ }
114
+
115
+ private Object executeImpl (VirtualFrame frame , boolean isReturn ) {
107
116
Object withObject = getWithObject (frame );
108
117
Object clazz = getClassNode .execute (withObject );
109
118
Object enterCallable = enterSpecialGetter .execute (frame , clazz , withObject );
@@ -117,11 +126,12 @@ public void executeVoid(VirtualFrame frame) {
117
126
throw getRaiseNode ().raise (PythonBuiltinClassType .AttributeError , ErrorMessages .OBJ_P_HAS_NO_ATTR_S , withObject , __EXIT__ );
118
127
}
119
128
doEnter (frame , withObject , enterCallable );
129
+ Object result = null ;
120
130
try {
121
- doBody (frame );
131
+ result = doBody (frame , isReturn );
122
132
} catch (PException exception ) {
123
133
handleException (frame , withObject , exitCallable , exception );
124
- return ;
134
+ return PNone . NONE ;
125
135
} catch (ControlFlowException e ) {
126
136
doLeave (frame , withObject , exitCallable );
127
137
throw e ;
@@ -131,9 +141,10 @@ public void executeVoid(VirtualFrame frame) {
131
141
throw e ;
132
142
}
133
143
handleException (frame , withObject , exitCallable , pe );
134
- return ;
144
+ return PNone . NONE ;
135
145
}
136
146
doLeave (frame , withObject , exitCallable );
147
+ return result ;
137
148
}
138
149
139
150
/**
@@ -146,8 +157,8 @@ protected Object getWithObject(VirtualFrame frame) {
146
157
/**
147
158
* Execute the body
148
159
*/
149
- protected void doBody (VirtualFrame frame ) {
150
- body .executeVoid (frame );
160
+ protected Object doBody (VirtualFrame frame , boolean isReturn ) {
161
+ return body .genericExecute (frame , isReturn );
151
162
}
152
163
153
164
/**
0 commit comments