compiler/PPCCodeGenerator.st
changeset 479 6316a98b7150
parent 478 711c8bc1ec04
child 481 34ee0d3c72e7
equal deleted inserted replaced
478:711c8bc1ec04 479:6316a98b7150
   202 ! !
   202 ! !
   203 
   203 
   204 !PPCCodeGenerator methodsFor:'visiting'!
   204 !PPCCodeGenerator methodsFor:'visiting'!
   205 
   205 
   206 visitActionNode: node
   206 visitActionNode: node
   207     | blockId |
   207     | blockNode blockBody blockNodesVar |
   208 
   208 
   209     blockId := 'block_', (compiler idFor: node).
   209     blockNode := node block ast copy.
   210     compiler addConstant: node block as: blockId.
   210     self assert: blockNode arguments size == 1.
   211         
   211     blockNodesVar := blockNode arguments first .
       
   212     blockBody := blockNode body.
       
   213     "Replace all references to blockNodeVar to retvalVar..."
       
   214     blockBody variableNodesDo:[:variableNode| 
       
   215         variableNode name = blockNodesVar name ifTrue:[ 
       
   216             variableNode token value: self retvalVar.
       
   217         ].
       
   218     ].
       
   219     "Block return value is return value of last statement.
       
   220      So if the method is not inline, make last statement a return.
       
   221         if the method is inline, make it assignment to retvalVar."
       
   222     compiler currentMethod isInline ifTrue:[ 
       
   223         |  assignment |
       
   224 
       
   225         assignment := RBAssignmentNode variable: (RBVariableNode named: self retvalVar) value:  blockBody statements last.
       
   226         blockBody replaceNode: blockBody statements last withNode: assignment.
       
   227     ] ifFalse:[  
       
   228         | return |
       
   229 
       
   230         return := RBReturnNode value: blockBody statements last.
       
   231         blockBody replaceNode: blockBody statements last withNode: return.
       
   232     ].
       
   233 
   212     compiler codeStoreValueOf: [ self visit: node child ] intoVariable: self retvalVar.
   234     compiler codeStoreValueOf: [ self visit: node child ] intoVariable: self retvalVar.
   213     compiler codeIf: 'error' then: [ 
   235     compiler codeIf: 'error' then: [ 
   214         compiler codeReturn: 'failure'. 
   236         compiler codeReturn: 'failure'. 
   215     ] else: [ 
   237     ] else: [
   216         compiler codeReturn: blockId, ' value: ', self retvalVar. 
   238         compiler code: blockBody.    
   217     ]
   239     ]
   218 
   240 
   219     "Modified (format): / 01-06-2015 / 23:03:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   241     "Modified: / 01-06-2015 / 23:58:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   220 !
   242 !
   221 
   243 
   222 visitAndNode: node
   244 visitAndNode: node
   223     | mementoVar |
   245     | mementoVar |
   224     
   246