compiler/TCompilerPass.st
changeset 9 569bf5707c7e
parent 8 eec72263ed75
child 11 6d39860d0fdb
equal deleted inserted replaced
8:eec72263ed75 9:569bf5707c7e
     4 
     4 
     5 TProgramNodeVisitor subclass:#TCompilerPass
     5 TProgramNodeVisitor subclass:#TCompilerPass
     6 	instanceVariableNames:'context currentClass currentMethod currentScope'
     6 	instanceVariableNames:'context currentClass currentMethod currentScope'
     7 	classVariableNames:''
     7 	classVariableNames:''
     8 	poolDictionaries:''
     8 	poolDictionaries:''
     9 	category:'Languages-Tea-Compiler'
     9 	category:'Languages-Tea-Compiler-Internals'
    10 !
    10 !
       
    11 
       
    12 !TCompilerPass class methodsFor:'running'!
       
    13 
       
    14 runOn: anObject
       
    15     ^ self new runOn: anObject
       
    16 
       
    17     "Created: / 14-09-2015 / 13:57:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    18 !
       
    19 
       
    20 runOn: anObject inContext: aTCompilerContext
       
    21     ^ self new runOn: anObject inContext: aTCompilerContext
       
    22 
       
    23     "Created: / 14-09-2015 / 13:57:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    24 !
       
    25 
       
    26 runOn: anObject inEnvironment: aTEnvironment
       
    27     ^ self new runOn: anObject inEnvironment: aTEnvironment
       
    28 
       
    29     "Created: / 14-09-2015 / 13:57:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    30 ! !
    11 
    31 
    12 !TCompilerPass methodsFor:'accessing'!
    32 !TCompilerPass methodsFor:'accessing'!
    13 
    33 
    14 context
    34 context
    15     ^ context
    35     ^ context
    20 ! !
    40 ! !
    21 
    41 
    22 !TCompilerPass methodsFor:'running'!
    42 !TCompilerPass methodsFor:'running'!
    23 
    43 
    24 run
    44 run
    25     self run: context unit
    45     self runOn: context unit
    26 
    46 
    27     "Created: / 31-08-2015 / 11:52:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    47     "Created: / 31-08-2015 / 11:52:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    48     "Modified: / 14-09-2015 / 13:54:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    28 !
    49 !
    29 
    50 
    30 run: anObject
    51 runOn: anObject
       
    52     context isNil ifTrue:[ 
       
    53         context := TCompilerContext new.
       
    54         context environment: TEnvironment new.
       
    55         context unit: anObject.
       
    56     ].
    31     anObject isRingObject 
    57     anObject isRingObject 
    32         ifTrue:[ self visitDefinition: anObject  ]
    58         ifTrue:[ self visitDefinition: anObject  ]
    33         ifFalse:[ self visitNode: anObject ]
    59         ifFalse:[ self visitNode: anObject ]
    34 
    60 
    35     "Created: / 29-08-2015 / 21:45:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    61     "Created: / 14-09-2015 / 13:54:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    62 !
       
    63 
       
    64 runOn: anObject inContext: aTCompilerContext
       
    65     self context: aTCompilerContext.
       
    66     self runOn: anObject
       
    67 
       
    68     "Created: / 14-09-2015 / 13:55:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    69 !
       
    70 
       
    71 runOn: anObject inEnvironment: aTEnvironment
       
    72     context isNil ifTrue:[ 
       
    73         context := TCompilerContext new.
       
    74         context unit: anObject.
       
    75     ].
       
    76     context environment: aTEnvironment.
       
    77     self runOn: anObject
       
    78 
       
    79     "Created: / 14-09-2015 / 13:59:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    36 ! !
    80 ! !
    37 
    81 
    38 !TCompilerPass methodsFor:'visiting'!
    82 !TCompilerPass methodsFor:'visiting'!
    39 
    83 
    40 visitDefinition: definition
    84 visitDefinition: definition
    69     aTCompilationUnitDefinition classes do:[:class |
   113     aTCompilationUnitDefinition classes do:[:class |
    70         self visitDefinition: class.
   114         self visitDefinition: class.
    71     ].
   115     ].
    72 
   116 
    73     "Created: / 14-09-2015 / 10:31:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   117     "Created: / 14-09-2015 / 10:31:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   118 !
       
   119 
       
   120 acceptIfTrueIfFalseNode: node 
       
   121     self acceptMessageNode: node
       
   122 
       
   123     "Created: / 14-09-2015 / 14:09:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   124 !
       
   125 
       
   126 acceptIfTrueNode: node
       
   127     self acceptMessageNode: node
       
   128 
       
   129     "Created: / 14-09-2015 / 14:09:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    74 !
   130 !
    75 
   131 
    76 acceptInlineAssemblyNode: aMethodNode
   132 acceptInlineAssemblyNode: aMethodNode
    77 
   133 
    78     "Created: / 02-09-2015 / 07:03:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   134     "Created: / 02-09-2015 / 07:03:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   110     ] ifFalse:[ 
   166     ] ifFalse:[ 
   111         self visitNode: aMethodNode body
   167         self visitNode: aMethodNode body
   112     ].
   168     ].
   113 
   169 
   114     "Created: / 02-09-2015 / 07:16:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   170     "Created: / 02-09-2015 / 07:16:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   171 !
       
   172 
       
   173 acceptSpecialFormNode:aTSpecialFormNode 
       
   174     aTSpecialFormNode selector = #ifTrue: ifTrue:[
       
   175         ^ self acceptIfTrueNode:aTSpecialFormNode.
       
   176     ].
       
   177     aTSpecialFormNode selector = #ifTrue:ifFalse: ifTrue:[
       
   178         ^ self acceptIfTrueIfFalseNode:aTSpecialFormNode.
       
   179     ].
       
   180     aTSpecialFormNode selector = #whileTrue: ifTrue:[
       
   181         ^ self acceptWhileTrueNode:aTSpecialFormNode.
       
   182     ].
       
   183     ^ self error:'Unsupported special form: #' , aTSpecialFormNode selector
       
   184 
       
   185     "Created: / 14-09-2015 / 14:09:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   186 !
       
   187 
       
   188 acceptWhileTrueNode: node
       
   189     self acceptMessageNode: node
       
   190 
       
   191     "Created: / 14-09-2015 / 14:09:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   115 ! !
   192 ! !
   116 
   193