compiler/PPCMethod.st
changeset 453 bd5107faf4d6
parent 448 02db0b67ed3f
parent 452 9f4558b3be66
child 460 87a3d30ab570
equal deleted inserted replaced
451:989570319d14 453:bd5107faf4d6
    16     "return an initialized instance"
    16     "return an initialized instance"
    17 
    17 
    18     ^ self basicNew initialize.
    18     ^ self basicNew initialize.
    19 ! !
    19 ! !
    20 
    20 
       
    21 !PPCMethod methodsFor:'accessing'!
       
    22 
       
    23 body
       
    24     ^ buffer contents
       
    25 !
       
    26 
       
    27 bridge
       
    28     ^ PPCBridge on: self methodName.
       
    29 !
       
    30 
       
    31 code
       
    32     ^ self methodName, Character cr asString,  
       
    33         self variables, Character cr asString,
       
    34         self profilingBegin, Character cr asString,
       
    35         self body, Character cr asString
       
    36 "               self profilingEnd"
       
    37 
       
    38     "Modified: / 23-04-2015 / 19:26:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    39 !
       
    40 
       
    41 id: value
       
    42     id := value
       
    43 !
       
    44 
       
    45 methodName
       
    46     ^ id
       
    47 !
       
    48 
       
    49 profile
       
    50     ^ profile
       
    51 !
       
    52 
       
    53 profile: aBoolean
       
    54     profile := aBoolean 
       
    55 ! !
       
    56 
    21 !PPCMethod methodsFor:'as yet unclassified'!
    57 !PPCMethod methodsFor:'as yet unclassified'!
    22 
    58 
    23 add: string
    59 add: string
    24 	self nl.
    60     self nl.
    25 	indentation timesRepeat: [ buffer nextPut: Character tab  ].
    61     indentation timesRepeat: [ buffer nextPut: Character tab  ].
    26 	self addOnLine: string.
    62     self addOnLine: string.
    27 !
    63 !
    28 
    64 
    29 addOnLine: string
    65 addOnLine: string
    30 	buffer nextPutAll: string.
    66     buffer nextPutAll: string.
    31 !
    67 !
       
    68 
       
    69 call
       
    70     ^ 'self ', self methodName, '.'.
       
    71 !
       
    72 
       
    73 nl
       
    74     ^ buffer nextPut: Character cr
       
    75 !
       
    76 
       
    77 profilingBegin
       
    78     self profile ifTrue: [ 
       
    79  		^ '  context methodInvoked: #', id, '.'	
       
    80     ].
       
    81     ^ ''
       
    82 !
       
    83 
       
    84 profilingEnd
       
    85     self profile ifTrue: [ 
       
    86  		^ '  context methodFinished: #', id, '.'	
       
    87     ].
       
    88     ^ ''
       
    89 ! !
       
    90 
       
    91 !PPCMethod methodsFor:'code generation - variables'!
    32 
    92 
    33 addVariable: name
    93 addVariable: name
    34     <resource: #obsolete>
    94     (variables includes: name) ifTrue:[ 
    35     self obsoleteFeatureWarning:'Use #allocateTemporaryVariableNamed: instead'.
    95         self error:'Duplicate variable name, must rename'.
    36     self error: 'Should no longer be used'
    96     ].
    37 
    97     variables add: name.
    38     "Modified: / 02-05-2015 / 06:49:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    98 
    39 !
    99     "Modified: / 23-04-2015 / 12:29:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    40 
   100 !
    41 body
       
    42 	^ buffer contents
       
    43 !
       
    44 
       
    45 bridge
       
    46 	^ PPCBridge on: self methodName.
       
    47 !
       
    48 
       
    49 call
       
    50 	^ 'self ', self methodName, '.'.
       
    51 !
       
    52 
       
    53 code
       
    54 	^ self methodName, Character cr asString,  
       
    55 		self variables, Character cr asString,
       
    56 		self profilingBegin, Character cr asString,
       
    57 		self body, Character cr asString
       
    58 "               self profilingEnd"
       
    59 
       
    60     "Modified: / 23-04-2015 / 19:26:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    61 !
       
    62 
       
    63 dedent
       
    64 	indentation := indentation - 1
       
    65 !
       
    66 
       
    67 id: value
       
    68 	id := value
       
    69 !
       
    70 
       
    71 indent 
       
    72 	indentation := indentation + 1
       
    73 !
       
    74 
       
    75 isInline
       
    76 	^ false
       
    77 !
       
    78 
       
    79 isMethod
       
    80 	^ true
       
    81 !
       
    82 
       
    83 methodName
       
    84 	^ id
       
    85 !
       
    86 
       
    87 nl
       
    88 	^ buffer nextPut: Character cr
       
    89 !
       
    90 
       
    91 profile
       
    92 	^ profile
       
    93 !
       
    94 
       
    95 profile: aBoolean
       
    96 	profile := aBoolean 
       
    97 !
       
    98 
       
    99 profilingBegin
       
   100 	self profile ifTrue: [ 
       
   101  		^ '  context methodInvoked: #', id, '.'	
       
   102 	].
       
   103 	^ ''
       
   104 !
       
   105 
       
   106 profilingEnd
       
   107 	self profile ifTrue: [ 
       
   108  		^ '  context methodFinished: #', id, '.'	
       
   109 	].
       
   110 	^ ''
       
   111 !
       
   112 
       
   113 returnVariable
       
   114     ^  variableForReturn
       
   115 
       
   116     "Created: / 23-04-2015 / 20:50:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   117 !
       
   118 
       
   119 returnVariable: aString
       
   120     ^ variableForReturn := aString
       
   121 
       
   122     "Created: / 23-04-2015 / 18:23:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   123     "Modified: / 23-04-2015 / 21:08:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   124 !
       
   125 
       
   126 variables
       
   127 	^ '  | ', (variables inject: '' into: [ :s :e | s, ' ', e]), ' |'
       
   128 ! !
       
   129 
       
   130 !PPCMethod methodsFor:'code generation - variables'!
       
   131 
   101 
   132 allocateReturnVariable
   102 allocateReturnVariable
   133     
   103     
   134 	^ variableForReturn isNil ifTrue:[ 
   104 	^ variableForReturn isNil ifTrue:[ 
   135 		variableForReturn := self allocateTemporaryVariableNamed: 'retval'  
   105 		variableForReturn := self allocateTemporaryVariableNamed: 'retval'  
   154 	variables add:name.
   124 	variables add:name.
   155 	^ name
   125 	^ name
   156     ].
   126     ].
   157 
   127 
   158     "Created: / 23-04-2015 / 17:37:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   128     "Created: / 23-04-2015 / 17:37:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   129 !
       
   130 
       
   131 returnVariable
       
   132     ^  variableForReturn
       
   133 
       
   134     "Created: / 23-04-2015 / 20:50:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   135 !
       
   136 
       
   137 returnVariable: aString
       
   138     ^ variableForReturn := aString
       
   139 
       
   140     "Created: / 23-04-2015 / 18:23:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   141     "Modified: / 23-04-2015 / 21:08:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   142 !
       
   143 
       
   144 variables
       
   145     ^ '  | ', (variables inject: '' into: [ :s :e | s, ' ', e]), ' |'
       
   146 ! !
       
   147 
       
   148 !PPCMethod methodsFor:'indentation'!
       
   149 
       
   150 dedent
       
   151     indentation := indentation - 1
       
   152 !
       
   153 
       
   154 indent 
       
   155     indentation := indentation + 1
       
   156 !
       
   157 
       
   158 indentationLevel
       
   159     ^ indentation
       
   160 !
       
   161 
       
   162 indentationLevel: value
       
   163     indentation := value
   159 ! !
   164 ! !
   160 
   165 
   161 !PPCMethod methodsFor:'initialization'!
   166 !PPCMethod methodsFor:'initialization'!
   162 
   167 
   163 initialize
   168 initialize
   164 	buffer := WriteStream on: ''.
   169     buffer := WriteStream on: ''.
   165 	indentation := 1.
   170     indentation := 1.
   166 	variables := OrderedCollection new.
   171     variables := OrderedCollection new.
   167 ! !
   172 ! !
   168 
   173 
   169 !PPCMethod methodsFor:'printing & storing'!
   174 !PPCMethod methodsFor:'printing'!
   170 
   175 
   171 printOn:aStream
   176 printOn:aStream
   172     "append a printed representation if the receiver to the argument, aStream"
   177     "append a printed representation if the receiver to the argument, aStream"
   173 
   178 
   174     super printOn:aStream.
   179     super printOn:aStream.
   176     id printOn:aStream.
   181     id printOn:aStream.
   177 
   182 
   178     "Modified: / 23-04-2015 / 12:32:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   183     "Modified: / 23-04-2015 / 12:32:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   179 ! !
   184 ! !
   180 
   185 
       
   186 !PPCMethod methodsFor:'testing'!
       
   187 
       
   188 isInline
       
   189     ^ false
       
   190 !
       
   191 
       
   192 isMethod
       
   193     ^ true
       
   194 ! !
       
   195 
   181 !PPCMethod class methodsFor:'documentation'!
   196 !PPCMethod class methodsFor:'documentation'!
   182 
   197 
   183 version_HG
   198 version_HG
   184 
   199 
   185     ^ '$Changeset: <not expanded> $'
   200     ^ '$Changeset: <not expanded> $'