This page is no longer maintained — Please continue to the home page at www.scala-lang.org

compiling Scala ASTs into Java CSTs (Concrete Syntax Trees)

1 reply
Miguel Garcia
Joined: 2009-06-10,
User offline. Last seen 42 years 45 weeks ago.

I've browsed GenJava, GenICode, and GenJVM and collected some ideas, here
they go for your valuable early feedback.

A general impression is that getting the translation right appears rocket
science only because the precise shape of the incoming ASTs is not
documented (like, the distinction between static and non-static modules
based on outer instance was not *evident* at first), although the compiler
backend has readable source comments.

To address the difficulty about "unknown shapes", I'm planning to break up
the translator into two phases:

(1) transforming the incoming ASTs so that they contain only the kind of
things that a Java CST can express. Rather than trying to untangle
on-the-fly as GenJava does.

After this step, ASTs should be "boring" (e.g., no arbitrary jumps, sorting
those Block(stats,expr) that return void from those that don't, etc.) I
haven't thought yet if "eliminating forward jumps" means

(1.a) un-applying some previous transformations (from pattern match,
maybe?); or
(1.b) adding new node types (e.g, "While", which used to be in the parse
tree); or
(1.c) letting jumps be and go for techniques heralded by the Soot Dava
decompiler.

(2) the second phase does serialization of .java files proper. Much like
writeICode does now.

During next week I may come up with more concrete approaches to the
translation, but feedback is welcome already.

Miguel
http://www.sts.tu-harburg.de/people/mi.garcia

extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: compiling Scala ASTs into Java CSTs (Concrete Syntax Trees)

On Sat, Jan 09, 2010 at 10:07:00PM +0100, Miguel Garcia wrote:
> (1.a) un-applying some previous transformations (from pattern
> match, maybe?); or

Yes, I do not think you will want to deal with the post pattern matcher
AST. I would say smarter to transform the Match AST node into an
if/then/else.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland