CodeBricks: code fragments as building blocks

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 objects. 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.

[1]  Soumen Sarkar CODE GENERATION USING XML BASED DOCUMENT TRANSFORMATION , 2001 .

[2]  Paul Hudak,et al.  Modular domain specific languages and tools , 1998, Proceedings. Fifth International Conference on Software Reuse (Cat. No.98TB100203).

[3]  Dawson R. Engler,et al.  C and tcc: a language and compiler for dynamic code generation , 1999, TOPL.

[4]  Dawson R. Engler,et al.  VCODE: a retargetable, extensible, very fast dynamic code generation system , 1996, PLDI '96.

[5]  Samuel N. Kamin,et al.  Lightweight and Generative Components 2: Binary-Level Components , 2000, SAIG.

[6]  Gregor Kiczales,et al.  Aspect-oriented programming , 1996, CSUR.

[7]  Henk-Evert Sonder,et al.  Common Language Runtime , 2001 .

[8]  Krzysztof Czarnecki,et al.  Generative Programming: Methods, Techniques, and Applications , 2002, ICSR.

[9]  Charles Consel,et al.  Tempo: specializing systems applications and beyond , 1998, CSUR.

[10]  Peter Sestoft,et al.  Partial evaluation and automatic program generation , 1993, Prentice Hall international series in computer science.

[11]  Antonio Cisternino,et al.  Multi-stage and meta-programming support in strongly typed execution engines , 2003 .

[12]  Peter Thiemann,et al.  Higher-Order Code Splicing , 1999, ESOP.

[13]  John R. Levine,et al.  Lex & yacc, 2nd edition , 1992 .

[14]  Todd L. Veldhuizen,et al.  Arrays in Blitz++ , 1998, ISCOPE.

[15]  Walid Taha,et al.  Multi-stage programming with explicit annotations , 1997 .

[16]  Krzysztof Czarnecki,et al.  Generative programming - methods, tools and applications , 2000 .

[17]  Charles Simonyi,et al.  The Death of Computer Languages, The Birth of Intentional Programming , 1995 .

[18]  Peter Sestoft,et al.  Runtime Code Generation with JVM and CLR , 2002 .

[19]  John Hannan,et al.  Specification and correctness of lambda lifting , 2000, Journal of Functional Programming.

[20]  Guy L. Steele,et al.  Common Lisp the Language , 1984 .

[21]  Hidehiko Masuhara,et al.  DynJava: Type Safe Dynamic Code Generation in Java , 2001 .

[22]  Jr. Guy L. Steele,et al.  Common LISP: the language (2nd ed.) , 1990 .