The Dryad Compiler is an open compiler for the Java platform, based on The Dryad.

Overview of Features

The Dryad Compiler is a compiler for a language formed by the mixture of Java and bytecode. This means that it can be used to compile regular Java programs, as well as programs that may already be partially or completely compiled to bytecode. The compiler uses transformation rules that normalize the input language to pure bytecode, i.e., the core language. This makes it well-suited for composition mechanisms, such as traits or aspects, as well as statement-level and expression-level language extensions. These can operate by transformation to Java source code or bytecode as required, and may include fragments of previously compiled code.

The Dryad Compiler makes use of The Dryad, which provides semantic analyis for the Java language and an interface for reading and writing Java class files.

The Java/bytecode Language

The mixed Java/bytecode language is formed by extension of the Java-front syntax definition for the Java language with an assembly language for bytecode. Bytecode fragments and Java fragments can be used interchangeably using the backtick operator (`), and allow direct interoperability through local variables, expression values, and fields. Fragments of the two constituent languages can be nested up to arbitrary depth.

An example program:

class Calculator {
  public static void main(String[] args) {
    // inline "goto" instruction for unstructured control flow in generated code
    `goto label; 

    System.out.println("Hello, Java world");

    label:
      // bytecode instruction in an expresion
      System.out.println(`ldc "Hello Java+bytecode world!");
  }
}

The complete syntax definition can be found online in the Stratego/XT repository.

Source Tracing

The parser maintains position information when parsing. Throughout the normalization process that transforms Java/bytecode to the core bytecode language, this origin information is maintained and used for errors and run-time exception/debugging information.

Type Checker and Verifier

The Dryad Compiler performs full type checking and verification of the mixed language. This is implemented as a modular extension of the Dryad type checker with a Stratego-based bytecode verifier. In the traversal of the typechecker, the two are used as required and share their environments.

Extensions

A number of language extensions for Java have been implemented based on the Dryad Compiler, each compiling to the mixed Java/bytecode language. For instance, we have implemented an extension with separately compiled traits, an extension of Java for modular reuse of code, where the Dryad Compiler is used to combine code of compiled traits and source code classes. Other extensions include assimilation of yield continuations (or "iterator generators) and new operators into Java code, that compile to a mixture of bytecode instructions and Java code.

Extensions of the Dryad Compiler can make use of source tracing for accurate error reporting.

Unit tests for extension-generated code can be performed by pattern matching on the generated Java/bytecode output, or by direct compilation and evaluation of the fragments in the Java Virtual Machine.

Example applications

A number of small example Stratego programs that use the Dryad Compiler are available from Subversion.

Project Info

Publications

Mixing Source and Bytecode. A Case for Compilation by Normalization. Lennart C. L. Kats, Martin Bravenboer, and Eelco Visser. The 23rd ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA 2008).ACM SIGPLAN Notices 43(10), pages 91—108. Nashville, Tenessee, USA in October 2008. [pdf] [bib] [doi]

Supporting Language Extension and Separate Compilation by Mixing Java and Bytecode. Lennart C. L. Kats. Master's thesis INF/SCR-07-02, Institute of Information and Computing Sciences, Utrecht University, 2007. August 31, 2007. [pdf] [bib]

Contact and Mailing List

Please send questions to the stratego@cs.uu.nl mailing list. Also, the Dryad and Dryad Compiler developers are usually available on IRC at #stratego on freenode.net. Feel free to drop by!

Downloads

Distributions are build continuously:

The sources of the Dryad Compiler are available from Subversion.

Development

Contributors

License

The Dryad Compiler is LGPL (GNU Lesser General Public License) software. This means that you can use the Dryad Compiler library (and tools) without being required to distribute your software under the GPL.

See also

Revision: r1.18 - 28 Sep 2009 - 12:19 - LennartKats
Stratego > TheDryadCompiler
Copyright © 1999-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback