compiler/PPCCodeBlock.st
changeset 515 b5316ef15274
parent 502 1e45d3c96ec5
child 516 3b81c9e53352
--- a/compiler/PPCCodeBlock.st	Fri Jul 24 15:06:54 2015 +0100
+++ b/compiler/PPCCodeBlock.st	Mon Aug 17 12:13:16 2015 +0100
@@ -38,16 +38,9 @@
 !PPCCodeBlock methodsFor:'code generation'!
 
 code: aStringOrBlockOrRBParseNode
-    aStringOrBlockOrRBParseNode isString ifTrue:[ 
-        self emitCodeAsString: aStringOrBlockOrRBParseNode
-    ] ifFalse:[
-        (aStringOrBlockOrRBParseNode isKindOf: RBProgramNode) ifTrue:[ 
-            self emitCodeAsRBNode: aStringOrBlockOrRBParseNode.
-        ] ifFalse:[  
-            self emitCodeAsBlock: aStringOrBlockOrRBParseNode
-        ].
-    ].
-
+    self codeNl.
+    self codeOnLine: aStringOrBlockOrRBParseNode
+    
     "Created: / 01-06-2015 / 21:07:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 03-06-2015 / 05:52:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
@@ -66,6 +59,22 @@
     ].
 
     "Created: / 01-06-2015 / 22:58:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+codeNl
+    self add: ''.
+!
+
+codeOnLine: aStringOrBlockOrRBParseNode
+    aStringOrBlockOrRBParseNode isString ifTrue:[ 
+        self emitCodeAsString: aStringOrBlockOrRBParseNode
+    ] ifFalse:[
+        (aStringOrBlockOrRBParseNode isKindOf: RBProgramNode) ifTrue:[ 
+            self emitCodeAsRBNode: aStringOrBlockOrRBParseNode.
+        ] ifFalse:[  
+            self emitCodeAsBlock: aStringOrBlockOrRBParseNode
+        ].
+    ].
 ! !
 
 !PPCCodeBlock methodsFor:'code generation - variables'!
@@ -144,6 +153,38 @@
     aStream nextPutAll: buffer contents
 
     "Created: / 01-06-2015 / 21:26:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+sourceOn:aStream 
+    "Dumps generated code on given stream"
+    
+    temporaries notEmpty ifTrue:[
+        ((Smalltalk respondsTo:#isSmalltalkX) and:[ Smalltalk isSmalltalkX ]) ifTrue:[
+            indentation * 4 timesRepeat:[
+                aStream nextPut:Character space
+            ].
+        ] ifFalse:[
+            indentation timesRepeat:[
+                aStream nextPut:Character tab
+            ].
+        ].
+        aStream nextPut:$|.
+        temporaries do:[:e | 
+            aStream
+                space;
+                nextPutAll:e
+        ].
+        aStream space.
+        aStream nextPut:$|.
+        self nl.
+         "In Smalltalk/X, there should be a blank line after temporaries"
+        ((Smalltalk respondsTo:#isSmalltalkX) and:[ Smalltalk isSmalltalkX ]) ifTrue:[
+            self nl.
+        ].
+    ].
+    aStream nextPutAll:buffer contents
+
+    "Created: / 01-06-2015 / 21:26:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !PPCCodeBlock methodsFor:'private'!
@@ -170,7 +211,7 @@
 !
 
 emitCodeAsString: aString
-    buffer nextPutAll: aString
+    self addOnLine: aString
 !
 
 formatRBNode: anRBNode