DMD - Druntime - Phobos questions.
Travis Boucher
boucher.travis at gmail.com
Sat Nov 21 06:15:52 PST 2009
I am trying to learn some of the internal implementations of D2, mostly
so I can make it work under other platforms. Right now it is making it
work under FreeBSD, since most of the stubs for FreeBSD already exist.
In the future, this will be extended to other operating systems, and
possibly embedded targets or even os development itself.
I need some help with the following, to make sure I am correct and to
add any missing pieces to puzzle.
-------------------
DMD - Digital Mars D Compiler.
http://svn.dsource.org/projects/dmd/
- src/ contains the 'front end'. This is the lexical and semantic analysis.
- src/backend/ contains the code generation parts of the compiler.
- src/root/ contains the application glue, combining the front end and
back end into something useful.
- src/tk contains helper code.
Linking (on gcc-based platforms) is done externally. The compiler just
generates objects appropriate for linking with external linkers.
Overall, the dependencies are minimal, host porting is trivial. Target
OS porting less trivial, but still pretty easy assuming well documented
and standardized object formats. Target CPU porting, don't even bother
trying with DMD.
-------------------
druntime - The runtime
http://svn.dsource.org/projects/druntime/
- import/ contains the core interfaces for the D language. These
interfaces (at least object.di and parts of core/*) need to be implemented.
- src/gc contains the garbage collector implementation. I assume
separated from the rest of the runtime to easy swapping out the GC.
- src/common/core contains the default implementation of the interfaces
in import/. Also serves as a good example of how to implement the
runtime in multiple languages (in this case, I see some D, some C and
some assembly).
- src/compiler - This one I am not too sure about. Not sure how and why
it differs from src/common/core. This is where object.d seems to be
implemented.
-------------------
phobos - The standard library (at least one of them)
http://svn.dsource.org/projects/phobos/
I won't go into too much detail of how this is organized. Overall it is
the stuff from 'import std.*'. The end-user callable code. std.c
contains the (mostly) unsafe direct interface to libc, and the rest is
wrappers around it. (of course this description is over simplified).
The standard library isn't something that is even really required (in
the way that libc for C applications isn't really required).
However implementing and using these interfaces (or the tango
interfaces) will make other code written in D work.
It should even be possible to use both tango and phobos in the same
application (correct me if I am wrong here please).
-------------------
Some things I am still unclear about.
- How does dmd know where the standard libraries (or interfaces) live?
Purely via command line? (since dmd.conf just modifies the command line)
- How does dmd know what to link in? Same as the include directories?
druntime.a is installed somewhere, and a -ldruntime (or similar) command
line is used?
- What requires what? Phobos isn't required (but without it or
something similar, things are pretty useless).
- How much of druntime is really required? This is an important
question for embedded/os development targets.
http://svn.dsource.org/projects/druntime/trunk/src/gc/stub/gc.d a good
example of a minimal garbage collector.
http://svn.dsource.org/projects/druntime/trunk/import/object.di seems
to be the only import that is *required*.
http://svn.dsource.org/projects/druntime/trunk/import/core/sys/ seems
to be system Dependant, and not required.
http://svn.dsource.org/projects/druntime/trunk/import/core/stdc/ seems
to be mostly an abstract of libc, so not really needed.
These questions obviously show my interest in (future) development on
either embedded platforms, or for OS development.
-------------------
Other general D questions.
- What is the general consensus on the different D compiler
implementations? I know this is a very opinionated question, I am
looking for answers that related to the D implementation and not the
compilers themselves. I am mostly interested in GCC due to it's huge
list of targets, complete and mature toolchain, and its something I've
always used.
- What is the general consensus on the different D standard libraries?
Again, I don't want religion here, just overall state related to D2.
From what I've seen, phobos is similar (in functionality) to something
like libc (plus extras of course), and tango would be more like boost
and STL.
Thanks,
Travis
More information about the Digitalmars-d-learn
mailing list