Kawa: Compiling Scheme to Java

Per Bothner

Cygnus Solutions

1325 Chesapeake Terrace
Sunnyvale CA 94089USA


Table of Contents
Introduction
History
Basic implementation strategy
Objects and Values
Numbers
Procedures
Overview of compilation
Expressions
Semantic analysis
Interpretation: Eval
Code generation
Class, types, and declarations
Low-level Java access
Scheme complications
Benchmark Results
Current and Future Work
Conclusion
Bibliography

Kawa is a set of Java classes useful for implementing dynamic languages, such as those in the Lisp family. Kawa is also an implementation of near-R5RS Scheme using these classes, and which compiles Scheme to the bytecode instructions of the Java Virtual Machine. This paper discusses the various issues involved in implementing Scheme using an abstract machine designed for a very different language. and how Kawa solves these problems.

The Kawa home page is http://www.cygnus.com/~bothner/kawa.html.

An earlier version of this paper was presented at Usenix in June 1998.

Introduction

While Java is a decent programming language, the reason for the “Java explosion” is largely due to the Java Virtual Machine. The JVM allows programs to be distributed easily and efficiently in the form of portable bytecodes, which can run on a wide variety of architectures and in web browsers. These advantages are largely independent of the Java language, which is why there have been a number of efforts to run other languages on the JVM, even though the JVM is very clearly designed and optimized for Java. Kawa is both a toolkit for compiling other languages into Java bytecodes, and an implementation of the Scheme language implemented in Java.

The benefits of this hybrid Scheme/Java environment include:

Kawa is intended to be a multi-langauge implementation toolkit. While only Scheme is currently supported, an implementation of ECMAScript (JavaScript) is coming along. Emacs Lisp is also planned.

(Note that Kawa is also the name of an unrelated commercial Java development environment.)