Fixed codegen for empty (mapped) action block.
authorJan Vrany <jan.vrany@fit.cvut.cz>
Mon, 15 Jun 2015 17:12:54 +0100
changeset 485 d86e2db09346
parent 484 e829f3860745
child 486 0dd7eb52b5a1
Fixed codegen for empty (mapped) action block. Although empty blocks are useless in practice, they may occur (and do occur in tests)
compiler/PPCCodeGenerator.st
--- a/compiler/PPCCodeGenerator.st	Fri Jun 05 00:05:08 2015 +0100
+++ b/compiler/PPCCodeGenerator.st	Mon Jun 15 17:12:54 2015 +0100
@@ -9,6 +9,7 @@
 	category:'PetitCompiler-Visitors'
 !
 
+
 !PPCCodeGenerator class methodsFor:'as yet unclassified'!
 
 new
@@ -219,16 +220,18 @@
     "Block return value is return value of last statement.
      So if the method is not inline, make last statement a return.
         if the method is inline, make it assignment to retvalVar."
-    compiler currentMethod isInline ifTrue:[ 
-        |  assignment |
+    blockBody statements notEmpty ifTrue:["Care for empty blocks - [:t | ] !!"
+        compiler currentMethod isInline ifTrue:[ 
+            |  assignment |
 
-        assignment := RBAssignmentNode variable: (RBVariableNode named: self retvalVar) value:  blockBody statements last.
-        blockBody replaceNode: blockBody statements last withNode: assignment.
-    ] ifFalse:[  
-        | return |
+            assignment := RBAssignmentNode variable: (RBVariableNode named: self retvalVar) value:  blockBody statements last.
+            blockBody replaceNode: blockBody statements last withNode: assignment.
+        ] ifFalse:[  
+            | return |
 
-        return := RBReturnNode value: blockBody statements last.
-        blockBody replaceNode: blockBody statements last withNode: return.
+            return := RBReturnNode value: blockBody statements last.
+            blockBody replaceNode: blockBody statements last withNode: return.
+        ].
     ].
 
     compiler codeStoreValueOf: [ self visit: node child ] intoVariable: self retvalVar.
@@ -238,7 +241,7 @@
         compiler code: blockBody.    
     ]
 
-    "Modified: / 01-06-2015 / 23:58:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 15-06-2015 / 17:08:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 visitAndNode: node
@@ -911,3 +914,10 @@
     compiler codeReturn.
 ! !
 
+!PPCCodeGenerator class methodsFor:'documentation'!
+
+version_HG
+
+    ^ '$Changeset: <not expanded> $'
+! !
+