283 ]. |
283 ]. |
284 |
284 |
285 blockNeedsCollection ifTrue:[ |
285 blockNeedsCollection ifTrue:[ |
286 "Bad, we have to use the collection. |
286 "Bad, we have to use the collection. |
287 Replace all references to blockNodeVar to retvalVar..." |
287 Replace all references to blockNodeVar to retvalVar..." |
288 blockBody variableNodesDo:[:variableNode| |
288 self withAllVariableNodesOf: blockBody do:[:variableNode| |
289 variableNode name = blockNodesVar name ifTrue:[ |
289 variableNode name = blockNodesVar name ifTrue:[ |
290 variableNode token value: self retvalVar. |
290 variableNode name: self retvalVar. |
291 ]. |
291 ]. |
292 ]. |
292 ]. |
293 ] ifFalse:[ |
293 ] ifFalse:[ |
294 "Good, can avoid intermediate collection. |
294 "Good, can avoid intermediate collection. |
295 Replace references to collection with corresponding temporary variable" |
295 Replace references to collection with corresponding temporary variable" |
296 blockMatches keysAndValuesDo:[:node :childValueVar | |
296 blockMatches keysAndValuesDo:[:matchingNode :childValueVar | |
297 node parent replaceNode: node withNode: (RBVariableNode named: childValueVar). |
297 matchingNode parent replaceNode: matchingNode withNode: (RBVariableNode named: childValueVar). |
298 ]. |
298 ]. |
299 node child returnParsedObjectsAsCollection: false. |
299 node child returnParsedObjectsAsCollection: false. |
300 ]. |
300 ]. |
301 |
301 |
302 "Block return value is return value of last statement. |
302 "Block return value is return value of last statement. |
531 | blockArg | |
531 | blockArg | |
532 |
532 |
533 blockArg := blockNode arguments first. |
533 blockArg := blockNode arguments first. |
534 self withAllVariableNodesOf: blockBody do:[:variableNode| |
534 self withAllVariableNodesOf: blockBody do:[:variableNode| |
535 variableNode name = blockArg name ifTrue:[ |
535 variableNode name = blockArg name ifTrue:[ |
536 variableNode token value: self retvalVar. |
536 variableNode name: self retvalVar. |
537 ]. |
537 ]. |
538 ]. |
538 ]. |
539 ]. |
539 ]. |
540 |
540 |
541 compiler codeAssignParsedValueOf: [ self visit: child ] to: self retvalVar. |
541 compiler codeAssignParsedValueOf: [ self visit: child ] to: self retvalVar. |
555 ]. |
555 ]. |
556 compiler code: blockBody. |
556 compiler code: blockBody. |
557 ] |
557 ] |
558 |
558 |
559 "Created: / 02-06-2015 / 17:28:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
559 "Created: / 02-06-2015 / 17:28:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
560 "Modified: / 18-06-2015 / 22:03:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
560 "Modified: / 19-06-2015 / 07:06:19 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
561 ! |
561 ! |
562 |
562 |
563 visitMessagePredicateNode: node |
563 visitMessagePredicateNode: node |
564 compiler add: '(context peek ', node message, ') ifFalse: ['. |
564 compiler add: '(context peek ', node message, ') ifFalse: ['. |
565 compiler codeError: 'predicate not found'. |
565 compiler codeError: 'predicate not found'. |