16 ! ! |
16 ! ! |
17 |
17 |
18 !PPCFSACodeGen methodsFor:'coding'! |
18 !PPCFSACodeGen methodsFor:'coding'! |
19 |
19 |
20 codeAbsoluteReturn: code |
20 codeAbsoluteReturn: code |
21 self add: '^ ', code |
21 self code: '^ ', code |
22 ! |
22 ! |
23 |
23 |
24 codeAssertPeek: t |
24 codeAssertPeek: t |
25 | id | |
25 | id | |
26 self assert: (t isKindOf: PEGFsaTransition). |
26 self assert: (t isKindOf: PEGFsaTransition). |
27 |
27 |
28 (t isPredicateTransition and: [t isEOF]) ifTrue: [ |
28 (t isPredicateTransition and: [t isEOF]) ifTrue: [ |
29 self addOnLine: 'currentChar isNil'. |
29 self codeOnLine: 'currentChar isNil'. |
30 ^ self |
30 ^ self |
31 ]. |
31 ]. |
32 |
32 |
33 |
|
34 (t isPredicateTransition) ifTrue: [ |
33 (t isPredicateTransition) ifTrue: [ |
35 self addOnLine: t predicate asString, ' value: currentChar codePoint'. |
34 self codeOnLine: t predicate asString, ' value: currentChar codePoint'. |
36 ^ self |
35 ^ self |
37 ]. |
36 ]. |
38 |
37 |
39 (t isAny) ifTrue: [ |
38 (t isAny) ifTrue: [ |
40 self addOnLine: 'true'. |
39 self codeOnLine: 'true'. |
41 ^ self |
40 ^ self |
42 ]. |
41 ]. |
43 |
42 |
44 |
43 |
45 (t isSingleCharacter) ifTrue: [ |
44 (t isSingleCharacter) ifTrue: [ |
46 self addOnLine: 'currentChar == ', t character storeString. |
45 self codeOnLine: 'currentChar == ', t character storeString. |
47 ^ self |
46 ^ self |
48 ]. |
47 ]. |
49 |
48 |
50 (t isNotSingleCharacter) ifTrue: [ |
49 (t isNotSingleCharacter) ifTrue: [ |
51 self addOnLine: 'currentChar ~~ ', t notCharacter storeString. |
50 self codeOnLine: 'currentChar ~~ ', t notCharacter storeString. |
52 ^ self |
51 ^ self |
53 ]. |
52 ]. |
54 |
53 |
55 (t isLetter) ifTrue: [ |
54 (t isLetter) ifTrue: [ |
56 self addOnLine: 'currentChar isLetter'. |
55 self codeOnLine: 'currentChar isLetter'. |
57 ^ self |
56 ^ self |
58 ]. |
57 ]. |
59 |
58 |
60 (t isWord) ifTrue: [ |
59 (t isWord) ifTrue: [ |
61 self addOnLine: 'currentChar isAlphaNumeric'. |
60 self codeOnLine: 'currentChar isAlphaNumeric'. |
62 ^ self |
61 ^ self |
63 ]. |
62 ]. |
64 |
63 |
65 (t isDigit) ifTrue: [ |
64 (t isDigit) ifTrue: [ |
66 self addOnLine: 'currentChar isDigit'. |
65 self codeOnLine: 'currentChar isDigit'. |
67 ^ self |
66 ^ self |
68 ]. |
67 ]. |
69 |
68 |
70 (t isSingleRange) ifTrue: [ |
69 (t isSingleRange) ifTrue: [ |
71 | begin end | |
70 | begin end | |
72 begin := t beginOfRange. |
71 begin := t beginOfRange. |
73 end := t endOfRange. |
72 end := t endOfRange. |
74 self addOnLine: 'self peekBetween: ', begin asString, ' and: ', end asString. |
73 self codeOnLine: 'self peekBetween: ', begin asString, ' and: ', end asString. |
75 ^ self |
74 ^ self |
76 ]. |
75 ]. |
77 |
76 |
78 |
77 |
79 id := idGen cachedSuchThat: [ :e | e = t characterSet ] |
78 id := self idGen cachedSuchThat: [ :e | e = t characterSet ] |
80 ifNone: [ self idFor: t characterSet defaultName: 'characterSet' ]. |
79 ifNone: [ self idFor: t characterSet defaultName: 'characterSet' ]. |
81 |
80 |
82 self addConstant: t characterSet as: id. |
81 self addConstant: t characterSet as: id. |
83 self addOnLine: '(currentChar isNotNil) and: [', id, ' at: currentChar codePoint ]'. |
82 self codeOnLine: '(currentChar isNotNil) and: [', id, ' at: currentChar codePoint ]'. |
84 ! |
83 ! |
85 |
84 |
86 codeAssertPeek: transition ifFalse: falseBlock |
85 codeAssertPeek: transition ifFalse: falseBlock |
87 self add: '('. |
86 self add: '('. |
88 self codeAssertPeek: transition. |
87 self codeAssertPeek: transition. |
159 ^ self codeNlReturnResult |
154 ^ self codeNlReturnResult |
160 ]. |
155 ]. |
161 self add: '^ self returnPriority: ', priority asString, '.' |
156 self add: '^ self returnPriority: ', priority asString, '.' |
162 ! |
157 ! |
163 |
158 |
|
159 codeRecordDistinctFailure: retval offset: value |
|
160 self add: 'self recordDistinctFailure: ', retval storeString, ' offset: ', value storeString, '.' |
|
161 ! |
|
162 |
164 codeRecordDistinctMatch: retval offset: value |
163 codeRecordDistinctMatch: retval offset: value |
165 self add: 'self recordDistinctMatch: ', retval storeString, ' offset: ', value storeString, '.' |
164 self code: 'self recordDistinctMatch: ', retval storeString, ' offset: ', value storeString, '.' |
166 ! |
165 ! |
167 |
166 |
168 codeRecordMatch: state priority: priority |
167 codeRecordMatch: state priority: priority |
169 priority isNil ifTrue: [ |
168 priority isNil ifTrue: [ |
170 ^ self codeRecordMatch: state |
169 ^ self codeRecordMatch: state |
171 ]. |
170 ]. |
172 |
171 |
173 self add: 'self recordMatch: ', state storeString, ' priority: ', priority asString, '.' |
172 self add: 'self recordMatch: ', state storeString, ' priority: ', priority asString, '.' |
174 ! |
173 ! |
175 |
174 |
|
175 codeReturn: code |
|
176 arguments profile ifTrue:[ |
|
177 self codeProfileStop. |
|
178 ]. |
|
179 self code: '^ '. |
|
180 self codeOnLine: code |
|
181 ! |
|
182 |
176 codeReturnResult |
183 codeReturnResult |
177 self addOnLine: '^ self return.' |
184 self addOnLine: '^ self return.' |
178 ! |
185 ! |
179 |
186 |
180 codeReturnResult: priority |
187 codeReturnResult: priority |
|
188 self error: 'deprecated?'. |
181 priority isNil ifTrue: [ |
189 priority isNil ifTrue: [ |
182 ^ self codeReturnResult |
190 ^ self codeReturnResult |
183 ]. |
191 ]. |
184 |
192 |
185 self addOnLine: '^ self returnPriority: ', priority asString, '.' |
193 self addOnLine: '^ self returnPriority: ', priority asString, '.' |
186 ! |
194 ! |
187 |
195 |
188 codeStartBlock |
196 codeStartBlock |
189 self add: '['. |
197 self code: '['. |
190 self indent. |
198 self indent. |
191 ! ! |
199 ! ! |
192 |
200 |
193 !PPCFSACodeGen methodsFor:'coding - results'! |
201 !PPCFSACodeGen methodsFor:'coding - results'! |
194 |
202 |
|
203 codeRecordDistinctFailure: retval |
|
204 self assert: retval isNil. |
|
205 |
|
206 self code: 'self recordDistinctFailure.' |
|
207 ! |
|
208 |
195 codeRecordDistinctMatch: retval |
209 codeRecordDistinctMatch: retval |
196 self add: 'self recordDistinctMatch: ', retval storeString, '.' |
210 self code: 'self recordDistinctMatch: ', retval storeString, '.' |
197 ! |
211 ! |
198 |
212 |
199 codeRecordFailure: index |
213 codeRecordFailure: index |
200 self assert: index isInteger. |
214 self assert: index isInteger. |
201 self add: 'self recordFailure: ', index asString, '.' |
215 self code: 'self recordFailure: ', index asString, '.' |
202 ! |
216 ! |
203 |
217 |
204 codeRecordMatch: retval |
218 codeRecordMatch: retval |
205 self add: 'self recordMatch: ', retval storeString, '.' |
219 self add: 'self recordMatch: ', retval storeString, '.' |
206 ! |
220 ! |
207 |
221 |
208 codeRecordMatch: retval offset: offset |
222 codeRecordMatch: retval offset: offset |
209 self add: 'self recordMatch: ', retval storeString, ' offset: ', offset storeString, '.' |
223 self code: 'self recordMatch: ', retval storeString, ' offset: ', offset storeString, '.' |
210 ! |
224 ! |
211 |
225 |
212 codeReturn |
226 codeReturn |
213 self addOnLine: '^ self' |
227 self codeOnLine: '^ self' |
214 ! |
228 ! |
215 |
229 |
216 codeReturnDistinct |
230 codeReturnDistinct |
217 self addOnLine: '^ self returnDistinct.' |
231 self codeOnLine: '^ self returnDistinct.' |
218 ! ! |
232 ! ! |
219 |
233 |
220 !PPCFSACodeGen methodsFor:'intitialization'! |
234 !PPCFSACodeGen methodsFor:'intitialization'! |
221 |
235 |
222 initialize |
236 initialize |
223 super initialize. |
237 super initialize. |
224 |
238 ! ! |
225 compiler := PPCCodeGen new. |
239 |
226 backlinkStates := IdentityDictionary new. |
|
227 ! ! |
|
228 |
|