www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - How to know the D version ?

reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Is there any way for the source code to know
which version of the D spec is being used ?

Like:
    version(D > 0.116) {}

I'm running into new and/or experimental
features, like __TIMESTAMP__ or the [$]
and it would be nice to be able to know...

Nicer than "expression expected, not 'TOK36'" ?


For instance, there is "D_InlineAsm" for
the asm{} syntax - maybe more are needed ?
Both general spec vers, a specific features.

Maybe it could use something simple like :
version(D_VERSION_0_116_AND_LATER) {}
(assuming no versioned versions, just yet)


Or perhaps a pragma flag for the entire module :
"this file requires D version 0.116 to compile"
(maybe even a "but less than D 0.123" as well ?)

--anders
Apr 25 2005
parent reply Derek Parnell <derek psych.ward> writes:
On Mon, 25 Apr 2005 10:20:33 +0200, Anders F Björklund wrote:

 Is there any way for the source code to know
 which version of the D spec is being used ?
 
 Like:
     version(D > 0.116) {}
 
Hey, you've given me an idea. There is no simple way to do that now, but I could via the Build utility. The utility can inspect the DMD version and set a version identifer (or two). I'll think about this one and see what I can come up with. -- Derek Parnell Melbourne, Australia http://www.dsource.org/projects/build 25/04/2005 6:54:53 PM
Apr 25 2005
parent reply J C Calvarese <jcc7 cox.net> writes:
Derek Parnell wrote:
 On Mon, 25 Apr 2005 10:20:33 +0200, Anders F Björklund wrote:
 
 
Is there any way for the source code to know
which version of the D spec is being used ?

Like:
    version(D > 0.116) {}
Hey, you've given me an idea. There is no simple way to do that now, but I could via the Build utility. The utility can inspect the DMD version and set a version identifer (or two). I'll think about this one and see what I can come up with.
That'd be great! It'd be nice if std.compiler (http://www.digitalmars.com/d/phobos.html#compiler) was in some way useful for this, but apparently Walter doesn't plan on editing it until DMD 1.0. In DMD 0.121 for example: // The vendor specific version number, as in // version_major.version_minor uint version_major = 0; uint version_minor = 0; // The version of the D Programming Language Specification // Supported by the compiler uint D_major = 0; uint D_minor = 0; -- jcc7 http://jcc_7.tripod.com/d/
Apr 25 2005
next sibling parent reply Derek Parnell <derek psych.ward> writes:
On Tue, 26 Apr 2005 00:03:29 -0500, J C Calvarese wrote:

 Derek Parnell wrote:
 On Mon, 25 Apr 2005 10:20:33 +0200, Anders F Björklund wrote:
 
Is there any way for the source code to know
which version of the D spec is being used ?

Like:
    version(D > 0.116) {}
Hey, you've given me an idea. There is no simple way to do that now, but I could via the Build utility. The utility can inspect the DMD version and set a version identifer (or two). I'll think about this one and see what I can come up with.
That'd be great! It'd be nice if std.compiler (http://www.digitalmars.com/d/phobos.html#compiler) was in some way useful for this, but apparently Walter doesn't plan on editing it until DMD 1.0. In DMD 0.121 for example: // The vendor specific version number, as in // version_major.version_minor uint version_major = 0; uint version_minor = 0; // The version of the D Programming Language Specification // Supported by the compiler uint D_major = 0; uint D_minor = 0;
I've done some research now and I don't think I can do anything useful. Its a real PITA. Even if I did manage to find out what version of the compiler you have, there is no easy way to tell the source code being compiled what it is. For example, if I have code that wants to use __TIMESTAMP__ but I'm running a compiler that doesn't support it, what do I write? I know it was introduced in 0.116 but that doesn't help much at compile time. It would be extremely useful if I could code ... version(DigitalMars) { compiler_version(0.116) { // Stuff to compile if we are running 0.116 *or later* . . . } } The problem is muddied by the version statement not differentiating between application version and compiler version. -- Derek Parnell Melbourne, Australia http://www.dsource.org/projects/build/ v2.03 released 20/Apr/2005 http://www.prowiki.org/wiki4d/wiki.cgi?FrontPage 26/04/2005 3:15:42 PM
Apr 25 2005
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Derek Parnell wrote:
 On Tue, 26 Apr 2005 00:03:29 -0500, J C Calvarese wrote:
<snip>
 For example, if I have code that wants to use __TIMESTAMP__ but I'm running
 a compiler that doesn't support it, what do I write? I know it was
 introduced in 0.116 but that doesn't help much at compile time. It would be
 extremely useful if I could code ...
 
  version(DigitalMars)
  {
   compiler_version(0.116)
   {
     // Stuff to compile if we are running 0.116 *or later*
     . . .
   }
  }
 
 The problem is muddied by the version statement not differentiating between
 application version and compiler version.
There's a plan to use the D_xxxx version space to determine which language features are supported - presumably this applies to features that'll be added after 1.0 (though we have one already, D_InlineAsm). However, this can't by itself support _syntactical_ backward compatibility, since parsing happens before versioning, and so trying to use $ would cause a syntax error in older DMD. (Of course __TIMESTAMP__ would work, since it is an ordinary identifier otherwise.) However, it could be possible to support syntactical backward compatibility by something like this Older version: CompilerVersionBlock: compiler_version ( Token ) { CompilerVersionPiece* } CompilerVersionPiece: NonBrace { CompilerVersionPiece* } (Of course, every symbol character would need to be defined to be a token, even if they don't all mean anything.) Newer version: CompilerVersionBlock: compiler_version ( 0.116 ) { Statement* } (or Declaration* or whatever depending on context....) Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Apr 26 2005
parent =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Stewart Gordon wrote:

 However, this can't by itself support _syntactical_ backward 
 compatibility, since parsing happens before versioning, and so trying to 
 use $ would cause a syntax error in older DMD.  (Of course __TIMESTAMP__ 
 would work, since it is an ordinary identifier otherwise.)
Ouch, you are right. Using "version" does not work for this... I must have been thinking about the old #ifdef and friends ? For $, the only compatible approach is to use the long form "ArrayName.length" (if possible, or just "length" otherwise) At least until this experimental D feature has been finalized, and until GDC catches up with DMD 0.116 which will happen soon. I recall Java having the same problem with "future compatibility" (i.e. trying to compile new source code with the older compilers) --anders
Apr 26 2005
prev sibling parent =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
J C Calvarese wrote:

 It'd be nice if std.compiler 
 (http://www.digitalmars.com/d/phobos.html#compiler) was in some way 
 useful for this, but apparently Walter doesn't plan on editing it until 
 DMD 1.0.
It needs to be done at the "version" level, to be useful... Otherwise the compiler will choke on the new constructs anyway ? It's not hard to add it, but with the current system it'll look like: version = D_VERSION_0_110_AND_LATER; version = D_VERSION_0_111_AND_LATER; version = D_VERSION_0_112_AND_LATER; version = D_VERSION_0_113_AND_LATER; version = D_VERSION_0_114_AND_LATER; version = D_VERSION_0_115_AND_LATER; version = D_VERSION_0_116_AND_LATER; version = D_VERSION_0_117_AND_LATER; version = D_VERSION_0_118_AND_LATER; version = D_VERSION_0_119_AND_LATER; version = D_VERSION_0_120_AND_LATER; version = D_VERSION_0_121_AND_LATER; And that's not very pretty. Hopefully, by D 1.0 the spec will be frozen. --anders
Apr 25 2005