Friday, November 02, 2018

Dynamic creation of compiler plugins in Pharo

A new class (merged this week into Pharo 7) called "OCCompilerDynamicASTPlugin" allows for the dynamic creation of compiler plugins


Object compiler
 addPlugin: 
  (OCCompilerDynamicASTPlugin 
   newFromTransformBlock: [ :ast | (RBParseTreeRewriter replaceLiteral: 42 with: 'meaning of life') executeTree: ast. ast. ]
   andPriority: 0
  );
 evaluate: '42'.
This would give 'meaning of life'

No comments: