From: | Darius Blasband <darius@phidani.be> |
Newsgroups: | comp.compilers |
Date: | 29 Jan 1996 17:47:51 -0500 |
Organization: | EUnet Belgium, Leuven, Belgium |
References: | 96-01-037, 96-01-061 |
Keywords: | translator, interpreter, comment |
>The easiest way to compile a programming language to the Java VM is to
>cross-compile to Java and use the Java compiler to generate Java VM code.
>So you don't need to know the details of the Java VM and you can use all
>the features of Java like garbage collection and libraries. But you need
>to know Java implementation in some detail to make design decisions like
>using implicitely Javas internal stack or using a stack explicitely and
>things like that.
I am afraid I basically disagree with you: generating Java source code
as intermediate compilation step does not seem to be an applicable
(not to mention good) idea in almost any case I can think of. Fortran
to Java ? Cobol to Java ? Perl to Java ? Translating such languages
to Java source code will prove pretty cumbersome, classes will have to
be designed for almost every syntactical construct of the source
language, the resulting performance will be poor (How do you translate
Cobol's PERFORM THRU into Java source code ?)
Some other languages will even prove worse. Prolog to Java ? Lisp to
Java ? The peculiarities of these languages's control flow mechanism
will prove even more difficult to translate into Java (at least at the
source level, I am not even sure it would be reasonable to do so at
the VM level)
The solution you suggest will only work when the language you wish to
compile is pretty close to the Java model, and in these case,
generating bytecode directly is pretty easy. There is an almost
functional mapping between the primitives of the language you wish to
compile and the Java VM.
In all other cases, my guess (IMHO) would be that it would require
more skill to know how Java generates VM code and generate Java source
code accordingly, than to generate VM code directly.
Please don't misunderstand me: I am pretty enthousiast about using
medium-level languages as intermediate steps to compile higher-level
languages. However, I believe that Java is definitely not a good
candidate for such a purpose, specially when considering the very wide
range (in terms of paradigms, control flow system, type systems,
etc...) of languages some people plan to compile to the Java VM.
Darius.
[I wonder how many bugs in Java VM implementations will surface when
people start generating code from non-Java sources. -John]
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.