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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

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

Nicolas Cellier
 
I have no commit right to VMMaker and plenty of local modifications,
so please see attachment


---------- Forwarded message ----------
From: Nicolas Cellier <[hidden email]>
Date: 2011/4/11
Subject: Re: [squeak-dev] The Trunk: Sound-nice.28.mcz
To: The general-purpose Squeak developers list
<[hidden email]>


2011/4/11 Levente Uzonyi <[hidden email]>:

> On Mon, 11 Apr 2011, [hidden email] 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: ')'.

Nicolas

Generate_repeat.st (7K) Download Attachment