Next

Kawa - Compiling Dynamic Languages to the Java VM

Per Bothner

Cygnus Solutions1325 Chesapeake Terrace Sunnyvale CA 94089, USA bothner@cygnus.com

Many are interested in Java for its portable bytecodes and extensive libraries, but prefer a different language, especially for scripting. People have implemented other languages using an interpreter (which is slow), or by translating into Java source (with poor responsiveness for eval). Kawa uses an interpreter only for “simple” expressions; all non-trivial expressions (such as function definitions) are compiled into Java bytecodes, which are emitted into an in-memory byte array. This can be saved for later, or quickly loaded using the Java ClassLoader.

Kawa is intended to be a framework that supports multiple source languages. Currently, it only supports Scheme, which is a lexically-scoped language in the Lisp family. The Kawa dialect of Scheme implements almost all of the current Scheme standard (R5RS), with a number of extensions, and is written in a efficient object-oriented style. It includes the full “numeric tower”, with complex numbers, exact infinite-precision rational arithmetic, and units. A number of extensions provide access to Java primitives, and some Java methods provide convenient access to Scheme. Since all Java objects are Scheme values and vice versa, this makes for a very powerful hybrid Java/Scheme environment.

An implementation of ECMAScript (the standardized “core” of JavaScript) is under construction. Other languages, including Emacs Lisp, are also being considered.

Kawa home page.

Introduction

While Java is a decent programming language, the reason for the “Java explosion” is largely due to the Java Virtual Machine (JVM), which 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. Many are especially interested in more high-level, dynamic “scripting” languages to use in a project in conjunction with Java. A language implemented on top of Java gives programmers many of the extra-linguistic benefits of Java, including libraries, portable bytecodes, web applets, and the existing efforts to improve Java implementations and tools.

The Kawa toolkit supports compiling and running various languages on the Java Virtual Machine. Currently, Scheme is fully supported (except for a few difficult features discussed later). An implementation of ECMAScript is coming along, but at the time of writing it is not usable.

Scheme R5RS is a simple yet powerful language. It is a non-pure functional language (i.e. it has first-class functions, lexical scoping, non-lazy evaluation, and side effects). It has dynamic typing, and usually has an interactive read-evaluate-print interface. The dynamic nature of Scheme (run-time typing, immediate expression evaluation) may be a better match for the dynamic Java environment (interpreted bytecodes, dynamic loading) than Java is!

ECMAScript is the name of the dialect of JavaScript defined by ECMA standard 262 ECMAScript, which standardizes JavaScript's core language only, with no input/output or browser/document interface. It defines a very dynamic object-based language based on prototype inheritance, rather than classes. A number of new or proposed Web standards are based on ECMAScript.

Information and source code will be available from here. (Note that Kawa is also the name of an unrelated commercial Java development environment.)


  Next
  History