This is the mail archive of the mailing list for the Kawa project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Using Kawa to port Perl to the JVM

Per Bothner <> wrote:
> "Bradley M. Kuhn" <> writes:
> > I'd like to somehow use a walk of the perl intermediate representation to
> > generate Kawa's intermediate representation.
> I think that is the best approach.
> > Thus, I'd like to reuse much of what is in gnu.expr.* in some way.  However,
> > I am not sure what is reusable.  Some things seem pretty general, but a lot
> > of it seems specific to Lisp-like languages.
> Such as?  I think most of it should be re-usable.

I suppose my concern was that changes would like be needed to support Perl.
It seems like they will be needed.

For example, I would likely need to add types to Compilation class.

Perl's "native" data types are scalar, array, hash and reference, which have
clearly defined semantics that must be supported.  My plan has been to
implement these data types as Java classes.

Thus, it seems I would have to add:

  static public ClassType perlScalarType =

and the like to the Compilation class.

Am I on the right track, or have I completely missed something?

> > Do you all (and, in particular, Per :) have an suggestions on what parts of
> > gnu.expr.* I should look at reusing?
> All of it ...

I figured you'd say that.  ;) Now, the hard part if getting a deep enough
understanding to begin working with it.

I have read internals.xml a few times, but it doesn't go to the level of
depth I'd need to simply begin hacking.  Once I figure it out enough, I
suppose should write a tutorial on porting new languages to Kawa.  ;)

Any hints you can give beyond what is in internals.xml, I would appreciate

> One problem that comes to mind: What kind of control structures does the
> Perl intermediate format use?  If it involves unrestricted gotos that
> would be a little more difficult, since gnu.expr does not at this point
> support that.  However, it does support the ususual control structures,
> including exit from a block.

At least in this respect, I think this should be a nearly perfect match.
Perl's IR is roughly a parse tree, an argument list (to pass values from one
OP-code to the next), and a few different types of lookup tables (for
example, both dynamic and lexically scoped variables are permitted).

The difficult parts are:

   * Perl's native data types must be implemented, and they are pretty
     complex.  (Must more complex than those of Scheme, for example.)

   * Almost everything function call in libc is a native op-code in Perl.

   * The Perl backend is complex and mostly undocumented. 
> > I started by thinking I should just begin subclassing Expression, creating
> > my own Perl expressions.
> In general, you should avoid sub-classing.  For example, data operations
> (anything that in Scheme would be a builtin procedure) should all be
> handled as ApplyExp instances.  You can use that to call a specific
> method, if you need to.

Ok, that makes sense on a conceptual level.  I guess the hard time that I am
having is finding where to start.

If I could get the proverbial "Hello World" in Perl to compile to Kawa, and
be able to create simple variables and assign them, that might give me some
idea of where to go from there.

Is there a place you recommend I look to see how to set up the right objects
in the right way to begin compiling very trivial programs to Kawa

> Is there a convenient on-line definition of the Perl intermediate format?

Sadly, no.  The intermediate format is very ad-hoc, and is closely tied to
the implementation itself.  The best reference for the perl internals is and and the 'perlguts' man page that comes
with Perl.

That likely won't be too much help, though, unless you want to dive deep
into the code of perl itself.  I could probably answer questions on it, as I
have spent a lot of time studying.

Bradley M. Kuhn  -

PGP signature

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]