Another Phobos2 test
spir
denis.spir at gmail.com
Tue Feb 8 08:35:17 PST 2011
On 02/08/2011 04:11 PM, Adam Ruppe wrote:
>> I know, but I was suggesting something different, to turn the JSON
>> > creation into some kind of Phobos library that you may call at
>> > compile-time from normal D code. Then a compile-time JSON reader in
>> > Phobos will allow to perform certain kinds of static introspection,
>> > that later will be quite useful to create user-defined @annotations.
> We could do that today with a combination of -X, -J, and a CTFE
> JSON parser (it's possible that std.json would work today. I haven't
> tried it specifically, but ctfe tends to surprise me with its
> capabilities).
>
> Of course, you'd have to run the compiler twice, but there's other
> advantages to that too (like getting dependencies - my build tool
> does this - and the first run is fast anyway.
>
>
> I'm tempted to do it now just to prove we can... but I'm already
> a bit loaded with stuff to do.
What I dream of is something a bit different: a D "decoder" (lexical,
syntactic, semantic(*) analyser) that constructs an AST as a plain D data
structure --without any fancy stuff. And writes it out on demand as a D module
(in static this(), since for a reason I haven't yet caught data description can
only go there).
I can't even start to imagine all what we could then do /easily/. (we would
even have type defs in D... would change from obscure RTTI)
=================================
import std.stdio;
a = 1;
void main () {
writeln(a);
}
=================================
==>
=================================
import AST; // Node types, mainly
Module module;
static this () {
module = Module ([
Import("std.stdio"),
Assignment("a", Integer(1)),
FunctionDef(
/* name */ "main",
/* params */ [],
/* block */ [
FunctionCall(
/* name */ "writeln",
/* args */ [Symbol(a)]
)
]
)
]);
}
=================================
Too bad we're missing named args, would be highly helpful here; but we can
probably survive that...
(Yes, Bearophile, there's certainly a bug report for this ;-)
I would enjoy writing a prototype when I have some time (not tomorrow), for a
tiny subset of D (kind of proof of concept).
Denis
(*) As far as possible.
--
_________________
vita es estrany
spir.wikidot.com
More information about the Digitalmars-d
mailing list