compiler/PPCCodeGenerator.st
changeset 485 d86e2db09346
parent 484 e829f3860745
child 486 0dd7eb52b5a1
equal deleted inserted replaced
484:e829f3860745 485:d86e2db09346
     6 	instanceVariableNames:'compiler'
     6 	instanceVariableNames:'compiler'
     7 	classVariableNames:''
     7 	classVariableNames:''
     8 	poolDictionaries:''
     8 	poolDictionaries:''
     9 	category:'PetitCompiler-Visitors'
     9 	category:'PetitCompiler-Visitors'
    10 !
    10 !
       
    11 
    11 
    12 
    12 !PPCCodeGenerator class methodsFor:'as yet unclassified'!
    13 !PPCCodeGenerator class methodsFor:'as yet unclassified'!
    13 
    14 
    14 new
    15 new
    15     ^ self basicNew
    16     ^ self basicNew
   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     
   909     compiler dedent.
   912     compiler dedent.
   910     compiler add: 'error := ', self retvalVar, ' isPetitFailure.'.
   913     compiler add: 'error := ', self retvalVar, ' isPetitFailure.'.
   911     compiler codeReturn.
   914     compiler codeReturn.
   912 ! !
   915 ! !
   913 
   916 
       
   917 !PPCCodeGenerator class methodsFor:'documentation'!
       
   918 
       
   919 version_HG
       
   920 
       
   921     ^ '$Changeset: <not expanded> $'
       
   922 ! !
       
   923