D and the world

eao197 eao197 at intervale.ru
Wed Apr 25 23:29:56 PDT 2007


On Thu, 26 Apr 2007 02:00:44 +0400, Jari-Matti Mäkelä  
<jmjmak at utu.fi.invalid> wrote:

Excuse me, I made a mistake: x.509 certificate, not x.503 (see  
http://en.wikipedia.org/wiki/X.509)

>> At now I just want to understand what kinds of DSL can be handled by
>> different techniques (CTFE and mixins, macros, external code generation
>> and so on).
>>
>
> Yeah, I follow you. Simple text imports can be done with the import
> expression, but if you need more processing functionality, it can be
> done with D without need for external tools. Actually it's quite simple,
> you just need to create a custom parser for a DSL. Something like
>
> const char[] file = "foo.bar";
>
> char[] parseX503File(char[] data) {
>         return data[1..$-1]; // or something more interesting
> }
>
> const certificate = parseX503File(import(file));
>
> void main() {
> 	setServerCertificate(certificate);
> }

Unfortunately parsing X509 certificates can be very tired task because it  
is necessary to handle ASN.1 data structures, byte ordering, calculating  
digital signatures and so on. Do you want to implement MD5, SHA1 or SHA256  
via CTFE and templates? :)
However, Tango already has necessary classes which can significaly  
simplify the task of parsing X509 certificates (tango.transform.digest.*,  
tango.io.protocol.* and so on). And yet more it is possible to wrap  
OpenSSL into D library and use very powerful tool for handling  
certificates.

It would be great if ordinary D code/libraries/wrappers-for-C-libraries  
can be used in compile-time. But I don't know how it can be done in D. As  
I've said previously it is not necessary at all, because we can use  
external code generation.

Another interesting idea which can be used for some kind of DSL  
(especially in Don Clugston's computation examples) is a staged  
compilation. For example see Jumbo project for Java:  
http://loome.cs.uiuc.edu/Jumbo/

> This could be done with much cleaner code too, but DMD has now several
> bugs in type inference.
>
> CTFE and templates are already Turing complete so you won't get much
> more with additional macro features.

It is said that C++ templates are Turing complete too :))

-- 
Regards,
Yauheni Akhotnikau



More information about the Digitalmars-d mailing list