compiler/PPCMethod.st
changeset 391 553a5456963b
child 392 9b297f0d949c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/compiler/PPCMethod.st	Sun Oct 26 01:03:31 2014 +0000
@@ -0,0 +1,111 @@
+"{ Package: 'stx:goodies/petitparser/compiler' }"
+
+Object subclass:#PPCMethod
+	instanceVariableNames:'buffer variables indentation id profile canInline'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'PetitCompiler-Core'
+!
+
+PPCMethod comment:''
+!
+
+!PPCMethod methodsFor:'as yet unclassified'!
+
+add: string
+	self nl.
+	indentation timesRepeat: [ buffer nextPutAll: '  ' ].
+	self addOnLine: string.
+!
+
+addOnLine: string
+	buffer nextPutAll: string.
+!
+
+addVariable: name
+	variables add: name.
+!
+
+allowInline
+	canInline := true
+!
+
+body
+	^ buffer contents
+!
+
+bridge
+	^ PPCBridge on: self methodName.
+!
+
+call
+	^ 'self ', self methodName, '.'.
+!
+
+code
+	^ self methodName, String cr,  
+		self variables, String cr,
+		self profilingBegin, String cr,
+		self body, String cr
+"		self profilingEnd"
+!
+
+dedent
+	indentation := indentation - 1
+!
+
+id: value
+	id := value
+!
+
+indent 
+	indentation := indentation + 1
+!
+
+isMethod
+	^ true
+!
+
+methodName
+	^ id
+!
+
+nl
+	^ buffer nextPut: Character cr
+!
+
+profile
+	^ profile
+!
+
+profile: aBoolean
+	profile := aBoolean 
+!
+
+profilingBegin
+	self profile ifTrue: [ 
+ 		^ '  context methodInvoked: #', id, '.'	
+	].
+	^ ''
+!
+
+profilingEnd
+	self profile ifTrue: [ 
+ 		^ '  context methodFinished: #', id, '.'	
+	].
+	^ ''
+!
+
+variables
+	^ '  | ', (variables inject: '' into: [ :s :e | s, ' ', e]), ' |'
+! !
+
+!PPCMethod methodsFor:'initialization'!
+
+initialize
+	buffer := WriteStream on: ''.
+	indentation := 1.
+	variables := OrderedCollection new.
+	canInline := false
+! !
+