[Reflectivity] Compiler AST transformation Plugins

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

[Reflectivity] Compiler AST transformation Plugins

Marcus Denker-4
 A simple AST-transformer plugin architecture for Opal...

-> subclass OCCompilerASTPlugin
-> implement #transform e.g.

transform
    | rule |
    rule := RBParseTreeRewriter replaceLiteral: 42 with: 'meaning of life'.
    rule executeTree: ast.
    ^ast

The plugin can be activated *per class hierarchy* by overriding #compiler

compiler
    "the example plugin is active for this class"
    ^super compiler addPlugin: ASTPluginMeaningOfLife.

or of course for a single compilation:

(Smalltalk compiler addPlugin: ASTPluginMeaningOfLife) evaluate: ’42’

For review here:

https://pharo.fogbugz.com/f/cases/15019/Compiler-AST-transformation-Plugins

        Marcus
Reply | Threaded
Open this post in threaded view
|

Re: [Reflectivity] Compiler AST transformation Plugins

Thierry Goubier

Cool.

Per class customizable code rewriting. Great for extendable frameworks.

Thierry

Le 28 févr. 2015 16:18, "Marcus Denker" <[hidden email]> a écrit :
 A simple AST-transformer plugin architecture for Opal...

-> subclass OCCompilerASTPlugin
-> implement #transform e.g.

transform
    | rule |
    rule := RBParseTreeRewriter replaceLiteral: 42 with: 'meaning of life'.
    rule executeTree: ast.
    ^ast

The plugin can be activated *per class hierarchy* by overriding #compiler

compiler
    "the example plugin is active for this class"
    ^super compiler addPlugin: ASTPluginMeaningOfLife.

or of course for a single compilation:

(Smalltalk compiler addPlugin: ASTPluginMeaningOfLife) evaluate: ’42’

For review here:

https://pharo.fogbugz.com/f/cases/15019/Compiler-AST-transformation-Plugins

        Marcus