CodeBricks

Giuseppe Attardi, Antonio Cisternino, Andrew Kennedy
2003 SIGPLAN notices  
We present a framework for code generation that allows programs to manipulate and generate code at the source level while the joining and splicing of executable code is carried out automatically at the intermediate code/VM level. The framework introduces a data type Code to represent code fragments: methods/operators from this class are used to reify a method from a class, producing its representation as an object of type Code. Code objects can be combined by partial application to other Code
more » ... jects. Code combinators, corresponding to higher-order methods, allow splicing the code of a functional actual parameter into the resulting Code object. CodeBricks is a library implementing the framework for the .NET Common Language Runtime. The framework can be exploited by language designers to implement metaprogramming, multistage programming and other language features. We illustrate the use of the technique in the implementation of a fully featured regular expression compiler that generates code emulating a finite state automaton. We present benchmarks comparing the performance of the RE matcher built with CodeBricks with the hand written one present in .NET.
doi:10.1145/966049.777396 fatcat:j4ft5bkncvcz5ondvcnh42o6ca