SCHOOL OF ENGINEERING AND COMPUTER SCIENCE

Meta-FJig
A meta-circular composition language for Java-like classes

  1. Description
  2. Papers
  3. Download
MetaFJig is a Java-like language where class definitions are first class values, and new classes can be derived from existing ones by exploiting the full power of the language itself, used on top of a small set of primitive composition operators, instead of using a fixed mechanism like inheritance. Moreover, such operators are deep, that is, they allow to manipulate (e.g., rename or duplicate) a nested class at any level of depth.

This provides an effective language support for active libraries: namely, a (library) class can provide a method returning a customized version of a class, depending, e.g., on the execution platform. Since a class can contain nested classes, a whole library can be generated in this way. That is, deep operators allows the programmer to better exploit meta-programming capabilities, leading to a “ meta-programming in the large ” style.

Compilation requires to perform (meta-)reduction steps, by a process that we call compile-time execution. This approach differs from meta-programming techniques available in mainstream languages since it is meta-circular, hence programmers are not required to learn new syntax and idioms.

Compile-time execution is guaranteed to be sound (not to get stuck) by a lightweight technique, where class composition errors are detected dynamically, and conventional typing errors are detected by interleaving typechecking with meta-reduction steps. This allows for a modular approach, that is, compile-time execution is defined, and can be implemented, on top of typechecking and execution of the underlying language. Moreover, programmers can handle errors due to composition operators.

Besides soundness, our technique ensures an additional important property called meta-level soundness, that is, typing errors never originate from (meta-)code in already compiled programs.

To show the effectiveness of our technique, we have implemented a prototype compiler, which supports a superset of the language used in the formal description, including primitive types int and boolean, predefined classes Object, RuntimeException and String, arrays, void methods, statements if, while, try-catch, for-each, variable declaration and assignment. This prototype compiler is built on top of Java compiler and Java Virtual Machine.


Downloads

Papers

  1. MetaFJig - A meta-circular language for active libraries (pdf)
    M.Servetto and E.Zucca
    Submitted for publication. The full version of the language (called MetaFjig* in the paper) including nested classes.
  2. MetaFJig - A meta-circular composition language for Java-like classes (pdf)
    M.Servetto and E.Zucca
    In OOPSLA'10, Reno, October 2010. The simplified version of the language with no nesting.
  3. MetaFJig - A meta-circular composition language for Java-like classes (pdf)
    M.Servetto
    Ph.D. Thesis, May 2011. An extensive and incremental presentation of different versions of the language.

Implementation


The compiler uses
The graphical interface uses