[Pharo-project] Playing with Opal AST->BC Translator
Opal is fun. I have a few simplifications to propose for the AST->BC OCASTTranslator 1) instead of testing isEffectTranslator or refining in subclass, most often we could just let self visit the node. Indeed, self will already be either a Translator ForEffect or ForValue. For example, this could apply to emitIfFalseIfTrue: emitIfNilIfNotNil: visitCascadeNode: This might also remove a few useless pushNil; pop BC sequences. 2) I think we can simplify the #visitBlockNode: / #visitSequenceNode: pair. Indeed, visitSequenceNode: tests if its parent isBlock, and if so will emitValue, else emitEffect. Inversely visitBlockNode: always ask to emitEffect, but since it contains a SequenceNode, this is a big lie. I suggest to always let the valueTranslator emitValue visitBlockNode: and simplify #visitSequenceNode: to just let (self visitNode: statements last). 3) I suggest changing the BC generated for or: and and: instead of: valueTranslator visitNode: aMessageNode receiver. methodBuilder jumpAheadTo: #else if: false; pushLiteral: true; jumpAheadTo: #end; jumpAheadTarget: #else. valueTranslator visitInlinedBlockNode: aMessageNode arguments first. methodBuilder jumpAheadTarget: #end. We could just use dup and thus remove a jump: valueTranslator visitNode: aMessageNode receiver. methodBuilder pushDup; jumpAheadTo: #end if: true; popTop. self visitInlinedBlockNode: aMessageNode arguments first. methodBuilder jumpAheadTarget: #end. ForEffect, this would just be self emitIfFalse: aMessageNode Of course, that last change might disturb the Decompiler a bit, but since we care far less now... I can open 1 or more issues if there is an interest. Nicolas
Hum several of your improvements look cool. Marcus and I are currently working on Opal. We are quite busy for the next two weeks but we'll find some time to have a deeper look on your changes. Then we'll mail you back. 2013/5/1 Nicolas Cellier <nicolas.cellier.aka.nice@gmail.com>
Opal is fun. I have a few simplifications to propose for the AST->BC OCASTTranslator
1) instead of testing isEffectTranslator or refining in subclass, most often we could just let self visit the node. Indeed, self will already be either a Translator ForEffect or ForValue.
For example, this could apply to emitIfFalseIfTrue: emitIfNilIfNotNil: visitCascadeNode:
This might also remove a few useless pushNil; pop BC sequences.
2) I think we can simplify the #visitBlockNode: / #visitSequenceNode: pair.
Indeed, visitSequenceNode: tests if its parent isBlock, and if so will emitValue, else emitEffect. Inversely visitBlockNode: always ask to emitEffect, but since it contains a SequenceNode, this is a big lie.
I suggest to always let the valueTranslator emitValue visitBlockNode: and simplify #visitSequenceNode: to just let (self visitNode: statements last).
3) I suggest changing the BC generated for or: and and:
instead of:
valueTranslator visitNode: aMessageNode receiver. methodBuilder jumpAheadTo: #else if: false; pushLiteral: true; jumpAheadTo: #end; jumpAheadTarget: #else. valueTranslator visitInlinedBlockNode: aMessageNode arguments first. methodBuilder jumpAheadTarget: #end.
We could just use dup and thus remove a jump:
valueTranslator visitNode: aMessageNode receiver. methodBuilder pushDup; jumpAheadTo: #end if: true; popTop. self visitInlinedBlockNode: aMessageNode arguments first. methodBuilder jumpAheadTarget: #end.
ForEffect, this would just be
self emitIfFalse: aMessageNode
Of course, that last change might disturb the Decompiler a bit, but since we care far less now...
I can open 1 or more issues if there is an interest.
Nicolas
-- Clément Béra Mate Virtual Machine Engineer Bâtiment B 40, avenue Halley 59650 *Villeneuve d'Ascq*
Nicolas I'm convinced marcus and clement will be definitively interested! Open tickets :). Opal is not fully polished yet. It has a nice skeleton but requires more love to really shine. This is great that it was pushed in Pharo so that we can all have a look. For us this is the infrastructure for a new generation open-compiler so this is nice to hear that from you. :) Stef
Opal is fun. I have a few simplifications to propose for the AST->BC OCASTTranslator
1) instead of testing isEffectTranslator or refining in subclass, most often we could just let self visit the node. Indeed, self will already be either a Translator ForEffect or ForValue.
For example, this could apply to emitIfFalseIfTrue: emitIfNilIfNotNil: visitCascadeNode:
This might also remove a few useless pushNil; pop BC sequences.
2) I think we can simplify the #visitBlockNode: / #visitSequenceNode: pair.
Indeed, visitSequenceNode: tests if its parent isBlock, and if so will emitValue, else emitEffect. Inversely visitBlockNode: always ask to emitEffect, but since it contains a SequenceNode, this is a big lie.
I suggest to always let the valueTranslator emitValue visitBlockNode: and simplify #visitSequenceNode: to just let (self visitNode: statements last).
3) I suggest changing the BC generated for or: and and:
instead of:
valueTranslator visitNode: aMessageNode receiver. methodBuilder jumpAheadTo: #else if: false; pushLiteral: true; jumpAheadTo: #end; jumpAheadTarget: #else. valueTranslator visitInlinedBlockNode: aMessageNode arguments first. methodBuilder jumpAheadTarget: #end.
We could just use dup and thus remove a jump:
valueTranslator visitNode: aMessageNode receiver. methodBuilder pushDup; jumpAheadTo: #end if: true; popTop. self visitInlinedBlockNode: aMessageNode arguments first. methodBuilder jumpAheadTarget: #end.
ForEffect, this would just be
self emitIfFalse: aMessageNode
Of course, that last change might disturb the Decompiler a bit, but since we care far less now...
I can open 1 or more issues if there is an interest.
Nicolas
On May 1, 2013, at 7:21 PM, Nicolas Cellier <nicolas.cellier.aka.nice@gmail.com> wrote:
Opal is fun. I have a few simplifications to propose for the AST->BC OCASTTranslator
1) instead of testing isEffectTranslator or refining in subclass, most often we could just let self visit the node. Indeed, self will already be either a Translator ForEffect or ForValue.
2) I think we can simplify the #visitBlockNode: / #visitSequenceNode: pair.
3) I suggest changing the BC generated for or: and and:
I can open 1 or more issues if there is an interest.
Yes! After we finish the front end I want to do a pass again on the backend⦠there are still some things to simplify, and these look interesting. Opal TODO right now: - refactoring to the new API - AST Transformer Plugins - compiler Pragmas (to turn of inlining, for example.) - get non-boolean receivers for ifTrue: working even when optimizing (see mustBeBooleanIn:) - Pluggable everything (so people can exchange everything (Parser, Semantic Check, Translator, IR backendâ¦) - Write something about it so people can use it - Do another pass on the backend Marcus
participants (4)
-
Clément Bera -
Marcus Denker -
Nicolas Cellier -
Stéphane Ducasse