I haven't tried it, but here is an idea to target the JVM:
- use ldc `-output-ll` option to generate LLVM IR.
- use the LLJVM backend to generate some Jasmin assembly code
from the LLVM IR ( as described on
- link with the LLJVM linker.
This may produce some java bytecode, but to have something
working properly I suppose the D runtime should also be compiled
along with Phobos.
This may be a faster way to get to the JVM than writing a source
translator. However, this is not the best way to get Java
compatability since it does not seems to be possible to access
the Java library from the input D code.
On Friday, 15 November 2013 at 07:13:34 UTC, Jeremy DeHaan wrote:
I have been experimenting for the past couple of days with an
idea I had, and since I recently made a little progress I
thought I would share some of what I have been doing with you.
What I have done, in a nutshell, is began the process for a
language converter that takes D source files, converts them
into Java source files, and then compiles them as Java class
files so that they can be ran on Java's VM. It is extremely
limited in what it can do right now, only being able to
convert/compile a simple Hello World program, but I was proud
of myself for getting even that far so I wanted to brag. :P
You may want to ask, "Hey, man. D is a great language. Why
would I ever want to convert it to Java?" Normally, you
wouldn't. Java blows. What I am envisioning for this project is
something quite magical in my opinion. If we can take D code
and have it compile into Java class files, we can then compile
them into Android dex files. This would make D able to build
and run on Android devices through its VM. Sure, people are
working on getting D to compile to ARM binaries, but this could
be another option as a Java alternative on Android.(eventually)
Unfortunately I do not know much about compilers, but even in
the last couple of days I feel like I have learned a great deal
about what kinds of stuff goes into them. Eventually I'd like
to make a full blown compiler that takes D code and can go
right to dex files, but that would be something that would
happen way down the road. In order to get D working on Android
sooner, I figured a language converter would be the easier
I can, and would love to go in to more detail about this, but
it is getting late and this post is already quite long. Maybe I
should start a blog about my D escapades? Anyways, I would love
to hear feedback on this idea! Thanks for your time!