compiler/PPCMethod.st
changeset 477 b18b6cc7aabc
parent 468 3cbcf5839693
child 478 711c8bc1ec04
--- a/compiler/PPCMethod.st	Fri May 29 07:25:31 2015 +0100
+++ b/compiler/PPCMethod.st	Mon Jun 01 22:02:17 2015 +0100
@@ -3,11 +3,10 @@
 "{ NameSpace: Smalltalk }"
 
 Object subclass:#PPCMethod
-	instanceVariableNames:'buffer variables indentation id profile variableForReturn
-		category'
+	instanceVariableNames:'buffer id variableForReturn category'
 	classVariableNames:''
 	poolDictionaries:''
-	category:'PetitCompiler-Core'
+	category:'PetitCompiler-Compiler-Codegen'
 !
 
 
@@ -41,57 +40,52 @@
 !
 
 code
-    ^ self methodName, Character cr asString,  
-        self variables, Character cr asString,
-        self profilingBegin, Character cr asString,
-        self body, Character cr asString
-"               self profilingEnd"
+    ^ String streamContents: [ :s |
+        s nextPutAll: self methodName; cr.
+        buffer codeOn: s.    
+    ]
 
-    "Modified: / 23-04-2015 / 19:26:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 01-06-2015 / 21:24:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 id: value
     id := value
 !
 
-methodName
-    ^ id
+indentationLevel
+    ^ buffer indentationLevel
+
+    "Created: / 01-06-2015 / 21:38:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-profile
-    ^ profile
+indentationLevel: anInteger
+    buffer indentationLevel: anInteger
+
+    "Created: / 01-06-2015 / 21:38:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-profile: aBoolean
-    profile := aBoolean 
+methodName
+    ^ id
 ! !
 
 !PPCMethod methodsFor:'as yet unclassified'!
 
 add: string
-    self nl.
-    ((Smalltalk respondsTo:#isSmalltalkX) and:[ Smalltalk isSmalltalkX ]) ifTrue:[ 
-        indentation * 4 timesRepeat: [ buffer nextPut: Character space  ].
-    ] ifFalse:[ 
-        indentation timesRepeat: [ buffer nextPut: Character tab  ].
-    ].
-    self addOnLine: string.
+    buffer add: string
 
-    "Modified: / 21-05-2015 / 15:42:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 01-06-2015 / 21:09:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 addOnLine: string
-    buffer nextPutAll: string.
+    buffer addOnLine: string
+
+    "Modified: / 01-06-2015 / 21:09:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 call
     ^ 'self ', self methodName, '.'.
 !
 
-nl
-    ^ buffer nextPut: Character cr
-!
-
 profilingBegin
     self profile ifTrue: [ 
  				^ '  context methodInvoked: #', id, '.'	
@@ -106,44 +100,48 @@
     ^ ''
 ! !
 
+!PPCMethod methodsFor:'code generation - indenting'!
+
+dedent
+    buffer dedent
+
+    "Created: / 01-06-2015 / 21:32:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+indent
+    buffer indent
+
+    "Created: / 01-06-2015 / 21:32:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+nl
+
+    buffer nl
+
+    "Created: / 01-06-2015 / 21:52:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !PPCMethod methodsFor:'code generation - variables'!
 
-addVariable: name
-    (variables includes: name) ifTrue:[ 
-        self error:'Duplicate variable name, must rename'.
+allocateReturnVariable    
+    ^ variableForReturn isNil ifTrue:[ 
+            variableForReturn := self allocateTemporaryVariableNamed: 'retval'  
+    ] ifFalse:[ 
+            variableForReturn
     ].
-    variables add: name.
-
-    "Modified: / 23-04-2015 / 12:29:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-allocateReturnVariable
-    
-	^ variableForReturn isNil ifTrue:[ 
-		variableForReturn := self allocateTemporaryVariableNamed: 'retval'  
-	] ifFalse:[ 
-		variableForReturn
-	].
 
     "Created: / 23-04-2015 / 18:03:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified (format): / 01-06-2015 / 21:01:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 allocateTemporaryVariableNamed:preferredName 
     "Allocate a new variable with (preferably) given name.
      Returns a real variable name that should be used."
-    
-    (variables includes:preferredName) ifFalse:[
-	variables add:preferredName.
-	^ preferredName
-    ] ifTrue:[
-	| name |
 
-	name := preferredName , '_' , (variables size + 1) printString.
-	variables add:name.
-	^ name
-    ].
+    ^ buffer allocateTemporaryVariableNamed: preferredName
 
     "Created: / 23-04-2015 / 17:37:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 01-06-2015 / 21:04:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 returnVariable
@@ -157,36 +155,14 @@
 
     "Created: / 23-04-2015 / 18:23:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 23-04-2015 / 21:08:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-variables
-    ^ '  | ', (variables inject: '' into: [ :s :e | s, ' ', e]), ' |'
-! !
-
-!PPCMethod methodsFor:'indentation'!
-
-dedent
-    indentation := indentation - 1
-!
-
-indent 
-    indentation := indentation + 1
-!
-
-indentationLevel
-    ^ indentation
-!
-
-indentationLevel: value
-    indentation := value
 ! !
 
 !PPCMethod methodsFor:'initialization'!
 
 initialize
-    buffer := WriteStream on: ''.
-    indentation := 1.
-    variables := OrderedCollection new.
+    buffer := PPCCodeBlock new.
+
+    "Modified: / 01-06-2015 / 21:33:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !PPCMethod methodsFor:'printing'!