compiler/PPCFSACodeGen.st
changeset 524 f6f68d32de73
parent 515 b5316ef15274
child 529 439c4057517f
--- a/compiler/PPCFSACodeGen.st	Mon Aug 17 12:13:16 2015 +0100
+++ b/compiler/PPCFSACodeGen.st	Mon Aug 24 15:34:14 2015 +0100
@@ -3,7 +3,7 @@
 "{ NameSpace: Smalltalk }"
 
 PPCCodeGen subclass:#PPCFSACodeGen
-	instanceVariableNames:'fsa backlinkStates compiler'
+	instanceVariableNames:''
 	classVariableNames:''
 	poolDictionaries:''
 	category:'PetitCompiler-Scanner'
@@ -18,7 +18,7 @@
 !PPCFSACodeGen methodsFor:'coding'!
 
 codeAbsoluteReturn: code
-    self add: '^ ', code
+    self code: '^ ', code
 !
 
 codeAssertPeek: t
@@ -26,44 +26,43 @@
     self assert: (t isKindOf: PEGFsaTransition).
 
     (t isPredicateTransition and: [t isEOF]) ifTrue: [ 
-        self addOnLine: 'currentChar isNil'.
+        self codeOnLine: 'currentChar isNil'.
         ^ self
     ].
 
-    
     (t isPredicateTransition) ifTrue: [ 
-        self addOnLine: t predicate asString, ' value: currentChar codePoint'.
+        self codeOnLine: t predicate asString, ' value: currentChar codePoint'.
         ^ self
     ].
 
     (t isAny) ifTrue: [ 
-        self addOnLine: 'true'.
+        self codeOnLine: 'true'.
         ^ self
     ].
 
     
     (t isSingleCharacter) ifTrue: [ 
-        self addOnLine: 'currentChar == ', t character storeString.
+        self codeOnLine: 'currentChar == ', t character storeString.
         ^ self
     ].
 
     (t isNotSingleCharacter) ifTrue: [ 
-        self addOnLine: 'currentChar ~~ ', t notCharacter storeString.
+        self codeOnLine: 'currentChar ~~ ', t notCharacter storeString.
         ^ self
     ].
 
     (t isLetter) ifTrue: [ 
-        self addOnLine: 'currentChar isLetter'.
+        self codeOnLine: 'currentChar isLetter'.
         ^ self
     ].
 
     (t isWord) ifTrue: [ 
-        self addOnLine: 'currentChar isAlphaNumeric'.
+        self codeOnLine: 'currentChar isAlphaNumeric'.
         ^ self
     ].
 
     (t isDigit) ifTrue: [ 
-        self addOnLine: 'currentChar isDigit'.
+        self codeOnLine: 'currentChar isDigit'.
         ^ self
     ].
 
@@ -71,16 +70,16 @@
         | begin end |
         begin := t beginOfRange.
         end := t endOfRange.
-        self addOnLine: 'self peekBetween: ', begin asString, ' and: ', end asString.
+        self codeOnLine: 'self peekBetween: ', begin asString, ' and: ', end asString.
         ^ self
     ].
 
     
-    id := idGen cachedSuchThat: [ :e | e = t characterSet ] 
+    id := self idGen cachedSuchThat: [ :e | e = t characterSet ] 
                     ifNone: [ self idFor: t characterSet defaultName: 'characterSet' ].
     
     self addConstant: t characterSet as: id.
-    self addOnLine: '(currentChar isNotNil) and: [',  id, ' at: currentChar codePoint ]'.
+    self codeOnLine: '(currentChar isNotNil) and: [',  id, ' at: currentChar codePoint ]'.
 !
 
 codeAssertPeek: transition ifFalse: falseBlock
@@ -93,13 +92,13 @@
 !
 
 codeAssertPeek: t ifTrue: block
-    self addOnLine: '('.
+    self codeOnLine: '('.
     self codeAssertPeek: t.
-    self addOnLine: ') ifTrue: ['.
+    self codeOnLine: ') ifTrue: ['.
     self indent.
     self code: block.
     self dedent.
-    self add: ']'.
+    self code: ']'.
 !
 
 codeAssertPeek: transition orReturn: priority
@@ -130,19 +129,15 @@
 
 codeEndBlockWhileTrue
     self dedent.	
-    self add: '] whileTrue.'.
+    self code: '] whileTrue.'.
 !
 
 codeIfFalse
-    self addOnLine: ' ifFalse: ['.
+    self codeOnLine: ' ifFalse: ['.
 !
 
 codeNextChar
-    self add: 'self step.'
-!
-
-codeNl
-    self add: ''.
+    self code: 'self step.'
 !
 
 codeNlAssertPeek: characterSet
@@ -161,8 +156,12 @@
     self add: '^ self returnPriority: ', priority asString, '.'
 !
 
+codeRecordDistinctFailure: retval offset: value
+    self add: 'self recordDistinctFailure: ', retval storeString, ' offset: ', value storeString, '.'
+!
+
 codeRecordDistinctMatch: retval offset: value
-    self add: 'self recordDistinctMatch: ', retval storeString, ' offset: ', value storeString, '.'
+    self code: 'self recordDistinctMatch: ', retval storeString, ' offset: ', value storeString, '.'
 !
 
 codeRecordMatch: state priority: priority
@@ -173,32 +172,47 @@
     self add: 'self recordMatch: ', state storeString, ' priority: ', priority asString, '.'
 !
 
+codeReturn: code
+    arguments profile ifTrue:[ 
+        self codeProfileStop.
+    ].   
+    self code: '^ '.
+    self codeOnLine: code            
+!
+
 codeReturnResult
     self addOnLine: '^ self return.'
 !
 
 codeReturnResult: priority
+    self error: 'deprecated?'.
     priority isNil ifTrue: [ 
         ^ self codeReturnResult
     ].
-
+    
     self addOnLine: '^ self returnPriority: ', priority asString, '.'
 !
 
 codeStartBlock
-    self add: '['.
+    self code: '['.
     self indent.
 ! !
 
 !PPCFSACodeGen methodsFor:'coding - results'!
 
+codeRecordDistinctFailure: retval
+    self assert: retval isNil.
+    
+    self code: 'self recordDistinctFailure.'
+!
+
 codeRecordDistinctMatch: retval
-    self add: 'self recordDistinctMatch: ', retval storeString, '.'
+    self code: 'self recordDistinctMatch: ', retval storeString, '.'
 !
 
 codeRecordFailure: index
     self assert: index isInteger.
-    self add: 'self recordFailure: ', index asString, '.'
+    self code: 'self recordFailure: ', index asString, '.'
 !
 
 codeRecordMatch: retval
@@ -206,23 +220,20 @@
 !
 
 codeRecordMatch: retval offset: offset
-    self add: 'self recordMatch: ', retval storeString, ' offset: ', offset storeString, '.'
+    self code: 'self recordMatch: ', retval storeString, ' offset: ', offset storeString, '.'
 !
 
 codeReturn
-    self addOnLine: '^ self'
+    self codeOnLine: '^ self'
 !
 
 codeReturnDistinct
-    self addOnLine: '^ self returnDistinct.'
+    self codeOnLine: '^ self returnDistinct.'
 ! !
 
 !PPCFSACodeGen methodsFor:'intitialization'!
 
 initialize
     super initialize.
-    
-    compiler := PPCCodeGen new.
-    backlinkStates := IdentityDictionary new.
 ! !