compiler/PPCCompiler.st
changeset 460 87a3d30ab570
parent 454 a9cd5ea7cc36
parent 459 4751c407bb40
child 465 f729f6cd3c76
equal deleted inserted replaced
458:a4da1c24d84a 460:87a3d30ab570
    46 
    46 
    47 compiledParserSuperclass
    47 compiledParserSuperclass
    48     ^ compiledParserSuperclass ifNil: [ PPCompiledParser ]
    48     ^ compiledParserSuperclass ifNil: [ PPCompiledParser ]
    49 !
    49 !
    50 
    50 
       
    51 currentMethod
       
    52     ^ currentMethod 
       
    53 !
       
    54 
    51 currentNonInlineMethod
    55 currentNonInlineMethod
    52     ^ compilerStack 
    56     ^ compilerStack 
    53         detect:[:m | m isInline not ] 
    57         detect:[:m | m isInline not ] 
    54         ifNone:[ self error: 'No non-inlined method']
    58         ifNone:[ self error: 'No non-inlined method']
    55 
    59 
    65 ! !
    69 ! !
    66 
    70 
    67 !PPCCompiler methodsFor:'cleaning'!
    71 !PPCCompiler methodsFor:'cleaning'!
    68 
    72 
    69 clean: class
    73 clean: class
    70 "	Transcript crShow: 'Cleaning time: ',
    74 "	Transcript show: ('Cleaning time: ',
    71     [	
    75     [	
    72 "		self cleanGeneratedMethods: class.
    76 "		self cleanGeneratedMethods: class.
    73         self cleanInstVars: class.
    77         self cleanInstVars: class.
    74         self cleanConstants: class.
    78         self cleanConstants: class.
    75 "	] timeToRun asMilliSeconds asString, 'ms'."
    79 "	] timeToRun asMilliSeconds asString, 'ms'); cr. "
    76 !
    80 !
    77 
    81 
    78 cleanConstants: class
    82 cleanConstants: class
    79     class constants removeAll.
    83     class constants removeAll.
    80 !
    84 !
    81 
    85 
    82 cleanGeneratedMethods: class
    86 cleanGeneratedMethods: class
    83     ((Smalltalk respondsTo:#isSmalltalkX) and:[ Smalltalk isSmalltalkX ]) ifTrue:[
    87     ((Smalltalk respondsTo:#isSmalltalkX) and:[ Smalltalk isSmalltalkX ]) ifTrue:[
    84         class methodsDo: [ :mthd |
    88         class methodsDo: [ :mthd |
    85             mthd category = #generated ifTrue:[
    89             (mthd category beginsWith: 'generated') ifTrue:[
    86                 class removeSelector: mthd selector.
    90                 class removeSelector: mthd selector.
    87             ]
    91             ]
    88         ]
    92         ]
    89     ] ifFalse: [ 
    93     ] ifFalse: [ 
    90         (class allSelectorsInProtocol: #generated) do: [ :selector | 
    94         (class allProtocolsUpTo: class) do: [ :protocol |
    91             class removeSelectorSilently: selector ].
    95             (protocol beginsWith: 'generated') ifTrue: [ 
       
    96                 class removeProtocol: protocol.
       
    97             ]
       
    98         ]
    92     ]
    99     ]
    93 !
   100 !
    94 
   101 
    95 cleanInstVars: class
   102 cleanInstVars: class
    96     class class instanceVariableNames: ''.
   103     class class instanceVariableNames: ''.
   169     
   176     
   170     "TODO JK: Hack alert, whatever is magic constant!!"
   177     "TODO JK: Hack alert, whatever is magic constant!!"
   171     (variable == #whatever) ifFalse: [ 
   178     (variable == #whatever) ifFalse: [ 
   172         "Do not assign, if somebody does not care!!"
   179         "Do not assign, if somebody does not care!!"
   173         self add: variable ,' := ', code.
   180         self add: variable ,' := ', code.
   174  	] ifTrue: [ 
   181  		] ifTrue: [ 
   175         "In case code hava a side effect"
   182         "In case code hava a side effect"
   176  		self add: code	
   183  				self add: code	
   177     ]
   184     ]
   178 !
   185 !
   179 
   186 
   180 codeClearError
   187 codeClearError
   181     self add: 'self clearError.'.
   188     self add: 'self clearError.'.
   206     "Modified: / 23-04-2015 / 20:51:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   213     "Modified: / 23-04-2015 / 20:51:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   207 !
   214 !
   208 
   215 
   209 codeReturn
   216 codeReturn
   210    currentMethod isInline ifTrue: [
   217    currentMethod isInline ifTrue: [
   211 		"If inlined, the return variable already holds the value"
   218 				"If inlined, the return variable already holds the value"
   212 	] ifFalse: [
   219 		] ifFalse: [
   213 		self add: '^ ', currentMethod returnVariable  
   220 				self add: '^ ', currentMethod returnVariable  
   214    ].
   221    ].
   215 
   222 
   216     "Created: / 23-04-2015 / 18:01:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   223 	"Created: / 23-04-2015 / 18:01:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   217     "Modified: / 23-04-2015 / 20:51:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   224 	"Modified: / 23-04-2015 / 20:51:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   218 !
   225 !
   219 
   226 
   220 codeReturn: code
   227 codeReturn: code
   221     " - returns whatever is in code OR
   228     " - returns whatever is in code OR
   222       - assigns whatever is in code into the returnVariable"
   229       - assigns whatever is in code into the returnVariable"
   440     ]
   447     ]
   441 !
   448 !
   442 
   449 
   443 installMethods
   450 installMethods
   444     cache keysAndValuesDo: [ :key :method |
   451     cache keysAndValuesDo: [ :key :method |
   445         compiledParser compileSilently: method code classified: 'generated'.
   452         compiledParser compileSilently: method code classified: method category.
   446     ]
   453     ]
   447 !
   454 !
   448 
   455 
   449 installVariables
   456 installVariables
   450     | varString |
   457     | varString |