36 ! ! |
36 ! ! |
37 |
37 |
38 !PPCCodeBlock methodsFor:'code generation'! |
38 !PPCCodeBlock methodsFor:'code generation'! |
39 |
39 |
40 code: aStringOrBlockOrRBParseNode |
40 code: aStringOrBlockOrRBParseNode |
|
41 self codeNl. |
|
42 self codeOnLine: aStringOrBlockOrRBParseNode |
|
43 |
|
44 "Created: / 01-06-2015 / 21:07:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
45 "Modified: / 03-06-2015 / 05:52:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
46 ! |
|
47 |
|
48 codeIndent |
|
49 self codeIndent:indentation |
|
50 |
|
51 "Created: / 01-06-2015 / 22:58:00 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
52 ! |
|
53 |
|
54 codeIndent: level |
|
55 ((Smalltalk respondsTo:#isSmalltalkX) and:[ Smalltalk isSmalltalkX ]) ifTrue:[ |
|
56 level * 4 timesRepeat: [ buffer nextPut: Character space ]. |
|
57 ] ifFalse:[ |
|
58 level timesRepeat: [ buffer nextPut: Character tab ]. |
|
59 ]. |
|
60 |
|
61 "Created: / 01-06-2015 / 22:58:07 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
62 ! |
|
63 |
|
64 codeNl |
|
65 self add: ''. |
|
66 ! |
|
67 |
|
68 codeOnLine: aStringOrBlockOrRBParseNode |
41 aStringOrBlockOrRBParseNode isString ifTrue:[ |
69 aStringOrBlockOrRBParseNode isString ifTrue:[ |
42 self emitCodeAsString: aStringOrBlockOrRBParseNode |
70 self emitCodeAsString: aStringOrBlockOrRBParseNode |
43 ] ifFalse:[ |
71 ] ifFalse:[ |
44 (aStringOrBlockOrRBParseNode isKindOf: RBProgramNode) ifTrue:[ |
72 (aStringOrBlockOrRBParseNode isKindOf: RBProgramNode) ifTrue:[ |
45 self emitCodeAsRBNode: aStringOrBlockOrRBParseNode. |
73 self emitCodeAsRBNode: aStringOrBlockOrRBParseNode. |
46 ] ifFalse:[ |
74 ] ifFalse:[ |
47 self emitCodeAsBlock: aStringOrBlockOrRBParseNode |
75 self emitCodeAsBlock: aStringOrBlockOrRBParseNode |
48 ]. |
76 ]. |
49 ]. |
77 ]. |
50 |
|
51 "Created: / 01-06-2015 / 21:07:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
52 "Modified: / 03-06-2015 / 05:52:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
53 ! |
|
54 |
|
55 codeIndent |
|
56 self codeIndent:indentation |
|
57 |
|
58 "Created: / 01-06-2015 / 22:58:00 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
59 ! |
|
60 |
|
61 codeIndent: level |
|
62 ((Smalltalk respondsTo:#isSmalltalkX) and:[ Smalltalk isSmalltalkX ]) ifTrue:[ |
|
63 level * 4 timesRepeat: [ buffer nextPut: Character space ]. |
|
64 ] ifFalse:[ |
|
65 level timesRepeat: [ buffer nextPut: Character tab ]. |
|
66 ]. |
|
67 |
|
68 "Created: / 01-06-2015 / 22:58:07 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
69 ! ! |
78 ! ! |
70 |
79 |
71 !PPCCodeBlock methodsFor:'code generation - variables'! |
80 !PPCCodeBlock methodsFor:'code generation - variables'! |
72 |
81 |
73 allocateTemporaryVariableNamed:preferredName |
82 allocateTemporaryVariableNamed:preferredName |
142 ]. |
151 ]. |
143 ]. |
152 ]. |
144 aStream nextPutAll: buffer contents |
153 aStream nextPutAll: buffer contents |
145 |
154 |
146 "Created: / 01-06-2015 / 21:26:03 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
155 "Created: / 01-06-2015 / 21:26:03 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
156 ! |
|
157 |
|
158 sourceOn:aStream |
|
159 "Dumps generated code on given stream" |
|
160 |
|
161 temporaries notEmpty ifTrue:[ |
|
162 ((Smalltalk respondsTo:#isSmalltalkX) and:[ Smalltalk isSmalltalkX ]) ifTrue:[ |
|
163 indentation * 4 timesRepeat:[ |
|
164 aStream nextPut:Character space |
|
165 ]. |
|
166 ] ifFalse:[ |
|
167 indentation timesRepeat:[ |
|
168 aStream nextPut:Character tab |
|
169 ]. |
|
170 ]. |
|
171 aStream nextPut:$|. |
|
172 temporaries do:[:e | |
|
173 aStream |
|
174 space; |
|
175 nextPutAll:e |
|
176 ]. |
|
177 aStream space. |
|
178 aStream nextPut:$|. |
|
179 self nl. |
|
180 "In Smalltalk/X, there should be a blank line after temporaries" |
|
181 ((Smalltalk respondsTo:#isSmalltalkX) and:[ Smalltalk isSmalltalkX ]) ifTrue:[ |
|
182 self nl. |
|
183 ]. |
|
184 ]. |
|
185 aStream nextPutAll:buffer contents |
|
186 |
|
187 "Created: / 01-06-2015 / 21:26:03 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
147 ! ! |
188 ! ! |
148 |
189 |
149 !PPCCodeBlock methodsFor:'private'! |
190 !PPCCodeBlock methodsFor:'private'! |
150 |
191 |
151 emitCodeAsBlock: aBlock |
192 emitCodeAsBlock: aBlock |