217 ]. |
218 ]. |
218 ]. |
219 ]. |
219 "Block return value is return value of last statement. |
220 "Block return value is return value of last statement. |
220 So if the method is not inline, make last statement a return. |
221 So if the method is not inline, make last statement a return. |
221 if the method is inline, make it assignment to retvalVar." |
222 if the method is inline, make it assignment to retvalVar." |
222 compiler currentMethod isInline ifTrue:[ |
223 blockBody statements notEmpty ifTrue:["Care for empty blocks - [:t | ] !!" |
223 | assignment | |
224 compiler currentMethod isInline ifTrue:[ |
224 |
225 | assignment | |
225 assignment := RBAssignmentNode variable: (RBVariableNode named: self retvalVar) value: blockBody statements last. |
226 |
226 blockBody replaceNode: blockBody statements last withNode: assignment. |
227 assignment := RBAssignmentNode variable: (RBVariableNode named: self retvalVar) value: blockBody statements last. |
227 ] ifFalse:[ |
228 blockBody replaceNode: blockBody statements last withNode: assignment. |
228 | return | |
229 ] ifFalse:[ |
229 |
230 | return | |
230 return := RBReturnNode value: blockBody statements last. |
231 |
231 blockBody replaceNode: blockBody statements last withNode: return. |
232 return := RBReturnNode value: blockBody statements last. |
|
233 blockBody replaceNode: blockBody statements last withNode: return. |
|
234 ]. |
232 ]. |
235 ]. |
233 |
236 |
234 compiler codeStoreValueOf: [ self visit: node child ] intoVariable: self retvalVar. |
237 compiler codeStoreValueOf: [ self visit: node child ] intoVariable: self retvalVar. |
235 compiler codeIf: 'error' then: [ |
238 compiler codeIf: 'error' then: [ |
236 compiler codeReturn: 'failure'. |
239 compiler codeReturn: 'failure'. |
237 ] else: [ |
240 ] else: [ |
238 compiler code: blockBody. |
241 compiler code: blockBody. |
239 ] |
242 ] |
240 |
243 |
241 "Modified: / 01-06-2015 / 23:58:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
244 "Modified: / 15-06-2015 / 17:08:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
242 ! |
245 ! |
243 |
246 |
244 visitAndNode: node |
247 visitAndNode: node |
245 | mementoVar | |
248 | mementoVar | |
246 |
249 |