D to C compiler?

Wolfgang Draxinger wdraxinger at darkstargames.de
Wed Jan 28 04:50:09 PST 2009


Nicolay Korslund wrote:

> I remember reading something about a D to C compiler on this
> group a few years ago. (I'm not really a regular here anymore,
> so there might have been more recent mentions that I've
> missed.) Does anyone know if there's any such project still
> around that's alive or could be revived? Or if there's any
> other viable solutions for converting D to C (or C++)?
> 
> The reason I would want to do this is to port D code to
> currently non-supported platforms. This is especially important
> for game projects (like my own monsterscript project) - most
> game console SDKs take C/C++ and nothing else. The C/C++ output
> wouldn't have to be nice or even human readable - just
> compilable. It would only be used as a middle step in the
> compilation process for these platforms.
> 
> Any ideas or suggestions?

There's the "Trivial D compiler" TDC on dsource.org, however it's
not been active for years.

And I'm working on a similair project, though my compiler will
use a laguage derived from D, but with some significant changes,
which I call 'D*'. One of the features of D* is, that it's
explicitly meant to be compiled into C, and it has a special
import mode, in which one can "import" a C header file. Actually
the file goes to a full C99 lexer I wrote from scratch. It also
takes care of preprocessor constants and stuff like that.

Also this special import allows to apply regular expressions to
all found itentifiers, so that the identifiers used from the D*
source.

E.g.

extern (C) {
        namespace gl {
                import <GL/gl.h> : "s/^gl\.+//", "s/GL_\.+//";
        }
} 

would include the OpenGL headers into namespace gl, rewriting all
identifers so that one can write

gl.Begin(gl.POINTS)

instead of

gl.glBegin(GL_POINTS)

Wolfgang




More information about the Digitalmars-d mailing list