compiler/PPCConfiguration.st
changeset 534 a949c4fe44df
parent 532 132d7898a2a1
child 535 a8feb0f47574
--- a/compiler/PPCConfiguration.st	Wed Aug 26 23:34:48 2015 +0100
+++ b/compiler/PPCConfiguration.st	Sat Aug 29 07:56:14 2015 +0100
@@ -31,16 +31,21 @@
 
 !PPCConfiguration methodsFor:'accessing'!
 
+context
+    ^ context
+!
+
 defaultArguments
     ^ PPCCompilationOptions default
 
     "Modified: / 24-08-2015 / 23:39:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-input: whatever
-    ir := whatever.
-    
+input: aPPParser
+    ir := aPPParser asCompilerTree.    
     self remember: (self copyTree: ir) as: #input
+
+    "Modified (format): / 29-08-2015 / 07:18:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 ir
@@ -51,55 +56,28 @@
     ir := whatever
 ! !
 
-!PPCConfiguration methodsFor:'caching'!
-
-cacheFirstSet
-    "Creates a PPCNodes from a PPParser"
-    | firstSets |
-    firstSets := ir firstSets.
-    ir allNodesDo: [ :node |
-        node firstSet: (firstSets at: node)
-    ]
-!
-
-cacheFirstSetWithProductions
-    "Creates a PPCNodes from a PPParser"
-    | firstSets |
-    firstSets := ir firstSetsSuchThat: [:e | e name isNil not ].
-    ir allNodesDo: [ :node |
-        node firstSetWithProductions: (firstSets at: node)
-    ]
-!
+!PPCConfiguration methodsFor:'accessing - defaults'!
 
-cacheFirstSetWithTokens
-    "Creates a PPCNodes from a PPParser"
-    | firstSets |
-    firstSets := ir firstSetsSuchThat: [:e | e isTerminal or: [ e isTokenNode ] ].
-    ir allNodesDo: [ :node |
-        node firstSetWithTokens: (firstSets at: node)
-    ]
-!
+defaultParserSuperclass
+    self subclassResponsibility
 
-cacheFollowSet
-    "Creates a PPCNodes from a PPParser"
-    | followSets |
-    followSets := ir followSets.
-    ir allNodesDo: [ :node |
-        node followSet: (followSets at: node)
-    ]
-!
-
-cacheFollowSetWithTokens
-    "Creates a PPCNodes from a PPParser"
-    | followSets |
-    followSets := ir followSetsSuchThat: [:e | e isTerminal or: [ e isTokenNode ] ].
-    ir allNodesDo: [ :node |
-        node followSetWithTokens: (followSets at: node)
-    ]
+    "Created: / 01-09-2015 / 08:46:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !PPCConfiguration methodsFor:'compiling'!
 
+buildClass: clazz
+    |  builder |
+    builder := PPCClassBuilder new.
+    
+    builder compiledClassName: clazz name.
+    builder compiledSuperclass: clazz superclass.
+    builder methodDictionary: clazz methodDictionary.
+    builder constants: clazz constants.
+
+    ^ builder compileClass.	
+!
+
 compile: whatever
     | time |
     self input: whatever.
@@ -116,6 +94,45 @@
     "Modified: / 17-08-2015 / 13:06:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+generateParser
+    | parserClass parserSuper rootMethod |
+
+    context options generate ifFalse:[
+        ^ self
+    ].
+    parserSuper := context options parserSuperclass.
+    parserSuper isNil ifTrue:[ 
+        parserSuper := self defaultParserSuperclass.
+    ].
+    rootMethod := context parserClass propertyAt:#rootMethod.
+    context parserClass name:context options parserName.
+    context parserClass superclass: parserSuper.
+    parserClass := self buildClass:context parserClass.
+    parserClass startSymbol:rootMethod methodName.
+    self remember:parserClass as:#parser.
+    ir := parserClass new
+
+    "Modified: / 25-08-2015 / 00:05:49 / Jan Vrany"
+    "Modified: / 01-09-2015 / 08:46:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+generateScanner
+    | scanner |
+
+    context options generate ifFalse:[
+        ^ self
+    ].
+    context scannerClass name:context options scannerName.
+    context scannerClass superclass:context options scannerSuperclass.
+    scanner := (self buildClass:context scannerClass).
+    context parserClass addConstant:scanner as:#scannerClass.
+    ir := scanner.
+    self remember:scanner as:#scanner
+
+    "Modified: / 25-08-2015 / 00:06:49 / Jan Vrany"
+    "Modified: / 26-08-2015 / 19:58:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 invokePhases
     self subclassResponsibility
 ! !
@@ -140,9 +157,11 @@
 !
 
 remember: value as: key
-    self options debug ifTrue: [ 
+    context options debug ifTrue: [ 
         history add: key -> value.
     ]
+
+    "Modified: / 28-08-2015 / 14:14:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !PPCConfiguration methodsFor:'error handling'!
@@ -168,82 +187,6 @@
     "Modified: / 26-08-2015 / 19:49:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
-!PPCConfiguration methodsFor:'phases'!
-
-cacheFirstFollow
-    context options cacheFirstFollow ifFalse:[
-        ^ self
-    ].
-    self cacheFirstSet.
-    self cacheFollowSet.
-    self cacheFirstSetWithTokens.
-    self cacheFollowSetWithTokens.
-!
-
-check
-    ir checkTree 
-!
-
-createRecognizingComponents
-    context options recognizingComponents ifFalse:[
-        ^ self
-    ].
-    self runPass: PPCRecognizerComponentDetector
-
-    "Modified: / 26-08-2015 / 22:36:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-createTokens
-    context options detectTokens ifFalse:[
-        ^ self
-    ].
-    self runPass: PPCTokenDetector
-
-    "Modified: / 26-08-2015 / 22:36:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-inline
-    context options inline ifFalse:[
-        ^ self
-    ].
-    self runPass: PPCInliningVisitor
-
-    "Modified: / 26-08-2015 / 22:36:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-merge
-    "Merge equivalent nodes under one object with single identity"
-    
-    context options merge ifFalse:[
-        ^ self
-    ].
-    self runPass: PPCMergingVisitor
-
-    "Modified: / 26-08-2015 / 22:36:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-specialize
-    context options specialize ifFalse:[
-        ^ self
-    ].
-    "
-     Invokes a visitor that creates specialized nodes
-     for some patterns of PPCNodes,
-     
-     e.g. $a astar can be represented by PPCCharacterStarNode
-    "
-   self runPass: PPCSpecializingVisitor
-
-    "Modified: / 26-08-2015 / 22:36:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-toPPCIr
-    "Creates a PPCNodes from a PPParser"
-    ir := ir asCompilerTree.
-    
-    self remember: (self copyTree: ir) as: #ppcNodes
-! !
-
 !PPCConfiguration methodsFor:'reporting'!
 
 reportTime: timeInMs
@@ -256,10 +199,14 @@
 
 !PPCConfiguration methodsFor:'running'!
 
-runPass: passClassOrAlike
-    ir := passClassOrAlike run: ir in: context.
-    self remember:(self copyTree:ir) as:passClassOrAlike name
+runPass: pass
+    | p |
+
+    p := pass asPPCPass.
+    ir := p run: ir in: context.
+    self remember:(self copyTree:ir) as:p class name
 
     "Created: / 26-08-2015 / 22:35:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 29-08-2015 / 07:16:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !