[squeak-dev] Let C Code generator generate repeat loops (was The Trunk: Sound-nice.28.mcz)

Igor Stasenko siguctua at gmail.com
Mon Apr 11 19:47:59 UTC 2011


On 11 April 2011 19:01, Nicolas Cellier
<nicolas.cellier.aka.nice at gmail.com> wrote:
> I have no commit right to VMMaker and plenty of local modifications,
> so please see attachment
>
>
> ---------- Forwarded message ----------
> From: Nicolas Cellier <nicolas.cellier.aka.nice at gmail.com>
> Date: 2011/4/11
> Subject: Re: [squeak-dev] The Trunk: Sound-nice.28.mcz
> To: The general-purpose Squeak developers list
> <squeak-dev at lists.squeakfoundation.org>
>
>
> 2011/4/11 Levente Uzonyi <leves at elte.hu>:
>> On Mon, 11 Apr 2011, commits at source.squeak.org wrote:
>>
>>> Nicolas Cellier uploaded a new version of Sound to project The Trunk:
>>> http://source.squeak.org/trunk/Sound-nice.28.mcz
>>>
>>> ==================== Summary ====================
>>>
>>> Name: Sound-nice.28
>>> Author: nice
>>> Time: 11 April 2011, 4:49:01.623 pm
>>> UUID: 3de2013e-36c1-bd46-a5db-a56a85de109a
>>> Ancestors: Sound-nice.27
>>>
>>> Use #repeat instead of [true] whileTrue
>>
>> Can VMMaker compile #repeat to C? According to
>> http://wiki.squeak.org/squeak/2267 it can't, but the wiki page may not be up
>> to date.
>>
>>
>> Levente
>>
>
> Right, it sounds like CCodeGenerator>>initializeCTranslationDictionary
> does not have #repeat translation.
> Though it does not sound difficult to add:
>
> generateRepeat: msgNode on: aStream indent: level
>        "Generate do {stmtList} while(true)"
>
>        | stmts testStmt |
>        stmts := msgNode receiver statements.
>        testStmt := TConstantNode new setValue: true.
>        msgNode receiver setStatements: stmts.
>        aStream nextPutAll: 'do {'; cr.
>        msgNode receiver emitCCodeOn: aStream level: level + 1 generator: self.
>        level timesRepeat: [ aStream tab ].
>        aStream nextPutAll: '} while('.
>        testStmt emitCCodeOn: aStream level: 0 generator: self.
>        aStream nextPutAll: ')'.
>

it can be much shorter :

 generateRepeat: msgNode on: aStream indent: level
        "Generate while(1) { stmtList } "

        aStream nextPutAll: 'while(1) {'; cr.
        msgNode receiver emitCCodeOn: aStream level: level + 1 generator: self.
        level timesRepeat: [ aStream tab ].
        aStream nextPutAll: '}'.


> Nicolas
>
>
>
>



-- 
Best regards,
Igor Stasenko AKA sig.



More information about the Squeak-dev mailing list