acess the d parser and compiler from the source code
James Dunne
james.jdunne at gmail.com
Wed Mar 1 11:10:13 PST 2006
dennis luehring wrote:
> what about extending the std.compiler module
>
> with an parse(char[] buffer/filename) feature
> why do we need extra parser projects - can't we use the dmd one
> internaly?
>
> import std.compiler;
> token_tree = parse("test.d"); ...
>
> and maybe an internal compile() feature (like java have)
>
> ciao dennis lühring
>
>
With the current DMD reference compiler implementation, which is written
in minimal C++ using globals everywhere and is obviously not
context-safe, this would prove very difficult to integrate natively with
D source code. What I mean by non context-safe is that the compiler is
meant to run in a single executable for a single time, not handle
multiple compilations pseudo-simultaneously using different compilation
context structures.
Now, if the compiler were implemented as a context-safe library (and
further, thread-safe) with an exposed C API, then all one would have to
do is write a D header module to interface with the compiled library's C
API. Voila - you have D compiler access within the D language. :)
I've mentioned this before, but I see it's a fair amount of work. Since
the compiler *is* implemented in C++, the classes do a fair amount of
keeping context, yet the main function and its global variables do need
to be refactored into a compiler class. Just one more level of
abstraction necessary.
--
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/MU/S d-pu s:+ a-->? C++++$ UL+++ P--- L+++ !E W-- N++ o? K? w--- O
M--@ V? PS PE Y+ PGP- t+ 5 X+ !R tv-->!tv b- DI++(+) D++ G e++>e
h>--->++ r+++ y+++
------END GEEK CODE BLOCK------
James Dunne
More information about the Digitalmars-d
mailing list