D - Condicional Compilation && Alien Code embedding
- Juarez Rudsatz (64/64) Aug 27 2001 Hello all !
- Dan Hursh (22/90) Aug 27 2001 Well, I think I like the idea. It's a little hard to read the grammar
- Walter (11/11) Aug 28 2001 I was thinking of generalizing your idea with a version statement, which
- Jan Knepper (9/12) Aug 28 2001 I think proper usage should be...
- Juarez Rudsatz (16/27) Aug 28 2001 My explanation was not so good.
- Walter (7/41) Aug 28 2001 I think it might be better to make it a keyword, for consistency. -Walte...
- Dan Hursh (35/51) Aug 28 2001 1) Would it be OK to add boolean logic to the test so that it could be:
- Walter (5/11) Aug 28 2001 Yes!
Hello all !
In this post I will expand some ideas from previous post ( Meaningless
title : NONE ).
My motivation is the possible ugly uses of debug statement by users and
a more flexible conditional compilation of source code. The ideas are a
merge from another posts, and a simple generalization of conditional
compilation.
Often users need maintain different app versions under same source code.
Different app features, different plataforms, different toolkits and
librarian are some of the reasons for code splitt. Another need is the use
of another languages, like assembly, for function not disponible for
language itself.
Preprocessor macros #ifdef and #ifndef is a common used for conditional
compiling in C. From this we can use the idea.
In D the are two statements for this functionality :
(1)
DebugStatement:
debug Statement
debug ( Integer ) Statement
debug ( Identifier ) Statement
(2)
AsmStatement : (probably identical as discuted before in anothers posts )
Eg :
debug { ... }
debug (10) { ... }
debug (identifier) { ... }
asm (x86) { ... }
But if we make some generalization a more flexible statement could
appear :
Conditional Statement :
[Exclude] conditional <identifier> [handler <handlername>] statement;
Eg :
Conditional debug;
Conditional asm handler assembler;
Conditional version;
Then this statement could be used as another statament in the code.
Eg : ( very hipotetical )
[a]
debug { <D source code> }
asm (x86) { <x86 assembly code> }
asm (sparc) { <sparc assemby code> }
version(light) { <D source code> }
version(premium) { <D source code> }
More explanation :
conditional <identifier> : will declare a statement for conditional
compilation of code. The language could have standart ones like debug and
asm. The code is compiled if the statement is setted in for the compiler
( -statement debug e.g.) and if it type is setted, if it has a type
(-statement asm(x86) e.g.).
Exclude : The code is compiled if the statement is not setted for the
compiler.
handler : The code module needed for generate the program fraction of the
"Alien Code". If no handler specified then the code will be D. May be a
error if there are not present and if the module type ( x86, sparc, etc.. )
is not present.
The following premisses are assumpted :
1 - If the conditional code is not D then the code is not portable.
2 - The code compiles if there are a D compiler, a "D assembler", and a
"assembler" for all modules and modules type defined.
3 - D code under coditional statement is parsed always but only included if
statement is setted. This prevents from crashed code.
Any comments, please ?
Juarez Rudsatz
P.S: sorry for bad english writing.
Aug 27 2001
Well, I think I like the idea. It's a little hard to read the grammar
though because of how my reader formatted the message, so I don't know
that I follow the syntax entirely. Specifically, does it change the
syntax of the debug statement? If so, does it change it much. I think
the design for debug is powerful and should be maintained. Extending it
to a more general mechanism just some like an acceptance of the real
world fact that platforms are grossly different and even on the same
platforms, some of us include compile time options. I don't see D
seriously being consider for OS development with out some form of
conditional compilation. I'd rather see something elegant in the
language than to see something grafted on the side. If seen that done
at places using 'legacy languages' and it has never been pretty. C was
livable, but it's time to do better.
I do wish there was a way to block out, not necessarily correct code.
I tend to write my code, first with comments and empty conditionals and
loops with obviously syntactical incorrect fillers like ??? or *** and
then block comment out the regions that aren't ready yet for testing.
Being that we are not (and should not) planning on any kind of raw text
macros, I don't think my wish is possible. Fortunately I think emacs
and // will get me by.
Dan
Juarez Rudsatz wrote:
Hello all !
In this post I will expand some ideas from previous post ( Meaningless
title : NONE ).
My motivation is the possible ugly uses of debug statement by users and
a more flexible conditional compilation of source code. The ideas are a
merge from another posts, and a simple generalization of conditional
compilation.
Often users need maintain different app versions under same source code.
Different app features, different plataforms, different toolkits and
librarian are some of the reasons for code splitt. Another need is the use
of another languages, like assembly, for function not disponible for
language itself.
Preprocessor macros #ifdef and #ifndef is a common used for conditional
compiling in C. From this we can use the idea.
In D the are two statements for this functionality :
(1)
DebugStatement:
debug Statement
debug ( Integer ) Statement
debug ( Identifier ) Statement
(2)
AsmStatement : (probably identical as discuted before in anothers posts )
Eg :
debug { ... }
debug (10) { ... }
debug (identifier) { ... }
asm (x86) { ... }
But if we make some generalization a more flexible statement could
appear :
Conditional Statement :
[Exclude] conditional <identifier> [handler <handlername>] statement;
Eg :
Conditional debug;
Conditional asm handler assembler;
Conditional version;
Then this statement could be used as another statament in the code.
Eg : ( very hipotetical )
[a]
debug { <D source code> }
asm (x86) { <x86 assembly code> }
asm (sparc) { <sparc assemby code> }
version(light) { <D source code> }
version(premium) { <D source code> }
More explanation :
conditional <identifier> : will declare a statement for conditional
compilation of code. The language could have standart ones like debug and
asm. The code is compiled if the statement is setted in for the compiler
( -statement debug e.g.) and if it type is setted, if it has a type
(-statement asm(x86) e.g.).
Exclude : The code is compiled if the statement is not setted for the
compiler.
handler : The code module needed for generate the program fraction of the
"Alien Code". If no handler specified then the code will be D. May be a
error if there are not present and if the module type ( x86, sparc, etc.. )
is not present.
The following premisses are assumpted :
1 - If the conditional code is not D then the code is not portable.
2 - The code compiles if there are a D compiler, a "D assembler", and a
"assembler" for all modules and modules type defined.
3 - D code under coditional statement is parsed always but only included if
statement is setted. This prevents from crashed code.
Any comments, please ?
Juarez Rudsatz
P.S: sorry for bad english writing.
Aug 27 2001
I was thinking of generalizing your idea with a version statement, which
will work just like the debug statement. For example:
version (demo)
{
... demo code ...
}
And you'd compile it in with something like:
dmd test.d -version=demo
One nice thing is there would be no else clause (I've found that #else
clauses on #if OPERATINGSYSTEM were almost always wrong, what is the default
operating system?).
Aug 28 2001
One nice thing is there would be no else clause (I've found that #else clauses on #if OPERATINGSYSTEM were almost always wrong, what is the default operating system?).I think proper usage should be... #if OPERATINGSYSTEM_0 #elif OPERATINGSYSTEM_1 #elif OPERATINGSYSTEM_2 #else #error ( "No implementation for this operating system (yet)!" ) #endif At least... That's how I use it... <g> Jan
Aug 28 2001
My explanation was not so good. The idea is not create another statement, but is not discarded. But let the user choice the statement name. The he could create any statement like : debug , asm, version, designtime , runtime /* for gui builder */ or anything. This could be much more flexible. Standart conditional statements could be a good idea too. The language simply specifies a construction, another statement, for buildingconditional statements. And this statements will be used like global variables. I dont have ideia if it is too complicated for implementing. How good is this solution ? Juarez Rudsatz "Walter" <walter digitalmars.com> wrote in message news:9mfc2k$nv4$1 digitaldaemon.com...I was thinking of generalizing your idea with a version statement, which will work just like the debug statement. For example: version (demo) { ... demo code ... } And you'd compile it in with something like: dmd test.d -version=demo One nice thing is there would be no else clause (I've found that #else clauses on #if OPERATINGSYSTEM were almost always wrong, what is thedefaultoperating system?).
Aug 28 2001
I think it might be better to make it a keyword, for consistency. -Walter "Juarez Rudsatz" <juarez mpsinf.com.br> wrote in message news:9mgk49$1gri$1 digitaldaemon.com...My explanation was not so good. The idea is not create another statement, but is not discarded. But lettheuser choice the statement name. The he could create any statement like : debug , asm, version, designtime,runtime /* for gui builder */ or anything. This could be much more flexible. Standart conditional statements could beagood idea too. The language simply specifies a construction, another statement, for buildingconditional statements. And this statements will be used likeglobalvariables. I dont have ideia if it is too complicated for implementing. How good is this solution ? Juarez Rudsatz "Walter" <walter digitalmars.com> wrote in message news:9mfc2k$nv4$1 digitaldaemon.com...I was thinking of generalizing your idea with a version statement, which will work just like the debug statement. For example: version (demo) { ... demo code ... } And you'd compile it in with something like: dmd test.d -version=demo One nice thing is there would be no else clause (I've found that #else clauses on #if OPERATINGSYSTEM were almost always wrong, what is thedefaultoperating system?).
Aug 28 2001
Walter wrote:
I was thinking of generalizing your idea with a version statement, which
will work just like the debug statement. For example:
version (demo)
{
... demo code ...
}
And you'd compile it in with something like:
dmd test.d -version=demo
One nice thing is there would be no else clause (I've found that #else
clauses on #if OPERATINGSYSTEM were almost always wrong, what is the default
operating system?).
1) Would it be OK to add boolean logic to the test so that it could be:
version((X || Y) && Z){
}
This isn't too important since the logic could be worked out in a make
file to define a flag lXoYlaZ or some other meaningless but functional
flag.
2) Would it be ok to nest these?
version(win32){
// neat things
version(MoNDo){
// neater things
}
// plain old neat things
}
version(POSIX){
// neat things
version(MoNDo){
// neater things
}
// plain old neat things
}
If might help configuration logic. It could also allow the removal of
and from the boolean logic above, but I wouldn't add this for that
reason alone. Given the first option, this is even less important.
3) If the first suggestion is out, can there be some way to at least
generate a compile time error if they don't prove the right concoction
of version flags? All three of the functionality's could be provided by
some for of configuration tool, but at the very least I think we should
be able to generate an error or warning at compile time.
4) Oh, I guess we would need to be able to generate that compile time
error also.
5) Debug is not being replaced is it? It says what it's for. Kinda
redundant, but pleasant.
Dan
Aug 28 2001
Dan Hursh wrote in message <3B8C5494.FB888168 infonet.isl.net>...1) Would it be OK to add boolean logic to the test so that it could be: version((X || Y) && Z){ }Yes, as long as the compiler is able to fold the constants.2) Would it be ok to nest these?Yes!5) Debug is not being replaced is it? It says what it's for. Kinda redundant, but pleasant.The debug statement would be redundant, but I think the clarity is worth having both.
Aug 28 2001









Dan Hursh <hursh infonet.isl.net> 