Next: Possible Approaches Up: Porting Challenges Previous: General Challenges   Contents

Perl-Specific Challenges

In addition to the general challenges that the JVM presents inherent in its nature, there are also some challenges that are specific to porting Perl to the JVM. Perl is a unique language; Perl has both cultural and technical aspects that make it different from other programming languages. These issues create some specific challenges in porting Perl to the JVM.

First, parsing Perl is a particularly difficult problem. The Perl language is designed with lots of syntactic sugar and special cases. There are reasonable and laudable design goals (which are beyond the scope of this thesis) for this design. Regardless, though, this design makes Perl particularly difficult to parse. Currently, the only known full parser for Perl is the one that ships with the perl distribution, and it is infamously very complex.

There is also no formal specification for Perl. While this will likely change for the next major version of Perl, the current mantra of the Perl community is ``the implementation is the specification''--meaning that whatever perl does defines what the language Perl itself should always do. Implementing a new compiler, given that no specification exists, is particularly difficult.

Finally, Perl's native data types are particularly uncommon. While on the surface, the native data types (array, hash, and scalar) seem common, there are some frequently used special cases that introduce complexity for a compiler writer. For example, Perl's tie feature allows the programmer to arbitrarily make any variable in the language a full-fledged object, where arbitrary code is executed for any variable access. Figure 1.3 shows a simple example of a tied Perl scalar.

Figure 1.3: A Simple Example of a Tied Perl Scalar
This Program:
package AlwaysOne;
sub FETCH { return 1;}
sub STORE { print "warning: cannot change this variable\n"; }
sub TIESCALAR { my($c, $r) = @_; return bless \$r, $c; }
package main;
tie $x, AlwaysOne;
print "$x\n"; $x = "Hello World\n"; print "$x\n";
generates the output:
warning: cannot change this variable

In this example, the scalar variable, $x, is tied to the package AlwaysOne. The example shows how the semantics of variable assignment and variable use are changed utterly by tie. The FETCH and STORE methods replace assignment and use of $x.

As can be seen through the example of tie, Perl's data types, while seemingly straight-forward at first glance, are actually quite advanced and complex. A JVM port of Perl must handle these special cases. Care must be taken so that the underlying data structures used to implement Perl's data types can support these advanced features.

Next: Possible Approaches Up: Porting Challenges Previous: General Challenges   Contents

Copyright © 2000, 2001 Bradley M. Kuhn.

Verbatim copying and distribution of this entire thesis is permitted in any medium, provided this notice is preserved.