40 ! |
45 ! |
41 |
46 |
42 code |
47 code |
43 ^ String streamContents: [ :s | |
48 ^ String streamContents: [ :s | |
44 s nextPutAll: self methodName; cr. |
49 s nextPutAll: self methodName; cr. |
45 buffer codeOn: s. |
50 source codeOn: s. |
46 ] |
51 ] |
47 |
52 |
48 "Modified: / 01-06-2015 / 21:24:47 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
53 "Modified: / 01-06-2015 / 21:24:47 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
49 ! |
54 ! |
50 |
55 |
51 id: value |
56 id: value |
52 id := value |
57 selector := value |
53 ! |
58 ! |
54 |
59 |
55 indentationLevel |
60 indentationLevel |
56 ^ buffer indentationLevel |
61 ^ source indentationLevel |
57 |
62 |
58 "Created: / 01-06-2015 / 21:38:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
63 "Created: / 01-06-2015 / 21:38:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
59 ! |
64 ! |
60 |
65 |
61 indentationLevel: anInteger |
66 indentationLevel: anInteger |
62 buffer indentationLevel: anInteger |
67 source indentationLevel: anInteger |
63 |
68 |
64 "Created: / 01-06-2015 / 21:38:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
69 "Created: / 01-06-2015 / 21:38:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
65 ! |
70 ! |
66 |
71 |
67 methodName |
72 methodName |
68 ^ id |
73 ^ selector |
69 ! |
74 ! |
70 |
75 |
71 profile |
76 profile |
|
77 self error: 'Should no longer be used'. |
|
78 " |
72 ^ profile |
79 ^ profile |
|
80 " |
|
81 |
|
82 "Modified: / 17-08-2015 / 11:58:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
73 ! |
83 ! |
74 |
84 |
75 profile: aBoolean |
85 profile: aBoolean |
|
86 self error: 'Should no longer be used'. |
|
87 " |
76 profile := aBoolean |
88 profile := aBoolean |
|
89 " |
|
90 |
|
91 "Modified: / 17-08-2015 / 11:58:46 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
92 ! |
|
93 |
|
94 source |
|
95 ^ source isString ifTrue:[ |
|
96 source |
|
97 ] ifFalse:[ |
|
98 String streamContents: [ :s | |
|
99 s nextPutAll: self methodName; cr. |
|
100 source sourceOn:s. |
|
101 ] |
|
102 ]. |
|
103 |
|
104 "Created: / 24-07-2015 / 19:46:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
105 ! |
|
106 |
|
107 source: aString |
|
108 source := aString |
|
109 |
|
110 "Created: / 24-07-2015 / 19:48:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
77 ! ! |
111 ! ! |
78 |
112 |
79 !PPCMethod methodsFor:'as yet unclassified'! |
113 !PPCMethod methodsFor:'as yet unclassified'! |
80 |
114 |
81 add: string |
115 add: string |
82 buffer add: string |
116 source add: string |
83 |
117 |
84 "Modified: / 01-06-2015 / 21:09:06 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
118 "Modified: / 01-06-2015 / 21:09:06 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
85 ! |
119 ! |
86 |
120 |
87 addOnLine: string |
121 addOnLine: string |
88 buffer addOnLine: string |
122 source addOnLine: string |
89 |
123 |
90 "Modified: / 01-06-2015 / 21:09:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
124 "Modified: / 01-06-2015 / 21:09:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
91 ! |
125 ! |
92 |
126 |
93 call |
127 call |
94 ^ 'self ', self methodName, '.'. |
128 ^ 'self ', self methodName, '.'. |
95 ! |
129 ! |
96 |
130 |
|
131 callOn: receiver |
|
132 ^ receiver, ' ', self methodName. |
|
133 ! |
|
134 |
97 profilingBegin |
135 profilingBegin |
98 self profile ifTrue: [ |
136 self profile ifTrue: [ |
99 ^ ' context methodInvoked: #', id, '.' |
137 ^ ' context methodInvoked: #', selector, '.' |
100 ]. |
138 ]. |
101 ^ '' |
139 ^ '' |
102 ! |
140 ! |
103 |
141 |
104 profilingEnd |
142 profilingEnd |
105 self profile ifTrue: [ |
143 self profile ifTrue: [ |
106 ^ ' context methodFinished: #', id, '.' |
144 ^ ' context methodFinished: #', selector, '.' |
107 ]. |
145 ]. |
108 ^ '' |
146 ^ '' |
109 ! ! |
147 ! ! |
110 |
148 |
111 !PPCMethod methodsFor:'code generation'! |
149 !PPCMethod methodsFor:'code generation'! |
112 |
150 |
113 code: aStringOrBlockOrRBParseNode |
151 code: aStringOrBlockOrRBParseNode |
114 buffer code: aStringOrBlockOrRBParseNode. |
152 source code: aStringOrBlockOrRBParseNode. |
115 |
153 |
116 "Created: / 01-06-2015 / 22:31:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
154 "Created: / 01-06-2015 / 22:31:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
117 "Modified (format): / 01-06-2015 / 23:50:26 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
155 "Modified (format): / 01-06-2015 / 23:50:26 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
118 ! |
156 ! |
119 |
157 |
120 codeBlock: contents |
158 codeBlock: contents |
121 | outerBlock innerBlock | |
159 | outerBlock innerBlock | |
122 |
160 |
123 outerBlock := buffer. |
161 outerBlock := source. |
124 innerBlock := PPCCodeBlock new. |
162 innerBlock := PPCCodeBlock new. |
125 innerBlock indentationLevel: outerBlock indentationLevel + 1. |
163 innerBlock indentationLevel: outerBlock indentationLevel + 1. |
126 [ |
164 [ |
127 outerBlock addOnLine:'['. |
165 outerBlock addOnLine:'['. |
128 buffer := innerBlock. |
166 source := innerBlock. |
129 self code: contents. |
167 self codeOnLine: contents. |
130 ] ensure:[ |
168 ] ensure:[ |
131 outerBlock |
169 outerBlock |
132 code: (String streamContents:[:s | innerBlock codeOn: s]); |
170 code: (String streamContents:[:s | innerBlock sourceOn:s]); |
133 add:']'. |
171 add:']'. |
134 buffer := outerBlock. |
172 source := outerBlock. |
135 ] |
173 ] |
136 |
174 |
137 "Created: / 01-06-2015 / 22:33:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
175 "Created: / 01-06-2015 / 22:33:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
138 "Modified: / 03-06-2015 / 06:11:32 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
176 "Modified: / 03-06-2015 / 06:11:32 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
177 ! |
|
178 |
|
179 codeOnLine: aStringOrBlockOrRBParseNode |
|
180 source codeOnLine: aStringOrBlockOrRBParseNode. |
|
181 |
|
182 "Created: / 01-06-2015 / 22:31:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
183 "Modified (format): / 01-06-2015 / 23:50:26 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
139 ! ! |
184 ! ! |
140 |
185 |
141 !PPCMethod methodsFor:'code generation - indenting'! |
186 !PPCMethod methodsFor:'code generation - indenting'! |
142 |
187 |
143 dedent |
188 dedent |
144 buffer dedent |
189 source dedent |
145 |
190 |
146 "Created: / 01-06-2015 / 21:32:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
191 "Created: / 01-06-2015 / 21:32:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
147 ! |
192 ! |
148 |
193 |
149 indent |
194 indent |
150 buffer indent |
195 source indent |
151 |
196 |
152 "Created: / 01-06-2015 / 21:32:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
197 "Created: / 01-06-2015 / 21:32:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
153 ! |
198 ! |
154 |
199 |
155 nl |
200 nl |
156 |
201 |
157 buffer nl |
202 source nl |
158 |
203 |
159 "Created: / 01-06-2015 / 21:52:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
204 "Created: / 01-06-2015 / 21:52:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
160 ! ! |
205 ! ! |
161 |
206 |
162 !PPCMethod methodsFor:'code generation - variables'! |
207 !PPCMethod methodsFor:'code generation - variables'! |
|
208 |
|
209 addVariable: name |
|
210 self error: 'Should no longer be used' |
|
211 " |
|
212 (variables includes: name) ifTrue:[ |
|
213 self error:'Duplicate variable name, must rename'. |
|
214 ]. |
|
215 variables add: name. |
|
216 " |
|
217 |
|
218 "Modified: / 17-08-2015 / 11:56:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
219 ! |
163 |
220 |
164 allocateReturnVariable |
221 allocateReturnVariable |
165 |
222 |
166 ^ variableForReturn isNil ifTrue:[ |
223 ^ variableForReturn isNil ifTrue:[ |
167 variableForReturn := self allocateTemporaryVariableNamed: 'retval' |
224 variableForReturn := self allocateTemporaryVariableNamed: 'retval' |