compiler/PPCCompiler.st
changeset 477 b18b6cc7aabc
parent 476 c45383095de4
child 478 711c8bc1ec04
equal deleted inserted replaced
476:c45383095de4 477:b18b6cc7aabc
   131 
   131 
   132 addOnLine: string
   132 addOnLine: string
   133     currentMethod addOnLine: string.
   133     currentMethod addOnLine: string.
   134 !
   134 !
   135 
   135 
   136 addVariable: name
       
   137     ^ self currentNonInlineMethod addVariable: name
       
   138 
       
   139     "Modified: / 23-04-2015 / 17:34:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   140 !
       
   141 
       
   142 call: anotherMethod
   136 call: anotherMethod
   143     currentMethod add: anotherMethod call.
   137     currentMethod add: anotherMethod call.
   144 !
   138 !
   145 
   139 
   146 callOnLine: anotherMethod
   140 callOnLine: anotherMethod
   250 
   244 
   251     "Created: / 23-04-2015 / 18:01:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   245     "Created: / 23-04-2015 / 18:01:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   252     "Modified: / 23-04-2015 / 20:51:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   246     "Modified: / 23-04-2015 / 20:51:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   253 !
   247 !
   254 
   248 
       
   249 codeProfileStart
       
   250     self add: 'context methodInvoked: #', currentMethod methodName, '.'
       
   251 
       
   252     "Created: / 01-06-2015 / 21:17:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   253 !
       
   254 
       
   255 codeProfileStop
       
   256     self add: 'context methodFinished: #', currentMethod methodName, '.'
       
   257 
       
   258     "Created: / 01-06-2015 / 21:19:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   259 !
       
   260 
   255 codeReturn
   261 codeReturn
   256    currentMethod isInline ifTrue: [
   262    currentMethod isInline ifTrue: [
   257 				"If inlined, the return variable already holds the value"
   263         "If inlined, the return variable already holds the value"
   258 		] ifFalse: [
   264     ] ifFalse: [
   259 				self add: '^ ', currentMethod returnVariable  
   265         arguments profile ifTrue:[ 
   260    ].
   266             self codeProfileStop.
   261 
   267         ]. 
   262 	"Created: / 23-04-2015 / 18:01:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   268         self add: '^ ', currentMethod returnVariable  
   263 	"Modified: / 23-04-2015 / 20:51:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   269     ].
       
   270 
       
   271     "Created: / 23-04-2015 / 18:01:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   272     "Modified: / 01-06-2015 / 21:49:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   264 !
   273 !
   265 
   274 
   266 codeReturn: code
   275 codeReturn: code
   267     " - returns whatever is in code OR
   276     " - returns whatever is in code OR
   268       - assigns whatever is in code into the returnVariable"
   277       - assigns whatever is in code into the returnVariable"
   269    currentMethod isInline ifTrue:[ 
   278     currentMethod isInline ifTrue:[
   270         self codeEvaluateAndAssign: code to: currentMethod returnVariable. 
   279         self codeEvaluateAndAssign: code to: currentMethod returnVariable. 
   271    ] ifFalse: [ 
   280     ] ifFalse: [ 
   272         self add: '^ ', code 		
   281         arguments profile ifTrue:[ 
       
   282             self codeProfileStop.
       
   283         ].   
       
   284         self add: '^ ', code            
   273     ]
   285     ]
   274 
   286 
   275     "Created: / 23-04-2015 / 18:01:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   287     "Created: / 23-04-2015 / 18:01:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   276     "Modified: / 23-04-2015 / 20:51:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   288     "Modified: / 01-06-2015 / 21:48:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   277 !
   289 !
   278 
   290 
   279 codeStoreValueOf: aBlock intoVariable: aString
   291 codeStoreValueOf: aBlock intoVariable: aString
   280     | tmpVarirable method |
   292     | tmpVarirable method |
   281     self assert: aBlock isBlock.
   293     self assert: aBlock isBlock.
   425     (cache includesKey: id) ifTrue: [ self error: 'OOOUPS!!' ].
   437     (cache includesKey: id) ifTrue: [ self error: 'OOOUPS!!' ].
   426     indentationLevel := currentMethod indentationLevel.
   438     indentationLevel := currentMethod indentationLevel.
   427     
   439     
   428     currentMethod := PPCInlinedMethod new.
   440     currentMethod := PPCInlinedMethod new.
   429     currentMethod id: id.   
   441     currentMethod id: id.   
   430     currentMethod profile: arguments profile.
       
   431     currentMethod returnVariable: returnVariable.
   442     currentMethod returnVariable: returnVariable.
   432     currentMethod indentationLevel: indentationLevel.
   443     currentMethod indentationLevel: indentationLevel.
   433     self push.
   444     self push.
   434 
   445 
   435     "Modified: / 23-04-2015 / 18:28:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   446     "Modified: / 01-06-2015 / 21:48:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   436 !
   447 !
   437 
   448 
   438 startMethod: id
   449 startMethod: id
   439     (cache includesKey: id) ifTrue: [ self error: 'OOOUPS!!' ].
   450     (cache includesKey: id) ifTrue: [ self error: 'OOOUPS!!' ].
   440 
   451 
   441     currentMethod := PPCMethod new.
   452     currentMethod := PPCMethod new.
   442     currentMethod id: id.
   453     currentMethod id: id.
   443     currentMethod profile: arguments profile.    
   454     arguments profile ifTrue:[ 
       
   455         self codeProfileStart.
       
   456     ].
   444     self push.      
   457     self push.      
   445                 
   458                 
   446     self cache: id as: currentMethod.
   459     self cache: id as: currentMethod.
   447 
   460 
   448     "Modified: / 23-04-2015 / 18:36:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   461     "Modified: / 01-06-2015 / 21:19:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   449 !
   462 !
   450 
   463 
   451 stopInline
   464 stopInline
   452 
       
   453     ^ self pop.
   465     ^ self pop.
   454 
   466 
   455     "Modified: / 23-04-2015 / 18:28:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   467     "Modified: / 01-06-2015 / 21:37:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   456 !
   468 !
   457 
   469 
   458 stopMethod
   470 stopMethod
   459     self cache: currentMethod methodName as: currentMethod.
   471    self cache: currentMethod methodName as: currentMethod.
   460     
   472     
   461     "arguments profile ifTrue: [ Transcript show: currentMethod code; cr. ]."
   473     "arguments profile ifTrue: [ Transcript show: currentMethod code; cr. ]."
   462     ^ self pop.
   474     ^ self pop.
   463 
   475 
   464     "Modified: / 01-05-2015 / 14:18:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   476     "Modified: / 01-06-2015 / 21:38:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   465 !
   477 !
   466 
   478 
   467 top
   479 top
   468     ^ compilerStack top
   480     ^ compilerStack top
   469 ! !
   481 ! !