equal
deleted
inserted
replaced
1 "{ Package: 'stx:goodies/petitparser/compiler' }" |
1 "{ Package: 'stx:goodies/petitparser/compiler' }" |
2 |
2 |
3 "{ NameSpace: Smalltalk }" |
3 "{ NameSpace: Smalltalk }" |
4 |
4 |
5 Object subclass:#PPCMethod |
5 Object subclass:#PPCMethod |
6 instanceVariableNames:'buffer id variableForReturn category' |
6 instanceVariableNames:'buffer id variableForReturn category profile' |
7 classVariableNames:'' |
7 classVariableNames:'' |
8 poolDictionaries:'' |
8 poolDictionaries:'' |
9 category:'PetitCompiler-Compiler-Codegen' |
9 category:'PetitCompiler-Compiler-Codegen' |
10 ! |
10 ! |
11 |
11 |
64 "Created: / 01-06-2015 / 21:38:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
64 "Created: / 01-06-2015 / 21:38:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
65 ! |
65 ! |
66 |
66 |
67 methodName |
67 methodName |
68 ^ id |
68 ^ id |
|
69 ! |
|
70 |
|
71 profile |
|
72 ^ profile |
|
73 ! |
|
74 |
|
75 profile: aBoolean |
|
76 profile := aBoolean |
69 ! ! |
77 ! ! |
70 |
78 |
71 !PPCMethod methodsFor:'as yet unclassified'! |
79 !PPCMethod methodsFor:'as yet unclassified'! |
72 |
80 |
73 add: string |
81 add: string |
86 ^ 'self ', self methodName, '.'. |
94 ^ 'self ', self methodName, '.'. |
87 ! |
95 ! |
88 |
96 |
89 profilingBegin |
97 profilingBegin |
90 self profile ifTrue: [ |
98 self profile ifTrue: [ |
91 ^ ' context methodInvoked: #', id, '.' |
99 ^ ' context methodInvoked: #', id, '.' |
92 ]. |
100 ]. |
93 ^ '' |
101 ^ '' |
94 ! |
102 ! |
95 |
103 |
96 profilingEnd |
104 profilingEnd |
97 self profile ifTrue: [ |
105 self profile ifTrue: [ |
98 ^ ' context methodFinished: #', id, '.' |
106 ^ ' context methodFinished: #', id, '.' |
99 ]. |
107 ]. |
100 ^ '' |
108 ^ '' |
101 ! ! |
109 ! ! |
102 |
110 |
103 !PPCMethod methodsFor:'code generation'! |
111 !PPCMethod methodsFor:'code generation'! |
114 |
122 |
115 outerBlock := buffer. |
123 outerBlock := buffer. |
116 innerBlock := PPCCodeBlock new. |
124 innerBlock := PPCCodeBlock new. |
117 innerBlock indentationLevel: outerBlock indentationLevel + 1. |
125 innerBlock indentationLevel: outerBlock indentationLevel + 1. |
118 [ |
126 [ |
119 buffer addOnLine:'['; nl; codeIndent. |
127 outerBlock addOnLine:'['. |
120 buffer := innerBlock. |
128 buffer := innerBlock. |
121 self code: contents. |
129 self code: contents. |
122 ] ensure:[ |
130 ] ensure:[ |
|
131 outerBlock |
|
132 code: (String streamContents:[:s | innerBlock codeOn: s]); |
|
133 add:']'. |
123 buffer := outerBlock. |
134 buffer := outerBlock. |
124 buffer |
|
125 code: (String streamContents:[:s | innerBlock codeOn: s]); |
|
126 nl; |
|
127 codeIndent. |
|
128 |
|
129 buffer addOnLine:']'. |
|
130 ] |
135 ] |
131 |
136 |
132 "Created: / 01-06-2015 / 22:33:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
137 "Created: / 01-06-2015 / 22:33:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
133 "Modified: / 03-06-2015 / 06:11:32 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
138 "Modified: / 03-06-2015 / 06:11:32 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
134 ! ! |
139 ! ! |
153 |
158 |
154 "Created: / 01-06-2015 / 21:52:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
159 "Created: / 01-06-2015 / 21:52:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
155 ! ! |
160 ! ! |
156 |
161 |
157 !PPCMethod methodsFor:'code generation - variables'! |
162 !PPCMethod methodsFor:'code generation - variables'! |
|
163 |
|
164 allocateReturnVariable |
|
165 |
|
166 ^ variableForReturn isNil ifTrue:[ |
|
167 variableForReturn := self allocateTemporaryVariableNamed: 'retval' |
|
168 ] ifFalse:[ |
|
169 variableForReturn |
|
170 ]. |
|
171 |
|
172 "Created: / 23-04-2015 / 18:03:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
173 ! |
158 |
174 |
159 allocateReturnVariableNamed: name |
175 allocateReturnVariableNamed: name |
160 "Allocate temporary variable used for storing a parser's return value (the parsed object)" |
176 "Allocate temporary variable used for storing a parser's return value (the parsed object)" |
161 |
177 |
162 variableForReturn notNil ifTrue:[ |
178 variableForReturn notNil ifTrue:[ |