compiler/PPCMethod.st
changeset 453 bd5107faf4d6
parent 448 02db0b67ed3f
parent 452 9f4558b3be66
child 460 87a3d30ab570
--- a/compiler/PPCMethod.st	Tue May 05 16:25:23 2015 +0200
+++ b/compiler/PPCMethod.st	Sun May 10 06:46:56 2015 +0100
@@ -18,117 +18,87 @@
     ^ self basicNew initialize.
 ! !
 
-!PPCMethod methodsFor:'as yet unclassified'!
-
-add: string
-	self nl.
-	indentation timesRepeat: [ buffer nextPut: Character tab  ].
-	self addOnLine: string.
-!
-
-addOnLine: string
-	buffer nextPutAll: string.
-!
-
-addVariable: name
-    <resource: #obsolete>
-    self obsoleteFeatureWarning:'Use #allocateTemporaryVariableNamed: instead'.
-    self error: 'Should no longer be used'
-
-    "Modified: / 02-05-2015 / 06:49:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
+!PPCMethod methodsFor:'accessing'!
 
 body
-	^ buffer contents
+    ^ buffer contents
 !
 
 bridge
-	^ PPCBridge on: self methodName.
-!
-
-call
-	^ 'self ', self methodName, '.'.
+    ^ PPCBridge on: self methodName.
 !
 
 code
-	^ self methodName, Character cr asString,  
-		self variables, Character cr asString,
-		self profilingBegin, Character cr asString,
-		self body, Character cr asString
+    ^ self methodName, Character cr asString,  
+        self variables, Character cr asString,
+        self profilingBegin, Character cr asString,
+        self body, Character cr asString
 "               self profilingEnd"
 
     "Modified: / 23-04-2015 / 19:26:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-dedent
-	indentation := indentation - 1
-!
-
 id: value
-	id := value
-!
-
-indent 
-	indentation := indentation + 1
-!
-
-isInline
-	^ false
-!
-
-isMethod
-	^ true
+    id := value
 !
 
 methodName
-	^ id
-!
-
-nl
-	^ buffer nextPut: Character cr
+    ^ id
 !
 
 profile
-	^ profile
+    ^ profile
 !
 
 profile: aBoolean
-	profile := aBoolean 
+    profile := aBoolean 
+! !
+
+!PPCMethod methodsFor:'as yet unclassified'!
+
+add: string
+    self nl.
+    indentation timesRepeat: [ buffer nextPut: Character tab  ].
+    self addOnLine: string.
+!
+
+addOnLine: string
+    buffer nextPutAll: string.
+!
+
+call
+    ^ 'self ', self methodName, '.'.
+!
+
+nl
+    ^ buffer nextPut: Character cr
 !
 
 profilingBegin
-	self profile ifTrue: [ 
+    self profile ifTrue: [ 
  		^ '  context methodInvoked: #', id, '.'	
-	].
-	^ ''
+    ].
+    ^ ''
 !
 
 profilingEnd
-	self profile ifTrue: [ 
+    self profile ifTrue: [ 
  		^ '  context methodFinished: #', id, '.'	
-	].
-	^ ''
-!
-
-returnVariable
-    ^  variableForReturn
-
-    "Created: / 23-04-2015 / 20:50:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-returnVariable: aString
-    ^ variableForReturn := aString
-
-    "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:'code generation - variables'!
 
+addVariable: name
+    (variables includes: name) ifTrue:[ 
+        self error:'Duplicate variable name, must rename'.
+    ].
+    variables add: name.
+
+    "Modified: / 23-04-2015 / 12:29:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 allocateReturnVariable
     
 	^ variableForReturn isNil ifTrue:[ 
@@ -156,17 +126,52 @@
     ].
 
     "Created: / 23-04-2015 / 17:37:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+returnVariable
+    ^  variableForReturn
+
+    "Created: / 23-04-2015 / 20:50:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+returnVariable: aString
+    ^ variableForReturn := aString
+
+    "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 := WriteStream on: ''.
+    indentation := 1.
+    variables := OrderedCollection new.
 ! !
 
-!PPCMethod methodsFor:'printing & storing'!
+!PPCMethod methodsFor:'printing'!
 
 printOn:aStream
     "append a printed representation if the receiver to the argument, aStream"
@@ -178,6 +183,16 @@
     "Modified: / 23-04-2015 / 12:32:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!PPCMethod methodsFor:'testing'!
+
+isInline
+    ^ false
+!
+
+isMethod
+    ^ true
+! !
+
 !PPCMethod class methodsFor:'documentation'!
 
 version_HG