September 15, 2001 Re: new version statement - no else? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Phil Brooks | Phil Brooks wrote in message <3BA13EE3.8D8F68B6@mentor.com>... >One thing I have wished for in C++ was that templates weren't so obtuse (all >the type stuff that is used to hide information somewhere and dig it out somewhere else etc). > >It seems to me that one way to handle this ifdef issue as well as the template issue would >be to have some sort of run-time scripting language that you can break into that >has a well defined interface to the compiler's current state. It wouldn't be the >brute force type of string substitution of macros since it would obey scoping etc. and it >would be a lot more straight forward than the hide-and-seek with types games that C++ >uses. > >So you might do something like > >compiler.runtime< HARDWARE.CONFIG_PPC601=1; >; > >... > >void func_A() { > compiler.runtime< > if ( CONFIG_PPC601==1 ) { > compiler.write_code( > some PPC601 specific code... > ); > } else { > compiler.write_code( > some generic code > ); > >; >} > >and go on to do other interesting things like template, varargs, etc assuming you >can get at things like currently defined variables, type arguments to a template, >arguments from the call site of a function where a template is being instantiated, >etc. > >so something like > >void template_func_A( ... ) { > compiler.runtime< > foreach current_argument in compiler.current_function_arguments { > compiler.write_code( > if ( current_argument.type() == A ) { > process type A argument > } else if ( current_argument.type().is_derived_from( A ) { > process something derived from A argument > } else { > process generic argument > } > ); > } > >; >} > >Has any compiler ever done something like that? Not that I've seen. The specification for C++ templates is 56 pages long. While people have convinced me that templates should be in D, I will find a simpler way. -Walter |
September 17, 2001 Re: new version statement - no else? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | Walter wrote: > Phil Brooks wrote in message > <3BA13EE3.8D8F68B6@mentor.com>... > >> One thing I have wished for in C++ was that templates >> weren't so obtuse... It seems to me that one way to >> handle this ifdef issue as well as the >> > template issue would > >> be to have some sort of run-time scripting language that >> you can break into ... >> >> Has any compiler ever done something like that? >> > > > Not that I've seen. The specification for C++ templates is > 56 pages long. While people have convinced me that > templates should be in D, I will find a simpler way. -Walter > One thing that you might consider would be the use of Python as a scripting language, though I really feel that this is more properly a part of the IDE than of the language. If one were to consider the language and the IDE to be in some sort of unity, then the code that was written could be in some sort of "pre-final" form, the code that was emitted could be the D language that we have been discussing, and the IDE could have all sorts of compile-time options that were basically python text processing widgets. (Ruby might be even better for this, but Python is more widely known in the Indo-European speaking world.) But if the idea is that the actual D language be simple to parse locally, then this couldn't be a part of the final D language, and would need to be an ancillary option. (I.e., one could write pure D with a text editor, or with the Netscape Composer. One wouldn't need a special language parser beyond the D compiler.) Still, it could easily be a very nice addition, rather like Idle is for Python. Not necessary, but nice to have. |
September 17, 2001 Re: new version statement - no else? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | My assertion is that a scripting language with access to compile-time state and the ability to generate code would be vastly simpler to spec. and easier to understand than C++ templates are. It would also easily replace the constant definition, conditional compilation, and macro expansion uses of the pre-processor.
Walter wrote:
>
> Phil Brooks wrote in message <3BA13EE3.8D8F68B6@mentor.com>...
> >One thing I have wished for in C++ was that templates weren't so obtuse
> (all
> >the type stuff that is used to hide information somewhere and dig it out somewhere else etc).
> >
> >It seems to me that one way to handle this ifdef issue as well as the
> template issue would
> >be to have some sort of run-time scripting language that you can break into
> that
> >has a well defined interface to the compiler's current state. It wouldn't
> be the
> >brute force type of string substitution of macros since it would obey
> scoping etc. and it
> >would be a lot more straight forward than the hide-and-seek with types
> games that C++
> >uses.
> >
> >So you might do something like
> >
> >compiler.runtime< HARDWARE.CONFIG_PPC601=1; >;
> >
> >...
> >
> >void func_A() {
> > compiler.runtime<
> > if ( CONFIG_PPC601==1 ) {
> > compiler.write_code(
> > some PPC601 specific code...
> > );
> > } else {
> > compiler.write_code(
> > some generic code
> > );
> > >;
> >}
> >
> >and go on to do other interesting things like template, varargs, etc
> assuming you
> >can get at things like currently defined variables, type arguments to a
> template,
> >arguments from the call site of a function where a template is being
> instantiated,
> >etc.
> >
> >so something like
> >
> >void template_func_A( ... ) {
> > compiler.runtime<
> > foreach current_argument in compiler.current_function_arguments {
> > compiler.write_code(
> > if ( current_argument.type() == A ) {
> > process type A argument
> > } else if ( current_argument.type().is_derived_from( A ) {
> > process something derived from A argument
> > } else {
> > process generic argument
> > }
> > );
> > }
> > >;
> >}
> >
> >Has any compiler ever done something like that?
>
> Not that I've seen. The specification for C++ templates is 56 pages long. While people have convinced me that templates should be in D, I will find a simpler way. -Walter
|
December 07, 2001 Re: new version statement - no else? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Phil Brooks | "Phil Brooks" <phil_brooks@mentor.com> wrote in message news:3BA6244C.56E8D085@mentor.com... > My assertion is that a scripting language with access to compile-time state and the ability to generate code would be vastly simpler to spec. and easier to understand than C++ templates are. It would also easily replace the constant definition, conditional compilation, and macro expansion uses of the pre-processor. Yes, it would. I do not see offhand, however, how it could be interleaved with D code in a way that the different languages are clearly distinguishable. One of my beefs with C is that the two languages are interleaved, but not distinguishable. |
Copyright © 1999-2021 by the D Language Foundation