About the new compiler, Part I

Marcus Denker denker at iam.unibe.ch
Sun Jan 20 09:07:28 UTC 2008

On 19.01.2008, at 18:11, John Brant wrote:

> Marcus Denker wrote:
>> 4) The annotated AST now can be used to generate Code. The  
>> NewCompiler uses a very nice small "Squeak Assembler" to emit
>>   the code. The class for Code Generation is ASTTranslator. Again a  
>> visitor, walks over the tree and calls IRBuilder to
>>   emit code.
>>   Here in ASTTranslator the magic happens for the inlining of if/ 
>> and/while and so on:
>>    acceptMessageNode: aMessageNode
>>        aMessageNode isInlineIf ifTrue: [^ self emitIfNode:  
>> aMessageNode].
>>        aMessageNode isInlineIfNil ifTrue: [^ self emitIfNilNode:  
>> aMessageNode].
>>        aMessageNode isInlineAndOr ifTrue: [^ self emitAndOrNode:  
>> aMessageNode].
>>        aMessageNode isInlineWhile ifTrue: [^ self emitWhileNode:  
>> aMessageNode].
>>        aMessageNode isInlineToDo ifTrue: [^ self emitToDoNode:  
>> aMessageNode].
>>        aMessageNode isInlineCase ifTrue: [^ self emitCaseNode:  
>> aMessageNode].
>>        ^ self emitMessageNode: aMessageNode
>>           Uncomment the line with "isInlineIfNil" --> no compiler  
>> generates normal message send for ifNil:. Easy.
> Since you have the transformations available, you could use them as  
> macros to eliminate some of the cases here. For example, #ifNil: can  
> be transformed into "isNil ifTrue:".

Very nice, yes!

There was some use of the Rewriter in the, I think #emitCaseNode:. For  
now this was removed as we do not (yet) want to make the NewCompiler  
depend on the
RB package. (partly because there are people whose only comment on the  
RB is "oh, that's a lot of classes". Even today, the usefulness of  
refactorings is not
yet common knowledge... it's a bit like with Tests. Hard to change  

The first step for that would be to make the RB actually use the SmaCC  
based compiler, there is already work beeing done for that. Gwenaël  
Casaccio already has
a SmaCC based parser for the RB Pattern-Rewriter and is fixing the  
SmaCC parser / RB Framework to work together so that we can remove the  

Marcus Denker  --  denker at iam.unibe.ch

More information about the Squeak-dev mailing list